1 //===-- sanitizer_allocator_internal.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This allocator is used inside run-times.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_ALLOCATOR_INTERNAL_H
15 #define SANITIZER_ALLOCATOR_INTERNAL_H
17 #include "sanitizer_allocator.h"
18 #include "sanitizer_internal_defs.h"
20 namespace __sanitizer {
22 // FIXME: Check if we may use even more compact size class map for internal
24 typedef CompactSizeClassMap InternalSizeClassMap;
26 static const uptr kInternalAllocatorSpace = 0;
27 static const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE;
28 static const uptr kInternalAllocatorRegionSizeLog = 20;
29 #if SANITIZER_WORDSIZE == 32
30 static const uptr kInternalAllocatorNumRegions =
31 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
32 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
34 static const uptr kInternalAllocatorNumRegions =
35 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
36 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
38 typedef SizeClassAllocator32<
39 kInternalAllocatorSpace, kInternalAllocatorSize, 0, InternalSizeClassMap,
40 kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator;
42 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
43 InternalAllocatorCache;
45 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
46 LargeMmapAllocator<> > InternalAllocator;
48 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr);
49 void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
50 InternalAllocator *internal_allocator();
52 enum InternalAllocEnum {
56 } // namespace __sanitizer
58 inline void *operator new(__sanitizer::operator_new_size_type size,
60 return InternalAlloc(size);
63 #endif // SANITIZER_ALLOCATOR_INTERNAL_H