PR c++/87122
[official-gcc.git] / libsanitizer / lsan / lsan_allocator.h
blobb0c0ec241d967484a61a40545b450601af2c70d5
1 //=-- lsan_allocator.h ----------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of LeakSanitizer.
9 // Allocator for standalone LSan.
11 //===----------------------------------------------------------------------===//
13 #ifndef LSAN_ALLOCATOR_H
14 #define LSAN_ALLOCATOR_H
16 #include "sanitizer_common/sanitizer_allocator.h"
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_internal_defs.h"
19 #include "lsan_common.h"
21 namespace __lsan {
23 void *Allocate(const StackTrace &stack, uptr size, uptr alignment,
24 bool cleared);
25 void Deallocate(void *p);
26 void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
27 uptr alignment);
28 uptr GetMallocUsableSize(const void *p);
30 template<typename Callable>
31 void ForEachChunk(const Callable &callback);
33 void GetAllocatorCacheRange(uptr *begin, uptr *end);
34 void AllocatorThreadFinish();
35 void InitializeAllocator();
37 const bool kAlwaysClearMemory = true;
39 struct ChunkMetadata {
40 u8 allocated : 8; // Must be first.
41 ChunkTag tag : 2;
42 #if SANITIZER_WORDSIZE == 64
43 uptr requested_size : 54;
44 #else
45 uptr requested_size : 32;
46 uptr padding : 22;
47 #endif
48 u32 stack_trace_id;
51 #if defined(__mips64) || defined(__aarch64__) || defined(__i386__) || \
52 defined(__arm__)
53 static const uptr kRegionSizeLog = 20;
54 static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
55 typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;
57 struct AP32 {
58 static const uptr kSpaceBeg = 0;
59 static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
60 static const uptr kMetadataSize = sizeof(ChunkMetadata);
61 typedef __sanitizer::CompactSizeClassMap SizeClassMap;
62 static const uptr kRegionSizeLog = __lsan::kRegionSizeLog;
63 typedef __lsan::ByteMap ByteMap;
64 typedef NoOpMapUnmapCallback MapUnmapCallback;
65 static const uptr kFlags = 0;
67 typedef SizeClassAllocator32<AP32> PrimaryAllocator;
68 #elif defined(__x86_64__) || defined(__powerpc64__)
69 struct AP64 { // Allocator64 parameters. Deliberately using a short name.
70 static const uptr kSpaceBeg = 0x600000000000ULL;
71 static const uptr kSpaceSize = 0x40000000000ULL; // 4T.
72 static const uptr kMetadataSize = sizeof(ChunkMetadata);
73 typedef DefaultSizeClassMap SizeClassMap;
74 typedef NoOpMapUnmapCallback MapUnmapCallback;
75 static const uptr kFlags = 0;
78 typedef SizeClassAllocator64<AP64> PrimaryAllocator;
79 #endif
80 typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
82 AllocatorCache *GetAllocatorCache();
84 void *lsan_memalign(uptr alignment, uptr size, const StackTrace &stack);
85 void *lsan_malloc(uptr size, const StackTrace &stack);
86 void lsan_free(void *p);
87 void *lsan_realloc(void *p, uptr size, const StackTrace &stack);
88 void *lsan_calloc(uptr nmemb, uptr size, const StackTrace &stack);
89 void *lsan_valloc(uptr size, const StackTrace &stack);
90 uptr lsan_mz_size(const void *p);
92 } // namespace __lsan
94 #endif // LSAN_ALLOCATOR_H