interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tests / native / v2 / dev / context-ro.c

31 lines · 987 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#define _GNU_SOURCE
3/* White-box oracle only: production consumers include omega_native.h. */
4#include "omega_native.c"
5#include <assert.h>
6#include <stdio.h>
7#include <sys/wait.h>
8#include <unistd.h>
9static void cannot_write(const ombr_rt *rt)
10{
11 pid_t pid = fork();
12 assert(pid >= 0);
13 if (pid == 0) {
14 const void *volatile *entry = (const void *volatile *)(uintptr_t)rt;
15 entry[31] = 0;
16 _exit(0);
17 }
18 int status;
19 assert(waitpid(pid, &status, 0) == pid);
20 assert(WIFSIGNALED(status) && (WTERMSIG(status) == SIGSEGV || WTERMSIG(status) == SIGBUS));
21}
22int main(void)
23{
24 omega_native_context *c = 0;
25 assert(omega_native_context_create(1, &c) == OMEGA_OK);
26 cannot_write(c->rt);
27 cannot_write(&ombr_rt_table);
28 assert(omega_native_context_destroy(c) == OMEGA_OK);
29 puts("NATIVE-CONTEXT-RO PASS default and explicit dispatch tables reject writes");
30 return 0;
31}