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