blob: 5b24bfdafa36167342b4944e250ef9433a14169d [file] [log] [blame]
Alexey Samsonov1f3c2fe2013-05-29 09:15:39 +00001//===-- 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
Alexey Samsonov616659a2013-05-29 09:40:07 +000022// FIXME: Check if we may use even more compact size class map for internal
Alexey Samsonov1f3c2fe2013-05-29 09:15:39 +000023// purposes.
24typedef CompactSizeClassMap InternalSizeClassMap;
25
26static const uptr kInternalAllocatorSpace = 0;
27#if SANITIZER_WORDSIZE == 32
28static const u64 kInternalAllocatorSize = (1ULL << 32);
29static const uptr kInternalAllocatorRegionSizeLog = 20;
30#else
31static const u64 kInternalAllocatorSize = (1ULL << 47);
32static const uptr kInternalAllocatorRegionSizeLog = 24;
33#endif
34static const uptr kInternalAllocatorFlatByteMapSize =
35 kInternalAllocatorSize >> kInternalAllocatorRegionSizeLog;
36typedef SizeClassAllocator32<
37 kInternalAllocatorSpace, kInternalAllocatorSize, 16, InternalSizeClassMap,
38 kInternalAllocatorRegionSizeLog,
39 FlatByteMap<kInternalAllocatorFlatByteMapSize> > PrimaryInternalAllocator;
40
41typedef SizeClassAllocatorLocalCache<PrimaryInternalAllocator>
42 InternalAllocatorCache;
43
44// We don't want our internal allocator to do any map/unmap operations.
45struct CrashOnMapUnmap {
46 void OnMap(uptr p, uptr size) const {
Alexey Samsonov845abaf2013-05-29 10:41:53 +000047 RAW_CHECK_MSG(0, "Unexpected mmap in InternalAllocator!");
Alexey Samsonov1f3c2fe2013-05-29 09:15:39 +000048 }
49 void OnUnmap(uptr p, uptr size) const {
Alexey Samsonov845abaf2013-05-29 10:41:53 +000050 RAW_CHECK_MSG(0, "Unexpected munmap in InternalAllocator!");
Alexey Samsonov1f3c2fe2013-05-29 09:15:39 +000051 }
52};
53
54typedef CombinedAllocator<PrimaryInternalAllocator, InternalAllocatorCache,
55 LargeMmapAllocator<CrashOnMapUnmap> >
56 InternalAllocator;
57
58void *InternalAlloc(uptr size, InternalAllocatorCache *cache = 0);
59void InternalFree(void *p, InternalAllocatorCache *cache = 0);
60InternalAllocator *internal_allocator();
61
62} // namespace __sanitizer
63
64#endif // SANITIZER_ALLOCATOR_INTERNAL_H