feat(libkernel): cancel blocked POSIX writes safely #11969

Closed
Felipebmaitan wants to merge 66 commits from upstream-pr/11969 into main
Felipebmaitan commented 2026-10-27 14:07:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Felipebmaitan on 2026-10-27T14:07:34Z.


What

Implement milestone 2: a blocked POSIX write can be cancelled while retaining descriptor ownership until native operations drain. Completed positive counts, including partial counts, win; zero/error returns check pending cancellation after guards release. Disabled cancellation stays pending, and cleanup/TSD run exactly once after operation ownership ends.

APIs: write, _write, writev, _writev, pwrite, pwritev, send, sendto, sendmsg, _sendto, _sendmsg. Paths include ordinary files, shared-memory objects, pipes, stream and datagram sockets. Positioned pipe/socket writes retain their existing errors. SCE and libSceNet gain no cancellation points. Accept/connect and multiplexed waits remain later milestones.

The write layer reuses #11872's descriptor admission, signals and cancellation/close machinery. Native transports preserve known partial progress; Windows pipe vector transfers preserve small-write atomicity. Linux preflight metadata and synchronous flushes now participate in native interruption. An interrupted two-phase O_FSYNC write can leave buffered bytes visible without durable completion; it reports success only after flushing succeeds and never replays those bytes after interrupted flushing. Direct SCE flush behavior is preserved. Restricted-right Windows pipe handles fall back to their existing native write capability when attribute queries are denied.

Stack: read 8c68efe407; transport 3c360d54ee; write dc7772e6e1. Includes pinned main 228cd64b53 and declared read prerequisites #10817/#10755 with original commits/authorship preserved. The transport branch preserves all six exact #10943 candidate commits through 6adaa5acdf. The standalone owning-TLS repair eebaac5b24 and descriptor export repair 4527224683 belong to the read prerequisite.

Transport-only comparison; write-only comparison (17 files, seven commits after transport).

Publication constraint: CONTRIBUTING allows 20 open PRs while an author has 1-19 merged; this author has 20 open/17 merged. The separate transport branch is published but cannot have an upstream PR yet. This account lacks upstream push access and upstream has no read/transport base branch. This PR still targets main, so its Files changed includes prerequisites; the linked incremental comparison is write-only. A maintainer-provided upstream base or merged prerequisites is needed for a write-only upstream Files changed view.

Overlap coordination: #11872 tracker explicitly covers #11896, #10645, #10552 and #11625. #11896 confirms reads first; external #10645/#10552 replies remain pending. #11625 source head is preserved. Write/carrier seam requests remain linked for #8463, #9019, #10645 and #10943. No agreement or combined runtime validation of those external PRs is claimed. The overlap report includes inconclusive comparisons for older base-conflicting PRs. Its live base d13b3d7c55 has no libkernel changes after the pinned main; its libc drift is an unrelated 15-line vector-algorithm addition. recvfrom/sendto are moved existing wrappers, not new duplicate exports (the public-header audit verifies ownership). The report's #11969 row compares this PR's previous head before publication, not another implementation.

Tested

Current-main refresh (2026-10-28)

Merged upstream main 957a22d51f02ccacff218cdf9a27c36af7cc9aeb without rewriting published commits; resulting head 560f498196e7db59ef8b4f41463105dadb96e15a. The refreshed #11872 head 21d5a977f9 is an ancestor. Code merged automatically; the manual debt resolution retains main's #8916 sleep-cancellation behavior and this stack's read/write/flush/signal limitations. Original transport commits and authorship remain intact.

Linux x86-64 Ubuntu 24.04 container translated on Apple Silicon, GCC 13.3, Release, bundled dependencies built from source: production libc/libkernel and focused test targets build; 536/536 tests pass, zero skips. Selection consists of all registrations using guest_io_write_cancel_tests, guest_io_write_sync_cancel_tests, guest_io_read_cancel_tests, guest_io_descriptor_access_tests and guest_pthread_cancel_tests, run with ctest --test-dir /tmp/anyps5-build -R <exact selected names> --output-on-failure -j 4. This is translated-container evidence, not native Linux/Windows or console evidence; no full-suite or fresh title run. Signal/context tests are outside this selection.

