1 //===-- scudo_platform.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Scudo platform specific definitions.
11 /// TODO(kostyak): add tests for the compile time defines.
13 //===----------------------------------------------------------------------===//
15 #ifndef SCUDO_PLATFORM_H_
16 #define SCUDO_PLATFORM_H_
18 #include "sanitizer_common/sanitizer_allocator.h"
20 #if !SANITIZER_LINUX && !SANITIZER_FUCHSIA
21 # error "The Scudo hardened allocator is not supported on this platform."
24 #define SCUDO_TSD_EXCLUSIVE_SUPPORTED (!SANITIZER_ANDROID && !SANITIZER_FUCHSIA)
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
35 # error "No default TSD model defined for this platform."
36 # endif // SANITIZER_ANDROID || SANITIZER_FUCHSIA
37 #endif // SCUDO_TSD_EXCLUSIVE
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."
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
49 # define SCUDO_SHARED_TSD_POOL_SIZE 32U
50 # endif // SANITIZER_ANDROID
51 #endif // SCUDO_SHARED_TSD_POOL_SIZE
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
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
64 # define SCUDO_CAN_USE_HOOKS 0
65 # endif // SANITIZER_FUCHSIA
66 #endif // SCUDO_CAN_USE_HOOKS
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.
76 const uptr AllocatorSize = 0x40000000000ULL; // 4T.
79 const uptr RegionSizeLog = SANITIZER_ANDROID ? 19 : 20;
80 #endif // SANITIZER_CAN_USE_ALLOCATOR64
82 #if !defined(SCUDO_SIZE_CLASS_MAP)
83 # define SCUDO_SIZE_CLASS_MAP Default
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
90 typedef SIZE_CLASS_MAP_TYPE SizeClassMap;
92 } // namespace __scudo
94 #endif // SCUDO_PLATFORM_H_