feat(libkernel): support EVFILT_READ on the read end of a pipe #5973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5973"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-14T17:38:41Z.
What
keventthrewkevent: EVFILT_READ on a non-socket descriptorfor anything that isn't a guest socket. Java 25 Networking (PPSA99868) stops there onmain, in itsNIO channels and selectorstage: the JDK's kqueue selector opens a pipe and registers its read end withEVFILT_READ/EV_ADDto wake itself up (KQueueSelectorImpl.java L84-L95).EVFILT_READnow works on the read end of a pipe, following FreeBSD 11'sfilt_piperead:datais the number of buffered bytes (L1794),EV_EOFis set once the write end is closed (L1798-L1803), and the event is active while either holds (L1804). It uses the same host checks #3644 added forpoll:GuestSockets::PipeReadState(new, next toReady) reads the buffered byte count and whether the write end is gone:NtQueryInformationFileon Windows, the queryPipeReadinessmakes;FIONREADandPOLLHUPon Linux.PipeReadinessand #5013'sPipeReadyonly report poll bits, so they don't givedata; both are untouched.GuestSockets::Ready, which the descriptor knote polls, falls back to it for a descriptor that isn't a socket.GuestSockets::WaitAnyputs the pipe in the hostppollon Linux, with a read mask: its only caller, the equeue wait, gets non-socket interests only from these knotes. Windows can't wait on a pipe, so there an infinite or longerWSAPollis cut to 1 ms, only when the queue has a non-socket interest.WSAStartupitself, assocketandsocketpairalready do. A kqueue can now wait on a pipe before the process has opened any socket, and the waker's loopback socket failed then withequeue waker: loopback socket setup failed, guest errno 5.Still throwing:
EVFILT_WRITEon a pipe,EVFILT_READon the write end (FreeBSD opens both ends for reading and writing,kern_pipeL422; host pipes are one-way), andEV_CLEARandNOTE_LOWATon a pipe. A newkevent on a pipeentry in the debt doc lists them, along with the 1 ms slices.pr_overlap flags #5847 (
EV_DISABLE,EV_DISPATCH,EV_FORCEONESHOT) and #5493 on the kqueue entry ofdocs/dev/debt/libkernel.md. This PR only changes two phrases on that line, the pointer to the new entry andEV_CLEARon a pipe, so whichever goes second keeps both.Kqueue.cppandGuestKqueue.cppmerge cleanly with #5847.Tested
Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release, on
mainf3b5daaf8:guest_kqueuepasses 5/5. The new case registers the read end and checks that it's quiet. Then 3 bytes givedata == 3and noEV_EOF, and akeventwith a 5 s timeout returns the event after a write from another thread at 50 ms. Closing the write end givesEV_EOFwith the 1 byte still buffered, anddata == 0once it's read.maine34c47921, with the source changes reverted and the test kept, it aborts withkevent: EVFILT_READ on a non-socket descriptor not implemented. With only the 1 ms cut removed, thatkeventcomes back at the 5 s timeout instead and the test fails after 5.35 s, so it can't hang CI. Without the waker'sWSAStartup, it aborts withequeue waker: loopback socket setup failed, guest errno 5, since the pipe case runs before any socket is opened.guest_poll,guest_select,guest_equeue_events,guest_socket_*,guest_tcp,guest_udp,guest_sce_net, ...) pass, 31/31. The full suite passed one34c47921, 1198/1198.Linux, Ubuntu 26.04 under WSL 2, GCC 15.2.0, CMake 4.2.3, Ninja Release,
BUILD_TESTING=ON, on the same commit, from an archive of this branch with its submodules.FFMPEG_PREBUILT_DIRpoints at the headers of the local Windows FFmpeg package instead of downloading the Linux one, and none of the built targets link FFmpeg. I built the targets of the tests below and ran them, not the whole suite:guest_kqueuepasses 5/5. WithKqueue.cpp,Udp.cppandSocketRuntime.hppfrommain, it aborts with the samekevent: EVFILT_READ on a non-socket descriptor not implemented.guest_dup,guest_equeue_events,guest_kernel_fcntl,guest_poll,guest_rudp_*,guest_sce_net,guest_select,guest_select_wait,guest_socket_*,guest_tcp,guest_udpandguest_kqueuepass, 19/19.Java 25 Networking (PPSA99868, 01.000.003, SHA-256
9765536f274f3b3e35922b29564ac67afc7cfe979df5d8f3cf5f2a3b3649ebc2, matching the release'sSHA256SUMS), relinked with--trap-sdk-syscall-stubs, onmaine34c47921:main, the third row stops right afterSTAGE: Network: NIO channels and selectorwithwhat(): kevent: EVFILT_READ on a non-socket descriptor not implemented.STAGE: Network25 returned normally, thenSTAGE: DestroyJavaVM complete, as on the console.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T06:42:56Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/Equeue/src/Kqueue.cppL137-139docs/dev/debt/libkernel.mdL112docs/dev/debt/libkernel.mdL111-112docs/dev/debt/libkernel.mdL173Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestKqueue.cppcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T07:27:13Z.
Review: COMMENTED
Windows check of head
46d49131e, merged ontomain5d9dcc42d(clean merge). Windows 11 Pro (26300), Ryzen 5 3600, RTX 3060, WinLibs GCC 15.2.0 r7, Ninja Release.Title: Java 25 Networking (PPSA99868, 01.000.003, SHA-256
9765536f…bc2, matching the release'sSHA256SUMS), relinked with--windows --to-intel --trap-sdk-syscall-stubs --registry. Onmainthe third row stopped right afterSTAGE: Network: NIO channels and selectorwithkevent: EVFILT_READ on a non-socket descriptor not implemented. With this PR, all four rows pass:Tests:
guest_kqueue,guest_poll,guest_select*,guest_equeue*,guest_socket*,guest_tcp,guest_udp,guest_sce_net*: 29 of 29 pass.Code: I checked the Windows wait path for the case where an equeue waits only on pipes.
entriescan then hold no socket, but the thread's waker socket is always appended, soWSAPollnever gets an empty array, and the 1 ms slices only apply while a pipe interest is present.PipeReadStatetells the read end from the write end byFILE_READ_DATAon Windows andO_ACCMODEon Linux, which matches the new throwing cases inErrors(). I found no issue.AI-assisted: yes. I ran the build, the tests and the title above.
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T10:54:15Z.
Windows run of head
46d49131e, merged ontomain5d9dcc42dtogether with #6064 (libSceSysmodule only, no shared file; both merges clean).alignasAGC test (#6452/#6478).libspasses, with no warnings in the changed files.--repeat until-fail:3, 102/102 runs:guest_kqueuetogether withguest_poll,guest_select,guest_select_wait,guest_equeue_events,guest_dup,guest_kernel_fcntl,guest_tcp,guest_udp,guest_sce_net, the 21guest_socket_*tests and the 3guest_rudp_*tests.Kqueue.cpp,Udp.cppandSocketRuntime.hppfrommainand the test kept,guest_kqueueaborts withkevent: EVFILT_READ on a non-socket descriptor not implemented.WSAPollcut removed, the 5 skeventwait times out and the test fails after 7.58 s.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): 834/837, 2 skipped. Two load timeouts passed serially.guest_memoryfailed once at its host-wide commit-charge check, then passed serially and passed a second 10x run 10/10; it is not related to this change.tools/check_conventions.py --base 5d9dcc42dandgit diff --checkpass. There are no new exports.Titles: PPSA99868 is not available here. In the relinked titles I have,
keventis imported by PPSA99169, PPSA99360, PPSA99420 and PPSA99764, andkqueueby the first three. I ran each for 45 s with a local diagnosticlibkernelthat logskqueue/keventcalls and the filter of each change. None of them calledkqueueorkeventin that window (for PPSA99169 this coversapp.exeonly, not its picker child). So no local title reaches this path, and I ran no title before/after.Notes on the diff, none blocking:
PipeReadStaterepeats theNtQueryInformationFileaccess and pipe-information query fromPipeReadiness. A shared helper would remove the copy.WaitAnysetspipesfor any interest that is not a guest socket, not only for pipes. That is equivalent today, but a later non-socket knote would get 1 ms polling without anyone noticing.keventwakes about every 1 ms, which is the JDK selector's idle state. The debt entry documents this; I did not measure the CPU cost.Not checked: Linux, PPSA99868.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-16T13:44:31Z.
Thanks for the run.
Done in
647b5a1c9: both go throughQueryPipenow. I'd kept them apart while #5013 was open, to stay out of its way, and it's merged now. On Windows,guest_kqueue,guest_pollandguest_selectpass 5/5, and the 34 socket, poll and equeue tests pass.Right. Today that only happens for pipes:
AddDescriptorKnotethrows for any other non-socket descriptor, andsceKernelAddReadEvent/sceKernelAddWriteEventdon't add non-socket knotes. Whoever lifts one of those throws for another descriptor type has to go through this path anyway, so I left it. I can rename the flag if you think that reads better.Yes, same as
pollon a pipe since #3644. I didn't measure the CPU cost either.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:16:36Z.
Checked on Linux (build +
guest_kqueue,guest_poll,guest_select,guest_select_wait,guest_equeue_eventsall pass;guest_kqueuefails with the source changes reverted), against FreeBSD'sfilt_piperead, and the Windows runs from @karimibrahim07 and @screamm; merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:09:42Z.
Re-checked against current
main: the only shared file that changed isUdp.cpp(#5141, a Windows-only check inconnect), unrelated to the pipe path. Build +guest_kqueue,guest_poll,guest_select,guest_select_wait,guest_equeue_events,guest_tcpandguest_udppass on Linux, and the Windows runs from @karimibrahim07 and @screamm cover the Windows branch; merging once the full Build is green.