feat(libkernel): carry kqueue read and write events on pipes and terminals #4910
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4910"
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 VitzS7 on 2026-10-13T03:46:18Z.
What
A read or write event on a descriptor that is not a guest socket threw, in
keventand insceKernelAddReadEvent/sceKernelAddWriteEventalike, so a title that registers one on a pipe or on the console could not do it at all.The kind of the descriptor now decides, following FreeBSD 11's filter sets: a socket, a pipe and a terminal carry the read and write filters (
filt_soread,filt_sowrite,filt_piperead,filt_pipewrite, andtty_kqops_read_event/tty_kqops_write_eventbehindttydev_kqfilter), a file and a directory only carry the vnode filter and answerEINVALasfilt_fileattachdoes, and so does a character device that is not a terminal, askqueue_registeranswersEINVALfor a filter the descriptor has none of. The kind isGuestSockets::Kind, which asks the socket table first and then the host descriptor type — never a number range, since socket descriptors are ordinary ones — and it is kept in the knote, the wayf_attachfixes the filter at registration, so a terminal revoked later still reports its end of file through the terminal filter.The pipe filters report what
filt_pipereadandfilt_pipewritedo: a read event carries the bytes in the pipe buffer and returns once there is any, a write event carries the free space the host exposes and returns once there is any, and an end of file is set when the other end is closed. A terminal reports the bytes of a readable canonical line, which is whatttydisc_read_pollcounts throughttyinq_bytescanonicalized, and the space left in its output queue, whichttydisc_write_pollcounts throughttyoutq_bytesleftand the host does not expose, so a writable terminal carries the lower bound of one byte. The low water mark (NOTE_LOWAT, or thesizeof the two calls) holds any of them below the mark.Two things were needed for a wait to see a descriptor that is not a socket: the mark path and the wait now share one readiness helper, and
GuestSockets::WaitAnyadds a pipe descriptor to the set it polls, without which a thread blocked inkeventwould never wake on it. Windows pipes are not sockets andWSAPollcannot take them, so there the wait returns every millisecond instead.Tested
Linux (Fedora 44, GCC 16.2.1), full build,
ctest --test-dir build -E "agc_|video_out|lds_|msaa"534/534,python3 tools/check_conventions.py --base origin/mainclean.New cases:
GuestKqueue.cppregisters a read and a write event on a pipe, checks that an empty pipe is not readable, that the write event reports free space, that a read event reports the bytes in the buffer, that aNOTE_LOWATmark holds it below the mark and that the last writer closing setsEV_EOF; it does the same for a terminal over a host pty, where a partial line is not readable, a complete one reports its bytes, the terminal going away setsEV_EOF, and a device with no filters of its own answersEINVAL; a file, a directory and a closed descriptor answerEINVALandEBADF, replacing the assertions that a pipe threw.GuestSocketEvents.cppdoes the same throughsceKernelAddReadEvent'ssizeon a pipe and on a terminal, with the wait blocked on its own equeue and a thread writing, so a wait that does not see them fails instead of passing silently.Not tested on the console, and not reached at run time yet: PS5MC (PPSA99420) and XPSemu (PPSA97358) import
keventand both calls, andtools/import_audit.pyon their relinked registries reports them as stubs, but each stops earlier on an absent import (ixrw0h2tWuI,chflags, andx7g7Ebeo8-U,mlockall) that this PR does not touch. The semantics follow the FreeBSD 11 sources the existing filters were written from (kern_event.c,uipc_socket.c,tty.c,sys/sys/ttyqueue.h).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)keventand these calls; neither reaches them yetNote on coordination: #4391 gives guest sockets ordinary descriptors and rewrites the socket checks of this file to socket-table membership. This PR takes the membership check with it (in
DescriptorFilterErrorand by asking the socket table before the host descriptor type), so the two do not have to be merged in a particular order.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T04:45:31Z.
Progress report (
dacd785→6f51e1d)📈 System libraries: 88.21% (+0.06%, +2 implemented functions)
✅ 2 implemented
sceKernelAddReadEventsceKernelAddWriteEventImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T06:15:47Z.
Windows test: head
ca734ca92merged onto currentmain88107b7de(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_kqueue|guest_socket_event: guest_kqueue passed, guest_socket_events passed (2 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-13T06:29:04Z.
Thanks for the Windows run — that is the one platform I cannot check here, so it closes half of the checklist.
The other half, which your note says you did not run: the cases this PR adds fail on
mainwithout it. Onmaina read or write event on a pipe or a terminal throws, andsceKernelAddReadEventandsceKernelAddWriteEventthrow for either, soguest_kqueueaborts at the pipe case (it asserted that throw before this PR) andguest_socket_eventsat thesizecase, rather than passing silently.Coordination with #4924 and #4933
The overlap note points at the same lines of
Equeue.cpp, and there is a semantic side to it, since both PRs make libSceNet sockets ordinary descriptors as well.GuestSockets::Kind, which this PR introduces, answersEINVALfor a descriptor that is neither a libkernel socket, a pipe, a terminal, a file nor a directory. A libSceNet socket host descriptor is a socket, but it is not in the libkernel table, so today it would be classified as that last kind and a read or write event on it would answerEINVALwhere it should register a knote.Once #4924 or #4933 lands, the native lookup they register with libkernel is the natural source for that answer, and I am happy to rebase this on whichever lands first and ask it there instead of deriving the kind from the host descriptor alone.
Imported from boykopovar/AnyPS5. Originally posted by VitzS7 on 2026-10-13T19:49:23Z.
Rebased on current
main(dacd78525), which now carries #4391;Depends on: #4908still holds, since this branch sits on its two commits.Four files conflicted (
Equeue.cpp,Kqueue.cpp,SocketRuntime.hpp,Udp.cpp). The resolution keeps your socket-table membership work —DescriptorFilterErrorand theisSocketchecks stay as you wrote them — and puts the descriptor kind on top:GuestSockets::Kindasks the socket table first and the host descriptor type second, andAddDescriptorKnote/AddDescriptorEventuse it in place of the non-socket throw, so a pipe or a terminal registers a knote while a file answersEINVAL, exactly as the commit messages describe.One thing the rebuild caught, worth mentioning because it is the kind of thing a rebase hides:
GuestSockets::Poll(#4391) andGuestSockets::Kind(this PR) landed at the same place inUdp.cpp, and my first union of the two lost the brace that closesPoll, which the compiler then read as everything after it being nested inside that function. It is fixed inside the pipes commit, so the commit builds on its own.Local verification on
dacd78525+ this branch (cmake→python3 tools/check_test_registration.py build→cmake --build build→cmake --build build --target libs):ctest --test-dir build -E "agc_|video_out|lds_|msaa"570/570,guest_kqueue,guest_socket_eventsandguest_equeueincluded, andtools/check_conventions.py --base origin/mainclean.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:20:07Z.
Review: COMMENTED
The filter selection by descriptor kind follows FreeBSD's filter sets and looks right. One Windows timing point this extends to
kevent: a pipe in the set makesGuestSockets::WaitAnyloop with a 1 ms slice (WSAPoll(..., slice)when sockets are present,std::this_thread::sleep_for(1ms)otherwise). Both follow the coarse Windows timer, so each slice usually takes about 15.6 ms rather than 1 ms (#1471). That's why #4980 and #4754 move thepollandselectsleeps toPreciseSleepUs.For
keventthat matters more than forpoll. A thread parked inkeventon a pipe (an event loop's wake-up pipe, a log pipe) now sees each write up to ~15 ms late. WithNOTE_LOWATfrom #4908 on top, the wait rechecks at the same coarse rate. UsingPreciseSleepUs(1000)for the pipe-only slice, and a high-resolution wait for the mixed case (for example a pipe-ready event, or splitting the socket wait into a 0-timeoutWSAPollplusPreciseSleepUs), would make "every millisecond" actually 1 ms. Since it's the shared loop, it could also be a separate small PR that both this and #4908 depend on.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T04:41:43Z.
Closing: no title is known to reach this. With the queue at 480+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed