sanitizer_allocator_internal.h revision 1.1.1.5
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//===----------------------------------------------------------------------===//
11
12#ifndef SANITIZER_ALLOCATOR_INTERNAL_H
13#define SANITIZER_ALLOCATOR_INTERNAL_H
14
15#include "sanitizer_allocator.h"
16#include "sanitizer_internal_defs.h"
17
18namespace __sanitizer {
19
20// FIXME: Check if we may use even more compact size class map for internal
21// purposes.
22typedef CompactSizeClassMap InternalSizeClassMap;
23
24static const uptr kInternalAllocatorSpace = 0;
25static const u64 kInternalAllocatorSize = SANITIZER_MMAP_RANGE_SIZE;
26static const uptr kInternalAllocatorRegionSizeLog = 20;
27#if SANITIZER_WORDSIZE == 32
28static const uptr kInternalAllocatorNumRegions =
29    kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
30typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
31#else
32static const uptr kInternalAllocatorNumRegions =
33    kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
34typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
35#endif
36typedef SizeClassAllocator32<
37    kInternalAllocatorSpace, kInternalAllocatorSize, 0, InternalSizeClassMap,
38    kInternalAllocatorRegionSizeLog, ByteMap> PrimaryInternalAllocator;
39
40typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
41    InternalAllocatorCache;
42
43typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
44                          LargeMmapAllocator<> > InternalAllocator;
45
46void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr,
47                    uptr alignment = 0);
48void *InternalRealloc(void *p, uptr size,
49                      InternalAllocatorCache *cache = nullptr);
50void *InternalCalloc(uptr countr, uptr size,
51                     InternalAllocatorCache *cache = nullptr);
52void InternalFree(void *p, InternalAllocatorCache *cache = nullptr);
53InternalAllocator *internal_allocator();
54
55enum InternalAllocEnum {
56  INTERNAL_ALLOC
57};
58
59} // namespace __sanitizer
60
61inline void *operator new(__sanitizer::operator_new_size_type size,
62                          __sanitizer::InternalAllocEnum) {
63  return __sanitizer::InternalAlloc(size);
64}
65
66#endif // SANITIZER_ALLOCATOR_INTERNAL_H
67