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