1 | //===-- 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 | #ifndef SCUDO_PLATFORM_H_ |
10 | #define SCUDO_PLATFORM_H_ |
11 | |
12 | // Transitive includes of stdint.h specify some of the defines checked below. |
13 | #include <stdint.h> |
14 | |
15 | #if defined(__linux__) && !defined(__TRUSTY__) |
16 | #define SCUDO_LINUX 1 |
17 | #else |
18 | #define SCUDO_LINUX 0 |
19 | #endif |
20 | |
21 | // See https://android.googlesource.com/platform/bionic/+/master/docs/defines.md |
22 | #if defined(__BIONIC__) |
23 | #define SCUDO_ANDROID 1 |
24 | #else |
25 | #define SCUDO_ANDROID 0 |
26 | #endif |
27 | |
28 | #if defined(__Fuchsia__) |
29 | #define SCUDO_FUCHSIA 1 |
30 | #else |
31 | #define SCUDO_FUCHSIA 0 |
32 | #endif |
33 | |
34 | #if defined(__TRUSTY__) |
35 | #define SCUDO_TRUSTY 1 |
36 | #else |
37 | #define SCUDO_TRUSTY 0 |
38 | #endif |
39 | |
40 | #if defined(__riscv) && (__riscv_xlen == 64) |
41 | #define SCUDO_RISCV64 1 |
42 | #else |
43 | #define SCUDO_RISCV64 0 |
44 | #endif |
45 | |
46 | #if defined(__LP64__) |
47 | #define SCUDO_WORDSIZE 64U |
48 | #else |
49 | #define SCUDO_WORDSIZE 32U |
50 | #endif |
51 | |
52 | #if SCUDO_WORDSIZE == 64U |
53 | #define FIRST_32_SECOND_64(a, b) (b) |
54 | #else |
55 | #define FIRST_32_SECOND_64(a, b) (a) |
56 | #endif |
57 | |
58 | #ifndef SCUDO_CAN_USE_PRIMARY64 |
59 | #define SCUDO_CAN_USE_PRIMARY64 (SCUDO_WORDSIZE == 64U) |
60 | #endif |
61 | |
62 | #ifndef SCUDO_CAN_USE_MTE |
63 | #define SCUDO_CAN_USE_MTE (SCUDO_LINUX || SCUDO_TRUSTY) |
64 | #endif |
65 | |
66 | #ifndef SCUDO_ENABLE_HOOKS |
67 | #define SCUDO_ENABLE_HOOKS 0 |
68 | #endif |
69 | |
70 | #ifndef SCUDO_MIN_ALIGNMENT_LOG |
71 | // We force malloc-type functions to be aligned to std::max_align_t, but there |
72 | // is no reason why the minimum alignment for all other functions can't be 8 |
73 | // bytes. Except obviously for applications making incorrect assumptions. |
74 | // TODO(kostyak): define SCUDO_MIN_ALIGNMENT_LOG 3 |
75 | #define SCUDO_MIN_ALIGNMENT_LOG FIRST_32_SECOND_64(3, 4) |
76 | #endif |
77 | |
78 | #if defined(__aarch64__) |
79 | #define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48) |
80 | #else |
81 | #define SCUDO_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47) |
82 | #endif |
83 | |
84 | // Older gcc have issues aligning to a constexpr, and require an integer. |
85 | // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859 among others. |
86 | #if defined(__powerpc__) || defined(__powerpc64__) |
87 | #define SCUDO_CACHE_LINE_SIZE 128 |
88 | #else |
89 | #define SCUDO_CACHE_LINE_SIZE 64 |
90 | #endif |
91 | |
92 | #define SCUDO_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12) |
93 | |
94 | #endif // SCUDO_PLATFORM_H_ |
95 | |