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 kInternalAllocatorRegionSizeLog = 20; 27 static const uptr kInternalAllocatorNumRegions = 28 SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog; 29 #if SANITIZER_WORDSIZE == 32 30 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap; 31 #else 32 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap; 33 #endif 34 struct AP32 { 35 static const uptr kSpaceBeg = 0; 36 static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; 37 static const uptr kMetadataSize = 0; 38 typedef InternalSizeClassMap SizeClassMap; 39 static const uptr kRegionSizeLog = kInternalAllocatorRegionSizeLog; 40 using AddressSpaceView = LocalAddressSpaceView; 41 using ByteMap = __sanitizer::ByteMap; 42 typedef NoOpMapUnmapCallback MapUnmapCallback; 43 static const uptr kFlags = 0; 44 }; 45 typedef SizeClassAllocator32<AP32> PrimaryInternalAllocator; 46 47 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator> 48 InternalAllocatorCache; 49 50 typedef LargeMmapAllocator<NoOpMapUnmapCallback, 51 LargeMmapAllocatorPtrArrayStatic> 52 SecondaryInternalAllocator; 53 54 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache, 55 SecondaryInternalAllocator> InternalAllocator; 56 57 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr, 58 uptr alignment = 0); 59 void *InternalRealloc(void *p, uptr size, 60 InternalAllocatorCache *cache = nullptr); 61 void *InternalCalloc(uptr countr, uptr size, 62 InternalAllocatorCache *cache = nullptr); 63 void InternalFree(void *p, InternalAllocatorCache *cache = nullptr); 64 InternalAllocator *internal_allocator(); 65 66 } // namespace __sanitizer 67 68 #endif // SANITIZER_ALLOCATOR_INTERNAL_H 69