1 //===-- sanitizer_allocator_internal.h -------------------------- C++ -----===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This allocator is used inside run-times. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef SANITIZER_ALLOCATOR_INTERNAL_H 15 #define SANITIZER_ALLOCATOR_INTERNAL_H 16 17 #include "sanitizer_allocator.h" 18 #include "sanitizer_internal_defs.h" 19 20 namespace __sanitizer { 21 22 // FIXME: Check if we may use even more compact size class map for internal 23 // purposes. 24 typedef CompactSizeClassMap InternalSizeClassMap; 25 26 static const uptr kInternalAllocatorSpace = 0; 27 #if SANITIZER_WORDSIZE == 32 28 static const u64 kInternalAllocatorSize = (1ULL << 32); 29 static const uptr kInternalAllocatorRegionSizeLog = 20; 30 #else 31 static const u64 kInternalAllocatorSize = (1ULL << 47); 32 static const uptr kInternalAllocatorRegionSizeLog = 24; 33 #endif 34 static const uptr kInternalAllocatorFlatByteMapSize = 35 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 36 typedef SizeClassAllocator32< 37 kInternalAllocatorSpace, kInternalAllocatorSize, 16, InternalSizeClassMap, 38 kInternalAllocatorRegionSizeLog, 39 FlatByteMap<kInternalAllocatorFlatByteMapSize> > PrimaryInternalAllocator; 40 41 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator> 42 InternalAllocatorCache; 43 44 // We don't want our internal allocator to do any map/unmap operations. 45 struct CrashOnMapUnmap { 46 void OnMap(uptr p, uptr size) const { 47 RAW_CHECK_MSG(0, "Unexpected mmap in InternalAllocator!"); 48 } 49 void OnUnmap(uptr p, uptr size) const { 50 RAW_CHECK_MSG(0, "Unexpected munmap in InternalAllocator!"); 51 } 52 }; 53 54 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache, 55 LargeMmapAllocator<CrashOnMapUnmap> > 56 InternalAllocator; 57 58 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = 0); 59 void InternalFree(void *p, InternalAllocatorCache *cache = 0); 60 InternalAllocator *internal_allocator(); 61 62 } // namespace __sanitizer 63 64 #endif // SANITIZER_ALLOCATOR_INTERNAL_H 65