2014-01-30 Alangi Derick <alangiderick@gmail.com>
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_allocator_internal.h
blobefdb89e36825c749d3729a05a9fba4b7402513fe
1 //===-- sanitizer_allocator_internal.h -------------------------- C++ -----===//
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 allocator is used inside run-times.
9 //
10 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_ALLOCATOR_INTERNAL_H
13 #define SANITIZER_ALLOCATOR_INTERNAL_H
15 #include "sanitizer_allocator.h"
16 #include "sanitizer_internal_defs.h"
18 namespace __sanitizer {
20 // FIXME: Check if we may use even more compact size class map for internal
21 // purposes.
22 typedef CompactSizeClassMap InternalSizeClassMap;
24 static const uptr kInternalAllocatorSpace = 0;
25 #if SANITIZER_WORDSIZE == 32
26 static const u64 kInternalAllocatorSize = (1ULL << 32);
27 static const uptr kInternalAllocatorRegionSizeLog = 20;
28 static const uptr kInternalAllocatorNumRegions =
29 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
30 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
31 #else
32 static const u64 kInternalAllocatorSize = (1ULL << 47);
33 static const uptr kInternalAllocatorRegionSizeLog = 24;
34 static const uptr kInternalAllocatorNumRegions =
35 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
36 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
37 #endif
38 typedef SizeClassAllocator32<
39 kInternalAllocatorSpace, kInternalAllocatorSize, 16, InternalSizeClassMap,
40 kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator;
42 typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
43 InternalAllocatorCache;
45 // We don't want our internal allocator to do any map/unmap operations from
46 // LargeMmapAllocator.
47 struct CrashOnMapUnmap {
48 void OnMap(uptr p, uptr size) const {
49 RAW_CHECK_MSG(0, "Unexpected mmap in InternalAllocator!");
51 void OnUnmap(uptr p, uptr size) const {
52 RAW_CHECK_MSG(0, "Unexpected munmap in InternalAllocator!");
56 typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
57 LargeMmapAllocator<CrashOnMapUnmap> >
58 InternalAllocator;
60 void *InternalAlloc(uptr size, InternalAllocatorCache *cache = 0);
61 void InternalFree(void *p, InternalAllocatorCache *cache = 0);
62 InternalAllocator *internal_allocator();
64 } // namespace __sanitizer
66 #endif // SANITIZER_ALLOCATOR_INTERNAL_H