sanitizer_allocator_internal.h revision 1.1.1.4
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 18namespace __sanitizer { 19 20// FIXME: Check if we may use even more compact size class map for internal 21// purposes. 22typedef CompactSizeClassMap InternalSizeClassMap; 23 24static const uptr kInternalAllocatorRegionSizeLog = 20; 25static const uptr kInternalAllocatorNumRegions = 26 SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog; 27#if SANITIZER_WORDSIZE == 32 28typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap; 29#else 30typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap; 31#endif 32struct AP32 { 33 static const uptr kSpaceBeg = 0; 34 static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE; 35 static const uptr kMetadataSize = 0; 36 typedef InternalSizeClassMap SizeClassMap; 37 static const uptr kRegionSizeLog = kInternalAllocatorRegionSizeLog; 38 typedef __sanitizer::ByteMap ByteMap; 39 typedef NoOpMapUnmapCallback MapUnmapCallback; 40 static const uptr kFlags = 0; 41}; 42typedef SizeClassAllocator32<AP32> PrimaryInternalAllocator; 43 44typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator> 45 InternalAllocatorCache; 46 47typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache, 48 LargeMmapAllocator<NoOpMapUnmapCallback, DieOnFailure> 49 > InternalAllocator; 50 51void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr, 52 uptr alignment = 0); 53void *InternalRealloc(void *p, uptr size, 54 InternalAllocatorCache *cache = nullptr); 55void *InternalCalloc(uptr countr, uptr size, 56 InternalAllocatorCache *cache = nullptr); 57void InternalFree(void *p, InternalAllocatorCache *cache = nullptr); 58InternalAllocator *internal_allocator(); 59 60enum InternalAllocEnum { 61 INTERNAL_ALLOC 62}; 63 64} // namespace __sanitizer 65 66inline void *operator new(__sanitizer::operator_new_size_type size, 67 __sanitizer::InternalAllocEnum) { 68 return __sanitizer::InternalAlloc(size); 69} 70 71#endif // SANITIZER_ALLOCATOR_INTERNAL_H 72