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 kInternalAllocatorRegionSizeLog = 20;
27 static const uptr kInternalAllocatorNumRegions =
28 SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog;
29 #if SANITIZER_WORDSIZE == 32
30 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
32 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
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 typedef __sanitizer::ByteMap ByteMap;
41 typedef NoOpMapUnmapCallback MapUnmapCallback;
42 static const uptr kFlags = 0;
44 typedef SizeClassAllocator32<AP32> PrimaryInternalAllocator;
46 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
47 InternalAllocatorCache;
49 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
50 LargeMmapAllocator<NoOpMapUnmapCallback, DieOnFailure>
53 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr,
55 void *InternalRealloc(void *p, uptr size,
56 InternalAllocatorCache *cache = nullptr);
57 void *InternalCalloc(uptr countr, uptr size,
58 InternalAllocatorCache *cache = nullptr);
59 void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
60 InternalAllocator *internal_allocator();
62 enum InternalAllocEnum {
66 } // namespace __sanitizer
68 inline void *operator new(__sanitizer::operator_new_size_type size,
69 __sanitizer::InternalAllocEnum) {
70 return __sanitizer::InternalAlloc(size);
73 #endif // SANITIZER_ALLOCATOR_INTERNAL_H