feat(libkernel): support macOS pipe write readiness #13560

Merged
SHOnnay merged 2 commits from upstream-pr/13560 into main 2026-11-08 07:36:23 +00:00
SHOnnay commented 2026-10-30 18:17:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SHOnnay on 2026-10-30T18:17:35Z.


What

On macOS, GuestSockets::PipeWriteState threw for the write end of an anonymous pipe, so guest pipe-write events could not query readiness. The macOS branch now uses a private host kqueue with EVFILT_WRITE, a zero timeout and close-on-exec. It reports available host-buffer space when writable and zero with EOF when the reader closes. Each snapshot creates a queue, which is closed on success and exception paths; interrupted queries retry and other host errors throw with the host errno.

The Linux and Windows branches of PipeWriteState are byte-for-byte unchanged. Host buffer capacity remains different from FreeBSD's 16 KiB buffer, as recorded in the existing debt entry. Reverse-direction pipe events remain unsupported. Named FIFOs also remain unsupported: on this Mac, the host reports a FIFO writable after its reader closes without EOF, although a write fails with EPIPE. F_GETPATH distinguishes vnode-backed FIFOs from anonymous pipes; XNU returns EBADF for a non-vnode descriptor before attempting path lookup.

Contract sources:

The isolated fixture compiles production Udp.cpp directly, using dead stripping to discard unrelated runtime functions. A dedicated, file-gated CI job builds it on macos-15-intel and macos-15, following the write-watch job's checkout/merge pattern.

Related:

  • #10645 adds pipe-write support to sceKernelAddWriteEvent through this helper and explicitly leaves the macOS helper throwing. This backend does not require that PR.
  • #12741 adds the macOS EV_CLEAR edge-watch backend. This PR implements readiness snapshots; EV_CLEAR still requires an edge-watch backend. The fixture builds and passes against upstream/main without #12741.

Tested

macOS 27.0.1 (26A434), Apple M1. Native ARM64 and x86-64 under Rosetta were tested. Physical Intel macOS, Linux, Windows, a GPU and full guest titles were not run locally. The isolated fixture does not establish full guest-runtime kevent behavior.

Clean upstream/main baseline (4bc9e779aa7abb2109c65ee3bca19e1b85df3be8):

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_RELINKER_ONLY=ON
cmake --build build
ctest --test-dir build --output-on-failure

Result: 100% tests passed out of 522 (268.00 seconds).

Regression fixture:

cmake -S core/libs/tests/pipe_write -B build/pipe-write -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build/pipe-write
ctest --test-dir build/pipe-write --output-on-failure

With upstream/main's unchanged Udp.cpp, 7 of 9 cases fail (ready, full, threshold, EOF, duplicate, cleanup and descriptor exhaustion); invalid descriptors and the unsupported FIFO boundary pass. With the fix, 9/9 pass. The threshold case drains 511 bytes from a full pipe (not writable), then one more (writable, data 512), then another 512 (data 1024). Other cases cover repeated level snapshots, empty/full reader closure, duplicated descriptors, linked/unlinked FIFOs, descriptor leaks, and recovery after EMFILE.

ctest --test-dir build/pipe-write --output-on-failure --repeat until-fail:20
cmake -S core/libs/tests/pipe_write -B build/pipe-write-x86 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64
cmake --build build/pipe-write-x86
ctest --test-dir build/pipe-write-x86 --output-on-failure
ctest --test-dir build/pipe-write-x86 --output-on-failure --repeat until-fail:20

Result: 180/180 successful executions on ARM64; 9/9 and 180/180 under Rosetta.

cmake --build build
ctest --test-dir build -j4 --output-on-failure
python3 tools/tests/test_build_eligibility.py
python3 tools/check_conventions.py --base upstream/main
actionlint -oneline .github/workflows/build.yml

Results: relinker-only 522/522 (72.21 seconds); eligibility 10/10; conventions zero errors with the existing debt-length warning on the edited pipe entry (base 1230 characters, branch 1329); actionlint no new findings compared with upstream/main. Additional harness checks verified the new job's affected/unaffected paths for PR and manual runs, with full=true and full=false. The new output mirrors write-watch selection on push runs.

Overlap check: python3 tools/pr_overlap.py --branch codex/feat-macos-pipe-write checked 1597 open PRs. It reported 42 uncompared PRs because those branches conflict with main, ending with overlap check failed closed; manually compare every reported PR branch before opening this one. This is not a clean automated result. Every reported shared-file diff was inspected from its true merge base. None implements this macOS readiness helper; the shared Udp.cpp heads retain the macOS throw or predate the helper. None changes this PR's pipe-debt bullet. #12741 adds distinct edgeWatch/edge-watch workflow settings while this PR adds pipeWrite/pipe-write; keeping both is an integration/rebase concern, not a build dependency. Other shared debt-file topics are independent.

