scudo_platform.h revision 326943
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# define SCUDO_SHARED_TSD_POOL_SIZE 32U
47#endif  // SCUDO_SHARED_TSD_POOL_SIZE
48
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
52#endif
53
54namespace __scudo {
55
56#if SANITIZER_CAN_USE_ALLOCATOR64
57# if defined(__aarch64__) && SANITIZER_ANDROID
58const uptr AllocatorSize = 0x4000000000ULL;  // 256G.
59# elif defined(__aarch64__)
60const uptr AllocatorSize = 0x10000000000ULL;  // 1T.
61# else
62const uptr AllocatorSize = 0x40000000000ULL;  // 4T.
63# endif
64#else
65const uptr RegionSizeLog = SANITIZER_ANDROID ? 19 : 20;
66#endif  // SANITIZER_CAN_USE_ALLOCATOR64
67
68#if !defined(SCUDO_SIZE_CLASS_MAP)
69# define SCUDO_SIZE_CLASS_MAP Default
70#endif
71
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
75
76typedef SIZE_CLASS_MAP_TYPE SizeClassMap;
77
78}  // namespace __scudo
79
80#endif // SCUDO_PLATFORM_H_
81