Skip to content

Host: preserve output buffers after zero-byte syscalls#924

Closed
brandonpayton wants to merge 1 commit into
mainfrom
fix/zero-byte-syscall-copy-back
Closed

Host: preserve output buffers after zero-byte syscalls#924
brandonpayton wants to merge 1 commit into
mainfrom
fix/zero-byte-syscall-copy-back

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

This pulls one host-runtime fix out of #769, rebuilt directly on current main from source commit 5e1da94.

What #907 already landed

#907 landed the current ABI-39 host and kernel baseline, including the newer channel-completion lifecycle, diagnostic routing, and the overlapping mmap and munmap work. It did not include this output copy-length correction.

What remains here

A successful read, recv, or getdents-style syscall can return zero bytes. The host used to copy the whole zero-filled scratch buffer back anyway, overwriting bytes the guest still owned. This change copies no variable output for a zero result, while still copying fixed prefix metadata such as the message type used by msgrcv.

The focused tests cover:

  • read EOF leaving the destination unchanged;
  • a partial read copying only the reported bytes;
  • a zero-length msgrcv copying its fixed prefix without overwriting the tail.

The code is shared by Node and browser workers. The direct regression test exercises that shared path, and a Chromium guest lifecycle test passed against the rebuilt browser host.

What was deliberately removed

This does not replay the stale #769 ancestry or any of its mmap, SQLite, libc, VFS, credential, lock-table, or package changes. The test harness was adapted to the current #907 channel-publication flow instead of restoring the old assumptions.

ABI and package impact

This fixes the existing ABI-39 marshalling behavior without changing syscall numbers, descriptors, channel layout, pointer interpretation, or generated ABI data. Existing binaries remain valid, so there is no ABI version bump. The ABI snapshot check is clean. No package recipe, revision, or artifact output changes.

Validation run

  • checkout-local wasm32 and wasm64 musl sysroots built successfully;
  • current-main build completed successfully with the dev-shell LLVM archiver;
  • focused regression before the fix: 2 failed and 1 passed, demonstrating the bug;
  • focused regression after the fix: 3 passed;
  • host typecheck passed;
  • full Vitest: 147 files passed, 31 skipped; 1,269 tests passed, 2 expected failures, 130 skipped;
  • Bun teardown rerun: 3 tests passed;
  • ABI version and snapshot check passed;
  • browser asset check resolved all 92 imports;
  • focused Chromium environment lifecycle guest test passed on an isolated Vite port.

Validation not run

The full non-slow Playwright suite, Firefox, WebKit, manual ./run.sh browser verification, libc-test, POSIX, and Sortix suites were not run. This PR changes host scratch-buffer copy-back only; it does not change libc, the kernel syscall implementation, VFS state, or package artifacts. No performance claim is made and no performance benchmark was run.

@brandonpayton

Copy link
Copy Markdown
Member Author

Closing this focused source PR because its zero-byte syscall copy-back contract is now carried by #934 at exact green head 260d75d5adc31b327f5591229dbfbb287d395fd6. #934 keeps it as a separate purpose commit and passed the full staging and host test gates. This is not a claim that this branch was merged verbatim.

@brandonpayton
brandonpayton deleted the fix/zero-byte-syscall-copy-back branch July 14, 2026 02:43
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.

1 participant