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/aien-protocols-mv/patches/0168307c30889000 # aien-protocols-mv Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## [OSH][P0] Native stream and task acceptance vectors for pipeline execution (draft rev 2) merged `0168307c30889000` #46 · opened 2026-10-19 02:04 UTC · closed 2026-10-19 02:15 UTC · merged 2026-10-19 02:15 UTC Imported from GitHub aien-dev/aien-protocols-mv#46, by drakestapleton Labels: ready-to-merge Base `dc1b891cb9eda2c5fd4bfc7280c4edc273acf236` · Head `a6704d5b46a15ea078cb07d6ee5411aabc5df5e9` Merged on GitHub as `f0a602d4c4d756c94da7ddf13db2bdff4d9e5fe6`; reachable from main `a2a4bb5828b85d7d41cd0055155161b0898e24a4` (observed 2026-11-18T16:39:41Z) drakestapleton wrote on 2026-10-19 02:04 UTC Closes aien-dev/aien-protocols-mv#43 This freezes nothing. It makes the OSH byte pipe and task rules precise (draft revision 2) and ships shared test cases that both Omega on Linux and native AIENOS can run. What is in it - `specs/osh-platform/STREAM_TASK.md`: the rules for byte pipes and running programs. - `specs/osh-platform/AUDIT_STREAM_TASK.md`: line by line comparison with the two implementations (omega-mv main `a8ffd2b9`, aienos-mv PR 433 at `f8700d4c`). - 37 shared vectors (21 stream, 16 task), a checker, and a small C reference model that passes all 37. - 22 deliberately broken copies of the model; each is caught by at least one vector. - Pointers and the STREAM_DUP capability form in OSH_PLATFORM_ABI.md, vectors README, CHANGELOG. Verified (host only) - check-stream-vectors.sh: 37 of 37 pass, also under ASan and UBSan; 22 of 22 mutants killed. - tests/gates/run.sh c-vectors and anti-slop pass; cargo test --workspace passes (Rust untouched). - Rebased onto the crumb-migrated main; `crumb verify` OK. Not verified - Nothing ran on Omega, AIENOS, QEMU or hardware. This only checks the test cases themselves. Full handoff: Spark ~/handoffs/2026-10-18-protocols-43.md github-advanced-security[bot] commented on `specs/osh-platform/tools/osh_sv_ref.c` line 208 on 2026-10-19 02:05 UTC ## CodeQL / Unbounded write This 'call to strcpy' with input from string read by fgets may overflow the destination. Show more details github-advanced-security[bot] commented on `specs/osh-platform/tools/osh_sv_ref.c` line 823 on 2026-10-19 02:05 UTC ## CodeQL / Unbounded write This 'call to strcpy' with input from string read by fgets may overflow the destination. Show more details github-advanced-security[bot] commented on `specs/osh-platform/tools/osh_sv_ref.c` line 867 on 2026-10-19 02:05 UTC ## CodeQL / Potentially overflowing call to snprintf The size argument of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow. Show more details github-advanced-security[bot] reviewed (COMMENTED) on 2026-10-19 02:05 UTC github-advanced-security[bot] commented on `specs/osh-platform/tools/osh_sv_ref.c` line 869 on 2026-10-19 02:05 UTC ## CodeQL / Potentially overflowing call to snprintf The size argument of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow. Show more details github-advanced-security[bot] commented on `specs/osh-platform/tools/osh_sv_ref.c` line 871 on 2026-10-19 02:05 UTC ## CodeQL / Potentially overflowing call to snprintf The size argument of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow. Show more details github-advanced-security[bot] commented on `specs/osh-platform/tools/osh_sv_ref.c` line 884 on 2026-10-19 02:05 UTC ## CodeQL / Unbounded write This 'call to strcpy' with input from string read by fgets may overflow the destination. Show more details ### Apply it ``` git checkout -b patch-0168307c30889000 dc1b891cb9eda2c5fd4bfc7280c4edc273acf236 curl -fsSL https://interplane.io/drakestapleton/aien-protocols-mv/patches/0168307c30889000.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/aien-protocols-mv 46 a6704d5b46a15ea078cb07d6ee5411aabc5df5e9 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aien-protocols-mv","number":46,"url":"https://github.com/aien-dev/aien-protocols-mv/pull/46","export_sha256":"5e1c9b95fcaff04d8c4582debbd865230bbda8bc3ae215218d21a2cff1ad108b","imported_utc":"2026-11-18T16:39:41Z"} ``` ### Changes ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index a9de8f6..593c430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,20 @@ VERSIONING.md. ### Specifications +- `specs/osh-platform`: OSH Platform ABI v1 DRAFT revision 2, still not + frozen and still `abi_version` 1 (aien-protocols-mv#43). New + `STREAM_TASK.md` makes streams and tasks precise: platform call frame and + draft op ids, handle check order, byte-stream semantics, capability domain + check order, task binding, cancellation, launch and partial launch, + `OUTCOME_UNKNOWN`, receipt pins, and nine open freeze items. + Incompatible draft change: `STREAM_DUP(src_stream, dst_fd)` is replaced by + the capability form `STREAM_DUP(src_stream, rights, target)`. + `AUDIT_STREAM_TASK.md` compares the draft with Omega's Linux host adapter + and the AIENOS native pipe. Adds 37 shared stream and task vectors + (`vectors/s*.vec`, `vectors/t*.vec`), the C reference model + `tools/osh_sv_ref.c`, `tools/check-stream-vectors.sh` and + `tools/mutate-stream-ref.sh` (22 checks, 22 mutants killed). The 20 + shell-core vectors are unchanged. - `crates/aien-pi-spark-task` (C4, aien-protocols-mv#31): Rust reader and writer for the PST1 fixed header, no `unsafe`, no JSON, fixed bounds. Its test walks `specs/pi-spark-task/vectors/expected.txt` and requires the same diff --git a/specs/osh-platform/AUDIT_STREAM_TASK.md b/specs/osh-platform/AUDIT_STREAM_TASK.md new file mode 100644 index 0000000..debd9f4 --- /dev/null +++ b/specs/osh-platform/AUDIT_STREAM_TASK.md @@ -0,0 +1,54 @@ +# Audit: OSH ABI v1 streams and tasks against the two implementations + +**Status**: informative, part of aien-protocols-mv#43. Not a freeze and not a conformance claim: no adapter has run the stream and task vectors yet, so every "differs" below is read from source, not observed. +**Sources read**: `OSH_PLATFORM_ABI.md` at aien-protocols-mv `fb5fca98e667` (v1 DRAFT); Omega Linux host adapter at omega-mv `a8ffd2b912c84197d08f963b05f9c7d8b30a3f8a` (`src/osh/host/osh_exec.c`, `osh_caps.c`, `osh_host.h`); AIENOS native pipe at aienos-mv `f8700d4cb65e47225a04102cd8a4fa5b8791c6f1` (branch `feat/native-pipe-1`, PR #433: `native/kernel/core/pipe.h`, `pipe.c`, `osh_err.h`, `tests/fixtures/pipe/`), plus the AIENOS handoff that lists its UNVERIFIED choices. +**Result**: [`STREAM_TASK.md`](STREAM_TASK.md) (draft revision 2) settles what the evidence supports; the rest is listed in its section ST11. + +## A1. What each side implements today + +| ABI item | Omega Linux host adapter | AIENOS native (feat/native-pipe-1) | +|---|---|---| +| `PIPE_CREATE` | `pipe2(O_CLOEXEC)` per pipeline link inside `run_pipeline`; not a platform op the core calls | `ck_pipe_create`, op 1 of a versioned frame dispatch | +| `STREAM_READ` / `WRITE` | done by the child processes on raw descriptors; the adapter never reads or writes a pipe itself | `ck_stream_read` / `ck_stream_write`, ops 2 and 3, partial I/O, `BLOCK` flag | +| `STREAM_CLOSE` | `close()` of parent copies right after each fork | `ck_stream_close`, op 4 | +| `STREAM_DUP` | `dup2` in the child for `N>&M`; no platform op | capability form, op 5 (rights plus target table) | +| `TASK_SPAWN` / `WAIT` / `CANCEL` / `STATE` | `fork` + `execve`, `waitpid`; cancel only as `SIGTERM`+`SIGCONT` on partial launch and `SIGKILL` on a stopped member | none (task lifecycle is a separate AIENOS issue) | +| Binding checks | `authorize` (valid, domain 1 or 2, domain-1 narrow, `PERM_CHECK`) then a per-effect hook; hosted authority is domain 2 only | pipe ends are domain-1 kernel capabilities checked by `ck_cap_lookup`; no binding record on pipe ops | +| Intent and outcome records | durable journal, `OUTCOME_UNKNOWN` on recovery, never replayed | RAM-only records in the test-only `osh_op` layer | +| Error numbering (8.6) | `osh_host.h` | `osh_err.h`, same numbers and names | + +Both agree on the section 8.6 numbering and names, on the refusal namespaces staying separate, on never treating an unknown error as `OK`, and on the domain-1 narrowing refusal. + +## A2. The AIENOS UNVERIFIED choices, one by one + +| AIENOS choice | Evidence | Disposition in revision 2 | +|---|---|---| +| Op ids 1 to 5 | only implementation with op ids; Omega has no frames | Settled as draft numbering (ST2). Ids 6 to 15 assigned with no implementation: open ST11.1 | +| Call frame layout (magic, version, op, reserved, args; exact cell count) | matches ABI section 3 header and its check order | Settled (ST2), with the frame refusals mapped onto 8.6 errors: `INVALID_ARG` for length, magic, reserved, arg count; `NOT_SUPPORTED` for version and unknown op | +| `PIPE_CREATE` returning the write end in `value2` | only implementation | Settled (ST2) | +| `STREAM_DUP` in capability form instead of `(src_stream, dst_fd)` | Omega does descriptor duplication privately at spawn; AIENOS needs attenuation and transfer | Settled: capability form (ST4.10). The `dst_fd` form is withdrawn, an incompatible draft change recorded in ST12; confirm at freeze (ST11.3) | +| `PIPE_CREATE` needs no prior capability | ABI gives it no binding; both implementations create pipes unconditionally | Settled (ST3.5), bounded by `LIMIT` | +| Capability resource layout (tag, end bit, 3-bit index, 20-bit epoch) and pool of 4 pipes | private to the kernel | Layout: adapter-private, not ABI (ST2, ST3.3). Pool of 4 is below what ST9 implies: open ST11.4 | +| Error mapping (closed or reused handle `STALE`, missing right or wrong end `DENIED`, revoked `REVOKED`, malformed frame `INVALID_ARG`, other version or unknown op `NOT_SUPPORTED`) | Omega's capability mapping uses the same names for the same causes | Settled, including AIENOS's check order (ST3.2) | +| Pending cancel: an interrupt with nobody waiting interrupts the next call once | AIENOS only; a Linux signal outside a system call is not latched | Settled as the rule (ST4.7); Linux must emulate: open ST11.8 | +| 8-slot capability table, below "3 standard plus 16 open streams" | ABI 8.5 minimum stands | Open ST11.4; the `s018_limits` vector fails on AIENOS until it grows or the minimum changes | + +## A3. Contradictions and gaps found in the draft and in Omega + +1. **Platform frame refusals.** ABI section 3 lists the frame `OSHF` among blobs refused with `ABI_*` codes, but those are shell-core status codes (5.3) and a platform call answers with section 8.6 errors. Revision 2 maps them (ST2). The ABI text now points at ST2. +2. **`STREAM_DUP(src_stream, dst_fd)`** mixes two things: duplicating a capability and choosing a child's descriptor. Neither implementation exposes the second as a platform op. Withdrawn (ST4.10). +3. **Zero-length write with no reader.** AIENOS returns `BROKEN_PIPE`; Linux `write(fd, p, 0)` returns 0. Revision 2 follows AIENOS (ST4.3); open ST11.7. +4. **Partial writes.** AIENOS stores what fits; a Linux non-blocking pipe write of up to 4,096 bytes is all or nothing (`EAGAIN`). Omega does not serve `STREAM_WRITE` itself today, so nothing conflicts yet; open ST11.6 for when it does. +5. **Cleanup order (ABI section 12: interrupt, grace, terminate).** Omega's partial-launch cleanup sends `SIGTERM` and `SIGCONT` and then waits with no deadline; a child that ignores `SIGTERM` would hold the shell. Its stopped-member path uses `SIGKILL`. Revision 2 keeps section 12 and defines terminate as non-ignorable (ST6.5); Omega differs (ST11.5). The `t006_partial_launch` vector expects status 130 for an interrupted `hang`, where Omega's `SIGTERM` would give 143. +6. **Failing command's outcome on a launch failure.** Omega marks it `NOT_STARTED` with the error; section 10 has `FAILED_NO_EFFECT(error)` for exactly this. Revision 2 uses `FAILED_NO_EFFECT` (ST7.6); Omega differs (ST11.5). +7. **Per-command denial is not a partial launch.** Omega refuses a single command whose effect check fails (status 126) and lets the others run, as it does for a name not found (127). The draft did not say this; revision 2 adopts it (ST7.5), so `PARTIAL_LAUNCH` means only a resource failure of the spawn itself (ST7.6). +8. **Raw descriptors as handles.** If a Linux adapter ever exposes stream handles, descriptor reuse would defeat `STALE`. Revision 2 requires an adapter table with incarnations (ST3.4). +9. **Domain check order.** Omega checks narrowing before matching the resource's domain, so a domain-1 binding with a 64-bit generation against a domain-2 resource is `CAP_GEN_NARROW`, not `CAP_DOMAIN_MISMATCH`. Adopted (ST5); vector `t011_domain2_generation` pins it. +10. **`TASK_WAIT` deadline, `TASK_STATE` values, cancel statuses on a native adapter.** Not specified before and not implemented anywhere. Revision 2 defines them (ST6.2 to ST6.4) as UNVERIFIED. + +## A4. Which vectors each implementation can run today (read from source, not run) + +- **AIENOS `feat/native-pipe-1`**: the stream vectors `s001` to `s020` map onto its fixture runner with small changes (`fill W cap`, `skim`, `sweep`, `saturate`, `exhaust`, `limits` are new commands; kernel counters are gone). Expected to differ: `s018_limits` (pool of 4, table of 8). `s021_epoch` needs `reset` and `journal`; every `t*` vector needs tasks: `NOT_RUN` until the task issue lands. +- **Omega Linux host adapter**: has no stream handle API, so `s*` vectors are `NOT_RUN` until it exposes one (or a harness drives its pipes). Task and launch vectors need a harness that provides the conformance programs and a test authority; expected to differ on `t006_partial_launch` (A3.5, A3.6) and on any vector that needs the new `TASK_*` ops. + +These predictions are a reading of the code at the commits above. They become evidence only as receipts in the ST10.3 format. diff --git a/specs/osh-platform/OSH_PLATFORM_ABI.md b/specs/osh-platform/OSH_PLATFORM_ABI.md index 4596342..61671a7 100644 --- a/specs/osh-platform/OSH_PLATFORM_ABI.md +++ b/specs/osh-platform/OSH_PLATFORM_ABI.md @@ -1,10 +1,10 @@ # OSH Platform ABI v1 (Omega-native shell, working name `osh`) -**Status**: v1 DRAFT, not frozen: freezes after OSC-EXT-BYTES lands and the Linux adapter has consumed it once. +**Status**: v1 DRAFT, revision 2, not frozen: freezes after OSC-EXT-BYTES lands and the Linux adapter has consumed it once. Revision 2 (aien-protocols-mv#43) makes streams and tasks precise in [`STREAM_TASK.md`](STREAM_TASK.md), which is part of this ABI; the comparison with the implementations is [`AUDIT_STREAM_TASK.md`](AUDIT_STREAM_TASK.md). **ABI version field**: `1` (nothing is frozen, so any v1 field may still change until the freeze; after it, changes bump the version) **License**: Community Specification License 1.0 **Origin**: `aien-dev/aien-architecture#158`. This file makes the shell-core to platform boundary normative. First implementation: omega `src/osh` (lexer, parser and expander units in OSC with independent C references, and the Linux host `build/osh/osh`; omega#337, #339, #340). Where the implementation and this draft differ, the difference is listed in section 14 until the freeze. -**Conformance vectors**: [`vectors/`](vectors/), [`vectors/expected.txt`](vectors/expected.txt), generated inputs by [`tools/make-vectors.sh`](tools/make-vectors.sh) +**Conformance vectors**: [`vectors/`](vectors/), [`vectors/expected.txt`](vectors/expected.txt), generated inputs by [`tools/make-vectors.sh`](tools/make-vectors.sh); stream and task vectors `vectors/s*.vec` and `vectors/t*.vec`, checked by [`tools/check-stream-vectors.sh`](tools/check-stream-vectors.sh) **Not covered**: shell language semantics beyond what the request record needs (owned by the first-release freeze in `aien-architecture`), the Omega compiler, kernel IPC. ## 1. Model @@ -30,7 +30,7 @@ Every exchanged blob (workspace, request record, platform call frame) begins wit | 0 | `magic` | workspace `0x4F534857` ("OSHW"); request record `0x4F524551` ("OREQ"); platform frame `0x4F534846` ("OSHF") | | 1 (request record: 5) | `abi_version` | `1` | -Check order, first failure wins, each refusal numbered in section 5.3: slice too short for the header (`ABI_LENGTH`), wrong magic (`ABI_MAGIC`), `abi_version` not exactly 1 (`ABI_VERSION`), workspace shorter than 11456 cells (`WORKSPACE_SIZE`), any reserved field nonzero (`ABI_RESERVED`). A reader never guesses at a newer version, never reads past a refusal, and never partially applies a blob. A version bump changes `abi_version`; v1 readers refuse v2 blobs. +Check order, first failure wins, each refusal numbered in section 5.3: slice too short for the header (`ABI_LENGTH`), wrong magic (`ABI_MAGIC`), `abi_version` not exactly 1 (`ABI_VERSION`), workspace shorter than 11456 cells (`WORKSPACE_SIZE`), any reserved field nonzero (`ABI_RESERVED`). A reader never guesses at a newer version, never reads past a refusal, and never partially applies a blob. A version bump changes `abi_version`; v1 readers refuse v2 blobs. A platform frame answers with section 8.6 errors, not these status codes: its layout and the mapping of this check order onto 8.6 are in `STREAM_TASK.md` ST2. ## 4. Ownership and lifetimes @@ -134,7 +134,7 @@ The adapter implements these. Each takes borrowed slices and returns a frame `{e ### 8.1 Streams and buffers -`STREAM_OPEN(location, mode: read | write | append | create_excl)`, `STREAM_READ(stream, out_slice) -> n` (0 means EOF), `STREAM_WRITE(stream, in_slice) -> n` (partial writes allowed; the caller loops), `STREAM_CLOSE(stream)`, `STREAM_DUP(src_stream, dst_fd)`, `PIPE_CREATE() -> (read_stream, write_stream)`. Pipes are bounded and apply backpressure: a writer to a full pipe gets `WOULD_BLOCK` or blocks, never unbounded buffering. A write to a pipe whose reader closed returns `BROKEN_PIPE`. Standard descriptors 0 to 2 are the only fixed numbers. +`STREAM_OPEN(location, mode: read | write | append | create_excl)`, `STREAM_READ(stream, out_slice) -> n` (0 means EOF), `STREAM_WRITE(stream, in_slice) -> n` (partial writes allowed; the caller loops), `STREAM_CLOSE(stream)`, `STREAM_DUP(src_stream, rights, target) -> stream` (revision 2: capability form; the earlier `(src_stream, dst_fd)` form is withdrawn, descriptor duplication is the adapter's own business at `TASK_SPAWN`), `PIPE_CREATE() -> (read_stream, write_stream)`. Exact byte-stream semantics (partial and zero-length operations, end of stream, no reader, backpressure, interrupt, close and wake, revocation, handle checks and epochs) are `STREAM_TASK.md` ST3 and ST4. Pipes are bounded and apply backpressure: a writer to a full pipe gets `WOULD_BLOCK` or blocks, never unbounded buffering. A write to a pipe whose reader closed returns `BROKEN_PIPE`. Standard descriptors 0 to 2 are the only fixed numbers. ### 8.2 Storage locations @@ -146,7 +146,7 @@ A location is `{scheme u8, len u32, bytes}`. Scheme 1 `POSIX_PATH`: raw bytes, n ### 8.4 Execute, wait, cancel -`TASK_SPAWN(resolved, argv_slices, env_slices, stdio{0,1,2}, binding) -> task_id`, `TASK_WAIT(task, deadline) -> status`, `TASK_CANCEL(task, mode: interrupt | terminate)`, `TASK_STATE(task)`. `binding` is the authority record (section 9); spawn without a valid binding returns `DENIED`. On Linux, an interactive session runs each foreground pipeline in its own process group, hands it the terminal, and forwards an interrupt aimed at the shell to that group. A non-interactive session leaves the pipeline in the shell's process group, so a group-wide interrupt reaches the shell and the pipeline together; in that mode the shell does not die of the interrupt while waiting and ends with status 130 if the last command died of SIGINT. SIGINT and SIGQUIT ignored at entry stay ignored in children. R1 has no job control: a stopped pipeline member cancels the whole pipeline (status 128 plus the stop signal). Exit status follows POSIX shell convention (127 not found, 126 found but not executable, 128 plus signal); exact agreement with the pinned reference shell is checked by the differential suite, not asserted here. +`TASK_SPAWN(resolved, argv_slices, env_slices, stdio{0,1,2}, binding) -> task_id`, `TASK_WAIT(task, deadline) -> status`, `TASK_CANCEL(task, mode: interrupt | terminate)`, `TASK_STATE(task)`. `binding` is the authority record (section 9); spawn without a valid binding returns `DENIED`. On Linux, an interactive session runs each foreground pipeline in its own process group, hands it the terminal, and forwards an interrupt aimed at the shell to that group. A non-interactive session leaves the pipeline in the shell's process group, so a group-wide interrupt reaches the shell and the pipeline together; in that mode the shell does not die of the interrupt while waiting and ends with status 130 if the last command died of SIGINT. SIGINT and SIGQUIT ignored at entry stay ignored in children. R1 has no job control: a stopped pipeline member cancels the whole pipeline (status 128 plus the stop signal). Exit status follows POSIX shell convention (127 not found, 126 found but not executable, 128 plus signal); exact agreement with the pinned reference shell is checked by the differential suite, not asserted here. Task and stream binding, task id lifetime, cancel statuses, launch order, refusal before effects and partial launch are `STREAM_TASK.md` ST6 and ST7; the capability domain check order is ST5. ### 8.5 Permissions and limits @@ -167,7 +167,7 @@ A location is `{scheme u8, len u32, bytes}`. Scheme 1 `POSIX_PATH`: raw bytes, n ## 10. Interrupted effects and restart -An effect is one `TASK_SPAWN` or one write-class `STREAM_OPEN`. The adapter keeps a durable intent record before the effect and an outcome record after. Outcomes: `NOT_STARTED`, `COMPLETED(status)`, `FAILED_NO_EFFECT(error)`, `CANCELLED`, `OUTCOME_UNKNOWN`. After a crash, restart or lost connection, an intent with no outcome is reported `OUTCOME_UNKNOWN` with the request digest; the adapter never replays it. A new request is a new decision by the human or by AIEN. No operation is claimed reversible and none is claimed exactly-once. `EINTR`-style interrupted waits are retried by the adapter without re-running the effect. Partial launch failure (some commands of a pipeline started, a later one failed) returns `PARTIAL_LAUNCH` after the adapter cancels and reaps the commands already started. +An effect is one `TASK_SPAWN` or one write-class `STREAM_OPEN`. The adapter keeps a durable intent record before the effect and an outcome record after. Outcomes: `NOT_STARTED`, `COMPLETED(status)`, `FAILED_NO_EFFECT(error)`, `CANCELLED`, `OUTCOME_UNKNOWN`. After a crash, restart or lost connection, an intent with no outcome is reported `OUTCOME_UNKNOWN` with the request digest; the adapter never replays it. A new request is a new decision by the human or by AIEN. No operation is claimed reversible and none is claimed exactly-once. `EINTR`-style interrupted waits are retried by the adapter without re-running the effect. Partial launch failure (some commands of a pipeline started, a later one failed) returns `PARTIAL_LAUNCH` after the adapter cancels and reaps the commands already started. What counts as a launch failure, and `OUTCOME_UNKNOWN` while running, are `STREAM_TASK.md` ST7.6 and ST8. ## 11. AIEN direct-argv submission @@ -190,7 +190,8 @@ Execution recording to Cortex is optional and policy-controlled, off unless poli 5. The numbering in 5.3 is a draft assignment; it freezes with the ABI. 6. Expected outputs in `vectors/` were authored from this text; the omega host vector harness (`S_NOSKIP` = 1) is the first implementation to run them. 7. Implementation deltas folded in above and to be confirmed or renumbered at freeze: codes 246 to 250, the 239 list and its 8-byte limit, `S_NOSKIP`, `S_EOI`, the `STAGING` unanswered sentinel, positional `k` above 9, and the expander overlay of dead lexer cells. +8. Stream and task freeze items: `STREAM_TASK.md` ST11 (draft op ids 6 to 15 and their argument layouts, native cancel statuses, the withdrawn `dst_fd` form of `STREAM_DUP`, the AIENOS stream and pipe counts below section 8.5, Omega's cleanup order, partial-write atomicity and zero-length writes on Linux, latched interrupts on Linux, the grace period). ## 15. Conformance -A core conforms when, for every vector, it returns the status, request record, refusal code and offset in `vectors/expected.txt`, calling the entries as in section 5 with the vector's environment. An adapter conforms when it implements section 8 to 12 behavior against its platform and the adapter test suite passes; adapters are tested separately from the core. Vector format and the file list are defined in [`vectors/README.md`](vectors/README.md). +A core conforms when, for every vector, it returns the status, request record, refusal code and offset in `vectors/expected.txt`, calling the entries as in section 5 with the vector's environment. An adapter conforms when it implements section 8 to 12 behavior against its platform and the adapter test suite passes; adapters are tested separately from the core. For streams and tasks an adapter runs the shared vectors `vectors/s*.vec` and `vectors/t*.vec`, reports `NOT_RUN` for every vector whose features or domain it lacks, and pins its report as `STREAM_TASK.md` ST10 requires. Vector format and the file list are defined in [`vectors/README.md`](vectors/README.md). diff --git a/specs/osh-platform/STREAM_TASK.md b/specs/osh-platform/STREAM_TASK.md new file mode 100644 index 0000000..1e51bf5 --- /dev/null +++ b/specs/osh-platform/STREAM_TASK.md @@ -0,0 +1,170 @@ +# OSH Platform ABI v1: streams and tasks (draft revision 2) + +**Status**: v1 DRAFT, revision 2, **not frozen**. Part of [`OSH_PLATFORM_ABI.md`](OSH_PLATFORM_ABI.md) (same `abi_version` 1, same freeze rule). This file makes sections 8.1, 8.4, 10 and 12 of that document precise for byte streams and tasks; where the two differ, this file wins until the freeze. Nothing here is frozen and nothing here is a claim that an adapter conforms. +**Origin**: `aien-dev/aien-protocols-mv#43` under `aien-dev/aien-architecture-mv#158`. Written against `OSH_PLATFORM_ABI.md` at commit `fb5fca98e667`, Omega's Linux host adapter at omega-mv `a8ffd2b912c8` (`src/osh/host/osh_exec.c`, `osh_caps.c`), and the AIENOS native pipe at aienos-mv `f8700d4cb65e` (branch `feat/native-pipe-1`, PR #433, `native/kernel/core/pipe.h`). The comparison is in [`AUDIT_STREAM_TASK.md`](AUDIT_STREAM_TASK.md). +**Conformance corpus**: `vectors/s*.vec` and `vectors/t*.vec`, format in [`vectors/README.md`](vectors/README.md) (section "Stream and task vectors"), reference model and checker in `tools/osh_sv_ref.c` and `tools/check-stream-vectors.sh`. +**License**: Community Specification License 1.0 + +Every rule below that no implementation has yet shown is marked UNVERIFIED. An UNVERIFIED rule is still normative for the draft: the vectors test it, and the freeze either confirms it or changes it with a new revision. + +## ST1. Terms + +- **Stream end**: one end of a pipe (read end or write end) or one opened storage stream. A **handle** names one stream end inside one principal's handle table. A handle is a transient id (section 4.3 of the ABI): it is never persisted and never used as identity. +- **Data right**: the right a stream end needs for its data operation: read on a read end, write on a write end. A handle never carries the data right of the other end. +- **Task**: one started program (a Linux process, or an AIENOS task). A **task id** is a transient id. +- **Pipeline launch**: the adapter's execution of one request record (section 7): create the pipes, start the commands left to right, wait, clean up. It is built from `PIPE_CREATE`, `TASK_SPAWN`, `TASK_WAIT`, `TASK_CANCEL` and `STREAM_CLOSE`. +- **Authority root**: the capability authority the adapter calls (section 9). It mints and revokes. Revocation is never a platform operation (ABI section 9.5). + +## ST2. Platform call frame (settles ABI section 3 for frames) + +A platform call is a frame of cells plus at most one borrowed byte slice: + +| cell | field | value | +|---|---|---| +| 0 | `magic` | `0x4F534846` ("OSHF") | +| 1 | `abi_version` | `1` | +| 2 | `op` | operation id (table below) | +| 3 | reserved | `0` | +| 4 onward | arguments | exactly the count the operation defines | + +The frame has exactly `4 + nargs` cells. The result is `{error u32, value u64, value2 u64}`; `value2` is used only by `PIPE_CREATE` (the write end) and is 0 otherwise. + +Check order, first failure wins, all before any effect (same order as ABI section 3, mapped onto section 8.6 errors because a platform frame answers with platform errors, not shell-core refusal codes): fewer than 4 cells or wrong `magic` is `INVALID_ARG`; `abi_version` not exactly 1 is `NOT_SUPPORTED`; reserved cell nonzero is `INVALID_ARG`; `op` not in the table, or in the table but not provided by this adapter, is `NOT_SUPPORTED`; wrong cell count, a handle cell the adapter cannot decode, or unknown flag bits is `INVALID_ARG`. Evidence: the AIENOS dispatch uses exactly this order. + +Operation ids (draft assignment, freezes with the ABI). Ids 1 to 5 are taken from the AIENOS implementation; ids 6 to 15 are assigned here and are UNVERIFIED (no implementation); 0 and 16 to 255 are unassigned and are always `NOT_SUPPORTED`. + +| op | operation | args | value | +|---|---|---|---| +| 1 | `PIPE_CREATE` | none | read end (value), write end (value2) | +| 2 | `STREAM_READ` | handle, flags | bytes read | +| 3 | `STREAM_WRITE` | handle, flags | bytes written | +| 4 | `STREAM_CLOSE` | handle | 0 | +| 5 | `STREAM_DUP` | handle, rights, target (0 own table, 1 named peer table) | new handle | +| 6 | `STREAM_OPEN` | location descriptor, mode | handle | +| 7 | `TASK_SPAWN` | resolved ref, stdin, stdout, stderr, binding ref | task id | +| 8 | `TASK_WAIT` | task id, deadline | exit status | +| 9 | `TASK_CANCEL` | task id, mode (1 interrupt, 2 terminate) | 0 | +| 10 | `TASK_STATE` | task id | state (ST6.4) | +| 11 | `RESOLVE` | search context | class and target ref | +| 12 | `PERM_CHECK` | binding ref, op | 0 | +| 13 | `LIMITS_GET` | none | limit record ref | +| 14 | `LOC_GETCWD` | none | location ref | +| 15 | `LOC_CHDIR` | location ref, binding ref | 0 | + +Flags for `STREAM_READ` and `STREAM_WRITE`: bit 0 `BLOCK` (park instead of `WOULD_BLOCK`); every other bit is reserved and must be 0. Argument layouts of ops 6 to 15 beyond the cell count are open freeze items (ABI section 14, item 8). + +Handle cells are adapter-private encodings (the AIENOS register form `generation << 32 | index` is one). The shell core and the vectors treat a handle cell as opaque. A handle cell of 0 is never valid. + +## ST3. Handles, ownership and epochs + +1. A handle is valid only in the table of the principal that holds it. `PIPE_CREATE` puts both ends into the caller's table. `STREAM_DUP` with target 1 puts a new handle into another principal's table (transfer). +2. Every use of a handle checks, at the moment of the effect, in this order: the handle cell is well formed (nonzero, in range; else `INVALID_ARG`); it names a live entry of the caller's table with the same generation, created in the current `session_epoch` (else `STALE`); the entry carries the operation's right and names the end the operation needs (else `DENIED`); the entry belongs to the current incarnation of its stream (else `STALE`); the stream is not revoked (else `REVOKED`, except for `STREAM_CLOSE`). Evidence: AIENOS `resolve` uses exactly this order; Omega's capability mapping agrees on the names (stale generation `STALE`, revoked `REVOKED`, anything else `DENIED`). +3. Two counters make a handle stale and both must be checked: the `session_epoch` of ABI section 4.4 (a session reset ends every handle of the session) and the per-object incarnation (a closed handle, or a handle to a pipe slot that was freed and reused, never reaches the new object). The width and layout of the incarnation counter are adapter-private; an adapter that cannot tell incarnations apart must retire the slot rather than reuse it. +4. A Linux adapter must not expose raw file descriptor numbers as handles: the kernel reuses descriptor numbers, which would let a closed handle reach a new stream instead of failing `STALE`. It keeps its own table with an incarnation per entry (UNVERIFIED: no Linux adapter exposes stream handles yet). +5. `PIPE_CREATE` needs no binding and no prior capability: it creates a private object whose only authority is over itself, and it is bounded by `LIMIT`. Evidence: the ABI signature has no binding; AIENOS and Omega (`pipe2`) both create pipes unconditionally. + +## ST4. Byte-stream semantics + +A pipe is a bounded first-in first-out byte buffer with capacity `C` = `LIMITS_GET.max_pipe_bytes`, at least 65,536 bytes (ABI section 8.5). Bytes are bytes: NUL and bytes at or above `0x80` pass unchanged. + +Each data operation does its checks in this order and stops at the first that applies: handle checks (ST3.2), a latched interrupt on that end (ST4.7), for a write the reader check (ST4.5), the length-zero rule (ST4.3), then the buffer state. + +1. **Partial read.** `STREAM_READ(h, max)` with `max > 0` on a pipe holding `b > 0` bytes returns `OK` with `n = min(max, b)`, the oldest bytes first. It never waits for more bytes once it has at least one. +2. **Partial write.** `STREAM_WRITE(h, len)` with `len > 0` and a reader present stores `n = min(len, C - b)` bytes and returns `OK` with that `n` when `n > 0`. The caller loops. There is no all-or-nothing size: v1 makes no `PIPE_BUF`-style atomicity promise. (A Linux kernel pipe refuses a non-blocking write of up to 4,096 bytes that does not fit whole; a Linux adapter that serves `STREAM_WRITE` straight from a kernel pipe differs here. Open freeze item ST11.6.) +3. **Zero length.** `max = 0` or `len = 0` moves nothing and never blocks. A zero-length read returns `OK` with `n = 0`; this is not end of stream and the stream state is not consulted. A zero-length write still reports a missing reader: `BROKEN_PIPE`; otherwise `OK` with `n = 0`, even when the pipe is full. Authority is checked first in both cases. Evidence: AIENOS. (A Linux `write(fd, buf, 0)` on a pipe returns 0 without checking for readers; a Linux adapter must check, for example with `poll` for `POLLERR` on the write end. UNVERIFIED for Linux.) +4. **End of stream.** A read with `max > 0` on an empty pipe returns `OK` with `n = 0` (end of stream) only when every write-end handle is closed: the caller's, every duplicate, and every one held by a task. Bytes written before the last writer closed are delivered first. While any write end is open, an empty pipe gives `WOULD_BLOCK` (or parks with `BLOCK`). +5. **No reader.** A write when every read-end handle is closed returns `BROKEN_PIPE` and stores nothing. Bytes still buffered when the last reader closes are discarded and never delivered. +6. **Backpressure.** A write with `len > 0` on a full pipe returns `WOULD_BLOCK`, or with `BLOCK` parks until space, a close, a revoke or an interrupt. Nothing is ever buffered beyond `C`. A read on an empty pipe with a writer present behaves the same way. A parked call re-checks ST3.2 when it resumes, and returns as soon as it moved at least one byte. +7. **Interrupt.** An interrupt aimed at a stream end (the way `TASK_CANCEL(interrupt)` or a shell-level interrupt reaches a call on that end) makes the call parked on that end return `INTERRUPTED` with nothing moved. If no call is parked, the interrupt is latched on that end and the next data call on that end returns `INTERRUPTED` once; the call after that runs normally. An interrupted call never moved a byte, so the caller may retry it without repeating an effect (ABI section 10). Evidence: AIENOS. UNVERIFIED for Linux, where a signal that arrives outside a system call is not latched onto the next one: a Linux adapter latches it itself. +8. **Close and wake.** `STREAM_CLOSE(h)` releases the handle. Closing the last write end wakes every parked reader, which then sees the buffered bytes and then end of stream. Closing the last read end wakes every parked writer, which returns `BROKEN_PIPE` (or, if it already moved bytes in this call, `OK` with that count). Closing a handle of a revoked stream works and returns `OK`. Closing a closed or stale handle returns `STALE`. When both ends are closed the pipe is freed and its bytes are scrubbed. +9. **Revocation.** When the authority root revokes a pipe, the buffered bytes are scrubbed, every parked call on either end returns `REVOKED`, and every later read, write, dup or interrupt on any handle of that pipe returns `REVOKED`; no byte is delivered after the revoke. Only `STREAM_CLOSE` still works, so handles can be released. Revocation during a parked read or a parked write is covered by vectors. +10. **Duplicate.** `STREAM_DUP(h, rights, target)` makes a new handle on the same end. `rights` must contain the end's data right and nothing that is not a stream right (`INVALID_ARG`), and must be a subset of `h`'s rights. A duplicate into the caller's own table needs the derive right on `h`, into another principal's table the grant right (`DENIED` without it). Each duplicate counts as a separate reader or writer for ST4.4 and ST4.5. This is the capability form; the draft's `STREAM_DUP(src_stream, dst_fd)` is withdrawn in revision 2 (ST11.3). Descriptor duplication in a request record (redirection kind 4, `N>&M`) is the adapter's private business when it builds a task's standard streams for `TASK_SPAWN`; it is not a platform operation. +11. **Stream rights letters** (used by the vectors): `r` read, `w` write, `d` derive, `g` grant, `v` revoke (held by the authority root's delegate; revocation itself is still the root's act). `m` (map) is never a stream right. + +## ST5. Capability domains and generations (settles ABI section 9.3) + +Every effect that needs authority (`TASK_SPAWN`, write-class `STREAM_OPEN`, `LOC_CHDIR` into a protected location) carries a binding `{principal_id[32], domain u8, cap_index u32, cap_generation u64, resource_class u16, operation u16}`. The effect boundary checks it in this order at the moment of the effect, first failure wins, nothing happens on failure: + +0. No binding at all: `DENIED` (ABI section 8.4). +1. `domain` is neither 1 nor 2: `CAP_DOMAIN_MISMATCH`. +2. `domain` is 1 and `cap_generation` is above `0xFFFFFFFF`: `CAP_GEN_NARROW`. The generation is never truncated: a domain-1 binding with generation `0x1_00000007` is refused even if a live capability has generation 7. +3. `domain` differs from the domain of the resource's authority: `CAP_DOMAIN_MISMATCH`. v1 has no bridge. +4. `cap_index` is not live, or `cap_generation` differs from the live generation in all of its bits (32 bits in domain 1, 64 bits in domain 2): `STALE`. A domain-2 authority compares all 64 bits: generation `0x7` does not match a live `0x1_00000007`. +5. The capability was revoked: `REVOKED`. +6. The capability does not grant this resource and operation: `DENIED`. + +Evidence: steps 1, 2, 4, 5 and 6 are Omega's order (`authorize` then the capability root mapping); step 3 is Omega's hosted adapter (domain 2 only). AIENOS kernel tables are domain 1 with 32-bit generations. The full order across both domains is UNVERIFIED until both adapters run the vectors. + +## ST6. Tasks + +### ST6.1 Binding a task to streams + +`TASK_SPAWN(resolved, argv, env, stdio{0,1,2}, binding)` gives the new task its own duplicate of each standard stream; the caller keeps its own handles, and the caller closing its copy is what lets end of stream reach a reader (ST4.4). A `stdin` slot needs a read end, `stdout` and `stderr` need write ends; a stale handle in a slot is `STALE` and a handle of the wrong end is `INVALID_ARG`, both before the binding is checked and before the task exists (UNVERIFIED order). A slot may be empty (the task sees end of stream on input and its output is discarded). When a task ends for any reason, every stream end it holds is closed, with the wake rules of ST4.8. + +### ST6.2 Lifetime of a task id + +A task id is valid from a successful `TASK_SPAWN` until the `TASK_WAIT` that returns the task's final status (the task is reaped then). Any later use of that id, and any use of an id from an earlier `session_epoch`, is `STALE`. `TASK_WAIT` with deadline 0 on a task that has not ended returns `WOULD_BLOCK` and reaps nothing. UNVERIFIED: no adapter implements `TASK_WAIT` with a deadline. + +### ST6.3 Exit status + +A task that exits normally has its exit code. A task the adapter ended with `TASK_CANCEL(interrupt)` has status 130 and outcome `CANCELLED`; with `TASK_CANCEL(terminate)` status 137 and outcome `CANCELLED`. A task killed by a signal someone else sent (Linux) is `COMPLETED` with status 128 plus the signal, as in ABI section 8.4; `CANCELLED` is only the adapter's own act. A task that writes to a stream with no reader and does not handle `BROKEN_PIPE` ends with status 141 (Linux: death by `SIGPIPE`; native: the same number by rule). Statuses 130, 137 and 141 on a native adapter are UNVERIFIED conventions chosen to equal the Linux numbers. + +### ST6.4 State + +`TASK_STATE` returns 1 `RUNNING` or 2 `ENDED` (ended, not yet reaped). UNVERIFIED numbering. + +### ST6.5 Cancellation + +`TASK_CANCEL(interrupt)` delivers an interrupt: the task's parked stream call returns `INTERRUPTED` (ST4.7). A task may handle an interrupt and keep running. `TASK_CANCEL(terminate)` ends the task unconditionally: it cannot be ignored (Linux `SIGKILL`). Cancelling an ended, unreaped task returns `OK` and changes nothing. Cancelling a reaped task is `STALE`. + +Cleanup of a running pipeline (ABI section 12, on `ERROR`, reset, shutdown or partial launch): interrupt every running task, wait a bounded grace period, terminate the survivors, reap every task, close every stream end the adapter holds for that pipeline. After cleanup no task of that pipeline is running, no pipe end is open in the adapter, and every task id is released. + +## ST7. Pipeline launch, refusal before effects, partial launch + +The adapter launches a request record in this order. Steps 1 to 4 make no effect; a refusal there starts nothing and every command's outcome is `FAILED_NO_EFFECT`. + +1. Shape: `ncmds` 1 to 8 (more is `LIMIT`; a record above 8 is already refused by the decoder, ABI section 7.1), every field valid (`REQ_FIELD`). +2. `RESOLVE` every external command. A class this adapter does not provide refuses the whole pipeline: `UNAVAILABLE`, status 126. Classes never fall back to each other. +3. Binding checks of ST5 steps 0 to 2 (shape of the binding), plus `PERM_CHECK`: a failure refuses the whole pipeline with that error, status 126. +4. Create all `ncmds - 1` pipes. Failure: `LIMIT`, status 1; pipes already created are closed. +5. Start commands left to right. For each command, at the moment of its effect: a name that was not found gives that command status 127 (`NOT_FOUND`, outcome `FAILED_NO_EFFECT`); a binding that fails ST5 steps 3 to 6 now (for example revoked after an earlier command started) gives that command status 126 with that error and outcome `FAILED_NO_EFFECT`. In both cases the adapter closes that command's pipe ends so its neighbours see end of stream or `BROKEN_PIPE`, and the other commands still run, as in a POSIX shell. Evidence: Omega `run_pipeline`. +6. A **launch failure** is a resource failure of `TASK_SPAWN` itself (Linux `fork` failure, task table full: `LIMIT` or `IO`). If no command has started yet, the pipeline returns that error, status 1, the failing command `FAILED_NO_EFFECT`, the rest `NOT_STARTED`. If at least one command started, the adapter cancels and reaps the started ones (ST6.5 cleanup), closes every pipe, and returns `PARTIAL_LAUNCH`, status 1, with outcomes: started commands `CANCELLED` (status as they ended: 130 interrupted, 137 terminated), the failing one `FAILED_NO_EFFECT` with status 1, later ones `NOT_STARTED` with no status. A started command that had already ended on its own before the cleanup still reports `CANCELLED` (Omega does this; UNVERIFIED as a rule). +7. Wait for all, reap all. Pipeline status is the last command's status (ABI section 7.2); a nonzero status of an earlier command does not change it. + +Every operation an adapter does not provide is refused with a defined error before any effect: `NOT_SUPPORTED` for an op id, `UNAVAILABLE` for a resolution class or location scheme. An adapter never reports success for something it did not do. + +## ST8. Effects, outcomes and OUTCOME_UNKNOWN + +1. An effect is one `TASK_SPAWN` or one write-class `STREAM_OPEN` (ABI section 10). Pipe creation, reads, writes, closes and duplicates are not effects and have no intent record. +2. Before each effect the adapter makes a durable intent record; after it ends, an outcome record (`NOT_STARTED`, `COMPLETED(status)`, `FAILED_NO_EFFECT(error)`, `CANCELLED`, `OUTCOME_UNKNOWN`). If the intent cannot be made durable, the effect does not happen (`FAILED_NO_EFFECT`, `IO`). +3. After an adapter crash or restart, every intent with no outcome is reported `OUTCOME_UNKNOWN` and is **never replayed**; the restart also advances `session_epoch`, so every earlier handle and task id is `STALE`. +4. While running, a started task whose fate the adapter can no longer determine (Linux: someone else reaped the child, `waitpid` gives `ECHILD`) is reported by `TASK_WAIT` as error `OUTCOME_UNKNOWN`, status 1, outcome `OUTCOME_UNKNOWN`. It is never reported as success and never restarted. Evidence: Omega `wait_all` and its journal recovery. + +## ST9. Limits + +`LIMITS_GET` reports `{max_streams, max_tasks, max_pipe_bytes, max_output_bytes}`. v1 minimums (ABI section 8.5): 16 open stream handles per session besides the 3 standard ones (so at least 8 pipes with both ends held), 8 concurrent tasks per pipeline, 65,536 bytes per pipe. A request beyond a limit returns `LIMIT` and leaves nothing allocated; nothing is ever truncated silently. + +## ST10. Conformance and receipts + +1. The corpus `vectors/s*.vec` and `vectors/t*.vec` is shared by every adapter. Each vector names the features it needs and its authority domain. An adapter runs every vector it can; for any vector that needs a feature or a domain it does not have, it reports `NOT_RUN` with the reason. It never reports `PASS` for a vector it did not run, and never skips silently. +2. Each vector is marked `exec host-logic` (the adapter's state logic run in a host unit test is valid evidence) or `exec native-qemu` (it involves real parking, real tasks or real concurrent execution: AIENOS evidence counts only from a native run under QEMU, Omega evidence only from real Linux processes). The reference model in this repository runs every vector as logic; its result is a check of the corpus, not evidence about any adapter. +3. A run report is a receipt only if its first line pins all of: the implementation repository and full commit, this corpus's repository and full commit, the compiler and its version, and the target (`host` or `qemu-`). Format in `vectors/README.md`. Results without those pins are not receipts. + +## ST11. Open freeze items for streams and tasks + +These are recorded, not settled, and the ABI must not freeze while one is open. + +1. Op ids 6 to 15 and their argument layouts (ST2) have no implementation. +2. Status numbers 130, 137 and 141 on a native adapter (ST6.3) and the `TASK_STATE` numbering (ST6.4). +3. `STREAM_DUP(src_stream, dst_fd)` from the draft is withdrawn in favour of the capability form (ST4.10); the freeze confirms that no consumer needs a platform-level `dst_fd` form. +4. Minimum stream count: AIENOS currently has 8 handle slots per table and 4 pipes per pool, below ST9 (16 handles, 8 pipes, and 7 pipes for an 8-command pipeline). Either AIENOS grows or the minimum changes with a revision; the limit vector fails on AIENOS until then. +5. Section 12 says interrupt, grace, terminate. Omega's partial-launch cleanup sends `SIGTERM` and `SIGCONT` with no escalation, and labels the failing command `NOT_STARTED` instead of `FAILED_NO_EFFECT`; the vectors follow this document, so Omega differs until it changes or this text does. +6. Partial-write atomicity: Linux kernel pipes are all-or-nothing for non-blocking writes of up to 4,096 bytes; this text requires partial writes (ST4.2). Settle before the freeze whether the Linux adapter buffers to conform or the rule allows `WOULD_BLOCK` there. +7. Zero-length write on a pipe with no reader is `BROKEN_PIPE` here (AIENOS); Linux returns 0. The Linux adapter must check readers itself (ST4.3). +8. Latched interrupts (ST4.7) are AIENOS behaviour; a Linux adapter must emulate them. +9. The exact grace period of ST6.5 is not fixed; vectors only require that cleanup ends with every task reaped. + +## ST12. Revision history + +- Revision 1 (`fb5fca98e667` and earlier): ABI sections 8.1, 8.4, 10, 12 only. +- Revision 2 (this file, aien-protocols-mv#43): platform call frame layout and draft op ids (ST2); handle check order and incarnations (ST3); byte-stream semantics (ST4); `STREAM_DUP` changed to the capability form (incompatible with revision 1, allowed only because v1 is not frozen); domain check order (ST5); task binding, lifetime, statuses, cancellation (ST6); launch order and partial launch (ST7); outcome rules (ST8); conformance and receipts (ST10). `abi_version` stays 1 because nothing in v1 is frozen (ABI header); after the freeze, any change of this size bumps `abi_version`. diff --git a/specs/osh-platform/tools/check-stream-vectors.sh b/specs/osh-platform/tools/check-stream-vectors.sh new file mode 100755 index 0000000..ce1130c --- /dev/null +++ b/specs/osh-platform/tools/check-stream-vectors.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# check-stream-vectors.sh: check the OSH stream and task vectors (vectors/s*.vec, vectors/t*.vec) against the +# reference model, and guard the shell-core corpus next to them. +# +# Usage: check-stream-vectors.sh [CC] (default CC: cc) +# +# 1. Lints every s*.vec / t*.vec header (case, kind, exec, domain, needs; file name ends in _.vec; +# case names unique). +# 2. Builds tools/osh_sv_ref.c with warnings as errors (C99, libc only) and runs the corpus; every vector must +# PASS. Then the same with ASan/UBSan when the compiler supports it. +# 3. Runs tools/mutate-stream-ref.sh: every check of the model must be caught by a vector. +# 4. Regenerates the shell-core inputs (tools/make-vectors.sh) into a scratch directory and requires them +# byte-identical to vectors/v*.in and v*.env, so the stream corpus never disturbs the existing format. +# Host-only check of the corpus: it is not evidence about any adapter and qualifies no hardware. Shell and C +# only. Found by the PROTO-C-VECTORS gate (tests/gates/run.sh c-vectors) because its name matches check-*.sh. +set -eu +export LC_ALL=C +here=$(cd "$(dirname "$0")" && pwd) +vec="$here/../vectors" +CC=${1:-cc} +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +# 1. header lint +bad=0 +n=0 +for f in "$vec"/s*.vec "$vec"/t*.vec; do + [ -e "$f" ] || continue + n=$((n + 1)) + b=$(basename "$f" .vec) + c=$(sed -n 's/^case \([a-z0-9_]*\)$/\1/p' "$f" | head -n 1) + for key in case kind exec domain needs; do + grep -q "^$key " "$f" || { echo "OSHSV1_LINT $b: missing '$key' line" >&2; bad=1; } + done + grep -q -E '^kind (positive|negative)$' "$f" || { echo "OSHSV1_LINT $b: kind must be positive or negative" >&2; bad=1; } + grep -q -E '^exec (host-logic|native-qemu)$' "$f" || { echo "OSHSV1_LINT $b: exec must be host-logic or native-qemu" >&2; bad=1; } + grep -q -E '^domain (1|2|any)$' "$f" || { echo "OSHSV1_LINT $b: domain must be 1, 2 or any" >&2; bad=1; } + case "$b" in + [st][0-9][0-9][0-9]_"$c") ;; + *) echo "OSHSV1_LINT $b: file name must be sNNN_ or tNNN_" >&2; bad=1 ;; + esac + echo "$c" >>"$tmp/cases" +done +test "$n" -gt 0 || { echo "OSHSV1_LINT no stream or task vectors found" >&2; exit 1; } +dups=$(sort "$tmp/cases" | uniq -d) +test -z "$dups" || { echo "OSHSV1_LINT duplicate case names: $dups" >&2; bad=1; } +test "$bad" -eq 0 || exit 1 +echo "OSHSV1_LINT ok vectors=$n" + +# 2. reference model, plain and sanitized +corpus=$(git -C "$here" rev-parse HEAD 2>/dev/null || echo unpinned) +tc=$("$CC" --version 2>/dev/null | head -n 1 | tr ' ' '_') +"$CC" -std=c99 -O2 -Wall -Wextra -Werror -pedantic -o "$tmp/ref" "$here/osh_sv_ref.c" +"$tmp/ref" --corpus "$vec" --pin "corpus=$corpus" --pin "toolchain=$tc" +if "$CC" -std=c99 -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all \ + -o "$tmp/ref_san" "$here/osh_sv_ref.c" 2>/dev/null; then + "$tmp/ref_san" --corpus "$vec" | sed 's/impl=reference-model/impl=reference-model-asan-ubsan/' | grep -v '^PASS ' + test "${PIPESTATUS[0]}" -eq 0 +else + echo "OSHSV1_SANITIZER NOT_RUN (compiler lacks -fsanitize=address,undefined)" +fi + +# 3. every check has teeth +bash "$here/mutate-stream-ref.sh" "$CC" + +# 4. the shell-core corpus is untouched +mkdir -p "$tmp/core" +bash "$here/make-vectors.sh" "$tmp/core" +for f in "$tmp"/core/v*; do + cmp -s "$f" "$vec/$(basename "$f")" || { echo "OSHSV1_CORE_STALE $(basename "$f") differs from make-vectors.sh" >&2; exit 1; } +done +for f in "$vec"/v*.in "$vec"/v*.env; do + [ -e "$tmp/core/$(basename "$f")" ] || { echo "OSHSV1_CORE_STALE $(basename "$f") is not generated" >&2; exit 1; } +done +echo "OSHSV1_CORE_REGEN identical" +echo "OSHSV1_VECTORS_PASS" diff --git a/specs/osh-platform/tools/mutate-stream-ref.sh b/specs/osh-platform/tools/mutate-stream-ref.sh new file mode 100755 index 0000000..391ab09 --- /dev/null +++ b/specs/osh-platform/tools/mutate-stream-ref.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# mutate-stream-ref.sh: show that every check in osh_sv_ref.c is exercised by the stream and task vectors. +# Builds one model per check with that check disabled (-DSV_MUTANT=K, the order of `enum mut`) and +# requires the corpus to report at least one mismatch. A mutant the vectors do not notice is a SURVIVOR +# and fails this script. +# +# Usage: mutate-stream-ref.sh [CC] +set -eu +export LC_ALL=C +here=$(cd "$(dirname "$0")" && pwd) +vec="$here/../vectors" +CC=${1:-cc} +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +names=$(sed -n '/MUT_WRITE_RIGHT = 1/,/MUT_LAST/p' "$here/osh_sv_ref.c" | tr -d ' \n' | sed 's/MUT_WRITE_RIGHT=1/MUT_WRITE_RIGHT/; s/,MUT_LAST.*//' | tr ',' ' ') +test -n "$names" || { echo "cannot read the check list" >&2; exit 2; } +k=0 killed=0 survived=0 +for name in $names; do + k=$((k + 1)) + "$CC" -std=c99 -O1 -w -DSV_MUTANT=$k -o "$tmp/m$k" "$here/osh_sv_ref.c" + if "$tmp/m$k" --corpus "$vec" >"$tmp/out$k" 2>&1; then + echo "SURVIVOR $k $name" + survived=$((survived + 1)) + else + echo "killed $k $name: $(grep -c -E 'MISMATCH|VECTOR_ERROR' "$tmp/out$k") line(s) differ" + killed=$((killed + 1)) + fi +done +echo "OSHSV1_MUTANTS total=$k killed=$killed survived=$survived" +test "$survived" -eq 0 && test "$k" -gt 0 diff --git a/specs/osh-platform/tools/osh_sv_ref.c b/specs/osh-platform/tools/osh_sv_ref.c new file mode 100644 index 0000000..952b097 --- /dev/null +++ b/specs/osh-platform/tools/osh_sv_ref.c @@ -0,0 +1,1568 @@ +/* osh_sv_ref.c: reference model for the OSH stream and task vectors (OSHSV1). + * + * Contract: ../STREAM_TASK.md (OSH Platform ABI v1 DRAFT, revision 2, not frozen), written against + * ../OSH_PLATFORM_ABI.md at aien-protocols-mv commit fb5fca98e667. Corpus format: ../vectors/README.md, section + * "Stream and task vectors". This program plays one adapter that has every feature and both capability domains, and + * runs every vectors/s*.vec and vectors/t*.vec file against it. It is a check that the corpus is self-consistent and + * has teeth (tools/mutate-stream-ref.sh), not evidence about Omega or AIENOS, and it qualifies nothing physical. + * + * Model choices the spec does not pin (each UNVERIFIED, listed in the handoff and in STREAM_TASK.md ST11): + * - limits: 8 pipes of 65536 bytes, 16 handle slots per principal table, 16 tasks; + * - handle cell form generation << 32 | (slot + 1), opaque to the corpus; + * - a task runs one step per scheduler round, and checks a pending interrupt before each step; + * - the default capability generation is 7 in domain 1 and 0x100000007 in domain 2. + * + * Usage: osh_sv_ref --corpus DIR [--pin corpus=SHA] [--pin toolchain=TEXT] + * Build: cc -std=c99 -O2 -Wall -Wextra -Werror -pedantic osh_sv_ref.c. -DSV_MUTANT=K disables check K (enum mut). + * C99 and libc only. */ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include +#include + +#ifndef SV_MUTANT +#define SV_MUTANT 0 +#endif +/* Every check the vectors must catch. tools/mutate-stream-ref.sh builds one model per entry with that check off. */ +enum mut { + MUT_NONE = 0, + MUT_WRITE_RIGHT = 1, + MUT_EOF_ANY, + MUT_NO_BROKEN_PIPE, + MUT_ZERO_WRITE_NO_READER, + MUT_UNBOUNDED, + MUT_NO_LATCH, + MUT_NO_GENERATION, + MUT_NO_EPOCH, + MUT_FRAME_VERSION, + MUT_FRAME_RESERVED, + MUT_GEN_TRUNCATE, + MUT_GEN_32BIT_COMPARE, + MUT_DOMAIN_BRIDGE, + MUT_BIND_ONCE, + MUT_PARTIAL_NO_CANCEL, + MUT_CRASH_REPLAY, + MUT_TASK_KEEPS_ENDS, + MUT_DUP_NO_SUBSET, + MUT_LIMIT_LEAK, + MUT_STAGE_FAIL_ABORTS, + MUT_WAIT_NO_RELEASE, + MUT_TERMINATE_IGNORABLE, + MUT_LAST +}; +#define MUT(k) (SV_MUTANT == (k)) + +enum err { + E_OK = 0, E_DENIED, E_REVOKED, E_STALE, E_NOT_FOUND, E_UNAVAILABLE, E_INVALID_ARG, E_LIMIT, E_INTERRUPTED, + E_BROKEN_PIPE, E_IO, E_OUTCOME_UNKNOWN, E_CAP_DOMAIN_MISMATCH, E_CAP_GEN_NARROW, E_NOT_SUPPORTED, E_WOULD_BLOCK, + E_PARTIAL_LAUNCH, E_COUNT +}; +static const char *const k_err[E_COUNT] = {"OK", "DENIED", "REVOKED", "STALE", "NOT_FOUND", "UNAVAILABLE", + "INVALID_ARG", "LIMIT", "INTERRUPTED", "BROKEN_PIPE", "IO", + "OUTCOME_UNKNOWN", "CAP_DOMAIN_MISMATCH", "CAP_GEN_NARROW", + "NOT_SUPPORTED", "WOULD_BLOCK", "PARTIAL_LAUNCH"}; +enum outc { O_NOT_STARTED = 0, O_COMPLETED, O_FAILED_NO_EFFECT, O_CANCELLED, O_UNKNOWN }; +static const char *const k_out[] = {"NOT_STARTED", "COMPLETED", "FAILED_NO_EFFECT", "CANCELLED", "OUTCOME_UNKNOWN"}; + +/* ---- limits (section ST9 minimums; the model uses exactly them) ---- */ +#define CAP_BYTES 65536u +#define NPIPES 8 +#define NSLOTS 16 +#define NTASKS 16 +#define NTABLES (2 + NTASKS) /* A, B, then one table per task */ +#define NNAMES 96 +#define MAXSTAGES 8 + +/* ---- rights (ST4.11) ---- */ +#define R_READ 0x01u +#define R_WRITE 0x02u +#define R_MAP 0x04u +#define R_GRANT 0x08u +#define R_DERIVE 0x10u +#define R_REVOKE 0x20u +#define R_CTL (R_GRANT | R_DERIVE | R_REVOKE) + +#define FRAME_MAGIC 0x4F534846u + +struct pipe { + uint8_t buf[CAP_BYTES * 2]; /* twice the capacity so MUT_UNBOUNDED has room to misbehave */ + uint32_t head, len, inc; + unsigned readers, writers; + int live, revoked, latch[2]; +}; +struct slot { + int live; + uint32_t gen, inc; + uint64_t epoch; + unsigned pipe, end, rights; +}; +struct table { + struct slot s[NSLOTS]; + uint32_t gens[NSLOTS]; +}; +struct href { /* a named handle as the vector sees it (opaque cell) */ + char name[24]; + unsigned table, slot; + uint32_t gen; + uint64_t epoch; +}; + +enum prog { P_EXIT, P_EMIT, P_CAT, P_DRAIN, P_FLOOD, P_HANG, P_STUBBORN }; +enum tstate { T_FREE = 0, T_RUNNING, T_ENDED }; +struct task { + int state, intr, lost, intent_open; + uint32_t gen; + uint64_t epoch; + enum prog prog; + int arg, status, outcome, cancelled; + uint8_t data[256]; + size_t dlen, dpos; + uint8_t carry[4096]; + size_t clen; + int in_slot, out_slot; /* slot in the task's table, -1 none */ + int src_virtual; /* stdin is the pipeline source */ + int sink_virtual; /* stdout is the pipeline sink */ + int pipeline; /* index into pipelines or -1 */ +}; +struct tref { + char name[24]; + unsigned idx; + uint32_t gen; + uint64_t epoch; +}; +struct cap { + char name[24]; + unsigned index; + uint64_t gen; + int revoked; +}; +struct binding { + char name[24]; + int none; + unsigned domain, index; + uint64_t gen; +}; +struct pline { + char name[24]; + int live, n; + int task[MAXSTAGES]; /* task index, or -1 */ + int outcome[MAXSTAGES], status[MAXSTAGES]; + uint8_t src[256]; + size_t slen, spos; + uint8_t sink[4096]; + size_t sinklen; + uint64_t epoch; +}; + +static struct { + struct pipe pipes[NPIPES]; + struct table tables[NTABLES]; + struct task tasks[NTASKS]; + struct href h[NNAMES]; + unsigned nh; + struct tref t[NNAMES]; + unsigned nt; + struct cap caps[16]; + unsigned ncaps; + struct binding b[16]; + unsigned nb; + struct pline p[4]; + unsigned np; + uint64_t epoch; + unsigned domain; /* authority domain of this vector, 0 = any */ + unsigned open_intents, crashed_unknown; +} M; + +static int g_fail; +static const char *g_file; +static unsigned g_line; + +static void bad(const char *msg) +{ + fprintf(stderr, "VECTOR_ERROR %s:%u %s\n", g_file, g_line, msg); + g_fail = 1; +} + +static void model_reset(void) +{ + memset(&M, 0, sizeof M); + M.epoch = 1; + for (unsigned t = 0; t < NTABLES; t++) + for (unsigned i = 0; i < NSLOTS; i++) + M.tables[t].gens[i] = 0; +} + +/* ---------------- handles and pipes ---------------- */ + +static struct href *hname(const char *n, int create) +{ + for (unsigned i = 0; i < M.nh; i++) + if (!strcmp(M.h[i].name, n)) + return &M.h[i]; + if (!create || M.nh == NNAMES || strlen(n) >= sizeof M.h[0].name) + return 0; + struct href *r = &M.h[M.nh++]; + memset(r, 0, sizeof *r); + strcpy(r->name, n); + return r; +} + +static int slot_alloc(unsigned t, unsigned pipe, unsigned end, unsigned rights) +{ + struct table *tb = &M.tables[t]; + for (unsigned i = 0; i < NSLOTS; i++) + if (!tb->s[i].live) { + tb->gens[i]++; + tb->s[i].live = 1; + tb->s[i].gen = tb->gens[i]; + tb->s[i].inc = M.pipes[pipe].inc; + tb->s[i].epoch = M.epoch; + tb->s[i].pipe = pipe; + tb->s[i].end = end; + tb->s[i].rights = rights; + if (end == 0) + M.pipes[pipe].readers++; + else + M.pipes[pipe].writers++; + return (int)i; + } + return -1; +} + +static void pipe_free_if_done(unsigned p) +{ + struct pipe *q = &M.pipes[p]; + if (q->live && q->readers == 0 && q->writers == 0) { + memset(q->buf, 0, sizeof q->buf); + q->live = 0; + q->revoked = 0; + q->head = q->len = 0; + q->latch[0] = q->latch[1] = 0; + } +} + +static void slot_release(unsigned t, unsigned i) +{ + struct slot *s = &M.tables[t].s[i]; + if (!s->live) + return; + struct pipe *q = &M.pipes[s->pipe]; + if (s->inc == q->inc && q->live) { + if (s->end == 0 && q->readers) + q->readers--; + else if (s->end == 1 && q->writers) + q->writers--; + if (s->end == 0 && q->readers == 0) { /* bytes nobody can read any more are discarded (ST4.5) */ + memset(q->buf, 0, sizeof q->buf); + q->head = q->len = 0; + } + pipe_free_if_done(s->pipe); + } + s->live = 0; +} + +/* ST3.2 check order. need: rights; want_end: 0 read, 1 write, -1 either; close_ok: a revoked stream may be closed. */ +static int resolve(unsigned t, const struct href *h, unsigned need, int want_end, int close_ok, unsigned *pipe, + unsigned *end) +{ + if (!h || h->gen == 0 || h->slot >= NSLOTS) + return E_INVALID_ARG; + if (h->table != t) + return E_STALE; /* a handle names an entry of its own table only */ + const struct slot *s = &M.tables[t].s[h->slot]; + if (!s->live || (s->gen != h->gen && !MUT(MUT_NO_GENERATION))) + return E_STALE; + if (h->epoch != M.epoch && !MUT(MUT_NO_EPOCH)) + return E_STALE; + if ((s->rights & need) != need) + return E_DENIED; + if (want_end >= 0 && s->end != (unsigned)want_end) + return E_DENIED; + const struct pipe *q = &M.pipes[s->pipe]; + if (!q->live || q->inc != s->inc) + return E_STALE; + if (q->revoked && !close_ok) + return E_REVOKED; + *pipe = s->pipe; + *end = s->end; + return E_OK; +} + +static int op_create(unsigned t, struct href *r, struct href *w) +{ + unsigned idx = NPIPES; + for (unsigned i = 0; i < NPIPES; i++) + if (!M.pipes[i].live) { + idx = i; + break; + } + if (idx == NPIPES) + return E_LIMIT; + struct pipe *q = &M.pipes[idx]; + q->inc++; + q->live = 1; + q->revoked = 0; + q->head = q->len = 0; + q->readers = q->writers = 0; + q->latch[0] = q->latch[1] = 0; + int rs = slot_alloc(t, idx, 0, R_READ | R_CTL); + if (rs < 0) { + pipe_free_if_done(idx); + return E_LIMIT; + } + int ws = slot_alloc(t, idx, 1, R_WRITE | R_CTL); + if (ws < 0) { + if (!MUT(MUT_LIMIT_LEAK)) + slot_release(t, (unsigned)rs); + return E_LIMIT; + } + r->table = w->table = t; + r->slot = (unsigned)rs; + w->slot = (unsigned)ws; + r->gen = M.tables[t].s[rs].gen; + w->gen = M.tables[t].s[ws].gen; + r->epoch = w->epoch = M.epoch; + return E_OK; +} + +static int latched(struct pipe *q, unsigned end) +{ + if (q->latch[end]) { + q->latch[end] = 0; + return 1; + } + return 0; +} + +static int op_read(unsigned t, const struct href *h, uint8_t *out, size_t max, size_t *n) +{ + unsigned p, end; + *n = 0; + int e = resolve(t, h, R_READ, 0, 0, &p, &end); + if (e) + return e; + struct pipe *q = &M.pipes[p]; + if (latched(q, 0)) + return E_INTERRUPTED; + if (max == 0) + return E_OK; + if (q->len == 0) + return (q->writers == 0 || MUT(MUT_EOF_ANY)) ? E_OK : E_WOULD_BLOCK; + size_t take = max < q->len ? max : q->len; + for (size_t i = 0; i < take; i++) { + out[i] = q->buf[q->head]; + q->buf[q->head] = 0; + q->head = (q->head + 1) % (uint32_t)sizeof q->buf; + } + q->len -= (uint32_t)take; + *n = take; + return E_OK; +} + +static int op_write(unsigned t, const struct href *h, const uint8_t *in, size_t len, size_t *n) +{ + unsigned p, end; + *n = 0; + int e = resolve(t, h, MUT(MUT_WRITE_RIGHT) ? 0 : R_WRITE, MUT(MUT_WRITE_RIGHT) ? -1 : 1, 0, &p, &end); + if (e) + return e; + struct pipe *q = &M.pipes[p]; + if (latched(q, 1)) + return E_INTERRUPTED; + if (len == 0 && MUT(MUT_ZERO_WRITE_NO_READER)) + return E_OK; + if (q->readers == 0 && !MUT(MUT_NO_BROKEN_PIPE)) + return E_BROKEN_PIPE; + if (len == 0) + return E_OK; + size_t cap = MUT(MUT_UNBOUNDED) ? sizeof q->buf : CAP_BYTES; + size_t room = cap - q->len; + if (room == 0) + return E_WOULD_BLOCK; + size_t put = len < room ? len : room; + for (size_t i = 0; i < put; i++) + q->buf[(q->head + q->len + i) % (uint32_t)sizeof q->buf] = in[i]; + q->len += (uint32_t)put; + *n = put; + return E_OK; +} + +static int op_close(unsigned t, const struct href *h) +{ + if (!h || h->gen == 0 || h->slot >= NSLOTS) + return E_INVALID_ARG; + if (h->table != t) + return E_STALE; + struct slot *s = &M.tables[t].s[h->slot]; + if (!s->live || (s->gen != h->gen && !MUT(MUT_NO_GENERATION)) || (h->epoch != M.epoch && !MUT(MUT_NO_EPOCH))) + return E_STALE; + const struct pipe *q = &M.pipes[s->pipe]; + int stale = !q->live || q->inc != s->inc; + slot_release(t, h->slot); + return stale ? E_STALE : E_OK; +} + +static int op_dup(unsigned t, const struct href *h, unsigned to, unsigned rights, struct href *out) +{ + unsigned p, end; + unsigned need = to == t ? R_DERIVE : R_GRANT; + int e = resolve(t, h, need, -1, 0, &p, &end); + if (e) + return e; + unsigned dr = end == 0 ? R_READ : R_WRITE; + if (!(rights & dr) || (rights & ~(dr | R_CTL))) + return E_INVALID_ARG; + if ((rights & ~M.tables[t].s[h->slot].rights) && !MUT(MUT_DUP_NO_SUBSET)) + return E_DENIED; + int ns = slot_alloc(to, p, end, rights); + if (ns < 0) + return E_LIMIT; + out->table = to; + out->slot = (unsigned)ns; + out->gen = M.tables[to].s[ns].gen; + out->epoch = M.epoch; + return E_OK; +} + +static int op_revoke(unsigned t, const struct href *h) +{ + unsigned p, end; + int e = resolve(t, h, R_REVOKE, -1, 0, &p, &end); + if (e) + return e; + struct pipe *q = &M.pipes[p]; + q->revoked = 1; + q->latch[0] = q->latch[1] = 0; + { + memset(q->buf, 0, sizeof q->buf); + q->head = q->len = 0; + } + return E_OK; +} + +/* An interrupt aimed at the end h names (ST4.7). With nobody parked it is latched for the next call. */ +static int op_cancel(unsigned t, const struct href *h) +{ + unsigned p, end; + if (!h || h->table != t || h->slot >= NSLOTS || !M.tables[t].s[h->slot].live) + return resolve(t, h, 0, -1, 0, &p, &end); + unsigned need = M.tables[t].s[h->slot].end == 0 ? R_READ : R_WRITE; + int e = resolve(t, h, need, -1, 0, &p, &end); + if (e) + return e; + if (!MUT(MUT_NO_LATCH)) + M.pipes[p].latch[end] = 1; + return E_OK; +} + +/* ---------------- capabilities and bindings (ST5) ---------------- */ + +static struct cap *cname(const char *n) +{ + for (unsigned i = 0; i < M.ncaps; i++) + if (!strcmp(M.caps[i].name, n)) + return &M.caps[i]; + return 0; +} +static struct binding *bname(const char *n) +{ + for (unsigned i = 0; i < M.nb; i++) + if (!strcmp(M.b[i].name, n)) + return &M.b[i]; + return 0; +} + +/* steps 0 to 2: the shape of the binding (checked before any effect of a launch) */ +static int bind_shape(const struct binding *b) +{ + if (!b || b->none) + return E_DENIED; + if (b->domain != 1 && b->domain != 2) + return E_CAP_DOMAIN_MISMATCH; + if (b->domain == 1 && b->gen > 0xFFFFFFFFull && !MUT(MUT_GEN_TRUNCATE)) + return E_CAP_GEN_NARROW; + return E_OK; +} + +/* steps 3 to 6: against the authority, at the moment of the effect */ +static int bind_effect(const struct binding *b) +{ + int e = bind_shape(b); + if (e) + return e; + if (b->domain != M.domain && !MUT(MUT_DOMAIN_BRIDGE)) + return E_CAP_DOMAIN_MISMATCH; + uint64_t g = b->gen; + if (b->domain == 1) + g &= 0xFFFFFFFFull; /* only reachable under MUT_GEN_TRUNCATE: shape refused anything wider */ + for (unsigned i = 0; i < M.ncaps; i++) { + const struct cap *c = &M.caps[i]; + if (c->index != b->index) + continue; + int same = MUT(MUT_GEN_32BIT_COMPARE) ? (uint32_t)c->gen == (uint32_t)g : c->gen == g; + if (!same) + return E_STALE; + return c->revoked ? E_REVOKED : E_OK; + } + return E_STALE; +} + +/* ---------------- tasks ---------------- */ + +static void task_end(unsigned ti, int status, int outcome) +{ + struct task *k = &M.tasks[ti]; + k->state = T_ENDED; + k->status = status; + k->outcome = outcome; + if (!MUT(MUT_TASK_KEEPS_ENDS)) + for (unsigned i = 0; i < NSLOTS; i++) + slot_release(2 + ti, i); +} + +static struct href g_tmp; /* a handle into a task's own table */ +static const struct href *task_h(unsigned ti, int slot) +{ + const struct slot *s = &M.tables[2 + ti].s[slot]; + g_tmp.table = 2 + ti; + g_tmp.slot = (unsigned)slot; + g_tmp.gen = s->gen; + g_tmp.epoch = s->epoch; + return &g_tmp; +} + +/* Task output: to its stdout pipe, to the pipeline sink, or discarded. */ +static int task_out(unsigned ti, const uint8_t *b, size_t len, size_t *n) +{ + struct task *k = &M.tasks[ti]; + if (k->sink_virtual) { + struct pline *pl = &M.p[k->pipeline]; + size_t room = sizeof pl->sink - pl->sinklen, put = len < room ? len : room; + memcpy(pl->sink + pl->sinklen, b, put); + pl->sinklen += put; + *n = len; /* the sink never applies backpressure; overflow is a vector error caught by out= */ + return E_OK; + } + if (k->out_slot < 0) { + *n = len; + return E_OK; + } + return op_write(2 + ti, task_h(ti, k->out_slot), b, len, n); +} +static int task_in(unsigned ti, uint8_t *b, size_t max, size_t *n) +{ + struct task *k = &M.tasks[ti]; + *n = 0; + if (k->src_virtual) { + struct pline *pl = &M.p[k->pipeline]; + size_t take = pl->slen - pl->spos < max ? pl->slen - pl->spos : max; + memcpy(b, pl->src + pl->spos, take); + pl->spos += take; + *n = take; + return E_OK; + } + if (k->in_slot < 0) + return E_OK; + return op_read(2 + ti, task_h(ti, k->in_slot), b, max, n); +} + +/* One step of a running task. Returns 1 if it made progress. */ +static int task_step(unsigned ti) +{ + struct task *k = &M.tasks[ti]; + if (k->state != T_RUNNING) + return 0; + if (k->intr && k->prog != P_STUBBORN) { + k->intr = 0; + task_end(ti, 130, k->cancelled ? O_CANCELLED : O_COMPLETED); + return 1; + } + k->intr = 0; + size_t n = 0; + int e; + switch (k->prog) { + case P_EXIT: + task_end(ti, k->arg, O_COMPLETED); + return 1; + case P_EMIT: + case P_FLOOD: + if (k->prog == P_FLOOD && k->dpos == k->dlen) + k->dpos = 0; + if (k->dpos == k->dlen) { + task_end(ti, k->arg, O_COMPLETED); + return 1; + } + e = task_out(ti, k->data + k->dpos, k->dlen - k->dpos, &n); + if (e == E_BROKEN_PIPE) { + task_end(ti, 141, O_COMPLETED); + return 1; + } + if (e == E_INTERRUPTED) { + task_end(ti, 130, k->cancelled ? O_CANCELLED : O_COMPLETED); + return 1; + } + if (e != E_OK) + return 0; /* WOULD_BLOCK: parked */ + k->dpos += n; + return n > 0; + case P_CAT: + case P_DRAIN: + if (k->clen) { + e = task_out(ti, k->carry, k->clen, &n); + if (e == E_BROKEN_PIPE) { + task_end(ti, 141, O_COMPLETED); + return 1; + } + if (e != E_OK) + return 0; + memmove(k->carry, k->carry + n, k->clen - n); + k->clen -= n; + return n > 0; + } + e = task_in(ti, k->carry, sizeof k->carry, &n); + if (e == E_WOULD_BLOCK) + return 0; + if (e == E_INTERRUPTED) { + task_end(ti, 130, k->cancelled ? O_CANCELLED : O_COMPLETED); + return 1; + } + if (e != E_OK || n == 0) { + task_end(ti, e == E_OK ? 0 : 1, O_COMPLETED); + return 1; + } + k->clen = k->prog == P_CAT ? n : 0; + return 1; + case P_HANG: + case P_STUBBORN: + return 0; + } + return 0; +} + +static void sched_run(void) +{ + for (int round = 0; round < 100000; round++) { + int progress = 0; + for (unsigned i = 0; i < NTASKS; i++) + progress |= task_step(i); + if (!progress) + return; + } +} + +static void intent_close(unsigned ti) +{ + if (M.tasks[ti].intent_open) { + M.tasks[ti].intent_open = 0; + M.open_intents--; + } +} + +static void task_release(unsigned ti) +{ + intent_close(ti); + for (unsigned i = 0; i < NSLOTS; i++) + slot_release(2 + ti, i); + M.tasks[ti].state = T_FREE; +} + +static int task_cancel(unsigned ti, int terminate) +{ + struct task *k = &M.tasks[ti]; + if (k->state != T_RUNNING) + return E_OK; + k->cancelled = 1; + if (terminate && !MUT(MUT_TERMINATE_IGNORABLE)) { + task_end(ti, 137, O_CANCELLED); + return E_OK; + } + k->intr = 1; + return E_OK; +} + +/* ST6.5 cleanup of a set of tasks: interrupt, grace (the scheduler runs until nothing moves), terminate. */ +static void cleanup_tasks(const int *list, int n) +{ + for (int i = 0; i < n; i++) + if (list[i] >= 0) + task_cancel((unsigned)list[i], 0); + sched_run(); + for (int i = 0; i < n; i++) + if (list[i] >= 0) + task_cancel((unsigned)list[i], 1); +} + +static int parse_prog(char **tok, int ntok, struct task *k, int *consumed) +{ + const char *p = tok[0]; + *consumed = 1; + k->arg = 0; + k->dlen = k->dpos = 0; + if (!strcmp(p, "exit") || !strcmp(p, "emit")) { + if (!strcmp(p, "exit")) { + if (ntok < 2) + return -1; + k->prog = P_EXIT; + k->arg = atoi(tok[1]); + *consumed = 2; + return 0; + } + return -1; /* emit is handled by the caller (needs the byte decoder) */ + } + if (!strcmp(p, "cat")) k->prog = P_CAT; + else if (!strcmp(p, "drain")) k->prog = P_DRAIN; + else if (!strcmp(p, "flood")) { + k->prog = P_FLOOD; + memcpy(k->data, "y\n", 2); + k->dlen = 2; + } else if (!strcmp(p, "hang")) k->prog = P_HANG; + else if (!strcmp(p, "stubborn")) k->prog = P_STUBBORN; + else return -1; + return 0; +} + +/* ---------------- corpus parsing ---------------- */ + +static int unq(const char *q, uint8_t *out, size_t cap, size_t *n) +{ + size_t len = strlen(q), o = 0; + if (len < 2 || q[0] != '"' || q[len - 1] != '"') + return -1; + for (size_t i = 1; i + 1 < len; i++) { + unsigned c = (unsigned char)q[i]; + if (c == '\\') { + if (i + 2 >= len) return -1; + if (q[i + 1] == 'x') { + if (i + 4 >= len) return -1; + char hx[3] = {q[i + 2], q[i + 3], 0}; + c = (unsigned)strtoul(hx, 0, 16); + i += 3; + } else { + c = (unsigned char)q[i + 1]; + i++; + } + } + if (o == cap) return -1; + out[o++] = (uint8_t)c; + } + *n = o; + return 0; +} + +static void q_out(char *dst, size_t cap, const uint8_t *b, size_t n) +{ + size_t o = 0; + dst[o++] = '"'; + for (size_t i = 0; i < n && o + 6 < cap; i++) { + if (b[i] == '"' || b[i] == '\\') { + dst[o++] = '\\'; + dst[o++] = (char)b[i]; + } else if (b[i] < 0x20 || b[i] > 0x7E) { + o += (size_t)snprintf(dst + o, cap - o, "\\x%02x", b[i]); + } else { + dst[o++] = (char)b[i]; + } + } + dst[o++] = '"'; + dst[o] = 0; +} + +static int split(char *s, char **tok, int max) +{ + int n = 0; + while (*s) { + while (*s == ' ' || *s == '\t') s++; + if (!*s) break; + if (n == max) return -1; + tok[n++] = s; + int inq = 0; + while (*s && (inq || (*s != ' ' && *s != '\t'))) { + if (*s == '\\' && inq && s[1]) { s += 2; continue; } + if (*s == '"') inq = !inq; + s++; + } + if (*s) *s++ = 0; + } + return n; +} + +static unsigned tbl(const char *s) +{ + if (!strcmp(s, "A")) return 0; + if (!strcmp(s, "B")) return 1; + return 99; +} + +static unsigned rights_of(const char *s) +{ + unsigned r = 0; + for (; *s; s++) + switch (*s) { + case 'r': r |= R_READ; break; + case 'w': r |= R_WRITE; break; + case 'm': r |= R_MAP; break; + case 'g': r |= R_GRANT; break; + case 'd': r |= R_DERIVE; break; + case 'v': r |= R_REVOKE; break; + default: return 0x100; + } + return r; +} + +static struct tref *tname(const char *n, int create) +{ + for (unsigned i = 0; i < M.nt; i++) + if (!strcmp(M.t[i].name, n)) + return &M.t[i]; + if (!create || M.nt == NNAMES || strlen(n) >= sizeof M.t[0].name) + return 0; + struct tref *r = &M.t[M.nt++]; + memset(r, 0, sizeof *r); + strcpy(r->name, n); + return r; +} + +static int task_lookup(const struct tref *r, unsigned *ti) +{ + if (!r) return E_INVALID_ARG; + const struct task *k = &M.tasks[r->idx]; + if (k->state == T_FREE || k->gen != r->gen || (r->epoch != M.epoch && !MUT(MUT_NO_EPOCH))) + return E_STALE; + *ti = r->idx; + return E_OK; +} + +static int task_alloc(unsigned *ti) +{ + for (unsigned i = 0; i < NTASKS; i++) + if (M.tasks[i].state == T_FREE) { + uint32_t g = M.tasks[i].gen + 1; + memset(&M.tasks[i], 0, sizeof M.tasks[i]); + M.tasks[i].gen = g; + M.tasks[i].epoch = M.epoch; + M.tasks[i].in_slot = M.tasks[i].out_slot = -1; + M.tasks[i].pipeline = -1; + for (unsigned s = 0; s < NSLOTS; s++) + M.tables[2 + i].s[s].live = 0; + *ti = i; + return E_OK; + } + return E_LIMIT; +} + +/* give the task its own duplicate of a stream end (ST6.1) */ +static int task_take(unsigned ti, unsigned pipe, unsigned end) +{ + return slot_alloc(2 + ti, pipe, end, end == 0 ? R_READ : R_WRITE); +} + +static void list_out(char *dst, size_t cap, const int *v, int n, int outcomes) +{ + size_t o = 0; + dst[0] = 0; + for (int i = 0; i < n; i++) { + if (outcomes) + o += (size_t)snprintf(dst + o, cap - o, "%s%s", i ? "," : "", k_out[v[i]]); + else if (v[i] < 0) + o += (size_t)snprintf(dst + o, cap - o, "%s-", i ? "," : ""); + else + o += (size_t)snprintf(dst + o, cap - o, "%s%d", i ? "," : "", v[i]); + } +} + +static struct pline *pname(const char *n, int create) +{ + for (unsigned i = 0; i < M.np; i++) + if (!strcmp(M.p[i].name, n)) + return &M.p[i]; + if (!create || M.np == 4 || strlen(n) >= sizeof M.p[0].name) + return 0; + struct pline *r = &M.p[M.np++]; + memset(r, 0, sizeof *r); + strcpy(r->name, n); + return r; +} + +static void pl_result(char *res, size_t cap, struct pline *pl, int err, int status) +{ + char st[128], oc[256]; + list_out(st, sizeof st, pl->status, pl->n, 0); + list_out(oc, sizeof oc, pl->outcome, pl->n, 1); + snprintf(res, cap, "%s status=%d outcomes=%s statuses=%s", k_err[err], status, oc, st); +} + +/* launch P bind=B [in=Q] [inject=K:ERR] [revoke=K:CAP] : stage ! stage ... (ST7) */ +static void cmd_launch(char **tok, int n, char *res, size_t cap) +{ + struct pline *pl = pname(tok[1], 1); + if (!pl) { bad("too many pipelines"); return; } + pl->live = 1; + pl->epoch = M.epoch; + pl->slen = pl->spos = pl->sinklen = 0; + const struct binding *b = 0; + int inject_at = 0, inject_err = 0, revoke_at = 0; + struct cap *rc = 0; + int i = 2; + for (; i < n && strcmp(tok[i], ":"); i++) { + if (!strncmp(tok[i], "bind=", 5)) { + b = bname(tok[i] + 5); + if (!b) { bad("unknown binding"); return; } + } else if (!strncmp(tok[i], "in=", 3)) { + if (unq(tok[i] + 3, pl->src, sizeof pl->src, &pl->slen)) { bad("bad in="); return; } + } else if (!strncmp(tok[i], "inject=", 7)) { + inject_at = atoi(tok[i] + 7); + const char *c = strchr(tok[i], ':'); + for (int e = 0; c && e < E_COUNT; e++) + if (!strcmp(c + 1, k_err[e])) inject_err = e; + if (!c || !inject_err) { bad("bad inject="); return; } + } else if (!strncmp(tok[i], "revoke=", 7)) { + revoke_at = atoi(tok[i] + 7); + const char *c = strchr(tok[i], ':'); + rc = c ? cname(c + 1) : 0; + if (!rc) { bad("bad revoke="); return; } + } else { bad("unknown launch option"); return; } + } + if (i >= n) { bad("launch needs ':'"); return; } + /* stages */ + struct task proto[MAXSTAGES + 2]; + int kind[MAXSTAGES + 2]; /* 0 program, 1 nosuch, 2 foreign */ + int ns = 0; + i++; + while (i < n) { + if (ns == MAXSTAGES + 2) { bad("too many stages"); return; } + memset(&proto[ns], 0, sizeof proto[ns]); + kind[ns] = 0; + int used = 1; + if (!strcmp(tok[i], "nosuch")) kind[ns] = 1; + else if (!strcmp(tok[i], "foreign")) kind[ns] = 2; + else if (!strcmp(tok[i], "emit")) { + if (i + 1 >= n || unq(tok[i + 1], proto[ns].data, sizeof proto[ns].data, &proto[ns].dlen)) { bad("emit"); return; } + proto[ns].prog = P_EMIT; + used = 2; + if (i + 2 < n && strcmp(tok[i + 2], "!")) { proto[ns].arg = atoi(tok[i + 2]); used = 3; } + } else if (parse_prog(tok + i, n - i, &proto[ns], &used)) { bad("unknown program"); return; } + i += used; + ns++; + if (i < n) { + if (strcmp(tok[i], "!")) { bad("stages are separated by '!'"); return; } + i++; + } + } + pl->n = ns > MAXSTAGES ? MAXSTAGES : ns; + for (int s = 0; s < MAXSTAGES; s++) { + pl->task[s] = -1; + pl->outcome[s] = O_FAILED_NO_EFFECT; + pl->status[s] = -1; + } + /* steps 1 to 3: no effect yet; a refusal starts nothing */ + int pre = E_OK, pst = 1; + if (ns > MAXSTAGES) pre = E_LIMIT, pst = 1; + for (int s = 0; !pre && s < ns; s++) + if (kind[s] == 2) pre = E_UNAVAILABLE, pst = 126; + if (!pre && (pre = bind_shape(b)) != E_OK) pst = 126; + /* step 4: all pipes */ + int pp[MAXSTAGES][2]; + struct href ph[MAXSTAGES][2]; + for (int s = 0; s < MAXSTAGES; s++) pp[s][0] = pp[s][1] = -1; + for (int s = 0; !pre && s + 1 < ns; s++) { + memset(ph[s], 0, sizeof ph[s]); + if (op_create(0, &ph[s][0], &ph[s][1]) != E_OK) { + pre = E_LIMIT, pst = 1; + for (int u = 0; u <= s; u++) { + if (pp[u][0] >= 0) op_close(0, &ph[u][0]); + if (pp[u][1] >= 0) op_close(0, &ph[u][1]); + } + break; + } + pp[s][0] = 1; + pp[s][1] = 1; + } + if (pre) { + for (int s = 0; s < pl->n; s++) pl->status[s] = pst; + pl_result(res, cap, pl, pre, pst); + pl->live = 0; + return; + } + /* step 5 and 6: start left to right */ + int started = 0, fail = 0, fail_err = 0; + int bind_once = MUT(MUT_BIND_ONCE) ? bind_effect(b) : 0; + for (int s = 0; s < ns; s++) { + if (revoke_at == s + 1) rc->revoked = 1; + int st_e = E_OK, st_status = 0; + if (kind[s] == 1) st_e = E_NOT_FOUND, st_status = 127; + else { + int be = MUT(MUT_BIND_ONCE) ? bind_once : bind_effect(b); + if (be) st_e = be, st_status = 126; + } + if (st_e && MUT(MUT_STAGE_FAIL_ABORTS)) { fail = s + 1; fail_err = st_e; break; } + if (!st_e && inject_at == s + 1) { fail = s + 1; fail_err = inject_err; break; } + if (st_e) { + pl->outcome[s] = O_FAILED_NO_EFFECT; + pl->status[s] = st_status; + } else { + unsigned ti; + if (task_alloc(&ti)) { fail = s + 1; fail_err = E_LIMIT; break; } + struct task *k = &M.tasks[ti]; + uint32_t g = k->gen; + *k = proto[s]; + k->gen = g; + k->epoch = M.epoch; + k->state = T_RUNNING; + k->pipeline = (int)(pl - M.p); + k->in_slot = k->out_slot = -1; + if (s == 0) k->src_virtual = 1; + else k->in_slot = task_take(ti, M.tables[0].s[ph[s - 1][0].slot].pipe, 0); + if (s == ns - 1) k->sink_virtual = 1; + else k->out_slot = task_take(ti, M.tables[0].s[ph[s][1].slot].pipe, 1); + k->intent_open = 1; + M.open_intents++; + pl->task[s] = (int)ti; + pl->outcome[s] = O_COMPLETED; + started++; + } + /* the adapter closes its own copies of this stage's ends right after starting (or failing) it */ + if (s > 0 && pp[s - 1][0] >= 0) { op_close(0, &ph[s - 1][0]); pp[s - 1][0] = -1; } + if (s + 1 < ns && pp[s][1] >= 0) { op_close(0, &ph[s][1]); pp[s][1] = -1; } + } + if (fail) { + for (int u = 0; u + 1 < ns; u++) + for (int e = 0; e < 2; e++) + if (pp[u][e] >= 0) { op_close(0, &ph[u][e]); pp[u][e] = -1; } + pl->outcome[fail - 1] = O_FAILED_NO_EFFECT; + pl->status[fail - 1] = 1; + for (int s = fail; s < ns; s++) { pl->outcome[s] = O_NOT_STARTED; pl->status[s] = -1; } + if (started == 0) { + pl_result(res, cap, pl, fail_err, 1); + pl->live = 0; + return; + } + if (!MUT(MUT_PARTIAL_NO_CANCEL)) { + cleanup_tasks(pl->task, fail - 1); + for (int s = 0; s < fail - 1; s++) { + if (pl->task[s] < 0) continue; + unsigned ti = (unsigned)pl->task[s]; + pl->outcome[s] = O_CANCELLED; + pl->status[s] = M.tasks[ti].status; + task_release(ti); + pl->task[s] = -1; + } + } + pl_result(res, cap, pl, E_PARTIAL_LAUNCH, 1); + if (!MUT(MUT_PARTIAL_NO_CANCEL)) pl->live = 0; + return; + } + snprintf(res, cap, "OK"); +} + +static void cmd_waitp(struct pline *pl, char *res, size_t cap) +{ + if (!pl || !pl->live || (pl->epoch != M.epoch && !MUT(MUT_NO_EPOCH))) { snprintf(res, cap, "STALE"); return; } + for (int s = 0; s < pl->n; s++) + if (pl->task[s] >= 0 && M.tasks[pl->task[s]].state == T_RUNNING) { snprintf(res, cap, "WOULD_BLOCK"); return; } + for (int s = 0; s < pl->n; s++) { + if (pl->task[s] < 0) continue; + unsigned ti = (unsigned)pl->task[s]; + pl->outcome[s] = M.tasks[ti].outcome; + pl->status[s] = M.tasks[ti].status; + task_release(ti); + pl->task[s] = -1; + } + char base[512], out[1024]; + int last = pl->status[pl->n - 1]; + pl_result(base, sizeof base, pl, E_OK, last < 0 ? 1 : last); + q_out(out, sizeof out, pl->sink, pl->sinklen); + snprintf(res, cap, "%s out=%s", base, out); + pl->live = 0; +} + +/* ---------------- one vector file ---------------- */ + +static void exec_line(char **tok, int n, char *res, size_t cap) +{ + static uint8_t bufs[2][CAP_BYTES * 2]; /* one per nesting level: a peer action runs inside bread / bwrite */ + static int depth; + if (depth > 1) { bad("a peer action cannot block"); return; } + uint8_t *buf = bufs[depth]; + const size_t bufcap = sizeof bufs[0]; + const char *c = tok[0]; + size_t got = 0; + int e; + res[0] = 0; +#define NEED(k) do { if (n < (k)) { bad("missing argument"); return; } } while (0) + if (!strcmp(c, "create")) { + NEED(4); + unsigned t = tbl(tok[3]); + if (t > 1) { bad("table"); return; } + struct href *r = hname(tok[1], 1), *w = hname(tok[2], 1); + if (!r || !w) { bad("names"); return; } + struct href nr = *r, nw = *w; + e = op_create(t, &nr, &nw); + if (!e) { *r = nr; *w = nw; } + snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "write") || !strcmp(c, "fill") || !strcmp(c, "bwrite")) { + NEED(3); + struct href *h = hname(tok[1], 0); + size_t len = 0; + if (!strcmp(c, "fill")) { + NEED(4); + len = !strcmp(tok[2], "cap") ? CAP_BYTES : strtoul(tok[2], 0, 10); + if (len > bufcap) { bad("fill"); return; } + memset(buf, (int)strtoul(tok[3], 0, 16), len); + } else if (unq(tok[2], buf, bufcap, &len)) { bad("bytes"); return; } + unsigned t = h ? h->table : 0; + e = op_write(t, h, buf, len, &got); + if (!strcmp(c, "bwrite")) { + NEED(4); + if (e == E_WOULD_BLOCK) { + if (strcmp(tok[3], "none")) { + char pr[256]; + depth++; + exec_line(tok + 3, n - 3, pr, sizeof pr); + depth--; + if (strncmp(pr, "OK", 2)) { bad("peer action did not return OK"); return; } + } + e = op_write(t, h, buf, len, &got); + if (e == E_WOULD_BLOCK) e = E_INTERRUPTED; /* stalled peer: the deadline stand-in */ + } + } + if (e == E_OK) snprintf(res, cap, "OK n=%zu", got); + else snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "read") || !strcmp(c, "bread") || !strcmp(c, "skim")) { + NEED(3); + struct href *h = hname(tok[1], 0); + size_t max = strtoul(tok[2], 0, 10); + if (max > bufcap) { bad("max"); return; } + unsigned t = h ? h->table : 0; + e = op_read(t, h, buf, max, &got); + if (!strcmp(c, "bread")) { + NEED(4); + if (e == E_WOULD_BLOCK) { + if (strcmp(tok[3], "none")) { + char pr[256]; + depth++; + exec_line(tok + 3, n - 3, pr, sizeof pr); + depth--; + if (strncmp(pr, "OK", 2)) { bad("peer action did not return OK"); return; } + } + e = op_read(t, h, buf, max, &got); + if (e == E_WOULD_BLOCK) e = E_INTERRUPTED; + } + } + if (e == E_OK && got && !strcmp(c, "skim")) snprintf(res, cap, "OK n=%zu", got); + else if (e == E_OK && got) { + static char q[CAP_BYTES * 8]; + q_out(q, sizeof q, buf, got); + snprintf(res, cap, "OK n=%zu data=%s", got, q); + } else if (e == E_OK) snprintf(res, cap, "OK n=0"); + else snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "close") || !strcmp(c, "revoke") || !strcmp(c, "cancel")) { + NEED(2); + struct href *h = hname(tok[1], 0); + unsigned t = h ? h->table : 0; + e = !strcmp(c, "close") ? op_close(t, h) : !strcmp(c, "revoke") ? op_revoke(t, h) : op_cancel(t, h); + snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "dup")) { + NEED(5); + struct href *h = hname(tok[1], 0), *o = hname(tok[2], 1); + unsigned to = tbl(tok[3]), r = rights_of(tok[4]); + if (!o || to > 1 || r > 0xFF) { bad("dup"); return; } + struct href no = *o; + e = op_dup(h ? h->table : 0, h, to, r, &no); + if (!e) *o = no; + snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "release") || !strcmp(c, "sweep")) { + /* section 12 cleanup of one table; `sweep` is the same without the adapter-specific count */ + NEED(2); + unsigned t = tbl(tok[1]), k = 0; + if (t > 1) { bad("table"); return; } + for (unsigned i = 0; i < NSLOTS; i++) + if (M.tables[t].s[i].live) { slot_release(t, i); k++; } + if (!strcmp(c, "sweep")) snprintf(res, cap, "OK"); + else snprintf(res, cap, "OK n=%u", k); + } else if (!strcmp(c, "saturate")) { + /* saturate H T last=D: duplicate H (its data right only) into T until LIMIT; D names the last duplicate */ + NEED(4); + struct href *h = hname(tok[1], 0), *d = strncmp(tok[3], "last=", 5) ? 0 : hname(tok[3] + 5, 1); + unsigned to = tbl(tok[2]); + if (!h || !d || to > 1 || !M.tables[h->table].s[h->slot].live) { bad("saturate"); return; } + unsigned dr = M.tables[h->table].s[h->slot].end == 0 ? R_READ : R_WRITE; + struct href nd; + int made = 0; + for (;;) { + nd = *d; /* keeps the name */ + e = op_dup(h->table, h, to, dr, &nd); + if (e) break; + *d = nd; + made = 1; + } + if (!made) { bad("saturate made no duplicate"); return; } + snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "exhaust")) { + NEED(3); + unsigned t = tbl(tok[1]); + unsigned min = (unsigned)strtoul(tok[2] + (strncmp(tok[2], "min=", 4) ? 0 : 4), 0, 10); + struct href rr[NPIPES + 1], ww[NPIPES + 1]; + unsigned k = 0, before = 0; + for (unsigned i = 0; i < NSLOTS; i++) before += (unsigned)M.tables[t].s[i].live; + int last = E_OK; + while (k <= NPIPES) { + memset(&rr[k], 0, sizeof rr[k]); + memset(&ww[k], 0, sizeof ww[k]); + last = op_create(t, &rr[k], &ww[k]); + if (last) break; + k++; + } + unsigned live_slots = 0; + for (unsigned i = 0; i < NSLOTS; i++) live_slots += (unsigned)M.tables[t].s[i].live; + int leak = live_slots != before + 2 * k; /* the refused create left nothing allocated (ST9) */ + for (unsigned i = 0; i < k; i++) { op_close(t, &rr[i]); op_close(t, &ww[i]); } + if (k < min) snprintf(res, cap, "TOO_FEW n=%u", k); + else if (leak) snprintf(res, cap, "LEAK"); + else snprintf(res, cap, "%s", k_err[last]); + } else if (!strcmp(c, "frame")) { + NEED(3); + unsigned t = tbl(tok[1]); + uint64_t f[16]; + size_t nc = 0, slen = 0; + int has = strcmp(tok[2], "-") != 0; + if (has && unq(tok[2], buf, bufcap, &slen)) { bad("slice"); return; } + for (int i = 3; i < n; i++) { + if (nc == 16) { bad("frame too long"); return; } + if (tok[i][0] == '$') { + struct href *h = hname(tok[i] + 1, 0); + f[nc++] = h ? ((uint64_t)h->gen << 32 | (h->slot + 1)) : 0; + } else f[nc++] = strtoull(tok[i], 0, 16); + } + static const unsigned nargs[6] = {0, 0, 2, 2, 1, 3}; + int ef; + if (nc < 4 || f[0] != FRAME_MAGIC) ef = E_INVALID_ARG; + else if (f[1] != 1 && !MUT(MUT_FRAME_VERSION)) ef = E_NOT_SUPPORTED; + else if (f[3] != 0 && !MUT(MUT_FRAME_RESERVED)) ef = E_INVALID_ARG; + else if (f[2] == 0 || f[2] > 5) ef = E_NOT_SUPPORTED; /* 6 to 15 are assigned but not in this model */ + else { + unsigned op = (unsigned)f[2]; + struct href fh; + memset(&fh, 0, sizeof fh); + if (op != 1 && nc > 4) { + fh.table = t; + fh.gen = (uint32_t)(f[4] >> 32); + fh.slot = (unsigned)(f[4] & 0xFFFFFFFFu) - 1u; + fh.epoch = M.epoch; + for (unsigned i = 0; i < M.nh; i++) /* the cell carries no epoch; the model's names do */ + if (M.h[i].table == t && M.h[i].slot == fh.slot && M.h[i].gen == fh.gen) fh.epoch = M.h[i].epoch; + } + if (nc != 4 + nargs[op] || (op != 1 && fh.gen == 0)) ef = E_INVALID_ARG; + else if (op == 1) { + struct href a, b; + memset(&a, 0, sizeof a); + memset(&b, 0, sizeof b); + ef = op_create(t, &a, &b); + /* the new ends are unnamed: a vector releases them with `release` */ + } else if (op == 2 || op == 3) { + if (f[5] & ~1ull) ef = E_INVALID_ARG; + else ef = op == 2 ? op_read(t, &fh, buf, slen, &got) : op_write(t, &fh, buf, slen, &got); + } else if (op == 4) ef = op_close(t, &fh); + else { + if ((f[5] & ~0x3Full) || f[6] > 1) ef = E_INVALID_ARG; + else { + struct href o; + memset(&o, 0, sizeof o); + ef = op_dup(t, &fh, f[6] ? 1 - t : t, (unsigned)f[5], &o); + if (!ef) { /* register the anonymous handle so `release` can clean it */ } + } + } + } + if (ef == E_OK && (f[2] == 2 || f[2] == 3)) snprintf(res, cap, "OK n=%zu", got); + else snprintf(res, cap, "%s", k_err[ef]); + } else if (!strcmp(c, "cap")) { + NEED(2); + if (M.ncaps == 16 || M.domain == 0) { bad("cap needs a domain header"); return; } + struct cap *k = &M.caps[M.ncaps]; + memset(k, 0, sizeof *k); + snprintf(k->name, sizeof k->name, "%s", tok[1]); + k->index = 3 + M.ncaps; + k->gen = M.domain == 1 ? 7 : 0x100000007ull; + for (int i = 2; i < n; i++) + if (!strncmp(tok[i], "gen=", 4)) k->gen = strtoull(tok[i] + 4, 0, 0); + if (M.domain == 1 && k->gen > 0xFFFFFFFFull) { bad("domain-1 authority cannot mint a 64-bit generation"); return; } + M.ncaps++; + snprintf(res, cap, "OK"); + } else if (!strcmp(c, "revokecap")) { + NEED(2); + struct cap *k = cname(tok[1]); + if (!k) { bad("cap"); return; } + k->revoked = 1; + snprintf(res, cap, "OK"); + } else if (!strcmp(c, "bind")) { + NEED(3); + if (M.nb == 16) { bad("bindings"); return; } + struct binding *b = &M.b[M.nb]; + memset(b, 0, sizeof *b); + snprintf(b->name, sizeof b->name, "%s", tok[1]); + if (!strcmp(tok[2], "none")) b->none = 1; + else { + if (strncmp(tok[2], "cap=", 4) || !cname(tok[2] + 4)) { bad("bind cap="); return; } + const struct cap *k = cname(tok[2] + 4); + b->domain = M.domain; + b->index = k->index; + b->gen = k->gen; + for (int i = 3; i < n; i++) { + if (!strncmp(tok[i], "gen=", 4)) b->gen = strtoull(tok[i] + 4, 0, 0); + else if (!strncmp(tok[i], "domain=", 7)) b->domain = (unsigned)strtoul(tok[i] + 7, 0, 0); + else if (!strncmp(tok[i], "index=", 6)) b->index = (unsigned)strtoul(tok[i] + 6, 0, 0); + else { bad("bind option"); return; } + } + } + M.nb++; + snprintf(res, cap, "OK"); + } else if (!strcmp(c, "spawn")) { + /* spawn T [in=H|-] [out=H|-] bind=B */ + NEED(4); + struct tref *r = tname(tok[1], 1); + struct task proto; + memset(&proto, 0, sizeof proto); + int i = 2, used = 1; + if (!strcmp(tok[2], "emit")) { + if (unq(tok[3], proto.data, sizeof proto.data, &proto.dlen)) { bad("emit"); return; } + proto.prog = P_EMIT; + used = 2; + } else if (parse_prog(tok + 2, n - 2, &proto, &used)) { bad("program"); return; } + i += used; + struct href *in = 0, *out = 0; + const struct binding *b = 0; + for (; i < n; i++) { + if (!strncmp(tok[i], "in=", 3)) in = strcmp(tok[i] + 3, "-") ? hname(tok[i] + 3, 0) : 0; + else if (!strncmp(tok[i], "out=", 4)) out = strcmp(tok[i] + 4, "-") ? hname(tok[i] + 4, 0) : 0; + else if (!strncmp(tok[i], "bind=", 5)) b = bname(tok[i] + 5); + else { bad("spawn option"); return; } + } + if (!r) { bad("task name"); return; } + unsigned ip = 0, ie = 0, op = 0, oe = 0; + e = E_OK; + if (in) { + e = resolve(in->table, in, 0, -1, 0, &ip, &ie); /* the end decides, ST6.1 */ + if (!e && ie != 0) e = E_INVALID_ARG; + } + if (!e && out) { + e = resolve(out->table, out, 0, -1, 0, &op, &oe); + if (!e && oe != 1) e = E_INVALID_ARG; + } + if (!e) e = bind_effect(b); + unsigned ti = 0; + if (!e) e = task_alloc(&ti); + if (!e) { + struct task *k = &M.tasks[ti]; + uint32_t g = k->gen; + *k = proto; + k->gen = g; + k->epoch = M.epoch; + k->state = T_RUNNING; + k->pipeline = -1; + k->in_slot = in ? task_take(ti, ip, 0) : -1; + k->out_slot = out ? task_take(ti, op, 1) : -1; + k->intent_open = 1; + M.open_intents++; + r->idx = ti; + r->gen = g; + r->epoch = M.epoch; + } + snprintf(res, cap, "%s", k_err[e]); + } else if (!strcmp(c, "run")) { + sched_run(); + snprintf(res, cap, "OK"); + } else if (!strcmp(c, "wait") || !strcmp(c, "state") || !strcmp(c, "tcancel") || !strcmp(c, "lose")) { + NEED(2); + unsigned ti; + e = task_lookup(tname(tok[1], 0), &ti); + if (e) { snprintf(res, cap, "%s", k_err[e]); return; } + struct task *k = &M.tasks[ti]; + if (!strcmp(c, "state")) snprintf(res, cap, "OK state=%s", k->state == T_RUNNING ? "RUNNING" : "ENDED"); + else if (!strcmp(c, "tcancel")) { + NEED(3); + snprintf(res, cap, "%s", k_err[task_cancel(ti, !strcmp(tok[2], "terminate"))]); + } else if (!strcmp(c, "lose")) { + if (k->state != T_ENDED) { bad("lose needs an ended task"); return; } + k->lost = 1; + snprintf(res, cap, "OK"); + } else if (k->state == T_RUNNING) snprintf(res, cap, "WOULD_BLOCK"); + else if (k->lost) { + snprintf(res, cap, "OUTCOME_UNKNOWN status=1 outcome=OUTCOME_UNKNOWN"); + task_release(ti); + } else { + snprintf(res, cap, "OK status=%d outcome=%s", k->status, k_out[k->outcome]); + if (!MUT(MUT_WAIT_NO_RELEASE)) task_release(ti); + } + } else if (!strcmp(c, "launch")) { + NEED(4); + cmd_launch(tok, n, res, cap); + } else if (!strcmp(c, "waitp")) { + NEED(2); + cmd_waitp(pname(tok[1], 0), res, cap); + } else if (!strcmp(c, "cancelp")) { + NEED(3); + struct pline *pl = pname(tok[1], 0); + if (!pl || !pl->live) { snprintf(res, cap, "STALE"); return; } + for (int s = 0; s < pl->n; s++) + if (pl->task[s] >= 0) task_cancel((unsigned)pl->task[s], !strcmp(tok[2], "terminate")); + snprintf(res, cap, "OK"); + } else if (!strcmp(c, "reset")) { + /* ABI section 12 cleanup, then a new session_epoch */ + int list[NTASKS], k = 0; + for (unsigned i = 0; i < NTASKS; i++) + list[i] = M.tasks[i].state == T_RUNNING ? (k++, (int)i) : -1; + cleanup_tasks(list, NTASKS); + for (unsigned i = 0; i < NTASKS; i++) + if (M.tasks[i].state != T_FREE) task_release(i); + for (unsigned t = 0; t < 2; t++) + for (unsigned i = 0; i < NSLOTS; i++) slot_release(t, i); + for (unsigned i = 0; i < M.np; i++) M.p[i].live = 0; + M.epoch++; + snprintf(res, cap, "OK cancelled=%d", k); + } else if (!strcmp(c, "crash")) { + /* the adapter process is gone: nothing is cleaned, nothing records an outcome; its tables restart empty */ + M.crashed_unknown = M.open_intents; + for (unsigned i = 0; i < NTASKS; i++) M.tasks[i].state = T_FREE, M.tasks[i].intent_open = 0; + for (unsigned t = 0; t < NTABLES; t++) memset(&M.tables[t], 0, sizeof M.tables[t]); + for (unsigned i = 0; i < NPIPES; i++) { + uint32_t inc = M.pipes[i].inc; + memset(&M.pipes[i], 0, sizeof M.pipes[i]); + M.pipes[i].inc = inc; + } + for (unsigned i = 0; i < M.np; i++) M.p[i].live = 0; + M.open_intents = 0; + M.epoch++; + snprintf(res, cap, "OK"); + } else if (!strcmp(c, "recover")) { + snprintf(res, cap, "OK unknown=%u replayed=%u", MUT(MUT_CRASH_REPLAY) ? 0 : M.crashed_unknown, + MUT(MUT_CRASH_REPLAY) ? M.crashed_unknown : 0); + M.crashed_unknown = 0; + } else if (!strcmp(c, "limits")) { + snprintf(res, cap, "OK max_pipe_bytes>=65536 max_streams>=16 max_tasks>=8"); + if (!(CAP_BYTES >= 65536 && NSLOTS >= 16 && NTASKS >= 8)) snprintf(res, cap, "LIMIT"); + } else { + bad("unknown command"); + } +#undef NEED +} + +static int check_items(char **tok, int n) +{ + for (int i = 1; i < n; i++) { + if (!strcmp(tok[i], "empty")) { + for (unsigned t = 0; t < NTABLES; t++) + for (unsigned s = 0; s < NSLOTS; s++) + if (M.tables[t].s[s].live) return 0; + for (unsigned p = 0; p < NPIPES; p++) + if (M.pipes[p].live) return 0; + for (unsigned k = 0; k < NTASKS; k++) + if (M.tasks[k].state != T_FREE) return 0; + if (M.open_intents || M.crashed_unknown) return 0; + } else if (!strncmp(tok[i], "pipes=", 6)) { + unsigned live = 0; + for (unsigned p = 0; p < NPIPES; p++) live += (unsigned)M.pipes[p].live; + if (live != strtoul(tok[i] + 6, 0, 10)) return 0; + } else { + bad("unknown check item"); + return 0; + } + } + return 1; +} + +static int run_file(const char *path, const char *base, int *nfail) +{ + FILE *f = fopen(path, "r"); + if (!f) { fprintf(stderr, "cannot open %s\n", path); return 1; } + model_reset(); + g_file = base; + g_line = 0; + g_fail = 0; + static char line[4096]; + char res[CAP_BYTES * 8 + 64]; + int have_case = 0, have_kind = 0, have_exec = 0, have_needs = 0, have_domain = 0, last_check_empty = 0, mism = 0; + while (fgets(line, sizeof line, f)) { + g_line++; + size_t L = strlen(line); + while (L && (line[L - 1] == '\n' || line[L - 1] == '\r')) line[--L] = 0; + char *s = line; + while (*s == ' ') s++; + if (!*s || *s == '#') continue; + char *arrow = strstr(s, " => "); + char *want = 0; + if (arrow) { *arrow = 0; want = arrow + 4; } + char *tok[64]; + int n = split(s, tok, 64); + if (n <= 0) { bad("cannot split"); continue; } + if (!strcmp(tok[0], "case")) { have_case = 1; continue; } + if (!strcmp(tok[0], "kind")) { have_kind = n == 2 && (!strcmp(tok[1], "positive") || !strcmp(tok[1], "negative")); continue; } + if (!strcmp(tok[0], "exec")) { have_exec = n == 2 && (!strcmp(tok[1], "host-logic") || !strcmp(tok[1], "native-qemu")); continue; } + if (!strcmp(tok[0], "needs")) { have_needs = n >= 2; continue; } + if (!strcmp(tok[0], "domain")) { + have_domain = n == 2; + M.domain = !strcmp(tok[1], "any") ? 0 : (unsigned)atoi(tok[1]); + continue; + } + if (!have_case || !have_kind || !have_exec || !have_needs || !have_domain) { bad("header incomplete before first step"); break; } + if (!strcmp(tok[0], "check")) { + last_check_empty = 0; + for (int i = 1; i < n; i++) last_check_empty |= !strcmp(tok[i], "empty"); + if (!check_items(tok, n)) { + printf("MISMATCH %s:%u check failed\n", base, g_line); + mism = 1; + } + continue; + } + last_check_empty = 0; + if (!want) { bad("step without ' => '"); continue; } + exec_line(tok, n, res, sizeof res); + if (strcmp(res, want)) { + printf("MISMATCH %s:%u got \"%.200s\" want \"%.200s\"\n", base, g_line, res, want); + mism = 1; + } + } + fclose(f); + if (!last_check_empty) bad("a vector must end with 'check empty'"); + if (g_fail || mism) { (*nfail)++; return 1; } + printf("PASS %s\n", base); + return 0; +} + +static int cmpstr(const void *a, const void *b) { return strcmp(*(char *const *)a, *(char *const *)b); } + +int main(int argc, char **argv) +{ + const char *dir = 0, *corpus_pin = "unpinned", *tc_pin = "unpinned"; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--corpus") && i + 1 < argc) dir = argv[++i]; + else if (!strcmp(argv[i], "--pin") && i + 1 < argc) { + const char *p = argv[++i]; + if (!strncmp(p, "corpus=", 7)) corpus_pin = p + 7; + else if (!strncmp(p, "toolchain=", 10)) tc_pin = p + 10; + } else { fprintf(stderr, "usage: osh_sv_ref --corpus DIR [--pin corpus=SHA] [--pin toolchain=TEXT]\n"); return 2; } + } + if (!dir) { fprintf(stderr, "usage: osh_sv_ref --corpus DIR\n"); return 2; } + DIR *d = opendir(dir); + if (!d) { fprintf(stderr, "cannot open %s\n", dir); return 2; } + char *names[256]; + int nn = 0; + struct dirent *de; + while ((de = readdir(d)) && nn < 256) { + size_t L = strlen(de->d_name); + if (L > 4 && (de->d_name[0] == 's' || de->d_name[0] == 't') && !strcmp(de->d_name + L - 4, ".vec")) + names[nn++] = strdup(de->d_name); + } + closedir(d); + qsort(names, (size_t)nn, sizeof names[0], cmpstr); + printf("OSHSV1_RUN impl=reference-model mutant=%d corpus=%s toolchain=%s target=host\n", SV_MUTANT, corpus_pin, tc_pin); + int nfail = 0; + for (int i = 0; i < nn; i++) { + char path[4096]; + snprintf(path, sizeof path, "%s/%s", dir, names[i]); + run_file(path, names[i], &nfail); + free(names[i]); + } + printf("OSHSV1_CONFORMANCE impl=reference-model vectors=%d pass=%d fail=%d not_run=0\n", nn, nn - nfail, nfail); + return nn > 0 && nfail == 0 ? 0 : 1; +} diff --git a/specs/osh-platform/vectors/README.md b/specs/osh-platform/vectors/README.md index 094a25f..4c708be 100644 --- a/specs/osh-platform/vectors/README.md +++ b/specs/osh-platform/vectors/README.md @@ -23,3 +23,67 @@ The harness never executes pipelines. After each `PIPELINE_READY` it records the - `more` means the final call returned `NEED_MORE_INPUT` with no further input available. - `lex_resumes=N` is the exact number of `BUDGET_EXHAUSTED` returns the lexer gave before `PHASE_DONE`. - A core conforms when every line matches byte for byte. Refusal offsets follow spec section 5.4. + +## Stream and task vectors (`sNNN_.vec`, `tNNN_.vec`) + +Status: v1 DRAFT revision 2, with [`../STREAM_TASK.md`](../STREAM_TASK.md). Shared by every adapter (Omega's Linux host adapter, the AIENOS native harness). The `vNNN` shell-core vectors above are unchanged; `tools/check-stream-vectors.sh` regenerates them and fails if they differ. The grammar is the AIENOS native pipe fixture grammar (aienos-mv `native/kernel/tests/fixtures/pipe/README.md` at `f8700d4cb65e`, written so the corpus could move here) with its kernel-only counters removed and task, launch, authority and recovery commands added. `` is the quoted byte string of `expected.txt` (`\xHH`, `\"`, `\\`; spaces may appear inside the quotes). Checked by `tools/osh_sv_ref.c` (reference model) through `tools/check-stream-vectors.sh`, which also proves with `tools/mutate-stream-ref.sh` that every check of the model is caught by some vector. + +### Header (all required, before the first step) + +| line | meaning | +|---|---| +| `case ` | the file is `sNNN_.vec` (streams) or `tNNN_.vec` (tasks) | +| `kind positive\|negative` | negative: the vector contains refusals or failures | +| `exec host-logic\|native-qemu` | `host-logic`: a host unit run of the adapter's own logic counts as evidence. `native-qemu`: it parks callers, starts tasks or runs them concurrently; AIENOS evidence only from a native run under QEMU, Omega evidence only from real Linux processes | +| `domain 1\|2\|any` | authority domain of the vector's capabilities (ST5); an adapter without that domain reports `NOT_RUN` | +| `needs ...` | `streams`, `frames`, `tasks`, `launch`, `journal` (crash and recovery), `reset`, `test-authority` (the harness can mint and revoke capabilities with chosen generations), `fault-spawn` (make a chosen spawn fail), `fault-lose` (make a task's end unobservable); any missing feature gives `NOT_RUN` | + +`#` at the start of a line is a comment. Every other line is ` => ` or `check ...`. The runner compares the whole result text byte for byte. Every vector ends with `check empty`. + +### Stream commands + +Two principals, tables `A` and `B`, start empty. A handle name keeps its value after `close`, so a later use tests a stale handle. + +| command | meaning | result on success | +|---|---|---| +| `create ` | `PIPE_CREATE` in table T; each end gets its data right plus `d g v` | `OK` | +| `write ` / `fill ` | non-blocking `STREAM_WRITE`; `cap` is `LIMITS_GET.max_pipe_bytes` | `OK n=` | +| `read ` | non-blocking `STREAM_READ` | `OK n= data=`, or `OK n=0` | +| `skim ` | the same read, result without the bytes | `OK n=` | +| `bread ` / `bwrite ` | blocking call; the first time it would park, the peer runs `` (`none`, or one `write`, `read`, `close`, `revoke`, `cancel` command that must return `OK`); a second park gives up `INTERRUPTED` (the stalled-peer deadline) | as `read` / `write` | +| `close ` | `STREAM_CLOSE` | `OK` | +| `dup ` | `STREAM_DUP` into table T; letters `r w m g d v` (ST4.11) | `OK` | +| `revoke ` | the authority root revokes the pipe, through H's `v` right | `OK` | +| `cancel ` | an interrupt aimed at that end (ST4.7) | `OK` | +| `release ` / `sweep ` | close every handle in T; `release` prints the count (adapter-specific), `sweep` does not | `OK n=` / `OK` | +| `saturate last=` | duplicate H with its data right into T until `LIMIT`; D names the last duplicate made | `LIMIT` | +| `exhaust min=` | create pipes in T until `LIMIT`, require at least N and that the refused create left nothing, then close them | `LIMIT` | +| `limits` | `LIMITS_GET` meets ST9 | `OK max_pipe_bytes>=65536 max_streams>=16 max_tasks>=8` | +| `frame ...` | raw platform call (ST2) from table T; slice `-` or ``; cells hex, `$` = the adapter's handle cell for H; peer table is the other one | `OK`, or `OK n=` for read and write | + +### Task, launch and authority commands + +| command | meaning | result | +|---|---|---| +| `cap [gen=]` | the test authority mints a capability for spawning in the vector's domain; default generation 7 (domain 1) or `0x100000007` (domain 2) | `OK` | +| `revokecap ` | the authority root revokes it | `OK` | +| `bind cap= [gen=] [domain=] [index=]` / `bind none` | a binding built from C with fields overridden; `none` is no binding | `OK` | +| `spawn [in=] [out=] bind=` | `TASK_SPAWN` from table A; an omitted slot is empty | `OK` or the refusal | +| `run` | let every task run until none can move (a deterministic stand-in for time passing) | `OK` | +| `wait ` | `TASK_WAIT` with deadline 0 | `OK status= outcome=`, `WOULD_BLOCK`, `OUTCOME_UNKNOWN status=1 outcome=OUTCOME_UNKNOWN` | +| `state ` | `TASK_STATE` | `OK state=RUNNING\|ENDED` | +| `tcancel interrupt\|terminate` | `TASK_CANCEL` | `OK` | +| `launch

