]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/scudo/scudo_platform.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / scudo / scudo_platform.h
1 //===-- scudo_platform.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 /// Scudo platform specific definitions.
11 /// TODO(kostyak): add tests for the compile time defines.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SCUDO_PLATFORM_H_
16 #define SCUDO_PLATFORM_H_
17
18 #include "sanitizer_common/sanitizer_allocator.h"
19
20 #if !SANITIZER_LINUX && !SANITIZER_FUCHSIA
21 # error "The Scudo hardened allocator is not supported on this platform."
22 #endif
23
24 #define SCUDO_TSD_EXCLUSIVE_SUPPORTED (!SANITIZER_ANDROID && !SANITIZER_FUCHSIA)
25
26 #ifndef SCUDO_TSD_EXCLUSIVE
27 // SCUDO_TSD_EXCLUSIVE wasn't defined, use a default TSD model for the platform.
28 # if SANITIZER_ANDROID || SANITIZER_FUCHSIA
29 // Android and Fuchsia use a pool of TSDs shared between threads.
30 #  define SCUDO_TSD_EXCLUSIVE 0
31 # elif SANITIZER_LINUX && !SANITIZER_ANDROID
32 // Non-Android Linux use an exclusive TSD per thread.
33 #  define SCUDO_TSD_EXCLUSIVE 1
34 # else
35 #  error "No default TSD model defined for this platform."
36 # endif  // SANITIZER_ANDROID || SANITIZER_FUCHSIA
37 #endif  // SCUDO_TSD_EXCLUSIVE
38
39 // If the exclusive TSD model is chosen, make sure the platform supports it.
40 #if SCUDO_TSD_EXCLUSIVE && !SCUDO_TSD_EXCLUSIVE_SUPPORTED
41 # error "The exclusive TSD model is not supported on this platform."
42 #endif
43
44 // Maximum number of TSDs that can be created for the Shared model.
45 #ifndef SCUDO_SHARED_TSD_POOL_SIZE
46 # if SANITIZER_ANDROID
47 #  define SCUDO_SHARED_TSD_POOL_SIZE 2U
48 # else
49 #  define SCUDO_SHARED_TSD_POOL_SIZE 32U
50 # endif  // SANITIZER_ANDROID
51 #endif  // SCUDO_SHARED_TSD_POOL_SIZE
52
53 // The following allows the public interface functions to be disabled.
54 #ifndef SCUDO_CAN_USE_PUBLIC_INTERFACE
55 # define SCUDO_CAN_USE_PUBLIC_INTERFACE 1
56 #endif
57
58 // Hooks in the allocation & deallocation paths can become a security concern if
59 // implemented improperly, or if overwritten by an attacker. Use with caution.
60 #ifndef SCUDO_CAN_USE_HOOKS
61 # if SANITIZER_FUCHSIA
62 #  define SCUDO_CAN_USE_HOOKS 1
63 # else
64 #  define SCUDO_CAN_USE_HOOKS 0
65 # endif  // SANITIZER_FUCHSIA
66 #endif  // SCUDO_CAN_USE_HOOKS
67
68 namespace __scudo {
69
70 #if SANITIZER_CAN_USE_ALLOCATOR64
71 # if defined(__aarch64__) && SANITIZER_ANDROID
72 const uptr AllocatorSize = 0x4000000000ULL;  // 256G.
73 # elif defined(__aarch64__)
74 const uptr AllocatorSize = 0x10000000000ULL;  // 1T.
75 # else
76 const uptr AllocatorSize = 0x40000000000ULL;  // 4T.
77 # endif
78 #else
79 const uptr RegionSizeLog = SANITIZER_ANDROID ? 19 : 20;
80 #endif  // SANITIZER_CAN_USE_ALLOCATOR64
81
82 #if !defined(SCUDO_SIZE_CLASS_MAP)
83 # define SCUDO_SIZE_CLASS_MAP Default
84 #endif
85
86 #define SIZE_CLASS_MAP_TYPE SIZE_CLASS_MAP_TYPE_(SCUDO_SIZE_CLASS_MAP)
87 #define SIZE_CLASS_MAP_TYPE_(T) SIZE_CLASS_MAP_TYPE__(T)
88 #define SIZE_CLASS_MAP_TYPE__(T) T##SizeClassMap
89
90 typedef SIZE_CLASS_MAP_TYPE SizeClassMap;
91
92 }  // namespace __scudo
93
94 #endif // SCUDO_PLATFORM_H_