Repository navigation
fix(libkernel): take NOTE_LOWAT on socket read and write events - #7092
Conversation
kevent threw for NOTE_LOWAT. On a socket's EVFILT_READ it now sets the low-water mark as FreeBSD 11's filt_soread does: the event fires once the buffered bytes reach it, or at end of file or on a listening socket, and a later change of the knote replaces it. EVFILT_WRITE takes a mark of 1, where the host's writability stands in for a free byte; other write marks and marks below 1 still throw. A pipe ignores the mark, as filt_piperead does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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. |
…ream sockets On Linux, FIONREAD on a datagram socket reports the next datagram only, where FreeBSD's sbavail counts every queued byte, so a read mark above 1 there could never fire. kevent now throws for it as before; stream sockets and marks of 1 are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @oneandonlydean, good catch on the datagram case. 91fbafd keeps throwing for a read mark above 1 on any socket that isn't a stream (a new I left AI-assisted: yes (Claude Code) |
|
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.
Some 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.
|
XNU's FIONREAD on a datagram socket counts the queued sender addresses as well as the payload (35 bytes for one byte on an AF_UNIX pair, 51 over UDP), so kevent reported that size as EVFILT_READ data and fstat as st_size. With NOTE_LOWAT now honoured (boykopovar#7092), guest_kqueue saw the inflated count and aborted. SO_NREAD returns the next datagram's size, which matches Linux and the ioctl(FIONREAD) path in this file already uses it for datagrams. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XNU's FIONREAD on a datagram socket counts the queued sender addresses as well as the payload (35 bytes for one byte on an AF_UNIX pair, 51 over UDP), so kevent reported that size as EVFILT_READ data and fstat as st_size. With NOTE_LOWAT now honoured (boykopovar#7092), guest_kqueue saw the inflated count and aborted. SO_NREAD returns the next datagram's size, which matches Linux and the ioctl(FIONREAD) path in this file already uses it for datagrams. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XNU's FIONREAD on a datagram socket counts the queued sender addresses as well as the payload (35 bytes for one byte on an AF_UNIX pair, 51 over UDP), so kevent reported that size as EVFILT_READ data and fstat as st_size. With NOTE_LOWAT now honoured (boykopovar#7092), guest_kqueue saw the inflated count and aborted. SO_NREAD returns the next datagram's size, which matches Linux and the ioctl(FIONREAD) path in this file already uses it for datagrams. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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,
main864729d.LowWaterMarkscase inguest_kqueue:data4.NOTE_LOWATbrings back the default, and end of file fires below the mark.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 (feat(libkernel): declare physhm_open and physhm_unlink #6915, fix(libkernel): export sysarch so modules that import it load #6028, fix(libSceSystemService): declare the PsmKit local process exports #6939, feat(libSceKeyboard): export missing firmware functions from database #6787, feat(libkernel): report the guest address-space map through kern.proc.vmmap #7070, fix(memory): honor low guest mapping hints #6469, feat(libkernel): pass descriptors in SCM_RIGHTS messages on Unix sockets #7090), it stops 1 s in onkevent: NOTE_LOWAT not implemented, 2 of 2.sysarch, which fix(libkernel): export sysarch so modules that import it load #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