1 //===-- sanitizer_allocator_internal.h -------------------------- C++ -----===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This allocator is used inside run-times.
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
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
;
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
;
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
> >
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