Public-header audit: 368 libraries / 12,990 exports, unique declarations and umbrella coverage verified. Whitespace and conventions against actual upstream main pass (one inherited SSL debt-length warning). The required --base origin/main check also ran, but the fork's origin/main is still 0c6a5bd5938f; it reports upstream main's pre-existing non-Conventional revert subject 97f1d41a2c, rather than an error introduced by this refresh. The live tools/pr_overlap.py --branch refresh/posix-io-cancellation-writes --repo boykopovar/AnyPS5 --jobs 4 scan completed; existing unresolved overlaps/order and transport-publication constraints remain, with no new agreement claimed. Earlier evidence below remains attributed to its original revisions.

Windows 11 / WinLibs GCC 15.2 Release; Linux/WSL2 imav-tao / GCC 13.3 Release. Full production libs, relinker and focused-target builds pass on both systems.

  • 668/668 Windows and 712/712 Linux focused runtime tests pass, including patched-library loading. Public headers: Windows 65/65; Linux audit verifies 368 libraries / 12,811 exports, plus 64/64 compiler batches.
  • Real full pipes and loopback sockets cover backpressure, scalar/vector/positioned APIs, partial-progress byte accounting through EOF, peer drain/close, cancellation/completion races, disabled requests, aliases, close/reuse, cleanup/TSD, empty datagrams, append/shared offsets and admission locks. Existing reads, signals/contexts/nonlocal exits, borrowed libSceNet descriptors, AIO, SSL and transport mode/timeout tests are included.
  • Synchronous-write cancellation/zero-progress negative controls fail before their fixes on both OSes. A truly restricted Windows pipe duplicate reproduces guest EIO before the fallback repair; ordinary CreateFile handles silently retained attributes access and did not reproduce it. Two-byte/one-free-byte write/writev regressions return EAGAIN with unchanged queued bytes; the suggested partial-write failure was not reproduced on this backend.
  • 40/40 Linux preflight cases cover both metadata queries across write/writev/pwrite/pwritev, cancellation, disabled cancellation, completion, close and signals. Real FUSE GETATTR held before ordinary write requires external release at e87a337fee (zero bytes, no FUSE interrupt); the final head issues FUSE_INTERRUPT, cancels promptly and leaves zero bytes. Holding post-write synchronous classification also cancels promptly without external release and retains two buffered bytes. The private probe calls built production libraries; host libstdc++ preloading avoids unpatched libc guest-unwinder interposition in this host fixture.
  • Human Fall Flat PPSA02429 v01.017.000: same immutable relinked executable/assets, cold startup/no input on read, transport and final write heads, both OSes. Reaches rendering/save/network setup and actual blocking UDP recvfrom (flags 0), sends and title timeout/nonblocking-mode changes. The evidence comment gives all counts and capture limits. This is startup socket compatibility evidence, with no multiplayer/TCP-title, title cancellation/vector-write, complete playthrough, console, performance or title-unblock claim.

Fresh independent read-only MICRO/MACRO pairs reviewed the read repairs, transport composition and successive write candidates. Confirmed synchronous flush, restricted pipe and preflight metadata findings were fixed with regressions. The final pair reviewed dc7772e6e1 and found no remaining confirmed defect; both independently ran the 40 preflight cases. Earlier Windows address-waking fixture flakiness reproduces on the prerequisite baseline; this final serial suite passes.

Git diff --check and python3 tools/check_conventions.py --base origin/main pass with zero errors and one inherited SSL debt-length warning. tools/pr_overlap.py completes at the exact final head. No tracked notes/logs, new third-party dependency or source comments were added.

