| 1 |
// Copyright (c) 2023, Google Inc. |
| 2 |
// SPDX-License-Identifier: ISC |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_TARGET_H |
| 5 |
#define OPENSSL_HEADER_TARGET_H |
| 6 |
|
| 7 |
// Preprocessor symbols that define the target platform. |
| 8 |
// |
| 9 |
// This file may be included in C, C++, and assembler and must be compatible |
| 10 |
// with each environment. It is separated out only to share code between |
| 11 |
// <openssl/base.h> and <openssl/asm_base.h>. Prefer to include those headers |
| 12 |
// instead. |
| 13 |
|
| 14 |
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) |
| 15 |
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 16 |
# define OPENSSL_BIG_ENDIAN |
| 17 |
# endif |
| 18 |
#elif !defined(_MSC_VER) && defined(__has_include) |
| 19 |
# if __has_include(<endian.h>) |
| 20 |
# include <endian.h> |
| 21 |
# elif __has_include(<sys/param.h>) |
| 22 |
# include <sys/param.h> |
| 23 |
# endif |
| 24 |
# if (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || \ |
| 25 |
(defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && _BYTE_ORDER == _BIG_ENDIAN) || \ |
| 26 |
(defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) |
| 27 |
# define OPENSSL_BIG_ENDIAN |
| 28 |
# endif |
| 29 |
#elif defined(_M_PPC) |
| 30 |
# define OPENSSL_BIG_ENDIAN |
| 31 |
#endif |
| 32 |
|
| 33 |
#if (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8) || defined(__LP64__) || defined(_WIN64) |
| 34 |
#define OPENSSL_64_BIT |
| 35 |
#else |
| 36 |
#define OPENSSL_32_BIT |
| 37 |
#endif |
| 38 |
|
| 39 |
#if defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) |
| 40 |
#define OPENSSL_X86_64 |
| 41 |
#elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86) |
| 42 |
#define OPENSSL_X86 |
| 43 |
#elif defined(__AARCH64EL__) || defined(_M_ARM64) |
| 44 |
#define OPENSSL_AARCH64 |
| 45 |
#elif defined(__ARMEL__) || defined(_M_ARM) |
| 46 |
#define OPENSSL_ARM |
| 47 |
#elif defined(OPENSSL_64_BIT) && (defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC) || \ |
| 48 |
defined(__PPC__) || defined(__ppc64__) || defined(__PPC64__) || defined(_ARCH_PPC64) || \ |
| 49 |
defined(__ppc64le__) || defined(__powerpc64__) || defined(_M_PPC)) |
| 50 |
# if defined(OPENSSL_BIG_ENDIAN) |
| 51 |
# define OPENSSL_PPC64BE |
| 52 |
# else |
| 53 |
# define OPENSSL_PPC64LE |
| 54 |
# endif |
| 55 |
#elif defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__PPC__) || defined(_M_PPC) |
| 56 |
# if defined(OPENSSL_BIG_ENDIAN) |
| 57 |
# define OPENSSL_PPC32BE |
| 58 |
# else |
| 59 |
# define OPENSSL_PPC32LE |
| 60 |
# endif |
| 61 |
#elif defined(__s390x__) |
| 62 |
#define OPENSSL_S390X |
| 63 |
#elif defined(__sparc__) |
| 64 |
#define OPENSSL_SPARCV9 |
| 65 |
#elif defined(__MIPSEL__) || defined(__MIPSEB__) |
| 66 |
# if defined(OPENSSL_64_BIT) |
| 67 |
# define OPENSSL_MIPS64 |
| 68 |
# else |
| 69 |
# define OPENSSL_MIPS |
| 70 |
# endif |
| 71 |
#elif defined(__riscv) |
| 72 |
# if defined(OPENSSL_64_BIT) |
| 73 |
# define OPENSSL_RISCV64 |
| 74 |
# endif |
| 75 |
#elif defined(__loongarch_lp64) || \ |
| 76 |
(defined(__loongarch__) && defined(OPENSSL_64_BIT)) |
| 77 |
#define OPENSSL_LOONGARCH64 |
| 78 |
#elif defined(__pnacl__) |
| 79 |
#define OPENSSL_PNACL |
| 80 |
#elif defined(__wasm__) |
| 81 |
#define OPENSSL_WASM |
| 82 |
#elif defined(__asmjs__) // Allowed but no macro defined |
| 83 |
#elif defined(__myriad2__) // Allowed but no macro defined |
| 84 |
#else |
| 85 |
// Run the crypto_test binary, notably crypto/compiler_test.cc, before adding |
| 86 |
// a new architecture. |
| 87 |
#error "Unknown target CPU" |
| 88 |
#endif |
| 89 |
|
| 90 |
#if defined(__APPLE__) |
| 91 |
#define OPENSSL_APPLE |
| 92 |
// Note |TARGET_OS_MAC| is set for all Apple OS variants. |TARGET_OS_OSX| |
| 93 |
// targets macOS specifically. |
| 94 |
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX |
| 95 |
#define OPENSSL_MACOS |
| 96 |
#endif |
| 97 |
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
| 98 |
#define OPENSSL_IOS |
| 99 |
#endif |
| 100 |
#endif |
| 101 |
|
| 102 |
#if defined(_WIN32) |
| 103 |
#define OPENSSL_WINDOWS |
| 104 |
#endif |
| 105 |
|
| 106 |
// Android baremetal aren't Linux but currently define __linux__. |
| 107 |
// As a workaround, we exclude them here. |
| 108 |
// We also exclude nanolibc/CrOS EC/Zephyr. nanolibc/CrOS EC/Zephyr |
| 109 |
// sometimes build for a non-Linux target (which should not define __linux__), |
| 110 |
// but also sometimes build for Linux. Although technically running in Linux |
| 111 |
// userspace, this lacks all the libc APIs we'd normally expect on Linux, so we |
| 112 |
// treat it as a non-Linux target. |
| 113 |
// |
| 114 |
// TODO(b/291101350): Remove this workaround once Android baremetal no longer |
| 115 |
// defines it. |
| 116 |
#if defined(__linux__) && \ |
| 117 |
!defined(ANDROID_BAREMETAL) && !defined(OPENSSL_NANOLIBC) && \ |
| 118 |
!defined(CROS_EC) && !defined(CROS_ZEPHYR) |
| 119 |
#define OPENSSL_LINUX |
| 120 |
#endif |
| 121 |
|
| 122 |
// nanolibc is a particular minimal libc implementation. Defining this on any |
| 123 |
// other platform is not supported. Other embedded platforms must introduce |
| 124 |
// their own defines. |
| 125 |
#if defined(OPENSSL_NANOLIBC) |
| 126 |
#define OPENSSL_NO_FILESYSTEM |
| 127 |
#define OPENSSL_NO_POSIX_IO |
| 128 |
#define OPENSSL_NO_SOCK |
| 129 |
#define OPENSSL_NO_TTY |
| 130 |
#define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 131 |
#endif |
| 132 |
|
| 133 |
// Android baremetal is an embedded target that uses a subset of bionic. |
| 134 |
// Defining this on any other platform is not supported. Other embedded |
| 135 |
// platforms must introduce their own defines. |
| 136 |
#if defined(ANDROID_BAREMETAL) |
| 137 |
#define OPENSSL_NO_FILESYSTEM |
| 138 |
#define OPENSSL_NO_POSIX_IO |
| 139 |
#define OPENSSL_NO_SOCK |
| 140 |
#define OPENSSL_NO_TTY |
| 141 |
#define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 142 |
#endif |
| 143 |
|
| 144 |
// CROS_EC is an embedded target for ChromeOS Embedded Controller. Defining |
| 145 |
// this on any other platform is not supported. Other embedded platforms must |
| 146 |
// introduce their own defines. |
| 147 |
// |
| 148 |
// https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/README.md |
| 149 |
#if defined(CROS_EC) |
| 150 |
#define OPENSSL_NO_FILESYSTEM |
| 151 |
#define OPENSSL_NO_POSIX_IO |
| 152 |
#define OPENSSL_NO_SOCK |
| 153 |
#define OPENSSL_NO_TTY |
| 154 |
#define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 155 |
#endif |
| 156 |
|
| 157 |
// CROS_ZEPHYR is an embedded target for ChromeOS Zephyr Embedded Controller. |
| 158 |
// Defining this on any other platform is not supported. Other embedded |
| 159 |
// platforms must introduce their own defines. |
| 160 |
// |
| 161 |
// https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/docs/zephyr/README.md |
| 162 |
#if defined(CROS_ZEPHYR) |
| 163 |
#define OPENSSL_NO_FILESYSTEM |
| 164 |
#define OPENSSL_NO_POSIX_IO |
| 165 |
#define OPENSSL_NO_SOCK |
| 166 |
#define OPENSSL_NO_TTY |
| 167 |
#define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 168 |
#endif |
| 169 |
|
| 170 |
#if defined(__ANDROID_API__) |
| 171 |
#define OPENSSL_ANDROID |
| 172 |
#endif |
| 173 |
|
| 174 |
#if defined(__FreeBSD__) |
| 175 |
#define OPENSSL_FREEBSD |
| 176 |
#endif |
| 177 |
|
| 178 |
#if defined(__OpenBSD__) |
| 179 |
#define OPENSSL_OPENBSD |
| 180 |
#endif |
| 181 |
|
| 182 |
#if defined(__NetBSD__) |
| 183 |
#define OPENSSL_NETBSD |
| 184 |
#endif |
| 185 |
|
| 186 |
#if defined(__illumos__) || (defined(__sun) && defined(__SVR4)) |
| 187 |
#define OPENSSL_SOLARIS |
| 188 |
#endif |
| 189 |
|
| 190 |
// BoringSSL requires platform's locking APIs to make internal global state |
| 191 |
// thread-safe, including the PRNG. On some single-threaded embedded platforms, |
| 192 |
// locking APIs may not exist, so this dependency may be disabled with the |
| 193 |
// following build flag. |
| 194 |
// |
| 195 |
// IMPORTANT: Doing so means the consumer promises the library will never be |
| 196 |
// used in any multi-threaded context. It causes BoringSSL to be globally |
| 197 |
// thread-unsafe. Setting it inappropriately will subtly and unpredictably |
| 198 |
// corrupt memory and leak secret keys. |
| 199 |
// |
| 200 |
// Do not set this flag on any platform where threads are possible. BoringSSL |
| 201 |
// maintainers will not provide support for any consumers that do so. Changes |
| 202 |
// which break such unsupported configurations will not be reverted. |
| 203 |
#if !defined(OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED) |
| 204 |
#define OPENSSL_THREADS |
| 205 |
#endif |
| 206 |
|
| 207 |
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE) && \ |
| 208 |
!defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 209 |
#define BORINGSSL_UNSAFE_DETERMINISTIC_MODE |
| 210 |
#endif |
| 211 |
|
| 212 |
#if defined(__has_feature) |
| 213 |
#if __has_feature(address_sanitizer) |
| 214 |
#define OPENSSL_ASAN |
| 215 |
#endif |
| 216 |
#if __has_feature(thread_sanitizer) |
| 217 |
#define OPENSSL_TSAN |
| 218 |
#endif |
| 219 |
#if __has_feature(memory_sanitizer) |
| 220 |
#define OPENSSL_MSAN |
| 221 |
#define OPENSSL_ASM_INCOMPATIBLE |
| 222 |
#endif |
| 223 |
#if __has_feature(hwaddress_sanitizer) |
| 224 |
#define OPENSSL_HWASAN |
| 225 |
#endif |
| 226 |
#endif |
| 227 |
|
| 228 |
// Disable 32-bit Arm assembly on Apple platforms. The last iOS version that |
| 229 |
// supported 32-bit Arm was iOS 10. |
| 230 |
#if defined(OPENSSL_APPLE) && defined(OPENSSL_ARM) |
| 231 |
#define OPENSSL_ASM_INCOMPATIBLE |
| 232 |
#endif |
| 233 |
|
| 234 |
#if defined(OPENSSL_ASM_INCOMPATIBLE) |
| 235 |
#undef OPENSSL_ASM_INCOMPATIBLE |
| 236 |
#if !defined(OPENSSL_NO_ASM) |
| 237 |
#define OPENSSL_NO_ASM |
| 238 |
#endif |
| 239 |
#endif // OPENSSL_ASM_INCOMPATIBLE |
| 240 |
|
| 241 |
#endif // OPENSSL_HEADER_TARGET_H |