feat(libkernel): pass descriptors over socketpairs on Windows #25791
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25791"
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-22T17:48:49Z.
What
On Windows,
sendmsgwith control data threw (sendmsg: control data is not supported on Windows), so a guest could not pass descriptors inSCM_RIGHTSmessages.recvmsgalso refusedMSG_CMSG_CLOEXECwithEOPNOTSUPP, because only a receive that can take descriptors accepts that flag. Parallax Browser (PPSA99207, #23335) hits the second case: every IPC receive of its UI process fails withError receiving message: Operation not supported. Linux already passes descriptors through the host'sSCM_RIGHTS(#7090). Windows socket pairs are loopback TCP and UDP sockets, which cannot carry descriptors, so this PR passes them in the guest layer forSOCK_STREAMandSOCK_SEQPACKETsocketpair ends.sendmsgholds a guestdupof each passed descriptor and queues it on the peer end, keyed to the stream byte (stream) or record (seqpacket) where its data starts. Sends on an end are serialized, as FreeBSD'ssblockonso_snddoes, so the key is exact. The queue entry is made before the host send and withdrawn if the send fails.recv,recvfrom,recvmsg,readandreadv. Sends fromsend,sendto,sendmsg,write,writevandsendfileadvance the sender's position.uipc_send(sbappendcontrol_lockedmakes a record) andsoreceive_generic.MSG_WAITALLreturns short at that point (L1856).recvmsgon a stream delivers the descriptors once their data has arrived and leaves the data.SCM_RIGHTSmessage of onesendmsgarrives as its own control message.MSG_CTRUNC, and the rest are closed (kern_recvitcopies whole control mbufs and disposes the rest).MSG_CMSG_CLOEXECsets close-on-exec (unp_externalize).EMSGSIZEand the descriptors are freed (L1825).recv,read, ...) closes the descriptors, as doshutdown(SHUT_RD)(sorflush) and closing (ordup2over) the receiving end's last descriptor.SOCK_DGRAMpairs still throw: Windows drops a datagram sent to a full receiver, which would put the queue out of step. Seqpacket pairs do not drop with one sender per end: #23341's flow control admits a record only while the receiver holds less than the sender'sSO_SNDBUF(at most 512 KiB), and a record is at most 64 KiB, against a 1 MiB host buffer. Each sender checks for room before it takes the send lock, so nine or more threads sending 64 KiB records on one end at the same moment could still overflow the buffer. That was already possible with #23341, where it loses data; here it would also misplace descriptors. Moving the room check under the send lock is a follow-up.PassedDescriptorsalso reports each message's count.sendmsg and recvmsgentry now says what Windows does. It also lists the two remaining differences: a descriptor in flight occupies a number, and a socket passed into its own queue is never freed (FreeBSD'sunp_gc).Tested
Windows 11 Pro 10.0.26200, Intel Core i7-11370H, WinLibs GCC 15.2.0 r7, Release, rebased on
main788b1afac9.guest_socket_pair_rights(Windows only): passed pipes and stream, seqpacket and pair sockets; stream boundaries and merging;MSG_WAITALLstopping at a boundary; a blocked receiver; a zero-length receive; peek; truncation and several messages; disposal on a plain read, on close, ondup2and onSHUT_RD; refused sends to a closed peer and afterSHUT_WR(the second withdraws the queued entry); seqpacket records with truncation; a refused datagram pair; the lowest free number. 40 runs in a row pass (--repeat until-fail:40).CheckStreamRecords), without the lower-number choice (CheckLowestNumber), without disposal on close (CheckClosedReceiver) and without the withdrawal of a failed send (CheckRefusedSend).libkernel.prxswitched betweenmainand this PR:main: 9 linesIPC: error receiving on socket N ...: Error receiving message: Operation not supported. The web process ends after the first relaunch, and the title shows its error page twice.127.0.0.1:9021) for its WebProcess and NetworkProcess, so no page loads yet.g++ -std=gnu++20 -fsyntax-only -Wall -WextraofUdp.cppwith GCC 13 (WSL Ubuntu 24.04) is clean. The Linux rights test was not run here.tools/progress.py --module libkernel: 723/769 onmainand on this branch.tools/check_conventions.py --base origin/main: passes.tools/pr_overlap.py: no open PR implements descriptor passing on Windows.SendIovecssignature) and #25017 (macOS seqpacket pairs:CloseandForget) change lines next to this PR's; #18197 shares only the file.main, so the tool could not compare them. I compared them by hand: none passes descriptors. #22048 and #24944 editrecvmsgand leave the passing path to it.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 MarcZX10 on 2026-11-22T17:51:19Z.
Review: APPROVED
Reviewed — looks good
The code changes and added Windows test are consistent with the stated descriptor-passing behavior; the test results in the description were author-reported and were not run in this review.
What I ran
Reviewed head
536766a4744b25148a87603f5181ec3504ff026cusingrepo_read.py. No build or test commands were run. The PR description reports Windows tests and Linux syntax checking; those results were not independently confirmed.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full 162-test run, 40-repeat test run, Linux syntax check, and Parallax Browser run were not performed here. The Windows test target and its test source were read, but not executed. All changed files listed in the review manifest were read; no files were excluded.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T03:12:31Z.
Review: APPROVED
Reviewed current head
1250520f2a6f5d1962fbb5770ece1e4390e00f14against MarcZX10's previously approved head536766a4744b25148a87603f5181ec3504ff026c.Three of the four PR files are byte-identical. The only implementation delta is in Linux
SendBeforeConnect: the zero-timepoll(POLLOUT)now retriesEINTR, throws on another host poll error, and preserves the priorready == 0still-pending path. I found no regression; it prevents a negative poll result from being treated as a completed connect.Current exact-head checks are fully terminal: 9 success, 6 intentional workflow-design skips, 0 failures, 0 pending, including a successful Windows job for the descriptor-passing implementation.
No blocking findings on the current head. AI-assisted: yes