Skip to content

feat(libkernel): create SOCK_SEQPACKET socketpairs on Windows - #23341

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
DannyOppenheimer:fix/libkernel-windows-seqpacket-socketpair
Nov 22, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
DannyOppenheimer:fix/libkernel-windows-seqpacket-socketpair

Conversation

@DannyOppenheimer

@DannyOppenheimer DannyOppenheimer commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

socketpair(AF_UNIX, SOCK_SEQPACKET) threw on Windows (socketpair: SOCK_SEQPACKET is not supported on Windows), a gap listed in the socketpair entry of docs/dev/debt/libkernel.md. Parallax Browser (PPSA99207, #23335) stops there about 2 s after start, in the socket probe of its UIProcess.

On Windows the pair is now two connected loopback UDP sockets, as SOCK_DGRAM already is, and the guest layer adds what UDP lacks for a connected record socket, as FreeBSD 11.4 gives it:

  • a receive returns 0 once the peer is closed or has shut down writing and nothing is queued; recv, recvfrom, recvmsg, read, the poll paths and kqueue readiness all see it (ReceiveEnded, which is ReceiveShut on Linux and macOS);
  • the peer's close (last descriptor) or shutdown(SHUT_WR) wakes readers blocked in a receive or poll (WakeReadWatchers), and poll reports POLLIN, with POLLHUP after a close (sopoll_generic after soisdisconnected);
  • a send after the peer is gone, or after the end's own shutdown(SHUT_WR), fails with EPIPE;
  • a sender waits, or fails with EAGAIN when non-blocking, with MSG_DONTWAIT or after SO_SNDTIMEO, while the receiver holds at least its SO_SNDBUF bytes. This follows FreeBSD 11.4: uipc_send sets SB_STOP on the sender's so_snd once the receiver holds sb_hiwat bytes, uipc_rcvd clears it below that, and sbspace is 0 while it is set. The queued bytes come from the receiver's FIONREAD, which on Windows is the total of all queued datagrams (Winsock IOCTLs: "not the size of the first datagram"; measured below). Without this, Windows drops records: a loopback UDP socket with the default 64 KiB buffer kept 8 of 100 8 KiB datagrams. Each end gets a 1 MiB host receive buffer and keeps it when the guest sets SO_RCVBUF, since FreeBSD appends a SOCK_SEQPACKET record without checking the receiver's space (sbappendaddr_nospacecheck_locked); the guest still reads back the value it set. Windows counts only payload bytes against that buffer (it kept 20000 1-byte datagrams in 64 KiB), so the most one sender can queue, 512 KiB − 1 plus one 65507-byte record, always fits; only several threads sending on one end at the same moment could pass the check together. SIO_UDP_CONNRESET is off so a send that races the peer's close cannot turn the next receive into ECONNRESET;
  • a record that does not fit the buffer is truncated with MSG_TRUNC, as on Linux.

A record over 65507 bytes, which a loopback UDP datagram cannot carry, throws a std::runtime_error, as the other Windows input limits of this file do (sendmsg: control data is not supported on Windows); tools/progress.py --module libkernel gives 720/759 on main and on this branch. The debt entry now states the three remaining Windows gaps. The first is that limit. The second is that the send buffer counts bytes, where the console also counts mbufs. The third is that a full end still polls writable (POLLOUT), where SB_STOP makes the console report it unwritable; a send after POLLOUT then waits or fails with EAGAIN as above. To keep the entry under the 1000 characters check_conventions.py allows, it drops the clause that explained why stream ends get no POLLHUP. The change goes through the existing fragment fix-libkernel-socketpair-datagram-full-enobufs.md, which already changes this entry (debt_fold.py refuses two fragments for one entry). macOS still throws.

Tested

Windows 11 Pro (10.0.26200), Intel Core i7-11370H, WinLibs GCC 15.2.0 r7, Release, on main 1f46de048f:

  • guest_socket_pair now runs the SOCK_SEQPACKET checks that were Linux-only on Windows too: records, MSG_TRUNC, EMSGSIZE over the send buffer, EISCONN, and EPIPE after the peer's close. It also adds two checks that run on both:

    • CheckSequencedPacketEnds: POLLIN | POLLHUP and receives of 0 after the peer's close, with and without a queued record and with MSG_DONTWAIT; a reader blocked in recv woken by the peer's close and by its shutdown(SHUT_WR); EPIPE.
    • CheckSequencedPacketFlow: an end with a 64 KiB SO_SNDBUF sends records of six sizes (5 to 5000 bytes) to an end whose SO_RCVBUF is 2048 until EAGAIN, and every record arrives once, in order, at its size and intact. On Windows the queue must hold at least 64 KiB, and have held less before the last record. Then a blocking sender on a full receiver stays blocked and completes once the reader drains.

    Passed 10 times in a row (--repeat until-fail:10). Red checks on this head: the test aborts with SequencedRoom counting only the next queued datagram, and without the host receive buffer being reset after SO_RCVBUF. On the previous head, with the end-of-file check removed from ReceiveEnded, the test hung and timed out.

  • FIONREAD on a connected loopback UDP pair, measured with a standalone Winsock program: after datagrams of 1, 700, 2000, 37, 5000 and 3 bytes it read 1, 701, 2701, 2738, 7738 and 7741, and it fell by each record's size as they were read. Over 200000 sends of 1 to 4096 bytes, it matched the running total right after every send returned.

  • A full end, whose send fails with EAGAIN, polls writable (revents 0x4): the third gap in the debt entry.

  • 58 socket tests pass: ctest -R '^guest_(equeue_events|kernel_socket_.*|kernel_sys_pselect|kqueue.*|sce_net_kernel_forwards|net_socket_state|net_buffer_validation|net_oob_inline|poll|select.*|sendfile|sce_net|socket_.*|tcp|udp|datagram_.*|recvmsg_memory|sendmsg_memory|sendmsg_control)$'.

  • Linux: not built here.

    • Every expectation of the two new checks was run as a native C++ program against the host's AF_UNIX SOCK_SEQPACKET on Linux 6.6.87 (WSL 2), and all hold there. With the receiver's SO_RCVBUF at 2048, 48 mixed records (62008 bytes) queued before EAGAIN and arrived intact and in order.
    • An earlier run showed that Linux wakes a blocked sender only after the reader drains most of the queue (unix_writable), so the test drains the whole queue before it waits for the sender.
    • Udp.cpp and GuestSocketPair.cpp compile with GCC 13.3 for Linux with -Wall -Wextra and no warning.
    • Linux and macOS take no new code path.
  • Parallax Browser 0.2.2 (homebrew, GPL-3.0, catalog SHA-256 ac68d031…), NVIDIA GeForce RTX 3050 Ti Laptop GPU (596.71), on the previous head 342dbc18a8:

    • On main it ends with the exception above (exit 0xC0000409).
    • With this change its probe logs socketpair seqpacket rc 0 errno 0, and it connects the display, opens the pad and loads its UI fonts.
    • It then retries launching its WebProcess payload through the jailbreak ELF loader on 127.0.0.1:9021, which is not part of AnyPS5, and presents no frame. Details in Parallax Browser (PPSA99207) #23335.
    • ProsperoWeb (PRWB00001) passes the same point, as reported in the review comments above.
  • tools/check_conventions.py --base origin/main and tools/debt_fold.py --check pass.

Not tested: macOS, the Linux CI build, a commercial title, Parallax Browser on this head, and records near the 65507-byte limit.

Overlap: tools/pr_overlap.py --branch over the 2007 open pull requests reports a line conflict with #22048: it adds lines right after shut = ReceiveShut(*socket) in recvmsg, which this branch changes to ReceiveEnded. #21985, the other conflict reported before, has merged, and this branch is rebased onto it with both tests kept. The tool could not compare #8605, #11896, #12682, #12688, #12700 and #12965, which already conflict with main, so I read them by hand. #8605 changes only GuestSockets::Stat and stream-pair checks in the test's main, none of the lines this branch changes. #11896 moves the WSAEMSGSIZE lines this branch extends to SOCK_SEQPACKET into a receive helper that already takes type 5, and #12682, #12688, #12700 and #12965 replace the blocked-receive loop of WaitForTransfer and add ReceiveShut checks to new receive paths; whichever of those lands second should use ReceiveEnded there, so that blocked SOCK_SEQPACKET readers on Windows still see the end. None of them creates SOCK_SEQPACKET pairs or changes NativePair, and this branch builds on none of them; I will rebase onto whichever merges first, and have said so to the authors on #22048 (also for #21985), #11896 and #12688 (for the series).

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: PPSA99207 Parallax Browser (PPSA99207) #23335
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 3cd3a469a4:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_socket_pair_tests built cleanly.
  • CTest (guest_socket_pair, guest_recvmsg_memory, guest_sendmsg_memory, guest_sendmsg_control):
    1/4 Test #5649: guest_recvmsg_memory .............   Passed    0.01 sec
    2/4 Test #5650: guest_sendmsg_memory .............   Passed    0.00 sec
    3/4 Test #5652: guest_sendmsg_control ............   Passed    0.00 sec
    4/4 Test #5648: guest_socket_pair ................   Passed    0.31 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/4 Test #5649: guest_recvmsg_memory .............   Passed    0.01 sec
    2/4 Test #5650: guest_sendmsg_memory .............   Passed    0.01 sec
    3/4 Test #5652: guest_sendmsg_control ............   Passed    0.00 sec
    4/4 Test #5648: guest_socket_pair ................   Passed    0.31 sec
    100% tests passed, 0 tests failed out of 4
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp NativePair socket option initialization and SIO_UDP_CONNRESET configuration for Windows loopback UDP pairs.
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp SequencedRoom timeout arithmetic and deadline calculation using std::chrono and 64-bit split timeout seconds/nanoseconds.
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp SequencedRoom peer socket FIONREAD query and send buffer capacity enforcement.
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp ReceiveEnded, ReceiveAnsweredHere, and WaitForTransfer state transitions on shutdown(SHUT_WR) and socket closure.
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp WSAEMSGSIZE truncation handling in recv_nid_postfix and recvfrom_nid_postfix for SOCK_SEQPACKET (type 5).
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp PollDescriptors and GuestSockets::Poll handling of peer closure and revents (POLLIN | POLLHUP).
    • Verified docs/dev/debt/changes fragment format and AGENTS.md compliance regarding no comments and technical debt tracking.

Looks Good To Me

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Nov 18, 2026
@DannyOppenheimer
DannyOppenheimer force-pushed the fix/libkernel-windows-seqpacket-socketpair branch from 3cd3a46 to e00ce42 Compare November 18, 2026 22:14

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against e00ce42456:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_socket_pair_tests built cleanly.
  • CTest (guest_socket_pair, guest_recvmsg_memory, guest_sendmsg_memory, guest_sendmsg_control):
    1/4 Test #5649: guest_recvmsg_memory .............   Passed    0.02 sec
    2/4 Test #5650: guest_sendmsg_memory .............   Passed    0.01 sec
    3/4 Test #5652: guest_sendmsg_control ............   Passed    0.01 sec
    4/4 Test #5648: guest_socket_pair ................   Passed    0.32 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/4 Test #5649: guest_recvmsg_memory .............   Passed    0.02 sec
    2/4 Test #5650: guest_sendmsg_memory .............   Passed    0.01 sec
    3/4 Test #5652: guest_sendmsg_control ............   Passed    0.01 sec
    4/4 Test #5648: guest_socket_pair ................   Passed    0.34 sec
    100% tests passed, 0 tests failed out of 4
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified NativePair sets SO_RCVBUF to SequencedHostReceiveBuffer (1 MiB) and disables SIO_UDP_CONNRESET on Windows for type == 5 (SOCK_SEQPACKET) loopback UDP pairs.
    • Verified SequencedRoom send buffer accounting, deadline calculation, nonblocking EAGAIN (35), send shutdown EPIPE (32), and LongestLoopbackRecord bounds checks.
    • Verified ReceiveEnded, ReceiveAnsweredHere, and WaitForTransfer properly handle peer closure, shutdown(SHUT_WR), and drained datagrams on Windows.
    • Verified WSAEMSGSIZE truncation behavior is correctly preserved for both SOCK_DGRAM (2) and SOCK_SEQPACKET (5) in recv and recvfrom.
    • Verified PollDescriptors and GuestSockets::Poll propagate POLLIN and POLLHUP upon SequencedPeerGone and ReceiveEnded.
    • Verified AGENTS.md compliance: no disallowed comments, technical debt properly tracked in docs/dev/debt/changes fragment, and clean conventions.

Looks Good To Me

@DannyOppenheimer
DannyOppenheimer force-pushed the fix/libkernel-windows-seqpacket-socketpair branch from e00ce42 to 342dbc1 Compare November 18, 2026 22:27

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 342dbc18a8:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_socket_pair_tests built cleanly.
  • CTest (guest_socket_pair, guest_recvmsg_memory, guest_sendmsg_memory, guest_sendmsg_control):
    1/4 Test #5649: guest_recvmsg_memory .............   Passed    0.01 sec
    2/4 Test #5650: guest_sendmsg_memory .............   Passed    0.00 sec
    3/4 Test #5652: guest_sendmsg_control ............   Passed    0.00 sec
    4/4 Test #5648: guest_socket_pair ................   Passed    0.31 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/4 Test #5649: guest_recvmsg_memory .............   Passed    0.01 sec
    2/4 Test #5650: guest_sendmsg_memory .............   Passed    0.00 sec
    3/4 Test #5652: guest_sendmsg_control ............   Passed    0.00 sec
    4/4 Test #5648: guest_socket_pair ................   Passed    0.31 sec
    100% tests passed, 0 tests failed out of 4
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified NativePair on Windows sets SO_RCVBUF to SequencedHostReceiveBuffer (1 MiB) and disables SIO_UDP_CONNRESET via WSAIoctl for type == 5 (SOCK_SEQPACKET) loopback UDP pairs.
    • Verified SequencedRoom send buffer accounting, deadline calculation, nonblocking EAGAIN (35), send shutdown EPIPE (32), and LongestLoopbackRecord (65507 bytes) bounds checks against FreeBSD 11.4 socket semantics.
    • Verified ReceiveEnded, ReceiveAnsweredHere, and WaitForTransfer properly handle peer closure, shutdown(SHUT_WR), and drained datagrams on Windows.
    • Verified WSAEMSGSIZE truncation handling in recv_nid_postfix and recvfrom_nid_postfix correctly treats message truncation for SOCK_SEQPACKET (type == 5) similarly to SOCK_DGRAM (type == 2).
    • Verified PollDescriptors and GuestSockets::Poll propagate POLLIN and POLLHUP upon SequencedPeerGone and ReceiveEnded on Windows.
    • Verified AGENTS.md conventions: no illegal comments, debt documented under docs/dev/debt/changes/fix-libkernel-socketpair-datagram-full-enobufs.md, and clean mechanical checks.

Looks Good To Me

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 22048 core/libs/prx/libkernel/Socket/src/Udp.cpp L2626
PR 24382 core/libs/prx/libkernel/Socket/src/Udp.cpp L1975-1976, L1979

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.

Pull request Shared files not compared
PR 8605 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestSocketPair.cpp
PR 11896 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12682 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12688 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12700 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12965 core/libs/prx/libkernel/Socket/src/Udp.cpp

@zarmstrong

Copy link
Copy Markdown
Contributor

Ran it on a second Windows machine: head 342dbc18a8 merged onto main 3ead3ea870, with main itself as the baseline. Windows 11 Pro 26200, Intel Core i9-13900K, WinLibs GCC 15.2.0 r7, Ninja, Release.

  • guest_socket_pair passes 3/3 with --repeat until-fail:3.
  • The 57 tests matched by the description's regex all pass, as on main.
  • Red check: with only Udp.cpp reverted to main, guest_socket_pair aborts with socketpair: SOCK_SEQPACKET is not supported on Windows. Restored, it passes again.

Not tested here: Parallax Browser, and records near the 65507-byte limit.

AI-assisted: yes (Claude Code)

@Jazeupoi Jazeupoi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with a second title that stops on the same throw: ProsperoWeb (PRWB00001), a different WebKit browser from the catalog (release v0.2.1, PRWB00001.zip, SHA-256 matching the catalog).

Setup: Windows 11 Pro (build 26300), AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0 r7, Release. Base main cac6e5714d with #22373 (it only adds setenv for the AGC tests on Windows); "this PR" is the same tree with head 342dbc18a8 merged and only libs rebuilt. eboot.bin and sce_module/libc.prx unwrapped with tools/unwrap_self.py, converted with relinker --windows --trap-sdk-syscall-stubs --registry, one run each.

result
base presents 2 frames, then what(): socketpair: SOCK_SEQPACKET is not supported on Windows and FATAL: abort() (SIGABRT) about 7 s after start
this PR still running when closed after 95 s; it shows its own startup screen, "ProsperoWeb could not reach an ELF loader"

With this PR the next stop is the same as in Parallax Browser: the title needs the jailbreak ELF loader (elfldr 127.0.0.1:9021: Connection refused; websrv 127.0.0.1:8080: ... refused) to start its web engine, which is not a system library. No new what() or FATAL line in its log.

AI-assisted: yes (Claude Code)

@ShootanoJumper

Copy link
Copy Markdown
Contributor

Windows 11 22631 / GCC 15.2.0: guest_socket_pair, guest_sendmsg_memory, guest_recvmsg_memory pass. Not run on Parallax Browser.

@github-actions github-actions Bot added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict needs rebase Conflicts with main, rebase needed labels Nov 19, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: fix Windows sequenced-packet send-buffer accounting so a full receive queue cannot silently drop records.

What I ran

Reviewed head 342dbc18a81b964ca4a5832880ad40980b41171e. No build or test commands were run; the execution environment exposed only review-reader tools, so author-reported checks are not treated as runs performed here.

Results

Check Result Note
Diff and changed-file review passed All three changed files read
Targeted call-path review passed Send, receive, poll, and socket-option paths read
Build and tests not run Reader-only environment

Findings

Blocking

  • core/libs/prx/libkernel/Socket/src/Udp.cpp:1043 uses Windows FIONREAD to determine queued bytes. For a UDP socket, this reports the size of the next pending datagram, rather than the total bytes across queued datagrams. With multiple smaller records queued, SequencedRoom therefore undercounts occupancy, can permit sends beyond the configured send-buffer capacity, and can let Windows drop records instead of blocking or returning EAGAIN. Track queued records/bytes explicitly or use another mechanism that measures the whole queue before admitting a send.

Non-blocking

None.

Not verified

  • Build and tests were not run in this review. Windows runtime behavior, Linux CI, macOS, and physical-console behavior were not independently verified; the description reports author-run results.
  • Read: core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestSocketPair.cpp, and docs/dev/debt/changes/fix-libkernel-socketpair-datagram-full-enobufs.md, plus the prepared description, commits, manifest, and diff.
  • Excluded by the prepared inventory: none of the three changed files. review/files.json was unavailable through the reader; the reader’s file listing confirmed all three changed files were included.

To get this to a good state

Correct the total queued-byte accounting and add coverage with multiple queued records of differing sizes. Re-run the Windows socketpair tests on the updated head.

@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 20, 2026
A SOCK_SEQPACKET pair on Windows is two connected loopback UDP sockets,
as SOCK_DGRAM already is, with the connection semantics FreeBSD 11.4
gives the pair: a receive returns 0 once the peer is closed or has shut
down writing and the queue is empty, which also wakes blocked readers
and makes poll report POLLIN, with POLLHUP after a close; a send after
the peer is gone fails with EPIPE; and a sender waits, or fails with
EAGAIN, while the receiver holds its send buffer's bytes, as SB_STOP
does. Each end keeps a 1 MiB host receive buffer whatever SO_RCVBUF the
guest sets, so no record is dropped. A record over 65507 bytes throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DannyOppenheimer
DannyOppenheimer force-pushed the fix/libkernel-windows-seqpacket-socketpair branch from 342dbc1 to da39e63 Compare November 20, 2026 07:24
@DannyOppenheimer

DannyOppenheimer commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Rebased onto main 1f46de048f and pushed as da39e6367e.

FIONREAD on a Windows UDP socket is the total of all queued datagrams, not the next one. Microsoft's Winsock IOCTLs page, under FIONREAD: "If the socket passed in the s parameter is message oriented (for example, type SOCK_DGRAM), FIONREAD returns the reports the total number of bytes available to read, not the size of the first datagram (message) queued on the socket" (the typo is in the original). It is Linux that reports the next datagram. I measured it on Windows 11 Pro 26200 with a standalone Winsock program and a connected loopback UDP pair:

  • after datagrams of 1, 700, 2000, 37, 5000 and 3 bytes, FIONREAD read 1, 701, 2701, 2738, 7738 and 7741, and it fell by each record's size as they were read;
  • over 200000 sends of 1 to 4096 bytes, FIONREAD read right after each send returned matched the running total every time.

Coverage with records of differing sizes, as you asked. CheckSequencedPacketFlow now sends records of six sizes, from 5 to 5000 bytes, from an end with a 64 KiB SO_SNDBUF until EAGAIN. Every record must then arrive once, in order, at its size and intact. On Windows the test also checks that the queue stops at the send buffer. Red check: with SequencedRoom counting only the next queued datagram (the accounting the review describes), the test aborts.

Checking this turned up two real problems, both fixed on the new head:

  1. Records could be dropped another way, which is the failure you were after. A guest SO_RCVBUF on a pair end was passed to the host socket and shrank its 1 MiB receive buffer below what the sender may queue. I found it in SocketOptions.cpp while checking the review. The new test sets the receiver's SO_RCVBUF to 2048, and without the fix it aborts. FreeBSD 11.4 appends a SOCK_SEQPACKET record without checking the receiver's space (sbappendaddr_nospacecheck_locked in uipc_send). So the host buffer now stays at 1 MiB, and the guest still reads back the value it set.
  2. While reading uipc_send for this, I found that FreeBSD 11.4 sets SB_STOP on the sender once the receiver holds its sb_hiwat bytes, and uipc_rcvd clears it below that. It therefore accepts a record whenever less than the send buffer is queued. The branch also required the new record to fit, and its description named an older mechanism. SequencedRoom now follows 11.4. With one sender at a time, the most that can be queued is 512 KiB − 1 plus one 65507-byte record, which still fits the 1 MiB host buffer.

One gap remains and is now in the debt entry. On Windows a full end still reports POLLOUT (measured: revents 0x4 while send fails with EAGAIN). On the console, SB_STOP makes sbspace 0, so the end reports unwritable. A send after POLLOUT still waits or fails with EAGAIN as above.

Re-run on da39e6367e: Windows 11 Pro 26200, i7-11370H, WinLibs GCC 15.2.0 r7, Release.

  • guest_socket_pair passed 10 runs in a row (--repeat until-fail:10).
  • All 58 socket tests from the description's pattern pass.
  • On Linux 6.6.87 (WSL 2), the new expectations hold against the host's AF_UNIX SOCK_SEQPACKET: 48 records (62008 bytes) before EAGAIN, all intact and in order, with the receiver's SO_RCVBUF at 2048.
  • Udp.cpp and GuestSocketPair.cpp compile with GCC 13.3 for Linux with -Wall -Wextra and no warning.
  • check_conventions.py and debt_fold.py --check pass.
  • progress.py --module libkernel gives 720/759 on main and on the branch.

The description is updated.

AI Assisted: Yes, claude code drafted comment

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 20, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the inspected implementation and tests support merging.

What I ran

Reviewed head da39e6367eb57e1c9fdf7d05e305661733f8fe36. No build or tests were run; author-reported test results are not treated as checks performed here.

Results

Check Result Note
Diff and targeted code review passed Three changed files inspected
Build and tests not run No commands run

Findings

Blocking

None.

Non-blocking

None.

Not verified

Read description.md, commits.md, manifest.json, diff.patch, core/libs/prx/libkernel/Socket/src/Udp.cpp lines 965–1085, 1248–1272, and 1325–1560. The changed test file and debt fragment are listed in the manifest but their full text was not read; tests and platform behavior were not independently verified. The author reports tests and Windows/Linux observations in description.md.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot added the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 20, 2026

@Superseabas Superseabas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows check of head da39e6367e with GCC 16, merged onto main 0a025bd3c6 (clean merge), next to the author's GCC 15.2 run.

Setup: Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell. This was built together with #21969 and #24190, which touch other files.

  • The description's 57 socket tests (^guest_(equeue_events|kernel_socket_.*|…|sendmsg_control)$): main 57 of 57, and with this PR 57 of 57 in 3 of 3 runs.
  • guest_socket_pair, now with the SOCK_SEQPACKET checks on Windows: passes --repeat until-fail:10.
  • Red check: with SequencedRoom always reporting room (if (queued < capacity) return 0; → return 0;), guest_socket_pair aborts (0xc0000409). So CheckSequencedPacketFlow does catch a sender that isn't held back on a full receiver.

The approach reads right to me: loopback UDP as SOCK_DGRAM already uses, with ReceiveEnded, the close/shutdown wakeups and the FIONREAD-based send wait added on Windows only. The three remaining gaps are stated in the debt entry: records over 65507 bytes throw, the buffer counts bytes, and a full end still polls writable.

AI-assisted: yes (Claude Code)

Resolve recv_nid_postfix against the guest-prefix receive limit from main: keep ReceiveEnded and report a truncated SEQPACKET record like a datagram.
@oneandonlydean

Copy link
Copy Markdown
Collaborator

I merged main to clear the conflict (4e0cd57). The only conflict was recv_nid_postfix against the guest-prefix receive limit from #24382: I kept main's block, your ReceiveEnded, and type == 2 || type == 5 on the WSAEMSGSIZE return, the same shape recvfrom already merged into.

One non-blocking follow-up: PendingFits and DropDatagram in Udp.cpp still only treat type == 2 as record based, so a Windows SEQPACKET recv into a partly unmapped buffer takes the stream path (FIONREAD over the whole queue) instead of peeking the one record. Extending both checks to type 5 would match the datagram behaviour, if you agree that is what FreeBSD does for SEQPACKET there.

This head still needs the Windows guest_socket_pair run to go green.

@github-actions github-actions Bot added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed needs rebase Conflicts with main, rebase needed labels Nov 21, 2026
@oneandonlydean
oneandonlydean merged commit c060966 into boykopovar:main Nov 22, 2026
3 checks passed
@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libkernel unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants