David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2023, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | #ifndef OPENSSL_HEADER_TARGET_H |
| 16 | #define OPENSSL_HEADER_TARGET_H |
| 17 | |
| 18 | // Preprocessor symbols that define the target platform. |
| 19 | // |
| 20 | // This file may be included in C, C++, and assembler and must be compatible |
| 21 | // with each environment. It is separated out only to share code between |
| 22 | // <openssl/base.h> and <openssl/asm_base.h>. Prefer to include those headers |
| 23 | // instead. |
| 24 | |
| 25 | #if defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) |
| 26 | #define OPENSSL_64_BIT |
| 27 | #define OPENSSL_X86_64 |
| 28 | #elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86) |
| 29 | #define OPENSSL_32_BIT |
| 30 | #define OPENSSL_X86 |
| 31 | #elif defined(__AARCH64EL__) || defined(_M_ARM64) |
| 32 | #define OPENSSL_64_BIT |
| 33 | #define OPENSSL_AARCH64 |
| 34 | #elif defined(__ARMEL__) || defined(_M_ARM) |
| 35 | #define OPENSSL_32_BIT |
| 36 | #define OPENSSL_ARM |
| 37 | #elif defined(__MIPSEL__) && !defined(__LP64__) |
| 38 | #define OPENSSL_32_BIT |
| 39 | #define OPENSSL_MIPS |
| 40 | #elif defined(__MIPSEL__) && defined(__LP64__) |
| 41 | #define OPENSSL_64_BIT |
| 42 | #define OPENSSL_MIPS64 |
| 43 | #elif defined(__riscv) && __SIZEOF_POINTER__ == 8 |
| 44 | #define OPENSSL_64_BIT |
| 45 | #define OPENSSL_RISCV64 |
| 46 | #elif defined(__riscv) && __SIZEOF_POINTER__ == 4 |
| 47 | #define OPENSSL_32_BIT |
| 48 | #elif defined(__pnacl__) |
| 49 | #define OPENSSL_32_BIT |
| 50 | #define OPENSSL_PNACL |
| 51 | #elif defined(__wasm__) |
| 52 | #define OPENSSL_32_BIT |
| 53 | #elif defined(__asmjs__) |
| 54 | #define OPENSSL_32_BIT |
| 55 | #elif defined(__myriad2__) |
| 56 | #define OPENSSL_32_BIT |
| 57 | #else |
| 58 | // Note BoringSSL only supports standard 32-bit and 64-bit two's-complement, |
| 59 | // little-endian architectures. Functions will not produce the correct answer |
| 60 | // on other systems. Run the crypto_test binary, notably |
| 61 | // crypto/compiler_test.cc, before adding a new architecture. |
| 62 | #error "Unknown target CPU" |
| 63 | #endif |
| 64 | |
| 65 | #if defined(__APPLE__) |
| 66 | #define OPENSSL_APPLE |
| 67 | #endif |
| 68 | |
| 69 | #if defined(_WIN32) |
| 70 | #define OPENSSL_WINDOWS |
| 71 | #endif |
| 72 | |
David Benjamin | 5ba5db1 | 2023-07-14 16:30:43 -0400 | [diff] [blame] | 73 | // Trusty and Android baremetal aren't't Linux but currently define __linux__. |
| 74 | // As a workaround, we exclude them here. |
| 75 | // |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 76 | // TODO(b/169780122): Remove this workaround once Trusty no longer defines it. |
David Benjamin | 5ba5db1 | 2023-07-14 16:30:43 -0400 | [diff] [blame] | 77 | // TODO(b/291101350): Remove this workaround once Android baremetal no longer |
| 78 | // defines it. |
| 79 | #if defined(__linux__) && !defined(__TRUSTY__) && !defined(ANDROID_BAREMETAL) |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 80 | #define OPENSSL_LINUX |
| 81 | #endif |
| 82 | |
| 83 | #if defined(__Fuchsia__) |
| 84 | #define OPENSSL_FUCHSIA |
| 85 | #endif |
| 86 | |
David Benjamin | 2ff3a6b | 2023-07-13 14:25:01 -0400 | [diff] [blame] | 87 | // Trusty is Android's TEE target. See |
| 88 | // https://source.android.com/docs/security/features/trusty |
| 89 | // |
| 90 | // Defining this on any other platform is not supported. Other embedded |
| 91 | // platforms must introduce their own defines. |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 92 | #if defined(__TRUSTY__) |
| 93 | #define OPENSSL_TRUSTY |
David Benjamin | 5ba5db1 | 2023-07-14 16:30:43 -0400 | [diff] [blame] | 94 | #define OPENSSL_NO_FILESYSTEM |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 95 | #define OPENSSL_NO_POSIX_IO |
| 96 | #define OPENSSL_NO_SOCK |
| 97 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 98 | #endif |
| 99 | |
David Benjamin | 2ff3a6b | 2023-07-13 14:25:01 -0400 | [diff] [blame] | 100 | // nanolibc is a particular minimal libc implementation. Defining this on any |
| 101 | // other platform is not supported. Other embedded platforms must introduce |
| 102 | // their own defines. |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 103 | #if defined(OPENSSL_NANOLIBC) |
David Benjamin | 5ba5db1 | 2023-07-14 16:30:43 -0400 | [diff] [blame] | 104 | #define OPENSSL_NO_FILESYSTEM |
| 105 | #define OPENSSL_NO_POSIX_IO |
| 106 | #define OPENSSL_NO_SOCK |
| 107 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 108 | #endif |
| 109 | |
| 110 | // Android baremetal is an embedded target that uses a subset of bionic. |
| 111 | // Defining this on any other platform is not supported. Other embedded |
| 112 | // platforms must introduce their own defines. |
| 113 | #if defined(ANDROID_BAREMETAL) |
| 114 | #define OPENSSL_NO_FILESYSTEM |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 115 | #define OPENSSL_NO_POSIX_IO |
| 116 | #define OPENSSL_NO_SOCK |
| 117 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 118 | #endif |
| 119 | |
Yi Chou | 58adb8e | 2023-07-20 21:46:32 +0800 | [diff] [blame] | 120 | // CROS_EC is an embedded target for ChromeOS Embedded Controller. Defining |
| 121 | // this on any other platform is not supported. Other embedded platforms must |
| 122 | // introduce their own defines. |
| 123 | // |
| 124 | // https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/README.md |
| 125 | #if defined(CROS_EC) |
| 126 | #define OPENSSL_NO_FILESYSTEM |
| 127 | #define OPENSSL_NO_POSIX_IO |
| 128 | #define OPENSSL_NO_SOCK |
| 129 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 130 | #endif |
| 131 | |
| 132 | // CROS_ZEPHYR is an embedded target for ChromeOS Zephyr Embedded Controller. |
| 133 | // Defining this on any other platform is not supported. Other embedded |
| 134 | // platforms must introduce their own defines. |
| 135 | // |
| 136 | // https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/docs/zephyr/README.md |
| 137 | #if defined(CROS_ZEPHYR) |
| 138 | #define OPENSSL_NO_FILESYSTEM |
| 139 | #define OPENSSL_NO_POSIX_IO |
| 140 | #define OPENSSL_NO_SOCK |
| 141 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 142 | #endif |
| 143 | |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 144 | #if defined(__ANDROID_API__) |
| 145 | #define OPENSSL_ANDROID |
| 146 | #endif |
| 147 | |
| 148 | #if defined(__FreeBSD__) |
| 149 | #define OPENSSL_FREEBSD |
| 150 | #endif |
| 151 | |
| 152 | #if defined(__OpenBSD__) |
| 153 | #define OPENSSL_OPENBSD |
| 154 | #endif |
| 155 | |
| 156 | // BoringSSL requires platform's locking APIs to make internal global state |
| 157 | // thread-safe, including the PRNG. On some single-threaded embedded platforms, |
| 158 | // locking APIs may not exist, so this dependency may be disabled with the |
| 159 | // following build flag. |
| 160 | // |
| 161 | // IMPORTANT: Doing so means the consumer promises the library will never be |
| 162 | // used in any multi-threaded context. It causes BoringSSL to be globally |
| 163 | // thread-unsafe. Setting it inappropriately will subtly and unpredictably |
| 164 | // corrupt memory and leak secret keys. |
| 165 | // |
| 166 | // Do not set this flag on any platform where threads are possible. BoringSSL |
| 167 | // maintainers will not provide support for any consumers that do so. Changes |
| 168 | // which break such unsupported configurations will not be reverted. |
| 169 | #if !defined(OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED) |
| 170 | #define OPENSSL_THREADS |
| 171 | #endif |
| 172 | |
| 173 | #if defined(BORINGSSL_UNSAFE_FUZZER_MODE) && \ |
| 174 | !defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 175 | #define BORINGSSL_UNSAFE_DETERMINISTIC_MODE |
| 176 | #endif |
| 177 | |
| 178 | #if defined(__has_feature) |
| 179 | #if __has_feature(address_sanitizer) |
| 180 | #define OPENSSL_ASAN |
| 181 | #endif |
| 182 | #if __has_feature(thread_sanitizer) |
| 183 | #define OPENSSL_TSAN |
| 184 | #endif |
| 185 | #if __has_feature(memory_sanitizer) |
| 186 | #define OPENSSL_MSAN |
| 187 | #define OPENSSL_ASM_INCOMPATIBLE |
| 188 | #endif |
David Benjamin | d43fef7 | 2023-07-12 20:48:55 -0400 | [diff] [blame] | 189 | #if __has_feature(hwaddress_sanitizer) |
| 190 | #define OPENSSL_HWASAN |
| 191 | #endif |
David Benjamin | a905bbb | 2023-06-12 18:11:13 -0400 | [diff] [blame] | 192 | #endif |
| 193 | |
| 194 | #if defined(OPENSSL_ASM_INCOMPATIBLE) |
| 195 | #undef OPENSSL_ASM_INCOMPATIBLE |
| 196 | #if !defined(OPENSSL_NO_ASM) |
| 197 | #define OPENSSL_NO_ASM |
| 198 | #endif |
| 199 | #endif // OPENSSL_ASM_INCOMPATIBLE |
| 200 | |
| 201 | #endif // OPENSSL_HEADER_TARGET_H |