feat(libkernel): create SOCK_SEQPACKET socketpairs on macOS #25017
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25017"
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 Jazeupoi on 2026-11-21T15:01:40Z.
What
socketpair(AF_UNIX, SOCK_SEQPACKET)threw on macOS (socketpair: SOCK_SEQPACKET is not supported on macOS), which has no such type. Parallax Browser (PPSA99207, #23335) stopped there about 2 s after start, in the socket probe of its UIProcess.On macOS the pair is now a host
socketpair(AF_UNIX, SOCK_DGRAM), which keeps record boundaries, with 8 MiB send and receive buffers, and the guest layer that #23341 added for Windows now runs on macOS too, for what the host lacks (each measured on the M4):ECONNRESET, and does not report the peer'sshutdown(SHUT_WR)at all;recvnor a blockedpoll;EPIPE; macOS reportsEDESTADDRREQ;EAGAINwhen non-blocking, while the receiver holds itsSO_SNDBUFbytes; macOS fails withENOBUFSat once, even on a blocking socket;pollreportsPOLLHUPonce the peer is gone.An end now counts as gone when its last descriptor is closed or replaced by
dup2, even while another thread is still in a call on it. Before, a blocked send waited for the peer object itself to be freed, so a second blocked send, or a send blocked on the peer, could keep it waiting forever. This also changes the Windows pair, anddup2over the last descriptor of an end now releases it asclosedoes. For the peer, an end counts as ended only once its sends in flight have finished too, so end of file andPOLLHUPnever come before a record that a blocked send still queues; a new send to a closed end still fails withEPIPEat once. On macOS a descriptor-passingsendmsgchecks the guest capacity, as on Windows.Known macOS limits: a sequenced end passed with
SCM_RIGHTSarrives as a guestSOCK_DGRAMsocket without the pair state, and of two blocking readers on one end, the one that loses a record can stay in the native receive after a later peer shutdown.The 8 MiB come from measurement: macOS counts 16 more bytes per queued record and charges at least 128 bytes of buffer per record, so 8 MiB holds 65536 records, while at most about 31000 can be queued (the guest's 512 KiB capacity at 17 bytes per 1-byte record).
guest_socket_pairnow runs itsSOCK_SEQPACKETchecks on macOS. The debt entry states that the macOS send buffer andFIONREADcount those 16 bytes per record.Tested
Head
008f8c9bb5(the merge ofmain87f0e47be5plus the end-of-sends fix):guest_socket_pairpasses 200 of 200 runs. The newCheckEndAfterBlockedSendon the previous head6da03cba8afails 3 of 3 (POLLHUPwhile the send is still blocked).guest_socket_pairpasses 200 of 200 runs. On6da03cba8athe new check fails 3 of 3 at the descriptor-passingEAGAINcheck, and with only that line fixed, 3 of 3 atPOLLHUP.Earlier heads (
305a1a416bchanged only the test; the macOS results below are fromd501609a84):macOS 27.0.1, Apple M4 (Rosetta 2), Apple clang 21.0.0, Release, at
d501609a84merged ontomain44eccbf1b0plus #17425, #11049, #25331 and #26739 (needed to build on macOS):guest_socket_pair: passes 50 of 50 runs. With the previous head374abd9d8fand the new test it fails 3 of 3: the blocked sends do not end while another send still holds the closed end. With theUdp.cppof #23341 it aborted withSOCK_SEQPACKET is not supported on macOS.guest_socket_*,guest_kernel_socket_*,guest_sce_net*,guest_net_*):guest_net_raw_protocolskips;guest_sce_net(#22443),guest_socket_options(#17879),guest_socket_port_zero(#17878) andguest_net_oob_inline(now and then) fail the same way on that base without this PR; the rest pass.ca03c685d7: its socket probe logssocketpair seqpacket rc 0 errno 0, and it keeps loading for 11.6 s until it stops at mesh shaders (#17611).Windows 11, WinLibs GCC 15.2, Release, merged onto
main74952ba8d3:guest_socket_pair: passes 200 of 200 runs. With the fix ofd501609a84reverted it fails 3 of 3, and with only itsclosepart (noDuplicateTochange) it fails 3 of 3.guest_socket_pairincluded (guest_socket_*,guest_kernel_socket_*,guest_net_*,guest_sce_net,guest_poll,guest_select*,guest_tcp,guest_udp,guest_datagram_*and others): all pass.Linux: not built here. The new checks run only where the pair is emulated (Windows and macOS), and the Linux path does not change.
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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:14:58Z.
Review: COMMENTED
Reviewed — comments
The macOS socketpair compatibility path has a likely queue-accounting defect that needs runtime confirmation before a formal decision.
What I ran
Reviewed head
ca03c685d716cbabd97cde4059cb0c09398df8c0. No commands or tests were run;repo_read.pywas unavailable as an executable interface, so I used the provided reader tools. No merged-preview check was run.Results
Findings
Blocking
None verified.
Non-blocking
core/libs/prx/libkernel/Socket/src/Udp.cpp:1058usesFIONREADto determine queued bytes for the macOSSOCK_SEQPACKETemulation, which uses a datagram socket. If macOS reports only the next datagram's size for this socket type, the value never reflects the full queued amount andSequencedRoommay continue sending past the guest send-buffer limit. ConfirmFIONREADsemantics for this socket type on macOS; if it is per-datagram, use a total-queued-byte counter/API and add a test that verifies the configured guest capacity is enforced.Not verified
description.md,commits.md,manifest.json,diff.patch, and all changed files infiles/were read. No changed files were excluded according to the manifest.To get this to a good state
Nothing is required. Optional: confirm the macOS
FIONREADbehavior and adjust queue accounting and coverage if it reports only one datagram.Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T15:08:01Z.
Review: CHANGES_REQUESTED
Reviewed exact head
ca03c685d716cbabd97cde4059cb0c09398df8c0. I found one EOF-routing issue in the new Darwin ancillary-data path.After
WaitForTransfer,recvmsg_nid_postfixrefreshesshut = ReceiveEnded(...), but theif (passing)ancillary branch calls hostrecvmsgbefore the laterif (!shut)guard. On Apple this PR makespassingtrue for an AF_UNIX request with a control buffer and noMSG_PEEK. The emulated peer EOF can wake the wait itself, so a call that has just observed EOF can still enter nativerecvmsginstead of returning guest EOF.An independent native CPU fixture compiled the exact extracted routing functions with immediate in-memory poll/recv doubles; it used no host socket or network and aborts on a second fake poll. With a simulated peer half-close/SHUT_WR wake, the exact head called host
recvmsgonce and returned the injected host error (-1, errno 54). The no-control path, theMSG_PEEKcontrol path, and initial EOF all returned 0 without consuming host recv. Live data and a queued record after SHUT_WR both still returned all 4 bytes. Adding only!shutto the ancillary guard made all 7 cases pass (head exit 2, guarded control exit 0) without dropping queued data.Please gate the native ancillary receive on
!shutafter the wait and add a regression for a control-buffer receive woken by emulated peer EOF. I did not run a real Darwin socket, blocking wait, or macOS errno test.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T13:26:57Z.
Review: APPROVED
Rechecked exact head
374abd9d8fedeeb14814cdd6797cd3d2f9e80750. The Darwin ancillary EOF-routing blocker from my previous review is fixed.I rebuilt the old and new
recvmsg_nid_postfixbodies against the same seven-case mocked Darwin CPU harness. The previous head failed both peer-close andSHUT_WRwake cases by entering native receive after observing EOF; this head passed all seven, returned EOF without native receive, and preserved queued-after-half-close and live-record delivery.The author additionally reports a real Apple M4/Rosetta socket test: the new blocked ancillary case timed out 10/10 without the guard and passed 10/10 with it. Exact-head Windows
guest_socket_pairis green; the hosted macOS selection does not run this test. No real macOS test was run on my machine.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T02:01:32Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent macOS blocking sends from hanging when the peer closes while the sender waits for buffer capacity.
What I ran
374abd9d8fedeeb14814cdd6797cd3d2f9e80750usingrepo_read.py.Results
Findings
Blocking
SequencedRoom, a blocking macOS sender polls the peer’s receive queue every millisecond while capacity is full, but never checks whether the peer has closed. After closure, the weak peer reference expires, yet this loop retains its shared peer pointer and continues waiting indefinitely when the sender has no timeout. This can hang a blocking send where the description says sends after peer loss should fail withEPIPE. Return the peer-gone error while rechecking the peer state in the wait loop.core/libs/prx/libkernel/Socket/src/Udp.cpp:1065Non-blocking
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. All changed files marked included in the manifest were read. No files were excluded by rule according to the manifest.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-25T02:09:30Z.
Review: CHANGES_REQUESTED
I am revising my approval of exact head
374abd9d8fedeeb14814cdd6797cd3d2f9e80750after checking the newly reported send-wait lifetime.A single blocked sender does not retain the peer forever:
peeris scoped inside theforbody, is destroyed after the 1 ms wait, and the next iteration returns 32 whensocket.peer.lock()fails. There is nevertheless a blocking concurrency case with two sends on the same end. After the other end is closed and its registry owner is removed, sender A can reacquire the peer while sender B still owns it, then B can reacquire it while A owns it.ReleaseSequencedEndobserves the end as still alive, no closed state is recorded, the native peer socket remains open,FIONREADremains at capacity, and an untimed blocking wait need not terminate.I confirmed the ownership pattern with a bounded C++20 lifetime control on Windows/GCC 15.2: 20/20 single-worker schedules observed expiration in the second iteration, while 20/20 two-worker schedules kept the object alive through eight coordinated 1 ms handovers; all objects were destroyed once the bounded workers stopped. No socket runtime or macOS machine was used for this additional control.
Please make peer closure observable independently of the waiters' temporary strong references and add coverage with two concurrent blocked sends closing the peer. The existing single-sender flow test does not exercise this lifetime interleaving.
AI-assisted review: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T13:52:51Z.
Review: COMMENTED
Reviewed — comments
The socketpair changes add macOS emulation and close handling, but the new send capacity check does not account for the peer’s configured receive buffer.
What I ran
Reviewed head
d501609a84ad438ff560c63a5b3736f96c8ef3e. No build or tests were run in this review session. I read the prepared description, commits, manifest and diff, then targeted source and test context usingrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
SequencedRoomuses the sender’sSendBufferSizeas the threshold for the peer’s queued bytes (Udp.cpp:1056-1067). Butsetsockoptchanges the host buffers on the socket being configured (Udp.cpp:1769-1771), while queued records are stored on the receiving peer. If the peer lowersSO_RCVBUF, a sender can continue until the host queue fills and then receiveENOBUFSimmediately, even for a blocking send. Consider basing the capacity check on the peer’s receive-buffer setting and adding a test that fills a pair after lowering only the receiving end’s buffer.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.mdwere read.files.jsonwas not available through the review reader, so excluded files were not verified.To get this to a good state
Nothing is required. Optional: align macOS send-capacity accounting with the peer receive buffer and cover that case in a test.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-25T15:38:02Z.
Review: CHANGES_REQUESTED
The production fix is correct on exact head
d501609a84ad438ff560c63a5b3736f96c8ef3e6, but the new concurrency regression does not yet guarantee that its third sender has entered the call and retained the original end before close ordup2.CheckHeldSequencedEndCloseincrementsstartedbeforesend_nid_postfixand its descriptor lookup. Waiting 100 ms whilefinished == 0therefore cannot distinguish a sender blocked inSequencedRoomfrom one descheduled immediately after++started.Independent Windows 11 verification:
guest_socket_pair_tests: passed;ctest -R '^guest_socket_pair$' --repeat until-fail:20: 20/20 passed;Udp.cppwith the same new regression timed out/fails, confirming that the production change fixes the reported retained-peer case;++started, released only after close/replacement and the two original senders completed, makes the exact fixed fixture fail its existingholderFinished == 0assertion in both variants. The late close sender seesEBADFbecause its descriptor is already gone; the latedup2sender resolves the replacement descriptor and returnsEPIPEearly. It never proves that it retained the closed original end.Please add a deterministic handshake that is reached only after the holder has resolved and retained the original sequenced end and entered the blocking send path, then perform close/
dup2. This request is limited to the regression fixture; I found no remaining production-code blocker in the reviewed fix.Conventions, script registration and
git diff --checkpass. No macOS run was performed locally.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T18:08:50Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review covered all changed files, and the author reports platform test results that I did not run.
What I ran
No build or tests were run. The supplied review bundle identifies head
305a1a416ba83c6bebf3a99866e4f7cc8093fac2. I read the diff and all three changed files at the pinned head. I did not runrepo_read.pybecause repository reader commands are unavailable in this review interface.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run builds, tests, or platform checks. The change’s behavior on macOS, Windows, Linux, and physical console hardware is not independently verified. The supplied review bundle included
description.md,commits.md,manifest.json, anddiff.patch;review/files.jsonwas not available. The manifest lists three changed files, all marked included, and I read all three at head:core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/tests/GuestSocketPair.cpp, anddocs/dev/debt/changes/fix-libkernel-socketpair-datagram-full-enobufs.md.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T12:48:10Z.
Review: COMMENTED
Actionable comments posted: 4
4acbaad4-d842-4e5d-bd4b-801ade0b2878Reviewing files that changed from the base of the PR and between
e17dd1c40fand6da03cba8a.core/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/tests/GuestSocketPair.cppdocs/dev/debt/changes/fix-libkernel-socketpair-datagram-full-enobufs.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T12:53:04Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the inspected changes shows a concrete defect; the supplied macOS and Windows results support the reported behavior, but I did not run checks on this head.
What I ran
Reviewed head
6da03cba8a4d8d7a8effc5de4b972fc700500487using the prepared diff and pinned reader. No commands or tests were run. The description reports macOS tests atd501609a84and Windows tests on a merged build; these are author supplied results, not runs I performed.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not build or run tests on this head, verify macOS or Windows behavior, or inspect all unchanged callers. The prepared manifest lists three changed files, all marked included; I read all three through the pinned reader:
Udp.cpp,GuestSocketPair.cpp, andfix-libkernel-socketpair-datagram-full-enobufs.md. Nofiles.jsonwas available in the review bundle, so exclusions by rule are not verified. The review covered changed hunks and targeted surrounding code, not the full 3,841-lineUdp.cppor 820-lineGuestSocketPair.cpp.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T15:01:28Z.
Review: COMMENTED
Actionable comments posted: 2
9c05487f-5774-4b27-abfe-cba4ba8d181dReviewing files that changed from the base of the PR and between
6da03cba8aand008f8c9bb5.core/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/tests/GuestSocketPair.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T15:07:30Z.
Review: APPROVED
Reviewed — looks good
The reviewed head adds macOS sequenced-packet socketpair emulation and lifecycle handling; the source supports the stated behavior, though I could not run the checks here.
What I ran
Read the prepared diff and the three changed files at head
008f8c9bb595678e03a47ff328d9036af2dd25e3usingrepo_read.py. No build or test command was run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build or tests were run in this review. Windows, macOS and Linux behavior was not independently confirmed. The author reports Windows and macOS test runs; Linux was not built. No files were excluded from the changed-file review.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:28:21Z.
Review: COMMENTED
Built and ran
guest_socket_pairon Linux with this head integrated. The native control passed. I reviewed the Darwin path's use of the guest sequenced-pair state around the host datagram socket. The emulated close, shutdown, and receive behavior still need runtime coverage on macOS and Windows.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.