interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / spec / omegese-modules.md

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