]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h
Merge libxo 0.4.6
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_allocator_internal.h
1 //===-- sanitizer_allocator_internal.h --------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This allocator is used inside run-times.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SANITIZER_ALLOCATOR_INTERNAL_H
15 #define SANITIZER_ALLOCATOR_INTERNAL_H
16
17 #include "sanitizer_allocator.h"
18 #include "sanitizer_internal_defs.h"
19
20 namespace __sanitizer {
21
22 // FIXME: Check if we may use even more compact size class map for internal
23 // purposes.
24 typedef CompactSizeClassMap InternalSizeClassMap;
25
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;
33 #else
34 static const uptr kInternalAllocatorNumRegions =
35     kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
36 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
37 #endif
38 typedef SizeClassAllocator32<
39     kInternalAllocatorSpace, kInternalAllocatorSize, 0, InternalSizeClassMap,
40     kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator;
41
42 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
43     InternalAllocatorCache;
44
45 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
46                           LargeMmapAllocator<> > InternalAllocator;
47
48 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr);
49 void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
50 InternalAllocator *internal_allocator();
51
52 enum InternalAllocEnum {
53   INTERNAL_ALLOC
54 };
55
56 } // namespace __sanitizer
57
58 inline void *operator new(__sanitizer::operator_new_size_type size,
59                           InternalAllocEnum) {
60   return InternalAlloc(size);
61 }
62
63 #endif // SANITIZER_ALLOCATOR_INTERNAL_H