]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h
Update expat to 2.2.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 kInternalAllocatorRegionSizeLog = 20;
27 static const uptr kInternalAllocatorNumRegions =
28     SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog;
29 #if SANITIZER_WORDSIZE == 32
30 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
31 #else
32 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
33 #endif
34 struct AP32 {
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;
43 };
44 typedef SizeClassAllocator32<AP32> PrimaryInternalAllocator;
45
46 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
47     InternalAllocatorCache;
48
49 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
50                           LargeMmapAllocator<NoOpMapUnmapCallback, DieOnFailure>
51                          > InternalAllocator;
52
53 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr,
54                     uptr alignment = 0);
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();
61
62 enum InternalAllocEnum {
63   INTERNAL_ALLOC
64 };
65
66 } // namespace __sanitizer
67
68 inline void *operator new(__sanitizer::operator_new_size_type size,
69                           __sanitizer::InternalAllocEnum) {
70   return __sanitizer::InternalAlloc(size);
71 }
72
73 #endif // SANITIZER_ALLOCATOR_INTERNAL_H