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 // The list above enumerates the platforms that BoringSSL supports. For these 59 // platforms we keep a reasonable bar of not breaking them: automated test 60 // coverage, for one, but also we need access to these types for machines for 61 // fixing them. 62 // 63 // However, we know that anything that seems to work will soon be expected 64 // to work and, quickly, the implicit expectation is that every machine will 65 // always work. So this list serves to mark the boundary of what we guarantee. 66 // Of course, you can run the code any many more machines, but then you're 67 // taking on the burden of fixing it and, if you're doing that, then you must 68 // be able to carry local patches. In which case patching this list is trivial. 69 // 70 // BoringSSL will only possibly work on standard 32-bit and 64-bit 71 // two's-complement, little-endian architectures. Functions will not produce 72 // the correct answer on other systems. Run the crypto_test binary, notably 73 // crypto/compiler_test.cc, before trying a new architecture. 74 #error "Unknown target CPU" 75 #endif 76 77 #if defined(__APPLE__) 78 #define OPENSSL_APPLE 79 #endif 80 81 #if defined(_WIN32) 82 #define OPENSSL_WINDOWS 83 #endif 84 85 // Trusty and Android baremetal aren't Linux but currently define __linux__. 86 // As a workaround, we exclude them here. We also exclude nanolibc. nanolibc 87 // sometimes build for a non-Linux target (which should not define __linux__), 88 // but also sometimes build for Linux. Although technically running in Linux 89 // userspace, this lacks all the libc APIs we'd normally expect on Linux, so we 90 // treat it as a non-Linux target. 91 // 92 // TODO(b/169780122): Remove this workaround once Trusty no longer defines it. 93 // TODO(b/291101350): Remove this workaround once Android baremetal no longer 94 // defines it. 95 #if defined(__linux__) && !defined(__TRUSTY__) && \ 96 !defined(ANDROID_BAREMETAL) && !defined(OPENSSL_NANOLIBC) 97 #define OPENSSL_LINUX 98 #endif 99 100 #if defined(__Fuchsia__) 101 #define OPENSSL_FUCHSIA 102 #endif 103 104 // Trusty is Android's TEE target. See 105 // https://source.android.com/docs/security/features/trusty 106 // 107 // Defining this on any other platform is not supported. Other embedded 108 // platforms must introduce their own defines. 109 #if defined(__TRUSTY__) 110 #define OPENSSL_TRUSTY 111 #define OPENSSL_NO_FILESYSTEM 112 #define OPENSSL_NO_POSIX_IO 113 #define OPENSSL_NO_SOCK 114 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED 115 #endif 116 117 // nanolibc is a particular minimal libc implementation. Defining this on any 118 // other platform is not supported. Other embedded platforms must introduce 119 // their own defines. 120 #if defined(OPENSSL_NANOLIBC) 121 #define OPENSSL_NO_FILESYSTEM 122 #define OPENSSL_NO_POSIX_IO 123 #define OPENSSL_NO_SOCK 124 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED 125 #endif 126 127 // Android baremetal is an embedded target that uses a subset of bionic. 128 // Defining this on any other platform is not supported. Other embedded 129 // platforms must introduce their own defines. 130 #if defined(ANDROID_BAREMETAL) 131 #define OPENSSL_NO_FILESYSTEM 132 #define OPENSSL_NO_POSIX_IO 133 #define OPENSSL_NO_SOCK 134 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED 135 #endif 136 137 // CROS_EC is an embedded target for ChromeOS Embedded Controller. Defining 138 // this on any other platform is not supported. Other embedded platforms must 139 // introduce their own defines. 140 // 141 // https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/README.md 142 #if defined(CROS_EC) 143 #define OPENSSL_NO_FILESYSTEM 144 #define OPENSSL_NO_POSIX_IO 145 #define OPENSSL_NO_SOCK 146 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED 147 #endif 148 149 // CROS_ZEPHYR is an embedded target for ChromeOS Zephyr Embedded Controller. 150 // Defining this on any other platform is not supported. Other embedded 151 // platforms must introduce their own defines. 152 // 153 // https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/docs/zephyr/README.md 154 #if defined(CROS_ZEPHYR) 155 #define OPENSSL_NO_FILESYSTEM 156 #define OPENSSL_NO_POSIX_IO 157 #define OPENSSL_NO_SOCK 158 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED 159 #endif 160 161 #if defined(__ANDROID_API__) 162 #define OPENSSL_ANDROID 163 #endif 164 165 #if defined(__FreeBSD__) 166 #define OPENSSL_FREEBSD 167 #endif 168 169 #if defined(__OpenBSD__) 170 #define OPENSSL_OPENBSD 171 #endif 172 173 // BoringSSL requires platform's locking APIs to make internal global state 174 // thread-safe, including the PRNG. On some single-threaded embedded platforms, 175 // locking APIs may not exist, so this dependency may be disabled with the 176 // following build flag. 177 // 178 // IMPORTANT: Doing so means the consumer promises the library will never be 179 // used in any multi-threaded context. It causes BoringSSL to be globally 180 // thread-unsafe. Setting it inappropriately will subtly and unpredictably 181 // corrupt memory and leak secret keys. 182 // 183 // Do not set this flag on any platform where threads are possible. BoringSSL 184 // maintainers will not provide support for any consumers that do so. Changes 185 // which break such unsupported configurations will not be reverted. 186 #if !defined(OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED) 187 #define OPENSSL_THREADS 188 #endif 189 190 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE) && \ 191 !defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE) 192 #define BORINGSSL_UNSAFE_DETERMINISTIC_MODE 193 #endif 194 195 #if defined(__has_feature) 196 #if __has_feature(address_sanitizer) 197 #define OPENSSL_ASAN 198 #endif 199 #if __has_feature(thread_sanitizer) 200 #define OPENSSL_TSAN 201 #endif 202 #if __has_feature(memory_sanitizer) 203 #define OPENSSL_MSAN 204 #define OPENSSL_ASM_INCOMPATIBLE 205 #endif 206 #if __has_feature(hwaddress_sanitizer) 207 #define OPENSSL_HWASAN 208 #endif 209 #endif 210 211 #if defined(OPENSSL_ASM_INCOMPATIBLE) 212 #undef OPENSSL_ASM_INCOMPATIBLE 213 #if !defined(OPENSSL_NO_ASM) 214 #define OPENSSL_NO_ASM 215 #endif 216 #endif // OPENSSL_ASM_INCOMPATIBLE 217 218 #endif // OPENSSL_HEADER_TARGET_H 219