interplane.Get Omega
Read in your language

omega-bridge

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

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / docs / NATIVE-ABI.md

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