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 / bridge / shlib / README.md

167 lines · 12475 bytes Raw Blame History Source

bridge/shlib: shared libraries from Omega alone

shlib.om writes an AArch64 Linux shared object (ELF64 ET_DYN) from two inputs: the native object seed/out/omc emits for an OM-2 unit in object mode (OMOBJ001, spec/omegese-modules.md) and a table naming the soname, the libraries it needs, its states, its lock, its imports and its exports. No C compiler, assembler or linker takes part. The same program writes a probe executable that the system's dynamic loader runs against the library.

seed/out/omc < bridge/shlib/shlib.om > shlib
{ printf 'object\nom2\n'; cat bridge/shlib/rmfake.om bridge/shlib/nvrmfake.om; } | seed/out/omc > fake.obj
./shlib lib bridge/shlib/nvrmfake.tsv fake.obj libomega-nvrm.so.1
N=gpu/nvidia/native/nvml
{ printf 'object\nom2\n'; cat $N/nvml.om $N/query.om $N/step.om
  sed '/^note/!s/\bat\b/at_/g' $N/errstr.om; cat bridge/shlib/nvml.om; } | seed/out/omc > nvml.obj
./shlib lib bridge/shlib/nvml.tsv nvml.obj libnvidia-ml.so.1
./shlib call bridge/shlib/nvml.tsv nvprobe && ./nvprobe; echo $?

The sed line is the OM-2 view of errstr.om: its parameter at is a reserved word in OM-2, so the whole-word token becomes at_ outside note lines (the gate does the same in Omega). The table format, the refusals and the exit codes are at the top of shlib.om.

What the library holds

Limits

Gate

tests/gates/run.sh shlib (manifest tests/gates/omega-shlib.gate, program gate.om, in Omega) runs these checks; gate.om's header lists each with its exact status:

  1. It builds six objects: test.om, dep.om, imp.om, the test transport (rmfake.om then nvrmfake.om), the NVML unit (four files of gpu/nvidia/native/nvml then nvml.om) and the Ampere QMD unit (gpu/nvidia/om/encoder/amp_runtime.om, amp_qmd.om, then ampqmd.om).
  2. It builds each library and its probe.
  3. It runs each probe from one scratch directory, so libnvidia-ml.so.1 finds its transport and libomshimp.so.1 its dependency through $ORIGIN. The test.tsv probe calls constants, int arguments with dirty upper halves, a trapping division followed by another call, a pointer write read back by a later call, a uint with a dirty upper half, two bodies that need 8 KiB and 16 KiB of stack (one through a private call), a uchar, ushort, byte and short each under dirty upper bits, a division inside a private callee that traps, and a body whose need sits one call cost past a 4 KiB page. The imp.tsv probe calls across imports (live registers kept, a swapped and an offset argument, the C library's strlen), keeps a counter in a state, and shows that a trap releases the lock. The nvml.tsv probe drives the real NVML bodies against the RM fake: init, count, handles, name, UUID, temperature, memory, utilization, the running processes, error strings, refused arguments and shutdown, and the narrow arguments (error code, index, name length, sensor) with their upper 32 bits set. It compares what each call writes, the word after it and the words at each pointer a refused call was given, and each error string, with the C library. Each probe also sets x19..x27, x29 and d8..d15 and checks that they and sp come back unchanged.
  4. It runs /usr/bin/readelf -W -S -d --dyn-syms on each library. readelf reads the symbols through the section headers, which the loader never looks at; it must exit 0, print no warning, show the table's soname and every needed library and list every export of the table (at least one) as a FUNC GLOBAL DEFAULT symbol line. readelf is a read-only verification oracle, not part of the build.
  5. It reads the test library's wrappers (found through .dynsym): the stack probes, each with its ADD, MOVZ and MOVKs and the wrapper's BL after it, covering the page counts gate.om's header gives; and in each wrapper the 10 STP words that save x19..x30 and d8..d15, with the matching LDPs somewhere outside the wrappers (the restore controls check the shared return at run time).
  6. It requires a second build from the same object to have identical bytes.

Its controls change one thing each (the table, the object, the library or its copy, the composed source) and must be caught with their exact exit status and, where one is given, the refusal's own text. gate.om's header lists the controls; run.sh pins the summary line.

NVML

libnvidia-ml.so.1 built from nvml.tsv exports the 11 functions of CUDApp's compat/nvml/libnvidia-ml.map with its nvml.h C signatures, with real bodies: nvml.om is CUDApp's native/nvml/api.om shell and the checks its generated C glue made, in Omega, calling the unchanged request protocol (nvml_step) and error text (nvml_errstr) directly. It needs libomega-nvrm.so.1, the transport (omega2_nvrm_open_file, omega2_nvrm_close_file, omega2_nvrm_ioctl), and runs every call under one pthread mutex. In the gate the transport is the Omega RM fake (nvrmfake.om over CUDApp's tests/nvml/rmfake.om, copied unchanged). No device is opened by the gate; a run against /dev/nvidia* needs the real transport and the GPU.

Where it can differ from the C library, only after a bug (a trap): the call returns 999 (nvmlErrorString: NULL) at once, and a trap inside the step does not reset the step's resume point as the C does after its own trap.

CUDApp C entry points

ampqmd.om with ampqmd.tsv is CUDApp's src/omega_ampere_qmd.c (its default build) as libomega-ampere-qmd.so.1: omega_ampere_policy and omega_ampere_build_qmd over the unchanged amp_qmd unit. omega_ampere_build_qmd has ten parameters; the last two come on the caller's stack, which a frame export reaches through the frame word after its states. The gate's probe checks the three refusals; one accepted build whose last two arguments it passes on the stack, every narrow argument with its upper bits set; the same build as a policy request; the policy with no q; and the byte-reserve question CUDApp's dma_alloc asks (op 2) at four sizes around the reserve and the free bytes. It compares the 256 QMD bytes each writes, the word after them and the request words, with what the C writes for the same arguments; 200000 random builds are compared with the C outside this tree.