// Copyright 2009 Google LLC // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google LLC nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ #define GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ #include <stdint.h> #include <stdlib.h> #include <unistd.h> #include <sys/mman.h> #include <memory> #include <vector> #if defined(MEMORY_SANITIZER) #include <sanitizer/msan_interface.h> #endif #ifdef __APPLE__ #define sys_mmap … #define sys_munmap … #define MAP_ANONYMOUS … #else #include "third_party/lss/linux_syscall_support.h" #endif namespace google_breakpad { // This is very simple allocator which fetches pages from the kernel directly. // Thus, it can be used even when the heap may be corrupted. // // There is no free operation. The pages are only freed when the object is // destroyed. class PageAllocator { … }; // Wrapper to use with STL containers template <typename T> struct PageStdAllocator { … }; // A wasteful vector is a std::vector, except that it allocates memory from a // PageAllocator. It's wasteful because, when resizing, it always allocates a // whole new array since the PageAllocator doesn't support realloc. template<class T> class wasteful_vector : public std::vector<T, PageStdAllocator<T> > { … }; // auto_wasteful_vector allocates space on the stack for N entries to avoid // using the PageAllocator for small data, while still allowing for larger data. template<class T, unsigned int N> class auto_wasteful_vector : public wasteful_vector<T> { … }; } // namespace google_breakpad inline void* operator new(size_t nbytes, google_breakpad::PageAllocator& allocator) { … } #endif // GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_