feat(libkernel): create SOCK_SEQPACKET socketpairs on Windows #23341
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23341"
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 DannyOppenheimer on 2026-11-18T22:06:02Z.
What
socketpair(AF_UNIX, SOCK_SEQPACKET)threw on Windows (socketpair: SOCK_SEQPACKET is not supported on Windows), a gap listed in thesocketpairentry ofdocs/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_DGRAMalready is, and the guest layer adds what UDP lacks for a connected record socket, as FreeBSD 11.4 gives it:recv,recvfrom,recvmsg,read, thepollpaths and kqueue readiness all see it (ReceiveEnded, which isReceiveShuton Linux and macOS);close(last descriptor) orshutdown(SHUT_WR)wakes readers blocked in a receive orpoll(WakeReadWatchers), andpollreportsPOLLIN, withPOLLHUPafter aclose(sopoll_genericaftersoisdisconnected);shutdown(SHUT_WR), fails withEPIPE;EAGAINwhen non-blocking, withMSG_DONTWAITor afterSO_SNDTIMEO, while the receiver holds at least itsSO_SNDBUFbytes. This follows FreeBSD 11.4:uipc_sendsetsSB_STOPon the sender'sso_sndonce the receiver holdssb_hiwatbytes,uipc_rcvdclears it below that, andsbspaceis 0 while it is set. The queued bytes come from the receiver'sFIONREAD, 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 setsSO_RCVBUF, since FreeBSD appends aSOCK_SEQPACKETrecord 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_CONNRESETis off so a send that races the peer'sclosecannot turn the next receive intoECONNRESET;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 libkernelgives 720/759 onmainand 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), whereSB_STOPmakes the console report it unwritable; a send afterPOLLOUTthen waits or fails withEAGAINas above. To keep the entry under the 1000 characterscheck_conventions.pyallows, it drops the clause that explained why stream ends get noPOLLHUP. The change goes through the existing fragmentfix-libkernel-socketpair-datagram-full-enobufs.md, which already changes this entry (debt_fold.pyrefuses 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
main1f46de048f:guest_socket_pairnow runs theSOCK_SEQPACKETchecks that were Linux-only on Windows too: records,MSG_TRUNC,EMSGSIZEover the send buffer,EISCONN, andEPIPEafter the peer's close. It also adds two checks that run on both:CheckSequencedPacketEnds:POLLIN | POLLHUPand receives of 0 after the peer's close, with and without a queued record and withMSG_DONTWAIT; a reader blocked inrecvwoken by the peer'scloseand by itsshutdown(SHUT_WR);EPIPE.CheckSequencedPacketFlow: an end with a 64 KiBSO_SNDBUFsends records of six sizes (5 to 5000 bytes) to an end whoseSO_RCVBUFis 2048 untilEAGAIN, 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 withSequencedRoomcounting only the next queued datagram, and without the host receive buffer being reset afterSO_RCVBUF. On the previous head, with the end-of-file check removed fromReceiveEnded, the test hung and timed out.FIONREADon 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 everysendreturned.A full end, whose
sendfails withEAGAIN, polls writable (revents0x4): 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.
AF_UNIXSOCK_SEQPACKETon Linux 6.6.87 (WSL 2), and all hold there. With the receiver'sSO_RCVBUFat 2048, 48 mixed records (62008 bytes) queued beforeEAGAINand arrived intact and in order.unix_writable), so the test drains the whole queue before it waits for the sender.Udp.cppandGuestSocketPair.cppcompile with GCC 13.3 for Linux with-Wall -Wextraand no warning.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 head342dbc18a8:mainit ends with the exception above (exit0xC0000409).socketpair seqpacket rc 0 errno 0, and it connects the display, opens the pad and loads its UI fonts.127.0.0.1:9021, which is not part of AnyPS5, and presents no frame. Details in #23335.tools/check_conventions.py --base origin/mainandtools/debt_fold.py --checkpass.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 --branchover the 2007 open pull requests reports a line conflict with #22048: it adds lines right aftershut = ReceiveShut(*socket)inrecvmsg, which this branch changes toReceiveEnded. #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 withmain, so I read them by hand. #8605 changes onlyGuestSockets::Statand stream-pair checks in the test'smain, none of the lines this branch changes. #11896 moves theWSAEMSGSIZElines this branch extends toSOCK_SEQPACKETinto a receive helper that already takes type 5, and #12682, #12688, #12700 and #12965 replace the blocked-receive loop ofWaitForTransferand addReceiveShutchecks to new receive paths; whichever of those lands second should useReceiveEndedthere, so that blockedSOCK_SEQPACKETreaders on Windows still see the end. None of them createsSOCK_SEQPACKETpairs or changesNativePair, 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
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 PrivacyOnion on 2026-11-18T22:07:28Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3cd3a469a4:tools/check_conventions.pypassed.guest_socket_pair_testsbuilt cleanly.guest_socket_pair,guest_recvmsg_memory,guest_sendmsg_memory,guest_sendmsg_control):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T22:15:34Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e00ce42456:tools/check_conventions.pypassed.guest_socket_pair_testsbuilt cleanly.guest_socket_pair,guest_recvmsg_memory,guest_sendmsg_memory,guest_sendmsg_control):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T22:28:50Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
342dbc18a8:tools/check_conventions.pypassed.guest_socket_pair_testsbuilt cleanly.guest_socket_pair,guest_recvmsg_memory,guest_sendmsg_memory,guest_sendmsg_control):core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-19T09:42:24Z.
Review: COMMENTED
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
maincac6e5714dwith #22373 (it only addssetenvfor the AGC tests on Windows); "this PR" is the same tree with head342dbc18a8merged and onlylibsrebuilt.eboot.binandsce_module/libc.prxunwrapped withtools/unwrap_self.py, converted withrelinker --windows --trap-sdk-syscall-stubs --registry, one run each.what(): socketpair: SOCK_SEQPACKET is not supported on WindowsandFATAL: abort() (SIGABRT)about 7 s after startWith 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 newwhat()orFATALline in its log.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:27:35Z.
Review: CHANGES_REQUESTED
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
Findings
Blocking
core/libs/prx/libkernel/Socket/src/Udp.cpp:1043uses WindowsFIONREADto 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,SequencedRoomtherefore undercounts occupancy, can permit sends beyond the configured send-buffer capacity, and can let Windows drop records instead of blocking or returningEAGAIN. Track queued records/bytes explicitly or use another mechanism that measures the whole queue before admitting a send.Non-blocking
None.
Not verified
core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/tests/GuestSocketPair.cpp, anddocs/dev/debt/changes/fix-libkernel-socketpair-datagram-full-enobufs.md, plus the prepared description, commits, manifest, and diff.review/files.jsonwas 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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:38:08Z.
Review: APPROVED
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
Findings
Blocking
None.
Non-blocking
None.
Not verified
Read
description.md,commits.md,manifest.json,diff.patch,core/libs/prx/libkernel/Socket/src/Udp.cpplines 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 indescription.md.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-20T13:20:07Z.
Review: APPROVED
Windows check of head
da39e6367ewith GCC 16, merged ontomain0a025bd3c6(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.^guest_(equeue_events|kernel_socket_.*|…|sendmsg_control)$):main57 of 57, and with this PR 57 of 57 in 3 of 3 runs.guest_socket_pair, now with theSOCK_SEQPACKETchecks on Windows: passes--repeat until-fail:10.SequencedRoomalways reporting room (if (queued < capacity) return 0;→return 0;),guest_socket_pairaborts (0xc0000409). SoCheckSequencedPacketFlowdoes catch a sender that isn't held back on a full receiver.The approach reads right to me: loopback UDP as
SOCK_DGRAMalready uses, withReceiveEnded, the close/shutdown wakeups and theFIONREAD-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)