sanitizer_allocator_internal.h revision 276789
1//===-- sanitizer_allocator_internal.h -------------------------- C++ -----===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This allocator is used inside run-times.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef SANITIZER_ALLOCATOR_INTERNAL_H
15#define SANITIZER_ALLOCATOR_INTERNAL_H
16
17#include "sanitizer_allocator.h"
18#include "sanitizer_internal_defs.h"
19
20namespace __sanitizer {
21
22// FIXME: Check if we may use even more compact size class map for internal
23// purposes.
24typedef CompactSizeClassMap InternalSizeClassMap;
25
26static const uptr kInternalAllocatorSpace = 0;
27static const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE;
28static const uptr kInternalAllocatorRegionSizeLog = 20;
29#if SANITIZER_WORDSIZE == 32
30static const uptr kInternalAllocatorNumRegions =
31    kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
32typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
33#else
34static const uptr kInternalAllocatorNumRegions =
35    kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
36typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
37#endif
38typedef SizeClassAllocator32<
39    kInternalAllocatorSpace, kInternalAllocatorSize, 0, InternalSizeClassMap,
40    kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator;
41
42typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
43    InternalAllocatorCache;
44
45typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
46                          LargeMmapAllocator<> > InternalAllocator;
47
48void *InternalAlloc(uptr size, InternalAllocatorCache *cache = 0);
49void InternalFree(void *p, InternalAllocatorCache *cache = 0);
50InternalAllocator *internal_allocator();
51
52}  // namespace __sanitizer
53
54#endif  // SANITIZER_ALLOCATOR_INTERNAL_H
55