Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/test/abi_test.h

raw
1 // Copyright (c) 2018, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #ifndef OPENSSL_HEADER_ABI_TEST_H
5 #define OPENSSL_HEADER_ABI_TEST_H
6
7 #include <gtest/gtest.h>
8
9 #include <string>
10 #include <type_traits>
11 #include <vector>
12
13 #include <openssl/base.h>
14
15 #include "../internal.h"
16
17
18 // abi_test provides routines for verifying that functions satisfy platform ABI
19 // requirements.
20 namespace abi_test {
21
22 // Result stores the result of an ABI test.
23 struct Result {
24 bool ok() const { return errors.empty(); }
25
26 std::vector<std::string> errors;
27 };
28
29 namespace internal {
30
31 // DeductionGuard wraps |T| in a template, so that template argument deduction
32 // does not apply to it. This may be used to force C++ to deduce template
33 // arguments from another parameter.
34 template <typename T>
35 struct DeductionGuard {
36 using Type = T;
37 };
38
39 // Reg128 contains storage space for a 128-bit register.
40 struct alignas(16) Reg128 {
41 bool operator==(const Reg128 &x) const { return x.lo == lo && x.hi == hi; }
42 bool operator!=(const Reg128 &x) const { return !((*this) == x); }
43 uint64_t lo, hi;
44 };
45
46 // LOOP_CALLER_STATE_REGISTERS is a macro that iterates over all registers the
47 // callee is expected to save for the caller, with the exception of the stack
48 // pointer. The stack pointer is tested implicitly by the function successfully
49 // returning at all.
50 #if defined(OPENSSL_X86_64)
51
52 // References:
53 // SysV64: https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf
54 // Win64: https://docs.microsoft.com/en-us/cpp/build/x64-software-conventions?view=vs-2017#register-usage
55 #if defined(OPENSSL_WINDOWS)
56 #define LOOP_CALLER_STATE_REGISTERS() \
57 CALLER_STATE_REGISTER(uint64_t, rbx) \
58 CALLER_STATE_REGISTER(uint64_t, rbp) \
59 CALLER_STATE_REGISTER(uint64_t, rdi) \
60 CALLER_STATE_REGISTER(uint64_t, rsi) \
61 CALLER_STATE_REGISTER(uint64_t, r12) \
62 CALLER_STATE_REGISTER(uint64_t, r13) \
63 CALLER_STATE_REGISTER(uint64_t, r14) \
64 CALLER_STATE_REGISTER(uint64_t, r15) \
65 CALLER_STATE_REGISTER(Reg128, xmm6) \
66 CALLER_STATE_REGISTER(Reg128, xmm7) \
67 CALLER_STATE_REGISTER(Reg128, xmm8) \
68 CALLER_STATE_REGISTER(Reg128, xmm9) \
69 CALLER_STATE_REGISTER(Reg128, xmm10) \
70 CALLER_STATE_REGISTER(Reg128, xmm11) \
71 CALLER_STATE_REGISTER(Reg128, xmm12) \
72 CALLER_STATE_REGISTER(Reg128, xmm13) \
73 CALLER_STATE_REGISTER(Reg128, xmm14) \
74 CALLER_STATE_REGISTER(Reg128, xmm15)
75 #else
76 #define LOOP_CALLER_STATE_REGISTERS() \
77 CALLER_STATE_REGISTER(uint64_t, rbx) \
78 CALLER_STATE_REGISTER(uint64_t, rbp) \
79 CALLER_STATE_REGISTER(uint64_t, r12) \
80 CALLER_STATE_REGISTER(uint64_t, r13) \
81 CALLER_STATE_REGISTER(uint64_t, r14) \
82 CALLER_STATE_REGISTER(uint64_t, r15)
83 #endif // OPENSSL_WINDOWS
84
85 #elif defined(OPENSSL_X86)
86
87 // References:
88 // SysV32: https://uclibc.org/docs/psABI-i386.pdf and
89 // Win32: https://docs.microsoft.com/en-us/cpp/cpp/argument-passing-and-naming-conventions?view=vs-2017
90 #define LOOP_CALLER_STATE_REGISTERS() \
91 CALLER_STATE_REGISTER(uint32_t, esi) \
92 CALLER_STATE_REGISTER(uint32_t, edi) \
93 CALLER_STATE_REGISTER(uint32_t, ebx) \
94 CALLER_STATE_REGISTER(uint32_t, ebp)
95
96 #elif defined(OPENSSL_ARM)
97
98 // References:
99 // AAPCS: https://developer.arm.com/docs/ihi0042/latest
100 // iOS32: https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html
101 // Linux: http://sourcery.mentor.com/sgpp/lite/arm/portal/kbattach142/arm_gnu_linux_%20abi.pdf
102 //
103 // ARM specifies a common calling convention, except r9 is left to the platform.
104 // Linux treats r9 as callee-saved, while iOS 3+ treats it as caller-saved. Most
105 // of our assembly treats it as callee-saved to be uniform, but we match the
106 // platform to avoid false positives when testing compiler-generated output.
107 #define LOOP_CALLER_STATE_REGISTERS_PRE_R9() \
108 CALLER_STATE_REGISTER(uint64_t, d8) \
109 CALLER_STATE_REGISTER(uint64_t, d9) \
110 CALLER_STATE_REGISTER(uint64_t, d10) \
111 CALLER_STATE_REGISTER(uint64_t, d11) \
112 CALLER_STATE_REGISTER(uint64_t, d12) \
113 CALLER_STATE_REGISTER(uint64_t, d13) \
114 CALLER_STATE_REGISTER(uint64_t, d14) \
115 CALLER_STATE_REGISTER(uint64_t, d15) \
116 CALLER_STATE_REGISTER(uint32_t, r4) \
117 CALLER_STATE_REGISTER(uint32_t, r5) \
118 CALLER_STATE_REGISTER(uint32_t, r6) \
119 CALLER_STATE_REGISTER(uint32_t, r7) \
120 CALLER_STATE_REGISTER(uint32_t, r8)
121 #define LOOP_CALLER_STATE_REGISTERS_POST_R9() \
122 CALLER_STATE_REGISTER(uint32_t, r10) \
123 CALLER_STATE_REGISTER(uint32_t, r11)
124 #if defined(OPENSSL_APPLE)
125 #define LOOP_CALLER_STATE_REGISTERS() \
126 LOOP_CALLER_STATE_REGISTERS_PRE_R9() \
127 LOOP_CALLER_STATE_REGISTERS_POST_R9()
128 #else // !OPENSSL_APPLE
129 #define LOOP_CALLER_STATE_REGISTERS() \
130 LOOP_CALLER_STATE_REGISTERS_PRE_R9() \
131 CALLER_STATE_REGISTER(uint32_t, r9) \
132 LOOP_CALLER_STATE_REGISTERS_POST_R9()
133 #endif // OPENSSL_APPLE
134
135 #elif defined(OPENSSL_AARCH64)
136
137 // References:
138 // AAPCS64: https://developer.arm.com/docs/ihi0055/latest
139 // iOS64: https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html
140 //
141 // In aarch64, r18 (accessed as w18 or x18 in a 64-bit context) is the platform
142 // register. iOS says user code may not touch it. We found no clear reference
143 // for Linux. The iOS behavior implies portable assembly cannot use it, and
144 // aarch64 has many registers. Thus this framework ignores register's existence.
145 // We test r18 violations in arm-xlate.pl.
146 #define LOOP_CALLER_STATE_REGISTERS() \
147 /* Per AAPCS64, section 5.1.2, only the bottom 64 bits of v8-v15 */ \
148 /* are preserved. These are accessed as dN. */ \
149 CALLER_STATE_REGISTER(uint64_t, d8) \
150 CALLER_STATE_REGISTER(uint64_t, d9) \
151 CALLER_STATE_REGISTER(uint64_t, d10) \
152 CALLER_STATE_REGISTER(uint64_t, d11) \
153 CALLER_STATE_REGISTER(uint64_t, d12) \
154 CALLER_STATE_REGISTER(uint64_t, d13) \
155 CALLER_STATE_REGISTER(uint64_t, d14) \
156 CALLER_STATE_REGISTER(uint64_t, d15) \
157 /* For consistency with dN, use the 64-bit name xN, rather than */ \
158 /* the generic rN. */ \
159 CALLER_STATE_REGISTER(uint64_t, x19) \
160 CALLER_STATE_REGISTER(uint64_t, x20) \
161 CALLER_STATE_REGISTER(uint64_t, x21) \
162 CALLER_STATE_REGISTER(uint64_t, x22) \
163 CALLER_STATE_REGISTER(uint64_t, x23) \
164 CALLER_STATE_REGISTER(uint64_t, x24) \
165 CALLER_STATE_REGISTER(uint64_t, x25) \
166 CALLER_STATE_REGISTER(uint64_t, x26) \
167 CALLER_STATE_REGISTER(uint64_t, x27) \
168 CALLER_STATE_REGISTER(uint64_t, x28) \
169 CALLER_STATE_REGISTER(uint64_t, x29)
170
171 #elif defined(OPENSSL_PPC64LE)
172
173 // CRReg only compares the CR2-CR4 bits of a CR register.
174 struct CRReg {
175 uint32_t masked() const { return value & 0x00fff000; }
176 bool operator==(CRReg r) const { return masked() == r.masked(); }
177 bool operator!=(CRReg r) const { return masked() != r.masked(); }
178 uint32_t value;
179 };
180
181 // References:
182 // ELFv2: http://openpowerfoundation.org/wp-content/uploads/resources/leabi/leabi-20170510.pdf
183 //
184 // Note vector and floating-point registers on POWER have two different names.
185 // Originally, there were 32 floating-point registers and 32 vector registers,
186 // labelled f0-f31 and v0-v31 respectively. Later, VSX (Vector Scalar Extension)
187 // unified them into 64 registers vs0-vs63. f0-f31 map to the lower halves of
188 // vs0-vs31. v0-v31 map to vs32-vs63. The ABI was defined in terms of pre-VSX
189 // names, so we use those names here. In particular, f14-f31 are
190 // callee-saved, but the upper halves of vs14-vs31 are not.
191 #define LOOP_CALLER_STATE_REGISTERS() \
192 CALLER_STATE_REGISTER(Reg128, v20) \
193 CALLER_STATE_REGISTER(Reg128, v21) \
194 CALLER_STATE_REGISTER(Reg128, v22) \
195 CALLER_STATE_REGISTER(Reg128, v23) \
196 CALLER_STATE_REGISTER(Reg128, v24) \
197 CALLER_STATE_REGISTER(Reg128, v25) \
198 CALLER_STATE_REGISTER(Reg128, v26) \
199 CALLER_STATE_REGISTER(Reg128, v27) \
200 CALLER_STATE_REGISTER(Reg128, v28) \
201 CALLER_STATE_REGISTER(Reg128, v29) \
202 CALLER_STATE_REGISTER(Reg128, v30) \
203 CALLER_STATE_REGISTER(Reg128, v31) \
204 CALLER_STATE_REGISTER(uint64_t, r14) \
205 CALLER_STATE_REGISTER(uint64_t, r15) \
206 CALLER_STATE_REGISTER(uint64_t, r16) \
207 CALLER_STATE_REGISTER(uint64_t, r17) \
208 CALLER_STATE_REGISTER(uint64_t, r18) \
209 CALLER_STATE_REGISTER(uint64_t, r19) \
210 CALLER_STATE_REGISTER(uint64_t, r20) \
211 CALLER_STATE_REGISTER(uint64_t, r21) \
212 CALLER_STATE_REGISTER(uint64_t, r22) \
213 CALLER_STATE_REGISTER(uint64_t, r23) \
214 CALLER_STATE_REGISTER(uint64_t, r24) \
215 CALLER_STATE_REGISTER(uint64_t, r25) \
216 CALLER_STATE_REGISTER(uint64_t, r26) \
217 CALLER_STATE_REGISTER(uint64_t, r27) \
218 CALLER_STATE_REGISTER(uint64_t, r28) \
219 CALLER_STATE_REGISTER(uint64_t, r29) \
220 CALLER_STATE_REGISTER(uint64_t, r30) \
221 CALLER_STATE_REGISTER(uint64_t, r31) \
222 CALLER_STATE_REGISTER(uint64_t, f14) \
223 CALLER_STATE_REGISTER(uint64_t, f15) \
224 CALLER_STATE_REGISTER(uint64_t, f16) \
225 CALLER_STATE_REGISTER(uint64_t, f17) \
226 CALLER_STATE_REGISTER(uint64_t, f18) \
227 CALLER_STATE_REGISTER(uint64_t, f19) \
228 CALLER_STATE_REGISTER(uint64_t, f20) \
229 CALLER_STATE_REGISTER(uint64_t, f21) \
230 CALLER_STATE_REGISTER(uint64_t, f22) \
231 CALLER_STATE_REGISTER(uint64_t, f23) \
232 CALLER_STATE_REGISTER(uint64_t, f24) \
233 CALLER_STATE_REGISTER(uint64_t, f25) \
234 CALLER_STATE_REGISTER(uint64_t, f26) \
235 CALLER_STATE_REGISTER(uint64_t, f27) \
236 CALLER_STATE_REGISTER(uint64_t, f28) \
237 CALLER_STATE_REGISTER(uint64_t, f29) \
238 CALLER_STATE_REGISTER(uint64_t, f30) \
239 CALLER_STATE_REGISTER(uint64_t, f31) \
240 CALLER_STATE_REGISTER(CRReg, cr)
241
242 #endif // X86_64 || X86 || ARM || AARCH64 || PPC64LE
243
244 // Enable ABI testing if all of the following are true.
245 //
246 // - We have CallerState and trampoline support for the architecture.
247 //
248 // - Assembly is enabled.
249 //
250 // - This is not a shared library build. Assembly functions are not reachable
251 // from tests in shared library builds.
252 #if defined(LOOP_CALLER_STATE_REGISTERS) && !defined(OPENSSL_NO_ASM) && \
253 !defined(BORINGSSL_SHARED_LIBRARY)
254 #define SUPPORTS_ABI_TEST
255
256 // CallerState contains all caller state that the callee is expected to
257 // preserve.
258 struct CallerState {
259 #define CALLER_STATE_REGISTER(type, name) type name;
260 LOOP_CALLER_STATE_REGISTERS()
261 #undef CALLER_STATE_REGISTER
262 };
263
264 // RunTrampoline runs |func| on |argv|, recording ABI errors in |out|. It does
265 // not perform any type-checking. If |unwind| is true and unwind tests have been
266 // enabled, |func| is single-stepped under an unwind test.
267 crypto_word_t RunTrampoline(Result *out, crypto_word_t func,
268 const crypto_word_t *argv, size_t argc,
269 bool unwind);
270
271 template <typename T>
272 inline crypto_word_t ToWord(T t) {
273 // ABIs typically pass floats and structs differently from integers and
274 // pointers. We only need to support the latter.
275 static_assert(std::is_integral<T>::value || std::is_pointer<T>::value,
276 "parameter types must be integral or pointer types");
277 // We only support types which fit in registers.
278 static_assert(sizeof(T) <= sizeof(crypto_word_t),
279 "parameter types must be at most word-sized");
280
281 // ABIs are complex around arguments that are smaller than native words.
282 // Parameters passed in memory are sometimes packed and sometimes padded to a
283 // word. When parameters are padded in memory or passed in a larger register,
284 // the unused bits may be undefined or sign- or zero-extended.
285 //
286 // We could simply cast to |crypto_word_t| everywhere but, on platforms where
287 // padding is undefined, we perturb the bits to test the function accounts for
288 // for this.
289 #if defined(OPENSSL_32_BIT)
290 // We never pass parameters smaller than int, so require word-sized parameters
291 // on 32-bit architectures for simplicity.
292 static_assert(sizeof(T) == 4, "parameter types must be word-sized");
293 return (crypto_word_t)t;
294 #elif defined(OPENSSL_PPC64LE)
295 // ELFv2, section 2.2.2.3 says the parameter save area sign- or zero-extends
296 // parameters passed in memory. Section 2.2.3 is unclear on how to handle
297 // register parameters, but section 2.2.2.3 additionally says that the memory
298 // copy of a parameter is identical to the register one.
299 return (crypto_word_t)t;
300 #elif defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)
301 // AAPCS64, section 5.4.2, clauses C.7 and C.14 says any remaining bits in
302 // aarch are unspecified. iOS64 contradicts this and says the callee extends
303 // arguments up to 32 bits, and only the upper 32 bits are unspecified.
304 //
305 // On x86_64, Win64 leaves all unused bits unspecified. SysV also leaves
306 // unused bits in stack parameters unspecified, but it behaves like iOS64 for
307 // register parameters. This was determined via experimentation.
308 //
309 // We limit to 32-bit and 64-bit parameters, the subset where the above all
310 // align, and then test that functions tolerate arbitrary unused bits.
311 //
312 // TODO(davidben): Find authoritative citations for x86_64. For x86_64, I
313 // observed the behavior of Clang, GCC, and MSVC. ABI rules here may be
314 // inferred from two kinds of experiments:
315 //
316 // 1. When passing a value to a small-argument-taking function, does the
317 // compiler ensure unused bits are cleared, sign-extended, etc.? Tests for
318 // register parameters are confounded by x86_64's implicit clearing of
319 // registers' upper halves, but passing some_u64 >> 1 usually clears this.
320 //
321 // 2. When compiling a small-argument-taking function, does the compiler make
322 // assumptions about unused bits of arguments?
323 //
324 // MSVC was observed to tolerate and produce arbitrary values for unused bits,
325 // which is conclusive. GCC and Clang, targeting Linux, were similarly
326 // conclusive on stack parameters. Clang was also conclusive for register
327 // parameters. Callers only extended parameters up to 32 bits, and callees
328 // took advantage of the 32-bit extension. GCC only exhibited the callee
329 // behavior.
330 static_assert(sizeof(T) >= 4, "parameters must be at least 32 bits wide");
331 crypto_word_t ret;
332 // Filling extra bits with 0xaa will be vastly out of bounds for code
333 // expecting either sign- or zero-extension. (0xaa is 0b10101010.)
334 OPENSSL_memset(&ret, 0xaa, sizeof(ret));
335 OPENSSL_memcpy(&ret, &t, sizeof(t));
336 return ret;
337 #else
338 #error "unknown architecture"
339 #endif
340 }
341
342 // CheckImpl runs |func| on |args|, recording ABI errors in |out|. If |unwind|
343 // is true and unwind tests have been enabled, |func| is single-stepped under an
344 // unwind test.
345 //
346 // It returns the value as a |crypto_word_t| to work around problems when |R| is
347 // void. |args| is wrapped in a |DeductionGuard| so |func| determines the
348 // template arguments. Otherwise, |args| may deduce |Args| incorrectly. For
349 // instance, if |func| takes const int *, and the caller passes an int *, the
350 // compiler will complain the deduced types do not match.
351 template <typename R, typename... Args>
352 inline crypto_word_t CheckImpl(Result *out, bool unwind, R (*func)(Args...),
353 typename DeductionGuard<Args>::Type... args) {
354 // We only support up to 8 arguments, so all arguments on aarch64 and ppc64le
355 // are passed in registers. This is simpler and avoids the iOS discrepancy
356 // around packing small arguments on the stack. (See the iOS64 reference.)
357 static_assert(sizeof...(args) <= 8,
358 "too many arguments for abi_test_trampoline");
359
360 // Allocate one extra entry so MSVC does not complain about zero-size arrays.
361 crypto_word_t argv[sizeof...(args) + 1] = {
362 ToWord(args)...,
363 };
364 return RunTrampoline(out, reinterpret_cast<crypto_word_t>(func), argv,
365 sizeof...(args), unwind);
366 }
367 #else
368 // To simplify callers when ABI testing support is unavoidable, provide a backup
369 // CheckImpl implementation. It must be specialized for void returns because we
370 // call |func| directly.
371 template <typename R, typename... Args>
372 inline typename std::enable_if<!std::is_void<R>::value, crypto_word_t>::type
373 CheckImpl(Result *out, bool /* unwind */, R (*func)(Args...),
374 typename DeductionGuard<Args>::Type... args) {
375 *out = Result();
376 return func(args...);
377 }
378
379 template <typename... Args>
380 inline crypto_word_t CheckImpl(Result *out, bool /* unwind */,
381 void (*func)(Args...),
382 typename DeductionGuard<Args>::Type... args) {
383 *out = Result();
384 func(args...);
385 return 0;
386 }
387 #endif // SUPPORTS_ABI_TEST
388
389 // FixVAArgsString takes a string like "f, 1, 2" and returns a string like
390 // "f(1, 2)".
391 //
392 // This is needed because the |CHECK_ABI| macro below cannot be defined as
393 // CHECK_ABI(func, ...). The C specification requires that variadic macros bind
394 // at least one variadic argument. Clang, GCC, and MSVC all ignore this, but
395 // there are issues with trailing commas and different behaviors across
396 // compilers.
397 std::string FixVAArgsString(const char *str);
398
399 // CheckGTest behaves like |CheckImpl|, but it returns the correct type and
400 // raises GTest assertions on failure. If |unwind| is true and unwind tests are
401 // enabled, |func| is single-stepped under an unwind test.
402 template <typename R, typename... Args>
403 inline R CheckGTest(const char *va_args_str, const char *file, int line,
404 bool unwind, R (*func)(Args...),
405 typename DeductionGuard<Args>::Type... args) {
406 Result result;
407 crypto_word_t ret = CheckImpl(&result, unwind, func, args...);
408 if (!result.ok()) {
409 testing::Message msg;
410 msg << "ABI failures in " << FixVAArgsString(va_args_str) << ":\n";
411 for (const auto &error : result.errors) {
412 msg << " " << error << "\n";
413 }
414 ADD_FAILURE_AT(file, line) << msg;
415 }
416 return (R)ret;
417 }
418
419 } // namespace internal
420
421 // Check runs |func| on |args| and returns the result. If ABI-testing is
422 // supported in this build configuration, it writes any ABI failures to |out|.
423 // Otherwise, it runs the function transparently.
424 template <typename R, typename... Args>
425 inline R Check(Result *out, R (*func)(Args...),
426 typename internal::DeductionGuard<Args>::Type... args) {
427 return (R)internal::CheckImpl(out, false, func, args...);
428 }
429
430 // EnableUnwindTests enables unwind tests, if supported. If not supported, it
431 // does nothing.
432 void EnableUnwindTests();
433
434 // UnwindTestsEnabled returns true if unwind tests are enabled and false
435 // otherwise.
436 bool UnwindTestsEnabled();
437
438 } // namespace abi_test
439
440 // CHECK_ABI calls the first argument on the remaining arguments and returns the
441 // result. If ABI-testing is supported in this build configuration, it adds a
442 // non-fatal GTest failure if the call did not satisfy ABI requirements.
443 //
444 // |CHECK_ABI| does return the value and thus may replace any function call,
445 // provided it takes only simple parameters. However, it is recommended to test
446 // ABI separately from functional tests of assembly. Fully instrumenting a
447 // function for ABI checking requires single-stepping the function, which is
448 // inefficient.
449 //
450 // Functional testing requires coverage of input values, while ABI testing only
451 // requires branch coverage. Most of our assembly is constant-time, so usually
452 // only a few instrumented calls are necessary.
453 //
454 // TODO(https://crbug.com/boringssl/259): Most of Windows assembly currently
455 // fails SEH testing. For now, |CHECK_ABI| behaves like |CHECK_ABI_NO_UNWIND|
456 // on Windows. Functions which work with unwind testing on Windows should use
457 // |CHECK_ABI_SEH|.
458 #if defined(OPENSSL_WINDOWS)
459 #define CHECK_ABI(...) CHECK_ABI_NO_UNWIND(__VA_ARGS__)
460 #else
461 #define CHECK_ABI(...) CHECK_ABI_SEH(__VA_ARGS__)
462 #endif
463
464 // CHECK_ABI_SEH behaves like |CHECK_ABI| but enables unwind testing on Windows.
465 #define CHECK_ABI_SEH(...) \
466 abi_test::internal::CheckGTest(#__VA_ARGS__, __FILE__, __LINE__, true, \
467 __VA_ARGS__)
468
469 // CHECK_ABI_NO_UNWIND behaves like |CHECK_ABI| but disables unwind testing.
470 #define CHECK_ABI_NO_UNWIND(...) \
471 abi_test::internal::CheckGTest(#__VA_ARGS__, __FILE__, __LINE__, false, \
472 __VA_ARGS__)
473
474
475 // Internal functions.
476
477 #if defined(SUPPORTS_ABI_TEST)
478 struct Uncallable {
479 Uncallable() = delete;
480 };
481
482 extern "C" {
483
484 // abi_test_trampoline loads callee-saved registers from |state|, calls |func|
485 // with |argv|, then saves the callee-saved registers into |state|. It returns
486 // the result of |func|. If |unwind| is non-zero, this function triggers unwind
487 // instrumentation.
488 //
489 // We give |func| type |crypto_word_t| to avoid tripping MSVC's warning 4191.
490 crypto_word_t abi_test_trampoline(crypto_word_t func,
491 abi_test::internal::CallerState *state,
492 const crypto_word_t *argv, size_t argc,
493 crypto_word_t unwind);
494
495 #if defined(OPENSSL_X86_64)
496 // abi_test_unwind_start points at the instruction that starts unwind testing in
497 // |abi_test_trampoline|. This is the value of the instruction pointer at the
498 // first |SIGTRAP| during unwind testing.
499 //
500 // This symbol is not a function and should not be called.
501 void abi_test_unwind_start(Uncallable);
502
503 // abi_test_unwind_return points at the instruction immediately after the call in
504 // |abi_test_trampoline|. When unwinding the function under test, this is the
505 // expected address in the |abi_test_trampoline| frame. After this address, the
506 // unwind tester should ignore |SIGTRAP| until |abi_test_unwind_stop|.
507 //
508 // This symbol is not a function and should not be called.
509 void abi_test_unwind_return(Uncallable);
510
511 // abi_test_unwind_stop is the value of the instruction pointer at the final
512 // |SIGTRAP| during unwind testing.
513 //
514 // This symbol is not a function and should not be called.
515 void abi_test_unwind_stop(Uncallable);
516
517 // abi_test_bad_unwind_wrong_register preserves the ABI, but annotates the wrong
518 // register in unwind metadata.
519 void abi_test_bad_unwind_wrong_register(void);
520
521 // abi_test_bad_unwind_temporary preserves the ABI, but temporarily corrupts the
522 // storage space for a saved register, breaking unwind.
523 void abi_test_bad_unwind_temporary(void);
524
525 #if defined(OPENSSL_WINDOWS)
526 // abi_test_bad_unwind_epilog preserves the ABI, and correctly annotates the
527 // prolog, but the epilog does not match Win64's rules, breaking unwind during
528 // the epilog.
529 void abi_test_bad_unwind_epilog(void);
530 #endif
531 #endif // OPENSSL_X86_64
532
533 #if defined(OPENSSL_X86_64) || defined(OPENSSL_X86)
534 // abi_test_get_and_clear_direction_flag clears the direction flag. If the flag
535 // was previously set, it returns one. Otherwise, it returns zero.
536 int abi_test_get_and_clear_direction_flag(void);
537
538 // abi_test_set_direction_flag sets the direction flag. This does not conform to
539 // ABI requirements and must only be called within a |CHECK_ABI| guard to avoid
540 // errors later in the program.
541 int abi_test_set_direction_flag(void);
542 #endif // OPENSSL_X86_64 || OPENSSL_X86
543
544 } // extern "C"
545 #endif // SUPPORTS_ABI_TEST
546
547
548 #endif // OPENSSL_HEADER_ABI_TEST_H