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 // <ring-core/base.h> and <ring-core/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(__loongarch_lp64)
38 #define OPENSSL_64_BIT
39 #define OPENSSL_LOONGARCH64
40 #elif defined(__MIPSEL__) && !defined(__LP64__)
41 #define OPENSSL_32_BIT
42 #define OPENSSL_MIPS
43 #elif defined(__MIPSEL__) && defined(__LP64__)
44 #define OPENSSL_64_BIT
45 #define OPENSSL_MIPS64
46 #elif defined(__PPC64__) || defined(__powerpc64__)
47 #define OPENSSL_64_BIT
48 #elif (defined(__PPC__) || defined(__powerpc__)) && defined(_BIG_ENDIAN)
49 #define OPENSSL_32_BIT
50 #elif defined(__riscv) && __SIZEOF_POINTER__ == 8
51 #define OPENSSL_64_BIT
52 #define OPENSSL_RISCV64
53 #elif defined(__s390x__)
54 #define OPENSSL_64_BIT
55 #define OPENSSL_S390X
56 #elif defined(__wasm__)
57 #define OPENSSL_32_BIT
58 #else
59 // Note BoringSSL only supports standard 32-bit and 64-bit two's-complement,
60 // little-endian architectures. Functions will not produce the correct answer
61 // on other systems. Run the crypto_test binary, notably
62 // crypto/compiler_test.cc, before adding a new architecture.
63 #error "Unknown target CPU"
64 #endif
65 
66 #if defined(__APPLE__)
67 #define OPENSSL_APPLE
68 #endif
69 
70 #if defined(_WIN32)
71 #define OPENSSL_WINDOWS
72 #endif
73 
74 // Trusty isn't Linux but currently defines __linux__. As a workaround, we
75 // exclude it here.
76 // TODO(b/169780122): Remove this workaround once Trusty no longer defines it.
77 #if defined(__linux__) && !defined(__TRUSTY__)
78 #define OPENSSL_LINUX
79 #endif
80 
81 #if defined(__Fuchsia__)
82 #define OPENSSL_FUCHSIA
83 #endif
84 
85 #if defined(__TRUSTY__)
86 #define OPENSSL_TRUSTY
87 #define OPENSSL_NO_POSIX_IO
88 #define OPENSSL_NO_SOCK
89 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED
90 #endif
91 
92 #if defined(OPENSSL_NANOLIBC)
93 #define OPENSSL_NO_POSIX_IO
94 #define OPENSSL_NO_SOCK
95 #define OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED
96 #endif
97 
98 #if defined(__ANDROID_API__)
99 #define OPENSSL_ANDROID
100 #endif
101 
102 #if defined(__FreeBSD__)
103 #define OPENSSL_FREEBSD
104 #endif
105 
106 #if defined(__OpenBSD__)
107 #define OPENSSL_OPENBSD
108 #endif
109 
110 // BoringSSL requires platform's locking APIs to make internal global state
111 // thread-safe, including the PRNG. On some single-threaded embedded platforms,
112 // locking APIs may not exist, so this dependency may be disabled with the
113 // following build flag.
114 //
115 // IMPORTANT: Doing so means the consumer promises the library will never be
116 // used in any multi-threaded context. It causes BoringSSL to be globally
117 // thread-unsafe. Setting it inappropriately will subtly and unpredictably
118 // corrupt memory and leak secret keys.
119 //
120 // Do not set this flag on any platform where threads are possible. BoringSSL
121 // maintainers will not provide support for any consumers that do so. Changes
122 // which break such unsupported configurations will not be reverted.
123 #if !defined(OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED)
124 #define OPENSSL_THREADS
125 #endif
126 
127 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE) && \
128     !defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
129 #define BORINGSSL_UNSAFE_DETERMINISTIC_MODE
130 #endif
131 
132 #if defined(__has_feature)
133 #if __has_feature(address_sanitizer)
134 #define OPENSSL_ASAN
135 #endif
136 #if __has_feature(thread_sanitizer)
137 #define OPENSSL_TSAN
138 #endif
139 #if __has_feature(memory_sanitizer)
140 #define OPENSSL_MSAN
141 #define OPENSSL_ASM_INCOMPATIBLE
142 #endif
143 #if __has_feature(hwaddress_sanitizer)
144 #define OPENSSL_HWASAN
145 #endif
146 #endif
147 
148 #if defined(OPENSSL_ASM_INCOMPATIBLE)
149 #undef OPENSSL_ASM_INCOMPATIBLE
150 #if !defined(OPENSSL_NO_ASM)
151 #define OPENSSL_NO_ASM
152 #endif
153 #endif  // OPENSSL_ASM_INCOMPATIBLE
154 
155 #endif  // OPENSSL_HEADER_TARGET_H
156