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 static const u64 kInternalAllocatorSize
= SANITIZER_MMAP_RANGE_SIZE
;
26 #if SANITIZER_WORDSIZE == 32
27 static const uptr kInternalAllocatorRegionSizeLog
= 20;
28 static const uptr kInternalAllocatorNumRegions
=
29 kInternalAllocatorSize
>> kInternalAllocatorRegionSizeLog
;
30 typedef FlatByteMap
<kInternalAllocatorNumRegions
> ByteMap
;
32 static const uptr kInternalAllocatorRegionSizeLog
= 24;
33 static const uptr kInternalAllocatorNumRegions
=
34 kInternalAllocatorSize
>> kInternalAllocatorRegionSizeLog
;
35 typedef TwoLevelByteMap
<(kInternalAllocatorNumRegions
>> 12), 1 << 12> ByteMap
;
37 typedef SizeClassAllocator32
<
38 kInternalAllocatorSpace
, kInternalAllocatorSize
, 16, InternalSizeClassMap
,
39 kInternalAllocatorRegionSizeLog
, ByteMap
> PrimaryInternalAllocator
;
41 typedef SizeClassAllocatorLocalCache
<PrimaryInternalAllocator
>
42 InternalAllocatorCache
;
44 // We don't want our internal allocator to do any map/unmap operations from
45 // LargeMmapAllocator.
46 struct CrashOnMapUnmap
{
47 void OnMap(uptr p
, uptr size
) const {
48 RAW_CHECK_MSG(0, "Unexpected mmap in InternalAllocator!\n");
50 void OnUnmap(uptr p
, uptr size
) const {
51 RAW_CHECK_MSG(0, "Unexpected munmap in InternalAllocator!\n");
55 typedef CombinedAllocator
<PrimaryInternalAllocator
, InternalAllocatorCache
,
56 LargeMmapAllocator
<CrashOnMapUnmap
> >
59 void *InternalAlloc(uptr size
, InternalAllocatorCache
*cache
= 0);
60 void InternalFree(void *p
, InternalAllocatorCache
*cache
= 0);
61 InternalAllocator
*internal_allocator();
63 } // namespace __sanitizer
65 #endif // SANITIZER_ALLOCATOR_INTERNAL_H