Go to the documentation of this file.
15 #ifndef OPENSSL_HEADER_ABI_TEST_H
16 #define OPENSSL_HEADER_ABI_TEST_H
18 #include <gtest/gtest.h>
21 #include <type_traits>
26 #include "../internal.h"
61 #if defined(OPENSSL_X86_64)
66 #if defined(OPENSSL_WINDOWS)
67 #define LOOP_CALLER_STATE_REGISTERS() \
68 CALLER_STATE_REGISTER(uint64_t, rbx) \
69 CALLER_STATE_REGISTER(uint64_t, rbp) \
70 CALLER_STATE_REGISTER(uint64_t, rdi) \
71 CALLER_STATE_REGISTER(uint64_t, rsi) \
72 CALLER_STATE_REGISTER(uint64_t, r12) \
73 CALLER_STATE_REGISTER(uint64_t, r13) \
74 CALLER_STATE_REGISTER(uint64_t, r14) \
75 CALLER_STATE_REGISTER(uint64_t, r15) \
76 CALLER_STATE_REGISTER(Reg128, xmm6) \
77 CALLER_STATE_REGISTER(Reg128, xmm7) \
78 CALLER_STATE_REGISTER(Reg128, xmm8) \
79 CALLER_STATE_REGISTER(Reg128, xmm9) \
80 CALLER_STATE_REGISTER(Reg128, xmm10) \
81 CALLER_STATE_REGISTER(Reg128, xmm11) \
82 CALLER_STATE_REGISTER(Reg128, xmm12) \
83 CALLER_STATE_REGISTER(Reg128, xmm13) \
84 CALLER_STATE_REGISTER(Reg128, xmm14) \
85 CALLER_STATE_REGISTER(Reg128, xmm15)
87 #define LOOP_CALLER_STATE_REGISTERS() \
88 CALLER_STATE_REGISTER(uint64_t, rbx) \
89 CALLER_STATE_REGISTER(uint64_t, rbp) \
90 CALLER_STATE_REGISTER(uint64_t, r12) \
91 CALLER_STATE_REGISTER(uint64_t, r13) \
92 CALLER_STATE_REGISTER(uint64_t, r14) \
93 CALLER_STATE_REGISTER(uint64_t, r15)
94 #endif // OPENSSL_WINDOWS
96 #elif defined(OPENSSL_X86)
101 #define LOOP_CALLER_STATE_REGISTERS() \
102 CALLER_STATE_REGISTER(uint32_t, esi) \
103 CALLER_STATE_REGISTER(uint32_t, edi) \
104 CALLER_STATE_REGISTER(uint32_t, ebx) \
105 CALLER_STATE_REGISTER(uint32_t, ebp)
107 #elif defined(OPENSSL_ARM)
118 #define LOOP_CALLER_STATE_REGISTERS_PRE_R9() \
119 CALLER_STATE_REGISTER(uint64_t, d8) \
120 CALLER_STATE_REGISTER(uint64_t, d9) \
121 CALLER_STATE_REGISTER(uint64_t, d10) \
122 CALLER_STATE_REGISTER(uint64_t, d11) \
123 CALLER_STATE_REGISTER(uint64_t, d12) \
124 CALLER_STATE_REGISTER(uint64_t, d13) \
125 CALLER_STATE_REGISTER(uint64_t, d14) \
126 CALLER_STATE_REGISTER(uint64_t, d15) \
127 CALLER_STATE_REGISTER(uint32_t, r4) \
128 CALLER_STATE_REGISTER(uint32_t, r5) \
129 CALLER_STATE_REGISTER(uint32_t, r6) \
130 CALLER_STATE_REGISTER(uint32_t, r7) \
131 CALLER_STATE_REGISTER(uint32_t, r8)
132 #define LOOP_CALLER_STATE_REGISTERS_POST_R9() \
133 CALLER_STATE_REGISTER(uint32_t, r10) \
134 CALLER_STATE_REGISTER(uint32_t, r11)
135 #if defined(OPENSSL_APPLE)
136 #define LOOP_CALLER_STATE_REGISTERS() \
137 LOOP_CALLER_STATE_REGISTERS_PRE_R9() \
138 LOOP_CALLER_STATE_REGISTERS_POST_R9()
139 #else // !OPENSSL_APPLE
140 #define LOOP_CALLER_STATE_REGISTERS() \
141 LOOP_CALLER_STATE_REGISTERS_PRE_R9() \
142 CALLER_STATE_REGISTER(uint32_t, r9) \
143 LOOP_CALLER_STATE_REGISTERS_POST_R9()
144 #endif // OPENSSL_APPLE
146 #elif defined(OPENSSL_AARCH64)
157 #define LOOP_CALLER_STATE_REGISTERS() \
160 CALLER_STATE_REGISTER(uint64_t, d8) \
161 CALLER_STATE_REGISTER(uint64_t, d9) \
162 CALLER_STATE_REGISTER(uint64_t, d10) \
163 CALLER_STATE_REGISTER(uint64_t, d11) \
164 CALLER_STATE_REGISTER(uint64_t, d12) \
165 CALLER_STATE_REGISTER(uint64_t, d13) \
166 CALLER_STATE_REGISTER(uint64_t, d14) \
167 CALLER_STATE_REGISTER(uint64_t, d15) \
170 CALLER_STATE_REGISTER(uint64_t, x19) \
171 CALLER_STATE_REGISTER(uint64_t, x20) \
172 CALLER_STATE_REGISTER(uint64_t, x21) \
173 CALLER_STATE_REGISTER(uint64_t, x22) \
174 CALLER_STATE_REGISTER(uint64_t, x23) \
175 CALLER_STATE_REGISTER(uint64_t, x24) \
176 CALLER_STATE_REGISTER(uint64_t, x25) \
177 CALLER_STATE_REGISTER(uint64_t, x26) \
178 CALLER_STATE_REGISTER(uint64_t, x27) \
179 CALLER_STATE_REGISTER(uint64_t, x28) \
180 CALLER_STATE_REGISTER(uint64_t, x29)
182 #elif defined(OPENSSL_PPC64LE)
187 bool operator==(CRReg
r)
const {
return masked() ==
r.masked(); }
188 bool operator!=(CRReg
r)
const {
return masked() !=
r.masked(); }
202 #define LOOP_CALLER_STATE_REGISTERS() \
203 CALLER_STATE_REGISTER(Reg128, v20) \
204 CALLER_STATE_REGISTER(Reg128, v21) \
205 CALLER_STATE_REGISTER(Reg128, v22) \
206 CALLER_STATE_REGISTER(Reg128, v23) \
207 CALLER_STATE_REGISTER(Reg128, v24) \
208 CALLER_STATE_REGISTER(Reg128, v25) \
209 CALLER_STATE_REGISTER(Reg128, v26) \
210 CALLER_STATE_REGISTER(Reg128, v27) \
211 CALLER_STATE_REGISTER(Reg128, v28) \
212 CALLER_STATE_REGISTER(Reg128, v29) \
213 CALLER_STATE_REGISTER(Reg128, v30) \
214 CALLER_STATE_REGISTER(Reg128, v31) \
215 CALLER_STATE_REGISTER(uint64_t, r14) \
216 CALLER_STATE_REGISTER(uint64_t, r15) \
217 CALLER_STATE_REGISTER(uint64_t, r16) \
218 CALLER_STATE_REGISTER(uint64_t, r17) \
219 CALLER_STATE_REGISTER(uint64_t, r18) \
220 CALLER_STATE_REGISTER(uint64_t, r19) \
221 CALLER_STATE_REGISTER(uint64_t, r20) \
222 CALLER_STATE_REGISTER(uint64_t, r21) \
223 CALLER_STATE_REGISTER(uint64_t, r22) \
224 CALLER_STATE_REGISTER(uint64_t, r23) \
225 CALLER_STATE_REGISTER(uint64_t, r24) \
226 CALLER_STATE_REGISTER(uint64_t, r25) \
227 CALLER_STATE_REGISTER(uint64_t, r26) \
228 CALLER_STATE_REGISTER(uint64_t, r27) \
229 CALLER_STATE_REGISTER(uint64_t, r28) \
230 CALLER_STATE_REGISTER(uint64_t, r29) \
231 CALLER_STATE_REGISTER(uint64_t, r30) \
232 CALLER_STATE_REGISTER(uint64_t, r31) \
233 CALLER_STATE_REGISTER(uint64_t, f14) \
234 CALLER_STATE_REGISTER(uint64_t, f15) \
235 CALLER_STATE_REGISTER(uint64_t, f16) \
236 CALLER_STATE_REGISTER(uint64_t, f17) \
237 CALLER_STATE_REGISTER(uint64_t, f18) \
238 CALLER_STATE_REGISTER(uint64_t, f19) \
239 CALLER_STATE_REGISTER(uint64_t, f20) \
240 CALLER_STATE_REGISTER(uint64_t, f21) \
241 CALLER_STATE_REGISTER(uint64_t, f22) \
242 CALLER_STATE_REGISTER(uint64_t, f23) \
243 CALLER_STATE_REGISTER(uint64_t, f24) \
244 CALLER_STATE_REGISTER(uint64_t, f25) \
245 CALLER_STATE_REGISTER(uint64_t, f26) \
246 CALLER_STATE_REGISTER(uint64_t, f27) \
247 CALLER_STATE_REGISTER(uint64_t, f28) \
248 CALLER_STATE_REGISTER(uint64_t, f29) \
249 CALLER_STATE_REGISTER(uint64_t, f30) \
250 CALLER_STATE_REGISTER(uint64_t, f31) \
251 CALLER_STATE_REGISTER(CRReg, cr)
253 #endif // X86_64 || X86 || ARM || AARCH64 || PPC64LE
263 #if defined(LOOP_CALLER_STATE_REGISTERS) && !defined(OPENSSL_NO_ASM) && \
264 !defined(BORINGSSL_SHARED_LIBRARY)
265 #define SUPPORTS_ABI_TEST
270 #define CALLER_STATE_REGISTER(type, name) type name;
271 LOOP_CALLER_STATE_REGISTERS()
272 #undef CALLER_STATE_REGISTER
279 const crypto_word_t *argv,
size_t argc,
282 template <
typename T>
283 inline crypto_word_t ToWord(
T t) {
287 "parameter types must be integral or pointer types");
289 static_assert(
sizeof(
T) <=
sizeof(crypto_word_t),
290 "parameter types must be at most word-sized");
300 #if defined(OPENSSL_32_BIT)
303 static_assert(
sizeof(
T) == 4,
"parameter types must be word-sized");
304 return (crypto_word_t)
t;
305 #elif defined(OPENSSL_PPC64LE)
310 return (crypto_word_t)
t;
311 #elif defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)
341 static_assert(
sizeof(
T) >= 4,
"parameters must be at least 32 bits wide");
349 #error "unknown architecture"
362 template <
typename R,
typename...
Args>
368 static_assert(
sizeof...(
args) <= 8,
369 "too many arguments for abi_test_trampoline");
372 crypto_word_t argv[
sizeof...(args) + 1] = {
375 return RunTrampoline(
out,
reinterpret_cast<crypto_word_t
>(
func), argv,
376 sizeof...(
args), unwind);
382 template <
typename R,
typename...
Args>
390 template <
typename...
Args>
398 #endif // SUPPORTS_ABI_TEST
413 template <
typename R,
typename...
Args>
435 template <
typename R,
typename...
Args>
469 #if defined(OPENSSL_WINDOWS)
470 #define CHECK_ABI(...) CHECK_ABI_NO_UNWIND(__VA_ARGS__)
472 #define CHECK_ABI(...) CHECK_ABI_SEH(__VA_ARGS__)
476 #define CHECK_ABI_SEH(...) \
477 abi_test::internal::CheckGTest(#__VA_ARGS__, __FILE__, __LINE__, true, \
481 #define CHECK_ABI_NO_UNWIND(...) \
482 abi_test::internal::CheckGTest(#__VA_ARGS__, __FILE__, __LINE__, false, \
488 #if defined(SUPPORTS_ABI_TEST)
490 Uncallable() =
delete;
502 abi_test::internal::CallerState *
state,
503 const crypto_word_t *argv,
size_t argc,
504 crypto_word_t unwind);
506 #if defined(OPENSSL_X86_64)
536 #if defined(OPENSSL_WINDOWS)
540 void abi_test_bad_unwind_epilog(
void);
542 #endif // OPENSSL_X86_64
544 #if defined(OPENSSL_X86_64) || defined(OPENSSL_X86)
553 #endif // OPENSSL_X86_64 || OPENSSL_X86
556 #endif // SUPPORTS_ABI_TEST
559 #endif // OPENSSL_HEADER_ABI_TEST_H
std::vector< std::string > errors
bool operator==(const Reg128 &x) const
bool operator!=(const Reg128 &x) const
bool operator==(const BaseSlice &a, const BaseSlice &b)
#define abi_test_unwind_return
#define ADD_FAILURE_AT(file, line)
#define abi_test_trampoline
#define abi_test_get_and_clear_direction_flag
std::enable_if<!std::is_void< R >::value, crypto_word_t >::type CheckImpl(Result *out, bool, R(*func)(Args...), typename DeductionGuard< Args >::Type... args)
static void * OPENSSL_memset(void *dst, int c, size_t n)
#define T(upbtypeconst, upbtype, ctype, default_value)
#define abi_test_unwind_start
TestInstance::Result Result
std::string FixVAArgsString(const char *str)
unsigned __int64 uint64_t
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
bool operator!=(const Bytes &a, const Bytes &b)
UniquePtr< SSL_SESSION > ret
#define abi_test_bad_unwind_temporary
#define abi_test_bad_unwind_wrong_register
bool UnwindTestsEnabled()
R Check(Result *out, R(*func)(Args...), typename internal::DeductionGuard< Args >::Type... args)
R CheckGTest(const char *va_args_str, const char *file, int line, bool unwind, R(*func)(Args...), typename DeductionGuard< Args >::Type... args)
#define abi_test_set_direction_flag
#define abi_test_unwind_stop
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:28