Skip to content

feat(fs): binary-safe length-bearing file I/O through the native ABI and libc (refs #765) - #773

Merged
rwrife merged 4 commits into
mainfrom
feature/native-binary-fs-io-765
Sep 12, 2026
Merged

rwrife merged 4 commits into
mainfrom
feature/native-binary-fs-io-765

Conversation

@rwrife

@rwrife rwrife commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Summary

DEMO-01 (#765) slice: binary-safe, length-bearing file I/O through the native ABI and libc, reusing the existing kernel fs operations and capability/consent gates.

  • Public ABI + runtime (secureos_api.h, secureos_api_stubs.c): new os_fs_read_file_bytes / os_fs_write_file_bytes wrappers. Additive native-bridge slots; bridge version 4 -> 5; no OS_ABI_VERSION bump. Argument guards run before any bridge dereference; *out_len is pinned to 0 on every failure path; empty-file read is a clean OK-with-zero-length EOF.
  • Kernel bridge (launcher_exec.c): app_native_fs_read_file_bytes / app_native_fs_write_file_bytes call the existing fs_read_file_bytes / fs_write_file_bytes ops behind the exact same CAP_FS_READ/CAP_FS_WRITE + CAP_DISK_IO_REQUEST + per-operation disk-IO consent gates as the text pair — denied access performs no write and reports denial. Wire errors map NOT_FOUND vs capacity/storage distinctly.
  • clib fd adapter (posix_fd.c): snapshots now read and flush with actual byte lengths; the strnlen length inference and the documented embedded-NUL flush truncation are gone. Existing text callers keep their behavior (the text pair itself is unchanged).
  • Gates: clib_posix_fd extended with byte-exact leading/interior/trailing NUL read + create/append round-trips; new native_fs_bytes_wrapper host gate drives the wrappers over a synthetic v5 bridge page (exact-byte transport, pre-v5 handshake degrade, full return-code mapping, argument guards). Wired into test.sh, its usage list, and validate_bundle.sh TEST_TARGETS.
  • Bridge-version follow-through: process_exit_qemu / process_spawn_argv_roundtrip synthetic bridge pages bumped to v5 (required by the runtime handshake — same bookkeeping as every prior bridge bump).
  • Docs: docs/abi/syscalls.md filesystem table gains both calls with the explicit short-read/EOF/capacity/deny contract; docs/abi/clib-symbols.md fd-surface notes and the vendor/tinycc/libc-deps.json open-symbol note retire the text-payload limitation. Two-commit stamp pattern: stamp-only commit repoints both docs' Last verified lines to the content commit.

Test evidence (host gates, local green)

clib_posix_fd, native_fs_bytes_wrapper, abi_version, clib_stdio, clib_symbol_drift, fs_service, launcher_fs, app_runtime, mem_brk_wrapper, clib_os_brk, mem_brk_qemu, mem_brk_arena_cap_deny, process_exit_wrapper, process_exit_qemu, process_spawn_wrapper, process_spawn_argv_roundtrip, sosh_cap_cat_ls, sosh_cap_write_append, validate_sosh_capability_contract, tinycc_libc_deps, validate_abi_stamps.

Scope notes

  • Does not close DEMO-01: Expose binary-safe filesystem I/O through the native ABI and libc #765: the issue's remaining acceptance bullets are booted-guest evidence (binary write/reopen/compare on the real FAT path, real archive read, ELF/SOF persistence at demo sizes, guest-path denial behavior). A follow-up guest-evidence slice will carry Closes #765.
  • Deliberately untouched per the issue: real unlink and stdin improvements (not prerequisites for the compiler path).

Refs #765

…nd libc (refs #765)

DEMO-01 slice: native applications can read and persist arbitrary
binary payloads without NUL truncation.

- secureos_api.h: declare os_fs_read_file_bytes / os_fs_write_file_bytes
  with an explicit capacity/EOF/deny contract (additive, no
  OS_ABI_VERSION bump).
- launcher_exec.c: bridge slots fs_read_file_bytes /
  fs_write_file_bytes; kernel bridge version 4 -> 5; implementations
  reuse fs_read_file_bytes/fs_write_file_bytes with the same
  CAP_FS_READ/CAP_FS_WRITE + CAP_DISK_IO_REQUEST + per-operation
  disk-IO consent gates (denied access performs no write).
- secureos_api_stubs.c: v5 handshake + wrapper mappings; guards run
  before any bridge dereference (no-bridge hosts never touch
  0x9FF000); *out_len pinned to 0 on every failure path.
- posix_fd.c: snapshots read AND flush with explicit byte lengths via
  the byte APIs; strnlen length inference and embedded-NUL flush
  truncation removed; text write/append compatibility preserved.
- clib_posix_fd gate: byte-exact leading/interior/trailing NUL read +
  create/append round-trips.
- New native_fs_bytes_wrapper dynamic host gate (synthetic v5 bridge
  page: exact-byte transport, pre-v5 degrade, return-code mapping,
  argument guards); wired into test.sh + validate_bundle TEST_TARGETS.
- process_exit_qemu / process_spawn_argv_roundtrip: synthetic bridge
  pages bumped to v5 (same as every prior bridge-version bump).
- docs/abi syscalls + clib-symbols tables and the tinycc libc-deps
  open-symbol note aligned with the retired text-only limitation.
- State snapshot for 2026-09-11.
…apper gate

The pinned toolchain container compiles with stricter feature-test
macros than the dev host glibc; mirrors tests/process_exit_qemu_test.c
which defines _GNU_SOURCE for the same MAP_FIXED page setup.
…(refs #765)

Intentional documented drift: secureos_api.h and secureos_api_stubs.c
gain the os_fs_read_file_bytes / os_fs_write_file_bytes wrappers in this
PR (bridge v5), changing the pinned input hashes and the derived
hello.bin output hash.

Hash provenance: the three new values are the exact 'actual' hashes
emitted by the pinned-toolchain hello_sof_golden run in CI (actions run
34655783679, job build-and-validate), verified byte-identical to local
sha256sum for both changed input files. toolchain.lock, dev/hello.c and
crt0.c pins are unchanged (PASS in that run).
@rwrife
rwrife merged commit 78dbd31 into main Sep 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DEMO-01: Expose binary-safe filesystem I/O through the native ABI and libc

1 participant