• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                     uptr alignment = 0);
50 void *InternalRealloc(void *p, uptr size,
51                       InternalAllocatorCache *cache = nullptr);
52 void *InternalCalloc(uptr countr, uptr size,
53                      InternalAllocatorCache *cache = nullptr);
54 void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
55 InternalAllocator *internal_allocator();
56 
57 enum InternalAllocEnum {
58   INTERNAL_ALLOC
59 };
60 
61 } // namespace __sanitizer
62 
new(__sanitizer::operator_new_size_type size,InternalAllocEnum)63 inline void *operator new(__sanitizer::operator_new_size_type size,
64                           InternalAllocEnum) {
65   return InternalAlloc(size);
66 }
67 
68 #endif // SANITIZER_ALLOCATOR_INTERNAL_H
69