omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / spec / omegese-modules.md
| 1 | # Native Omega modules, version 1 |
| 2 | |
| 3 | `seed/modules/driver.om` is the seeded, offline AArch64 Linux module driver. |
| 4 | It compiles each source independently, stores native object bytes by SHA-256, |
| 5 | and links native call relocations. It never joins dependency source into a |
| 6 | compilation. Its only composed source is the driver itself, which reuses the |
| 7 | existing `seed/ng/sha256.om` compression implementation. This version is the |
| 8 | pure function-mode subset; it is not a general shared-library loader. |
| 9 | |
| 10 | ## Build the driver and check it |
| 11 | |
| 12 | From the repository root, with its seeded compiler already built: |
| 13 | |
| 14 | ```sh |
| 15 | { printf 'om2\n'; cat seed/ng/sha256.om seed/modules/driver.om; } > /tmp/ommod.om |
| 16 | seed/out/omc < /tmp/ommod.om > /tmp/ommod |
| 17 | chmod +x /tmp/ommod |
| 18 | python3 seed/modules/tests/check.py /absolute/path/to/object-enabled-omc /tmp/modules-check |
| 19 | ``` |
| 20 | |
| 21 | The first two commands must succeed before executing the output. The test |
| 22 | output directory must be new. The test harness is an independent Python/C/ASM |
| 23 | oracle, not a runtime dependency. It derives the compiler and source hashes |
| 24 | from actual bytes and reports them. The native driver has no shell, Python, |
| 25 | C-library, network, or registry dependency. Full seed qualification and the |
| 26 | integration review remain the owning release lane's responsibility. |
| 27 | |
| 28 | ## Commands and source |
| 29 | |
| 30 | Create the chosen store directory first. All paths may be relative to the |
| 31 | original working directory or absolute. Symbolic links in any traversed path |
| 32 | component are refused, including the store and source paths. |
| 33 | |
| 34 | ```text |
| 35 | ommod build COMPILER COMPILER_SHA256 PROFILE aarch64-linux STORE SOURCE SOURCE_SHA256 |
| 36 | ommod link STORE COMPILER_SHA256 PROFILE aarch64-linux SOURCE_SHA256 ARTIFACT_SHA256 program ENTRY OUTPUT |
| 37 | ommod link STORE COMPILER_SHA256 PROFILE aarch64-linux SOURCE_SHA256 ARTIFACT_SHA256 function - OUTPUT |
| 38 | ``` |
| 39 | |
| 40 | `PROFILE` is `debug` or `release`. Hashes are exactly 64 lowercase hex digits. |
| 41 | Build checks both the supplied source digest and compiler executable digest. |
| 42 | Success prints `BUILT ARTIFACT_SHA256` or `CACHE ARTIFACT_SHA256`. A cache hit |
| 43 | hashes the supplied compiler but does not invoke it. Link needs no compiler |
| 44 | file. It requires the exact root artifact digest returned by build. |
| 45 | |
| 46 | Source starts at byte zero with `om2\n` or `om2 release\n`, agreeing with the |
| 47 | profile. An import occupies one line: |
| 48 | |
| 49 | ```text |
| 50 | import localAlias SOURCE_SHA256 exportedName |
| 51 | ``` |
| 52 | |
| 53 | It names one function from a dependency already built in the same store and |
| 54 | compiler/profile/target context. The driver derives a typed `extern fn` |
| 55 | declaration from that dependency's validated object metadata. Aliases and |
| 56 | export names use the compiler's ASCII identifier subset, at most 63 bytes. |
| 57 | Import fields have single ASCII spaces; leading spaces before `import` are |
| 58 | allowed. No trailing fields or comments are allowed on import lines. Aliases |
| 59 | are unique within a module. Original `extern` lines are refused. All other |
| 60 | source lines are preserved byte for byte after the profile line, including |
| 61 | comments and local definitions. Dependencies' private names never enter this |
| 62 | source or another module's symbol namespace. |
| 63 | |
| 64 | The compiler input is `object\n`, the profile line, generated extern lines, |
| 65 | and the original source with import lines removed. Explicit `export fn` |
| 66 | definitions provide public entries. Private functions remain module-local. |
| 67 | The compiler independently checks call types, array capabilities, and its |
| 68 | function-mode restrictions. This format excludes globals, text, |
| 69 | struct/layout/nominal interfaces, inline external interfaces, and fresh |
| 70 | external parameters. A module may use `read`, `write`, `exit` and the |
| 71 | function-mode host subset that needs no program image (files, identity, |
| 72 | clocks; OMEGESE "Native object output"); the device words stay refused. The |
| 73 | stack each host word pushes is in the object's stack record, so the stack |
| 74 | check below covers it (`seed/omc/gate-objhost.sh`). Internal functions may retain fresh semantics. |
| 75 | Only acyclic module and call graphs are accepted, including unused imports |
| 76 | and unreachable private calls. Program entry must be exported, zero-argument, |
| 77 | and return `int` or `void`. `main` has no special meaning in objects. |
| 78 | |
| 79 | ## Content identity and storage |
| 80 | |
| 81 | All integer fields below are unsigned little-endian 64-bit values. No trailing |
| 82 | bytes are allowed. An artifact is: |
| 83 | |
| 84 | | Offset | Value | |
| 85 | | --- | --- | |
| 86 | | 0 | Eight bytes `OMMOD001` | |
| 87 | | 8 | Compiler executable SHA-256, 64 ASCII bytes | |
| 88 | | 72 | Original source SHA-256, 64 ASCII bytes | |
| 89 | | 136 | Profile, 0 debug or 1 release | |
| 90 | | 144 | Target, 1 AArch64 Linux | |
| 91 | | 152 | Original source byte count S | |
| 92 | | 160 | Native object byte count O | |
| 93 | | 168 | Import count D | |
| 94 | | 176 | Original source, S bytes | |
| 95 | | 176 + S | Native object, O bytes | |
| 96 | | 176 + S + O | D artifact digests, 64 ASCII bytes each, in source import order | |
| 97 | |
| 98 | The complete artifact's hash is its filename, `ARTIFACT_SHA256.mod`. |
| 99 | A lookup reference has filename `KEY.ref`, containing exactly the 64 ASCII |
| 100 | bytes of that artifact hash, without a newline. `KEY` is SHA-256 of the first |
| 101 | 152 artifact bytes, which bind the domain/version, source, compiler, profile, |
| 102 | and target. The reference is only a locator: its target bytes are hashed, |
| 103 | their identity fields checked, and each dependency is required to match the |
| 104 | exact artifact digest recorded by its parent. Every level binds transitive |
| 105 | identities. A different profile or compiler never reuses a digest-only match. |
| 106 | |
| 107 | Source and compiler files are read into owned snapshots and hashed there. |
| 108 | Only those compiler bytes are written to a private randomly named executable |
| 109 | snapshot for invocation. Compiler input and output use anonymous files. The |
| 110 | snapshot is unlinked after the child is reaped. Cache payload and reference |
| 111 | publication are independent atomic no-replace renames, with checked writes, |
| 112 | file sync and directory sync. A crash between them can leave an unreferenced |
| 113 | payload; rebuilding verifies and reuses those bytes before publishing the |
| 114 | reference. Concurrent publication may safely refuse instead of overwriting. |
| 115 | Interrupted temporary files are not live references or executable link outputs. |
| 116 | |
| 117 | Link snapshots all inputs before writing the final image. It writes a unique |
| 118 | file in the selected output parent, syncs it, and renames without replacement. |
| 119 | An existing output remains untouched. A refused link creates no final output. |
| 120 | Directory traversal opens each component with AArch64 `O_DIRECTORY|O_NOFOLLOW`; |
| 121 | regular-file reads also use `O_NONBLOCK`, then require a regular-file stat, so |
| 122 | a FIFO cannot stall a read. There is no runtime module-count or object-size |
| 123 | cap. Runtime pools grow with actual input; allocation failure is a refusal. |
| 124 | Machine address space, Linux path/component lengths, the compiler's parameter |
| 125 | ABI, native branch reach, and its 8 MiB caller stack remain real boundaries. |
| 126 | |
| 127 | Length arithmetic is checked, never wrapped. Sizes, offsets and growth requests |
| 128 | go through `sizeadd`, `sizemul` and `growto`; every arena reservation refuses |
| 129 | (code 20) when used plus request passes signed address space (byte arena) or |
| 130 | 2^60-1 words (word table, the byte count must fit signed 64 bits). The SHA-256 |
| 131 | message length field is 64 bits of bit count, so inputs of 2^61 bytes or more |
| 132 | are refused before any read. The growth slack is added only when it fits. |
| 133 | |
| 134 | Content hashes provide integrity and exact identity, not publisher signatures |
| 135 | or a native-code sandbox. A caller must trust the pinned compiler and the |
| 136 | artifact identity it elects to run. A party who replaces both a reference and |
| 137 | its self-consistent contents chooses a new identity; a pinned root link still |
| 138 | refuses that substitution. |
| 139 | |
| 140 | ## Native object validation |
| 141 | |
| 142 | The standalone object is `OMOBJ001`, as produced by the compiler: |
| 143 | |
| 144 | | Offset | Value | |
| 145 | | --- | --- | |
| 146 | | 0 | Eight bytes `OMOBJ001` | |
| 147 | | 8, 16, 24 | Version 1, target 1, profile 0/1 | |
| 148 | | 32, 40 | Code start 176, code end/metadata start C | |
| 149 | | 48, 56, 64 | Function, call and explicit export counts | |
| 150 | | 72..175 | Zero | |
| 151 | |
| 152 | Code `[176,C)` starts with an AArch64 `B` slot for each export in source |
| 153 | order, or an unused word when there are none. Local calls are resolved; |
| 154 | external calls contain `0x94000000` before linking. Metadata follows code: |
| 155 | |
| 156 | * Each function: flags (0 private, 1 exported, 2 imported), object-relative |
| 157 | address (0 for imported), result type, parameter count, maximum local stack |
| 158 | bytes, name length; then name bytes, zero padding to the next 8-byte offset |
| 159 | relative to the standalone object, and its parameter records. |
| 160 | * Each parameter: type, kind (0 scalar, 2 view, 3 edit/out), element count |
| 161 | (0 for an unsized array), layout (0), fresh (0/1). |
| 162 | * Each call: object-relative instruction offset, source function index, |
| 163 | destination function index, stack cost at this call including its save area. |
| 164 | |
| 165 | Scalar type IDs are compiler IDs 1..13; 12 (`void`) is result-only. Parameters |
| 166 | must fit six native argument slots; an unsized view/edit consumes two. Imported |
| 167 | functions have zero address and stack. Names are unique within an object, |
| 168 | export entry instructions must point to the exact corresponding function, |
| 169 | real function addresses are aligned and increasing, and imports must match |
| 170 | both source aliases and complete dependency export signatures. |
| 171 | |
| 172 | Every call record must name a unique aligned instruction within its source |
| 173 | function, with the expected local branch or unresolved external opcode. Every |
| 174 | native `BL` word must have a record. Indices, counts, lengths, zero padding, |
| 175 | reserved fields, type legality and exact end-of-object are independently |
| 176 | checked. Stack needs are settled from leaves upward: |
| 177 | `need(f) = max(local(f), cost(call) + need(callee) for each call)`. |
| 178 | Unsettled functions/modules are cycles; a need above 8 MiB is refused. The |
| 179 | linker copies native code and patches call words to the resolved export |
| 180 | address, checking signed 26-bit instruction displacement reach. |
| 181 | |
| 182 | ## Link outputs |
| 183 | |
| 184 | Program output is a static AArch64 Linux ELF with separate RX code and RW |
| 185 | zero-filled context/stack segments. Its wrapper provides X7, a trap entry |
| 186 | that exits with 100 + trap code, and exactly 8 MiB of stack above the context |
| 187 | page. Normal exit uses the entry's `int` result, or zero for `void`. |
| 188 | |
| 189 | Function output starts with one `B` slot per root export in source order, |
| 190 | followed by all native module code. It retains the Omega OM2 native ABI: |
| 191 | X7 is the caller's runtime context, `[X7+16]` is its trap entry, and the caller |
| 192 | supplies a suitably sized stack and preserves the ABI's pinned registers. |
| 193 | The independent test caller follows omega-bridge's native ABI, saves host |
| 194 | callee-saved integer/FP registers, and provides its own 8 MiB stack. |
| 195 | |
| 196 | The last eight bytes are `OMLINK01`; the preceding u64 is descriptor size, |
| 197 | excluding those 16 footer bytes. The descriptor starts that many bytes before |
| 198 | the size field. It has an export count, followed in root source order by: |
| 199 | `code offset, required stack bytes, result type, parameter count, name length`, |
| 200 | then name bytes and the same 40-byte parameter records, without padding. |
| 201 | Offsets are relative to the first output byte. It is derived from the actual |
| 202 | validated objects, not a separately maintained interface file. The descriptor |
| 203 | is metadata after code, not an additional entry point. |
| 204 | |
| 205 | ## Refusals and qualification |
| 206 | |
| 207 | The driver returns 10 for usage, 20/21 for address/allocation refusal, 22..24 |
| 208 | for malformed reads/digests, 25..27 for path/read/write errors, 28 for source |
| 209 | imports, 30..32 for object/relocation validation, 33 for missing export, 34 for |
| 210 | store identity/format, 35 for import signature, 36 for cycles, 37 for stack, |
| 211 | 38 for no-replace publication failure, 39 for compiler/child failure, and 40 |
| 212 | for the requested entry. Stderr supplies that numeric code. Compiler stderr |
| 213 | is retained. Tests require an explicit driver refusal rather than accepting |
| 214 | a crash/trap as correct rejection. |
| 215 | |
| 216 | Tests cover separate native compilation, two roots reusing identical native |
| 217 | bytes, a single-unit execution oracle, function-mode scalar and array calls, |
| 218 | program and host trap paths, void and release entries, cache no-exec tracing, |
| 219 | identity/payload/metadata/relocation mutations, cycles, stack overflow, |
| 220 | symlink/FIFO handling, existing output preservation, orphan payload recovery, |
| 221 | a 71-module graph, exhaustive synthetic boundary cases for the length |
| 222 | arithmetic (exact Python integers as oracle, no large allocation), and |
| 223 | implementation mutants for relocation, stack and arithmetic checks. |