omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / x86 / failed-cleanup.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #define _GNU_SOURCE |
| 3 | #include "omega_native.h" |
| 4 | #include <assert.h> |
| 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | #include <sys/mman.h> |
| 8 | #include <unistd.h> |
| 9 | /* Same CPU VA and Wolfram receipt as ../v2/dev/context.c. */ |
| 10 | int main(void) |
| 11 | { |
| 12 | omega_native_context *c = 0; |
| 13 | uint64_t h = 99, r = 99; |
| 14 | assert(omega_native_context_create(1, &c) == OMEGA_OK); |
| 15 | assert(omega2_ctx_reserve(c, &h, UINT64_C(68719484928), 4096) == OMEGA_OK); |
| 16 | assert((int64_t)h > 0); |
| 17 | /* The conductor forces cleanup munmap to fail after the real mmap EBADF. */ |
| 18 | assert(omega2_ctx_attach(c, &r, h, (uint64_t)-1) == 3 && r == 99); |
| 19 | assert(omega2_ctx_address(c, &r, h) == OMEGA_OK && r == UINT64_C(68719484928)); |
| 20 | r = 99; |
| 21 | assert(omega2_ctx_rd(c, &r, h) == 3 && r == 99); |
| 22 | assert(omega2_ctx_fetch(c, &r, h) == 3 && r == 99); |
| 23 | assert(omega2_ctx_publish(c, &r, h, 1) == 3 && r == 99); |
| 24 | assert(omega2_ctx_store(c, &r, h) == 3 && r == 99); |
| 25 | /* An invalid fd alone cannot distinguish quarantine from a live reservation: |
| 26 | both would trap on the conductor's forced cleanup error. A valid memfd |
| 27 | would bind successfully if access=0 were incorrectly left behind. */ |
| 28 | int fd = memfd_create("quarantine-control", 0); |
| 29 | assert(fd >= 0 && ftruncate(fd, 4096) == 0); |
| 30 | assert(omega2_ctx_attach(c, &r, h, (uint64_t)fd) == 3 && r == 99); |
| 31 | assert(close(fd) == 0); |
| 32 | assert(omega_native_context_destroy(c) == OMEGA_CONTEXT_BUSY); |
| 33 | assert(omega2_ctx_drop(c, &r, h) == OMEGA_OK && r == 0); |
| 34 | r = 99; |
| 35 | assert(omega2_ctx_address(c, &r, h) == 3 && r == 99); |
| 36 | assert(omega_native_context_destroy(c) == OMEGA_OK); |
| 37 | puts("NATIVE-X86-CLEANUP PASS quarantine before failing cleanup, access refused, drop retry"); |
| 38 | return 0; |
| 39 | } |