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 # define SCUDO_SHARED_TSD_POOL_SIZE 32U
47 #endif // SCUDO_SHARED_TSD_POOL_SIZE
49 // The following allows the public interface functions to be disabled.
50 #ifndef SCUDO_CAN_USE_PUBLIC_INTERFACE
51 # define SCUDO_CAN_USE_PUBLIC_INTERFACE 1
56 #if SANITIZER_CAN_USE_ALLOCATOR64
57 # if defined(__aarch64__) && SANITIZER_ANDROID
58 const uptr AllocatorSize = 0x4000000000ULL; // 256G.
59 # elif defined(__aarch64__)
60 const uptr AllocatorSize = 0x10000000000ULL; // 1T.
62 const uptr AllocatorSize = 0x40000000000ULL; // 4T.
65 const uptr RegionSizeLog = SANITIZER_ANDROID ? 19 : 20;
66 #endif // SANITIZER_CAN_USE_ALLOCATOR64
68 #if !defined(SCUDO_SIZE_CLASS_MAP)
69 # define SCUDO_SIZE_CLASS_MAP Default
72 #define SIZE_CLASS_MAP_TYPE SIZE_CLASS_MAP_TYPE_(SCUDO_SIZE_CLASS_MAP)
73 #define SIZE_CLASS_MAP_TYPE_(T) SIZE_CLASS_MAP_TYPE__(T)
74 #define SIZE_CLASS_MAP_TYPE__(T) T##SizeClassMap
76 typedef SIZE_CLASS_MAP_TYPE SizeClassMap;
78 } // namespace __scudo
80 #endif // SCUDO_PLATFORM_H_