11f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov//===-- sanitizer_allocator_internal.h -------------------------- C++ -----===// 21f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// 31f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// The LLVM Compiler Infrastructure 41f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// 51f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// This file is distributed under the University of Illinois Open Source 61f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// License. See LICENSE.TXT for details. 71f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// 81f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov//===----------------------------------------------------------------------===// 91f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// 101f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// This allocator is used inside run-times. 111f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// 121f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov//===----------------------------------------------------------------------===// 131f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 141f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#ifndef SANITIZER_ALLOCATOR_INTERNAL_H 151f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#define SANITIZER_ALLOCATOR_INTERNAL_H 161f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 171f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#include "sanitizer_allocator.h" 181f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#include "sanitizer_internal_defs.h" 191f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 201f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovnamespace __sanitizer { 211f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 22616659a1608efe3791e749d406824032afe694e9Alexey Samsonov// FIXME: Check if we may use even more compact size class map for internal 231f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov// purposes. 241f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovtypedef CompactSizeClassMap InternalSizeClassMap; 251f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 261f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovstatic const uptr kInternalAllocatorSpace = 0; 272d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesstatic const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE; 281f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#if SANITIZER_WORDSIZE == 32 291f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovstatic const uptr kInternalAllocatorRegionSizeLog = 20; 302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesstatic const uptr kInternalAllocatorNumRegions = 312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinestypedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap; 331f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#else 341f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovstatic const uptr kInternalAllocatorRegionSizeLog = 24; 352d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesstatic const uptr kInternalAllocatorNumRegions = 361f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 372d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinestypedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap; 382d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#endif 391f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovtypedef SizeClassAllocator32< 401f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov kInternalAllocatorSpace, kInternalAllocatorSize, 16, InternalSizeClassMap, 412d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator; 421f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 431f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovtypedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator> 441f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov InternalAllocatorCache; 451f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 462d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// We don't want our internal allocator to do any map/unmap operations from 472d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// LargeMmapAllocator. 481f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovstruct CrashOnMapUnmap { 491f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov void OnMap(uptr p, uptr size) const { 502d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines RAW_CHECK_MSG(0, "Unexpected mmap in InternalAllocator!\n"); 511f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov } 521f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov void OnUnmap(uptr p, uptr size) const { 532d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines RAW_CHECK_MSG(0, "Unexpected munmap in InternalAllocator!\n"); 541f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov } 551f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov}; 561f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 571f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovtypedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache, 581f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov LargeMmapAllocator<CrashOnMapUnmap> > 591f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov InternalAllocator; 601f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 611f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovvoid *InternalAlloc(uptr size, InternalAllocatorCache *cache = 0); 621f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonovvoid InternalFree(void *p, InternalAllocatorCache *cache = 0); 631f3c2fee395abc36230c445e9ebdba55c4729d35Alexey SamsonovInternalAllocator *internal_allocator(); 641f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 651f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov} // namespace __sanitizer 661f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov 671f3c2fee395abc36230c445e9ebdba55c4729d35Alexey Samsonov#endif // SANITIZER_ALLOCATOR_INTERNAL_H 68