bind= [in=] [inject=:] [revoke=:] : ! ...` | launch one pipeline (ST7); stdin of the first command is `in` then end of stream, stdout of the last is captured; `inject` makes the spawn of command k fail with ERR; `revoke` revokes C just before command k's effect | `OK`, or ` status= outcomes=,... statuses=,...` | +| `waitp

` | wait for every command (deadline 0) | `OK status= outcomes=... statuses=... out=` or `WOULD_BLOCK` | +| `cancelp

interrupt\|terminate` | `TASK_CANCEL` every running command of P | `OK` | +| `reset` | session reset with ABI section 12 cleanup | `OK cancelled=` | +| `crash` / `recover` | the adapter dies with no cleanup and restarts; recovery reports intents without outcome | `OK` / `OK unknown= replayed=0` | +| `lose ` | the ended task's status becomes unobservable to the adapter (Linux: someone else reaped it) | `OK` | + +Programs the harness provides (not shell commands; the adapter's test harness implements them natively): `exit `; `emit []` writes the bytes then exits N (default 0); `cat` copies input to output until end of stream; `drain` reads to end of stream; `flood` writes `y\n` forever; `hang` waits until interrupted; `stubborn` ignores interrupts; `nosuch` is a name `RESOLVE` does not find; `foreign` is a name that resolves to a class this adapter does not provide. A program that gets `BROKEN_PIPE` on output exits 141; an obeyed interrupt ends it with 130 (ST6.3). Outcomes are the section 10 names; a status `-` is a command that never started. + +`check` items: `empty` (both tables, every pipe, every task and every intent record are gone and no recovery report is pending) and `pipes=` (live pipes). + +### Run reports and receipts + +An adapter runner prints one line per vector, `PASS `, `MISMATCH : got "" want ""` or `NOT_RUN ` (missing feature or domain), then `OSHSV1_CONFORMANCE impl= vectors= pass= fail= not_run=`. Its first line is `OSHSV1_RUN impl=@<40-hex commit> corpus=aien-protocols-mv@<40-hex commit> toolchain= target=host|qemu-`; a report whose first line lacks any of these pins is not a receipt (ST10.3). The reference model prints the same format with `impl=reference-model`; its result is a check of the corpus only. diff --git a/specs/osh-platform/vectors/s001_nul_payload.vec b/specs/osh-platform/vectors/s001_nul_payload.vec new file mode 100644 index 0000000..9c4e2bb --- /dev/null +++ b/specs/osh-platform/vectors/s001_nul_payload.vec @@ -0,0 +1,14 @@ +case nul_payload +kind positive +exec host-logic +domain any +needs streams +# bytes are bytes: NUL and bytes >= 0x80 pass unchanged and in order (ST4) +create R W A => OK +write W "a\x00b\xff\x80\x00" => OK n=6 +read R 2 => OK n=2 data="a\x00" +read R 16 => OK n=4 data="b\xff\x80\x00" +close W => OK +read R 1 => OK n=0 +close R => OK +check empty diff --git a/specs/osh-platform/vectors/s002_capacity_partial.vec b/specs/osh-platform/vectors/s002_capacity_partial.vec new file mode 100644 index 0000000..67d9f19 --- /dev/null +++ b/specs/osh-platform/vectors/s002_capacity_partial.vec @@ -0,0 +1,20 @@ +case capacity_partial +kind negative +exec host-logic +domain any +needs streams +# partial reads and writes (ST4.1, ST4.2); bounded capacity, no PIPE_BUF atomicity (ST4.2, ST11.6) +create R W A => OK +write W "hello" => OK n=5 +read R 2 => OK n=2 data="he" +read R 10 => OK n=3 data="llo" +fill W 65530 61 => OK n=65530 +write W "abcdefghij" => OK n=6 +write W "x" => WOULD_BLOCK +write W "" => OK n=0 +skim R 65530 => OK n=65530 +read R 10 => OK n=6 data="abcdef" +read R 1 => WOULD_BLOCK +close R => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s003_zero_length.vec b/specs/osh-platform/vectors/s003_zero_length.vec new file mode 100644 index 0000000..f0bac94 --- /dev/null +++ b/specs/osh-platform/vectors/s003_zero_length.vec @@ -0,0 +1,16 @@ +case zero_length +kind negative +exec host-logic +domain any +needs streams +# zero-length read and write move nothing and never block; authority and the reader check still apply (ST4.3) +create R W A => OK +write W "" => OK n=0 +read R 0 => OK n=0 +read R 4 => WOULD_BLOCK +write R "" => DENIED +read W 0 => DENIED +close R => OK +write W "" => BROKEN_PIPE +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s004_broken_pipe.vec b/specs/osh-platform/vectors/s004_broken_pipe.vec new file mode 100644 index 0000000..36ee9db --- /dev/null +++ b/specs/osh-platform/vectors/s004_broken_pipe.vec @@ -0,0 +1,16 @@ +case broken_pipe +kind negative +exec host-logic +domain any +needs streams +# no reader: BROKEN_PIPE and nothing stored; a duplicate reader keeps the pipe readable (ST4.5, ST4.10) +create R W A => OK +dup R R2 A rd => OK +close R => OK +write W "abc" => OK n=3 +read R2 2 => OK n=2 data="ab" +close R2 => OK +write W "x" => BROKEN_PIPE +write W "" => BROKEN_PIPE +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s005_eof_after_drain.vec b/specs/osh-platform/vectors/s005_eof_after_drain.vec new file mode 100644 index 0000000..714514c --- /dev/null +++ b/specs/osh-platform/vectors/s005_eof_after_drain.vec @@ -0,0 +1,18 @@ +case eof_after_drain +kind positive +exec host-logic +domain any +needs streams +# end of stream only when every writer handle is closed and the bytes are drained (ST4.4) +create R W A => OK +dup W W2 A w => OK +write W "abc" => OK n=3 +close W => OK +read R 1 => OK n=1 data="a" +read R 8 => OK n=2 data="bc" +read R 8 => WOULD_BLOCK +close W2 => OK +read R 8 => OK n=0 +read R 8 => OK n=0 +close R => OK +check empty diff --git a/specs/osh-platform/vectors/s006_rights.vec b/specs/osh-platform/vectors/s006_rights.vec new file mode 100644 index 0000000..1c9a4ce --- /dev/null +++ b/specs/osh-platform/vectors/s006_rights.vec @@ -0,0 +1,31 @@ +case rights +kind negative +exec host-logic +domain any +needs streams +# data right per end, dup attenuation, derive for the own table, grant for another (ST3.2, ST4.10, ST4.11) +create R W A => OK +write R "x" => DENIED +read W 1 => DENIED +dup R X A w => INVALID_ARG +dup R X A rm => INVALID_ARG +dup R RB B r => OK +dup RB RC B r => DENIED +dup RB RC A r => DENIED +revoke RB => DENIED +dup R RG B rg => OK +dup RG RH A rgv => DENIED +dup RG RH A rg => OK +cancel W => OK +dup W WB B wg => OK +dup WB WC B wd => DENIED +write WB "q" => INTERRUPTED +write WB "q" => OK n=1 +read RB 4 => OK n=1 data="q" +close RB => OK +close RG => OK +close RH => OK +close WB => OK +close R => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s007_handle_reuse.vec b/specs/osh-platform/vectors/s007_handle_reuse.vec new file mode 100644 index 0000000..8eaee73 --- /dev/null +++ b/specs/osh-platform/vectors/s007_handle_reuse.vec @@ -0,0 +1,20 @@ +case handle_reuse +kind negative +exec host-logic +domain any +needs streams +# a closed handle never reaches the stream that later reuses its slot (ST3.2, ST3.3) +create R W A => OK +close R => OK +close W => OK +create R2 W2 A => OK +read R 1 => STALE +write W "x" => STALE +close R => STALE +cancel W => STALE +revoke W => STALE +write W2 "ok" => OK n=2 +read R2 8 => OK n=2 data="ok" +close R2 => OK +close W2 => OK +check empty diff --git a/specs/osh-platform/vectors/s008_revoke_blocked_read.vec b/specs/osh-platform/vectors/s008_revoke_blocked_read.vec new file mode 100644 index 0000000..0c1a584 --- /dev/null +++ b/specs/osh-platform/vectors/s008_revoke_blocked_read.vec @@ -0,0 +1,15 @@ +case revoke_blocked_read +kind negative +exec native-qemu +domain any +needs streams +# revocation while a reader is parked: it wakes REVOKED; every later use but close is REVOKED (ST4.9) +create R W A => OK +bread R 4 revoke W => REVOKED +write W "x" => REVOKED +read R 1 => REVOKED +dup R X A r => REVOKED +cancel R => REVOKED +close R => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s009_revoke_blocked_write.vec b/specs/osh-platform/vectors/s009_revoke_blocked_write.vec new file mode 100644 index 0000000..560989e --- /dev/null +++ b/specs/osh-platform/vectors/s009_revoke_blocked_write.vec @@ -0,0 +1,13 @@ +case revoke_blocked_write +kind negative +exec native-qemu +domain any +needs streams +# revocation while a writer is parked on a full pipe: buffered bytes are scrubbed, never delivered (ST4.9) +create R W A => OK +fill W cap 61 => OK n=65536 +bwrite W "z" revoke R => REVOKED +read R 1 => REVOKED +close W => OK +close R => OK +check empty diff --git a/specs/osh-platform/vectors/s010_close_reader_race.vec b/specs/osh-platform/vectors/s010_close_reader_race.vec new file mode 100644 index 0000000..e0d10ad --- /dev/null +++ b/specs/osh-platform/vectors/s010_close_reader_race.vec @@ -0,0 +1,11 @@ +case close_reader_race +kind negative +exec native-qemu +domain any +needs streams +# the last reader closes while a writer is parked: the writer wakes BROKEN_PIPE (ST4.8) +create R W A => OK +fill W cap 62 => OK n=65536 +bwrite W "z" close R => BROKEN_PIPE +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s011_close_writer_race.vec b/specs/osh-platform/vectors/s011_close_writer_race.vec new file mode 100644 index 0000000..6063fa7 --- /dev/null +++ b/specs/osh-platform/vectors/s011_close_writer_race.vec @@ -0,0 +1,10 @@ +case close_writer_race +kind positive +exec native-qemu +domain any +needs streams +# the last writer closes while a reader is parked: the reader wakes with end of stream (ST4.8) +create R W A => OK +bread R 4 close W => OK n=0 +close R => OK +check empty diff --git a/specs/osh-platform/vectors/s012_both_closed.vec b/specs/osh-platform/vectors/s012_both_closed.vec new file mode 100644 index 0000000..bc24d78 --- /dev/null +++ b/specs/osh-platform/vectors/s012_both_closed.vec @@ -0,0 +1,15 @@ +case both_closed +kind negative +exec host-logic +domain any +needs streams +# both ends closed: the pipe and its unread bytes are gone; double close is STALE (ST4.8) +create R W A => OK +write W "lost" => OK n=4 +close W => OK +close R => OK +check empty +close R => STALE +close W => STALE +read R 1 => STALE +check empty diff --git a/specs/osh-platform/vectors/s013_cancel_blocked_read.vec b/specs/osh-platform/vectors/s013_cancel_blocked_read.vec new file mode 100644 index 0000000..5fdc5c0 --- /dev/null +++ b/specs/osh-platform/vectors/s013_cancel_blocked_read.vec @@ -0,0 +1,14 @@ +case cancel_blocked_read +kind negative +exec native-qemu +domain any +needs streams +# an interrupt wakes a parked reader INTERRUPTED with nothing moved, once (ST4.7) +create R W A => OK +bread R 4 cancel R => INTERRUPTED +read R 4 => WOULD_BLOCK +write W "ok" => OK n=2 +read R 4 => OK n=2 data="ok" +close W => OK +close R => OK +check empty diff --git a/specs/osh-platform/vectors/s014_cancel_latched.vec b/specs/osh-platform/vectors/s014_cancel_latched.vec new file mode 100644 index 0000000..dd692b1 --- /dev/null +++ b/specs/osh-platform/vectors/s014_cancel_latched.vec @@ -0,0 +1,17 @@ +case cancel_latched +kind negative +exec host-logic +domain any +needs streams +# an interrupt with nobody parked is latched and interrupts the next call on that end only (ST4.7, ST11.8) +create R W A => OK +cancel W => OK +read R 1 => WOULD_BLOCK +write W "x" => INTERRUPTED +write W "x" => OK n=1 +cancel R => OK +read R 1 => INTERRUPTED +read R 1 => OK n=1 data="x" +close R => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s015_stalled_consumer.vec b/specs/osh-platform/vectors/s015_stalled_consumer.vec new file mode 100644 index 0000000..e5686c7 --- /dev/null +++ b/specs/osh-platform/vectors/s015_stalled_consumer.vec @@ -0,0 +1,13 @@ +case stalled_consumer +kind negative +exec native-qemu +domain any +needs streams +# backpressure: a writer parked on a full pipe whose reader never reads gives up INTERRUPTED; nothing is lost (ST4.6) +create R W A => OK +fill W cap 63 => OK n=65536 +bwrite W "z" none => INTERRUPTED +read R 3 => OK n=3 data="ccc" +close R => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s016_blocked_read_progress.vec b/specs/osh-platform/vectors/s016_blocked_read_progress.vec new file mode 100644 index 0000000..4bff3d1 --- /dev/null +++ b/specs/osh-platform/vectors/s016_blocked_read_progress.vec @@ -0,0 +1,13 @@ +case blocked_read_progress +kind positive +exec native-qemu +domain any +needs streams +# a parked reader returns as soon as one write lands; a blocking write with room never parks (ST4.1, ST4.6) +create R W B => OK +bread R 8 write W "hi\x00" => OK n=3 data="hi\x00" +bwrite W "yo" none => OK n=2 +read R 8 => OK n=2 data="yo" +close R => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s017_malformed_frames.vec b/specs/osh-platform/vectors/s017_malformed_frames.vec new file mode 100644 index 0000000..774398c --- /dev/null +++ b/specs/osh-platform/vectors/s017_malformed_frames.vec @@ -0,0 +1,36 @@ +case malformed_frames +kind negative +exec host-logic +domain any +needs streams frames +# platform call frames: every malformed header is refused before any effect, in the ST2 order +frame A - 4F534846 1 => INVALID_ARG +frame A - 4F534846 1 1 => INVALID_ARG +frame A - 12345678 1 1 0 => INVALID_ARG +frame A - 4F534846 2 1 0 => NOT_SUPPORTED +frame A - 4F534846 0 1 0 => NOT_SUPPORTED +frame A - 4F534846 2 1 1 => NOT_SUPPORTED +frame A - 4F534846 1 1 1 => INVALID_ARG +frame A - 4F534846 1 0 0 => NOT_SUPPORTED +frame A - 4F534846 1 10 0 => NOT_SUPPORTED +frame A - 4F534846 1 FF 0 => NOT_SUPPORTED +frame A - 4F534846 1 FFFFFFFF00000001 0 => NOT_SUPPORTED +frame A - 4F534846 1 1 0 0 => INVALID_ARG +frame A - 4F534846 1 4 0 0 => INVALID_ARG +check empty +create R W A => OK +frame A - 4F534846 1 3 0 $W => INVALID_ARG +frame A "abc" 4F534846 1 3 0 $W 2 => INVALID_ARG +frame A "abc" 4F534846 1 3 0 $W 0 => OK n=3 +frame A "zz" 4F534846 1 2 0 $R 0 => OK n=2 +frame A - 4F534846 1 5 0 $R 1 2 => INVALID_ARG +frame A - 4F534846 1 5 0 $R 1 1 => OK +frame A - 4F534846 1 7F 0 $R => NOT_SUPPORTED +release B => OK n=1 +frame A - 4F534846 1 4 0 $R => OK +frame A - 4F534846 1 4 0 $R => STALE +frame A - 4F534846 1 1 0 => OK +check pipes=2 +close W => OK +sweep A => OK +check empty diff --git a/specs/osh-platform/vectors/s018_limits.vec b/specs/osh-platform/vectors/s018_limits.vec new file mode 100644 index 0000000..cc71910 --- /dev/null +++ b/specs/osh-platform/vectors/s018_limits.vec @@ -0,0 +1,16 @@ +case limits +kind negative +exec host-logic +domain any +needs streams +# ST9 minimums; LIMIT leaves nothing allocated, also when the table runs out between the two ends +limits => OK max_pipe_bytes>=65536 max_streams>=16 max_tasks>=8 +exhaust A min=8 => LIMIT +check empty +create R W A => OK +saturate R A last=D => LIMIT +close D => OK +create X Y A => LIMIT +check pipes=1 +sweep A => OK +check empty diff --git a/specs/osh-platform/vectors/s019_dup_refs.vec b/specs/osh-platform/vectors/s019_dup_refs.vec new file mode 100644 index 0000000..a8d7fb2 --- /dev/null +++ b/specs/osh-platform/vectors/s019_dup_refs.vec @@ -0,0 +1,16 @@ +case dup_refs +kind positive +exec host-logic +domain any +needs streams +# every duplicate is a separate writer; end of stream waits for all of them (ST4.4, ST4.10) +create R W A => OK +dup W W2 A w => OK +close W => OK +write W2 "x" => OK n=1 +read R 4 => OK n=1 data="x" +read R 4 => WOULD_BLOCK +close W2 => OK +read R 4 => OK n=0 +close R => OK +check empty diff --git a/specs/osh-platform/vectors/s020_transfer.vec b/specs/osh-platform/vectors/s020_transfer.vec new file mode 100644 index 0000000..1293fbf --- /dev/null +++ b/specs/osh-platform/vectors/s020_transfer.vec @@ -0,0 +1,16 @@ +case transfer +kind positive +exec host-logic +domain any +needs streams +# a read end transferred to another principal; revocation through its delegate right reaches both ends (ST3.1, ST4.9) +create R W A => OK +dup R RB B rv => OK +close R => OK +write W "\x00\x01\x02" => OK n=3 +read RB 3 => OK n=3 data="\x00\x01\x02" +revoke RB => OK +write W "x" => REVOKED +close RB => OK +close W => OK +check empty diff --git a/specs/osh-platform/vectors/s021_epoch.vec b/specs/osh-platform/vectors/s021_epoch.vec new file mode 100644 index 0000000..e1954b8 --- /dev/null +++ b/specs/osh-platform/vectors/s021_epoch.vec @@ -0,0 +1,20 @@ +case epoch +kind negative +exec host-logic +domain any +needs streams reset journal +# an adapter restart and a session reset both end every earlier handle: STALE, even when the new +# session hands out the same slot with the same generation (ST3.3) +create R W A => OK +write W "b" => OK n=1 +crash => OK +recover => OK unknown=0 replayed=0 +create R2 W2 A => OK +read R 1 => STALE +write W "c" => STALE +read R2 1 => WOULD_BLOCK +write W2 "a" => OK n=1 +reset => OK cancelled=0 +read R2 1 => STALE +close W2 => STALE +check empty diff --git a/specs/osh-platform/vectors/t001_task_stream_binding.vec b/specs/osh-platform/vectors/t001_task_stream_binding.vec new file mode 100644 index 0000000..225b754 --- /dev/null +++ b/specs/osh-platform/vectors/t001_task_stream_binding.vec @@ -0,0 +1,22 @@ +case task_stream_binding +kind positive +exec native-qemu +domain 2 +needs streams tasks test-authority +# a task gets its own duplicate of its stream; the caller closing its copy is what lets end of stream arrive; +# a reaped task id is released (ST6.1, ST6.2) +cap C => OK +bind B cap=C => OK +create R W A => OK +spawn T emit "hi" out=W bind=B => OK +run => OK +read R 8 => OK n=2 data="hi" +read R 8 => WOULD_BLOCK +close W => OK +read R 8 => OK n=0 +state T => OK state=ENDED +wait T => OK status=0 outcome=COMPLETED +wait T => STALE +state T => STALE +close R => OK +check empty diff --git a/specs/osh-platform/vectors/t002_stage_nonzero_exit.vec b/specs/osh-platform/vectors/t002_stage_nonzero_exit.vec new file mode 100644 index 0000000..499edeb --- /dev/null +++ b/specs/osh-platform/vectors/t002_stage_nonzero_exit.vec @@ -0,0 +1,18 @@ +case stage_nonzero_exit +kind positive +exec native-qemu +domain 1 +needs tasks launch test-authority +# pipeline status is the last command's status; an earlier nonzero exit does not change it (ST7.7) +cap C => OK +bind B cap=C => OK +launch P bind=B : exit 3 ! cat => OK +run => OK +waitp P => OK status=0 outcomes=COMPLETED,COMPLETED statuses=3,0 out="" +launch Q bind=B : exit 0 ! exit 5 => OK +run => OK +waitp Q => OK status=5 outcomes=COMPLETED,COMPLETED statuses=0,5 out="" +launch S bind=B in="a\x00b" : cat ! cat ! cat => OK +run => OK +waitp S => OK status=0 outcomes=COMPLETED,COMPLETED,COMPLETED statuses=0,0,0 out="a\x00b" +check empty diff --git a/specs/osh-platform/vectors/t003_pipeline_broken_pipe.vec b/specs/osh-platform/vectors/t003_pipeline_broken_pipe.vec new file mode 100644 index 0000000..e7ee7af --- /dev/null +++ b/specs/osh-platform/vectors/t003_pipeline_broken_pipe.vec @@ -0,0 +1,12 @@ +case pipeline_broken_pipe +kind negative +exec native-qemu +domain 2 +needs tasks launch test-authority +# no readers: a writer that does not handle BROKEN_PIPE ends with status 141; pipeline status stays the last's (ST4.5, ST6.3) +cap C => OK +bind B cap=C => OK +launch P bind=B : flood ! exit 0 => OK +run => OK +waitp P => OK status=0 outcomes=COMPLETED,COMPLETED statuses=141,0 out="" +check empty diff --git a/specs/osh-platform/vectors/t004_task_cancel.vec b/specs/osh-platform/vectors/t004_task_cancel.vec new file mode 100644 index 0000000..6a69d44 --- /dev/null +++ b/specs/osh-platform/vectors/t004_task_cancel.vec @@ -0,0 +1,27 @@ +case task_cancel +kind negative +exec native-qemu +domain 1 +needs tasks test-authority +# interrupt can be handled, terminate cannot; cancelling an ended task changes nothing; a reaped id is STALE (ST6.3, ST6.5) +cap C => OK +bind B cap=C => OK +spawn T hang bind=B => OK +run => OK +state T => OK state=RUNNING +wait T => WOULD_BLOCK +tcancel T interrupt => OK +run => OK +wait T => OK status=130 outcome=CANCELLED +tcancel T interrupt => STALE +spawn S stubborn bind=B => OK +tcancel S interrupt => OK +run => OK +state S => OK state=RUNNING +tcancel S terminate => OK +wait S => OK status=137 outcome=CANCELLED +spawn U exit 4 bind=B => OK +run => OK +tcancel U terminate => OK +wait U => OK status=4 outcome=COMPLETED +check empty diff --git a/specs/osh-platform/vectors/t005_cancel_blocked_task.vec b/specs/osh-platform/vectors/t005_cancel_blocked_task.vec new file mode 100644 index 0000000..11951ec --- /dev/null +++ b/specs/osh-platform/vectors/t005_cancel_blocked_task.vec @@ -0,0 +1,24 @@ +case cancel_blocked_task +kind negative +exec native-qemu +domain 2 +needs streams tasks launch test-authority +# a task parked in a stream read is interrupted out of it; pipeline cancel reaches every stage (ST4.7, ST6.5) +cap C => OK +bind B cap=C => OK +create R W A => OK +spawn T cat in=R bind=B => OK +run => OK +state T => OK state=RUNNING +tcancel T interrupt => OK +run => OK +wait T => OK status=130 outcome=CANCELLED +close R => OK +close W => OK +launch P bind=B : hang ! cat => OK +run => OK +waitp P => WOULD_BLOCK +cancelp P interrupt => OK +run => OK +waitp P => OK status=130 outcomes=CANCELLED,CANCELLED statuses=130,130 out="" +check empty diff --git a/specs/osh-platform/vectors/t006_partial_launch.vec b/specs/osh-platform/vectors/t006_partial_launch.vec new file mode 100644 index 0000000..d1bbde9 --- /dev/null +++ b/specs/osh-platform/vectors/t006_partial_launch.vec @@ -0,0 +1,15 @@ +case partial_launch +kind negative +exec native-qemu +domain 2 +needs tasks launch test-authority fault-spawn +# a spawn that fails after others started: they are interrupted, then terminated, reaped, every pipe closed; +# with nothing started the error is the spawn's own (ST7.6, ABI section 10) +cap C => OK +bind B cap=C => OK +launch P bind=B inject=3:LIMIT : hang ! stubborn ! cat => PARTIAL_LAUNCH status=1 outcomes=CANCELLED,CANCELLED,FAILED_NO_EFFECT statuses=130,137,1 +check empty +launch Q bind=B inject=2:IO : hang ! cat ! cat => PARTIAL_LAUNCH status=1 outcomes=CANCELLED,FAILED_NO_EFFECT,NOT_STARTED statuses=130,1,- +check empty +launch S bind=B inject=1:LIMIT : hang ! cat => LIMIT status=1 outcomes=FAILED_NO_EFFECT,NOT_STARTED statuses=1,- +check empty diff --git a/specs/osh-platform/vectors/t007_refusal_before_effects.vec b/specs/osh-platform/vectors/t007_refusal_before_effects.vec new file mode 100644 index 0000000..6ba805a --- /dev/null +++ b/specs/osh-platform/vectors/t007_refusal_before_effects.vec @@ -0,0 +1,16 @@ +case refusal_before_effects +kind negative +exec host-logic +domain 2 +needs tasks launch test-authority +# refusals of the whole pipeline happen before any effect: nothing starts, no intent is written (ST7 steps 1 to 3) +cap C => OK +bind B cap=C => OK +bind N none => OK +bind X cap=C domain=3 => OK +launch P bind=B : cat ! foreign => UNAVAILABLE status=126 outcomes=FAILED_NO_EFFECT,FAILED_NO_EFFECT statuses=126,126 +check empty +launch Q bind=N : exit 0 => DENIED status=126 outcomes=FAILED_NO_EFFECT statuses=126 +check empty +launch S bind=X : exit 0 ! exit 0 => CAP_DOMAIN_MISMATCH status=126 outcomes=FAILED_NO_EFFECT,FAILED_NO_EFFECT statuses=126,126 +check empty diff --git a/specs/osh-platform/vectors/t008_not_found_stage.vec b/specs/osh-platform/vectors/t008_not_found_stage.vec new file mode 100644 index 0000000..fba0e31 --- /dev/null +++ b/specs/osh-platform/vectors/t008_not_found_stage.vec @@ -0,0 +1,15 @@ +case not_found_stage +kind negative +exec native-qemu +domain 1 +needs tasks launch test-authority +# a name not found fails only its own command (127); its neighbours still run and see end of stream (ST7.5) +cap C => OK +bind B cap=C => OK +launch P bind=B : nosuch ! cat => OK +run => OK +waitp P => OK status=0 outcomes=FAILED_NO_EFFECT,COMPLETED statuses=127,0 out="" +launch Q bind=B : exit 2 ! nosuch => OK +run => OK +waitp Q => OK status=127 outcomes=COMPLETED,FAILED_NO_EFFECT statuses=2,127 out="" +check empty diff --git a/specs/osh-platform/vectors/t009_revoke_between_stages.vec b/specs/osh-platform/vectors/t009_revoke_between_stages.vec new file mode 100644 index 0000000..fbeef28 --- /dev/null +++ b/specs/osh-platform/vectors/t009_revoke_between_stages.vec @@ -0,0 +1,14 @@ +case revoke_between_stages +kind negative +exec native-qemu +domain 1 +needs tasks launch test-authority +# authority is checked at the moment of each effect: a capability revoked after the first command started +# refuses the second (126, REVOKED), and later spawns (ABI 9.2, ST7.5) +cap C => OK +bind B cap=C => OK +launch P bind=B revoke=2:C : exit 4 ! exit 5 => OK +run => OK +waitp P => OK status=126 outcomes=COMPLETED,FAILED_NO_EFFECT statuses=4,126 out="" +spawn T exit 0 bind=B => REVOKED +check empty diff --git a/specs/osh-platform/vectors/t010_domain1_generation.vec b/specs/osh-platform/vectors/t010_domain1_generation.vec new file mode 100644 index 0000000..a492d96 --- /dev/null +++ b/specs/osh-platform/vectors/t010_domain1_generation.vec @@ -0,0 +1,28 @@ +case domain1_generation +kind negative +exec host-logic +domain 1 +needs tasks test-authority +# domain 1 (kernel IPC table): 32-bit generations; a wider one is refused, never truncated (ST5) +cap C => OK +bind B cap=C => OK +bind WIDE cap=C gen=0x100000007 => OK +bind OLD cap=C gen=8 => OK +bind D2 cap=C domain=2 => OK +bind D0 cap=C domain=0 => OK +bind GONE cap=C index=99 => OK +bind N none => OK +spawn T1 exit 0 bind=WIDE => CAP_GEN_NARROW +spawn T2 exit 0 bind=OLD => STALE +spawn T3 exit 0 bind=D2 => CAP_DOMAIN_MISMATCH +spawn T4 exit 0 bind=D0 => CAP_DOMAIN_MISMATCH +spawn T5 exit 0 bind=GONE => STALE +spawn T6 exit 0 bind=N => DENIED +launch P bind=WIDE : exit 0 => CAP_GEN_NARROW status=126 outcomes=FAILED_NO_EFFECT statuses=126 +check empty +spawn T exit 0 bind=B => OK +run => OK +wait T => OK status=0 outcome=COMPLETED +revokecap C => OK +spawn T7 exit 0 bind=B => REVOKED +check empty diff --git a/specs/osh-platform/vectors/t011_domain2_generation.vec b/specs/osh-platform/vectors/t011_domain2_generation.vec new file mode 100644 index 0000000..ef85ba6 --- /dev/null +++ b/specs/osh-platform/vectors/t011_domain2_generation.vec @@ -0,0 +1,23 @@ +case domain2_generation +kind negative +exec host-logic +domain 2 +needs tasks test-authority +# domain 2 (hosted authority): 64-bit generations compared in all 64 bits; a domain-1 binding cannot carry them (ST5) +cap C => OK +bind B cap=C => OK +bind LOW cap=C gen=0x7 => OK +bind HIGH cap=C gen=0x200000007 => OK +bind AS1 cap=C domain=1 => OK +bind AS1LOW cap=C domain=1 gen=7 => OK +spawn T1 exit 0 bind=LOW => STALE +spawn T2 exit 0 bind=HIGH => STALE +spawn T3 exit 0 bind=AS1 => CAP_GEN_NARROW +spawn T4 exit 0 bind=AS1LOW => CAP_DOMAIN_MISMATCH +check empty +spawn T exit 0 bind=B => OK +run => OK +wait T => OK status=0 outcome=COMPLETED +revokecap C => OK +spawn T5 exit 0 bind=B => REVOKED +check empty diff --git a/specs/osh-platform/vectors/t012_outcome_unknown_crash.vec b/specs/osh-platform/vectors/t012_outcome_unknown_crash.vec new file mode 100644 index 0000000..d4a558e --- /dev/null +++ b/specs/osh-platform/vectors/t012_outcome_unknown_crash.vec @@ -0,0 +1,17 @@ +case outcome_unknown_crash +kind negative +exec native-qemu +domain 2 +needs tasks launch journal test-authority +# after an adapter crash every intent without an outcome is OUTCOME_UNKNOWN, nothing is replayed, +# and every earlier task id is STALE (ST8.3) +cap C => OK +bind B cap=C => OK +launch P bind=B : hang ! cat => OK +spawn T exit 0 bind=B => OK +run => OK +crash => OK +recover => OK unknown=3 replayed=0 +wait T => STALE +waitp P => STALE +check empty diff --git a/specs/osh-platform/vectors/t013_outcome_unknown_lost.vec b/specs/osh-platform/vectors/t013_outcome_unknown_lost.vec new file mode 100644 index 0000000..f90e740 --- /dev/null +++ b/specs/osh-platform/vectors/t013_outcome_unknown_lost.vec @@ -0,0 +1,14 @@ +case outcome_unknown_lost +kind negative +exec native-qemu +domain 2 +needs tasks test-authority fault-lose +# a started task whose fate the adapter can no longer learn is OUTCOME_UNKNOWN, never success (ST8.4) +cap C => OK +bind B cap=C => OK +spawn T exit 0 bind=B => OK +run => OK +lose T => OK +wait T => OUTCOME_UNKNOWN status=1 outcome=OUTCOME_UNKNOWN +wait T => STALE +check empty diff --git a/specs/osh-platform/vectors/t014_reset_cleanup.vec b/specs/osh-platform/vectors/t014_reset_cleanup.vec new file mode 100644 index 0000000..bf8ed86 --- /dev/null +++ b/specs/osh-platform/vectors/t014_reset_cleanup.vec @@ -0,0 +1,17 @@ +case reset_cleanup +kind negative +exec native-qemu +domain 1 +needs streams tasks reset test-authority +# section 12 cleanup on a session reset: interrupt, grace, terminate, reap, close; every id STALE after (ST6.5) +cap C => OK +bind B cap=C => OK +create R W A => OK +spawn T hang bind=B => OK +spawn S stubborn out=W bind=B => OK +run => OK +reset => OK cancelled=2 +wait T => STALE +wait S => STALE +read R 1 => STALE +check empty diff --git a/specs/osh-platform/vectors/t015_spawn_argument_refusals.vec b/specs/osh-platform/vectors/t015_spawn_argument_refusals.vec new file mode 100644 index 0000000..bc2315f --- /dev/null +++ b/specs/osh-platform/vectors/t015_spawn_argument_refusals.vec @@ -0,0 +1,15 @@ +case spawn_argument_refusals +kind negative +exec host-logic +domain 2 +needs streams tasks test-authority +# a standard-stream slot needs the right end and a live handle; refused before the task exists (ST6.1) +cap C => OK +bind B cap=C => OK +create R W A => OK +spawn T1 cat in=W bind=B => INVALID_ARG +spawn T2 emit "x" out=R bind=B => INVALID_ARG +close W => OK +spawn T3 emit "x" out=W bind=B => STALE +close R => OK +check empty diff --git a/specs/osh-platform/vectors/t016_eof_all_task_writers.vec b/specs/osh-platform/vectors/t016_eof_all_task_writers.vec new file mode 100644 index 0000000..c85be83 --- /dev/null +++ b/specs/osh-platform/vectors/t016_eof_all_task_writers.vec @@ -0,0 +1,22 @@ +case eof_all_task_writers +kind positive +exec native-qemu +domain 1 +needs streams tasks test-authority +# end of stream waits for writers held by tasks too; a task's ends close when it ends (ST4.4, ST6.1) +cap C => OK +bind B cap=C => OK +create R W A => OK +spawn T1 emit "a" out=W bind=B => OK +spawn T2 hang out=W bind=B => OK +close W => OK +run => OK +read R 8 => OK n=1 data="a" +read R 8 => WOULD_BLOCK +tcancel T2 interrupt => OK +run => OK +read R 8 => OK n=0 +wait T1 => OK status=0 outcome=COMPLETED +wait T2 => OK status=130 outcome=CANCELLED +close R => OK +check empty ```