1296417Sdim//===-- sanitizer_allocator_internal.h --------------------------*- C++ -*-===// 2274201Sdim// 3274201Sdim// The LLVM Compiler Infrastructure 4274201Sdim// 5274201Sdim// This file is distributed under the University of Illinois Open Source 6274201Sdim// License. See LICENSE.TXT for details. 7274201Sdim// 8274201Sdim//===----------------------------------------------------------------------===// 9274201Sdim// 10274201Sdim// This allocator is used inside run-times. 11274201Sdim// 12274201Sdim//===----------------------------------------------------------------------===// 13274201Sdim 14274201Sdim#ifndef SANITIZER_ALLOCATOR_INTERNAL_H 15274201Sdim#define SANITIZER_ALLOCATOR_INTERNAL_H 16274201Sdim 17274201Sdim#include "sanitizer_allocator.h" 18274201Sdim#include "sanitizer_internal_defs.h" 19274201Sdim 20274201Sdimnamespace __sanitizer { 21274201Sdim 22274201Sdim// FIXME: Check if we may use even more compact size class map for internal 23274201Sdim// purposes. 24274201Sdimtypedef CompactSizeClassMap InternalSizeClassMap; 25274201Sdim 26274201Sdimstatic const uptr kInternalAllocatorSpace = 0; 27276789Sdimstatic const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE; 28276789Sdimstatic const uptr kInternalAllocatorRegionSizeLog = 20; 29274201Sdim#if SANITIZER_WORDSIZE == 32 30276789Sdimstatic const uptr kInternalAllocatorNumRegions = 31276789Sdim kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 32276789Sdimtypedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap; 33274201Sdim#else 34276789Sdimstatic const uptr kInternalAllocatorNumRegions = 35276789Sdim kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog; 36276789Sdimtypedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap; 37274201Sdim#endif 38274201Sdimtypedef SizeClassAllocator32< 39276789Sdim kInternalAllocatorSpace, kInternalAllocatorSize, 0, InternalSizeClassMap, 40276789Sdim kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator; 41274201Sdim 42274201Sdimtypedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator> 43274201Sdim InternalAllocatorCache; 44274201Sdim 45274201Sdimtypedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache, 46276789Sdim LargeMmapAllocator<> > InternalAllocator; 47274201Sdim 48296417Sdimvoid *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr); 49296417Sdimvoid InternalFree(void *p, InternalAllocatorCache *cache = nullptr); 50274201SdimInternalAllocator *internal_allocator(); 51274201Sdim 52280031Sdimenum InternalAllocEnum { 53280031Sdim INTERNAL_ALLOC 54280031Sdim}; 55280031Sdim 56296417Sdim} // namespace __sanitizer 57274201Sdim 58280031Sdiminline void *operator new(__sanitizer::operator_new_size_type size, 59280031Sdim InternalAllocEnum) { 60280031Sdim return InternalAlloc(size); 61280031Sdim} 62280031Sdim 63296417Sdim#endif // SANITIZER_ALLOCATOR_INTERNAL_H 64