Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/patches/40b30a239727a089 # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers ## feat(profile): DRA-419 critical source profile for seed/authority merged `40b30a239727a089` #1063 · opened 2026-11-07 05:47 UTC · closed 2026-11-15 14:36 UTC · merged 2026-11-15 14:36 UTC Imported from GitHub aien-dev/omega-mv#1063, by drakestapleton Base `943d955531b9d4d9f70deb41756c0b46441dd5e0` · Head `b27482f47212049df2e60a58dd734b347b02b319` Merged on GitHub as `6efc45728d5080b0fc5d74016a00ba8bbfcf9698`; reachable from main `c7acd2607139eedfabeac16b6042cefe8ede431f` (observed 2026-11-18T16:35:38Z) drakestapleton wrote on 2026-11-07 05:47 UTC DRA-419 adds a critical source profile for `seed/authority`: Holzmann's Power of Ten, adapted to Omega and checked mechanically. Status: IMPLEMENTED, and EXERCISED on the host (HOST_TESTED). It is not QUALIFIED, not merged and not deployed. Draft: do not self-merge. ## What changed Checker. `seed/profile/profile.om` is the checker, in seeded Omega. Its rules: Rule Checks B1 Loop bounds B2 Qualified recursion, followed by omc/DRA-311 leaf removal. Qualified recursion is not banned. B3 Allocation and global caps E1 Checked call results X1 Host words appear only in `note p10 effect` functions P1 Pure functions C1 Contract mode Modules. The profiled unit is `action.om`, `store.om` and `lock.om`, with `dispatch.om` as the consumer. The profile found defects, and this PR fixes them: - lock.om - `lread` used to return 32/33/34 as error codes. A live owner whose pid is 32 was therefore read as an error. It now reports errors through `lerr`. - `lacq` was unbounded. It now refuses more than 1000 tries, with return 43. - dispatch.om - An `actlost` error was overwritten. It now returns 79. - A `writerec` error on the lost and reconcile paths was dropped. It now returns 77. - A release error was dropped. It now returns 78 when no earlier failure code is set. - `dcopy` was unbounded and is now bounded. - store.om - `dec` now returns void. - The rule that a primary write or sync error wins over a cleanup close error is now annotated. Gates. The six authority gates were regenerated from the module text. `check.sh` now checks that they are not stale. CI. `.github/workflows/om-profile-arm64.yml` runs `seed/profile/check.sh` on pull requests, on pushes to main, weekly, and by manual dispatch. ## Evidence Run on spark-b87b (Cortex-X925/A725, GB10 present, GPU unused), core 2 only. Base is main `943d955531b9d4d9f70deb41756c0b46441dd5e0`. omc sha256 is `5f90edea61bac241398df5036990d899361a5acd9decb37954ce088ec0f6f6df`, which equals OMC_PIN. Profile binary sha256 is `98c95afffd3271c6a3f3ec20c291e918424ec355f2dabe7f3948ea1eda01e613`. The command was `taskset -c 2 nice -n 10 sh seed/profile/check.sh`, which exited 0 with `PROFILE CHECK PASS`: - Cases: `OM2GATE PASS cases=44 pass=44 fail=0 invalid=0 not_run=0`. The 44 rows are: - one refusal per rule, including the E1 dropped-error and B1 work-bound fixtures; - pre-fix controls on the real modules: main `dispatch.om` is refused at `E1:58` (a dropped release error), and `lock.om` without its retry bound is refused at `B1:111`; - capacity rows at each exact boundary, PASS at the maximum and INVALID one past it, for bytes (65535), lines (4095) and token length (63), plus more than 128 functions; - stop rows: random input and sequence input both terminate with INVALID; - the usage and missing-file exits. - Mutants: `OM2GATE FAIL cases=16 pass=8 fail=8`. There are 8 `profile.om` mutants, one per rule plus a second for B2 leaf removal. All are killed, and all controls pass. - Authority gates: Gate Result dispatch-gate 037/000 lock-gate 10/0 store-gate 077/000 dispatch-order-gate 3/0 store-exact-gate 4/0 store-cleanup-gate 18/0 - Negative control: main `lock.om` plus the new `lock-test.om` exits 1, so the pid-32 case catches the old behaviour. ## Limits - The profile is token-level and not path-sensitive. It is not a typechecker. - Callees outside the unit are not checked. - It makes no whole-kernel claim and does not cover the code behind host words. - `profile.om` and `gate.om` are not self-profiled, because their tables exceed B3. - Not run: fault-injection tests for the new dispatch codes 76–79. Those paths are covered only by the profile and by the existing 37 dispatch checks. - Cross-lane: omega-node #1060 edits `action.om`. After it lands, the unit row in `profile.cases` must still pass. Refs DRA-419. Signed: reliab (CriticalProfile, claude-opus-5-5). ### Apply it ``` git checkout -b patch-40b30a239727a089 943d955531b9d4d9f70deb41756c0b46441dd5e0 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/40b30a239727a089.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-mv 1063 b27482f47212049df2e60a58dd734b347b02b319 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":1063,"url":"https://github.com/aien-dev/omega-mv/pull/1063","export_sha256":"7319147b350ad908bf0b731068ec3be7b8dee848041dc862f71455e8e4680140","imported_utc":"2026-11-18T16:35:38Z"} ``` ### Changes ``` diff --git a/.crumb b/.crumb index 8cd3bba8a..47cf9f791 100644 --- a/.crumb +++ b/.crumb @@ -108,14 +108,14 @@ } ], "children_root": "sha256:966bedb54caa4209f9ab84526da66f6b13ce72e8831470170364eb5881355748", - "compiled_at": "2026-11-07T00:03:11Z", + "compiled_at": "2026-11-07T07:44:03Z", "compiler": "crumb-compile/1", - "digest": "sha256:c766e86587b26915acda065966218039cbb0906d4aa00d2ff65b752ed856cd8d", + "digest": "sha256:e578cb72a22966071d25ffca0528d7479ec75ecb84faa11fb979d05f6a474aab", "evidence_files": 15689, "evidence_root": "sha256:000da5d93352095d76c788394310aeee389738a37a0ff2b48cd2a85b664bbb74", - "files": 24223, - "generated_at_commit": "b740f8a0946f399f19005e944219193a1b8eadb1", - "source_tree": "sha256:e70341294fe408f345188b5e79ec08d8f37fa8d7c9d3fe6031914293fb3e2a10" + "files": 24289, + "generated_at_commit": "e6974c5d2bd02e4a9760bd7570d8cee1db4ab311", + "source_tree": "sha256:2f8bfca9be539a525899bc84e2aaa3fc232e7456a8e6bbd1f77d3029bb6cb9c4" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/om-profile-arm64.yml b/.github/workflows/om-profile-arm64.yml new file mode 100644 index 000000000..7bdaa65f9 --- /dev/null +++ b/.github/workflows/om-profile-arm64.yml @@ -0,0 +1,45 @@ +# om-profile-arm64: DRA-419 critical source profile on a GitHub-hosted ubuntu-24.04-arm machine with the +# pinned omc (om/units.sh OMC_PIN): seed/profile/check.om runs the rule fixtures, capacity and stop rows, +# one profile.om mutant per rule (five for B2), the authority unit profile, the seven authority regression +# gates and the two pre-fix negative controls. +# Weekly schedule catches drift in seed/effects/effects.om or the authority modules that PR paths miss. +# Advisory, like AIEN Checks: GitHub gates no merge (Alpha does). +name: om-profile-arm64 +on: + pull_request: + paths: ["seed/profile/**", "seed/authority/**", "seed/effects/effects.om", "seed/qualification/om2/gate.om", "seed/out/omc", "om/units.sh", ".github/workflows/om-profile-arm64.yml"] + push: + branches: [main] + schedule: + - cron: "17 5 * * 1" + workflow_dispatch: +permissions: + contents: read +jobs: + om-profile: + runs-on: ubuntu-24.04-arm + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: machine + run: uname -a; nproc + - name: omc pin + run: | + pin=$(sed -n 's/^OMC_PIN=//p' om/units.sh | tr -d '"') + got=$(sha256sum seed/out/omc | cut -c1-64) + echo "pin $pin"; echo "got $got" + [ "$pin" = "$got" ] || { echo "seed/out/omc does not match OMC_PIN"; exit 1; } + chmod +x seed/out/omc + - name: critical profile and authority gates + run: mkdir -p build/seed && seed/out/omc < seed/profile/check.om > build/seed/profile-check && chmod +x build/seed/profile-check && build/seed/profile-check 2>&1 | tee build/om-profile.log; test "${PIPESTATUS[0]}" = 0 + shell: bash + - name: logs + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: om-profile-arm64-logs + path: | + build/om-profile.log + build/seed/profile/*.log + build/seed/profile/*.out + build/seed/profile/unit.txt diff --git a/seed/authority/README.md b/seed/authority/README.md index eaa73aca3..078399286 100644 --- a/seed/authority/README.md +++ b/seed/authority/README.md @@ -14,7 +14,8 @@ dispatcher are the next phase; the C owner remains active until every consumer i | `store.om` | durable 32-word record and generation file: temp write, fsync, atomic rename, exact 256-byte read; torn/short files refused | | `dispatch.om` | persists in-flight, runs /bin/true and a static execpure effect, records performed/unknown, and marks unknown if the generation changes during the effect | | `lock.om` | cross-process O_EXCL pid lock with bounded retry and stale-pid reclaim; serializes read-check-persist, not the effect | -| `lock-test.om` | exclusive acquire, busy refusal, release, forked waiter, stale-pid reclaim and failed-release reporting | +| `lock-test.om` | exclusive acquire, busy refusal, release, forked waiter, stale-pid reclaim, failed-release reporting, a live owner with pid 32 (not a read error) and the retry-bound refusal (43) | +| `dispatch-fault-test.om` | injected actlost, actrecon, record-write and release failures; checks dispatch codes 76..79 and that the lock is released on every path | | `*-test.om` | transition and store checks; no provider simulation | | `*-gate.om` | source + test concatenation for the current single-file compiler | @@ -43,10 +44,11 @@ Expected output and exit: | reuse | `reuse checks=074 000` | 0 | | store | `store checks=077 000` | 0 | | dispatch | `dispatch checks=037 000` | 0 | -| lock | `lock checks=8 fails=0` | 0 | +| lock | `lock checks=10 fails=0` | 0 | | dispatch-order | `dispatch order checks=3 fails=0` | 0 | | store-exact | `store exact checks=4 fails=0` | 0 | | store-cleanup | `store cleanup cases=18 fails=0` | 0 | +| dispatch-fault | `dispatch fault checks=10 fails=0` | 0 | The authority gates and the standalone lock gate are run by `seed/qualification/security673/gate669.om` as part of the security qualification; the dispatcher @@ -146,9 +148,32 @@ an absent path). The lock gate checks ordinary release, directory refusal and missing-path refusal. Its directory fixture is removed with `rmdir`; run gates only in disposable test working directories, never against an active store. -The pre-effect dispatcher release check returns 78 on this failure. Other dispatcher -cleanup and final-release sites still ignore the release result; this change does not -claim those paths report it, nor does it redesign stale-lock reclamation. +The pre-effect dispatcher release check returns 78 on this failure. Since DRA-419 every later +release goes through `dfinish`, which releases and keeps an earlier failure code, or returns 78 +when the release is the only failure. This change does not redesign stale-lock reclamation. + +## Return codes added by the DRA-419 critical profile + +`seed/profile/profile.om` refused the pre-fix modules (dropped results, unbounded loops, host words +outside declared effect functions). The fixes add these codes: + +| Code | Function | Meaning | +| --- | --- | --- | +| 43 | `lacq` | more than 1000 tries requested; refused before any attempt (the retry loop is bounded by 1000) | +| 40 | `ltry` | the owner pid file could not be read (`lerr` set by `lread`: 32 open, 33 close, 34 short read). `lread` used to return 32..34 as the pid itself, so a live owner with pid 32 looked like a read error | +| 76 | `dispatch` | reconcile (`actrecon`) refused the receipt; the current (still in-flight) record is persisted unchanged by the following record write | +| 77 | `dispatch` | the post-effect record write failed, on the reconcile, lost-generation or normal path (lost-generation and reconcile write errors were dropped before) | +| 78 | `dispatch` | the lock release failed and no earlier failure is set (post-effect release errors were dropped before) | +| 79 | `dispatch` | `actlost` refused to mark the record unknown after a generation change (the error was overwritten before) | + +`dispatch-fault-gate.om` is `action.om`, `store.om`, then `dispatch.om` with the lines +`err = actlost r`, `err = actrecon r s` and `err = writerec r` calling `factlost`, `factrecon` and +`fwriterec`, then `dispatch-fault-test.om`, which replaces `lock.om` with a counting double. +`seed/profile/check.om` regenerates it with the same line replacements, compares, runs it, and runs the same injection over +the frozen pre-fix `seed/profile/cases/dispatch-943d955.om`. The pre-fix module fails cases 2, 3, 4, 5, 7 +and 8 (79, 77, 78, 79, 77, 78). Cases 0, 1, 6 and 9 (0, 60, 76, 77 normal path) are regressions that the +old code also passed. This is fault injection at the call results, not a qualification of real disk or +lock failure, and it is not yet in `gate669`. Native run (2026-10-31, Linux AArch64, seed/out/omc 7a8b84fc): `lock checks=8 fails=0`, exit 0. Negative control with `lock.om` from main 1db94162 (`lrm` returns 0 on unlink failure): no pass diff --git a/seed/authority/dispatch-fault-gate.om b/seed/authority/dispatch-fault-gate.om new file mode 100644 index 000000000..b11dac172 --- /dev/null +++ b/seed/authority/dispatch-fault-gate.om @@ -0,0 +1,669 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note OM-CONTROL-659 action contract v1. See ../README.md for the trusted-caller boundary. +note No I/O, authority minting or persistence. Caller serializes and durably commits transitions. +note Record words 0..7: version,state,attempt,limit,generation,epoch,expiry,reserved. +note Words 8..31: operation,request,scope,provider,policy,grant identities, four words each. +note State 1 ready,2 in-flight,3 unknown,4 performed. No timeout implies not performed. + +fn actvalid r view ulong 32 to ulong +if ne get r 0 1 +ret 11 +end +if or lt get r 1 1 gt get r 1 4 +ret 12 +end +if or eq get r 3 0 gt get r 3 1024 +ret 12 +end +if gt get r 2 get r 3 +ret 12 +end +if and ne get r 1 1 eq get r 2 0 +ret 12 +end +if or eq get r 4 0 eq get r 5 0 +ret 12 +end +if or eq get r 6 0 ne get r 7 0 +ret 12 +end +for g ulong 6 +bits = ulong 0 +for j ulong 4 +bits = or bits get r add 8 add mul g 4 j +end +if eq bits 0 +ret 12 +end +end +ret 0 +end + +fn actbind r view ulong 32 c view ulong 32 to ulong +for g ulong 6 +diff = ulong 0 +for j ulong 4 +at = add 8 add mul g 4 j +diff = or diff xor get r at get c at +end +if ne diff 0 +ret add 40 g +end +end +ret 0 +end + +fn actauth r view ulong 32 c view ulong 32 to ulong +if ne get c 0 1 +ret 11 +end +if or ne get c 3 0 or ne get c 6 0 ne get c 7 0 +ret 12 +end +if ne get c 1 1 +ret 30 +end +if ne get r 4 get c 4 +ret 31 +end +if ne get r 5 get c 5 +ret 32 +end +if ge get c 2 get r 6 +ret 33 +end +ret actbind r c +end + +fn actstart r edit ulong 32 c view ulong 32 to ulong +err = actvalid r +if ne err 0 +ret err +end +if eq get r 1 3 +ret 21 +end +if eq get r 1 4 +ret 22 +end +if ne get r 1 1 +ret 20 +end +if ge get r 2 get r 3 +ret 23 +end +err = actauth r c +if ne err 0 +ret err +end +put r 2 add get r 2 1 +put r 1 2 +ret 0 +end + +fn actlost r edit ulong 32 to ulong +err = actvalid r +if ne err 0 +ret err +end +if eq get r 1 3 +ret 0 +end +if ne get r 1 2 +ret 20 +end +put r 1 3 +ret 0 +end + +note A trusted receipt maps outcome 0 unknown,1 definitely not performed,2 performed. +note Not-found or timeout is outcome 0 unless the provider proves absence and quiescence. +note Receipt words 2/3: exact attempt and verification=1. Words 6/7 must be zero. +note Recording an observed outcome is permitted after expiry; another attempt is not. +fn actrecon r edit ulong 32 s view ulong 32 to ulong +err = actvalid r +if ne err 0 +ret err +end +if not or eq get r 1 2 eq get r 1 3 +ret 20 +end +if ne get s 0 1 +ret 11 +end +if or gt get s 1 2 or ne get s 6 0 ne get s 7 0 +ret 12 +end +if ne get s 3 1 +ret 36 +end +if ne get s 2 get r 2 +ret 35 +end +if ne get s 4 get r 4 +ret 31 +end +if ne get s 5 get r 5 +ret 32 +end +err = actbind r s +if ne err 0 +ret err +end +if eq get s 1 0 +put r 1 3 +ret 21 +end +if eq get s 1 1 +put r 1 1 +else +put r 1 4 +end +ret 0 +end +note SPDX-License-Identifier: AGPL-3.0-only +note Durable 32-word authority record store. Caller supplies the record and generation. +note Writes a temporary 256-byte file, fsyncs it, then atomically renames it into place. +note Reads require exactly 256 bytes; a short or torn file is refused. Store calls do not lock; the +note dispatcher holds lock.om around its read-check-persist window. +text recp "build/authority-store/rec" +text tmpp "build/authority-store/tmp" +text genp "build/authority-store/gen" +global sb uchar 256 +global stail uchar 1 +global spkt uchar 256 +global sn ulong 1 +global spath uchar 128 +global splen ulong 1 +global sgerr ulong 1 +fn put16 v ulong to void +put spkt get sn 0 uchar and v 255 +put spkt add get sn 0 1 uchar shr v 8 +put sn 0 add get sn 0 2 +end +fn setrec to void +put splen 0 len recp +for i ulong len recp +put spath i get recp i +end +end +fn settmp to void +put splen 0 len tmpp +for i ulong len tmpp +put spath i get tmpp i +end +end +fn setgen to void +put splen 0 len genp +for i ulong len genp +put spath i get genp i +end +end +fn pack2 to ulong +put sn 0 0 +put16 2 +put16 len tmpp +for i ulong len tmpp +put spkt add get sn 0 i get tmpp i +end +put sn 0 add get sn 0 len tmpp +put16 len recp +for i ulong len recp +put spkt add get sn 0 i get recp i +end +put sn 0 add get sn 0 len recp +ret get sn 0 +end +fn enc r view ulong 32 to void +for i ulong 32 +v = get r i +for j ulong 8 +put sb add mul i 8 j uchar and shr v mul j 8 255 +end +end +end +fn dec r edit ulong 32 to void +for i ulong 32 +v = ulong 0 +for j ulong 8 +v = or v shl ulong get sb add mul i 8 j mul j 8 +end +put r i v +end +end +note p10 effect +fn writerec r view ulong 32 to ulong +enc r +settmp +fd = fopen spath 0 get splen 0 577 384 +if lt fd 0 +ret 10 +end +n = write int fd sb 0 256 +if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error +cleanup = fclose int fd +ret 11 +end +if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error +cleanup = fclose int fd +ret 12 +end +if ne fclose int fd 0 +ret 13 +end +pn = pack2 +rr = renames spkt 0 pn 0 +if lt rr 0 +ret 14 +end +ret 0 +end +note p10 effect +fn readrec r edit ulong 32 to ulong +setrec +fd = fopen spath 0 get splen 0 0 0 +if lt fd 0 +ret 20 +end +n = read int fd sb 0 256 +extra = long -1 +if eq n 256 +extra = read int fd stail 0 1 +end +if ne fclose int fd 0 +ret 21 +end +if or ne n 256 ne extra 0 +ret 22 +end +dec r +ret 0 +end +note p10 effect +fn readgen to ulong +put sgerr 0 0 +setgen +fd = fopen spath 0 get splen 0 0 0 +if lt fd 0 +put sgerr 0 30 +ret 0 +end +n = read int fd sb 0 8 +extra = long -1 +if eq n 8 +extra = read int fd stail 0 1 +end +if ne fclose int fd 0 +put sgerr 0 31 +ret 0 +end +if or ne n 8 ne extra 0 +put sgerr 0 32 +ret 0 +end +v = ulong 0 +for j ulong 8 +v = or v shl ulong get sb j mul j 8 +end +ret v +end +note p10 effect +fn writegen v ulong to ulong +setgen +fd = fopen spath 0 get splen 0 577 384 +if lt fd 0 +ret 40 +end +for j ulong 8 +put sb j uchar and shr v mul j 8 255 +end +n = write int fd sb 0 8 +if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error +cleanup = fclose int fd +ret 41 +end +if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error +cleanup = fclose int fd +ret 42 +end +if ne fclose int fd 0 +ret 43 +end +ret 0 +end +note p10 pure +fn storevalid r view ulong 32 g ulong to ulong +if ne get r 0 1 +ret 51 +end +if ne get r 4 g +ret 52 +end +ret 0 +end +note SPDX-License-Identifier: AGPL-3.0-only +note Single-effect dispatcher over the action contract and durable store. +note The state is persisted in-flight before the effect. A generation change during the effect +note marks the operation unknown; a duplicate or performed record is refused. The effect here is +note a synthetic fork child: mode '1' writes generation2, mode '2' exits1, mode '0' exits0. +global dstat uchar 4 +global dpkt uchar 256 +global dn ulong 1 +global dpath uchar 128 +global dplen ulong 1 +global dpid ulong 1 +text truep "/bin/true" +text strictp "seed/authority/effect-ok" +fn dput16 v ulong to void +put dpkt get dn 0 uchar and v 255 +put dpkt add get dn 0 1 uchar shr v 8 +put dn 0 add get dn 0 2 +end +fn dcopy to void +for i ulong get dplen 0 bound 128 +put dpkt add get dn 0 i get dpath i +end +put dn 0 add get dn 0 get dplen 0 +end +fn packtrue to ulong +put dn 0 0 +dput16 1 +dput16 len truep +for i ulong len truep +put dpkt add get dn 0 i get truep i +end +put dn 0 add get dn 0 len truep +ret get dn 0 +end +fn doreceipt r view ulong 32 s edit ulong 32 outcome ulong to void +for i ulong 32 +put s i 0 +end +put s 0 1 +put s 1 outcome +put s 2 get r 2 +put s 3 1 +put s 4 get r 4 +put s 5 get r 5 +for i ulong 24 +put s add 8 i get r add 8 i +end +end +note Preserve an already established failure; otherwise expose release failure. +fn dfinish code ulong to ulong +lk = lrel +if ne code 0 +ret code +end +if ne lk 0 +ret 78 +end +ret 0 +end +note p10 effect +fn dispatch r edit ulong 32 c view ulong 32 mode uchar to ulong +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +err = readrec r +if ne err 0 +ret dfinish 70 +end +g = readgen +if ne get sgerr 0 0 +ret dfinish 71 +end +err = storevalid r g +if ne err 0 +ret dfinish err +end +err = actstart r c +if ne err 0 +ret dfinish err +end +err = fwriterec r +if ne err 0 +ret dfinish 72 +end +lk = lrel +if ne lk 0 +ret 78 +end +pid = fork +if lt pid 0 +ret 73 +end +if eq pid 0 +if eq mode 49 +e = writegen 2 +if ne e 0 +exit int 97 +end +end +if eq mode 50 +exit int 1 +end +if eq mode 51 +n = packtrue +note p10 allow E1 exec returns only on failure and the next line exits 98 +rr = execprog dpkt 0 n +exit int 98 +end +if eq mode 52 +put dn 0 0 +dput16 1 +dput16 get dplen 0 +dcopy +note p10 allow E1 exec returns only on failure and the next line exits 98 +rx = execpure dpkt 0 get dn 0 +exit int 98 +end +exit int 0 +end +wr = waitpid int pid dstat 0 len dstat 0 +if ne wr long pid +ret 74 +end +sig = ulong get dstat 0 +code = ulong get dstat 1 +g2 = readgen +if ne get sgerr 0 0 +ret 75 +end +if ne g2 g +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +err = factlost r +if ne err 0 +ret dfinish 79 +end +err = fwriterec r +if ne err 0 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk +end +ret 60 +end +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +s = new ulong 32 0 +outcome = ulong 0 +if and eq sig 0 eq code 0 +outcome = ulong 2 +end +doreceipt r s outcome +err = factrecon r s +if ne err 0 +err = fwriterec r +if ne err 0 +ret dfinish 77 +end +ret dfinish 76 +end +err = fwriterec r +if ne err 0 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk +end +if eq outcome 0 +ret 61 +end +ret 0 +end +note SPDX-License-Identifier: AGPL-3.0-only +note Fault injection for the dispatch failure codes 76..79, not a qualification of the real pid lock. +note Link action.om, store.om, dispatch.om and this file, WITHOUT lock.om. In dispatch.om the lines +note "err = actlost r", "err = actrecon r s" and "err = writerec r" call factlost, factrecon and +note fwriterec instead (dispatch-fault-gate.om is generated that way, see seed/profile/check.om). +note Call 1 of writerec and lrel is the pre-fork commit and release; call 2 is the post-run one. +global wcall ulong 1 +global wfail ulong 1 +global rcall ulong 1 +global rfail ulong 1 +global lostbad ulong 1 +global reconbad ulong 1 +global fails ulong 1 +global fline uchar 32 +text faultdir "build/authority-store" +text faultbld "build" +text failmsg "FAIL dispatch fault case " +text okfault "dispatch fault checks=10 fails=0\n" +fn lacq p ulong tries ulong to ulong +ret 0 +end +fn lrel to ulong +put rcall 0 add get rcall 0 1 +if eq get rcall 0 get rfail 0 +ret 30 +end +ret 0 +end +fn fwriterec r view ulong 32 to ulong +put wcall 0 add get wcall 0 1 +if eq get wcall 0 get wfail 0 +ret 31 +end +ret writerec r +end +fn factlost r edit ulong 32 to ulong +if ne get lostbad 0 0 +ret 20 +end +ret actlost r +end +fn factrecon r edit ulong 32 s view ulong 32 to ulong +if ne get reconbad 0 0 +ret 20 +end +ret actrecon r s +end +fn fsetup r edit ulong 32 c edit ulong 32 to void +put r 0 1 +put r 1 1 +put r 3 3 +put r 4 1 +put r 5 9 +put r 6 100 +put c 0 1 +put c 1 1 +put c 2 50 +put c 4 1 +put c 5 9 +for i ulong 24 +put r add i 8 add i 100 +put c add i 8 add i 100 +end +end +fn fbad id ulong to void +put fails 0 add get fails 0 1 +for i ulong len failmsg +put fline i get failmsg i +end +n = len failmsg +put fline n uchar add 48 id +put fline add n 1 10 +w = write 1 fline 0 add n 2 +if ne w long add n 2 +exit 90 +end +end +fn farm wf ulong rf ulong lb ulong rb ulong to void +put wcall 0 0 +put wfail 0 wf +put rcall 0 0 +put rfail 0 rf +put lostbad 0 lb +put reconbad 0 rb +end +fn fcase id ulong mode uchar want ulong to void +r = new ulong 32 0 +c = new ulong 32 0 +fsetup r c +if ne writegen 1 0 +exit 93 +end +if ne writerec r 0 +exit 94 +end +got = dispatch r c mode +if or ne got want ne get rcall 0 2 +fbad id +end +end +fn main to int +mk = makedir faultbld 0 len faultbld 448 +if not or eq mk 0 eq mk -17 +ret 91 +end +mk = makedir faultdir 0 len faultdir 448 +if not or eq mk 0 eq mk -17 +ret 92 +end +put dpid 0 ulong getpid +note Controls: no fault, normal path (child exits 0) and lost path (child moves the generation). +farm 0 0 0 0 +fcase 0 48 0 +farm 0 0 0 0 +fcase 1 49 60 +note Lost path: actlost error 79, record write error 77, release error 78, earliest error wins. +farm 0 0 1 0 +fcase 2 49 79 +farm 2 0 0 0 +fcase 3 49 77 +farm 0 2 0 0 +fcase 4 49 78 +farm 0 2 1 0 +fcase 5 49 79 +note Reconcile path: actrecon error 76, its record write error 77; normal-path release error 78. +farm 0 0 0 1 +fcase 6 48 76 +farm 2 0 0 1 +fcase 7 48 77 +farm 0 2 0 0 +fcase 8 48 78 +farm 2 0 0 0 +fcase 9 48 77 +if ne get fails 0 0 +ret 1 +end +w = write 1 okfault 0 len okfault +if ne w long len okfault +ret 95 +end +ret 0 +end diff --git a/seed/authority/dispatch-fault-test.om b/seed/authority/dispatch-fault-test.om new file mode 100644 index 000000000..3b2e0285f --- /dev/null +++ b/seed/authority/dispatch-fault-test.om @@ -0,0 +1,142 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note Fault injection for the dispatch failure codes 76..79, not a qualification of the real pid lock. +note Link action.om, store.om, dispatch.om and this file, WITHOUT lock.om. In dispatch.om the lines +note "err = actlost r", "err = actrecon r s" and "err = writerec r" call factlost, factrecon and +note fwriterec instead (dispatch-fault-gate.om is generated that way, see seed/profile/check.om). +note Call 1 of writerec and lrel is the pre-fork commit and release; call 2 is the post-run one. +global wcall ulong 1 +global wfail ulong 1 +global rcall ulong 1 +global rfail ulong 1 +global lostbad ulong 1 +global reconbad ulong 1 +global fails ulong 1 +global fline uchar 32 +text faultdir "build/authority-store" +text faultbld "build" +text failmsg "FAIL dispatch fault case " +text okfault "dispatch fault checks=10 fails=0\n" +fn lacq p ulong tries ulong to ulong +ret 0 +end +fn lrel to ulong +put rcall 0 add get rcall 0 1 +if eq get rcall 0 get rfail 0 +ret 30 +end +ret 0 +end +fn fwriterec r view ulong 32 to ulong +put wcall 0 add get wcall 0 1 +if eq get wcall 0 get wfail 0 +ret 31 +end +ret writerec r +end +fn factlost r edit ulong 32 to ulong +if ne get lostbad 0 0 +ret 20 +end +ret actlost r +end +fn factrecon r edit ulong 32 s view ulong 32 to ulong +if ne get reconbad 0 0 +ret 20 +end +ret actrecon r s +end +fn fsetup r edit ulong 32 c edit ulong 32 to void +put r 0 1 +put r 1 1 +put r 3 3 +put r 4 1 +put r 5 9 +put r 6 100 +put c 0 1 +put c 1 1 +put c 2 50 +put c 4 1 +put c 5 9 +for i ulong 24 +put r add i 8 add i 100 +put c add i 8 add i 100 +end +end +fn fbad id ulong to void +put fails 0 add get fails 0 1 +for i ulong len failmsg +put fline i get failmsg i +end +n = len failmsg +put fline n uchar add 48 id +put fline add n 1 10 +w = write 1 fline 0 add n 2 +if ne w long add n 2 +exit 90 +end +end +fn farm wf ulong rf ulong lb ulong rb ulong to void +put wcall 0 0 +put wfail 0 wf +put rcall 0 0 +put rfail 0 rf +put lostbad 0 lb +put reconbad 0 rb +end +fn fcase id ulong mode uchar want ulong to void +r = new ulong 32 0 +c = new ulong 32 0 +fsetup r c +if ne writegen 1 0 +exit 93 +end +if ne writerec r 0 +exit 94 +end +got = dispatch r c mode +if or ne got want ne get rcall 0 2 +fbad id +end +end +fn main to int +mk = makedir faultbld 0 len faultbld 448 +if not or eq mk 0 eq mk -17 +ret 91 +end +mk = makedir faultdir 0 len faultdir 448 +if not or eq mk 0 eq mk -17 +ret 92 +end +put dpid 0 ulong getpid +note Controls: no fault, normal path (child exits 0) and lost path (child moves the generation). +farm 0 0 0 0 +fcase 0 48 0 +farm 0 0 0 0 +fcase 1 49 60 +note Lost path: actlost error 79, record write error 77, release error 78, earliest error wins. +farm 0 0 1 0 +fcase 2 49 79 +farm 2 0 0 0 +fcase 3 49 77 +farm 0 2 0 0 +fcase 4 49 78 +farm 0 2 1 0 +fcase 5 49 79 +note Reconcile path: actrecon error 76, its record write error 77; normal-path release error 78. +farm 0 0 0 1 +fcase 6 48 76 +farm 2 0 0 1 +fcase 7 48 77 +farm 0 2 0 0 +fcase 8 48 78 +farm 2 0 0 0 +fcase 9 48 77 +if ne get fails 0 0 +ret 1 +end +w = write 1 okfault 0 len okfault +if ne w long len okfault +ret 95 +end +ret 0 +end diff --git a/seed/authority/dispatch-gate.om b/seed/authority/dispatch-gate.om index aed32008c..ec9f46774 100644 --- a/seed/authority/dispatch-gate.om +++ b/seed/authority/dispatch-gate.om @@ -222,7 +222,7 @@ put sb add mul i 8 j uchar and shr v mul j 8 255 end end end -fn dec r edit ulong 32 to ulong +fn dec r edit ulong 32 to void for i ulong 32 v = ulong 0 for j ulong 8 @@ -230,8 +230,8 @@ v = or v shl ulong get sb add mul i 8 j mul j 8 end put r i v end -ret 0 end +note p10 effect fn writerec r view ulong 32 to ulong enc r settmp @@ -241,10 +241,12 @@ ret 10 end n = write int fd sb 0 256 if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 11 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 12 end @@ -258,6 +260,7 @@ ret 14 end ret 0 end +note p10 effect fn readrec r edit ulong 32 to ulong setrec fd = fopen spath 0 get splen 0 0 0 @@ -275,9 +278,10 @@ end if or ne n 256 ne extra 0 ret 22 end -dv = dec r +dec r ret 0 end +note p10 effect fn readgen to ulong put sgerr 0 0 setgen @@ -305,6 +309,7 @@ v = or v shl ulong get sb j mul j 8 end ret v end +note p10 effect fn writegen v ulong to ulong setgen fd = fopen spath 0 get splen 0 577 384 @@ -316,10 +321,12 @@ put sb j uchar and shr v mul j 8 255 end n = write int fd sb 0 8 if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 41 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 42 end @@ -328,6 +335,7 @@ ret 43 end ret 0 end +note p10 pure fn storevalid r view ulong 32 g ulong to ulong if ne get r 0 1 ret 51 @@ -342,6 +350,7 @@ note Cross-process lock for the authority store. A lock is an O_EXCL file contai note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed. note This serializes the read-check-persist window. It does not serialize the effect itself. global lb uchar 8 +global lerr ulong 1 text lpath "build/authority-store/lock" fn lpid p ulong to void @@ -363,6 +372,7 @@ end ret v end +note p10 effect fn ltake p ulong to ulong fd = fopen lpath 0 len lpath 193 384 if lt fd 0 @@ -385,21 +395,27 @@ end ret 0 end +note p10 effect fn lread to ulong +put lerr 0 0 fd = fopen lpath 0 len lpath 0 0 if lt fd 0 -ret 32 +put lerr 0 32 +ret 0 end n = read int fd lb 0 8 if ne fclose int fd 0 -ret 33 +put lerr 0 33 +ret 0 end if ne n 8 -ret 34 +put lerr 0 34 +ret 0 end ret lget end +note p10 effect fn lrm to ulong r = unlink lpath 0 len lpath if lt r 0 @@ -408,6 +424,7 @@ end ret 0 end +note p10 effect fn ltry p ulong to ulong r = ltake p if eq r 0 @@ -417,7 +434,7 @@ if ne r 20 ret r end q = lread -if or eq q 32 or eq q 33 eq q 34 +if ne get lerr 0 0 ret 40 end k = killpid int q 0 @@ -431,9 +448,13 @@ end ret ltake p end +note p10 effect fn lacq p ulong tries ulong to ulong +if gt tries 1000 +ret 43 +end i = ulong 0 -while lt i tries +while lt i tries bound 1000 r = ltry p if eq r 0 ret 0 @@ -471,7 +492,7 @@ put dpkt add get dn 0 1 uchar shr v 8 put dn 0 add get dn 0 2 end fn dcopy to void -for i ulong get dplen 0 +for i ulong get dplen 0 bound 128 put dpkt add get dn 0 i get dpath i end put dn 0 add get dn 0 get dplen 0 @@ -500,6 +521,18 @@ for i ulong 24 put s add 8 i get r add 8 i end end +note Preserve an already established failure; otherwise expose release failure. +fn dfinish code ulong to ulong +lk = lrel +if ne code 0 +ret code +end +if ne lk 0 +ret 78 +end +ret 0 +end +note p10 effect fn dispatch r edit ulong 32 c view ulong 32 mode uchar to ulong err = lacq get dpid 0 1000 if ne err 0 @@ -507,28 +540,23 @@ ret 80 end err = readrec r if ne err 0 -lk = lrel -ret 70 +ret dfinish 70 end g = readgen if ne get sgerr 0 0 -lk = lrel -ret 71 +ret dfinish 71 end err = storevalid r g if ne err 0 -lk = lrel -ret err +ret dfinish err end err = actstart r c if ne err 0 -lk = lrel -ret err +ret dfinish err end err = writerec r if ne err 0 -lk = lrel -ret 72 +ret dfinish 72 end lk = lrel if ne lk 0 @@ -550,6 +578,7 @@ exit int 1 end if eq mode 51 n = packtrue +note p10 allow E1 exec returns only on failure and the next line exits 98 rr = execprog dpkt 0 n exit int 98 end @@ -558,6 +587,7 @@ put dn 0 0 dput16 1 dput16 get dplen 0 dcopy +note p10 allow E1 exec returns only on failure and the next line exits 98 rx = execpure dpkt 0 get dn 0 exit int 98 end @@ -579,8 +609,17 @@ if ne err 0 ret 80 end err = actlost r +if ne err 0 +ret dfinish 79 +end err = writerec r -lk = lrel +if ne err 0 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk +end ret 60 end err = lacq get dpid 0 1000 @@ -596,13 +635,18 @@ doreceipt r s outcome err = actrecon r s if ne err 0 err = writerec r -lk = lrel -ret 76 +if ne err 0 +ret dfinish 77 +end +ret dfinish 76 end err = writerec r -lk = lrel if ne err 0 -ret 77 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk end if eq outcome 0 ret 61 diff --git a/seed/authority/dispatch-order-gate.om b/seed/authority/dispatch-order-gate.om index e03d99501..905364677 100644 --- a/seed/authority/dispatch-order-gate.om +++ b/seed/authority/dispatch-order-gate.om @@ -222,7 +222,7 @@ put sb add mul i 8 j uchar and shr v mul j 8 255 end end end -fn dec r edit ulong 32 to ulong +fn dec r edit ulong 32 to void for i ulong 32 v = ulong 0 for j ulong 8 @@ -230,8 +230,8 @@ v = or v shl ulong get sb add mul i 8 j mul j 8 end put r i v end -ret 0 end +note p10 effect fn writerec r view ulong 32 to ulong enc r settmp @@ -241,10 +241,12 @@ ret 10 end n = write int fd sb 0 256 if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 11 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 12 end @@ -258,6 +260,7 @@ ret 14 end ret 0 end +note p10 effect fn readrec r edit ulong 32 to ulong setrec fd = fopen spath 0 get splen 0 0 0 @@ -275,9 +278,10 @@ end if or ne n 256 ne extra 0 ret 22 end -dv = dec r +dec r ret 0 end +note p10 effect fn readgen to ulong put sgerr 0 0 setgen @@ -305,6 +309,7 @@ v = or v shl ulong get sb j mul j 8 end ret v end +note p10 effect fn writegen v ulong to ulong setgen fd = fopen spath 0 get splen 0 577 384 @@ -316,10 +321,12 @@ put sb j uchar and shr v mul j 8 255 end n = write int fd sb 0 8 if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 41 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 42 end @@ -328,6 +335,7 @@ ret 43 end ret 0 end +note p10 pure fn storevalid r view ulong 32 g ulong to ulong if ne get r 0 1 ret 51 @@ -356,7 +364,7 @@ put dpkt add get dn 0 1 uchar shr v 8 put dn 0 add get dn 0 2 end fn dcopy to void -for i ulong get dplen 0 +for i ulong get dplen 0 bound 128 put dpkt add get dn 0 i get dpath i end put dn 0 add get dn 0 get dplen 0 @@ -385,6 +393,18 @@ for i ulong 24 put s add 8 i get r add 8 i end end +note Preserve an already established failure; otherwise expose release failure. +fn dfinish code ulong to ulong +lk = lrel +if ne code 0 +ret code +end +if ne lk 0 +ret 78 +end +ret 0 +end +note p10 effect fn dispatch r edit ulong 32 c view ulong 32 mode uchar to ulong err = lacq get dpid 0 1000 if ne err 0 @@ -392,28 +412,23 @@ ret 80 end err = readrec r if ne err 0 -lk = lrel -ret 70 +ret dfinish 70 end g = readgen if ne get sgerr 0 0 -lk = lrel -ret 71 +ret dfinish 71 end err = storevalid r g if ne err 0 -lk = lrel -ret err +ret dfinish err end err = actstart r c if ne err 0 -lk = lrel -ret err +ret dfinish err end err = writerec r if ne err 0 -lk = lrel -ret 72 +ret dfinish 72 end lk = lrel if ne lk 0 @@ -435,6 +450,7 @@ exit int 1 end if eq mode 51 n = packtrue +note p10 allow E1 exec returns only on failure and the next line exits 98 rr = execprog dpkt 0 n exit int 98 end @@ -443,6 +459,7 @@ put dn 0 0 dput16 1 dput16 get dplen 0 dcopy +note p10 allow E1 exec returns only on failure and the next line exits 98 rx = execpure dpkt 0 get dn 0 exit int 98 end @@ -464,8 +481,17 @@ if ne err 0 ret 80 end err = actlost r +if ne err 0 +ret dfinish 79 +end err = writerec r -lk = lrel +if ne err 0 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk +end ret 60 end err = lacq get dpid 0 1000 @@ -481,13 +507,18 @@ doreceipt r s outcome err = actrecon r s if ne err 0 err = writerec r -lk = lrel -ret 76 +if ne err 0 +ret dfinish 77 +end +ret dfinish 76 end err = writerec r -lk = lrel if ne err 0 -ret 77 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk end if eq outcome 0 ret 61 diff --git a/seed/authority/dispatch.om b/seed/authority/dispatch.om index 32f550185..bee661896 100644 --- a/seed/authority/dispatch.om +++ b/seed/authority/dispatch.om @@ -17,7 +17,7 @@ put dpkt add get dn 0 1 uchar shr v 8 put dn 0 add get dn 0 2 end fn dcopy to void -for i ulong get dplen 0 +for i ulong get dplen 0 bound 128 put dpkt add get dn 0 i get dpath i end put dn 0 add get dn 0 get dplen 0 @@ -46,6 +46,18 @@ for i ulong 24 put s add 8 i get r add 8 i end end +note Preserve an already established failure; otherwise expose release failure. +fn dfinish code ulong to ulong +lk = lrel +if ne code 0 +ret code +end +if ne lk 0 +ret 78 +end +ret 0 +end +note p10 effect fn dispatch r edit ulong 32 c view ulong 32 mode uchar to ulong err = lacq get dpid 0 1000 if ne err 0 @@ -53,28 +65,23 @@ ret 80 end err = readrec r if ne err 0 -lk = lrel -ret 70 +ret dfinish 70 end g = readgen if ne get sgerr 0 0 -lk = lrel -ret 71 +ret dfinish 71 end err = storevalid r g if ne err 0 -lk = lrel -ret err +ret dfinish err end err = actstart r c if ne err 0 -lk = lrel -ret err +ret dfinish err end err = writerec r if ne err 0 -lk = lrel -ret 72 +ret dfinish 72 end lk = lrel if ne lk 0 @@ -96,6 +103,7 @@ exit int 1 end if eq mode 51 n = packtrue +note p10 allow E1 exec returns only on failure and the next line exits 98 rr = execprog dpkt 0 n exit int 98 end @@ -104,6 +112,7 @@ put dn 0 0 dput16 1 dput16 get dplen 0 dcopy +note p10 allow E1 exec returns only on failure and the next line exits 98 rx = execpure dpkt 0 get dn 0 exit int 98 end @@ -125,8 +134,17 @@ if ne err 0 ret 80 end err = actlost r +if ne err 0 +ret dfinish 79 +end err = writerec r -lk = lrel +if ne err 0 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk +end ret 60 end err = lacq get dpid 0 1000 @@ -142,13 +160,18 @@ doreceipt r s outcome err = actrecon r s if ne err 0 err = writerec r -lk = lrel -ret 76 +if ne err 0 +ret dfinish 77 +end +ret dfinish 76 end err = writerec r -lk = lrel if ne err 0 -ret 77 +ret dfinish 77 +end +lk = dfinish 0 +if ne lk 0 +ret lk end if eq outcome 0 ret 61 diff --git a/seed/authority/lock-gate.om b/seed/authority/lock-gate.om index abd580201..5d394941f 100644 --- a/seed/authority/lock-gate.om +++ b/seed/authority/lock-gate.om @@ -3,6 +3,7 @@ note Cross-process lock for the authority store. A lock is an O_EXCL file contai note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed. note This serializes the read-check-persist window. It does not serialize the effect itself. global lb uchar 8 +global lerr ulong 1 text lpath "build/authority-store/lock" fn lpid p ulong to void @@ -24,6 +25,7 @@ end ret v end +note p10 effect fn ltake p ulong to ulong fd = fopen lpath 0 len lpath 193 384 if lt fd 0 @@ -46,21 +48,27 @@ end ret 0 end +note p10 effect fn lread to ulong +put lerr 0 0 fd = fopen lpath 0 len lpath 0 0 if lt fd 0 -ret 32 +put lerr 0 32 +ret 0 end n = read int fd lb 0 8 if ne fclose int fd 0 -ret 33 +put lerr 0 33 +ret 0 end if ne n 8 -ret 34 +put lerr 0 34 +ret 0 end ret lget end +note p10 effect fn lrm to ulong r = unlink lpath 0 len lpath if lt r 0 @@ -69,6 +77,7 @@ end ret 0 end +note p10 effect fn ltry p ulong to ulong r = ltake p if eq r 0 @@ -78,7 +87,7 @@ if ne r 20 ret r end q = lread -if or eq q 32 or eq q 33 eq q 34 +if ne get lerr 0 0 ret 40 end k = killpid int q 0 @@ -92,9 +101,13 @@ end ret ltake p end +note p10 effect fn lacq p ulong tries ulong to ulong +if gt tries 1000 +ret 43 +end i = ulong 0 -while lt i tries +while lt i tries bound 1000 r = ltry p if eq r 0 ret 0 @@ -114,8 +127,9 @@ fn lrel to ulong ret lrm end note SPDX-License-Identifier: AGPL-3.0-only -note Lock checks: exclusive acquire, busy refusal, release, a forked waiter, stale-pid reclaim, and failed release. -text passm "lock checks=8 fails=0\n" +note Lock checks: exclusive acquire, busy refusal, release, a forked waiter, stale-pid reclaim, failed release, +note an owner pid equal to an old lread error code (32), and the lacq retry cap. +text passm "lock checks=10 fails=0\n" global checks ulong 1 global fails ulong 1 global lbuf uchar 8 @@ -192,6 +206,27 @@ ret 98 end cbyte 0 check ulong get rb 0 0 +note Owner pid 32 was once read back as lread error 32 and refused with 40; it is a real pid now. +lpid 32 +fd = fopen lpath 0 len lpath 577 384 +if lt fd 0 +ret 103 +end +n = write int fd lb 0 8 +if ne n 8 +ret 104 +end +if ne fclose int fd 0 +ret 105 +end +want = ulong 20 +if eq killpid 32 0 -3 +want = ulong 0 +end +u = ltry ulong getpid +check u want +u = lacq ulong getpid 1001 +check u 43 lpid 999999 fd = fopen lpath 0 len lpath 577 384 if lt fd 0 diff --git a/seed/authority/lock-test.om b/seed/authority/lock-test.om index 641bbb81e..24b01cbc0 100644 --- a/seed/authority/lock-test.om +++ b/seed/authority/lock-test.om @@ -1,6 +1,7 @@ note SPDX-License-Identifier: AGPL-3.0-only -note Lock checks: exclusive acquire, busy refusal, release, a forked waiter, stale-pid reclaim, and failed release. -text passm "lock checks=8 fails=0\n" +note Lock checks: exclusive acquire, busy refusal, release, a forked waiter, stale-pid reclaim, failed release, +note an owner pid equal to an old lread error code (32), and the lacq retry cap. +text passm "lock checks=10 fails=0\n" global checks ulong 1 global fails ulong 1 global lbuf uchar 8 @@ -77,6 +78,27 @@ ret 98 end cbyte 0 check ulong get rb 0 0 +note Owner pid 32 was once read back as lread error 32 and refused with 40; it is a real pid now. +lpid 32 +fd = fopen lpath 0 len lpath 577 384 +if lt fd 0 +ret 103 +end +n = write int fd lb 0 8 +if ne n 8 +ret 104 +end +if ne fclose int fd 0 +ret 105 +end +want = ulong 20 +if eq killpid 32 0 -3 +want = ulong 0 +end +u = ltry ulong getpid +check u want +u = lacq ulong getpid 1001 +check u 43 lpid 999999 fd = fopen lpath 0 len lpath 577 384 if lt fd 0 diff --git a/seed/authority/lock.om b/seed/authority/lock.om index a0f868631..22d23eab2 100644 --- a/seed/authority/lock.om +++ b/seed/authority/lock.om @@ -3,6 +3,7 @@ note Cross-process lock for the authority store. A lock is an O_EXCL file contai note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed. note This serializes the read-check-persist window. It does not serialize the effect itself. global lb uchar 8 +global lerr ulong 1 text lpath "build/authority-store/lock" fn lpid p ulong to void @@ -24,6 +25,7 @@ end ret v end +note p10 effect fn ltake p ulong to ulong fd = fopen lpath 0 len lpath 193 384 if lt fd 0 @@ -46,21 +48,27 @@ end ret 0 end +note p10 effect fn lread to ulong +put lerr 0 0 fd = fopen lpath 0 len lpath 0 0 if lt fd 0 -ret 32 +put lerr 0 32 +ret 0 end n = read int fd lb 0 8 if ne fclose int fd 0 -ret 33 +put lerr 0 33 +ret 0 end if ne n 8 -ret 34 +put lerr 0 34 +ret 0 end ret lget end +note p10 effect fn lrm to ulong r = unlink lpath 0 len lpath if lt r 0 @@ -69,6 +77,7 @@ end ret 0 end +note p10 effect fn ltry p ulong to ulong r = ltake p if eq r 0 @@ -78,7 +87,7 @@ if ne r 20 ret r end q = lread -if or eq q 32 or eq q 33 eq q 34 +if ne get lerr 0 0 ret 40 end k = killpid int q 0 @@ -92,9 +101,13 @@ end ret ltake p end +note p10 effect fn lacq p ulong tries ulong to ulong +if gt tries 1000 +ret 43 +end i = ulong 0 -while lt i tries +while lt i tries bound 1000 r = ltry p if eq r 0 ret 0 diff --git a/seed/authority/store-cleanup-gate.om b/seed/authority/store-cleanup-gate.om index 0d30be5da..ec6420107 100644 --- a/seed/authority/store-cleanup-gate.om +++ b/seed/authority/store-cleanup-gate.om @@ -59,7 +59,7 @@ put sb add mul i 8 j uchar and shr v mul j 8 255 end end end -fn dec r edit ulong 32 to ulong +fn dec r edit ulong 32 to void for i ulong 32 v = ulong 0 for j ulong 8 @@ -67,8 +67,8 @@ v = or v shl ulong get sb add mul i 8 j mul j 8 end put r i v end -ret 0 end +note p10 effect fn writerec r view ulong 32 to ulong enc r settmp @@ -78,10 +78,12 @@ ret 10 end n = cwrite int fd 0 256 if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error cleanup = cfclose int fd ret 11 end if ne cfsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = cfclose int fd ret 12 end @@ -95,6 +97,7 @@ ret 14 end ret 0 end +note p10 effect fn readrec r edit ulong 32 to ulong setrec fd = cfopen 0 get splen 0 0 0 @@ -112,9 +115,10 @@ end if or ne n 256 ne extra 0 ret 22 end -dv = dec r +dec r ret 0 end +note p10 effect fn readgen to ulong put sgerr 0 0 setgen @@ -142,6 +146,7 @@ v = or v shl ulong get sb j mul j 8 end ret v end +note p10 effect fn writegen v ulong to ulong setgen fd = cfopen 0 get splen 0 577 384 @@ -153,10 +158,12 @@ put sb j uchar and shr v mul j 8 255 end n = cwrite int fd 0 8 if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error cleanup = cfclose int fd ret 41 end if ne cfsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = cfclose int fd ret 42 end @@ -165,6 +172,7 @@ ret 43 end ret 0 end +note p10 pure fn storevalid r view ulong 32 g ulong to ulong if ne get r 0 1 ret 51 diff --git a/seed/authority/store-exact-gate.om b/seed/authority/store-exact-gate.om index 57a56def7..a66b55358 100644 --- a/seed/authority/store-exact-gate.om +++ b/seed/authority/store-exact-gate.om @@ -59,7 +59,7 @@ put sb add mul i 8 j uchar and shr v mul j 8 255 end end end -fn dec r edit ulong 32 to ulong +fn dec r edit ulong 32 to void for i ulong 32 v = ulong 0 for j ulong 8 @@ -67,8 +67,8 @@ v = or v shl ulong get sb add mul i 8 j mul j 8 end put r i v end -ret 0 end +note p10 effect fn writerec r view ulong 32 to ulong enc r settmp @@ -78,10 +78,12 @@ ret 10 end n = write int fd sb 0 256 if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 11 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 12 end @@ -95,6 +97,7 @@ ret 14 end ret 0 end +note p10 effect fn readrec r edit ulong 32 to ulong setrec fd = fopen spath 0 get splen 0 0 0 @@ -112,9 +115,10 @@ end if or ne n 256 ne extra 0 ret 22 end -dv = dec r +dec r ret 0 end +note p10 effect fn readgen to ulong put sgerr 0 0 setgen @@ -142,6 +146,7 @@ v = or v shl ulong get sb j mul j 8 end ret v end +note p10 effect fn writegen v ulong to ulong setgen fd = fopen spath 0 get splen 0 577 384 @@ -153,10 +158,12 @@ put sb j uchar and shr v mul j 8 255 end n = write int fd sb 0 8 if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 41 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 42 end @@ -165,6 +172,7 @@ ret 43 end ret 0 end +note p10 pure fn storevalid r view ulong 32 g ulong to ulong if ne get r 0 1 ret 51 diff --git a/seed/authority/store-gate.om b/seed/authority/store-gate.om index 10faad6d7..2c52e1496 100644 --- a/seed/authority/store-gate.om +++ b/seed/authority/store-gate.om @@ -59,7 +59,7 @@ put sb add mul i 8 j uchar and shr v mul j 8 255 end end end -fn dec r edit ulong 32 to ulong +fn dec r edit ulong 32 to void for i ulong 32 v = ulong 0 for j ulong 8 @@ -67,8 +67,8 @@ v = or v shl ulong get sb add mul i 8 j mul j 8 end put r i v end -ret 0 end +note p10 effect fn writerec r view ulong 32 to ulong enc r settmp @@ -78,10 +78,12 @@ ret 10 end n = write int fd sb 0 256 if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 11 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 12 end @@ -95,6 +97,7 @@ ret 14 end ret 0 end +note p10 effect fn readrec r edit ulong 32 to ulong setrec fd = fopen spath 0 get splen 0 0 0 @@ -112,9 +115,10 @@ end if or ne n 256 ne extra 0 ret 22 end -dv = dec r +dec r ret 0 end +note p10 effect fn readgen to ulong put sgerr 0 0 setgen @@ -142,6 +146,7 @@ v = or v shl ulong get sb j mul j 8 end ret v end +note p10 effect fn writegen v ulong to ulong setgen fd = fopen spath 0 get splen 0 577 384 @@ -153,10 +158,12 @@ put sb j uchar and shr v mul j 8 255 end n = write int fd sb 0 8 if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 41 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 42 end @@ -165,6 +172,7 @@ ret 43 end ret 0 end +note p10 pure fn storevalid r view ulong 32 g ulong to ulong if ne get r 0 1 ret 51 diff --git a/seed/authority/store.om b/seed/authority/store.om index 0691e8484..2838a7ce2 100644 --- a/seed/authority/store.om +++ b/seed/authority/store.om @@ -59,7 +59,7 @@ put sb add mul i 8 j uchar and shr v mul j 8 255 end end end -fn dec r edit ulong 32 to ulong +fn dec r edit ulong 32 to void for i ulong 32 v = ulong 0 for j ulong 8 @@ -67,8 +67,8 @@ v = or v shl ulong get sb add mul i 8 j mul j 8 end put r i v end -ret 0 end +note p10 effect fn writerec r view ulong 32 to ulong enc r settmp @@ -78,10 +78,12 @@ ret 10 end n = write int fd sb 0 256 if ne n 256 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 11 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 12 end @@ -95,6 +97,7 @@ ret 14 end ret 0 end +note p10 effect fn readrec r edit ulong 32 to ulong setrec fd = fopen spath 0 get splen 0 0 0 @@ -112,9 +115,10 @@ end if or ne n 256 ne extra 0 ret 22 end -dv = dec r +dec r ret 0 end +note p10 effect fn readgen to ulong put sgerr 0 0 setgen @@ -142,6 +146,7 @@ v = or v shl ulong get sb j mul j 8 end ret v end +note p10 effect fn writegen v ulong to ulong setgen fd = fopen spath 0 get splen 0 577 384 @@ -153,10 +158,12 @@ put sb j uchar and shr v mul j 8 255 end n = write int fd sb 0 8 if ne n 8 +note p10 allow E1 primary write error wins over cleanup close error cleanup = fclose int fd ret 41 end if ne fsync int fd 0 +note p10 allow E1 primary sync error wins over cleanup close error cleanup = fclose int fd ret 42 end @@ -165,6 +172,7 @@ ret 43 end ret 0 end +note p10 pure fn storevalid r view ulong 32 g ulong to ulong if ne get r 0 1 ret 51 diff --git a/seed/profile/.crumb b/seed/profile/.crumb new file mode 100644 index 000000000..80eccf6a5 --- /dev/null +++ b/seed/profile/.crumb @@ -0,0 +1,20 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-11-07T07:44:03Z", + "compiler": "crumb-compile/1", + "digest": "sha256:145661c743c14a7c9b993c3d2c97c30071ffc0c135fb94e1196fdb1535ebe6a9", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 63, + "generated_at_commit": "e6974c5d2bd02e4a9760bd7570d8cee1db4ab311", + "source_tree": "sha256:264052a33ff3fff6ed67c553e6933e92770996aec2f3c16d278b0211ff55ac35" + } + }, + "layer": "seed", + "name": "profile", + "purpose": "Critical source profile (DRA-419) in seeded Omega: Power-of-Ten rules B1 B2 B3 E1 X1 P1 C1 over .om units, fixtures, checker mutants, authority-module check", + "schema_version": "1.0.0" +} diff --git a/seed/profile/README.md b/seed/profile/README.md new file mode 100644 index 000000000..36c5e539d --- /dev/null +++ b/seed/profile/README.md @@ -0,0 +1,94 @@ +# seed/profile: critical source profile (DRA-419) + +`profile.om` is a seeded-Omega checker that applies an adaptation of Holzmann's Power of Ten to a +unit of `.om` sources. It runs from the repository root, because it reads the host words from +`seed/effects/effects.om`. Compile the checked unit with the pinned `omc` too. This tool is a +token-level profile, not a parser or a typechecker. + + profile [bounds] [SOURCE ...] (no SOURCE: read the unit from stdin) + +The sources are concatenated in the order given. Line numbers refer to that concatenation. + +| exit | stdout | meaning | +|---|---|---| +| 0 | `PROFILE-PASS` | every rule holds | +| 1 | `PROFILE-REFUSED::` | first violation | +| 2 | (usage on stderr) | more than 16 arguments, or an unreadable argument | +| 3 | `PROFILE-INVALID` | a capacity was exceeded, the unit has no function, or `fn`/`end` are unbalanced | +| 4 | | I/O error, or a SOURCE cannot be opened | + +Capacities, all fail-closed (exit 3): at most 65535 input bytes, 4095 lines, 16383 tokens, 63 bytes per +token, 128 functions and 128 host words. Every loop in the checker is bounded, and its storage is +static globals only. + +## Rules + +| id | rule | +|---|---| +| B1 | `while` needs `bound N`. A `for` count must be a literal, a `const`, `len X` of a declared array, or carry `bound N`. N must be at most 8192. | +| B2 | Recursion is admitted only in qualified form. Every function on a cycle takes `depth` as its first parameter, never assigns it and has no `new`. Each in-cycle call passes `depth` unchanged, or passes `NAME` after the canonical guard `NAME = add depth 1` / `if gt NAME LIM` (LIM at most 64) / an optional call to a unit function / `ret`, `exit` or `trap` / `end`, with no reassignment of NAME before the call. The stop must close the guard's then-block: an `else` or any other structural line in the guard is refused. The assignment and the call must be in the same block instance. No line between them may leave that block or start its `else` arm; equal nesting depth alone does not count. An entry from outside the cycle passes a literal or a `const` of at most 64. The omc/DRA-311 leaf-removal analysis then runs over the remaining edges, and any surviving node is refused. | +| B3 | Each `global` and each `new` is at most 65536 elements. All globals together are at most 65536 bytes. The `new` bytes per function, and across the whole unit, are each at most 65536. | +| E1 | The result of a call or host word assigned to a name must be read on the straight-line continuation before the name is reassigned or the function returns. The exemption is `note p10 allow E1 ` on the line before. | +| X1 | Host words (the effects table) appear only in functions marked `note p10 effect` on the line before `fn`. | +| P1 | A function marked `note p10 pure` contains no `put` and calls only pure functions. | +| C1 | `requires`, `ensures` and `invariant` need an earlier `om2` line. `om2 release` is refused, because it compiles contracts out. | + +`bounds` mode checks B1, B2, B3, P1 and C1. It skips E1 and X1 for units that carry no p10 annotations, +such as `seed/omc/tests/recursion/nest.om`. + +Assignments are recognised in both spellings that the pinned omc accepts (`s_name`/`s_assign`, +`name [=] value`). One classifier serves B2, B3 and E1: a line assigns when its second token is `=`, or +when its first token is not a statement keyword, a unit function or a host word. omc refuses a +parameter, global or local named like a function (error 10) or a host word (error 16), so a leading +function or host-word name is always a call. So `nd sub nd 1` after a guard, `depth ulong 0`, a +`b new T N` frame allocation and an `r f 2` overwrite are checked like their `=` forms. The canonical +B2 guard itself must still be spelled `NAME = add depth 1`; `NAME add depth 1` is refused. + +## Profiled modules + +`seed/authority/action.om`, `store.om` and `lock.om` are profiled as one unit together with +`dispatch.om`, which is their consumer. The fixes this profile forced are as follows. + +- **lock.om** + - `lread` reported errors as pids 32, 33 and 34. It now sets `lerr`, so a live owner with pid 32 is no longer treated as a read error. + - `lacq` refuses more than 1000 tries with return 43, and its loop is bounded. +- **store.om** + - `dec` returns nothing. + - The primary write and sync error wins over a cleanup close error. This is annotated. +- **dispatch.om** + - `dcopy` is bounded. + - A release failure returns 78, unless an earlier failure code is already set. + - An `actlost` failure returns 79. Before this fix the error was overwritten. + - A `writerec` failure on the lost path, or on the reconcile path, returns 77. Before this fix it was dropped. + +## Limits (what is not proved) + +- The analysis is textual and not path-sensitive. Assignments are classified in both omc spellings, `NAME = value` and `NAME value`. + - It is conservative about loop back-edges: a result read only at a loop head is refused. + - `break` and `continue` do not end a path. + - A callee that is not defined in the unit is not treated as a call. A line that starts with such a callee is classified as an assignment to that name, so E1 may refuse it. +- The unit result is a claim only for the sources passed in. It makes no whole-kernel or + whole-repository claim, and it does not cover the code behind host words. +- `profile.om` and `gate.om` are not themselves profiled: their tables exceed B3. + +## Checks + +`seed/profile/check.om` is the driver, in seeded Omega. Build it with the pinned omc and run it from the +repository root: + +```sh +mkdir -p build/seed && seed/out/omc < seed/profile/check.om > build/seed/profile-check +chmod +x build/seed/profile-check && build/seed/profile-check +``` + +It exits 0 (`PROFILE CHECK PASS`), 1 (`PROFILE CHECK FAIL failed=N`) or 3 (`NOT_RUN`: no `seed/out/omc`, +or its sha256 is not `OMC_PIN`). It runs these checks: + +- `profile.cases` (53 rows): one refusal fixture per rule, pre-fix controls on the real modules, and the capacity and stop rows. + - Three B2 structure fixtures that the checker at `7ae0a1df` wrongly passed: `b2-else` (stop in the else arm), `b2-arm` (guard borrowed from the sibling then-arm) and `b2-sibling` (guard in a separate earlier block). One positive nested control, `ok-b2-nested`. + - Four `=`-less assignment fixtures that the checker at `795f5d0d` wrongly passed: `b2-noeq-nd` and `b2-noeq-depth` (the review probes), `e1-noeq` and `b3-noeq`. One positive non-recursive control, `ok-noeq`. +- `mutants.cases`: one `profile.om` mutant per rule, plus three more for B2 (`b2-else`, `b2-block`, `b2-noeq`) that reintroduce those defects. Each mutant is killed, and each control passes. +- The authority unit profile. +- A staleness check for the seven authority gates, then compiling and running each of them. + +`.github/workflows/om-profile-arm64.yml` runs the checks on pull requests, on pushes to main, and weekly. diff --git a/seed/profile/cases/b1-cap.om b/seed/profile/cases/b1-cap.om new file mode 100644 index 000000000..024b61f02 --- /dev/null +++ b/seed/profile/cases/b1-cap.om @@ -0,0 +1,8 @@ +note B1 mutant: a literal loop count above 8192. +fn main to int +s = ulong 0 +for i ulong 8193 +s = add s i +end +ret 0 +end diff --git a/seed/profile/cases/b1-var.om b/seed/profile/cases/b1-var.om new file mode 100644 index 000000000..ffb6bf627 --- /dev/null +++ b/seed/profile/cases/b1-var.om @@ -0,0 +1,12 @@ +note B1 mutant: a for count that is neither literal, const, len nor bound. +fn sum n ulong to ulong +s = ulong 0 +for i ulong n +s = add s i +end +ret s +end +fn main to int +v = sum 5 +ret int v +end diff --git a/seed/profile/cases/b1-while.om b/seed/profile/cases/b1-while.om new file mode 100644 index 000000000..26c6d0f6a --- /dev/null +++ b/seed/profile/cases/b1-while.om @@ -0,0 +1,8 @@ +note B1 mutant: while without a bound. +fn main to int +k = ulong 0 +while lt k 10 +k = add k 1 +end +ret 0 +end diff --git a/seed/profile/cases/b2-arm.om b/seed/profile/cases/b2-arm.om new file mode 100644 index 000000000..928c9ca36 --- /dev/null +++ b/seed/profile/cases/b2-arm.om @@ -0,0 +1,16 @@ +fn walk depth ulong to ulong +nd = ulong 0 +if eq depth 1 +nd = add depth 1 +if gt nd 64 +ret 0 +end +else +ret walk nd +end +ret 0 +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b2-else.om b/seed/profile/cases/b2-else.om new file mode 100644 index 000000000..0c1f27459 --- /dev/null +++ b/seed/profile/cases/b2-else.om @@ -0,0 +1,12 @@ +fn walk depth ulong to ulong +nd = add depth 1 +if gt nd 64 +else +ret 0 +end +ret walk nd +end +fn main to int +d = walk 64 +ret int d +end diff --git a/seed/profile/cases/b2-entry.om b/seed/profile/cases/b2-entry.om new file mode 100644 index 000000000..f3973de65 --- /dev/null +++ b/seed/profile/cases/b2-entry.om @@ -0,0 +1,13 @@ +note B2 mutant: the recursion entry passes a computed start depth. +fn walk depth ulong to ulong +nd = add depth 1 +if gt nd 16 +ret 0 +end +ret walk nd +end +fn main to int +x = ulong 3 +d = walk x +ret int d +end diff --git a/seed/profile/cases/b2-limit.om b/seed/profile/cases/b2-limit.om new file mode 100644 index 000000000..d626fdf36 --- /dev/null +++ b/seed/profile/cases/b2-limit.om @@ -0,0 +1,12 @@ +note B2 mutant: the depth guard admits more than 64 frames. +fn walk depth ulong to ulong +nd = add depth 1 +if gt nd 65 +ret 0 +end +ret walk nd +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b2-mutual.om b/seed/profile/cases/b2-mutual.om new file mode 100644 index 000000000..32aea7df6 --- /dev/null +++ b/seed/profile/cases/b2-mutual.om @@ -0,0 +1,11 @@ +note B2 mutant: mutual recursion where neither edge increases depth. +fn ping depth ulong to ulong +ret pong depth +end +fn pong depth ulong to ulong +ret ping depth +end +fn main to int +d = ping 0 +ret int d +end diff --git a/seed/profile/cases/b2-nodepth.om b/seed/profile/cases/b2-nodepth.om new file mode 100644 index 000000000..d32353ed2 --- /dev/null +++ b/seed/profile/cases/b2-nodepth.om @@ -0,0 +1,11 @@ +note B2 mutant: a recursive function whose first parameter is not depth. +fn walk n ulong to ulong +if eq n 0 +ret 0 +end +ret walk sub n 1 +end +fn main to int +d = walk 5 +ret int d +end diff --git a/seed/profile/cases/b2-noeq-depth.om b/seed/profile/cases/b2-noeq-depth.om new file mode 100644 index 000000000..e40e817fc --- /dev/null +++ b/seed/profile/cases/b2-noeq-depth.om @@ -0,0 +1,12 @@ +fn walk depth ulong to ulong +depth ulong 0 +nd = add depth 1 +if gt nd 64 +ret 0 +end +ret walk nd +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b2-noeq-nd.om b/seed/profile/cases/b2-noeq-nd.om new file mode 100644 index 000000000..ff5a17b03 --- /dev/null +++ b/seed/profile/cases/b2-noeq-nd.om @@ -0,0 +1,12 @@ +fn walk depth ulong to ulong +nd = add depth 1 +if gt nd 64 +ret 0 +end +nd sub nd 1 +ret walk nd +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b2-noguard.om b/seed/profile/cases/b2-noguard.om new file mode 100644 index 000000000..5b4e29e6d --- /dev/null +++ b/seed/profile/cases/b2-noguard.om @@ -0,0 +1,9 @@ +note B2 mutant: self recursion with no depth guard before the call. +fn walk depth ulong to ulong +nd = add depth 1 +ret walk nd +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b2-reset.om b/seed/profile/cases/b2-reset.om new file mode 100644 index 000000000..ad2d26ecd --- /dev/null +++ b/seed/profile/cases/b2-reset.om @@ -0,0 +1,13 @@ +note B2 mutant: the checked depth is reassigned between guard and call. +fn walk depth ulong to ulong +nd = add depth 1 +if gt nd 16 +ret 0 +end +nd = ulong 0 +ret walk nd +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b2-sibling.om b/seed/profile/cases/b2-sibling.om new file mode 100644 index 000000000..1574bd551 --- /dev/null +++ b/seed/profile/cases/b2-sibling.om @@ -0,0 +1,17 @@ +fn walk depth ulong to ulong +nd = ulong 0 +if eq depth 1 +nd = add depth 1 +if gt nd 64 +ret 0 +end +end +if lt depth 2 +ret walk nd +end +ret 0 +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/b3-global.om b/seed/profile/cases/b3-global.om new file mode 100644 index 000000000..62bb8c019 --- /dev/null +++ b/seed/profile/cases/b3-global.om @@ -0,0 +1,5 @@ +note B3 mutant: one global above 65536 bytes. +global big uchar 65537 +fn main to int +ret 0 +end diff --git a/seed/profile/cases/b3-new.om b/seed/profile/cases/b3-new.om new file mode 100644 index 000000000..f28e77621 --- /dev/null +++ b/seed/profile/cases/b3-new.om @@ -0,0 +1,5 @@ +note B3 mutant: a frame allocation above 65536 bytes. +fn main to int +b = new ulong 8193 0 +ret 0 +end diff --git a/seed/profile/cases/b3-noeq.om b/seed/profile/cases/b3-noeq.om new file mode 100644 index 000000000..c2e344d86 --- /dev/null +++ b/seed/profile/cases/b3-noeq.om @@ -0,0 +1,5 @@ +note B3 mutant: a frame allocation above 65536 bytes in the omc NAME new form (no =). +fn main to int +b new ulong 8193 0 +ret int get b 0 +end diff --git a/seed/profile/cases/b3-total.om b/seed/profile/cases/b3-total.om new file mode 100644 index 000000000..6be31fa9b --- /dev/null +++ b/seed/profile/cases/b3-total.om @@ -0,0 +1,7 @@ +note B3 mutant: globals that are each in range but together exceed 65536 bytes. +global a ulong 4096 +global b ulong 4096 +global c uchar 1 +fn main to int +ret 0 +end diff --git a/seed/profile/cases/c1-mode.om b/seed/profile/cases/c1-mode.om new file mode 100644 index 000000000..80110ae5d --- /dev/null +++ b/seed/profile/cases/c1-mode.om @@ -0,0 +1,9 @@ +note C1 mutant: a contract with no om2 mode line. +fn half x ulong to ulong +requires le x 100 +ret div x 2 +end +fn main to int +v = half 10 +ret int v +end diff --git a/seed/profile/cases/c1-release.om b/seed/profile/cases/c1-release.om new file mode 100644 index 000000000..4d61e9f56 --- /dev/null +++ b/seed/profile/cases/c1-release.om @@ -0,0 +1,10 @@ +note C1 mutant: release mode would compile contracts out. +om2 release +fn half x ulong to ulong +requires le x 100 +ret div x 2 +end +fn main to int +v = half 10 +ret int v +end diff --git a/seed/profile/cases/dispatch-943d955.om b/seed/profile/cases/dispatch-943d955.om new file mode 100644 index 000000000..32f550185 --- /dev/null +++ b/seed/profile/cases/dispatch-943d955.om @@ -0,0 +1,157 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note Single-effect dispatcher over the action contract and durable store. +note The state is persisted in-flight before the effect. A generation change during the effect +note marks the operation unknown; a duplicate or performed record is refused. The effect here is +note a synthetic fork child: mode '1' writes generation2, mode '2' exits1, mode '0' exits0. +global dstat uchar 4 +global dpkt uchar 256 +global dn ulong 1 +global dpath uchar 128 +global dplen ulong 1 +global dpid ulong 1 +text truep "/bin/true" +text strictp "seed/authority/effect-ok" +fn dput16 v ulong to void +put dpkt get dn 0 uchar and v 255 +put dpkt add get dn 0 1 uchar shr v 8 +put dn 0 add get dn 0 2 +end +fn dcopy to void +for i ulong get dplen 0 +put dpkt add get dn 0 i get dpath i +end +put dn 0 add get dn 0 get dplen 0 +end +fn packtrue to ulong +put dn 0 0 +dput16 1 +dput16 len truep +for i ulong len truep +put dpkt add get dn 0 i get truep i +end +put dn 0 add get dn 0 len truep +ret get dn 0 +end +fn doreceipt r view ulong 32 s edit ulong 32 outcome ulong to void +for i ulong 32 +put s i 0 +end +put s 0 1 +put s 1 outcome +put s 2 get r 2 +put s 3 1 +put s 4 get r 4 +put s 5 get r 5 +for i ulong 24 +put s add 8 i get r add 8 i +end +end +fn dispatch r edit ulong 32 c view ulong 32 mode uchar to ulong +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +err = readrec r +if ne err 0 +lk = lrel +ret 70 +end +g = readgen +if ne get sgerr 0 0 +lk = lrel +ret 71 +end +err = storevalid r g +if ne err 0 +lk = lrel +ret err +end +err = actstart r c +if ne err 0 +lk = lrel +ret err +end +err = writerec r +if ne err 0 +lk = lrel +ret 72 +end +lk = lrel +if ne lk 0 +ret 78 +end +pid = fork +if lt pid 0 +ret 73 +end +if eq pid 0 +if eq mode 49 +e = writegen 2 +if ne e 0 +exit int 97 +end +end +if eq mode 50 +exit int 1 +end +if eq mode 51 +n = packtrue +rr = execprog dpkt 0 n +exit int 98 +end +if eq mode 52 +put dn 0 0 +dput16 1 +dput16 get dplen 0 +dcopy +rx = execpure dpkt 0 get dn 0 +exit int 98 +end +exit int 0 +end +wr = waitpid int pid dstat 0 len dstat 0 +if ne wr long pid +ret 74 +end +sig = ulong get dstat 0 +code = ulong get dstat 1 +g2 = readgen +if ne get sgerr 0 0 +ret 75 +end +if ne g2 g +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +err = actlost r +err = writerec r +lk = lrel +ret 60 +end +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +s = new ulong 32 0 +outcome = ulong 0 +if and eq sig 0 eq code 0 +outcome = ulong 2 +end +doreceipt r s outcome +err = actrecon r s +if ne err 0 +err = writerec r +lk = lrel +ret 76 +end +err = writerec r +lk = lrel +if ne err 0 +ret 77 +end +if eq outcome 0 +ret 61 +end +ret 0 +end diff --git a/seed/profile/cases/dispatch-prefix.om b/seed/profile/cases/dispatch-prefix.om new file mode 100644 index 000000000..aa700a09a --- /dev/null +++ b/seed/profile/cases/dispatch-prefix.om @@ -0,0 +1,161 @@ +note E1 control: dispatch.om at main 943d9555 with only the B1 bound and the p10 annotations added. +note SPDX-License-Identifier: AGPL-3.0-only +note Single-effect dispatcher over the action contract and durable store. +note The state is persisted in-flight before the effect. A generation change during the effect +note marks the operation unknown; a duplicate or performed record is refused. The effect here is +note a synthetic fork child: mode '1' writes generation2, mode '2' exits1, mode '0' exits0. +global dstat uchar 4 +global dpkt uchar 256 +global dn ulong 1 +global dpath uchar 128 +global dplen ulong 1 +global dpid ulong 1 +text truep "/bin/true" +text strictp "seed/authority/effect-ok" +fn dput16 v ulong to void +put dpkt get dn 0 uchar and v 255 +put dpkt add get dn 0 1 uchar shr v 8 +put dn 0 add get dn 0 2 +end +fn dcopy to void +for i ulong get dplen 0 bound 128 +put dpkt add get dn 0 i get dpath i +end +put dn 0 add get dn 0 get dplen 0 +end +fn packtrue to ulong +put dn 0 0 +dput16 1 +dput16 len truep +for i ulong len truep +put dpkt add get dn 0 i get truep i +end +put dn 0 add get dn 0 len truep +ret get dn 0 +end +fn doreceipt r view ulong 32 s edit ulong 32 outcome ulong to void +for i ulong 32 +put s i 0 +end +put s 0 1 +put s 1 outcome +put s 2 get r 2 +put s 3 1 +put s 4 get r 4 +put s 5 get r 5 +for i ulong 24 +put s add 8 i get r add 8 i +end +end +note p10 effect +fn dispatch r edit ulong 32 c view ulong 32 mode uchar to ulong +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +err = readrec r +if ne err 0 +lk = lrel +ret 70 +end +g = readgen +if ne get sgerr 0 0 +lk = lrel +ret 71 +end +err = storevalid r g +if ne err 0 +lk = lrel +ret err +end +err = actstart r c +if ne err 0 +lk = lrel +ret err +end +err = writerec r +if ne err 0 +lk = lrel +ret 72 +end +lk = lrel +if ne lk 0 +ret 78 +end +pid = fork +if lt pid 0 +ret 73 +end +if eq pid 0 +if eq mode 49 +e = writegen 2 +if ne e 0 +exit int 97 +end +end +if eq mode 50 +exit int 1 +end +if eq mode 51 +n = packtrue +note p10 allow E1 exec returns only on failure and the next line exits 98 +rr = execprog dpkt 0 n +exit int 98 +end +if eq mode 52 +put dn 0 0 +dput16 1 +dput16 get dplen 0 +dcopy +note p10 allow E1 exec returns only on failure and the next line exits 98 +rx = execpure dpkt 0 get dn 0 +exit int 98 +end +exit int 0 +end +wr = waitpid int pid dstat 0 len dstat 0 +if ne wr long pid +ret 74 +end +sig = ulong get dstat 0 +code = ulong get dstat 1 +g2 = readgen +if ne get sgerr 0 0 +ret 75 +end +if ne g2 g +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +err = actlost r +err = writerec r +lk = lrel +ret 60 +end +err = lacq get dpid 0 1000 +if ne err 0 +ret 80 +end +s = new ulong 32 0 +outcome = ulong 0 +if and eq sig 0 eq code 0 +outcome = ulong 2 +end +doreceipt r s outcome +err = actrecon r s +if ne err 0 +err = writerec r +lk = lrel +ret 76 +end +err = writerec r +lk = lrel +if ne err 0 +ret 77 +end +if eq outcome 0 +ret 61 +end +ret 0 +end diff --git a/seed/profile/cases/e1-drop.om b/seed/profile/cases/e1-drop.om new file mode 100644 index 000000000..ea136151b --- /dev/null +++ b/seed/profile/cases/e1-drop.om @@ -0,0 +1,11 @@ +note E1 mutant: a host-word result assigned and never read. +text path "build/profile-e1" +note p10 effect +fn main to int +fd = fopen path 0 len path 0 0 +if lt fd 0 +ret 1 +end +r = fclose int fd +ret 0 +end diff --git a/seed/profile/cases/e1-else.om b/seed/profile/cases/e1-else.om new file mode 100644 index 000000000..f853f2e90 --- /dev/null +++ b/seed/profile/cases/e1-else.om @@ -0,0 +1,16 @@ +note E1 mutant: the result is read only in the sibling else branch, not on the continuation. +fn get1 to ulong +ret 1 +end +fn main to int +x = get1 +if gt x 1 +r = get1 +else +r = ulong 0 +if ne r 0 +ret 2 +end +end +ret 0 +end diff --git a/seed/profile/cases/e1-noeq.om b/seed/profile/cases/e1-noeq.om new file mode 100644 index 000000000..23966263f --- /dev/null +++ b/seed/profile/cases/e1-noeq.om @@ -0,0 +1,9 @@ +note E1 mutant: a call result overwritten by the omc NAME value form (no =) before it is read. +fn get1 x ulong to ulong +ret add x 1 +end +fn main to int +r = get1 1 +r get1 2 +ret int r +end diff --git a/seed/profile/cases/e1-overwrite.om b/seed/profile/cases/e1-overwrite.om new file mode 100644 index 000000000..90761be33 --- /dev/null +++ b/seed/profile/cases/e1-overwrite.om @@ -0,0 +1,12 @@ +note E1 mutant: a call result overwritten before it is read. +fn get1 to ulong +ret 1 +end +fn main to int +r = get1 +r = get1 +if ne r 0 +ret 1 +end +ret 0 +end diff --git a/seed/profile/cases/lock-943d955.om b/seed/profile/cases/lock-943d955.om new file mode 100644 index 000000000..a0f868631 --- /dev/null +++ b/seed/profile/cases/lock-943d955.om @@ -0,0 +1,115 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note Cross-process lock for the authority store. A lock is an O_EXCL file containing the owner pid. +note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed. +note This serializes the read-check-persist window. It does not serialize the effect itself. +global lb uchar 8 +text lpath "build/authority-store/lock" + +fn lpid p ulong to void +put lb 0 uchar and p 255 +put lb 1 uchar and shr p 8 255 +put lb 2 uchar and shr p 16 255 +put lb 3 uchar and shr p 24 255 +put lb 4 uchar and shr p 32 255 +put lb 5 uchar and shr p 40 255 +put lb 6 uchar and shr p 48 255 +put lb 7 uchar shr p 56 +end + +fn lget to ulong +v = ulong 0 +for i ulong 8 +v = or v shl ulong get lb i mul i 8 +end +ret v +end + +fn ltake p ulong to ulong +fd = fopen lpath 0 len lpath 193 384 +if lt fd 0 +if eq fd -17 +ret 20 +end +ret 40 +end +lpid p +n = write int fd lb 0 8 +if ne n 8 +if ne fclose int fd 0 +ret 30 +end +ret 31 +end +if ne fclose int fd 0 +ret 31 +end +ret 0 +end + +fn lread to ulong +fd = fopen lpath 0 len lpath 0 0 +if lt fd 0 +ret 32 +end +n = read int fd lb 0 8 +if ne fclose int fd 0 +ret 33 +end +if ne n 8 +ret 34 +end +ret lget +end + +fn lrm to ulong +r = unlink lpath 0 len lpath +if lt r 0 +ret 41 +end +ret 0 +end + +fn ltry p ulong to ulong +r = ltake p +if eq r 0 +ret 0 +end +if ne r 20 +ret r +end +q = lread +if or eq q 32 or eq q 33 eq q 34 +ret 40 +end +k = killpid int q 0 +if ne k -3 +ret 20 +end +r = lrm +if ne r 0 +ret 41 +end +ret ltake p +end + +fn lacq p ulong tries ulong to ulong +i = ulong 0 +while lt i tries +r = ltry p +if eq r 0 +ret 0 +end +if ne r 20 +ret r +end +if ne sleepns 1000000 0 +ret 42 +end +i = add i 1 +end +ret 22 +end + +fn lrel to ulong +ret lrm +end diff --git a/seed/profile/cases/lock-unbounded.om b/seed/profile/cases/lock-unbounded.om new file mode 100644 index 000000000..899b707d8 --- /dev/null +++ b/seed/profile/cases/lock-unbounded.om @@ -0,0 +1,129 @@ +note B1 control: lock.om with the lacq retry bound removed. +note SPDX-License-Identifier: AGPL-3.0-only +note Cross-process lock for the authority store. A lock is an O_EXCL file containing the owner pid. +note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed. +note This serializes the read-check-persist window. It does not serialize the effect itself. +global lb uchar 8 +global lerr ulong 1 +text lpath "build/authority-store/lock" + +fn lpid p ulong to void +put lb 0 uchar and p 255 +put lb 1 uchar and shr p 8 255 +put lb 2 uchar and shr p 16 255 +put lb 3 uchar and shr p 24 255 +put lb 4 uchar and shr p 32 255 +put lb 5 uchar and shr p 40 255 +put lb 6 uchar and shr p 48 255 +put lb 7 uchar shr p 56 +end + +fn lget to ulong +v = ulong 0 +for i ulong 8 +v = or v shl ulong get lb i mul i 8 +end +ret v +end + +note p10 effect +fn ltake p ulong to ulong +fd = fopen lpath 0 len lpath 193 384 +if lt fd 0 +if eq fd -17 +ret 20 +end +ret 40 +end +lpid p +n = write int fd lb 0 8 +if ne n 8 +if ne fclose int fd 0 +ret 30 +end +ret 31 +end +if ne fclose int fd 0 +ret 31 +end +ret 0 +end + +note p10 effect +fn lread to ulong +put lerr 0 0 +fd = fopen lpath 0 len lpath 0 0 +if lt fd 0 +put lerr 0 32 +ret 0 +end +n = read int fd lb 0 8 +if ne fclose int fd 0 +put lerr 0 33 +ret 0 +end +if ne n 8 +put lerr 0 34 +ret 0 +end +ret lget +end + +note p10 effect +fn lrm to ulong +r = unlink lpath 0 len lpath +if lt r 0 +ret 41 +end +ret 0 +end + +note p10 effect +fn ltry p ulong to ulong +r = ltake p +if eq r 0 +ret 0 +end +if ne r 20 +ret r +end +q = lread +if ne get lerr 0 0 +ret 40 +end +k = killpid int q 0 +if ne k -3 +ret 20 +end +r = lrm +if ne r 0 +ret 41 +end +ret ltake p +end + +note p10 effect +fn lacq p ulong tries ulong to ulong +if gt tries 1000 +ret 43 +end +i = ulong 0 +while lt i tries +r = ltry p +if eq r 0 +ret 0 +end +if ne r 20 +ret r +end +if ne sleepns 1000000 0 +ret 42 +end +i = add i 1 +end +ret 22 +end + +fn lrel to ulong +ret lrm +end diff --git a/seed/profile/cases/many-fns.om b/seed/profile/cases/many-fns.om new file mode 100644 index 000000000..b66c3516a --- /dev/null +++ b/seed/profile/cases/many-fns.om @@ -0,0 +1,258 @@ +fn fa0 to void +end +fn fa1 to void +end +fn fa2 to void +end +fn fa3 to void +end +fn fa4 to void +end +fn fa5 to void +end +fn fa6 to void +end +fn fa7 to void +end +fn fa8 to void +end +fn fa9 to void +end +fn fa10 to void +end +fn fa11 to void +end +fn fa12 to void +end +fn fa13 to void +end +fn fa14 to void +end +fn fa15 to void +end +fn fa16 to void +end +fn fa17 to void +end +fn fa18 to void +end +fn fa19 to void +end +fn fa20 to void +end +fn fa21 to void +end +fn fa22 to void +end +fn fa23 to void +end +fn fa24 to void +end +fn fa25 to void +end +fn fa26 to void +end +fn fa27 to void +end +fn fa28 to void +end +fn fa29 to void +end +fn fa30 to void +end +fn fa31 to void +end +fn fa32 to void +end +fn fa33 to void +end +fn fa34 to void +end +fn fa35 to void +end +fn fa36 to void +end +fn fa37 to void +end +fn fa38 to void +end +fn fa39 to void +end +fn fa40 to void +end +fn fa41 to void +end +fn fa42 to void +end +fn fa43 to void +end +fn fa44 to void +end +fn fa45 to void +end +fn fa46 to void +end +fn fa47 to void +end +fn fa48 to void +end +fn fa49 to void +end +fn fa50 to void +end +fn fa51 to void +end +fn fa52 to void +end +fn fa53 to void +end +fn fa54 to void +end +fn fa55 to void +end +fn fa56 to void +end +fn fa57 to void +end +fn fa58 to void +end +fn fa59 to void +end +fn fa60 to void +end +fn fa61 to void +end +fn fa62 to void +end +fn fa63 to void +end +fn fa64 to void +end +fn fa65 to void +end +fn fa66 to void +end +fn fa67 to void +end +fn fa68 to void +end +fn fa69 to void +end +fn fa70 to void +end +fn fa71 to void +end +fn fa72 to void +end +fn fa73 to void +end +fn fa74 to void +end +fn fa75 to void +end +fn fa76 to void +end +fn fa77 to void +end +fn fa78 to void +end +fn fa79 to void +end +fn fa80 to void +end +fn fa81 to void +end +fn fa82 to void +end +fn fa83 to void +end +fn fa84 to void +end +fn fa85 to void +end +fn fa86 to void +end +fn fa87 to void +end +fn fa88 to void +end +fn fa89 to void +end +fn fa90 to void +end +fn fa91 to void +end +fn fa92 to void +end +fn fa93 to void +end +fn fa94 to void +end +fn fa95 to void +end +fn fa96 to void +end +fn fa97 to void +end +fn fa98 to void +end +fn fa99 to void +end +fn fa100 to void +end +fn fa101 to void +end +fn fa102 to void +end +fn fa103 to void +end +fn fa104 to void +end +fn fa105 to void +end +fn fa106 to void +end +fn fa107 to void +end +fn fa108 to void +end +fn fa109 to void +end +fn fa110 to void +end +fn fa111 to void +end +fn fa112 to void +end +fn fa113 to void +end +fn fa114 to void +end +fn fa115 to void +end +fn fa116 to void +end +fn fa117 to void +end +fn fa118 to void +end +fn fa119 to void +end +fn fa120 to void +end +fn fa121 to void +end +fn fa122 to void +end +fn fa123 to void +end +fn fa124 to void +end +fn fa125 to void +end +fn fa126 to void +end +fn fa127 to void +end +fn fa128 to void +end diff --git a/seed/profile/cases/min.om b/seed/profile/cases/min.om new file mode 100644 index 000000000..2e2af0761 --- /dev/null +++ b/seed/profile/cases/min.om @@ -0,0 +1,4 @@ +note Minimal unit for capacity rows: stdin is appended as a second source. +fn main to int +ret 0 +end diff --git a/seed/profile/cases/ok-b2-nested.om b/seed/profile/cases/ok-b2-nested.om new file mode 100644 index 000000000..6f261d457 --- /dev/null +++ b/seed/profile/cases/ok-b2-nested.om @@ -0,0 +1,22 @@ +note Positive B2 control: guard and call in one nested block, with an inner if/else between them. +fn walk depth ulong to ulong +if lt depth 100 +nd = add depth 1 +if gt nd 64 +ret 0 +end +x = ulong 0 +if eq nd 3 +x = ulong 1 +else +x = ulong 2 +end +r = walk nd +ret add x r +end +ret 0 +end +fn main to int +d = walk 0 +ret int d +end diff --git a/seed/profile/cases/ok-noeq.om b/seed/profile/cases/ok-noeq.om new file mode 100644 index 000000000..9d5b06e94 --- /dev/null +++ b/seed/profile/cases/ok-noeq.om @@ -0,0 +1,13 @@ +note Positive control: ordinary non-recursive omc NAME value assignments (no =) are classified, not refused. +fn get1 x ulong to ulong +ret add x 1 +end +fn main to int +b new uchar 16 0 +n ulong 3 +n add n 1 +r get1 n +put b 0 uchar r +s get1 ulong get b 0 +ret int s +end diff --git a/seed/profile/cases/ok-unit.om b/seed/profile/cases/ok-unit.om new file mode 100644 index 000000000..529468b82 --- /dev/null +++ b/seed/profile/cases/ok-unit.om @@ -0,0 +1,45 @@ +note Positive unit: every rule satisfied, with each annotation form. +const LIM ulong 16 +global buf uchar 64 +text path "build/profile-ok" +note p10 pure +fn twice x ulong to ulong +ret add x x +end +note p10 effect +fn save n ulong to ulong +fd = fopen path 0 len path 577 384 +if lt fd 0 +ret 1 +end +w = write int fd buf 0 n +note p10 allow E1 the write status is reported; a close error after it is not +cl = fclose int fd +if ne w long n +ret 2 +end +ret 0 +end +fn walk depth ulong to ulong +nd = add depth 1 +if gt nd LIM +ret 0 +end +ret walk nd +end +fn main to int +s = ulong 0 +for i ulong len buf +s = add s twice i +end +k = ulong 0 +while lt k 10 bound 10 +k = add k 1 +end +r = save 8 +if ne r 0 +ret 1 +end +d = walk 0 +ret int add d s +end diff --git a/seed/profile/cases/p1-call.om b/seed/profile/cases/p1-call.om new file mode 100644 index 000000000..27d396fef --- /dev/null +++ b/seed/profile/cases/p1-call.om @@ -0,0 +1,14 @@ +note P1 mutant: a pure function calls a function that is not pure. +global g ulong 1 +fn side x ulong to ulong +put g 0 x +ret x +end +note p10 pure +fn calc x ulong to ulong +ret side x +end +fn main to int +v = calc 1 +ret int v +end diff --git a/seed/profile/cases/p1-put.om b/seed/profile/cases/p1-put.om new file mode 100644 index 000000000..456471ff7 --- /dev/null +++ b/seed/profile/cases/p1-put.om @@ -0,0 +1,11 @@ +note P1 mutant: a pure function writes state. +global g ulong 1 +note p10 pure +fn bump x ulong to ulong +put g 0 x +ret x +end +fn main to int +v = bump 1 +ret int v +end diff --git a/seed/profile/cases/x1-boundary.om b/seed/profile/cases/x1-boundary.om new file mode 100644 index 000000000..cf9d4efa9 --- /dev/null +++ b/seed/profile/cases/x1-boundary.om @@ -0,0 +1,8 @@ +note X1 mutant: a host word in a function without note p10 effect. +fn main to int +p = getpid +if lt p 0 +ret 1 +end +ret 0 +end diff --git a/seed/profile/check.om b/seed/profile/check.om new file mode 100644 index 000000000..94cbee711 --- /dev/null +++ b/seed/profile/check.om @@ -0,0 +1,1450 @@ +om2 +note SPDX-License-Identifier: AGPL-3.0-only +note seed/profile/check.om: qualification for seed/profile (DRA-419 critical source profile) and the +note profiled authority modules. Seeded Omega, program mode, Linux AArch64. It compiles and runs the +note seeded checker (profile.om), the OM-2 conductor (seed/qualification/om2/gate.om) and the authority +note gates with the pinned omc, and compares their results. +note Build and run from the repository root: +note mkdir -p build/seed && seed/out/omc < seed/profile/check.om > build/seed/profile-check +note chmod +x build/seed/profile-check && build/seed/profile-check +note Exit 0 PASS (last line PROFILE CHECK PASS), 1 FAIL (PROFILE CHECK FAIL failed=N, or a compile +note failure of gate.om or profile.om), 3 NOT_RUN (no seed/out/omc, or its sha256 is not om/units.sh +note OMC_PIN). The sha256 is FIPS 180-4 with the constants of seed/qualification/om2/fixtures. +note Children get an empty environment (execprog); stdin and stderr are inherited unless redirected. +note Scratch: build/seed/profile, removed and recreated on every run. + +text omcp "seed/out/omc" +text units "om/units.sh" +text pinkey "OMC_PIN=" +text kdec "seed/qualification/om2/fixtures/sha256-k.dec" +text ivdec "seed/qualification/om2/fixtures/sha256-iv.dec" +text bd1 "build" +text bd2 "build/seed" +text bdir "build/seed/profile" +text slash "/" +text adir "seed/authority/" +text dotom ".om" +text dotout ".out" +text dnull "/dev/null" +text mname "src" +text gatesrc "seed/qualification/om2/gate.om" +text profsrc "seed/profile/profile.om" +text ngate "gate" +text nprof "profile" +text pcases "seed/profile/profile.cases" +text mcases "seed/profile/mutants.cases" +text ncases "cases" +text nmut "mutants" +text ncaslog "cases.log" +text nmutlog "mutants.log" +text nunit "unit.txt" +text aact "seed/authority/action.om" +text asto "seed/authority/store.om" +text alck "seed/authority/lock.om" +text adis "seed/authority/dispatch.om" +text oldlock "seed/profile/cases/lock-943d955.om" +text olddis "seed/profile/cases/dispatch-943d955.om" +text nlkold "lock-old" +text nlkout "lock-old.out" +text nfold "fault-old" +text nfout "fault-old.out" +text faction "action.om" +text fstore "store.om" +text flck "lock.om" +text fdisp "dispatch.om" +text fdtest "dispatch-test.om" +text fltest "lock-test.om" +text fstest "store-test.om" +text fotest "dispatch-order-test.om" +text fxtest "store-exact-test.om" +text fctest "store-cleanup-test.om" +text fftest "dispatch-fault-test.om" +text gdisp "dispatch-gate" +text glock "lock-gate" +text gstore "store-gate" +text gorder "dispatch-order-gate" +text gexact "store-exact-gate" +text gclean "store-cleanup-gate" +text gfault "dispatch-fault-gate" +text ldisp "action.om store.om lock.om dispatch.om dispatch-test.om" +text llock "lock.om lock-test.om" +text lstore "store.om store-test.om" +text lorder "action.om store.om dispatch.om dispatch-order-test.om" +text lexact "store.om store-exact-test.om" +text ocleanm "store-cleanup-gate.om = injected store.om store-cleanup-test.om\n" +text bcleanm "store-cleanup-gate.om is stale against store.om store-cleanup-test.om\n" +text ofaultm "dispatch-fault-gate.om = injected dispatch.om\n" +text bfaultm "dispatch-fault-gate.om is stale against action.om store.om dispatch.om dispatch-fault-test.om\n" +note store-cleanup-gate routes the store descriptor calls through the test's failure injectors: +note the first occurrence on each line is replaced, in this order. +text cf1 "fopen spath" +text ct1 "cfopen" +text cf2 "write int fd sb" +text ct2 "cwrite int fd" +text cf3 "fsync int fd" +text ct3 "cfsync int fd" +text cf4 "fclose int fd" +text ct4 "cfclose int fd" +text cf5 "renames spkt" +text ct5 "crenames" +note dispatch-fault-gate routes dispatch's actlost, actrecon and writerec results through the +note test's injectors: whole-line replacements. +text ff1 "err = actlost r" +text ft1 "err = factlost r" +text ff2 "err = actrecon r s" +text ft2 "err = factrecon r s" +text ff3 "err = writerec r" +text ft3 "err = fwriterec r" +text okp "ok " +text badp "FAIL " +text nl "\n" +text nrnoomc "NOT_RUN profile: no omc at seed/out/omc\n" +text nrpin "NOT_RUN profile: omc is not the pinned compiler " +text nrsha "NOT_RUN profile: cannot read the SHA-256 constants in seed/qualification/om2/fixtures\n" +text tomc "omc " +text tgatecc "FAIL gate.om does not compile\n" +text tprofcc "FAIL profile.om does not compile\n" +text tprofsha "profile sha256 " +text pass53 "OM2GATE PASS cases=53 pass=53 fail=0 invalid=0 not_run=0" +text mut22 "OM2GATE FAIL cases=22 pass=11 fail=11 invalid=0 not_run=0" +text vctl "VERDICT ctl-" +text vmut "VERDICT m-" +text spass " PASS " +text sfail " FAIL " +text verdict "VERDICT" +text okcases "profile cases (53)\n" +text bdcases "profile cases\n" +text okmut "11 profile.om mutants killed, 11 controls pass\n" +text bdmut "profile mutants (gate exit " +text cpar ")\n" +text profok "PROFILE-PASS" +text okunit "authority unit profile\n" +text bdunit "authority unit: " +text teq ".om = " +text tstale ".om is stale against " +text tnocc " does not compile\n" +text texit0 " exit 0: " +text texit " exit " +text tcolon ": " +text oklk "pre-fix lock.om refused by lock-test (exit 1)\n" +text bdlk "pre-fix lock.om: lock-test exit " +text casep "case " +text want "234578" +text okfault "pre-fix dispatch.om fails fault cases 2 3 4 5 7 8 (79 77 78 79 77 78)\n" +text bdfault "pre-fix dispatch.om: fault gate exit " +text tcases " cases '" +text tquote "'\n" +text tpass "PROFILE CHECK PASS\n" +text tfail "PROFILE CHECK FAIL failed=" +text dbig "FAIL check.om: input or line too large\n" +text dproc "FAIL check.om: fork, wait or memfd failed\n" +text dargs "FAIL check.om: path or argument capacity\n" +text dwipe "FAIL check.om: cannot remove build/seed/profile\n" + +global pb uchar 4096 +global pbn ulong 1 +global av uchar 16384 +global avp ulong 1 +global avc ulong 1 +global avl ulong 1 +global fa uchar 4194304 +global fan ulong 1 +global fb uchar 4194304 +global fbn ulong 1 +global ln uchar 65536 +global lnn ulong 1 +global l2 uchar 65536 +global pin uchar 4096 +global pinn ulong 1 +global hexd uchar 64 +global kk uint 64 +global ivs uint 8 +global nums ulong 64 +global hv uint 8 +global ws uint 64 +global st uint 8 +global blk uchar 64 +global bk ulong 2 +global stb uchar 4 +global nfail ulong 1 +global wpath uchar 4096 +global dg uchar 4096 +global dgn ulong 1 +global nb uchar 32 + +note ---- output ------------------------------------------------------------------------------ +fn say t view uchar * to void +r = write 1 t 0 len t +end + +fn num v ulong to void +n = ulong 0 +x = v +while true bound 32 +put nb sub 31 n uchar add rem x 10 48 +n = add n 1 +x = div x 10 +if eq x 0 +break +end +end +r = write 1 nb sub 32 n n +end + +fn die t view uchar * to void +r = write 1 t 0 len t +exit 1 +end + +fn okh to void +say okp +end + +fn badh to void +put nfail 0 add get nfail 0 1 +say badp +end + +note ---- paths and argument lists ----------------------------------------------------------- +fn pclear to void +put pbn 0 0 +end + +fn pcat t view uchar * to void +p = get pbn 0 +n = len t +if gt add p n 4095 +die dargs +end +for i ulong n +put pb add p i get t i +end +put pbn 0 add p n +end + +note pb = build/seed/profile/NAME +fn bpath t view uchar * to void +pclear +pcat bdir +pcat slash +pcat t +end + +fn areset to void +put avc 0 0 +put avp 0 2 +put av 0 0 +put av 1 0 +end + +fn afix to void +p = get avp 0 +q = get avl 0 +m = sub sub p q 2 +if gt m 65535 +die dargs +end +put av q uchar and m 255 +put av add q 1 uchar shr m 8 +end + +note start a new argument record +fn anew to void +p = get avp 0 +if gt add p 2 len av +die dargs +end +put avl 0 p +put avp 0 add p 2 +c = add get avc 0 1 +put avc 0 c +put av 0 uchar and c 255 +put av 1 uchar shr c 8 +afix +end + +fn amore t view uchar * to void +p = get avp 0 +n = len t +if gt add p n len av +die dargs +end +for i ulong n +put av add p i get t i +end +put avp 0 add p n +afix +end + +fn apin to void +p = get avp 0 +n = get pinn 0 +if gt add p n len av +die dargs +end +for i ulong n +put av add p i get pin i +end +put avp 0 add p n +afix +end + +note argv[0] = build/seed/profile/NAME +fn abin t view uchar * to void +areset +anew +amore bdir +amore slash +amore t +end + +note ---- children --------------------------------------------------------------------------- +note run the argument list; a negative descriptor is inherited. Shell-style status: the exit status, +note 128 + signal for a signalled child, 127 when the program is missing, 126 when it cannot run. +fn spawn fi int fo int fe int ss bool to ulong +pid = fork +if lt pid 0 +die dproc +end +if eq pid 0 +if ge fi 0 +r = dupfd fi 0 0 +end +if ge fo 0 +r = dupfd fo 1 0 +end +if ge fe 0 +r = dupfd fe 2 0 +end +if ss +r = setsid +end +r = execprog av 0 get avp 0 +if eq r -2 +exit 127 +end +exit 126 +end +r = waitpid int pid stb 0 4 0 +if ne r pid +die dproc +end +sg = and ulong get stb 0 127 +if eq sg 0 +ret ulong get stb 1 +end +ret add sg 128 +end + +fn opr to long +ret fopen pb 0 get pbn 0 0 0 +end + +fn opw to long +ret fopen pb 0 get pbn 0 577 420 +end + +fn fclo fd long to void +if ge fd 0 +r = fclose int fd +end +end + +note run the argument list with stdout to the file pb (stderr too when both), stdin /dev/null when +note nul, in a new session when ss; status 1 when the output file cannot be created +fn runpb nul bool both bool ss bool to ulong +ofd = opw +if lt ofd 0 +ret 1 +end +ifd = long -1 +if nul +ifd = fopen dnull 0 len dnull 0 0 +end +efd = long -1 +if both +efd = ofd +end +s = spawn int ifd int ofd int efd ss +fclo ifd +fclo ofd +ret s +end + +note compile the source on descriptor sfd with the pinned omc into build/seed/profile/NAME; on +note exit 0 the output is made executable (0755) +fn compfd sfd long t view uchar * to ulong +if lt sfd 0 +ret 1 +end +bpath t +ofd = opw +if lt ofd 0 +fclo sfd +ret 1 +end +areset +anew +amore omcp +s = spawn int sfd int ofd -1 false +fclo sfd +fclo ofd +if eq s 0 +r = chmod pb 0 get pbn 0 493 +end +ret s +end + +fn comptx src view uchar * t view uchar * to ulong +pclear +pcat src +fd = opr +ret compfd fd t +end + +note a memfd holding fa, positioned at 0 +fn famem to long +fd = memfd mname 0 len mname 0 +if lt fd 0 +die dproc +end +n = get fan 0 +o = ulong 0 +while lt o n bound 4194304 +r = write int fd fa o sub n o +if le r 0 +die dproc +end +o = add o ulong r +end +r = fseek int fd 0 0 +if ne r 0 +die dproc +end +ret fd +end + +note ---- files ------------------------------------------------------------------------------ +note fb = the bytes of the file pb; false when it cannot be read +fn rdb to bool +put fbn 0 0 +fd = opr +if lt fd 0 +ret false +end +n = ulong 0 +while true bound 4194305 +if eq n len fb +die dbig +end +r = read int fd fb n sub len fb n +if lt r 0 +fclo fd +put fbn 0 n +ret false +end +if eq r 0 +break +end +n = add n ulong r +end +fclo fd +put fbn 0 n +ret true +end + +note append the bytes of the file pb to fa (cat: an unreadable file adds nothing) +fn rda to void +fd = opr +if lt fd 0 +ret +end +n = get fan 0 +while true bound 4194305 +if eq n len fa +die dbig +end +r = read int fd fa n sub len fa n +if le r 0 +break +end +n = add n ulong r +end +fclo fd +put fan 0 n +end + +fn cata t view uchar * to void +pclear +pcat t +rda +end + +fn cats t view uchar * to void +pclear +pcat adir +pcat t +rda +end + +note fa equals fb +fn sameab to bool +n = get fan 0 +if ne n get fbn 0 +ret false +end +i = ulong 0 +while lt i n bound 4194304 +if ne get fa i get fb i +ret false +end +i = add i 1 +end +ret true +end + +fn faputb b uchar to void +n = get fan 0 +if ge n len fa +die dbig +end +put fa n b +put fan 0 add n 1 +end + +note ---- lines of fb ------------------------------------------------------------------------ +note index of the next newline at or after s, or the end of fb +fn lend s ulong to ulong +n = get fbn 0 +e = s +while lt e n bound 4194305 +if eq get fb e 10 +ret e +end +e = add e 1 +end +ret n +end + +fn eqat p ulong t view uchar * to bool +if gt add p len t get fbn 0 +ret false +end +for i ulong len t +if ne get fb add p i get t i +ret false +end +end +ret true +end + +note grep -qx: some line of fb equals t +fn hasline t view uchar * to bool +n = get fbn 0 +s = ulong 0 +while lt s n bound 4194305 +e = lend s +if eq sub e s len t +if eqat s t +ret true +end +end +s = add e 1 +end +ret false +end + +fn hasin s ulong e ulong t view uchar * to bool +p = s +while le add p len t e bound 4194305 +if eqat p t +ret true +end +p = add p 1 +end +ret false +end + +fn isnm c uchar to bool +if and ge c 97 le c 122 +ret true +end +if and ge c 48 le c 57 +ret true +end +ret eq c 45 +end + +note does line [s, e) match ^PRE[a-z0-9-]*SUF +fn verok s ulong e ulong pre view uchar * suf view uchar * to bool +if gt add s len pre e +ret false +end +if eqat s pre +p = add s len pre +while lt p e bound 4194305 +if isnm get fb p +p = add p 1 +else +break +end +end +if gt add p len suf e +ret false +end +ret eqat p suf +end +ret false +end + +note grep -c '^PRE[a-z0-9-]*SUF' over fb +fn cntver pre view uchar * suf view uchar * to ulong +n = get fbn 0 +c = ulong 0 +s = ulong 0 +while lt s n bound 4194305 +e = lend s +if verok s e pre suf +c = add c 1 +end +s = add e 1 +end +ret c +end + +note grep -v ' PASS ' | grep '^VERDICT' over fb +fn badver to void +n = get fbn 0 +s = ulong 0 +while lt s n bound 4194305 +e = lend s +if eqat s verdict +if hasin s e spass +else +r = write 1 fb s sub e s +say nl +end +end +s = add e 1 +end +end + +note tail -1 of fb: raw keeps the final newline; otherwise as $(tail -1) +fn tailln raw bool to void +n = get fbn 0 +k = n +if gt n 0 +if eq get fb sub n 1 10 +k = sub n 1 +end +end +s = k +while gt s 0 bound 4194305 +if eq get fb sub s 1 10 +break +end +s = sub s 1 +end +if raw +r = write 1 fb s sub n s +else +r = write 1 fb s sub k s +end +end + +note $(cat): fb without its trailing newlines +fn catstr to void +n = get fbn 0 +while gt n 0 bound 4194305 +if ne get fb sub n 1 10 +break +end +n = sub n 1 +end +r = write 1 fb 0 n +end + +note ---- line rewriting (fb to fa) ---------------------------------------------------------- +fn lnat p ulong t view uchar * to bool +if gt add p len t get lnn 0 +ret false +end +for i ulong len t +if ne get ln add p i get t i +ret false +end +end +ret true +end + +note ln[p .. p+fl) becomes t +fn splice p ulong fl ulong t view uchar * to void +r = add p fl +k = sub get lnn 0 r +q = add p len t +if gt add q k len ln +die dbig +end +for i ulong k +put l2 i get ln add r i +end +for i ulong len t +put ln add p i get t i +end +for i ulong k +put ln add q i get l2 i +end +put lnn 0 add q k +end + +note sed s/F/T/: the first occurrence of f in ln becomes t +fn subst f view uchar * t view uchar * to void +n = get lnn 0 +p = ulong 0 +while le add p len f n bound 65537 +if lnat p f +splice p len f t +ret +end +p = add p 1 +end +end + +note sed s/^F$/T/: a line equal to f becomes t +fn wsub f view uchar * t view uchar * to void +if eq get lnn 0 len f +if lnat 0 f +for i ulong len t +put ln i get t i +end +put lnn 0 len t +end +end +end + +note fa += fb with mode 1 the store-cleanup injection, mode 2 the dispatch-fault injection +fn xform mode ulong to void +n = get fbn 0 +s = ulong 0 +while lt s n bound 4194305 +e = lend s +k = sub e s +if gt k len ln +die dbig +end +for i ulong k +put ln i get fb add s i +end +put lnn 0 k +if eq mode 1 +subst cf1 ct1 +subst cf2 ct2 +subst cf3 ct3 +subst cf4 ct4 +subst cf5 ct5 +else +wsub ff1 ft1 +wsub ff2 ft2 +wsub ff3 ft3 +end +for i ulong get lnn 0 +faputb get ln i +end +if lt e n +faputb 10 +end +s = add e 1 +end +end + +note fa = action.om store.om, injected D, dispatch-fault-test.om +fn faultsrc d view uchar * to void +put fan 0 0 +cats faction +cats fstore +pclear +pcat d +b = rdb +xform 2 +cats fftest +end + +note ---- SHA-256 (FIPS 180-4), for compiler and checker identity ---------------------------- +fn shasched to void +for i ulong 16 +b = mul i 4 +v = shl uint get blk b 24 +v = or v shl uint get blk add b 1 16 +v = or v shl uint get blk add b 2 8 +v = or v uint get blk add b 3 +put ws i v +end +for j ulong 48 +q = add j 16 +x = get ws sub q 15 +y = get ws sub q 2 +s0 = xor xor rotr x 7 rotr x 18 shr x 3 +s1 = xor xor rotr y 17 rotr y 19 shr y 10 +put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1 +end +end + +fn shat1 i ulong to uint +e = get st 4 +s1 = xor xor rotr e 6 rotr e 11 rotr e 25 +ch = xor and e get st 5 and not e get st 6 +ret add add add add get st 7 s1 ch get kk i get ws i +end + +fn shat2 to uint +a = get st 0 +b = get st 1 +c = get st 2 +s0 = xor xor rotr a 2 rotr a 13 rotr a 22 +mj = xor xor and a b and a c and b c +ret add s0 mj +end + +fn shacomp to void +shasched +for i ulong 8 +put st i get hv i +end +for i ulong 64 +t1 = shat1 i +t2 = shat2 +put st 7 get st 6 +put st 6 get st 5 +put st 5 get st 4 +put st 4 add get st 3 t1 +put st 3 get st 2 +put st 2 get st 1 +put st 1 get st 0 +put st 0 add t1 t2 +end +for i ulong 8 +put hv i add get hv i get st i +end +end + +fn shabyte b uchar to void +n = get bk 0 +put blk n b +n = add n 1 +if eq n 64 +shacomp +n = ulong 0 +end +put bk 0 n +put bk 1 add get bk 1 1 +end + +fn hexch v uint to uchar +if lt v 10 +ret uchar add v 48 +end +ret uchar add v 87 +end + +fn shafinal to void +bits = mul get bk 1 8 +shabyte 128 +while ne get bk 0 56 bound 64 +shabyte 0 +end +for i ulong 8 +shabyte uchar and shr bits mul sub 7 i 8 255 +end +for i ulong 8 +v = get hv i +for j ulong 8 +put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15 +end +end +end + +note hexd = sha256 of the file pb; false when it cannot be read +fn hashpb to bool +fd = opr +if lt fd 0 +ret false +end +for i ulong 8 +put hv i get ivs i +end +put bk 0 0 +put bk 1 0 +while true bound 1000000000 +r = read int fd ln 0 len ln +if lt r 0 +fclo fd +ret false +end +if eq r 0 +fclo fd +shafinal +ret true +end +for i ulong ulong r +shabyte get ln i +end +end +ret false +end + +note fb as WANT decimal lines, each below 2^32, into nums +fn parsenum wn ulong to bool +n = get fbn 0 +k = ulong 0 +v = ulong 0 +nd = ulong 0 +for i ulong n +c = get fb i +if and ge c 48 le c 57 +if ge nd 10 +ret false +end +v = add mul v 10 ulong sub c 48 +nd = add nd 1 +else +if or ne c 10 eq nd 0 +ret false +end +if or ge k wn gt v 4294967295 +ret false +end +put nums k v +k = add k 1 +v = ulong 0 +nd = ulong 0 +end +end +ret and eq k wn eq nd 0 +end + +fn ldconst to bool +pclear +pcat kdec +if rdb +if parsenum 64 +for i ulong 64 +put kk i uint get nums i +end +pclear +pcat ivdec +if rdb +if parsenum 8 +for i ulong 8 +put ivs i uint get nums i +end +ret true +end +end +end +end +ret false +end + +note ---- pin -------------------------------------------------------------------------------- +note pin += fb[a .. e), after a newline when pin is not empty +fn pinadd a ulong e ulong to void +m = get pinn 0 +if gt add m add 1 sub e a len pin +die dbig +end +if gt m 0 +put pin m 10 +m = add m 1 +end +for i ulong sub e a +put pin add m i get fb add a i +end +put pinn 0 add m sub e a +end + +note pin = the rest of every om/units.sh line that starts with OMC_PIN=, joined by newlines +fn ldpin to void +put pinn 0 0 +pclear +pcat units +b = rdb +n = get fbn 0 +s = ulong 0 +while lt s n bound 4194305 +e = lend s +if eqat s pinkey +pinadd add s len pinkey e +end +s = add e 1 +end +end + +fn pinok to bool +if ne get pinn 0 64 +ret false +end +for i ulong 64 +if ne get pin i get hexd i +ret false +end +end +ret true +end + +note ---- scratch directory ------------------------------------------------------------------ +fn wname d view uchar * o ulong base ulong to ulong +k = add o 19 +if eq get d k 46 +if eq get d add k 1 0 +ret 0 +end +if eq get d add k 1 46 +if eq get d add k 2 0 +ret 0 +end +end +end +put wpath base 47 +p = add base 1 +while ne get d k 0 bound 4096 +if ge p 4095 +die dwipe +end +put wpath p get d k +p = add p 1 +k = add k 1 +end +ret p +end + +fn wone d view uchar * o ulong base ulong depth ulong to ulong +rl = or ulong get d add o 16 shl ulong get d add o 17 8 +if eq rl 0 +die dwipe +end +q = wname d o base +if eq q 0 +ret rl +end +r = unlink wpath 0 q +if eq r -21 +if eq depth 0 +die dwipe +end +wipe q sub depth 1 +r = rmdir wpath 0 q +end +if ne r 0 +die dwipe +end +ret rl +end + +fn wipe base ulong depth ulong to void +d = new uchar 8192 0 +fd = fopen wpath 0 base 16384 0 +if lt fd 0 +die dwipe +end +while true bound 1000000 +n = getdnts int fd d 0 len d +if lt n 0 +die dwipe +end +if eq n 0 +break +end +o = ulong 0 +while lt o ulong n bound 8192 +o = add o wone d o base depth +end +end +fclo fd +end + +note rm -rf build/seed/profile; mkdir -p build/seed/profile +fn fresh0 to void +n = len bdir +for i ulong n +put wpath i get bdir i +end +r = unlink wpath 0 n +if eq r -21 +wipe n 16 +r = rmdir wpath 0 n +end +if and ne r 0 ne r -2 +die dwipe +end +r = makedir bd1 0 len bd1 511 +r = makedir bd2 0 len bd2 511 +r = makedir bdir 0 len bdir 511 +end + +note ---- checks ----------------------------------------------------------------------------- +note gate OMC PIN CASES build/seed/profile/SCRATCH > build/seed/profile/LOG; fb = LOG; gate status +fn rungate cases view uchar * scr view uchar * log view uchar * to ulong +abin ngate +anew +amore omcp +anew +apin +anew +amore cases +anew +amore bdir +amore slash +amore scr +bpath log +s = runpb false false false +bpath log +b = rdb +ret s +end + +note 1. Rule fixtures, real-module pre-fix controls, capacity and stop rows. +fn step1 to void +s = rungate pcases ncases ncaslog +if hasline pass53 +okh +say okcases +else +badh +say bdcases +badver +end +end + +note 2. One profile.om mutant per rule: every control PASS, every kill row FAIL. +fn step2 to void +s = rungate mcases nmut nmutlog +g = false +if eq s 1 +if hasline mut22 +if eq cntver vctl spass 11 +if eq cntver vmut sfail 11 +g = true +end +end +end +end +if g +okh +say okmut +else +badh +say bdmut +num s +say cpar +tailln true +end +end + +note 3. The profiled modules pass the profile as one unit (dispatch is the consumer of lock and store). +fn step3 to void +abin nprof +anew +amore aact +anew +amore asto +anew +amore alck +anew +amore adis +bpath nunit +s = runpb false false false +bpath nunit +b = rdb +g = false +if eq s 0 +if hasline profok +g = true +end +end +if g +okh +say okunit +else +badh +say bdunit +catstr +say nl +end +end + +note fb = seed/authority/G.om; report whether fa equals it +fn gatecmp g view uchar * to bool +pclear +pcat adir +pcat g +pcat dotom +if rdb +ret sameab +end +ret false +end + +note 4. The authority gates are the committed module text plus the test. +fn same g view uchar * lbl view uchar * to void +if gatecmp g +okh +say g +say teq +else +badh +say g +say tstale +end +say lbl +say nl +end + +fn step4a to void +put fan 0 0 +cats faction +cats fstore +cats flck +cats fdisp +cats fdtest +same gdisp ldisp +put fan 0 0 +cats flck +cats fltest +same glock llock +put fan 0 0 +cats fstore +cats fstest +same gstore lstore +put fan 0 0 +cats faction +cats fstore +cats fdisp +cats fotest +same gorder lorder +put fan 0 0 +cats fstore +cats fxtest +same gexact lexact +end + +fn step4b to void +put fan 0 0 +pclear +pcat asto +b = rdb +xform 1 +cats fctest +if gatecmp gclean +okh +say ocleanm +else +badh +say bcleanm +end +faultsrc adis +if gatecmp gfault +okh +say ofaultm +else +badh +say bfaultm +end +end + +note compile seed/authority/G.om to build/seed/profile/G and run it: stdin /dev/null, stdout and +note stderr to build/seed/profile/G.out +fn rungt g view uchar * to void +pclear +pcat adir +pcat g +pcat dotom +fd = opr +s = compfd fd g +if ne s 0 +badh +say g +say tnocc +ret +end +abin g +bpath g +pcat dotout +s = runpb true true false +bpath g +pcat dotout +b = rdb +if eq s 0 +okh +say g +say texit0 +else +badh +say g +say texit +num s +say tcolon +end +tailln false +say nl +end + +fn step4c to void +rungt gdisp +rungt glock +rungt gstore +rungt gorder +rungt gexact +rungt gclean +rungt gfault +end + +note the digit after every "case " in fb (grep -o 'case [0-9]' | tr -d 'case ' | tr -d '\n') +fn digits to void +n = get fbn 0 +m = ulong 0 +p = ulong 0 +while lt add p 5 n bound 4194305 +g = false +if eqat p casep +c = get fb add p 5 +if and ge c 48 le c 57 +g = true +if ge m len dg +die dbig +end +put dg m c +m = add m 1 +end +end +if g +p = add p 6 +else +p = add p 1 +end +end +put dgn 0 m +end + +fn dgok to bool +if ne get dgn 0 len want +ret false +end +for i ulong len want +if ne get dg i get want i +ret false +end +end +ret true +end + +note 5. Negative controls: the pre-fix modules of main 943d955 fail the new regression tests. +note The old lock test run may signal its own process group, so it runs in a new session. +fn step5a to void +put fan 0 0 +cata oldlock +cats fltest +fd = famem +s = compfd fd nlkold +abin nlkold +bpath nlkout +s = runpb true true true +if eq s 1 +okh +say oklk +else +badh +say bdlk +num s +say nl +end +end + +fn step5b to void +faultsrc olddis +fd = famem +s = compfd fd nfold +abin nfold +bpath nfout +s = runpb true true true +bpath nfout +b = rdb +digits +g = false +if eq s 1 +if dgok +g = true +end +end +if g +okh +say okfault +else +badh +say bdfault +num s +say tcases +r = write 1 dg 0 get dgn 0 +say tquote +end +end + +fn main to int +ldpin +r = faccess omcp 0 len omcp 1 +if ne r 0 +say nrnoomc +ret 3 +end +if ldconst +else +say nrsha +ret 3 +end +pclear +pcat omcp +g = false +if hashpb +g = pinok +end +if g +else +say nrpin +r = write 1 pin 0 get pinn 0 +say nl +ret 3 +end +fresh0 +put nfail 0 0 +say tomc +r = write 1 pin 0 get pinn 0 +say nl +if ne comptx gatesrc ngate 0 +say tgatecc +ret 1 +end +if ne comptx profsrc nprof 0 +say tprofcc +ret 1 +end +bpath nprof +g = hashpb +say tprofsha +r = write 1 hexd 0 64 +say nl +step1 +step2 +step3 +step4a +step4b +step4c +step5a +step5b +if eq get nfail 0 0 +say tpass +ret 0 +end +say tfail +num get nfail 0 +say nl +ret 1 +end diff --git a/seed/profile/mutants.cases b/seed/profile/mutants.cases new file mode 100644 index 000000000..ca3e998ff --- /dev/null +++ b/seed/profile/mutants.cases @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: AGPL-3.0-only +# seed/profile/mutants.cases: one profile.om mutant per enforced rule (five for B2: guard limit, +# DRA-311 leaf removal, stop in the guard's then-block, same block instance, NAME value assignment +# without =). Each mutant disables one check; its control row (ok-unit) must PASS and its kill row +# (the matching rule fixture) must FAIL. +# Expected: OM2GATE FAIL cases=22 pass=11 fail=11 invalid=0 not_run=0 +# --- mutant b1-cap +subst seed/profile/mutants/b1-cap.from seed/profile/mutants/b1-cap.to +ctl-b1-cap run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b1-cap.from seed/profile/mutants/b1-cap.to +m-b1-cap run seed/profile/profile.om - line:PROFILE-REFUSED:B1:4 - 1 seed/profile/cases/b1-while.om +# --- mutant b2-limit +subst seed/profile/mutants/b2-limit.from seed/profile/mutants/b2-limit.to +ctl-b2-limit run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b2-limit.from seed/profile/mutants/b2-limit.to +m-b2-limit run seed/profile/profile.om - line:PROFILE-REFUSED:B2:7 - 1 seed/profile/cases/b2-limit.om +# --- mutant b2-leaf +subst seed/profile/mutants/b2-leaf.from seed/profile/mutants/b2-leaf.to +ctl-b2-leaf run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b2-leaf.from seed/profile/mutants/b2-leaf.to +m-b2-leaf run seed/profile/profile.om - line:PROFILE-REFUSED:B2:2 - 1 seed/profile/cases/b2-mutual.om +# --- mutant b2-else: the optional guard line may again be any line (else included) +subst seed/profile/mutants/b2-else.from seed/profile/mutants/b2-else.to +ctl-b2-else run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b2-else.from seed/profile/mutants/b2-else.to +m-b2-else run seed/profile/profile.om - line:PROFILE-REFUSED:B2:7 - 1 seed/profile/cases/b2-else.om +# --- mutant b2-block: equal nesting depth again counts as the same block +subst seed/profile/mutants/b2-block.from seed/profile/mutants/b2-block.to +ctl-b2-block run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b2-block.from seed/profile/mutants/b2-block.to +m-b2-block run seed/profile/profile.om - line:PROFILE-REFUSED:B2:9 - 1 seed/profile/cases/b2-arm.om +# --- mutant b2-noeq: the shared assignment classifier again recognises only NAME = value +subst seed/profile/mutants/b2-noeq.from seed/profile/mutants/b2-noeq.to +ctl-b2-noeq run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b2-noeq.from seed/profile/mutants/b2-noeq.to +m-b2-noeq run seed/profile/profile.om - line:PROFILE-REFUSED:B2:7 - 1 seed/profile/cases/b2-noeq-nd.om +# --- mutant b3-total +subst seed/profile/mutants/b3-total.from seed/profile/mutants/b3-total.to +ctl-b3-total run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/b3-total.from seed/profile/mutants/b3-total.to +m-b3-total run seed/profile/profile.om - line:PROFILE-REFUSED:B3:4 - 1 seed/profile/cases/b3-total.om +# --- mutant e1-used +subst seed/profile/mutants/e1-used.from seed/profile/mutants/e1-used.to +ctl-e1-used run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/e1-used.from seed/profile/mutants/e1-used.to +m-e1-used run seed/profile/profile.om - line:PROFILE-REFUSED:E1:9 - 1 seed/profile/cases/e1-drop.om +# --- mutant x1-effect +subst seed/profile/mutants/x1-effect.from seed/profile/mutants/x1-effect.to +ctl-x1-effect run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/x1-effect.from seed/profile/mutants/x1-effect.to +m-x1-effect run seed/profile/profile.om - line:PROFILE-REFUSED:X1:3 - 1 seed/profile/cases/x1-boundary.om +# --- mutant p1-put +subst seed/profile/mutants/p1-put.from seed/profile/mutants/p1-put.to +ctl-p1-put run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/p1-put.from seed/profile/mutants/p1-put.to +m-p1-put run seed/profile/profile.om - line:PROFILE-REFUSED:P1:5 - 1 seed/profile/cases/p1-put.om +# --- mutant c1-mode +subst seed/profile/mutants/c1-mode.from seed/profile/mutants/c1-mode.to +ctl-c1-mode run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +subst seed/profile/mutants/c1-mode.from seed/profile/mutants/c1-mode.to +m-c1-mode run seed/profile/profile.om - line:PROFILE-REFUSED:C1:3 - 1 seed/profile/cases/c1-mode.om diff --git a/seed/profile/mutants/b1-cap.from b/seed/profile/mutants/b1-cap.from new file mode 100644 index 000000000..521c411ed --- /dev/null +++ b/seed/profile/mutants/b1-cap.from @@ -0,0 +1,2 @@ +if gt v 8192 +refuse 0 l diff --git a/seed/profile/mutants/b1-cap.to b/seed/profile/mutants/b1-cap.to new file mode 100644 index 000000000..aab165657 --- /dev/null +++ b/seed/profile/mutants/b1-cap.to @@ -0,0 +1,2 @@ +if gt v 1048577 +refuse 0 l diff --git a/seed/profile/mutants/b2-block.from b/seed/profile/mutants/b2-block.from new file mode 100644 index 000000000..6908683a5 --- /dev/null +++ b/seed/profile/mutants/b2-block.from @@ -0,0 +1 @@ +if not sameblk p l dl diff --git a/seed/profile/mutants/b2-block.to b/seed/profile/mutants/b2-block.to new file mode 100644 index 000000000..d377b72af --- /dev/null +++ b/seed/profile/mutants/b2-block.to @@ -0,0 +1 @@ +if eq dl 0 diff --git a/seed/profile/mutants/b2-else.from b/seed/profile/mutants/b2-else.from new file mode 100644 index 000000000..6666ce967 --- /dev/null +++ b/seed/profile/mutants/b2-else.from @@ -0,0 +1 @@ +if ge func at q 0 128 diff --git a/seed/profile/mutants/b2-else.to b/seed/profile/mutants/b2-else.to new file mode 100644 index 000000000..835518b0e --- /dev/null +++ b/seed/profile/mutants/b2-else.to @@ -0,0 +1 @@ +if eq q 0 diff --git a/seed/profile/mutants/b2-leaf.from b/seed/profile/mutants/b2-leaf.from new file mode 100644 index 000000000..804280d34 --- /dev/null +++ b/seed/profile/mutants/b2-leaf.from @@ -0,0 +1,2 @@ +if ne get alive i 0 +refuse 1 get fs i diff --git a/seed/profile/mutants/b2-leaf.to b/seed/profile/mutants/b2-leaf.to new file mode 100644 index 000000000..5e2ae79e0 --- /dev/null +++ b/seed/profile/mutants/b2-leaf.to @@ -0,0 +1,2 @@ +if eq get alive i 9 +refuse 1 get fs i diff --git a/seed/profile/mutants/b2-limit.from b/seed/profile/mutants/b2-limit.from new file mode 100644 index 000000000..065356ba5 --- /dev/null +++ b/seed/profile/mutants/b2-limit.from @@ -0,0 +1 @@ +if or eq lim 0 gt lim 64 diff --git a/seed/profile/mutants/b2-limit.to b/seed/profile/mutants/b2-limit.to new file mode 100644 index 000000000..3f461126f --- /dev/null +++ b/seed/profile/mutants/b2-limit.to @@ -0,0 +1 @@ +if eq lim 0 diff --git a/seed/profile/mutants/b2-noeq.from b/seed/profile/mutants/b2-noeq.from new file mode 100644 index 000000000..acca4eda5 --- /dev/null +++ b/seed/profile/mutants/b2-noeq.from @@ -0,0 +1 @@ +bare = ulong 1 diff --git a/seed/profile/mutants/b2-noeq.to b/seed/profile/mutants/b2-noeq.to new file mode 100644 index 000000000..5e66ee50c --- /dev/null +++ b/seed/profile/mutants/b2-noeq.to @@ -0,0 +1 @@ +bare = ulong 0 diff --git a/seed/profile/mutants/b3-total.from b/seed/profile/mutants/b3-total.from new file mode 100644 index 000000000..e0ff39066 --- /dev/null +++ b/seed/profile/mutants/b3-total.from @@ -0,0 +1,2 @@ +if gt get st 5 65536 +refuse 2 l diff --git a/seed/profile/mutants/b3-total.to b/seed/profile/mutants/b3-total.to new file mode 100644 index 000000000..b725dc703 --- /dev/null +++ b/seed/profile/mutants/b3-total.to @@ -0,0 +1,2 @@ +if gt get st 5 1048576 +refuse 2 l diff --git a/seed/profile/mutants/c1-mode.from b/seed/profile/mutants/c1-mode.from new file mode 100644 index 000000000..4cd3a886b --- /dev/null +++ b/seed/profile/mutants/c1-mode.from @@ -0,0 +1,2 @@ +if ne get st 6 1 +refuse 6 l diff --git a/seed/profile/mutants/c1-mode.to b/seed/profile/mutants/c1-mode.to new file mode 100644 index 000000000..43b2e0d0d --- /dev/null +++ b/seed/profile/mutants/c1-mode.to @@ -0,0 +1,2 @@ +if eq get st 6 9 +refuse 6 l diff --git a/seed/profile/mutants/e1-used.from b/seed/profile/mutants/e1-used.from new file mode 100644 index 000000000..e90460179 --- /dev/null +++ b/seed/profile/mutants/e1-used.from @@ -0,0 +1,2 @@ +if not used l at l 0 +refuse 3 l diff --git a/seed/profile/mutants/e1-used.to b/seed/profile/mutants/e1-used.to new file mode 100644 index 000000000..be8f58545 --- /dev/null +++ b/seed/profile/mutants/e1-used.to @@ -0,0 +1,2 @@ +if false +refuse 3 l diff --git a/seed/profile/mutants/p1-put.from b/seed/profile/mutants/p1-put.from new file mode 100644 index 000000000..f432e27de --- /dev/null +++ b/seed/profile/mutants/p1-put.from @@ -0,0 +1,2 @@ +if is l 0 16 +note Pure functions \ No newline at end of file diff --git a/seed/profile/mutants/p1-put.to b/seed/profile/mutants/p1-put.to new file mode 100644 index 000000000..24b255347 --- /dev/null +++ b/seed/profile/mutants/p1-put.to @@ -0,0 +1,2 @@ +if false +note Pure functions \ No newline at end of file diff --git a/seed/profile/mutants/x1-effect.from b/seed/profile/mutants/x1-effect.from new file mode 100644 index 000000000..245326210 --- /dev/null +++ b/seed/profile/mutants/x1-effect.from @@ -0,0 +1,2 @@ +if ne get fx f 1 +refuse 4 l diff --git a/seed/profile/mutants/x1-effect.to b/seed/profile/mutants/x1-effect.to new file mode 100644 index 000000000..23d84b724 --- /dev/null +++ b/seed/profile/mutants/x1-effect.to @@ -0,0 +1,2 @@ +if eq get fx f 9 +refuse 4 l diff --git a/seed/profile/profile.cases b/seed/profile/profile.cases new file mode 100644 index 000000000..89ab2805f --- /dev/null +++ b/seed/profile/profile.cases @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: AGPL-3.0-only +# seed/profile/profile.cases: DRA-419 critical-profile gate. Run from the repository root by +# seed/qualification/om2/gate.om (seed/profile/check.om). Each row compiles seed/profile/profile.om with +# the pinned omc and runs it on the named sources. Rule fixtures: seed/profile/cases/-*.om. +# Expected: OM2GATE PASS cases=53 pass=53 fail=0 invalid=0 not_run=0 +deadline 30 +# ---- profiled modules: seed/authority action+store+lock+dispatch (full), omc recursion fixture (bounds) +unit-authority run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/authority/action.om seed/authority/store.om seed/authority/lock.om seed/authority/dispatch.om +unit-authority-bounds run seed/profile/profile.om - line:PROFILE-PASS - 0 bounds seed/authority/action.om seed/authority/store.om seed/authority/lock.om seed/authority/dispatch.om +nest-bounds run seed/profile/profile.om - line:PROFILE-PASS - 0 bounds seed/omc/tests/recursion/nest.om +ok-unit run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-unit.om +ok-b2-nested run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-b2-nested.om +ok-noeq run seed/profile/profile.om - line:PROFILE-PASS - 0 seed/profile/cases/ok-noeq.om +ok-unit-stdin run seed/profile/profile.om file:seed/profile/cases/ok-unit.om line:PROFILE-PASS - 0 +# ---- one refusal per enforced rule (fixtures compile with the pinned omc; the profile is stricter) +b1-while run seed/profile/profile.om - line:PROFILE-REFUSED:B1:4 - 1 seed/profile/cases/b1-while.om +b1-cap run seed/profile/profile.om - line:PROFILE-REFUSED:B1:4 - 1 seed/profile/cases/b1-cap.om +b1-var run seed/profile/profile.om - line:PROFILE-REFUSED:B1:4 - 1 seed/profile/cases/b1-var.om +b2-noguard run seed/profile/profile.om - line:PROFILE-REFUSED:B2:4 - 1 seed/profile/cases/b2-noguard.om +b2-limit run seed/profile/profile.om - line:PROFILE-REFUSED:B2:7 - 1 seed/profile/cases/b2-limit.om +b2-nodepth run seed/profile/profile.om - line:PROFILE-REFUSED:B2:2 - 1 seed/profile/cases/b2-nodepth.om +b2-entry run seed/profile/profile.om - line:PROFILE-REFUSED:B2:11 - 1 seed/profile/cases/b2-entry.om +b2-mutual run seed/profile/profile.om - line:PROFILE-REFUSED:B2:2 - 1 seed/profile/cases/b2-mutual.om +b2-reset run seed/profile/profile.om - line:PROFILE-REFUSED:B2:8 - 1 seed/profile/cases/b2-reset.om +b2-else run seed/profile/profile.om - line:PROFILE-REFUSED:B2:7 - 1 seed/profile/cases/b2-else.om +b2-arm run seed/profile/profile.om - line:PROFILE-REFUSED:B2:9 - 1 seed/profile/cases/b2-arm.om +b2-sibling run seed/profile/profile.om - line:PROFILE-REFUSED:B2:10 - 1 seed/profile/cases/b2-sibling.om +b2-noeq-nd run seed/profile/profile.om - line:PROFILE-REFUSED:B2:7 - 1 seed/profile/cases/b2-noeq-nd.om +b2-noeq-depth run seed/profile/profile.om - line:PROFILE-REFUSED:B2:2 - 1 seed/profile/cases/b2-noeq-depth.om +b3-global run seed/profile/profile.om - line:PROFILE-REFUSED:B3:2 - 1 seed/profile/cases/b3-global.om +b3-total run seed/profile/profile.om - line:PROFILE-REFUSED:B3:4 - 1 seed/profile/cases/b3-total.om +b3-new run seed/profile/profile.om - line:PROFILE-REFUSED:B3:3 - 1 seed/profile/cases/b3-new.om +b3-noeq run seed/profile/profile.om - line:PROFILE-REFUSED:B3:3 - 1 seed/profile/cases/b3-noeq.om +e1-drop run seed/profile/profile.om - line:PROFILE-REFUSED:E1:9 - 1 seed/profile/cases/e1-drop.om +e1-overwrite run seed/profile/profile.om - line:PROFILE-REFUSED:E1:6 - 1 seed/profile/cases/e1-overwrite.om +e1-else run seed/profile/profile.om - line:PROFILE-REFUSED:E1:8 - 1 seed/profile/cases/e1-else.om +e1-noeq run seed/profile/profile.om - line:PROFILE-REFUSED:E1:6 - 1 seed/profile/cases/e1-noeq.om +x1-boundary run seed/profile/profile.om - line:PROFILE-REFUSED:X1:3 - 1 seed/profile/cases/x1-boundary.om +p1-put run seed/profile/profile.om - line:PROFILE-REFUSED:P1:5 - 1 seed/profile/cases/p1-put.om +p1-call run seed/profile/profile.om - line:PROFILE-REFUSED:P1:8 - 1 seed/profile/cases/p1-call.om +c1-mode run seed/profile/profile.om - line:PROFILE-REFUSED:C1:3 - 1 seed/profile/cases/c1-mode.om +c1-release run seed/profile/profile.om - line:PROFILE-REFUSED:C1:2 - 1 seed/profile/cases/c1-release.om +# ---- pre-fix controls on the real modules: dropped release error (E1), unbounded lock retry (B1) +e1-dispatch-prefix run seed/profile/profile.om - line:PROFILE-REFUSED:E1:58 - 1 seed/profile/cases/dispatch-prefix.om seed/authority/action.om seed/authority/store.om seed/authority/lock.om +b1-lock-unbounded run seed/profile/profile.om - line:PROFILE-REFUSED:B1:111 - 1 seed/profile/cases/lock-unbounded.om seed/authority/action.om seed/authority/store.om seed/authority/dispatch.om +# ---- bounds mode skips E1/X1 only +bounds-skips-x1 run seed/profile/profile.om - line:PROFILE-PASS - 0 bounds seed/profile/cases/x1-boundary.om +bounds-skips-e1 run seed/profile/profile.om - line:PROFILE-PASS - 0 bounds seed/profile/cases/e1-drop.om +bounds-keeps-b2 run seed/profile/profile.om - line:PROFILE-REFUSED:B2:4 - 1 bounds seed/profile/cases/b2-noguard.om +bounds-keeps-c1 run seed/profile/profile.om - line:PROFILE-REFUSED:C1:2 - 1 bounds seed/profile/cases/c1-release.om +# ---- bounded memory and stop: every capacity fails closed, hostile bytes terminate +cap-functions run seed/profile/profile.om - line:PROFILE-INVALID - 3 seed/profile/cases/many-fns.om +# min.om (100 bytes, 4 lines) plus stdin as a second source: limits are 65535 bytes, 4095 lines, 63-byte tokens +cap-source-max run seed/profile/profile.om rep:32:65434 line:PROFILE-PASS - 0 seed/profile/cases/min.om /dev/stdin +cap-source-over run seed/profile/profile.om rep:32:65435 line:PROFILE-INVALID - 3 seed/profile/cases/min.om /dev/stdin +cap-source-huge run seed/profile/profile.om rep:10:70000 line:PROFILE-INVALID - 3 +cap-lines-max run seed/profile/profile.om rep:10:4091 line:PROFILE-PASS - 0 seed/profile/cases/min.om /dev/stdin +cap-lines-over run seed/profile/profile.om rep:10:4092 line:PROFILE-INVALID - 3 seed/profile/cases/min.om /dev/stdin +cap-token-max run seed/profile/profile.om rep:97:63 line:PROFILE-PASS - 0 seed/profile/cases/min.om /dev/stdin +cap-token-over run seed/profile/profile.om rep:97:64 line:PROFILE-INVALID - 3 seed/profile/cases/min.om /dev/stdin +empty run seed/profile/profile.om - line:PROFILE-INVALID - 3 +stop-random run seed/profile/profile.om rnd:7:60000 line:PROFILE-INVALID - 3 +stop-seq run seed/profile/profile.om seq:60000 line:PROFILE-INVALID - 3 +usage-args run seed/profile/profile.om - - any 2 x x x x x x x x x x x x x x x x x +missing-file run seed/profile/profile.om - - - 4 seed/profile/cases/absent.om diff --git a/seed/profile/profile.om b/seed/profile/profile.om new file mode 100644 index 000000000..6e98449a0 --- /dev/null +++ b/seed/profile/profile.om @@ -0,0 +1,950 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note Critical source profile. Compile the checked unit too; this is not a parser/typechecker. +note Full-byte token identity, finite pools, fail-closed capacity checks. See README. +global src uchar 65536 +global off ulong 16384 +global siz ulong 16384 +global ls ulong 4096 +global lc ulong 4096 +global lf ulong 4096 +global dep ulong 4096 +global fs ulong 128 +global fe ulong 128 +global nm ulong 128 +global fx uchar 128 +global mem ulong 128 +global edges uchar 16384 +global weak uchar 16384 +global reach uchar 16384 +global alive uchar 128 +global ko ulong 64 +global kl ulong 64 +global st ulong 8 +global host ulong 128 +global hb uchar 16384 +global arg uchar 4096 +global ob uchar 24 +text keys "note fn end if else while for bound new global text const to ret exit trap put requires ensures invariant om2 release = len ulong uint ushort uchar long int short byte view edit own add gt depth p10 effect allow E1 pure main" +text hp "seed/effects/effects.om" +text tpre "text tab " +text pass "PROFILE-PASS\n" +text bad "PROFILE-REFUSED:" +text rules "B1B2B3E1X1P1C1" +text lpre ":" +text inv "PROFILE-INVALID\n" +text use "profile [bounds] [SOURCE ...] < unit.om\n" +text bmode "bounds" +fn stop code int to void +if ne write 1 inv 0 len inv long len inv +exit 4 +end +exit code +end +note Rules: 0 B1 loop bound, 1 B2 recursion, 2 B3 allocation, 3 E1 checked result, 4 X1 effect boundary, 5 P1 pure, 6 C1 contract mode. +fn refuse rule ulong l ulong to void +if ne write 1 bad 0 len bad long len bad +exit 4 +end +if ne write 1 rules mul rule 2 2 2 +exit 4 +end +if ne write 1 lpre 0 len lpre long len lpre +exit 4 +end +put ob 23 10 +v = add l 1 +i = ulong 23 +for j ulong 20 bound 20 +i = sub i 1 +put ob i uchar add 48 rem v 10 +v = div v 10 +if eq v 0 +break +end +end +if ne write 1 ob i sub 24 i long sub 24 i +exit 4 +end +exit 1 +end +fn init to void +s = ulong 0 +k = ulong 0 +for i ulong len keys +if eq get keys i 32 +put ko k s +put kl k sub i s +k = add k 1 +s = add i 1 +end +end +put ko k s +put kl k sub len keys s +end +fn keyis t ulong k ulong to bool +if eq t 0 +ret false +end +if ne get siz t get kl k +ret false +end +o = get ko k +for j ulong get siz t bound 63 +x = get src add get off t j +if ne x get keys add o j +ret false +end +end +ret true +end +fn word t ulong to ulong +if or eq t 0 gt get siz t 8 +ret 0 +end +v = ulong 0 +for j ulong get siz t bound 8 +c = ulong get src add get off t j +v = or v shl c mul j 8 +end +ret v +end +fn at l ulong p ulong to ulong +if ge p get lc l +ret 0 +end +ret add get ls l p +end +fn is l ulong p ulong k ulong to bool +ret keyis at l p k +end +fn same a ulong b ulong to bool +if or eq a 0 eq b 0 +ret false +end +if ne get siz a get siz b +ret false +end +for j ulong get siz a bound 63 +x = get src add get off a j +y = get src add get off b j +if ne x y +ret false +end +end +ret true +end +fn number t ulong to ulong +if eq t 0 +ret 1048577 +end +v = ulong 0 +for j ulong get siz t bound 63 +c = get src add get off t j +if or lt c 48 gt c 57 +ret 1048577 +end +if gt v 1048576 +ret 1048577 +end +v = add mul v 10 sub ulong c 48 +end +ret v +end +fn value t ulong to ulong +v = number t +if le v 1048576 +ret v +end +for l ulong get st 1 bound 4096 +if is l 0 11 +if same t at l 1 +ret number at l 3 +end +end +end +ret 1048577 +end +fn func t ulong to ulong +for f ulong get st 2 bound 128 +if same t get nm f +ret f +end +end +ret 128 +end +fn token a ulong n ulong to void +if eq n 0 +ret +end +if gt n 63 +stop 3 +end +t = add get st 0 1 +if ge t 16384 +stop 3 +end +put off t a +put siz t n +put st 0 t +l = get st 1 +if eq get lc l 0 +put ls l t +end +put lc l add get lc l 1 +end +fn blank c ulong to bool +if or eq c 32 eq c 9 +ret true +end +if or eq c 13 eq c 40 +ret true +end +ret eq c 41 +end +fn tabpre i ulong to bool +for k ulong len tpre +if ne get hb add sub i len tpre k get tpre k +ret false +end +end +ret true +end +fn lex n ulong to void +a = ulong 0 +size = ulong 0 +quote = false +esc = false +skip = false +for i ulong n bound 65536 +c = get src i +if eq c 10 +token a size +size = ulong 0 +quote = false +esc = false +skip = false +l = add get st 1 1 +if ge l 4096 +stop 3 +end +put st 1 l +continue +end +if skip +continue +end +if quote +if esc +esc = false +else +if eq c 92 +esc = true +else +if eq c 34 +quote = false +end +end +end +continue +end +if eq c 34 +token a size +size = ulong 0 +quote = true +continue +end +if blank ulong c +token a size +size = ulong 0 +note Preserve only p10 annotations; ordinary comments need no bounded token storage. +l = get st 1 +if ge get lc l 2 +if and is l 0 0 not is l 1 38 +skip = true +end +end +continue +end +if eq size 0 +a = i +end +size = add size 1 +end +token a size +put st 1 add get st 1 1 +end +fn hosts to void +fd = fopen hp 0 len hp 0 0 +if lt fd 0 +stop 3 +end +n = read int fd hb 0 len hb +if ne fclose int fd 0 +stop 3 +end +if le n 0 +stop 3 +end +note Find the exact authoritative effects table prefix, then decode only its first column. +a = ulong 0 +found = false +for i ulong ulong n bound 16384 +c = get hb i +if ge i len tpre +if and eq c 34 tabpre i +a = add i 1 +found = true +break +end +end +end +if not found +stop 3 +end +hdecode a ulong n +end +note cnt 9 marks a row whose first column was already stored. +fn hdecode a ulong n ulong to void +w = ulong 0 +cnt = ulong 0 +for j ulong sub n a bound 16384 +c = get hb add a j +if eq c 34 +if eq get st 3 0 +stop 3 +end +ret +end +if eq c 110 +if eq get hb sub add a j 1 92 +w = ulong 0 +cnt = ulong 0 +continue +end +end +if lt cnt 9 +if eq c 32 +k = get st 3 +if ge k 128 +stop 3 +end +put host k w +put st 3 add k 1 +cnt = ulong 9 +else +if ge cnt 8 +stop 3 +end +w = or w shl ulong c mul cnt 8 +cnt = add cnt 1 +end +end +end +stop 3 +end +fn ishost t ulong to bool +w = word t +for i ulong get st 3 bound 128 +if eq w get host i +ret true +end +end +ret false +end +fn declarations to void +f = ulong 128 +d = ulong 0 +for l ulong get st 1 bound 4096 +if is l 0 1 +if ne d 0 +stop 3 +end +f = get st 2 +if ge f 128 +stop 3 +end +put fs f l +put nm f at l 1 +put st 2 add f 1 +if gt l 0 +p = sub l 1 +if and is p 0 0 and is p 1 38 is p 2 39 +put fx f 1 +end +if and is p 0 0 and is p 1 38 is p 2 42 +put fx f 2 +end +end +d = ulong 1 +else +if is l 0 2 +if eq d 0 +stop 3 +end +d = sub d 1 +if eq d 0 +put fe f l +end +end +end +put lf l f +put dep l d +if or is l 0 3 or is l 0 5 is l 0 6 +d = add d 1 +end +end +if or ne d 0 eq get st 2 0 +stop 3 +end +end +note Shared assignment classifier for B2, B3 and E1: the index of the value's first token when line l +note assigns, else 0. omc s_name accepts NAME [=] value: a leading name that is not a statement +note keyword (indexes 0..21), a unit function or a host word assigns even without =. omc refuses a +note parameter, global or local that shadows a function or host word (errors 10 and 16). +fn asg l ulong to ulong +if lt get lc l 2 +ret 0 +end +if is l 1 22 +ret 2 +end +for k ulong 22 +if is l 0 k +ret 0 +end +end +t = at l 0 +if or lt func t 128 ishost t +ret 0 +end +bare = ulong 1 +ret bare +end +fn exempt l ulong to bool +if eq l 0 +ret false +end +p = sub l 1 +ret and gt get lc p 4 and is p 0 0 and is p 1 38 and is p 2 40 is p 3 41 +end +fn mentions k ulong name ulong to bool +start = asg k +for p ulong sub get lc k start bound 16384 +t = at k add p start +if same name t +ret true +end +end +ret false +end +note Walk the straight-line continuation: leave blocks outward, skip the sibling else branch. +fn used l ulong name ulong to bool +d = get dep l +e = get fe get lf l +sk = ulong 0 +for j ulong sub e l bound 4096 +k = add add l j 1 +dk = get dep k +if lt dk d +d = dk +end +if ne sk 0 +if ge dk sk +continue +end +sk = ulong 0 +end +if is k 0 0 +continue +end +if and eq dk d is k 0 4 +sk = d +continue +end +if mentions k name +ret true +end +if eq dk d +if and ne asg k 0 same name at k 0 +ret false +end +if or is k 0 13 or is k 0 14 is k 0 15 +ret false +end +end +end +ret false +end +note Size of t if line r declares it (global, text or same-function new); 0 if it does not. +fn dsize r ulong t ulong fl ulong to ulong +if and is r 0 9 same at r 1 t +ret value at r 3 +end +if and is r 0 10 same at r 1 t +note Source span conservatively includes the declaration words, quotes and escapes. +q = add r 1 +if lt q get st 1 +if gt get ls q 0 +ret sub get off get ls q get off at r 0 +end +end +ret 1048577 +end +if ne get lf r fl +ret 0 +end +v = asg r +if and ne v 0 and is r v 8 same at r 0 t +ret value at r add v 2 +end +ret 0 +end +fn length l ulong t ulong to ulong +fl = get lf l +for r ulong l bound 4096 +v = dsize r t fl +if ne v 0 +ret v +end +end +if ge fl 128 +ret 1048577 +end +r = get fs fl +for p ulong get lc r bound 16384 +if same at r p t +q = add p 1 +if or is r q 32 or is r q 33 is r q 34 +ret value at r add p 3 +end +end +end +ret 1048577 +end +fn checkloop l ulong to void +v = ulong 1048577 +if is l 0 6 +v = value at l 3 +if is l 3 23 +v = length l at l 4 +end +end +for p ulong get lc l bound 16384 +if is l p 7 +v = value at l add p 1 +end +end +if gt v 8192 +refuse 0 l +end +end +fn width l ulong t ulong to ulong +if or keyis t 24 keyis t 28 +ret 8 +end +if or keyis t 25 keyis t 29 +ret 4 +end +if or keyis t 26 keyis t 30 +ret 2 +end +if or keyis t 27 keyis t 31 +ret 1 +end +refuse 2 l +ret 0 +end +fn salloc l ulong f ulong to void +if is l 0 9 +v = value at l 3 +if gt v 65536 +refuse 2 l +end +b = mul v width l at l 2 +put st 5 add get st 5 b +if gt get st 5 65536 +refuse 2 l +end +end +if or ge f 128 is l 0 1 +ret +end +a = asg l +if and ne a 0 is l a 8 +v = value at l add a 2 +if gt v 65536 +refuse 2 l +end +b = mul v width l at l add a 1 +put mem f add get mem f b +put st 7 add get st 7 b +if gt get st 7 65536 +refuse 2 l +end +if gt get mem f 65536 +refuse 2 l +end +end +end +fn scalls l ulong f ulong to bool +call = false +for p ulong get lc l bound 16384 +t = at l p +g = func t +if lt g 128 +a = add mul f 128 g +put edges a 1 +put reach a 1 +call = true +end +if ishost t +call = true +if eq get st 4 0 +if ne get fx f 1 +refuse 4 l +end +end +end +end +ret call +end +fn scan to void +for l ulong get st 1 bound 4096 +if eq get lc l 0 +continue +end +if is l 0 0 +continue +end +if is l 0 20 +if or is l 1 21 is l 2 21 +refuse 6 l +end +put st 6 1 +continue +end +if or is l 0 5 is l 0 6 +checkloop l +end +f = get lf l +salloc l f +if or ge f 128 is l 0 1 +continue +end +call = scalls l f +if and eq get st 4 0 and ne asg l 0 call +if not exempt l +if not used l at l 0 +refuse 3 l +end +end +end +if eq get fx f 2 +if is l 0 16 +note Pure functions may inspect arrays but cannot write even borrowed state. +refuse 5 l +end +end +if or is l 0 17 or is l 0 18 is l 0 19 +if ne get st 6 1 +refuse 6 l +end +end +end +end +fn crow i ulong k ulong n ulong to void +a = mul i 128 +b = mul k 128 +for j ulong n bound 128 +if ne get reach add b j 0 +put reach add a j 1 +end +end +end +fn closure to void +n = get st 2 +for k ulong n bound 128 +for i ulong n bound 128 +if ne get reach add mul i 128 k 0 +crow i k n +end +end +end +end +fn stops q ulong to bool +ret or is q 0 13 or is q 0 14 is q 0 15 +end +note No mutation of the checked depth between guard and recursive call. +fn unchanged s ulong e ulong argt ulong to bool +for h ulong sub e s bound 4096 +r = add s h +if ne asg r 0 +if same at r 0 argt +ret false +end +end +end +ret true +end +note Line p must be NAME = add depth 1, then if gt NAME LIM (LIM <= 64), an optional call statement, +note a stop, end: the stop is the last statement of the guard's then-block (no else, no nested block). +fn guarded p ulong l ulong argt ulong name ulong to bool +if not is p 2 35 +ret false +end +if not same at p 3 name +ret false +end +if ne number at p 4 1 +ret false +end +q = add p 1 +if not and is q 0 3 is q 1 36 +ret false +end +if not same at q 2 argt +ret false +end +lim = value at q 3 +if or eq lim 0 gt lim 64 +ret false +end +q = add q 1 +note Permit the existing nest.om stop-code call before the return; only a call to a unit function, +note never else or another structural line, so the stop belongs to the guard's then-block. +if not stops q +if ge func at q 0 128 +ret false +end +q = add q 1 +end +if not stops q +ret false +end +q = add q 1 +if not is q 0 2 +ret false +end +if ge q l +ret false +end +ret unchanged add q 1 l argt +end +note Lines p and l share one block instance: no line between them leaves the block (depth below dl) +note or starts its sibling else arm (else at depth dl). Equal depth alone is not enough. +fn sameblk p ulong l ulong dl ulong to bool +for h ulong sub l add p 1 bound 4096 +r = add add p 1 h +if lt get dep r dl +ret false +end +if and eq get dep r dl is r 0 4 +ret false +end +end +ret true +end +note A qualifying increasing edge has a canonical dominating guard in the same block instance. +fn increasing l ulong t ulong f ulong to bool +name = at get fs f 2 +argt = add t 1 +dl = get dep l +for p ulong l bound 4096 +if ne get lf p f +continue +end +if ne get dep p dl +continue +end +if eq asg p 0 +continue +end +if same at p 0 argt +if not sameblk p l dl +continue +end +ret guarded p l argt name +end +end +ret false +end +note Classify one call t to g on line r of f; keep all but guarded increasing in-SCC edges. +fn redge r ulong t ulong f ulong g ulong cyclic bool to void +a = add mul f 128 g +gg = mul g 128 +if eq get reach add gg g 0 +put weak a 1 +ret +end +inscc = and cyclic ne get reach add gg f 0 +if not inscc +put weak a 1 +if gt value add t 1 64 +refuse 1 r +end +ret +end +if same add t 1 at get fs f 2 +put weak a 1 +ret +end +if not increasing r t f +refuse 1 r +end +end +fn rline r ulong f ulong cyclic bool to void +for p ulong get lc r bound 16384 +t = at r p +g = func t +if lt g 128 +redge r t f g cyclic +end +end +end +fn isleaf i ulong n ulong to bool +b = mul i 128 +for j ulong n bound 128 +if ne get weak add b j 0 +if ne get alive j 0 +ret false +end +end +end +ret true +end +fn prune n ulong to void +for i ulong n bound 128 +put alive i 1 +end +for round ulong n bound 128 +for i ulong n bound 128 +if isleaf i n +put alive i 0 +end +end +end +end +fn recursion to void +n = get st 2 +for f ulong n bound 128 +h = get fs f +cyclic = ne get reach add mul f 128 f 0 +if cyclic +if ne get mem f 0 +refuse 1 h +end +if not is h 2 37 +refuse 1 h +end +end +for l ulong sub get fe f h bound 4096 +r = add add h l 1 +if is r 0 0 +continue +end +if and cyclic and ne asg r 0 same at r 0 at h 2 +refuse 1 r +end +rline r f cyclic +end +end +note DRA-311/omc leaf-removal analysis, applied after removing guarded increasing edges. +prune n +for i ulong n bound 128 +if ne get alive i 0 +refuse 1 get fs i +end +if eq get fx i 2 +for j ulong n bound 128 +if and ne get edges add mul i 128 j 0 ne get fx j 2 +refuse 5 get fs i +end +end +end +end +end +fn slurp fd int n ulong to ulong +total = n +while true bound 65536 +r = read fd src total sub len src total +if lt r 0 +exit 4 +end +if eq r 0 +ret total +end +total = add total ulong r +if ge total len src +stop 3 +end +end +stop 3 +ret 0 +end +fn main to int +init +ac = ulong argcnt +if gt ac 16 +if ne write 2 use 0 len use long len use +ret 4 +end +ret 2 +end +first = ulong 1 +if gt ac 1 +m = argread 1 arg 0 len arg +mode = eq m long len bmode +if mode +for i ulong len bmode +if ne get arg i get bmode i +mode = false +end +end +end +if mode +put st 4 1 +first = ulong 2 +end +end +n = ulong 0 +if eq ac first +n = slurp 0 0 +else +for j ulong sub ac first bound 16 +m = argread add first j arg 0 len arg +if or le m 0 ge m long len arg +ret 2 +end +fd = fopen arg 0 ulong m 0 0 +if lt fd 0 +ret 4 +end +n = slurp int fd n +if ne fclose int fd 0 +ret 4 +end +if gt n 0 +if ne get src sub n 1 10 +put src n 10 +n = add n 1 +if ge n len src +stop 3 +end +end +end +end +end +if eq n 0 +stop 3 +end +lex n +hosts +declarations +scan +closure +recursion +if ne write 1 pass 0 len pass long len pass +ret 4 +end +ret 0 +end ```