111
|
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.
|
|
10 //
|
|
11 //===----------------------------------------------------------------------===//
|
|
12
|
|
13 #ifndef LSAN_ALLOCATOR_H
|
|
14 #define LSAN_ALLOCATOR_H
|
|
15
|
|
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"
|
|
20
|
|
21 namespace __lsan {
|
|
22
|
|
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);
|
|
29
|
|
30 template<typename Callable>
|
|
31 void ForEachChunk(const Callable &callback);
|
|
32
|
|
33 void GetAllocatorCacheRange(uptr *begin, uptr *end);
|
|
34 void AllocatorThreadFinish();
|
|
35 void InitializeAllocator();
|
|
36
|
|
37 const bool kAlwaysClearMemory = true;
|
|
38
|
|
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;
|
|
49 };
|
|
50
|
|
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;
|
|
56
|
|
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;
|
|
66 };
|
|
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;
|
|
76 };
|
|
77
|
|
78 typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
|
79 #endif
|
|
80 typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
|
|
81
|
|
82 AllocatorCache *GetAllocatorCache();
|
|
83
|
|
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);
|
|
91
|
|
92 } // namespace __lsan
|
|
93
|
|
94 #endif // LSAN_ALLOCATOR_H
|