Limits remain in library debt: deferred cancellation only; non-interruptible drivers can delay cancellation/close, descriptor replacement and stdio closure can wait, Windows pipe quota readiness retries use 1 ms, and Windows blocking PEEK|WAITALL remains unsupported. macOS runtime and console behavior are unverified.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #11872; transport branch feat/posix-socket-transport (upstream PR blocked by author limit)
  • Fixes: none (the separate transport layer owns #10943)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5035276239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11969). Originally posted by [Felipebmaitan](https://github.com/Felipebmaitan) on 2026-10-27T14:07:34Z. --- ### What Implement milestone 2: a blocked POSIX write can be cancelled while retaining descriptor ownership until native operations drain. Completed positive counts, including partial counts, win; zero/error returns check pending cancellation after guards release. Disabled cancellation stays pending, and cleanup/TSD run exactly once after operation ownership ends. APIs: write, _write, writev, _writev, pwrite, pwritev, send, sendto, sendmsg, _sendto, _sendmsg. Paths include ordinary files, shared-memory objects, pipes, stream and datagram sockets. Positioned pipe/socket writes retain their existing errors. SCE and libSceNet gain no cancellation points. Accept/connect and multiplexed waits remain later milestones. The write layer reuses #11872's descriptor admission, signals and cancellation/close machinery. Native transports preserve known partial progress; Windows pipe vector transfers preserve small-write atomicity. Linux preflight metadata and synchronous flushes now participate in native interruption. An interrupted two-phase O_FSYNC write can leave buffered bytes visible without durable completion; it reports success only after flushing succeeds and never replays those bytes after interrupted flushing. Direct SCE flush behavior is preserved. Restricted-right Windows pipe handles fall back to their existing native write capability when attribute queries are denied. Stack: read 8c68efe40774567be1ea5801f330c0351727f518; transport 3c360d54ee73e5188358d0e97537be4ff728d1a8; write dc7772e6e18b612ede5b926496cf955251bfca1f. Includes pinned main 228cd64b538d456d68831dc1c7df7e8f43765626 and declared read prerequisites #10817/#10755 with original commits/authorship preserved. The transport branch preserves all six exact #10943 candidate commits through 6adaa5acdf716f37ecef7b410505f91d8a75b8b0. The standalone owning-TLS repair eebaac5b2483ca7bbda3b3f87f1f165abb3dae35 and descriptor export repair 45272246838fa21709c48de50e2208f8820e9019 belong to the read prerequisite. [Transport-only comparison](https://github.com/Felipebmaitan/AnyPS5/compare/8c68efe40774567be1ea5801f330c0351727f518...3c360d54ee73e5188358d0e97537be4ff728d1a8); [write-only comparison](https://github.com/Felipebmaitan/AnyPS5/compare/3c360d54ee73e5188358d0e97537be4ff728d1a8...dc7772e6e18b612ede5b926496cf955251bfca1f) (17 files, seven commits after transport). Publication constraint: CONTRIBUTING allows 20 open PRs while an author has 1-19 merged; this author has 20 open/17 merged. The separate transport branch is published but cannot have an upstream PR yet. This account lacks upstream push access and upstream has no read/transport base branch. This PR still targets main, so its Files changed includes prerequisites; the linked incremental comparison is write-only. A maintainer-provided upstream base or merged prerequisites is needed for a write-only upstream Files changed view. Overlap coordination: [#11872 tracker](https://github.com/boykopovar/AnyPS5/pull/11872#issuecomment-6441991970) explicitly covers #11896, #10645, #10552 and #11625. #11896 confirms reads first; external #10645/#10552 replies remain pending. #11625 source head is preserved. Write/carrier seam requests remain linked for [#8463](https://github.com/boykopovar/AnyPS5/pull/8463#issuecomment-6443677771), [#9019](https://github.com/boykopovar/AnyPS5/pull/9019#issuecomment-6443678612), [#10645](https://github.com/boykopovar/AnyPS5/pull/10645#issuecomment-6443679430) and [#10943](https://github.com/boykopovar/AnyPS5/issues/10943#issuecomment-6443032753). No agreement or combined runtime validation of those external PRs is claimed. The overlap report includes inconclusive comparisons for older base-conflicting PRs. Its live base d13b3d7c55a433c7a5040076d849dbe59fad4b53 has no libkernel changes after the pinned main; its libc drift is an unrelated 15-line vector-algorithm addition. recvfrom/sendto are moved existing wrappers, not new duplicate exports (the public-header audit verifies ownership). The report's #11969 row compares this PR's previous head before publication, not another implementation. ### Tested #### Current-main refresh (2026-10-28) Merged upstream main `957a22d51f02ccacff218cdf9a27c36af7cc9aeb` without rewriting published commits; resulting head `560f498196e7db59ef8b4f41463105dadb96e15a`. The refreshed #11872 head `21d5a977f9` is an ancestor. Code merged automatically; the manual debt resolution retains main's #8916 sleep-cancellation behavior and this stack's read/write/flush/signal limitations. Original transport commits and authorship remain intact. Linux x86-64 Ubuntu 24.04 container translated on Apple Silicon, GCC 13.3, Release, bundled dependencies built from source: production libc/libkernel and focused test targets build; **536/536 tests pass**, zero skips. Selection consists of all registrations using `guest_io_write_cancel_tests`, `guest_io_write_sync_cancel_tests`, `guest_io_read_cancel_tests`, `guest_io_descriptor_access_tests` and `guest_pthread_cancel_tests`, run with `ctest --test-dir /tmp/anyps5-build -R <exact selected names> --output-on-failure -j 4`. This is translated-container evidence, not native Linux/Windows or console evidence; no full-suite or fresh title run. Signal/context tests are outside this selection. Public-header audit: 368 libraries / 12,990 exports, unique declarations and umbrella coverage verified. Whitespace and conventions against actual upstream main pass (one inherited SSL debt-length warning). The required `--base origin/main` check also ran, but the fork's origin/main is still `0c6a5bd5938f`; it reports upstream main's pre-existing non-Conventional revert subject `97f1d41a2c`, rather than an error introduced by this refresh. The live `tools/pr_overlap.py --branch refresh/posix-io-cancellation-writes --repo boykopovar/AnyPS5 --jobs 4` scan completed; existing unresolved overlaps/order and transport-publication constraints remain, with no new agreement claimed. Earlier evidence below remains attributed to its original revisions. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 / WinLibs GCC 15.2 Release; Linux/WSL2 imav-tao / GCC 13.3 Release. Full production libs, relinker and focused-target builds pass on both systems. - **668/668 Windows** and **712/712 Linux** focused runtime tests pass, including patched-library loading. Public headers: Windows **65/65**; Linux audit verifies **368 libraries / 12,811 exports**, plus **64/64** compiler batches. - Real full pipes and loopback sockets cover backpressure, scalar/vector/positioned APIs, partial-progress byte accounting through EOF, peer drain/close, cancellation/completion races, disabled requests, aliases, close/reuse, cleanup/TSD, empty datagrams, append/shared offsets and admission locks. Existing reads, signals/contexts/nonlocal exits, borrowed libSceNet descriptors, AIO, SSL and transport mode/timeout tests are included. - Synchronous-write cancellation/zero-progress negative controls fail before their fixes on both OSes. A truly restricted Windows pipe duplicate reproduces guest EIO before the fallback repair; ordinary CreateFile handles silently retained attributes access and did not reproduce it. Two-byte/one-free-byte write/writev regressions return EAGAIN with unchanged queued bytes; the suggested partial-write failure was not reproduced on this backend. - **40/40 Linux preflight cases** cover both metadata queries across write/writev/pwrite/pwritev, cancellation, disabled cancellation, completion, close and signals. Real FUSE GETATTR held before ordinary write requires external release at e87a337fee (zero bytes, no FUSE interrupt); the final head issues FUSE_INTERRUPT, cancels promptly and leaves zero bytes. Holding post-write synchronous classification also cancels promptly without external release and retains two buffered bytes. The private probe calls built production libraries; host libstdc++ preloading avoids unpatched libc guest-unwinder interposition in this host fixture. - **Human Fall Flat PPSA02429 v01.017.000**: same immutable relinked executable/assets, cold startup/no input on read, transport and final write heads, both OSes. Reaches rendering/save/network setup and actual blocking UDP recvfrom (flags 0), sends and title timeout/nonblocking-mode changes. The evidence comment gives all counts and capture limits. This is startup socket compatibility evidence, with no multiplayer/TCP-title, title cancellation/vector-write, complete playthrough, console, performance or title-unblock claim. Fresh independent read-only MICRO/MACRO pairs reviewed the read repairs, transport composition and successive write candidates. Confirmed synchronous flush, restricted pipe and preflight metadata findings were fixed with regressions. The final pair reviewed dc7772e6e18 and found no remaining confirmed defect; both independently ran the 40 preflight cases. Earlier Windows address-waking fixture flakiness reproduces on the prerequisite baseline; this final serial suite passes. Git diff --check and python3 tools/check_conventions.py --base origin/main pass with zero errors and one inherited SSL debt-length warning. tools/pr_overlap.py completes at the exact final head. No tracked notes/logs, new third-party dependency or source comments were added. Limits remain in library debt: deferred cancellation only; non-interruptible drivers can delay cancellation/close, descriptor replacement and stdio closure can wait, Windows pipe quota readiness retries use 1 ms, and Windows blocking PEEK|WAITALL remains unsupported. macOS runtime and console behavior are unverified. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> #11872; transport branch feat/posix-socket-transport (upstream PR blocked by author limit) - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none (the separate transport layer owns #10943) - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11969
No description provided.