fix(libkernel): take NOTE_LOWAT on socket read and write events #7092
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7092"
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 milescoviello on 2026-10-17T11:10:04Z.
What
keventthrewNOTE_LOWAT not implemented. Wine's wineserver registers each of its sockets withEVFILT_READandEVFILT_WRITEcarryingNOTE_LOWATand a mark of 1, so Forever Launcher (PPSA99030) stops on it as its wineserver starts.NOTE_LOWATnow sets the low-water mark of a socket's read and write events, as FreeBSD 11'sfilt_soreadandfilt_sowritereadkn_sdata:EVFILT_READon a socket fires once the buffered bytes reach the mark. It also fires at end of file, and on a listening socket, which FreeBSD checks before the mark. A read mark above 1 is taken on stream sockets only. On a datagram socket, Linux'sFIONREADreports only the next datagram, where FreeBSD'ssbavailcounts every queued byte, so such a mark throws.EVFILT_WRITEon a socket takes a mark of 1. The host's writability stands in for one free byte, since the host doesn't report the send buffer's free space. Other write marks throw.NOTE_LOWAT), askqueue_registerreplaceskn_sdata.filt_pipereaddoes.The debt entries say the same.
Tested
Ubuntu 24.04, GCC 13.3, Release,
main864729dc0d.LowWaterMarkscase inguest_kqueue:data4.NOTE_LOWATbrings back the default, and end of file fires below the mark.91fbafd94a, after review).main'sKqueue.cppthe test aborts onkevent: NOTE_LOWAT not implemented. It passes 3 of 3.ctest -R '^guest_|libc': 401 of 401 pass.keventaddsEVFILT_READ(EV_ADD | EV_ENABLE) andEVFILT_WRITE(EV_ADD | EV_DISABLE) on one end of a socket pair, both withNOTE_LOWATand data 1.mainwith the PRs for its earlier stops merged locally (#6915, #6028, #6939, #6787, #7070, #6469, #7090), it stops 1 s in onkevent: NOTE_LOWAT not implemented, 2 of 2.sysarch, which #6028 declares as throwing.#7075, #7088 and #7049 change lines next to these in
Kqueue.cpp,GuestKqueue.cppand the libkernel debt file (#7075 also edits the two debt lines that listNOTE_LOWATas throwing). The conflicts are textual, and I'll rebase this one if any of them lands first.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T11:17:48Z.
Thanks, this matches FreeBSD 11's filt_soread/filt_sowrite well: the listening-socket bypass, EOF/error firing past the mark, write mark 1 only, the mark reset on re-add, and pipes ignoring the flag all look right.
One change before merge: on Linux, FIONREAD on a UDP socket returns the size of the next datagram only (udp_ioctl -> first_packet_length), while FreeBSD's sbavail counts every queued byte (Windows also returns the total). So with a read mark N > 1 on a datagram socket and several small datagrams queued whose total reaches N, FreeBSD fires and this never does. That turns a loud "not implemented" throw on main into a silent hang. Could you keep throwing for a read mark above 1 on non-stream sockets (or, if you need it, sum the queue some other way)? Wine's mark 1 isn't affected.
Minor, optional: Listening() does a getsockopt on every poll of a below-mark socket. It's cheap, but could be cached once the socket starts listening.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T11:20:45Z.
Thanks @oneandonlydean, good catch on the datagram case.
91fbafd94akeeps throwing for a read mark above 1 on any socket that isn't a stream (a newGuestSockets::Type), and adds a datagram case to the test: a read mark of 2 throws, and a mark of 1 fires on a one-byte datagram. Stream sockets and Wine's mark of 1 are unchanged, and the debt entry says why.guest_kqueuepasses 3 of 3 and still fails withmain'sKqueue.cpp.I left
Listening()uncached: it only runs while a socket is below its mark, and a cached flag would need updating fromlistenandclose.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T11:22:02Z.
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.cppL129docs/dev/debt/libkernel.mdL112docs/dev/debt/libkernel.mdL111-112core/libs/tests/GuestKqueue.cppL652docs/dev/debt/libkernel.mdL112, L174core/libs/prx/libkernel/Equeue/src/Kqueue.cppL129, L222-224docs/dev/debt/libkernel.mdL112, L174core/libs/prx/libkernel/Equeue/src/Kqueue.cppL222-228docs/dev/debt/libkernel.mdL112-113core/libs/prx/libkernel/Equeue/src/Kqueue.cppL129, L145-147, L151core/libs/prx/libkernel/Socket/include/SocketRuntime.hppL18core/libs/tests/GuestKqueue.cppL272docs/dev/debt/libkernel.mdL112, L173-174docs/dev/debt/libkernel.mdL173-174docs/dev/debt/libkernel.mdL173-174Some 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.mdcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/prx/libkernel/Equeue/Equeue.cppcore/libs/prx/libkernel/Equeue/Equeue.hppcore/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.mdcore/libs/prx/libkernel/Socket/src/Udp.cpp