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 static const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE; 28 #if SANITIZER_WORDSIZE == 32 29 static const uptr kInternalAllocatorRegionSizeLog = 20; 30 static const uptr kInternalAllocatorNumRegions = 31 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 32 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap; 33 #else 34 static const uptr kInternalAllocatorRegionSizeLog = 24; 35 static const uptr kInternalAllocatorNumRegions = 36 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 37 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap; 38 #endif 39 typedef SizeClassAllocator32< 40 kInternalAllocatorSpace, kInternalAllocatorSize, 16, InternalSizeClassMap, 41 kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator; 42 43 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator> 44 InternalAllocatorCache; 45 46 // We don't want our internal allocator to do any map/unmap operations from 47 // LargeMmapAllocator. 48 struct CrashOnMapUnmap { 49 void OnMap(uptr p, uptr size) const { 50 RAW_CHECK_MSG(0, "Unexpected mmap in InternalAllocator!\n"); 51 } 52 void OnUnmap(uptr p, uptr size) const { 53 RAW_CHECK_MSG(0, "Unexpected munmap in InternalAllocator!\n"); 54 } 55 }; 56 57 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache, 58 LargeMmapAllocator<CrashOnMapUnmap> > 59 InternalAllocator; 60 61 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = 0); 62 void InternalFree(void *p, InternalAllocatorCache *cache = 0); 63 InternalAllocator *internal_allocator(); 64 65 } // namespace __sanitizer 66 67 #endif // SANITIZER_ALLOCATOR_INTERNAL_H 68