| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 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. |
| 87 | // We also exclude nanolibc/CrOS EC. nanolibc/CrOS EC sometimes build for a |
| 88 | // non-Linux target (which should not define __linux__), but also sometimes |
| 89 | // build for Linux. Although technically running in Linux userspace, this lacks |
| 90 | // all the libc APIs we'd normally expect on Linux, so we treat it as a |
| 91 | // non-Linux target. |
| 92 | // |
| 93 | // TODO(b/169780122): Remove this workaround once Trusty no longer defines it. |
| 94 | // TODO(b/291101350): Remove this workaround once Android baremetal no longer |
| 95 | // defines it. |
| 96 | #if defined(__linux__) && !defined(__TRUSTY__) && \ |
| 97 | !defined(ANDROID_BAREMETAL) && !defined(OPENSSL_NANOLIBC) && \ |
| 98 | !defined(CROS_EC) |
| 99 | #define OPENSSL_LINUX |
| 100 | #endif |
| 101 |
| 102 | #if defined(__Fuchsia__) |
| 103 | #define OPENSSL_FUCHSIA |
| 104 | #endif |
| 105 |
| 106 | // Trusty is Android's TEE target. See |
| 107 | // https://source.android.com/docs/security/features/trusty |
| 108 | // |
| 109 | // Defining this on any other platform is not supported. Other embedded |
| 110 | // platforms must introduce their own defines. |
| 111 | #if defined(__TRUSTY__) |
| 112 | #define OPENSSL_TRUSTY |
| 113 | #define OPENSSL_NO_FILESYSTEM |
| 114 | #define OPENSSL_NO_POSIX_IO |
| 115 | #define OPENSSL_NO_SOCK |
| 116 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 117 | #endif |
| 118 |
| 119 | // nanolibc is a particular minimal libc implementation. Defining this on any |
| 120 | // other platform is not supported. Other embedded platforms must introduce |
| 121 | // their own defines. |
| 122 | #if defined(OPENSSL_NANOLIBC) |
| 123 | #define OPENSSL_NO_FILESYSTEM |
| 124 | #define OPENSSL_NO_POSIX_IO |
| 125 | #define OPENSSL_NO_SOCK |
| 126 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 127 | #endif |
| 128 |
| 129 | // Android baremetal is an embedded target that uses a subset of bionic. |
| 130 | // Defining this on any other platform is not supported. Other embedded |
| 131 | // platforms must introduce their own defines. |
| 132 | #if defined(ANDROID_BAREMETAL) |
| 133 | #define OPENSSL_NO_FILESYSTEM |
| 134 | #define OPENSSL_NO_POSIX_IO |
| 135 | #define OPENSSL_NO_SOCK |
| 136 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 137 | #endif |
| 138 |
| 139 | // CROS_EC is an embedded target for ChromeOS Embedded Controller. Defining |
| 140 | // this on any other platform is not supported. Other embedded platforms must |
| 141 | // introduce their own defines. |
| 142 | // |
| 143 | // https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/README.md |
| 144 | #if defined(CROS_EC) |
| 145 | #define OPENSSL_NO_FILESYSTEM |
| 146 | #define OPENSSL_NO_POSIX_IO |
| 147 | #define OPENSSL_NO_SOCK |
| 148 | #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED |
| 149 | #endif |
| 150 |
| 151 | // Zephyr is an open source RTOS, optimized for embedded devices. |
| 152 | // Defining this on any other platform is not supported. Other embedded |
| 153 | // platforms must introduce their own defines. |
| 154 | // |
| 155 | // Zephyr supports multithreading with cooperative and preemptive scheduling. |
| 156 | // It also implements POSIX Threads (pthread) API, so it's not necessary to |
| 157 | // implement BoringSSL internal threading API using some custom API. |
| 158 | // |
| 159 | // https://www.zephyrproject.org/ |
| 160 | #if defined(__ZEPHYR__) |
| 161 | #define OPENSSL_NO_FILESYSTEM |
| 162 | #define OPENSSL_NO_POSIX_IO |
| 163 | #define OPENSSL_NO_SOCK |
| 164 | #endif |
| 165 |
| 166 | #if defined(__ANDROID_API__) |
| 167 | #define OPENSSL_ANDROID |
| 168 | #endif |
| 169 |
| 170 | #if defined(__FreeBSD__) |
| 171 | #define OPENSSL_FREEBSD |
| 172 | #endif |
| 173 |
| 174 | #if defined(__OpenBSD__) |
| 175 | #define OPENSSL_OPENBSD |
| 176 | #endif |
| 177 |
| 178 | // BoringSSL requires platform's locking APIs to make internal global state |
| 179 | // thread-safe, including the PRNG. On some single-threaded embedded platforms, |
| 180 | // locking APIs may not exist, so this dependency may be disabled with the |
| 181 | // following build flag. |
| 182 | // |
| 183 | // IMPORTANT: Doing so means the consumer promises the library will never be |
| 184 | // used in any multi-threaded context. It causes BoringSSL to be globally |
| 185 | // thread-unsafe. Setting it inappropriately will subtly and unpredictably |
| 186 | // corrupt memory and leak secret keys. |
| 187 | // |
| 188 | // Do not set this flag on any platform where threads are possible. BoringSSL |
| 189 | // maintainers will not provide support for any consumers that do so. Changes |
| 190 | // which break such unsupported configurations will not be reverted. |
| 191 | #if !defined(OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED) |
| 192 | #define OPENSSL_THREADS |
| 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 | // Disable 32-bit Arm assembly on Apple platforms. The last iOS version that |
| 212 | // supported 32-bit Arm was iOS 10. |
| 213 | #if defined(OPENSSL_APPLE) && defined(OPENSSL_ARM) |
| 214 | #define OPENSSL_ASM_INCOMPATIBLE |
| 215 | #endif |
| 216 |
| 217 | #if defined(OPENSSL_ASM_INCOMPATIBLE) |
| 218 | #undef OPENSSL_ASM_INCOMPATIBLE |
| 219 | #if !defined(OPENSSL_NO_ASM) |
| 220 | #define OPENSSL_NO_ASM |
| 221 | #endif |
| 222 | #endif // OPENSSL_ASM_INCOMPATIBLE |
| 223 |
| 224 | // We do not detect any features at runtime on several 32-bit Arm platforms. |
| 225 | // Apple platforms and OpenBSD require NEON and moved to 64-bit to pick up Armv8 |
| 226 | // extensions. Android baremetal does not aim to support 32-bit Arm at all, but |
| 227 | // it simplifies things to make it build. |
| 228 | #if defined(OPENSSL_ARM) && !defined(OPENSSL_STATIC_ARMCAP) && \ |
| 229 | (defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD) || \ |
| 230 | defined(ANDROID_BAREMETAL)) |
| 231 | #define OPENSSL_STATIC_ARMCAP |
| 232 | #endif |
| 233 |
| 234 | #endif // OPENSSL_HEADER_TARGET_H |
| 235 |