Uncompared PRs: #4630, #5021, #6936, #7088, #7105, #7121, #7135, #7149, #7192, #7447, #7464, #7509, #7804, #8605, #9156, #9242, #9293, #9297, #9302, #9326, #9389, #9557, #9566, #9843, #9938, #10025, #10442, #10552, #10645, #11215, #11628, #11661, #11689, #11698, #11939, #12682, #12688, #12700, #12741, #12925, #12965, #12970.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5089061468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13560). Originally posted by [SHOnnay](https://github.com/SHOnnay) on 2026-10-30T18:17:35Z. --- ### What On macOS, `GuestSockets::PipeWriteState` threw for the write end of an anonymous pipe, so guest pipe-write events could not query readiness. The macOS branch now uses a private host kqueue with `EVFILT_WRITE`, a zero timeout and close-on-exec. It reports available host-buffer space when writable and zero with EOF when the reader closes. Each snapshot creates a queue, which is closed on success and exception paths; interrupted queries retry and other host errors throw with the host errno. The Linux and Windows branches of `PipeWriteState` are byte-for-byte unchanged. Host buffer capacity remains different from FreeBSD's 16 KiB buffer, as recorded in the existing debt entry. Reverse-direction pipe events remain unsupported. Named FIFOs also remain unsupported: on this Mac, the host reports a FIFO writable after its reader closes without EOF, although a write fails with `EPIPE`. `F_GETPATH` distinguishes vnode-backed FIFOs from anonymous pipes; XNU returns `EBADF` for a non-vnode descriptor before attempting path lookup. Contract sources: - [Apple kevent(2), EVFILT_WRITE](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kevent.2.html): buffer space and reader-disconnect EOF. - [FreeBSD 11.4 filt_pipewrite, lines 1813–1834](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/sys_pipe.c#L1813-L1834): zero data and EOF on closure; otherwise available space and readiness at PIPE_BUF. - [XNU F_GETPATH, lines 3805–3813](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/kern/kern_descrip.c#L3805-L3813): non-vnode descriptors return EBADF. The isolated fixture compiles production `Udp.cpp` directly, using dead stripping to discard unrelated runtime functions. A dedicated, file-gated CI job builds it on `macos-15-intel` and `macos-15`, following the write-watch job's checkout/merge pattern. Related: - #10645 adds pipe-write support to `sceKernelAddWriteEvent` through this helper and explicitly leaves the macOS helper throwing. This backend does not require that PR. - #12741 adds the macOS EV_CLEAR edge-watch backend. This PR implements readiness snapshots; EV_CLEAR still requires an edge-watch backend. The fixture builds and passes against upstream/main without #12741. ### Tested <!-- 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. --> macOS 27.0.1 (26A434), Apple M1. Native ARM64 and x86-64 under Rosetta were tested. Physical Intel macOS, Linux, Windows, a GPU and full guest titles were not run locally. The isolated fixture does not establish full guest-runtime kevent behavior. Clean upstream/main baseline (`4bc9e779aa7abb2109c65ee3bca19e1b85df3be8`): ```sh cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_RELINKER_ONLY=ON cmake --build build ctest --test-dir build --output-on-failure ``` Result: `100% tests passed out of 522` (268.00 seconds). Regression fixture: ```sh cmake -S core/libs/tests/pipe_write -B build/pipe-write -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build build/pipe-write ctest --test-dir build/pipe-write --output-on-failure ``` With upstream/main's unchanged `Udp.cpp`, 7 of 9 cases fail (ready, full, threshold, EOF, duplicate, cleanup and descriptor exhaustion); invalid descriptors and the unsupported FIFO boundary pass. With the fix, 9/9 pass. The threshold case drains 511 bytes from a full pipe (not writable), then one more (writable, data 512), then another 512 (data 1024). Other cases cover repeated level snapshots, empty/full reader closure, duplicated descriptors, linked/unlinked FIFOs, descriptor leaks, and recovery after EMFILE. ```sh ctest --test-dir build/pipe-write --output-on-failure --repeat until-fail:20 cmake -S core/libs/tests/pipe_write -B build/pipe-write-x86 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64 cmake --build build/pipe-write-x86 ctest --test-dir build/pipe-write-x86 --output-on-failure ctest --test-dir build/pipe-write-x86 --output-on-failure --repeat until-fail:20 ``` Result: 180/180 successful executions on ARM64; 9/9 and 180/180 under Rosetta. ```sh cmake --build build ctest --test-dir build -j4 --output-on-failure python3 tools/tests/test_build_eligibility.py python3 tools/check_conventions.py --base upstream/main actionlint -oneline .github/workflows/build.yml ``` Results: relinker-only 522/522 (72.21 seconds); eligibility 10/10; conventions zero errors with the existing debt-length warning on the edited pipe entry (base 1230 characters, branch 1329); actionlint no new findings compared with upstream/main. Additional harness checks verified the new job's affected/unaffected paths for PR and manual runs, with full=true and full=false. The new output mirrors write-watch selection on push runs. Overlap check: `python3 tools/pr_overlap.py --branch codex/feat-macos-pipe-write` checked 1597 open PRs. It reported 42 uncompared PRs because those branches conflict with main, ending with `overlap check failed closed; manually compare every reported PR branch before opening this one`. This is not a clean automated result. Every reported shared-file diff was inspected from its true merge base. None implements this macOS readiness helper; the shared `Udp.cpp` heads retain the macOS throw or predate the helper. None changes this PR's pipe-debt bullet. #12741 adds distinct `edgeWatch`/`edge-watch` workflow settings while this PR adds `pipeWrite`/`pipe-write`; keeping both is an integration/rebase concern, not a build dependency. Other shared debt-file topics are independent. Uncompared PRs: #4630, #5021, #6936, #7088, #7105, #7121, #7135, #7149, #7192, #7447, #7464, #7509, #7804, #8605, #9156, #9242, #9293, #9297, #9302, #9326, #9389, #9557, #9566, #9843, #9938, #10025, #10442, #10552, #10645, #11215, #11628, #11661, #11689, #11698, #11939, #12682, #12688, #12700, #12741, #12925, #12965, #12970. ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes (Codex) <!-- yes / no -->
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!13560
No description provided.