omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / docs / NATIVE-ABI.md
| 1 | # Native call ABI v1 and v2 |
| 2 | |
| 3 | ABI v0 (docs/ABI.md) translates Omega source into C or Python source. ABI v1 calls the machine code |
| 4 | the seeded Omega compiler itself produced. Nothing is translated: each foreign language calls the same |
| 5 | compiled Omega function. Omega's language and its internal calling rules are unchanged; the bridge |
| 6 | adapts the foreign side to them. |
| 7 | |
| 8 | ## Target selection and compiler custody |
| 9 | |
| 10 | `tools/native [--target aarch64linux|x86linux] [--freestanding] [--host] OUTDIR unit.om...` |
| 11 | selects the output ABI explicitly. The default is `aarch64linux`; it keeps the |
| 12 | existing generator invocation and compiler inputs unchanged. The tool does not |
| 13 | infer a target from the build host or try to execute a generated library. |
| 14 | |
| 15 | `OMEGA_NATIVE_OMC` remains mandatory for both targets and must have sha256 |
| 16 | `734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`. |
| 17 | It builds `src/native.om` into the AArch64-hosted `work/native-gen`. With the |
| 18 | default target it also compiles OM-1 units; `OMEGA_NATIVE_OMC2` compiles OM-2 |
| 19 | units and supplies their compiler identity, as before. |
| 20 | |
| 21 | The **native-v2 qualification suite** needs two explicitly pinned OM-2 compiler roles until the |
| 22 | upstream hoist and function-host changes are combined: `OMEGA_NATIVE_OMC2` for ABI/hoist units and |
| 23 | `OMEGA_NATIVE_HOST_OMC2` for section 11's host units. This is test configuration, not a change to the |
| 24 | production compiler pin or `tools/native`'s interface. See AArch64 qualification below for exact |
| 25 | revisions, digests, and the seed-only rebuild. |
| 26 | |
| 27 | For `--target x86linux` **without `--host`**, `OMEGA_NATIVE_X86_OMC` compiles **both** OM-1 and OM-2 |
| 28 | units and must have sha256 |
| 29 | `be8c51301307555254fc59e351d281aae1aa096d91521777e33a41c8b446448a`, the |
| 30 | committed `seed/out/omc` of omega-mv main |
| 31 | `474197e4fa0207e0e2fb3c0494594a975f5031fa` (last changed by omega-mv #994). |
| 32 | Its compiler source sha256 is |
| 33 | `d4b4b89d8a58cc90d30d15a525b417e4b31e5bfe5288d21d665f1c7958a330f6`. |
| 34 | This is a separate candidate compiler pin, not a replacement for the generator's |
| 35 | baseline pin. `OMEGA_NATIVE_OMC2` is not used for this target. Each compiler |
| 36 | input is `target x86linux\n` followed by the snapshotted source. The directive |
| 37 | exists only in `work/<unit>.compile.om`: profile detection, generator framing, |
| 38 | the `src=` identity and `work/<unit>.om` all retain the exact original source |
| 39 | bytes. The `omc=` identity records the x86 compiler's digest, not the baseline |
| 40 | generator compiler's digest. |
| 41 | |
| 42 | The x86 generator contract is `native-gen OUTPUT x86linux` for pure output and |
| 43 | `native-gen OUTPUT x86host` with `--host`. Default AArch64 calls remain |
| 44 | `native-gen OUTPUT`. Set `CC` to a compiler for the selected target; for example: |
| 45 | |
| 46 | ```sh |
| 47 | OMEGA_NATIVE_OMC=/path/to/baseline/omc \ |
| 48 | OMEGA_NATIVE_X86_OMC=/path/to/x86/omc \ |
| 49 | CC=x86_64-linux-gnu-gcc \ |
| 50 | tools/native --target x86linux build/native-x86 \ |
| 51 | tests/native/madd.om tests/native/v2/vec.om |
| 52 | ``` |
| 53 | |
| 54 | The x86 target is hosted Linux x86-64 SysV output. With `--freestanding` it emits |
| 55 | the same freestanding binding (pure-scalar OM-1 units, and OM-2 units with output |
| 56 | `fapic`, see below) with a SysV adapter that runs on the caller's stack, |
| 57 | keeps the trap anchor in R12 and sets the owned-stack floor R15 to 0 (no bound |
| 58 | check, as in the AArch64 freestanding binding). x86 code bytes are packed as |
| 59 | little-endian `.quad` words plus a `.byte` tail; the assembled bytes are the |
| 60 | compiler's bytes. Before omega-mv#940 the combination refused with exit 110 before |
| 61 | creating OUTDIR. An unknown target or malformed option exits 2. A mismatched |
| 62 | compiler digest refuses before generating or installing outputs. |
| 63 | |
| 64 | **Evidence boundary:** the x86 integration is IMPLEMENTED and EXERCISED under |
| 65 | QEMU 10.0.14, not qualified by the historical AArch64 receipts below. At the |
| 66 | current x86 compiler pin, see |
| 67 | [`evidence/native-x86-be8c5130.json`](../evidence/native-x86-be8c5130.json) |
| 68 | and its command receipts; earlier pins' receipts remain in |
| 69 | `evidence/native-x86-62775d2a.json`, `evidence/native-x86-badedbb0/`, `evidence/native-x86-f7752bc5/` and `evidence/native-x86/`. Native physical x86-64 execution remains **NOT_RUN**. |
| 70 | No GPU execution is part of this target. The compiler is merged on omega-mv |
| 71 | main. The full compiler differential is recorded separately; this bridge |
| 72 | receipt does not qualify the compiler. |
| 73 | |
| 74 | ### x86 emulator runner and QEMU oracle |
| 75 | |
| 76 | `sh tests/native/x86/run.sh [EMPTY_OUTPUT]` cross-builds the callers and executes |
| 77 | all target programs through `QEMU_X86_64` by default, even on an x86 build host. It requires |
| 78 | the baseline and x86 compiler variables above, `CC`/`CXX` targeting x86 Linux, |
| 79 | Rust's `x86_64-unknown-linux-gnu` standard library, Zig 0.13, Go with cgo, and an |
| 80 | x86 Linux Python interpreter supplied as `OMEGA_NATIVE_X86_PYTHON`. This is not |
| 81 | the build host's Python. `OMEGA_NATIVE_X86_SYSROOT` defaults to |
| 82 | `/usr/x86_64-linux-gnu`; `OMEGA_NATIVE_X86_LIBPATH` optionally supplies the guest |
| 83 | library search path. `tests/native/x86/prepare.py EMPTY_OUTPUT` extracts a Python |
| 84 | oracle without installing host packages and prints the Python/library variables; |
| 85 | its `runtime-packages.json` records exact archive versions and digests. |
| 86 | |
| 87 | `OMEGA_NATIVE_X86_EXEC=native` runs the same suite with every target program |
| 88 | executed directly on an x86-64 host CPU instead of under QEMU; the QEMU oracle is |
| 89 | then not used, and check names and the aggregate line say `NATIVE`. Preflight |
| 90 | refuses a non-x86-64 host and any other mode value, and prints the CPU model, |
| 91 | hypervisor flag, kernel and detected virtualization. The pinned compilers are |
| 92 | AArch64 executables, so the x86 host runs them through binfmt `qemu-aarch64`. |
| 93 | [NATIVE-X86-PHYSICAL.md](NATIVE-X86-PHYSICAL.md) is the runbook, the control set |
| 94 | and the receipt format; a receipt is labelled PHYSICAL only for |
| 95 | `virtualization=none` with the hypervisor flag clear. |
| 96 | |
| 97 | Select the emulator explicitly for qualification: |
| 98 | |
| 99 | ```sh |
| 100 | OMEGA_NATIVE_OMC=/path/to/baseline/omc \ |
| 101 | OMEGA_NATIVE_X86_OMC=/path/to/x86/omc \ |
| 102 | CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++ \ |
| 103 | QEMU_X86_64=/path/to/qemu-10.0.14/build/qemu-x86_64 \ |
| 104 | OMEGA_NATIVE_X86_PYTHON=/path/to/amd64-python/root/usr/bin/python3.12 \ |
| 105 | OMEGA_NATIVE_X86_LIBPATH=/path/to/amd64-python/root/usr/lib/x86_64-linux-gnu:/path/to/amd64-python/root/lib/x86_64-linux-gnu:/usr/x86_64-linux-gnu/lib \ |
| 106 | sh tests/native/x86/run.sh build/native-x86-new |
| 107 | ``` |
| 108 | |
| 109 | Integration observations found crashes in the C signal control and Rust/Go |
| 110 | `/proc/self/maps` paths under QEMU 8.2.2. The unchanged callers exited 0 with |
| 111 | unpatched QEMU 10.0.14. Do not alter callers or weaken signal/thread controls |
| 112 | to accommodate the older emulator. The complete integrated suite and its |
| 113 | failed/missing-toolchain controls subsequently passed under 10.0.14 (EMULATED). |
| 114 | |
| 115 | The suite now checks the emulator before any caller runs. It prints |
| 116 | `INFO qemu executable=`, `INFO qemu sha256=` and `INFO qemu version=` for the |
| 117 | resolved `QEMU_X86_64`, then cross-builds `tests/native/x86/qemu_probe.c` and runs |
| 118 | it in two modes through the same `-L`/`-E` guest command as the callers: |
| 119 | |
| 120 | - `maps` reads `/proc/self/maps`, as glibc does during Rust and Go thread startup. |
| 121 | QEMU 8.2.2 crashes internally (`QEMU internal SIGSEGV {code=MAPERR, addr=0x20}`). |
| 122 | - `sigframe` takes SIGALRM while RSP is on a stack laid out like the owned Omega |
| 123 | stack and records RSP at handler entry in an assembly handler. The SysV ABI |
| 124 | requires RSP+8 to be 16-byte aligned there. QEMU 8.2.2 enters handlers 8 bytes |
| 125 | off, so the C caller's reentry handler faults on the `movaps` stack stores in |
| 126 | `omega2_vlen` (#GP, reported as signal 11). |
| 127 | |
| 128 | A mode that does not print exactly `QEMU-PROBE <mode> ok` and exit 0 prints |
| 129 | `NOT_RUN QEMU-ORACLE-UNUSABLE <mode>: …`, and the aggregate ends |
| 130 | `NATIVE-X86 NOT_RUN (not run: … qemu-oracle …)` with exit 1. The emulator is judged |
| 131 | by behavior, not by a version list. Set `OMEGA_NATIVE_X86_BAD_QEMU` to a known-bad |
| 132 | emulator to make `test_build_failures.py` require that refusal; unset, that |
| 133 | control prints NOT_RUN. |
| 134 | |
| 135 | The replacement oracle comes from |
| 136 | <https://download.qemu.org/qemu-10.0.14.tar.xz>, archive SHA256 |
| 137 | `c7230968906fdb5540d803e2af1f515e77590a414f2a4dbd3ec9ada3c47083d0`. |
| 138 | QEMU is a read-only verification oracle, not a bridge build or production |
| 139 | dependency, and does not require an Omega replacement. With the native compiler, |
| 140 | Python, Ninja, pkg-config and GLib development prerequisites installed, a minimal |
| 141 | user-mode build from the verified, unpacked source is: |
| 142 | |
| 143 | ```sh |
| 144 | mkdir qemu-10.0.14/build |
| 145 | cd qemu-10.0.14/build |
| 146 | ../configure --target-list=x86_64-linux-user --disable-system --disable-docs \ |
| 147 | --without-default-features --disable-tools --disable-guest-agent \ |
| 148 | --disable-plugins --disable-slirp --disable-pixman --disable-capstone \ |
| 149 | --disable-fdt --audio-drv-list= |
| 150 | ninja qemu-x86_64 |
| 151 | ``` |
| 152 | |
| 153 | No installation or host binfmt registration is required. Keep its source digest, |
| 154 | configure command, binary digest and `--version` output with the execution |
| 155 | receipt. An emulator PASS still leaves physical x86 execution NOT_RUN. |
| 156 | |
| 157 | The exercised aggregate command is |
| 158 | `python3 tests/native/x86/test_build_failures.py [EMPTY_OUTPUT]`, with the same |
| 159 | environment as the runner above. It requires actual successful C, C++, Python, |
| 160 | Rust (2021 and 2024), Zig and Go executions; failed Zig/Go compilers and missing |
| 161 | toolchains must refuse aggregate PASS. The positive case also exercises the |
| 162 | existing ABI-v2 pointer/status-32, signal-reentry/status-33, stale-identity and |
| 163 | thread controls, private-symbol/TLS isolation, and boundary/API mutants. Added |
| 164 | controls cover nested traps, bad-runtime/status-34 recovery, SysV saved-register |
| 165 | sentinels, and the fixed owned-stack floor after out-buffer allocation. |
| 166 | At the 62775d2a pin all 150 baseline/output comparisons with `0c4cb9ff` passed |
| 167 | byte-for-byte, including unchanged AArch64 freestanding refusals. #26 (`f637021`) |
| 168 | then changed AArch64 output on purpose (f32 and ushort array kinds, the Python |
| 169 | header), so the parity baseline is now the generator at `f637021`, the last |
| 170 | accepted AArch64 contract; later `src/native.om` changes keep AArch64 output |
| 171 | byte-identical to it (the x86 suite's `aarch64_parity` check). The generator at |
| 172 | `f637021^` still matches `0c4cb9ff` on every pre-#26 fixture and output, so the |
| 173 | chain back to the pre-x86 generator is unbroken. The receipts retain the |
| 174 | earlier failing emulator run rather than rewriting it as a pass. #27 respelled |
| 175 | the assembler directives (`OMBR_*` macros in `pre`, `fp`, `fr`, `fv`, `xjmp`) and |
| 176 | the Python loader's library name, so the check first applies those spellings to |
| 177 | the baseline source: a `~`-separated piece of those texts that equals the same |
| 178 | piece at `7af4d11` takes that piece of blob `5115113` (`src/native.om` as #27 left |
| 179 | it), and the two `tb` loader literals take #27's text. Both sides are pinned |
| 180 | objects, so any other change to those texts in the tree still fails parity. |
| 181 | `tests/native/macos/` (the host-word unit, whose C output gains the intended |
| 182 | macOS `#error`) is not a parity fixture. |
| 183 | |
| 184 | ## What Omega produces |
| 185 | |
| 186 | For the default AArch64 target, a unit with no `fn main` is compiled by the seeded |
| 187 | compiler (`seed/out/omc`) in function mode: raw AArch64 words, entry at word 0 |
| 188 | (`docs/one_layer/OMEGESE.md` 9.1). Its rules (`docs/osc/OSC-1-DESIGN.md` |
| 189 | section 7): parameters in x0..x5 (an `edit`/`view` array arrives as its address; its length is part of |
| 190 | its type), result in x0, the runtime table pointer in x7. A trap loads its code into x1, the table into |
| 191 | x0 and branches to the table entry at offset 16; it never returns. `madd` below compiles to three |
| 192 | instructions (`mul x3, x0, x1; add x0, x3, x2; ret`). |
| 193 | |
| 194 | ``` |
| 195 | fn madd a ulong b ulong c ulong to ulong |
| 196 | p = mul a b |
| 197 | ret add p c |
| 198 | end |
| 199 | ``` |
| 200 | |
| 201 | ## The binding |
| 202 | |
| 203 | `src/native.om` is an Omega program. It reads units (the unit's source, a 0 byte, the code length as 8 |
| 204 | decimal digits, the code) and an argument naming the output: `c` is the library source, one C file; |
| 205 | `h`, `python`, `rust`, `zig` and `go` are that library's declarations for those languages (next |
| 206 | section), written from the same parsed signatures. An optional second argument `x86linux` selects |
| 207 | the x86 binding; omitting it keeps AArch64 output. Output appears only after every unit is accepted; |
| 208 | anything outside the supported signature set, and a missing or unknown output word or unknown target, |
| 209 | is refused (exit 110, no output). The default AArch64 C file: |
| 210 | |
| 211 | - embeds each unit's code byte for byte (tests/native/run.sh compares the bytes inside the built |
| 212 | library with the compiler's output); |
| 213 | - enters the code through a small trampoline that saves the callee-saved registers x19..x28 and |
| 214 | d8..d15 on the caller's stack, keeps the caller's stack pointer in x19, sets x7, loads the arguments and |
| 215 | runs the code on the binding's own stack (below); |
| 216 | - gives the code a read-only 32-entry runtime table whose trap entry restores the caller's stack pointer from x19 |
| 217 | and returns the trap code from the exported function (no setjmp/longjmp, nothing crosses the caller's |
| 218 | frame) and whose other entries refuse with status 34, since function-mode units of this ABI use none |
| 219 | of them. The contract for a unit's code is what the trampoline guarantees: it may write x0..x17, |
| 220 | x20..x28, v0..v31 and the flags (x20..x28 and d8..d15 are restored on a return and on a trap); it must |
| 221 | not write x18 (the platform register, which the trampoline does not save), x19 or x29 and must keep sp |
| 222 | balanced. The hosted and the freestanding trampolines give the same contract. OSC-1 (OM-1) allocates x0..x6, x8..x15 and x17, with x7 |
| 223 | the runtime table and x16 scratch; an OM-2 omc with loop-constant hoisting (omega-mv |
| 224 | perf/omc-loop-checks) also keeps loop constants in x20..x26, and its int/float conversions can write |
| 225 | d8..d15. tests/native/v2 decodes `hoist`'s code (x20..x26 and d8..d15 written, x18, x19 and x29 never |
| 226 | named in any unit) and calls both trampolines directly with a hand-assembled unit that writes x20..x29 |
| 227 | and d8..d15, with one mutant per restore pair in each; |
| 228 | - reaches each unit through a two-instruction stub (`bti c`, branch) so the code runs under branch |
| 229 | target identification (BTI) without changing the compiler's bytes; |
| 230 | - exports, per unit, `uint32_t omega_<name>(uint64_t *result, ...)`. |
| 231 | |
| 232 | ### x86-64 SysV entry and trap contract |
| 233 | |
| 234 | The foreign entry point uses the Linux x86-64 SysV C ABI; embedded Omega code |
| 235 | does not. Its private frame ABI stores arguments in the old RBP-relative, |
| 236 | negative-offset slot area. The trampoline supplies the initial 256-byte area |
| 237 | covering 18 storage slots, establishes the owned stack, and enters the selected |
| 238 | six-byte JMP/NOP export slot. The Omega result returns in RAX. |
| 239 | |
| 240 | R12 retains the native stack anchor, R14 points to the read-only runtime table, |
| 241 | and R15 holds the owned-stack floor. The trampoline restores the SysV |
| 242 | callee-saved registers and the caller's stack on both success and trap return. |
| 243 | The compiler's **bare-unit** trap hook must put the trap code in ESI and execute |
| 244 | `jmp *16(%r14)` to runtime entry 2. The binding's trap handler uses the saved |
| 245 | native anchor and returns that code as the public status; it must not terminate |
| 246 | the calling process. A compiler that still lowers bare-unit traps to process |
| 247 | exit does not satisfy this contract. The pinned candidate includes the |
| 248 | bare-unit trap hook; compiler availability is not an execution receipt, and |
| 249 | bridge trap-return exercise remains pending. |
| 250 | |
| 251 | Indirect entry veneers use `endbr64` for Intel CET indirect branch tracking |
| 252 | (IBT) landing. This does **not** support CET shadow-stack enforcement: a trap's |
| 253 | nonlocal return abandons intermediate Omega call frames rather than unwinding |
| 254 | their shadow-stack entries. Do not claim shadow-stack compatibility or run this |
| 255 | binding under enforced shadow stacks. None of these mechanisms changes the |
| 256 | compiler's embedded machine bytes or the public argument/status contract. |
| 257 | |
| 258 | All private `ombr_` and `ombr2_` assembly labels have local binding; private C helpers, |
| 259 | runtime tables and per-translation-unit TLS retain static linkage. Independently generated |
| 260 | C units can be linked together without helper collisions. Their trap/stack/thread state |
| 261 | remains distinct; public `omega_`/`omega2_` exports and compiler machine bytes are unchanged. |
| 262 | `tests/native/test_private_symbols.py` regenerates two separate bindings, checks their |
| 263 | `nm` visibility and exact public exports, exercises traps and concurrent threads, and |
| 264 | requires a `.globl ombr_enter` emitter mutant to fail linking. |
| 265 | |
| 266 | The emitter has finite pools of 16777216 input bytes and 33554432 output bytes (two |
| 267 | 16777216-byte pools, the per-pool maximum) for the complete framed unit set and one |
| 268 | generated output. Input must be strictly smaller than its pool (maximum 16777215 |
| 269 | bytes); output may fill its pools exactly. Exhausting |
| 270 | a pool traps with resource status 6 (process exit 106), before any generated output |
| 271 | is written. This does not relax individual compiler, source-language, slot or unit-count limits. |
| 272 | `tests/native/test_capacity.py` compiles a matching 64-unit frame exceeding the former |
| 273 | 4194304-byte input and 16777216-byte output pools, builds and calls both endpoint units |
| 274 | (`cap00`, and `cap63`, whose generated code lies past byte 16777216 and is therefore read |
| 275 | from the second output pool `outc`) plus `cap15`, |
| 276 | restores each old pool size as a failing mutant, and checks both current overflow |
| 277 | boundaries. Its oversized output control is a hostile framing-only resource probe, |
| 278 | not compiler-custody or behavioral evidence for the deliberately mismatched code. |
| 279 | |
| 280 | Names must be C identifiers, a parameter name may not end in `_len` (the binding names a length |
| 281 | `o_<name>_len`), and each unit name appears once; anything else is refused before any C is written. |
| 282 | |
| 283 | Supported signatures: up to 6 parameters, each `ulong`, `long`, or `edit`/`view` of `ulong`, `uchar`, |
| 284 | `f32` or `ushort` with a fixed length; result `ulong`, `long` or `void`. A length is a decimal number or |
| 285 | the name of an integer constant declared on its own line before the signature as exactly |
| 286 | `const NAME ulong DIGITS` (OMEGESE 9.12); any other spelling of a constant used as a length is refused, |
| 287 | so a shape-specialised unit can be written as one fixed kernel text after a header of constants. |
| 288 | An `f32` array is packed binary32 (4-byte elements, 4-byte alignment) and a `ushort` array is packed 16-bit words (2-byte |
| 289 | elements, 2-byte alignment), for example binary16 bits that the Omega code converts itself. C and C++ |
| 290 | declarations stay `void *` / `const void *`; the generated library checks the element size, alignment, |
| 291 | length and overlap. Python ctypes uses `c_float` and `c_uint16`. Rust and Zig declarations type these |
| 292 | arrays as byte pointers (`*mut u8` / `*const u8`, Zig `?[*]u8`); Go stays `unsafe.Pointer`. |
| 293 | |
| 294 | `OMEGA_NATIVE_OMC=<seed omc> sh tests/native/kinds.sh` binds `fsum.om` and `halve.om`, compares every |
| 295 | lane to a C `_Float16` oracle, refuses misaligned, wrong-length, overlapping and null arrays (status |
| 296 | 32), and requires a mutant that changes fsum's `add` to `sub` to fail. The same script calls both units |
| 297 | through the `python` binding (`tests/native/pykinds.py`): lanes and halving against Python `struct` |
| 298 | values, wrong lengths refused with status 32 and the arrays untouched, `f64`/`int32` arrays for an `f32` |
| 299 | view, `bytes` for an `edit ushort` array and a 2^64 length refused by ctypes; the fsum mutant must fail there too. A unit may hold several functions: the seeded |
| 300 | compiler enters function-mode code at the unit's last function (the leading entry branches to it), so the |
| 301 | binding exports that one and the earlier functions stay private helpers, called directly inside the |
| 302 | embedded code, with any Omega types. Only the last function's signature must be supported |
| 303 | (`tests/native/hsum.om`: two helpers, one of which traps). |
| 304 | |
| 305 | ### Additive public float scalar profile |
| 306 | |
| 307 | `tools/native --float OUTDIR unit.om...` selects the exact seeded compiler |
| 308 | omega-mv `e5b32567` for OM-1 units through `OMEGA_NATIVE_FLOAT_OMC`, sha256 |
| 309 | `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`. |
| 310 | The baseline `OMEGA_NATIVE_OMC` still builds the generator and its pin does not |
| 311 | change. Compiler custody records the selected digest in `work/ident.txt`. |
| 312 | The profile is hosted AArch64 only; `--float --freestanding` and |
| 313 | `--float --target x86linux` refuse before installing outputs. |
| 314 | Direct framed-generator use must likewise select the optional `float` argument |
| 315 | (or `fhost` with the existing host-word capability). Without it, every binding |
| 316 | mode refuses public float signatures with exit 110 and no stdout. The checked |
| 317 | wrapper selects these tokens; it does not broaden the default profile. |
| 318 | |
| 319 | `--float-next` is an explicit draft profile, selected through |
| 320 | `OMEGA_NATIVE_FLOAT_NEXT_OMC`; it pins the omega-mv #1049 candidate at |
| 321 | `7e93ca8e29b3fe81314a88c9f1cb70666fca27f5`, executable sha256 |
| 322 | `d89bdc08ca21ea9726f1117adc791f683287d3698ea112a9db5519df2e79aeec`. |
| 323 | It adds the compiler's scalar `fma` and correctly rounded decimal literals; |
| 324 | it has the same hosted AArch64 OM-1 restriction. It is not an implicit refresh |
| 325 | of the e5, OM-2, baseline generator, or BridgeHost's integrated compiler pins. |
| 326 | |
| 327 | Public parameters/results may be `f32` or `f64` in addition to the existing |
| 328 | integer signatures. C uses `float`/`double`, Rust and Zig `f32`/`f64`, Go |
| 329 | `float32`/`float64`, and Python ctypes `c_float`/`c_double`. The result pointer |
| 330 | has the matching scalar type. No arithmetic conversion is used for the native |
| 331 | frame: the adapter copies the IEEE bits to/from its canonical integer slots. |
| 332 | A float result occupies 4 bytes, not 8, for alignment, overlap and store checks; |
| 333 | a double occupies 8. Invalid arguments and traps leave the result unchanged. |
| 334 | Python callers can pass a ctypes scalar and inspect result storage with |
| 335 | `from_buffer_copy` to retain signaling-NaN payloads without Python float conversion. |
| 336 | The caller must retain the seeded floating environment (round-to-nearest-even, |
| 337 | subnormals enabled); changing FPCR or using fast-math is outside the contract. |
| 338 | |
| 339 | `tests/native/float.py` calls the same f32/f64 identity units from C, Python, |
| 340 | Rust, Zig and Go, comparing raw NaN payload, signed-zero, denormal and infinity |
| 341 | bits. It also checks mixed f32 scalar/view/edit frame slots, array counts, result |
| 342 | and mutable-view alias refusals, null results, unsupported profile combinations |
| 343 | before output, unprofiled framed-generator refusals, explicit `--host` C |
| 344 | marshalling, and kills one result-marshalling mutant per float width. Missing |
| 345 | language toolchains are explicitly NOT_RUN, not PASS. |
| 346 | OM-2/v2 float signatures and freestanding floats remain outside this profile. |
| 347 | |
| 348 | Run both profiles with the baseline generator compiler and available toolchains: |
| 349 | |
| 350 | ```sh |
| 351 | export OMEGA_NATIVE_OMC=/path/to/baseline-734f0a39-omc |
| 352 | export OMEGA_NATIVE_FLOAT_OMC=/path/to/e5b32567-omc |
| 353 | export OMEGA_NATIVE_FLOAT_NEXT_OMC=/path/to/draft-1049-omc |
| 354 | # RUSTC, ZIG and GO may name installed executables not on PATH. |
| 355 | bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 python3 tests/native/float.py |
| 356 | bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 env OMEGA_NATIVE_FLOAT_PROFILE=next python3 tests/native/float.py |
| 357 | ``` |
| 358 | |
| 359 | ## Pure freestanding output |
| 360 | |
| 361 | `OMEGA_NATIVE_OMC=<seed omc> tools/native --freestanding OUTDIR unit.om...` installs |
| 362 | `omega_native.c`, `omega_native.h`, `omega_native.o` and compiler-custody `work/` files. |
| 363 | Direct framed-input users select generator output `freest`; declarations remain output `h`. |
| 364 | Both the default `aarch64linux` target and `--target x86linux` support this output. |
| 365 | For OM-1 the public ABI is unchanged: `uint32_t omega_<name>(uint64_t *result, ...)`, with |
| 366 | `ulong`/`long` scalar arguments and `ulong`, `long` or `void` results. Compiler bytes |
| 367 | are embedded unchanged. A trap returns its status and leaves `*result` unchanged; |
| 368 | success writes the result (zero for `void`), and bad result arguments return 32. |
| 369 | |
| 370 | Unlike hosted output `c`, this mode runs on the caller's stack and needs no pthread, |
| 371 | mmap, heap, TLS or mutable runtime state. Its private trampolines and read-only runtime |
| 372 | table have translation-unit-local linkage. Nested traps unwind to that call's saved |
| 373 | frame, so independent calls and threads do not share trap or stack state. The caller |
| 374 | must provide sufficient stack for the compiled functions and their local/out arrays; there is no separate |
| 375 | guarded stack, stack-allocation status or hosted reentry restriction. |
| 376 | |
| 377 | The emitter validates every source token, including unused helpers. An OM-1 unit remains |
| 378 | integer-scalar only: integer/bool types, decimal integer literals, scalar locals, functions, |
| 379 | arithmetic, comparisons, control flow, contracts and traps. Its arrays and floating-point |
| 380 | operations remain refused. OM-2 additionally admits views, layouts, local/out arrays, unrolling, |
| 381 | rotations, remainder and private `f32`/`f64` operations with an integer-only public ABI. |
| 382 | Public float parameters, results and view elements, globals, text and host words remain |
| 383 | refused with exit 110 and no output. An OM-2 frame without its |
| 384 | `omega-unit` trailer is also refused. Ordinary compiler source |
| 385 | validation still applies. As with hosted transport, framed source and machine bytes |
| 386 | must come from the same pinned compiler invocation; this is not an arbitrary-bytecode |
| 387 | sandbox. `tools/native` snapshots each input once in private scratch storage; profile |
| 388 | detection, compilation, framing and identity all consume that same snapshot. |
| 389 | |
| 390 | The objects are built with `-ffreestanding -fno-builtin -fno-stack-protector`, against the generated |
| 391 | public header. Their unresolved imports must be empty except for the toolchain's |
| 392 | `_GLOBAL_OFFSET_TABLE_` linker marker: **no libc helper is allowed**, including `memcpy`, |
| 393 | `memmove` or `memset`. Failed symbol extraction or filtering is a refusal, |
| 394 | not an empty accepted import set. Any refused import/inspection leaves prior outputs |
| 395 | untouched. `tests/native/test_freestanding.py` exercises epoch increment/MAX refusal, |
| 396 | nested trap unwind, independent scalar units, concurrent threads, non-pure source |
| 397 | refusals, a pthread-emitter mutant, failed inspectors and a deterministic source-swap |
| 398 | control whose old-reread mutant admits mismatched source/code and is caught. |
| 399 | |
| 400 | **OM-2 freestanding** (the same `--freestanding` flag with an OM-2 unit; output `freest`). |
| 401 | An OM-2 unit without host effects is accepted: its compiler bytes are embedded unchanged |
| 402 | and bound as `omega2_<name>`, with the same argument checks as output `c` (views, layouts, |
| 403 | out, overlaps). Each out parameter is a zero-filled, 16-byte-aligned buffer in the entry's |
| 404 | own frame, rounded up to 16 bytes, passed in its slot and copied back to the caller only |
| 405 | after status 0; a nonzero status (a trap, a refused argument) leaves the caller's buffer as |
| 406 | it was. The runtime table has one entry, the trap, and nothing else: no TLS, no heap, no |
| 407 | stack mapping, no pthread and no stack guard, so the caller must provide a stack large |
| 408 | enough for the compiled functions. There are no C library calls: small static byte-transport |
| 409 | helpers zero and copy the private out frame through volatile byte stores so C optimization |
| 410 | cannot substitute libc calls. The copy source is the entry's private out frame, disjoint from |
| 411 | the checked caller destinations; the existing caller-overlap refusal and status-0 copy-back |
| 412 | rule are unchanged. |
| 413 | |
| 414 | A borrowed byte view (`view uchar *`) is admitted on this profile, on both targets, with no libc. |
| 415 | The scan never inspects past the bound: an index at or past `len` traps inside the unit, and the |
| 416 | wrapper does not walk the pointer. An empty view is admitted, including a NULL pointer with length |
| 417 | 0, and its length is 0. A nonempty NULL pointer is refused with status 32 before the unit runs, and |
| 418 | the result slot is left unchanged. `tests/native/freestanding/pathlen.om` is that scan (`omega2_pathlen`). |
| 419 | `tests/native/test_freestanding_pathlen.py` compares it with a bounded `memchr` for every length |
| 420 | 0..256 and every terminator position in that window (WolframLanguageEvaluator: |
| 421 | `Sum[n + 1, {n, 0, 256}] + 2` -> 33155), plus three guard pages placed on the next byte, and kills |
| 422 | six source mutants and one generated nonempty-NULL mutant on AArch64 and under x86 QEMU. That is |
| 423 | host and EMULATED evidence, not chip qualification. |
| 424 | |
| 425 | Private `f32` and `f64` use the target's hardware floating-point instructions. The caller |
| 426 | must enable hardware FP and provide its normal ABI control modes; the wrapper does not |
| 427 | configure FPCR/MXCSR control bits. FP exception/status-flag preservation is not promised. |
| 428 | This is not soft-float, kernel/firmware FP-state management, or firmware qualification. |
| 429 | Public arguments/results and view elements remain integer-only. The source whitelist |
| 430 | parses decimal/exponent literals with optional `f32`/`f64` suffixes and function parameter |
| 431 | names separately from their types; an unsupported type must not become an accepted |
| 432 | identifier through a malformed declaration. |
| 433 | |
| 434 | The existing binary64 oracle is unchanged: exact C bit comparisons include negative zero, |
| 435 | a subnormal and quiet-NaN operands. The x86 compiler reproduces Arm's positive default NaN; |
| 436 | that oracle corrects only C's exact negative-indefinite result for signed-zero divided by |
| 437 | signed-zero, never an Omega result or operand NaN. Its controls reject a different payload |
| 438 | and nonzero status and require negative operand-NaN propagation in both positions. |
| 439 | |
| 440 | The separate binary32 oracle (`tests/native/freestanding/f32.{om,c}`) uses round-to-nearest, |
| 441 | ties-to-even and gradual underflow. Other FP control modes are not qualified. Non-NaN |
| 442 | arithmetic results must match C's non-contracting IEEE operations bit-for-bit; arithmetic |
| 443 | NaNs compare by class only, with `0x7fffffff` as the documented **comparison** |
| 444 | canonicalization. Operand cases include that canonical qNaN and other payloads. NaN-result |
| 445 | payloads are not asserted, including raw zero-divided-by-zero bits. Neither the bridge nor |
| 446 | the caller rewrites integer-ABI outputs: the identity operation must preserve even NaN |
| 447 | operand bits exactly, and bare/hosted raw output streams must agree for the same compiler. |
| 448 | Separate multiply/add, RNE ties and subnormal controls are backed by the Wolfram queries |
| 449 | in the FP32 receipt. Source mutants change add to subtract, widen a product before add, |
| 450 | and incorrectly canonicalize an integer identity result; all must be caught. |
| 451 | |
| 452 | The bounded source-name registry contains at most 1024 **distinct spellings**, not assignment |
| 453 | occurrences. Reusing a name, including at full capacity, does not consume another slot; a new |
| 454 | name beyond the bound refuses with exit 110. Fixed view extents may use the same earlier |
| 455 | positive `const NAME ulong DIGITS` syntax as public extents. A constant extent is consumed |
| 456 | without registering a following type as a parameter name; layout views and `fresh` checks |
| 457 | retain their existing boundaries. |
| 458 | |
| 459 | With an OM-2 unit, `--freestanding` also installs `omega_api_decl.h` and |
| 460 | `omega_api_defs.{c,o}` (output `fapic`): the same prototypes as output `apih`, but each |
| 461 | definition calls `__builtin_trap()` on a nonzero status instead of `abort()`, so the |
| 462 | definition object imports no C library function either. It does not install `omega_api.h`, |
| 463 | whose inline wrappers call `abort()`. The two objects are inspected together: a global |
| 464 | definition in one satisfies a reference in the other (the wrappers calling `omega2_*`), |
| 465 | and every other unresolved import must be absent except `_GLOBAL_OFFSET_TABLE_`. |
| 466 | `tests/native/test_freestanding_om2.py` (run by `tests/native/v2/run.sh`, step 10b) links the |
| 467 | two objects with `-r -nostdlib`, requires no runtime imports, and compares the same caller |
| 468 | against hosted output. It exercises FIPS 180-4 digests of `sha256-om2.om` (empty, abc, the |
| 469 | 448-bit message, a million `a` through a split update), untouched out buffers after refusal/trap, |
| 470 | four hashing threads, private-f64 bit parity and the trap wrapper (exit 133, SIGTRAP). |
| 471 | Attributed mutants remove copy-back, write the wrong zero fill, copy on trap, reintroduce |
| 472 | a real libc import, and restore duplicate-name exhaustion. Scanner-only framed controls |
| 473 | check the exact distinct-name boundary, named/fresh extents, layout-view alignment and |
| 474 | private-type/host/storage refusals; deliberately reused frame code is never executed. |
| 475 | With `--target x86linux --freestanding` the same OM-2 units are bound through the x86 |
| 476 | SysV adapter, with the same out-buffer and import rules. `tests/native/x86/suite.py` |
| 477 | (step `freestanding_om2_x86`) cross-builds `fsom2.c` against that output and runs it under |
| 478 | QEMU: same digests, untouched out buffers and four threads, the trap wrapper (`ud2`, SIGILL), |
| 479 | and the copy-back mutant must leave the pre-call fill in all four digests. That is EMULATED |
| 480 | only; native x86 is NOT_RUN. |
| 481 | |
| 482 | `tests/native/test_freestanding_f32.py --out OUTDIR [--target x86linux]` separately |
| 483 | qualifies private FP32 behind the integer-only public ABI: a static no-libc ELF has no |
| 484 | undefined symbol, interpreter or TLS and emits the exact raw hosted byte stream. |
| 485 | All fourteen public-float parameter/result/fixed-view/edit/out/dynamic-view/edit fixtures |
| 486 | compile before **direct generator** refusal110 with empty stdout, then CLI refusal110 |
| 487 | without installed output. The direct check cannot mistake a generator crash for refusal. |
| 488 | The unused host-helper control deliberately reuses a clean frame's code solely to reach |
| 489 | the whole-source scanner, requires refusal110/no output, and is never executed. |
| 490 | Two counted generator mutants remove private-FP32 admission or its literal suffix and |
| 491 | must restore refusal110; three source mutants and a wrong-result control must fail their |
| 492 | exact runtime assertions. The OM2 test invokes this on AArch64; the x86 gate's |
| 493 | `freestanding_f32_x86` step uses its existing guest runner for both bare and hosted callers. |
| 494 | |
| 495 | `tests/native/test_freestanding_aggregate.py --regalloc CUDAPP_REGALLOC_TREE --core |
| 496 | CUDAPP_CORE_TREE --out OUTDIR [--target x86linux]` qualifies the actual six-unit composition |
| 497 | without depending on an unpinned checkout location. The allocator owner’s portable |
| 498 | `regalloc.om`, `regalloc_ir.om`, `regalloc_live.om` each receive exactly an `om2` line in an |
| 499 | immutable input copy; the originals are unchanged. CoreUtil's `native.om`, `cubin.om` and |
| 500 | `ampere.om` are already OM-2 and copied unchanged. The receipt records both original-source |
| 501 | and composed-input hashes. One generated library contains all six units. |
| 502 | The caller executes allocation, IR/liveness decisions, a full-size graph edit, private |
| 503 | log-one, padded NOP encoding and CUBIN metadata refusal; it is not the full CUDApp test suite. |
| 504 | A linked `-nostdlib -static` Linux ELF must have no undefined symbol, interpreter or TLS, |
| 505 | run successfully and produce bytes identical to the same hosted caller. A wrong-length |
| 506 | large fixed span must refuse with status 32 and leave outputs unchanged; the wrong-result |
| 507 | control must exit 90. C in this test is only an ABI/syscall verification oracle, never the |
| 508 | implementation of those algorithms. |
| 509 | |
| 510 | Adding `--api CUDAPP_API_TREE` composes the actual portable `api_policy.om`, |
| 511 | `api_mm_plan.om` and whole `api_at_plan.om` from `om/components/` with the same exact `om2` |
| 512 | prefix, for nine units in one library. No attention modes are removed. Portable OM-1 |
| 513 | sources are **not** accepted by the freestanding array path without that explicit |
| 514 | composition; the OM-1 scalar boundary is unchanged. The additional bare caller exercises |
| 515 | policy remainder acceptance/refusal and matmul plan edits against Wolfram-derived words; |
| 516 | short views leave both result and all input words untouched. It calls attention modes |
| 517 | 0, 7, 22 and 23: integer planning/refusal, scale validation (including signed zero, |
| 518 | finite limits, infinity and NaN), private-FP32 conversion and the binary64 Newton path. |
| 519 | Exact output bits are derived with per-operation rounded Wolfram queries; integer |
| 520 | outputs are not canonicalized. Mutating the policy remainder predicate exits14, the |
| 521 | matmul output write exits15, attention scale validation exits19 and attention's FP32 |
| 522 | output packing exits20. Each mutation applies exactly once in a separate copied input; |
| 523 | baseline snapshots remain unchanged. This is not the full CUDApp API test suite. |
| 524 | |
| 525 | Run every acceptance command in a device-free namespace, including mutants and emulation: |
| 526 | `bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 COMMAND`. |
| 527 | No NVIDIA, cuse or VFIO device is available inside it. Native AArch64 host evidence and |
| 528 | x86 EMULATED evidence do not qualify firmware FP state, physical x86 or GPU execution. |
| 529 | |
| 530 | Receipts: [first pure freestanding OM2 profile](../evidence/native-freestanding-om2-nolibc/README.md) |
| 531 | records the immutable eight-unit profile at `12f8132c`, including its then-correct whole |
| 532 | attention/private-FP32 refusal. The [private-FP32 followup](../evidence/native-freestanding-f32/README.md) |
| 533 | records the new nine-unit profile, bit oracles, refusal boundaries and fresh regression |
| 534 | commands. The full AArch64 V2 gate's known hoist failure is not a green gate; its exact |
| 535 | fresh verdict belongs in that receipt. Physical x86, firmware and chip qualification |
| 536 | remain NOT_RUN. Drake must review and approve this draft contract before merge. |
| 537 | |
| 538 | ## The declarations for each language (`tools/native`) |
| 539 | |
| 540 | `OMEGA_NATIVE_OMC=<seed omc> tools/native OUTDIR unit.om...` compiles the units with the selected |
| 541 | target's compiler, runs the generator once per output word and installs, into OUTDIR: |
| 542 | |
| 543 | | file | for | how a program uses it | |
| 544 | |---|---|---| |
| 545 | | `omega_native.c` | the library source | built into `libomega_native.so` by the same command | |
| 546 | | `omega_native.h` | C and C++ | `#include "omega_native.h"` (`extern "C"` inside for C++) | |
| 547 | | `omega_native.py` | Python 3 (ctypes) | `import omega_native`; loads `libomega_native.so` from beside itself | |
| 548 | | `omega_native.rs` | Rust 1.82 or later, edition 2021 or 2024 | `mod omega_native;` beside the crate root; link with `-L OUTDIR` | |
| 549 | | `omega_native.zig` | Zig 0.13 | `@import("omega_native.zig")`; build with `-L OUTDIR -lomega_native -lc` | |
| 550 | | `omega_native.go` | Go (cgo) | package `omeganative`: a folder of that name holding the file, `omega_native.h` and the library | |
| 551 | | `work/` | the test driver | the generator and each unit's compiled code; not an interface | |
| 552 | |
| 553 | Every file carries the unit's Omega signature line as a comment above its declaration, the five status |
| 554 | constants (0, 32, 33, 34, 35) and the parameter names prefixed `o_` (so no language's reserved words |
| 555 | collide). The scalar type is the language's unsigned 64-bit integer, an array is a pointer then a |
| 556 | `uint64_t` count, the status is unsigned 32-bit: C `uint64_t` / `void *` / `const void *`; Rust `u64` / |
| 557 | `*mut u64`, `*mut u8`, `*const u64`, `*const u8` (declared in an `unsafe extern "C"` block); Zig `u64` / |
| 558 | `?[*]u64`, `?[*]u8`, `?[*]const u64`, `?[*]const u8`; Go `uint64` / `unsafe.Pointer` to memory holding |
| 559 | no Go pointers. Python checks instead of trusting: a scalar is an `int` in 0 .. 2^64-1 (a `long` is |
| 560 | passed as its two's-complement bits) and anything else, including a negative or an out-of-range value, |
| 561 | raises `ctypes.ArgumentError` rather than being truncated; an array is a ctypes array of its element type |
| 562 | (`POINTER(c_uint64)` for `edit`/`view ulong`, `POINTER(c_ubyte)` for `edit uchar`, `c_char_p` for `view |
| 563 | uchar`, which also takes `bytes`), and an `edit` array must be writable, so `bytes` are refused there. The |
| 564 | result pointer is `uint64_t *`, `ctypes.POINTER(c_uint64)` (pass `ctypes.byref`), `*mut u64`, `?*u64`, |
| 565 | `*uint64`. The Go file wraps each C function as `Omega_<name>` so the caller needs no cgo of its own; its |
| 566 | preamble includes the generated header (so the Go side and the C side cannot disagree) and bakes in no |
| 567 | run-time path: the program's build names the folder (`CGO_LDFLAGS=-Wl,-rpath,<folder>`) or |
| 568 | `LD_LIBRARY_PATH` does. |
| 569 | |
| 570 | Everything is produced in a scratch folder and installed together after the library compiles. A unit |
| 571 | outside the subset, or a name the binding cannot carry, is refused by name (exit 110): nothing is |
| 572 | installed and a previous run's outputs in OUTDIR stay as they were. The library is compiled with its own |
| 573 | header included (`-include omega_native.h`): a declaration that disagrees with a definition fails that |
| 574 | build, so the C file and the header cannot drift apart. The other four files are checked by the |
| 575 | qualification below, where each language builds its caller against its generated file only and a |
| 576 | one-word type change in the generator must make that build or run fail for the stated reason. |
| 577 | |
| 578 | ## Contract |
| 579 | |
| 580 | | | | |
| 581 | |---|---| |
| 582 | | scalar argument | `uint64_t`, the canonical bits of its type; a `long` is its two's-complement bits (-3 is 18446744073709551613) | |
| 583 | | array argument | `void *` (`const void *` for `view`) then `uint64_t` element count, which must equal the declared length; elements are 8 bytes (`ulong`), 1 byte (`uchar`), 4 bytes (`f32`, IEEE-754 binary32) or 2 bytes (`ushort`), and the address must be aligned to the element size | |
| 584 | | result | written only on status 0; a `void` function writes 0 | |
| 585 | | status 0 | success | |
| 586 | | status 1..14 | the Omega trap code (1 overflow, 2 divide by zero, 3 bounds, 4 loop bound, 5 conversion, 6 resource, 7 shift, or a `trap N` code) | |
| 587 | | status 32 | foreign argument refused: null pointer, wrong length, misaligned, address overflow, a writable array overlapping any other array or the result | |
| 588 | | status 33 | reentry on the same thread (for example from a signal handler during a call) | |
| 589 | | status 34 | the code reached a runtime entry this ABI does not provide | |
| 590 | | status 35 | the binding could not map its stack for this thread | |
| 591 | |
| 592 | Buffers stay owned by the caller and are borrowed for the call only; Omega keeps no address after it |
| 593 | returns. Writes made before a trap stay visible (no rollback). Calls on different threads are independent. The runtime table is one read-only table shared by |
| 594 | every call and thread (the code only reads it); a write to it would fault. |
| 595 | |
| 596 | Stack: on its first call from a thread the binding maps 8 MiB of stack for that thread above an 8 MiB |
| 597 | no-access guard, and frees both when the thread exits. The caller's own stack size does not matter (a |
| 598 | 4,000,000-byte local array runs from a 256 KiB C thread and a default 2 MiB Rust thread). A function-mode |
| 599 | unit has no call cycles and at most 4 MiB of local arrays per function, so a frame that would pass the |
| 600 | bottom starts inside the guard and the process faults there; memory below the guard is never written. |
| 601 | That fault is a crash, not a status: in function mode the seeded compiler does not check the stack |
| 602 | floor before reserving a frame (program mode traps 6 instead). A clean status needs that check in the |
| 603 | compiler; it is a compiler gap, not something the binding can add around the code. |
| 604 | |
| 605 | Host words are not an isolation boundary: permitted function-mode operations |
| 606 | make Linux system calls directly in the calling process, using its descriptors. |
| 607 | Legacy x86 `read`/`write` use the `om4`/`VT_SYS` path and `xio`, permitted in bare |
| 608 | units. With the separately pinned hosted compiler, `xhost` admits the same bounded |
| 609 | OM-2 subset as AArch64; OM-1 units and other host words still get compiler error9. |
| 610 | Its helpers preserve the binding's R12 native anchor, R14 runtime table and R15 |
| 611 | stack floor, use RBX for their saved-slot snapshot and restore R13 scratch before |
| 612 | returning. The program-mode syscall emitters are shared, not duplicated. |
| 613 | macOS numbers its system calls differently, so an AArch64 unit whose code holds an `svc` instruction |
| 614 | word is Linux-only: the generator puts `#error` for that unit under `__APPLE__` (see Platforms). |
| 615 | |
| 616 | Signals: a call from a signal handler while a call is running on the same thread returns 33. A handler |
| 617 | that leaves Omega code with `siglongjmp` abandons the call; every later call on that thread returns 33. |
| 618 | |
| 619 | ## AArch64 qualification (`OMEGA_NATIVE_OMC=<seed omc> sh tests/native/run.sh`) |
| 620 | |
| 621 | The compiler is pinned by sha256 (`734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`, |
| 622 | omega-mv PR #696). Expected values come from receipts, not from Omega: |
| 623 | (2^64-1)*2+5 mod 2^64 = 3 (calc:93e7b00a); 1311768467463790320*18364758544493064720+1085102592571150095 |
| 624 | mod 2^64 = 3637949782307626511 (calc:9bf5b67e, Wolfram agrees); -13 as 64-bit bits = 18446744073709551603 |
| 625 | (calc:cbb0735b); 0+1+...+999999 = 499999500000 (calc:3f197279). |
| 626 | |
| 627 | The six callers (C, C++, Python, Rust, Zig, Go) take every Omega declaration from their generated file |
| 628 | (the run fails if any caller source declares an `omega_` function, sets ctypes `argtypes`, loads the |
| 629 | library itself or carries its own cgo). All six check values, wrap-around, signed bits, a signed overflow |
| 630 | trap with the result left unchanged, a trap after two buffer writes (writes visible, result unchanged), a |
| 631 | successful buffer call, a refused null result (C++: a wrong length) and the six-parameter unit `mix` |
| 632 | (`view`/`edit` `uchar` and `ulong` arrays, no result: success with the void result written as 0, a `trap |
| 633 | 9` after two writes with the result unchanged, a conversion trap 5 after one write). The Python caller |
| 634 | also checks that the binding refuses 2^64+3, -1 and 2.0 as scalars and `bytes` for an `edit` array, and |
| 635 | that a call works after those refusals. The C caller also checks a null buffer, a wrong length, |
| 636 | misalignment, result/buffer overlap, a view overlapping an edit array, a call after traps, reentry from a |
| 637 | signal handler (status 33), a trap from a frame holding a 4,000,000-byte local array, that array on a |
| 638 | 256 KiB thread, and that x19..x28 and d8..d15 keep the caller's values across a normal return and a trap |
| 639 | raised in a callee of the exported function, and runs the hoisting unit on two threads. |
| 640 | The Rust caller runs the array on a default thread and is built twice, under edition 2021 and edition |
| 641 | 2024, with warnings as errors. The C caller runs a second time against a library built with BTI enforced. |
| 642 | `tests/native/reference.c`, prototypes for the seven test units (with `hsum`, bound at its last function) |
| 643 | written by hand from this contract, is compiled with the generated header included: a disagreement is a |
| 644 | conflicting-types error. The generator |
| 645 | is shown to refuse a non-C unit name, a parameter ending in `_len` and a repeated unit name, and to accept |
| 646 | the same unit once; `tools/native` is shown to refuse a unit with a `uchar` result by name, with exit 110, |
| 647 | leaving a previous run's outputs untouched. Not exercised: status 34 and 35 (no supported unit reaches |
| 648 | another runtime entry; mapping failure is not induced). |
| 649 | |
| 650 | Qualification requires an executed PASS for each caller (`c`, `c-bti`, `cpp`, `python`, `rust`, `zig`, |
| 651 | `go`). A present Zig/Go toolchain that fails to build emits `FAIL` and makes the runner exit nonzero. |
| 652 | A missing toolchain emits `NOT_RUN` and makes the runner exit nonzero, not a qualified PASS. Run |
| 653 | `OMEGA_NATIVE_OMC=<seed omc> sh tests/native/test_build_failures.sh` to check build-failure and |
| 654 | missing-toolchain controls, followed by positive calls with the real Zig and Go toolchains. The |
| 655 | historical `evidence/native-call-v1/run.log` predates this runner correction and is not rewritten. |
| 656 | |
| 657 | Red before green (this change): with the generator of commit e7777ca, the C caller dies with SIGILL |
| 658 | under BTI, and the 4,000,000-byte array on a 2 MiB thread dies with SIGSEGV; with this generator both |
| 659 | pass. Extra receipts: 5+20+7 = 32 (calc:08302bc4), (7+1)+7 = 15 (calc:e44bce3f), 5+20+300 exceeds 255 |
| 660 | by 70 (calc:a6a8bb76), 4,000,000 bytes is 0.954 of 4 MiB (calc:ffff21b2). Negative control: madd's `add` changed to |
| 661 | `sub` in the code must make the C caller fail. |
| 662 | |
| 663 | Separate claims, not made here: source translation (ABI v0) and GPU execution are qualified on their |
| 664 | own. These historical qualification results cover AArch64 Linux, not the x86 target. |
| 665 | |
| 666 | `f32` arrays and constant lengths (2026-10-26, for `pytorch/`): exercised by |
| 667 | `pytorch/tests/test_omega_torch.py` (class `Binding`: a `const L ulong 6` f32 unit binds with element |
| 668 | size 4 and the right writable flags; a `const L uint 6` length and an `f64` array are refused with exit |
| 669 | 110 and no output) and by every PyTorch op test, which calls f32 units through this binding. Those tests |
| 670 | use the omega-mv main compiler (`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`, |
| 671 | omega-mv `369dbc96`), because floats are newer than the pin above. `tests/native/run.sh` with the pinned |
| 672 | compiler still prints `NATIVE-CALL PASS` with this generator. |
| 673 | |
| 674 | After merging main `7af4d11` (2026-11-04), the f32 kinds are #26's and this change adds only the |
| 675 | named lengths (the unit start is kept in `st 9`). The generator now takes its output word as argument 1, |
| 676 | so the PyTorch glue and the `Binding` tests call it with `c`; before that fix every unit was refused |
| 677 | with exit 110, which the two refusal tests could not tell from a real refusal. Rerun: 22 tests OK |
| 678 | (`evidence/omega-torch-m1/tests-merge-main-7af4d11.log`); with `pparam` reverted to `tknum` (named |
| 679 | lengths unread) `test_const_f32_bound` fails and `Ops.test_mm` errors with the refusal (exit 110) |
| 680 | (`evidence/omega-torch-m1/mutant-const-length-tknum.log`). |
| 681 | |
| 682 | Which compilers reach a named length (issue #20, 2026-11-04, `evidence/issue-20-const-length/red-green.log`): |
| 683 | the AArch64 OM-1 pin `734f0a39` refuses `const` itself (`omc: line 8: error 9`), so through |
| 684 | `tools/native` an AArch64 OM-1 unit with a named length stays refused until that pin moves past omega-mv |
| 685 | #806. The x86 pin `be8c5130`, omega-mv main `b4f45121` and `2c824805` accept it and emit code |
| 686 | byte-identical to the literal form. With `--target x86linux`, main `7af4d11` refuses the unit with exit |
| 687 | 110 and this generator binds it; the bindings differ from the literal unit's only in the echoed |
| 688 | signature comment, and a C caller under QEMU 10.0.14 gets the same result and the same wrong-length |
| 689 | status 32 (EMULATED; physical x86 NOT_RUN). An undeclared name is refused by the compiler (error 16). |
| 690 | |
| 691 | Zig and Go: run with Zig 0.13.0 and Go 1.27.3 (official aarch64 archives, checksums from |
| 692 | ziglang.org/download/index.json and go.dev/dl, unpacked in the user's ~/.local/opt). Both callers pass |
| 693 | their checks (12 each in this change). The library is linked with `-soname libomega_native.so`: without that name, Zig records the |
| 694 | library as `./libomega_native.so` and the caller fails to load outside the build folder (red: dd8b9a9; |
| 695 | green: 1e40844). The embedded code is unchanged by the name. |
| 696 | |
| 697 | Generated declarations (this change): before it, each caller typed its own prototypes and a wrong |
| 698 | type there was the caller's mistake to find. Now `tools/native` builds everything and the generator |
| 699 | writes the six files above from the parsed signatures; the C output is byte for byte what the previous |
| 700 | generator wrote. The run adds: the no-hand-declaration check; the hand-written reference prototypes; |
| 701 | the `tools/native` refusal; refusals of a missing and of an unknown output word; and five generator |
| 702 | mutants, one per binding, each changing one scalar type word on the generator's text line (`uint64_t` |
| 703 | to `uint32_t`, `c_uint64` to `c_uint32`, `u64` to `u32` twice, `uint64` to `uint32`). The run checks |
| 704 | that each mutant changes exactly one generator line and is caught for the stated reason: the header |
| 705 | mutant by the library build (`conflicting types for omega_madd`), the Python mutant by wrong results |
| 706 | (seven of the eighteen checks fail: the scalar is truncated to 32 bits), the Rust mutant by `mismatched |
| 707 | types`, the Zig mutant by `type 'u32' cannot represent integer value`, the Go mutant by `cannot use ... |
| 708 | as uint32 value`. Found by reading the output before the run, not by a test: the first Go wrapper |
| 709 | called `C.omega_(` with no name; the test that would have caught it is the Go build, which this |
| 710 | change runs. Review of the first version of this change led to: the Rust block declared `unsafe |
| 711 | extern` (edition 2024 rejects a plain `extern` block); Python scalars range-checked and arrays typed |
| 712 | per kind instead of `c_void_p` (which took `bytes` for a writable array and truncated scalars |
| 713 | silently); the Go preamble including the header instead of repeating prototypes, with no baked |
| 714 | run-time path; `tools/native` producing in a scratch folder, installing together, and naming the |
| 715 | refused unit. |
| 716 | |
| 717 | ## Platforms: macOS arm64 (`sh tests/native/macos/run.sh bundle|run DIR`) |
| 718 | |
| 719 | One generated AArch64 C file builds on Linux (ELF) and on macOS arm64 (Mach-O); any other object |
| 720 | format stops at `#error`, and so does any other architecture than AArch64 (x86-64 has its own target, |
| 721 | `--target x86linux`, ELF only). The freestanding object is ELF only. Only the assembler spelling |
| 722 | differs, through the `OMBR_*` macros at the top of `omega_native.c`: on Mach-O, C names carry a leading |
| 723 | underscore, the code goes in `__TEXT,__text`, there is no `.type`, `.size`, `.local` or `.hidden` (a |
| 724 | symbol that is not `.globl` stays local to its object), and `ombr_trap`/`ombr_no_entry` are |
| 725 | `.alt_entry` points of `ombr_enter` with the assembler-local label `Lombr_leave`, so the linker cannot |
| 726 | split them from the shared exit path. On ELF the macros spell the directives the previous generator |
| 727 | wrote: for the AArch64 v1, ABI v2, freestanding and x86-64 units, `tools/native` output from this |
| 728 | generator and from 7af4d11's differs only in the text of `omega_native.c` and `omega_native.py`; the |
| 729 | libraries, the freestanding object and the other declaration files are byte-identical. |
| 730 | |
| 731 | - x18 is reserved on macOS. The seeded compiler's code uses x0..x16, x29 and x30; the macOS runner |
| 732 | disassembles each embedded unit and refuses any `x18`/`w18` (with a control that writes x18). |
| 733 | - `hint #34`/`hint #38` (BTI landing pads) execute as no-ops where BTI is not enforced. |
| 734 | - The stack mapping uses `MAP_NORESERVE` and `MAP_ANONYMOUS`, both provided by macOS with `-std=gnu11`; |
| 735 | the pthread key destructor frees each thread's stack on thread exit on both systems. |
| 736 | - Units with host words build on Linux only (see Host words). |
| 737 | - The Python binding loads `libomega_native.dylib` when `sys.platform` is `darwin`, otherwise |
| 738 | `libomega_native.so`, from its own folder. |
| 739 | |
| 740 | Generating needs Linux AArch64, because the seeded compiler is a Linux AArch64 executable: run |
| 741 | `tools/native OUTDIR unit.om ...` there and copy `omega_native.c`, `omega_native.h` and |
| 742 | `omega_native.py` to the Mac. Build there with |
| 743 | `clang -std=gnu11 -O2 -fPIC -shared -install_name @rpath/libomega_native.dylib -include omega_native.h -o libomega_native.dylib omega_native.c`. |
| 744 | |
| 745 | macOS qualification, in two steps: `OMEGA_NATIVE_OMC=<seed omc> sh tests/native/macos/run.sh bundle DIR` |
| 746 | on Linux AArch64 runs `tools/native` on the seven test units and writes the bundle; `sh DIR/run.sh run |
| 747 | DIR` on macOS arm64 needs only clang, its tools and python3. It builds the dylib, compares each unit's |
| 748 | embedded bytes with the compiler's output, checks for x18, runs the C and Python callers, checks that |
| 749 | the add -> sub mutant of `madd` is both embedded as generated and caught by the C caller, and checks |
| 750 | that the host-word unit `tests/native/macos/hostw.om` is refused by the macOS build. Last line: |
| 751 | `NATIVE-CALL-MACOS PASS`. The C++, Rust, Zig and Go callers, the BTI-enforced build, ABI v2 units and |
| 752 | the measurements are exercised on Linux only. |
| 753 | |
| 754 | ## G1 sample (`OMEGA_NATIVE_OMC=<seed omc> sh tests/native/g1/run.sh`) |
| 755 | |
| 756 | omega-mv #624 milestone G1: `fn calc i0 ulong i1 ulong to ulong` computing `(i0 + i1) * (i0 - i1)` modulo |
| 757 | 2^64 with a `new ulong` SSA array in the lowering form of `spec/universal/translation-v1.md` section 5. |
| 758 | `OMEGA_G1_UNIT` names the unit: by default `tests/native/g1/calc.om` (hand-written, no semantic `note` |
| 759 | line); `tests/native/g1/calc.lowered.om` is the unit the omega-mv pipeline generated from C |
| 760 | (`c-import | lower`, producing command and commit in `tests/native/g1/README.md`). The bound function's |
| 761 | name and arity come from the unit's last `fn` line and must be `calc` with two inputs (what the callers |
| 762 | and the reference implement). `tools/native` builds it; the C, C++, Python, Rust, Zig and Go callers read |
| 763 | `i0 i1` lines and print `i0 i1 status result`, and each output must equal, line for line, the Python |
| 764 | bigint reference (`tests/native/g1/reference.py`) on 81 vectors: every ordered pair of 0, 1, 2, 2^32, |
| 765 | 2^63-1, 2^63, 2^63+1, 2^64-2, 2^64-1. Negative control: the unit with its first `sub` changed to `add` |
| 766 | must disagree. The run writes `build/g1/manifest.json`: the unit, its function and arity; the source |
| 767 | identity (sha256 of the `.om` bytes); the semantic identity (section 4) when the unit's first line is |
| 768 | `note omega.universal.lower.v1 semantic <hex>`, else null; the omc, `src/native.om` and `tools/native` |
| 769 | sha256; the code, library and binding sha256; ISA aarch64, the ELF class and machine from `readelf -h`, |
| 770 | ABI `omega-native-v1`, OS Linux; and each caller's status (PASS, FAIL or NOT_RUN for a missing |
| 771 | toolchain) with its vector count and toolchain path. |
| 772 | |
| 773 | ## ABI v2: OM-2 units (omega-mv #747, contract `spec/omegese-om2.md` section 6, errata E1 and E5) |
| 774 | |
| 775 | ABI v2 adds to every v1 rule and check above; nothing in v1 changes. An OM-2 unit is one whose first |
| 776 | line that is not a note (a line whose first word is `note`) is exactly `om2`; a first such line that |
| 777 | starts with the word `om2` but is not exactly `om2` (`om2 diag`, `om2 fmt`) is refused. Every other |
| 778 | unit is OM-1 and gets the v1 binding, byte for byte what the generator of f637021 writes (checked on |
| 779 | every unit in `tests/native` and `tests/native/g1`, alone and as the v1 suite's set, in all six outputs; |
| 780 | the baseline was 3f05908 until #26 (f637021)'s f32 and ushort kinds changed the Python output for every unit). |
| 781 | |
| 782 | **Symbols.** Every OM-2 unit is bound as v2, whatever its parameter kinds (erratum E1): each |
| 783 | `export fn NAME` (source order) gets `uint32_t omega2_NAME(uint64_t *result, ...)`; without any |
| 784 | `export`, the last `fn` is bound (the v1 rule). No `omega_NAME` is emitted for an OM-2 unit, so a caller |
| 785 | built from v1 declarations fails to link (the explicit refusal), and every binding names the v2 symbol. |
| 786 | Functions that are not exported stay private: no symbol. All exports of a unit share its embedded code |
| 787 | and the library's one runtime (stack, table, reentry flag). Bound names (v1 unit names and v2 exports) |
| 788 | share one table: a repeat is refused. |
| 789 | |
| 790 | **AArch64 calling convention** (agreed with the OM-2 compiler lane, omega-mv S4, ledger L834). |
| 791 | Parameters go to x0..x5 in order, result in x0, runtime table in x7, trap through entry 2 with its code in x1 (as v1): |
| 792 | |
| 793 | | Omega parameter | slots | C argument(s) | checks before any Omega code runs (status 32) | |
| 794 | |---|---|---|---| |
| 795 | | `x ulong`, `x long` | 1 | `uint64_t o_x` (a long is its two's-complement bits) | none | |
| 796 | | `a view T *`, `a edit T *` (unsized) | 2: pointer, then the element count | `const T *o_a` (`T *o_a` for edit), `uint64_t o_a_len` | if `len > 0`: not NULL; aligned to sizeof(T); `len * sizeof(T)` fits in 64 bits; `ptr + len*sizeof(T)` does not wrap (the end may be at most 2^64-1). `len == 0` is the empty view with any pointer, NULL included, and adds no range | |
| 797 | | `a view T N`, `a edit T N` (sized) | 1 | `const T *o_a` / `T *o_a`, `uint64_t o_a_len` | the v1 checks: not NULL, count == N, aligned, no wrap | |
| 798 | | `c view L`, `c edit L` (layout `L` of SIZE bytes) | 1 | `const uint8_t *o_c` / `uint8_t *o_c` | not NULL; no wrap (alignment 1) | |
| 799 | | `o out T N` | 1 | `T *o_o` (no count; erratum E1) | not NULL; aligned to sizeof(T); no wrap | |
| 800 | |
| 801 | T is any of `uchar ushort uint ulong byte short int long` (C `uint8_t` .. `int64_t`). At most 6 slots; |
| 802 | the result is `ulong`, `long` or `void`; parameter names follow the v1 rules (C identifier, no `_len` |
| 803 | ending). **Overlap** (half-open ranges, empty ranges excluded): refused when an `edit` range (arrays and |
| 804 | layouts) or the result buffer overlaps any other range, or two `out` ranges overlap; an `out` range may |
| 805 | overlap a view. Status 33 keeps its v1 meaning (reentry); 34 and 35 as v1. |
| 806 | |
| 807 | **Outputs.** Each `out` parameter is a buffer the binding owns, carved from the top of the calling |
| 808 | thread's Omega stack, 16-byte aligned and zero-filled before the call, passed in its slot. Only after |
| 809 | status 0 is it copied to the caller's pointer with `memmove`, so it may overlap the inputs |
| 810 | (`sha256_hash(buf, n, buf)`), and nothing is written there on a trap or refusal. The generator refuses |
| 811 | more than 65536 out bytes per export (they come out of the 8 MiB thread stack). |
| 812 | |
| 813 | **Multi-entry code.** With AArch64 exports, words 0 .. E-1 of the unit's code are |
| 814 | `b <export k>` (E <= 32, the compiler's limit); the binding enters export k at byte |
| 815 | 4k, through its own `bti c` stub, and refuses code shorter than 4E bytes. |
| 816 | For `x86linux`, each entry is a six-byte JMP/NOP slot and the binding selects the |
| 817 | corresponding slot; it must not apply AArch64 word offsets or BTI stubs. |
| 818 | |
| 819 | **Identity.** Each OM-2 binding embeds `omega-ident 1 unit=U abi=2 profile=OM-2 src=S omc=C`: U the |
| 820 | unit's file basename with every byte outside `[A-Za-z0-9_]` made `_` (`sha256-om2.om` gives |
| 821 | `sha256_om2`), S the sha256 of the unit's exact source bytes, computed by `src/native.om` itself (a |
| 822 | FIPS 180-4 SHA-256 in Omega), C the sha256 of the compiler that wrote the code (`OMEGA_NATIVE_OMC2` |
| 823 | for AArch64 or the pinned `OMEGA_NATIVE_X86_OMC` for x86), supplied by `tools/native` |
| 824 | (contract C3: the compiler does not report its own identity). The library |
| 825 | exports `const char *omega2_ident_U(void)`; each binding carries the expected string: C/C++ |
| 826 | `OMEGA2_IDENT_U`, Python `OMEGA2_IDENT_U` (bytes; importing the module raises `ImportError` when the |
| 827 | library's string differs), Rust `OMEGA2_IDENT_U: &str`, Zig `OMEGA2_IDENT_U`, Go `Omega2Ident_U` and |
| 828 | `Omega2_ident_U()`. OM-1 units embed no identity (their bindings stay byte-identical); `tools/native` |
| 829 | writes every unit's identity, the OM-1 ones with `abi=1 profile=OM-1` and the selected compiler, to |
| 830 | `work/ident.txt` (harness-side; `om/units.sh --check` in omega-mv refuses a stale unit). |
| 831 | |
| 832 | **Generator input.** An OM-2 unit's frame is the v1 frame followed by the line |
| 833 | `omega-unit U C\n` (U a C identifier, new in the set; C 64 lowercase hex digits); a missing or |
| 834 | malformed line is refused. Layouts are read from `layout NAME SIZE` lines (SIZE 1..4096, at most 32). |
| 835 | Two `note` forms are read by the bridge (and are comments to the compiler): `note bridge c-type L CNAME` |
| 836 | names layout L's C struct type, `note bridge c-define NAME DIGITS` adds a `#define` to the API header; |
| 837 | any other `note bridge` line is refused. |
| 838 | |
| 839 | **API header** (`omega_api.h`, output word `api`, installed only when the set has an OM-2 unit). It |
| 840 | includes `omega_native.h` and gives each layout as `typedef struct { ... } CNAME;` with every field at |
| 841 | its declared offset (explicit `uint8_t ombr_padN[...]` padding; a field without COUNT is a scalar, with |
| 842 | a COUNT an array, even COUNT 1 (erratum E5); a big-endian or misaligned field is bytes), checked by |
| 843 | `sizeof` and `offsetof` static assertions that `tools/native` compiles; and each export as |
| 844 | `static inline` C function named exactly as the export, with C types (`const T *, size_t` for an |
| 845 | unsized view, `CNAME *` for a layout, `T [N]` for out), calling `omega2_NAME` and calling `abort()` on a |
| 846 | nonzero status. This is how the C names of a consumer API (for example `sha256_init`) come from the |
| 847 | bridge rather than from handwritten C. |
| 848 | |
| 849 | **Out-of-line API** (output words `apih` and `apic`, installed as `omega_api_decl.h` and |
| 850 | `omega_api_defs.c` beside `omega_api.h`), for a consumer that must not reference the C library from the |
| 851 | objects that use the API (a freestanding object: an inline wrapper puts an `abort` reference into every |
| 852 | object that includes `omega_api.h`). `omega_api_decl.h` holds the same layouts, defines and static |
| 853 | assertions and only the prototypes of the same C functions (external linkage, no `stdlib.h`); an object |
| 854 | including it references only the API functions it calls. `omega_api_defs.c` includes it and `stdlib.h` |
| 855 | and holds their definitions, each calling `omega2_NAME` and `abort()` on a nonzero status, exactly as |
| 856 | the inline ones; it is compiled into the consumer's hosted binding (for the SHA cutover, the generated |
| 857 | `src/omega_om_units.c`). `tools/native` compiles the header alone and the definitions against it |
| 858 | (`-Wmissing-prototypes -Werror`). `omega_api.h` is unchanged, byte for byte. Use one form or the |
| 859 | other in a program, not both: each defines the functions under the same names. |
| 860 | |
| 861 | **Freestanding API** (output word `fapic`, installed as `omega_api_defs.c` by `--freestanding` |
| 862 | only, in place of the `apic` output). It is the same definitions except that a nonzero status |
| 863 | executes `__builtin_trap()` instead of calling `abort()`, so the object imports no C library |
| 864 | function and can be linked into a freestanding binding. The prototypes stay those of output |
| 865 | `apih`. |
| 866 | |
| 867 | **Unsupported (caller precondition, not detected),** as the contract states: that the memory exists for |
| 868 | `len` elements, is writable for edit, or stays alive during the call; forged lengths and read-only |
| 869 | memory passed as edit. Function-mode stack exhaustion faults as in v1. Loops in the seeded compiler |
| 870 | run at most 1,000,000 passes (trap 4 beyond); a unit over a longer view must loop in parts (`part`). |
| 871 | |
| 872 | **Host words** (`tools/native --host`; omega-mv#1008/#1040 and the stacked |
| 873 | context-format compiler at omega-mv `a0d12c250` (includes #1047; |
| 874 | `fn hostval` in `seed/omc/omc.om`). |
| 875 | The context compiler sha256 is `6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8`. |
| 876 | It admits the nine file/identity words `fclose fopen fstat stat getuid geteuid getgid |
| 877 | getegid lstat`, the clocks `monons sleepns realns`, and the device words `devctl |
| 878 | mapnew mapdrop mapread mapwrite devcall uvmctl mapaddr mapget mapset maphold mapbind`. |
| 879 | Other host words stay refused in function mode. OM-1 units get none. |
| 880 | The bridge admits such a unit only when the caller asks: without `--host`, a unit whose source names any |
| 881 | of the host words (outside a note line) is refused with status110 and nothing is installed; with |
| 882 | `--host`, these words are admitted in an OM-2 unit and every other host word, or any host word in an |
| 883 | OM-1 unit, is still refused. `src/native.om` judges the source itself (`fn hscan`): words are split at |
| 884 | blanks, tabs, CR, LF and parentheses as the compiler splits them, and a line whose first word is exactly |
| 885 | `note` is skipped, so a note may name a host word. The scan is conservative: a host word inside a text |
| 886 | literal also counts. The identity of a unit that uses any admitted host word gains ` host=w1,w2,...` |
| 887 | (in compiler keyword-table order, only those used), in the embedded string and in `work/ident.txt`, which then comes |
| 888 | from the generator (output word `ident`) for every OM-2 unit; a unit without host words gets the same |
| 889 | bytes with and without `--host` when using the same compiler. `--host` supports |
| 890 | AArch64 Linux and x86-64 Linux, but `--freestanding` is refused (110) before OUTDIR. |
| 891 | The words run on the calling thread |
| 892 | with its credentials and file descriptors; a descriptor a unit opens is the process's descriptor until |
| 893 | the unit closes it, and a trap between `fopen` and `fclose` leaks it (write units so nothing between |
| 894 | them can trap). Out buffers still live on the Omega stack until the copy after status 0: a unit that |
| 895 | returns a secret leaves a copy there until the thread's next call overwrites it. |
| 896 | |
| 897 | Generate one native library per architecture from all device-word units in one |
| 898 | invocation; multiple `.om` inputs are supported: |
| 899 | |
| 900 | ```sh |
| 901 | tools/native --host OUT UNIT1.om UNIT2.om UNIT3.om |
| 902 | ``` |
| 903 | |
| 904 | The inputs share one runtime, default mapping context and context-management |
| 905 | API. A caller can select the same explicit context for exports from different |
| 906 | units. Input basenames and exported function names must be unique across the |
| 907 | library; exports are not namespaced by unit. Do not independently generate |
| 908 | device libraries and combine their duplicate context/runtime definitions. |
| 909 | The `ctxnew.om`, `ctxput.om`, `ctxget.om` fixture allocates in one unit, writes |
| 910 | in another, then reads and drops in the third, through both default and explicit |
| 911 | contexts. It also refuses foreign handles, busy destruction and generation |
| 912 | without `--host`. No generator change was needed for multi-input support. |
| 913 | |
| 914 | Mapping-using libraries provide entry31 as a context-table header followed by |
| 915 | owned slots; see **Explicit mapping contexts** below for the draft C API, |
| 916 | capacity, generation partition and exact layout. Ordinary exports use a128-slot |
| 917 | default context; each generated `omega2_ctx_EXPORT` selects an explicit context. |
| 918 | The per-thread reentry check precedes that context's mutex. Pure/nonmapping |
| 919 | libraries acquire no context lock. All three wrapper templates zero-initialize |
| 920 | their seven span slots; this intentionally changes generated C text, not Omega |
| 921 | code bytes or the public ABI. |
| 922 | Dispatch tables remain read-only. `mapset` performs one aligned4- or8-byte store |
| 923 | bracketed by `DSB SY` on AArch64 or `MFENCE` on x86-64; `mapget` similarly brackets |
| 924 | one aligned load. `cpufence` orders payload writes before a doorbell. |
| 925 | Fixed replacement is restricted to an entire owned PROT_NONE reservation; failed |
| 926 | bind retires its token after successful cleanup. Failed cleanup quarantines it |
| 927 | as described below. No arbitrary syscall, executable mapping or GPU qualification |
| 928 | is admitted. Traps do not implicitly release mappings. |
| 929 | |
| 930 | This strict AArch64 context profile additionally admits exactly these aien-gpu |
| 931 | ABI1 `devctl` requests: INFO `0x80704110`/112 bytes, MEM_ALLOC |
| 932 | `0xc0304121`/48, MEM_FREE `0xc0184122`/24, CHAN_CREATE `0xc0484123`/72, |
| 933 | and CHAN_DESTROY `0xc0184124`/24. The whole request (including type, direction |
| 934 | and encoded size) is allowlisted. The compiler's `seed/host/MAPPING.md` and |
| 935 | `aien-ioctl-matrix.json` record the UAPI pin and Wolfram recomputation. |
| 936 | No BOOT, ARENA_READ or RM_INIT request is added. Exact writable counts are |
| 937 | required; short and long counts trap3 without changing a result output. |
| 938 | Device identity, ABI/state and payload validation stay with the caller/driver. |
| 939 | This is a trust-surface draft: **Drake must approve the contract before merge**. |
| 940 | It does not authorize opening a device or establish driver/GPU behavior. |
| 941 | |
| 942 | CPU-only qualification: `python3 tests/native/v2/dev/run.py [OUTDIR]`, also called by the |
| 943 | v2 suite, compares FIONREAD on a pipe and three ioctl paths on `/dev/null` against libc; |
| 944 | maps a memfd and publishes payload plus doorbell to a C consumer thread; checks stale |
| 945 | handles, all 128 slots plus exhaustion, and clocks bracketed by libc `clock_gettime`. |
| 946 | It checks no-`--host` refusal for each of the15 new words, rejects incompatible |
| 947 | compiler metadata and reserved context-export names, exercises explicit capacity4098, |
| 948 | owned fixed bind, retirement, cross-context ownership and concurrent contexts, |
| 949 | and checks both dispatch tables are read-only. Four C-runtime mutants and six |
| 950 | compiler-lowering mutants must fail these same callers. A forced-cleanup-failure |
| 951 | control proves quarantine refuses bind/read/write, destroy returns36 until a |
| 952 | successful drop, and destroy then succeeds. The two quarantine mutants remove |
| 953 | the reservation mark or the read-access guards. Compiler-mutant framing |
| 954 | uses the original fingerprint deliberately only inside this negative oracle; |
| 955 | production generation hashes the actual compiler. This is host evidence only; |
| 956 | chip and NVIDIA driver behavior are NOT_RUN. The runner needs the compiler source |
| 957 | beside the selected fixpoint binary (or `OMEGA_NATIVE_OMC2_SOURCE` explicitly) and |
| 958 | first confirms that source rebuilds the exact selected compiler fingerprint. |
| 959 | |
| 960 | The additional `aien.c` caller compares all five requests against libc on fd-1 |
| 961 | and checks short/long counts using an oversized backing view, so generic view |
| 962 | bounds cannot conceal a missing exact-length guard. Its guard-removal mutant |
| 963 | must fail specifically at the short-count assertion (exit42), not merely exit |
| 964 | nonzero. Native AArch64 requires EBADF. The explicit test-only QEMU10 profile |
| 965 | requires ENOTTY: that emulator rejects untranslated requests before fd checks. |
| 966 | The x86 conductor traces exactly two ioctl traversals per request (C and Omega); |
| 967 | short/long counts must trap before ioctl. This is EMULATED compiler admission |
| 968 | and length-guard evidence, never native-kernel, driver or hardware admission. |
| 969 | |
| 970 | CPU-only single-edit qualification is |
| 971 | `python3 tests/native/v2/test_single_edit.py [OUTDIR]`. It compiles and runs the |
| 972 | fixed-size OM1 counterpart, dynamic OM2, mapping-default and explicit-context |
| 973 | wrappers with `-O2 -Wall -Wextra -Werror`, without warning suppression. |
| 974 | Exact initialized-declaration counts are respectively1,1,4,4. Reverting only |
| 975 | the pure-OM2 declaration must reproduce GCC13.3's `sp[1].lo` |
| 976 | `maybe-uninitialized` diagnostic (exit1); unrelated failures do not kill this |
| 977 | mutant. The two mapping exports produce both default and explicit-context |
| 978 | wrappers, hence four declarations per mapping fixture. |
| 979 | |
| 980 | Historical generated-output comparisons admit only the exact old |
| 981 | `ombr_span sp[7];` paired with `ombr_span sp[7] = {{0}};` at the corresponding |
| 982 | position. Every other byte is compared unchanged. The expected replacement |
| 983 | counts are1 per successful OM1 fixture,9 in the current combined OM1 set |
| 984 | (counted independently from the selected input fixtures), and14 in the original |
| 985 | v2 runner's fixed OM2 set (madd, vec, lay, one, hoist). Missing, stray, |
| 986 | differently spelled or differently sized |
| 987 | initializers fail; an unrelated one-byte change in the same wrapper also fails. |
| 988 | The x86 conductor reuses that exact comparator only for successful historical |
| 989 | AArch64 C output. Its per-OM2-fixture count comes independently from explicit |
| 990 | input exports (or the single implicit last export); OM1 counts1. It additionally |
| 991 | asserts combined input counts9 and13: its unchanged combined OM2 set is madd, |
| 992 | vec, lay and one; hoist remains an individual parity fixture. The original v2 |
| 993 | runner's14 count is unchanged. Return codes, stderr, all other output |
| 994 | formats and every other C byte remain strict, and the same five refusal controls |
| 995 | run inside that gate. This is gate maintenance requiring Drake's review before |
| 996 | merge. The pinned compiler's pre-existing hoist failure remains exactly |
| 997 | `NATIVE-V2 FAIL 1`. |
| 998 | |
| 999 | #### Hosted x86-64 device words (draft) |
| 1000 | |
| 1001 | `tools/native --host --target x86linux` selects the hosted context compiler in |
| 1002 | `OMEGA_NATIVE_X86_OMC` (not `OMEGA_NATIVE_OMC2`). This is a separate fingerprint |
| 1003 | from the pure x86 compiler above. The generator enforces the hosted fingerprint |
| 1004 | for every mapping unit, so raw128/AArch64/unknown compiler metadata cannot be |
| 1005 | silently combined with this runtime. `native-gen OUTPUT x86host` grants the same |
| 1006 | source subset as `host` while selecting SysV entry veneers and runtime assembly. |
| 1007 | The runtime table's entry31 is `[r14+248]`, pointing at the same header and slots |
| 1008 | as AArch64. The context API, capacities, generations, locking and read-only |
| 1009 | dispatch publication are architecture-independent. |
| 1010 | Its x86 hosted compiler fingerprint is |
| 1011 | `c5ac9979232afd0d750e1d5088af69692032997136f761e585a25aa9a1cfc87e`, |
| 1012 | from omega-mv `c6c30fe3`, a new seeded superset of #1047's exact ABI1 |
| 1013 | allowlist and #1046's hosted-x86 lowerers. The frozen #1046/#68 pair is not |
| 1014 | modified. AArch64 now pins `6d1b1cf5...`; pure x86 remains on `be8c5130...`. |
| 1015 | The draft compiler and bridge contracts require Drake's approval before merge. |
| 1016 | |
| 1017 | The words lower through the existing x86 compiler's program-mode emitters: |
| 1018 | |
| 1019 | | Words | Linux x86-64 operation | |
| 1020 | | --- | --- | |
| 1021 | | `devctl`, `devcall`, `uvmctl` | `ioctl`, syscall16, same checked payload rules | |
| 1022 | | `mapnew`, `maphold`, `mapbind` | `mmap`, syscall9, unchanged flags/access/offset rules | |
| 1023 | | `mapdrop` | `munmap`, syscall11 | |
| 1024 | | `mapread`, `mapwrite` | Checked byte copies, not ordered MMIO | |
| 1025 | | `mapaddr` | Checked owned base address | |
| 1026 | | `mapget`, `mapset` | Exactly one aligned32/64-bit load/store between MFENCE instructions | |
| 1027 | | `cpufence`, `cpurelax` | MFENCE, PAUSE respectively | |
| 1028 | |
| 1029 | Ordinary write-back TSO and a compiler barrier do not suffice for a potentially |
| 1030 | write-combining doorbell mapping. Intel SDM volume2B, order253667-093US, |
| 1031 | **MFENCE**, page4-15, says every prior load/store becomes globally visible before |
| 1032 | any later load/store and explicitly addresses weakly ordered memory types. |
| 1033 | **SFENCE** orders stores, not loads. The ABI keeps the stronger MFENCE common path on |
| 1034 | both sides of ordered reads and writes instead of weakening either operation. |
| 1035 | Source: [Intel SDM volume2B](https://cdrdv2.intel.com/v1/dl/getContent/671241). |
| 1036 | This is CPU ordering, not a device-completion, cache-coherency or GPU guarantee. |
| 1037 | |
| 1038 | Run the shared fake-device fixtures and x86-specific controls with: |
| 1039 | |
| 1040 | ```sh |
| 1041 | OMEGA_NATIVE_OMC=/path/to/baseline/omc \ |
| 1042 | OMEGA_NATIVE_X86_OMC=/path/to/hosted-x86/omc \ |
| 1043 | OMEGA_NATIVE_X86_SOURCE=/path/to/hosted-x86/seed/omc/omc.om \ |
| 1044 | QEMU_X86_64=/path/to/qemu-10.0.14/build/qemu-x86_64 \ |
| 1045 | X86_CC=x86_64-linux-gnu-gcc \ |
| 1046 | bwrap --dev-bind / / --dev /dev --proc /proc -- \ |
| 1047 | taskset -c 10-14 nice -n 10 \ |
| 1048 | python3 tests/native/x86/device.py build/native-x86-device |
| 1049 | ``` |
| 1050 | |
| 1051 | The conductor reuses `tests/native/v2/dev/{hdev.om,dcall.c,context.c,context-ro.c}` |
| 1052 | unchanged, adds the explicit QEMU10 oracle for the five exact ABI1 requests, and |
| 1053 | generates one library from ctxnew, ctxput and ctxget with one shared context API. |
| 1054 | It runs pipe/ioctl C differentials, a memfd producer/consumer, default128 and |
| 1055 | explicit4098 mapping exhaustion, stale/foreign handles, owned fixed binding, |
| 1056 | clocks and read-only dispatch controls under QEMU. Its12 mutants cover the wrong |
| 1057 | ioctl syscall, missing MFENCE instruction structure, invalid runtime entry31, |
| 1058 | context generation/capacity/destruction, read-only publication, fixed-map |
| 1059 | ownership, failed-bind retirement, forced cleanup failure with read-guard and late-quarantine mutants, |
| 1060 | and an exact-length guard removed (attributed short-count assertion exit42). |
| 1061 | QEMU cannot qualify WC timing: the fence mutant is caught by an instruction |
| 1062 | oracle, not a claim that an emulator exhibited hardware reordering. |
| 1063 | No NVIDIA device is opened. Physical x86 and GPU qualification remain NOT_RUN. |
| 1064 | The preexisting pure x86 suite retains its original compiler fingerprint and |
| 1065 | continues to run separately with `sh tests/native/x86/run.sh`. |
| 1066 | |
| 1067 | |
| 1068 | #### Function-table export design (PROPOSED, not implemented) |
| 1069 | |
| 1070 | A foreign runtime that needs a C function table with more than four C arguments should |
| 1071 | keep its exact public C signature in a generated adapter. The adapter packs the arguments |
| 1072 | into a named OM-2 `layout` (fixed widths and explicit padding), passes one layout view |
| 1073 | plus any checked view/out ranges to an exported Omega function, and converts its status |
| 1074 | and result according to that public API. This does not extend the six machine-argument |
| 1075 | slots or place a foreign callback pointer inside Omega code. The table contains the |
| 1076 | typed adapter addresses, never raw embedded Omega entry addresses. |
| 1077 | |
| 1078 | The next slice must define the table schema/version, refuse duplicate emitted names and |
| 1079 | unsupported callback signatures, emit C declarations and definitions from the same |
| 1080 | schema, and compare a greater-than-four-argument call through the table against direct C. |
| 1081 | Negative controls must include a mismatched table version, incorrect layout size and an |
| 1082 | unsupported signature. Until that slice is implemented, no C function-table export is |
| 1083 | claimed by this bridge. |
| 1084 | |
| 1085 | |
| 1086 | ### AArch64 qualification (`OMEGA_NATIVE_OMC=<seed omc> OMEGA_NATIVE_OMC2=<OM-2 omc> sh tests/native/v2/run.sh [measure]`) |
| 1087 | |
| 1088 | Current invocation (all callers require their toolchains on `PATH`): |
| 1089 | |
| 1090 | ```sh |
| 1091 | OMEGA_NATIVE_OMC=/path/to/pinned-generator-omc \ |
| 1092 | OMEGA_NATIVE_OMC2=/path/to/omega-hoist/seed/out/omc \ |
| 1093 | OMEGA_NATIVE_HOST_OMC2=/path/to/omega-host/seed/out/omc \ |
| 1094 | OMEGA_NATIVE_DEVICE_OMC2=/path/to/context-compiler/seed/out/omc \ |
| 1095 | OMEGA_NATIVE_OMC2_SOURCE=/path/to/context-compiler/seed/omc/omc.om \ |
| 1096 | sh tests/native/v2/run.sh # optional argument: measure |
| 1097 | ``` |
| 1098 | |
| 1099 | `OMEGA_NATIVE_OMC` retains the `734f0a39...` pin above. The runner checks all three OM-2 digests before |
| 1100 | building or replacing its output directory: |
| 1101 | |
| 1102 | | Role | omega-mv source | Required `seed/out/omc` sha256 | |
| 1103 | |---|---|---| |
| 1104 | | ABI and loop hoisting (`OMEGA_NATIVE_OMC2`) | `hoist/865-main` @ `7286d61d23c2b92ef6606c6b66072335e6a09813`, retained by `bridge74-hoist-omc-7286d61d` (#865 port onto main `9920aab1`) | `078200466af2dc0452da7793b186d91bc9539f0cf5fafa15bcdb2a48e3bedef7` | |
| 1105 | | Function-mode host subset (`OMEGA_NATIVE_HOST_OMC2`) | `feat/om2-fn-host-words` @ `2992a68b7a3bc1fa8b322924c3b3e786bebc9ee4`, retained by `bridge74-host-omc-2992a68b` (#1008; feature introduced by `dbc72448`) | `c000ec029fb85847084a82e345cb7b384cc678a735ed37e9fcbc0f557534b911` | |
| 1106 | | Device and single-edit phases (`OMEGA_NATIVE_DEVICE_OMC2`) | `a0d12c250` (includes #1047); source supplied with `OMEGA_NATIVE_OMC2_SOURCE` for mutant rebuilding | `6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8` | |
| 1107 | |
| 1108 | Rebuild each compiler from its own checkout, on AArch64 Linux. The script grows seed0, hex1, asm2, |
| 1109 | and om4, then requires om4-built, self-built, and second-self-built compilers to match: |
| 1110 | |
| 1111 | ```sh |
| 1112 | git -C /path/to/omega-mv worktree add --detach /path/to/omega-hoist 7286d61d23c2b92ef6606c6b66072335e6a09813 |
| 1113 | git -C /path/to/omega-mv worktree add --detach /path/to/omega-host 2992a68b7a3bc1fa8b322924c3b3e786bebc9ee4 |
| 1114 | (cd /path/to/omega-hoist && bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh seed/omega-from-seed.sh) |
| 1115 | (cd /path/to/omega-host && bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh seed/omega-from-seed.sh) |
| 1116 | sha256sum /path/to/omega-hoist/seed/out/omc /path/to/omega-host/seed/out/omc |
| 1117 | ``` |
| 1118 | |
| 1119 | Run qualification itself under the same `bwrap` wrapper on the shared Spark. The hoist compiler |
| 1120 | refuses the host fixtures with compiler error 9; #1008's compiler accepts them but does not hoist |
| 1121 | loop constants. A single one of these binaries cannot qualify the whole current suite. Section 11 |
| 1122 | uses the host compiler for actual host units and scanner fixtures, checking its own compiler |
| 1123 | identity. Its host-free `--host` parity control still uses the hoist compiler on **both** sides, |
| 1124 | so all nine files must remain byte-identical. No hoist, refusal, identity, caller, or mutant |
| 1125 | expectation is relaxed. See `evidence/native-v2-compiler-profile/` for the full PASS and pin-refusal |
| 1126 | controls. |
| 1127 | The single-edit and device phases explicitly select the context compiler; they do not |
| 1128 | inherit the ABI/hoist compiler. Its source must rebuild the exact selected fingerprint. |
| 1129 | |
| 1130 | The older PASS at bridge `2954d46` with compiler `13ce76c2...`, and the original freestanding PASS |
| 1131 | with `2c824805...`, exercised older runners, not this feature set. The hoist gate entered bridge |
| 1132 | main at `7ffd79d` (#24); section 11 entered at `d112461` (#54), after the audit. The runner itself is |
| 1133 | unchanged between main `3d01b49` and typed-views heads `758d74aa` / `79e8c36`; neither #71 nor #73 |
| 1134 | introduced these compiler-feature mismatches. The apparent hscan-off failure with `13ce76c2...` |
| 1135 | was secondary: error 9 prevented `paren.in` from being framed, so the mutant invocation exited 2 |
| 1136 | instead of reaching the scanner. The correct pair exercises and catches that mutant. |
| 1137 | |
| 1138 | Historical S4 qualification was recorded with omega-mv `om2/compiler-s4` @ f6a6492fd (draft PR #764, ledger L834), |
| 1139 | sha256 `499236398aabc652e2dae27fe4bdc4c5db3d3726314356e0dbef23e3345803ec`, which compiles the three OM-2 |
| 1140 | test units `tests/native/v2/{vec,lay,one}.om`; that digest is the `omc=` of their identities. Its code |
| 1141 | follows the convention above with no departure found: the entry table (vec: six `b` words), the slots |
| 1142 | and element counts, the out pointers, and the traps the callers expect (the `part` checks in the |
| 1143 | contract's order, element bounds, trap 9 after an out write). Before S4 existed the bridge was developed |
| 1144 | against hand-written OM-1 stand-ins of these units (commit 1392549); they are removed. |
| 1145 | |
| 1146 | The later historical `hoist` receipt used omega-mv `perf/omc-loop-checks` @ c4953df7b (draft PR #865), |
| 1147 | sha256 `13ce76c274d6bdce50613a242faa7cb07aadf65441ceecddf2d06bcfa4e48b69`, which keeps at most seven |
| 1148 | constants (x20..x26). Its decoded `hoist` code writes x20..x26 and d13, d14 and s15; that of 0d006207 |
| 1149 | (no hoisting) writes none of x20..x26, and the hoist check fails with it. The newer `25e264c6` |
| 1150 | perf-branch compiler (`c4380d3c...`) also hoists but still refuses function-mode host words. |
| 1151 | |
| 1152 | The run checks: v1 byte identity (above); every identity string against `sha256sum` (oracle); the |
| 1153 | embedded code against the compiler's bytes; the exact exported symbol set (15 `omega2_` symbols, 12 |
| 1154 | exports and 3 identities, and `omega_madd`; no private helper, no v1 name for a v2 unit); no caller |
| 1155 | declaring an Omega function by hand; the C caller (64 checks) normally and with BTI enforced; the C++, |
| 1156 | Python, Rust (2021 and 2024), Zig and Go callers (16 to 18 checks each); the link-time refusal in all six |
| 1157 | languages (v1 bindings of an OM-1 unit named `bsum` against the library: `undefined reference to |
| 1158 | omega_bsum`, Python `undefined symbol: omega_bsum`); the stale identity (a header from `vec.om` with one |
| 1159 | note byte changed is detected; its Python binding refuses to import; the matching header passes); 15 |
| 1160 | generator refusals of OM-2 input with a control; three negative controls (the wrap check, the |
| 1161 | edit-overlap rule and the out copy each removed from a copy of the generator must make the C caller |
| 1162 | fail, on the checks named); `hoist`'s decoded destinations (x20..x26 and some of d8..d15 written) and no |
| 1163 | unit's code naming x19 or x29; and the trampoline called directly (`tests/native/v2/tramp.c`, which |
| 1164 | includes the generated C, so no C wrapper can keep a register for it) with a hand-assembled unit that |
| 1165 | writes x20..x29 and d8..d15, on a return and on a trap, plus ten mutants, each removing one restore from |
| 1166 | `ombr_leave` (x19/x20, x21/x22, x23/x24, x25/x26, x27/x28, the four d pairs, x29) in a copy of the |
| 1167 | generator, every one of which must make it fail. |
| 1168 | |
| 1169 | For the out-of-line API the run also checks: every existing output (`c h python rust zig go api`) |
| 1170 | byte-identical to 3bb8b8a's generator on the v2 set; `tests/native/v2/fsuse.c`, built with |
| 1171 | `-ffreestanding -fno-builtin` from `omega_api_decl.h`, has exactly the undefined symbols `absorb bsum |
| 1172 | digest swap8` (no `abort`), while `omega_api_defs.o` holds the `abort` reference; the same object from |
| 1173 | the inline `omega_api.h` references `abort` (control); linked with `omega_api_defs.o` and the library it |
| 1174 | computes the right values, and a trapping call aborts (SIGABRT). Two generator mutants are caught: the |
| 1175 | prototype-only branch disabled (definitions in `omega_api_decl.h`: the freestanding build fails on the |
| 1176 | undeclared `abort`), and the inline branch disabled (`omega_api.h` loses `static inline`: caught by the |
| 1177 | byte-identity check). |
| 1178 | |
| 1179 | Host words (section11): without `--host`, `tests/native/v2/host/hfile.om` (all nine words) is refused |
| 1180 | and nothing is installed; `--host --freestanding` is refused for either target before |
| 1181 | OUTDIR; with `--host` its identity names the nine words, and a C caller (`hcall.c`) and a Rust caller |
| 1182 | (`hcall.rs`) check its results against libc and `std`: the uid/gid sum, a 5-byte read, `-ENOENT` for a |
| 1183 | missing path, `-ELOOP` for a symlink (`fopen` with `O_NOFOLLOW`), `st_size`. The v2 set built with |
| 1184 | `--host` is byte-identical in all nine outputs. The generator, fed directly: `geteuid` after `(`, a tab |
| 1185 | and before a CR is refused without host and named with it; host words in note lines (also indented, |
| 1186 | tab-separated) pass without host; `(note geteuid` is not a note; `unlink` (outside the nine) and |
| 1187 | `geteuid` in an OM-1 unit are refused even with host; `getuidx` is not a host word; the freestanding |
| 1188 | outputs `freest` and `fapic` refuse `host` (exit 110) on a unit they accept without it. Mutant: the scan |
| 1189 | removed from `fn unit` lets the parenthesised `geteuid` through without host (caught). The zig and go |
| 1190 | callers need their toolchains on PATH (zig 0.13.0, go 1.27.3 were used); without them the run reports |
| 1191 | NOT_RUN and exits 1. |
| 1192 | |
| 1193 | The C caller covers: values; empty views (NULL, misaligned); NULL with len 1; misalignment by 1, 2 and |
| 1194 | 4 for 4- and 8-byte elements and an edit; `len*size` overflow (2^62 x 4, 2^61 x 8, 2^64-1); address wrap |
| 1195 | at 2^64-16 (end 2^64 refused, end 2^64-8 accepted); a 2^32+5-element length accepted and passed whole |
| 1196 | (PROT_NONE mapping, no element read); the #748 golden at the boundary (len 2^64-1, o 2^64-2, k 4: 32) |
| 1197 | and inside the code (len 16, o 2^64-2, k 4: trap 3, the wrapped `o + k` never used), every (o, k) in |
| 1198 | 0..18 over 16 bytes; splits at every point of 64 bytes; 16 MiB of bytes and 64 MiB of words against a C |
| 1199 | reference; edit == view, overlap by one element, adjacent ranges, empty ranges, the result inside an |
| 1200 | edit or a view; the layout through `omega_api.h`; out overlapping a view (in-place reverse) and its own |
| 1201 | layout view; two outs adjacent, overlapping by one byte and at one address; out untouched after a |
| 1202 | trap; NULL and misaligned out; 2000 interleaved rounds across the three separately compiled OM-2 units |
| 1203 | and the OM-1 `madd` in one binary (module boundary); reentry from a signal handler (33); two threads |
| 1204 | with their own stacks and out buffers. |
| 1205 | |
| 1206 | Caller cost (HOST, `run.sh measure`, GB10 host CPU under load average 7-11 from other work, lowest of 7 |
| 1207 | runs, ns per call, two runs, S4 code): |
| 1208 | |
| 1209 | | call | ns | |
| 1210 | |---|---| |
| 1211 | | refused (argument checks only, no entry) | 2.6-3.1 | |
| 1212 | | one view, code returns its len (checks, entry, register saves, stack switch) | 8.0-8.2 | |
| 1213 | | empty view to `bsum` (its chunk loop runs once and calls `psum`) | 9.8 | |
| 1214 | | ABI v1, three scalars (baseline) | 5.2-6.1 | |
| 1215 | | a plain noinline C call (scale) | 1.4 | |
| 1216 | | one view and an 8-byte out (zero, run, memmove) | 14.3-15.0 | |
| 1217 | | 16-byte view sum (scalar C loop 4.9) | 15.0-15.5 | |
| 1218 | | 4 KiB view sum: 0.346 ns/B (C 0.258) | 1418 | |
| 1219 | | 16 MiB view sum: 0.379-0.384 ns/B (C 0.291-0.295) | 6.4 ms | |
| 1220 | | a thread's first call (maps its 8 MiB stack and 8 MiB guard), then the second | 11.5-12.4 us, 64 | |
| 1221 | |
| 1222 | The fixed v2 overhead over a plain C call is about 6.6 ns (checks about 1.5, entry and stack switch |
| 1223 | about 5), about 2 ns over v1 for one view; an out costs its zeroing and copy. Memory: 16 MiB of |
| 1224 | NORESERVE address space per calling thread; the RSS did not change at KiB resolution over a new thread's |
| 1225 | first two calls. |
| 1226 | |
| 1227 | Not run: status 34 and 35 (as v1). |
| 1228 | |
| 1229 | ### Explicit mapping contexts (contract draft; Drake approval required before merge) |
| 1230 | |
| 1231 | This stacked extension changes the function-mode entry-31 format. It must not be |
| 1232 | mixed with the raw 128-slot format from omega-mv#1040 / omega-bridge#66. Mapping |
| 1233 | units require the exact context-format compiler fingerprint recorded by the |
| 1234 | generator; pure/nonmapping compiler admission remains unchanged. Program-mode |
| 1235 | `MAPPING.md` keeps its raw128 slots, eight slot bits and existing semantics. |
| 1236 | |
| 1237 | The C compatibility API is: |
| 1238 | |
| 1239 | ```c |
| 1240 | typedef struct omega_native_context omega_native_context; |
| 1241 | uint32_t omega_native_context_create(uint64_t capacity, omega_native_context **out); |
| 1242 | uint32_t omega_native_context_destroy(omega_native_context *context); |
| 1243 | /* Every OM-2 export in a mapping-using library also has: */ |
| 1244 | uint32_t omega2_ctx_EXPORT(omega_native_context *context, |
| 1245 | uint64_t *result, /* unchanged export arguments */ ...); |
| 1246 | ``` |
| 1247 | |
| 1248 | Existing `omega2_EXPORT` calls use a default128-slot context. Explicit contexts |
| 1249 | admit capacity1..4098. A C NVRM context needs4096 live allocation mappings plus |
| 1250 | one usermode mapping and one transient slot. GPU channel VA bookkeeping is not a |
| 1251 | CPU mmap reservation. Context selection is explicit, never a TLS selector, and |
| 1252 | does not consume any of the six private Omega argument words. |
| 1253 | |
| 1254 | Mapping-using libraries reserve the `ctx_` export prefix for these generated |
| 1255 | wrappers and refuse an Omega export that would collide. Context pointers and |
| 1256 | handles belong to the generated library that created them, not another shared |
| 1257 | object with its own runtime. Only the C binding exposes the explicit-context |
| 1258 | API; the other bindings retain their default-context exports. |
| 1259 | |
| 1260 | Entry31 points at four u64 header words: capacity, generation base, generation |
| 1261 | limit, zero-reserved; then capacity slots of four u64 words: address, byte length, |
| 1262 | generation, access. A slot is live iff address is nonzero. Handle low13 bits are |
| 1263 | slot+1. Upper50 bits are a nonwrapping generation:24 context-ID bits followed by26 |
| 1264 | per-slot bits. Default context ID is1; IDs2..16777215 are issued once per generated |
| 1265 | library and never reused, including failed creations. Each slot starts at |
| 1266 | `contextID<<26`; successful allocation increments it, and an exhausted slot is |
| 1267 | never reused. Thus a handle from another context cannot alias a local slot. |
| 1268 | |
| 1269 | WolframLanguageEvaluator: |
| 1270 | `{4096+1+1,2^13,2^26,2^24-1,2*2^26-1,2^50-1,32+4098*32,32+128*32}` |
| 1271 | -> `{4098,8192,67108864,16777215,134217727,1125899906842623,131168,4128}`. |
| 1272 | The last two values are table byte sizes, including the32-byte header. |
| 1273 | |
| 1274 | `maphold(address,length)` uses PROT_NONE / MAP_FIXED_NOREPLACE and returns only |
| 1275 | an exact reservation at the requested address. `mapbind(handle,fd,offset,access)` |
| 1276 | may replace only the entire live PROT_NONE reservation owned by that context; |
| 1277 | access is literal1 or3. It accepts no arbitrary target address. A successful bind |
| 1278 | changes that same slot to a shared mapping. A failed bind marks the slot |
| 1279 | QUARANTINED (access4), then attempts to unmap the whole former reservation. |
| 1280 | Successful cleanup retires the token and returns the original negative Linux |
| 1281 | errno with bridge status0. Cleanup failure traps3 and preserves the droppable |
| 1282 | owner; the wrapper does not write its result. The caller must retain that owner |
| 1283 | on nonzero bridge status and retry `mapdrop`. Quarantined tokens refuse bind, |
| 1284 | read and write, but permit `mapaddr` and `mapdrop`. Destroy returns36 while any |
| 1285 | live or quarantined slot remains and succeeds after all drops complete. |
| 1286 | Linux may leave a gap after failed MAP_FIXED: **reservation preservation is not |
| 1287 | promised**. Reusing a retired token, binding an ordinary mapping, and using a |
| 1288 | cross-context handle trap3 before replacement. External munmap/mremap/MAP_FIXED over an owned range |
| 1289 | is outside this ownership contract. |
| 1290 | |
| 1291 | One mutex per context serializes bridge calls, with the per-thread/per-library |
| 1292 | reentry guard checked before locking. The caller additionally serializes each |
| 1293 | multi-call allocation/bind/cleanup transaction in its NVRM context. Different |
| 1294 | contexts may run concurrently. Locks cover normal/trap exits and out copies. |
| 1295 | The dispatch table is initialized in private memory and protected read-only |
| 1296 | before publication; entry31 alone differs between contexts. |
| 1297 | |
| 1298 | The caller must join/drain all context users and waiters before destruction. |
| 1299 | Destruction refuses any live mapping/reservation with status36 |
| 1300 | (`OMEGA_CONTEXT_BUSY`), performs no implicit unmap, and never destroys the |
| 1301 | default context. Null/invalid capacities return32; recursive calls return33; |
| 1302 | runtime allocation/lock failures return34. A destroyed pointer is invalid. |
| 1303 | As with the existing runtime, async cancellation/siglongjmp across a bridged |
| 1304 | call are unsupported. Pure/nonmapping libraries have no context overhead. |
| 1305 | |
| 1306 | ## Hosted seeded-C runtime-extent views (explicit profile) |
| 1307 | |
| 1308 | This is a converter ABI, not native ABI v2. It is selected with |
| 1309 | `tools/bridge-seeded --runtime-views c unit.om` or |
| 1310 | `tools/bridge-seeded --runtime-views h unit.om`. The unchanged e5b32567 source |
| 1311 | snapshot validator is required. Default `bridge-seeded` views still require |
| 1312 | the exact declared count; `--float-next` is not combined with this profile. |
| 1313 | |
| 1314 | | Omega declaration | Public C arguments | Live extent | |
| 1315 | |---|---|---| |
| 1316 | | `a view uchar CAP` | `const void *a, uint64_t a_n` | bytes, `0 <= a_n <= CAP` | |
| 1317 | | `a view ushort CAP` | `const void *a, uint64_t a_n` | 16-bit halfwords, bounded by CAP | |
| 1318 | | `a view uint CAP` | `const void *a, uint64_t a_n` | 32-bit words, bounded by CAP | |
| 1319 | | `a view ulong CAP` | `const void *a, uint64_t a_n` | 64-bit words, bounded by CAP | |
| 1320 | | `a view f32 CAP` | `const void *a, uint64_t a_n` | raw IEEE binary32 elements, bounded by CAP | |
| 1321 | | `a edit T CAP` | `void *a, uint64_t a_n` | same count/width policy, writable | |
| 1322 | | OM2 `a view T *` / `a edit T *` | same pointer/count pair | unsized; byte/address envelope only | |
| 1323 | | integer scalar/result | `uint64_t value` / `uint64_t *result` | unchanged canonical bits | |
| 1324 | | f32 scalar/result | `float value` / `float *result` | unchanged | |
| 1325 | |
| 1326 | For example, numeric bounded input: |
| 1327 | |
| 1328 | ```text |
| 1329 | fn copy a view uint 256 b edit uint 256 i ulong to ulong |
| 1330 | put b i get a i |
| 1331 | ret len b |
| 1332 | end |
| 1333 | ``` |
| 1334 | |
| 1335 | For counts above the fixed-declaration ceiling, use the pinned seed's existing |
| 1336 | unsized declaration syntax: |
| 1337 | |
| 1338 | ```text |
| 1339 | om2 |
| 1340 | fn copy a view uint * b edit uint * i ulong to ulong |
| 1341 | put b i get a i |
| 1342 | ret len b |
| 1343 | end |
| 1344 | ``` |
| 1345 | |
| 1346 | Both export the same ABI shape (the generated header uses numbered arguments): |
| 1347 | |
| 1348 | ```c |
| 1349 | uint32_t omega_copy(uint64_t *result, |
| 1350 | const void *a, uint64_t a_n, |
| 1351 | void *b, uint64_t b_n, uint64_t i); |
| 1352 | ``` |
| 1353 | |
| 1354 | The result pointer is first; other arguments retain source order. Generated |
| 1355 | source/header explicitly identify the runtime profile. The original source |
| 1356 | records numeric capacities versus `*`; consumers must pin both source and |
| 1357 | converter. A fixed, bounded-runtime and unsized-runtime C declaration alone |
| 1358 | cannot distinguish their policies. |
| 1359 | |
| 1360 | `len` returns the live element count; every access uses that count, including |
| 1361 | literal indices of unsized views and counts forwarded through helper calls. |
| 1362 | Passing any same-element array to an unsized helper is supported; a fixed |
| 1363 | helper still requires the declared fixed shape. Runtime-profile numeric |
| 1364 | declarations remain source-level capacities, not resized Omega local arrays. |
| 1365 | |
| 1366 | Nonempty arguments must be nonnull and naturally aligned. Element-count times |
| 1367 | element-width and pointer plus byte-length must not overflow. Empty arguments |
| 1368 | may be NULL or misaligned and contribute no range. Range checks use actual |
| 1369 | counts, not capacities: adjacent disjoint buffers and readonly/readonly |
| 1370 | aliases are allowed; any overlap involving a writable view is refused. All |
| 1371 | views, including readonly ones, must be disjoint from nonempty result storage. |
| 1372 | Result-pointer checks are unchanged, even when all view counts are zero. |
| 1373 | Invalid admission returns 32, access outside the live count returns trap 3, |
| 1374 | reentry returns 33, and success returns 0. Only success writes the result; |
| 1375 | earlier view writes remain visible after a trap. |
| 1376 | |
| 1377 | Six source parameters are available. Numeric views take one native seed |
| 1378 | slot each, so five numeric views can generate ten C pointer/count arguments. |
| 1379 | Unsized views take two native slots each, with six slots total; the original |
| 1380 | seed rejects larger signatures. Only the bare `om2` header and unsized views |
| 1381 | are added, not arbitrary OM2 layouts/contracts/exports/part syntax. Other |
| 1382 | converter limits and iteration guards are unchanged. Dimension products and |
| 1383 | strides remain the caller/unit's responsibility: checked view admission does |
| 1384 | not validate a wrapping dimension formula. Use `-ffp-contract=off` for |
| 1385 | sequential floating arithmetic. |
| 1386 | |
| 1387 | A borrowed NUL-terminated path can use the pointer plus its readable maximum |
| 1388 | extent, scanning only within that extent: |
| 1389 | |
| 1390 | ```text |
| 1391 | om2 |
| 1392 | fn pathlen a view uchar * to ulong |
| 1393 | for i ulong len a |
| 1394 | if eq get a i 0 |
| 1395 | ret i |
| 1396 | end |
| 1397 | end |
| 1398 | ret len a |
| 1399 | end |
| 1400 | ``` |
| 1401 | |
| 1402 | The C entry is `uint32_t omega_pathlen(uint64_t *result, const void *a, |
| 1403 | uint64_t a_n)`. A result smaller than `a_n` locates the first NUL; result |
| 1404 | equal to `a_n` means no NUL inside the bound (including empty input). The |
| 1405 | caller must supply a genuinely readable extent: the adapter checks arithmetic |
| 1406 | and aliasing, not virtual-memory mapping permissions. `bridge-seeded` keeps its |
| 1407 | hosted checked runtime. `tools/bridge-freest c|h SOURCE.om` now additionally |
| 1408 | supports these borrowed-view signatures with the same checked ABI and refusal |
| 1409 | codes, using stack-local explicit status/depth propagation instead of |
| 1410 | TLS/setjmp/longjmp. Its generated object has an empty allowed undefined-symbol |
| 1411 | set: no libc/POSIX, TLS, int128, abort or printf imports. Units without `om2` |
| 1412 | retain exact declared counts, matching the default hosted checked profile; |
| 1413 | the seed-validated `om2` header selects numeric capacities and unsized runtime |
| 1414 | views, matching hosted `--runtime-views`. No invocation flag is required. |
| 1415 | Both preserve bounds and alias semantics, partial writes before a refusal and |
| 1416 | result storage only on success; argument refusal 32 changes neither result |
| 1417 | nor buffers. This does not extend `tools/native --freestanding` or change the hosted profile. A |
| 1418 | view-taking unit with an unsupported capability refuses without output and |
| 1419 | never retries the legacy scalar profile. See CAPABILITIES.md for the exact |
| 1420 | subset and `tests/freest_views.py` for differential/import/mutation acceptance. |
| 1421 | The acceptance suite compares this scan to `memchr` on host and x86, including |
| 1422 | NULL/zero and a terminator immediately outside the bound. |
| 1423 | |
| 1424 | `tests/seeded_runtime_views.py` is the host/reference, emulated x86 and |
| 1425 | mutation acceptance path. No GPU or hardware qualification is claimed. |