omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / x86 / trapcheck.c
| 1 | /* EXPECT_TRAP is 5 for a genuine trap, 34 for a corrupted callback, and 6 |
| 2 | * for exhaustion of the test runtime's deliberately bounded stack. */ |
| 3 | #include "omega_native.h" |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | extern uint32_t x86_sysv_probe(void *, uint64_t *, uint64_t, uint64_t); |
| 8 | |
| 9 | int main(void) |
| 10 | { |
| 11 | const uint64_t sentinel = UINT64_C(0x5a5a5a5a5a5a5a5a); |
| 12 | uint64_t result = sentinel; |
| 13 | if (x86_sysv_probe((void *)omega_trapcall, &result, 0, 0) != EXPECT_TRAP || result != sentinel) |
| 14 | return 1; |
| 15 | #if EXPECT_TRAP == 6 |
| 16 | uint8_t out[64], original[64]; |
| 17 | memset(out, 0xa5, sizeof out); |
| 18 | memcpy(original, out, sizeof out); |
| 19 | if (x86_sysv_probe((void *)omega2_outtrap, &result, (uintptr_t)out, 0) != 6 || |
| 20 | result != sentinel || memcmp(out, original, sizeof out) != 0) |
| 21 | return 3; |
| 22 | #endif |
| 23 | /* Reenter the same library after recovery. With the small-floor control, |
| 24 | * the nested unit will still exhaust its budget: a separate scalar unit |
| 25 | * proves the native stack and TLS active flag were restored. */ |
| 26 | if (x86_sysv_probe((void *)omega_follow, &result, 7, 0) != OMEGA_OK || result != 7) |
| 27 | return 2; |
| 28 | puts("PASS trap status, unchanged result, SysV saved registers, subsequent call"); |
| 29 | return 0; |
| 30 | } |