feat(libkernel): implement socketpair #1711
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1711"
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 SleglJan on 2026-10-08T17:21:17Z.
What
Adds
socketpairto libkernel, inSocket/src/Udp.cppbesidesocketandaccept, with the semantics of FreeBSD 11'skern_socketpairandsocreate:AF_UNIXwithSOCK_STREAM,SOCK_DGRAMorSOCK_SEQPACKETand protocol 0.SOCK_NONBLOCK(0x20000000) puts both ends in non-blocking mode;SOCK_CLOEXEC(0x10000000) is accepted and has nothing to do.socreateandkern_socketpairgive them:EAFNOSUPPORTfor an unknown family;EPROTONOSUPPORTfor type 0 or a non-zero protocol;EPROTOTYPEfor another type;EOPNOTSUPPforAF_INETandAF_INET6with a type and protocol the inet domain has, whose protocols have noconnect2;EFAULTfor a null output. Nothing is written tosvon failure.send,recv(withMSG_NOSIGNALandMSG_PEEK),recvfrom,recvmsg,shutdown,fcntl,pollandclosework on them as on any guest socket, with the existing errno mapping (EAGAIN35,EPIPE32 on Linux). On a pair endgetsocknameandgetpeernamereport FreeBSD's unnamedAF_UNIXaddress (16 bytes, family 1, truncated to the caller's length askern_getsocknamedoes), andrecvfrom/recvmsgreport length 0 for a stream and the unnamed address for a datagram, instead of converting the host's address as an IP one.socketpair(AF_UNIX, ...). On Windows, which has none, aSOCK_STREAMpair is a loopback TCP connection (listener on 127.0.0.1:0 withSO_EXCLUSIVEADDRUSE, connect, accept, peer port checked against the client,TCP_NODELAY), the shape OpenSSL'srio_notifier.cand curl'ssocketpair.cuse on Windows, and aSOCK_DGRAMpair is two UDP sockets bound to 127.0.0.1:0 and connected to each other;SOCK_SEQPACKETthrows there. The differences from the console that remain (full-receiver datagrams,getpeernameafter the peer closed,connect/bind/sendtowith an address on a pair end,ECONNRESETon Windows) are recorded in TechnicalDebt.Of the 34 relinked titles in the homebrew catalog (#1578), 19 import
socketpairand 2 stop at it onmainb858fdc4, PPSA99810 PSBox Cloud Gaming and PPSA99995 Prospero Win: each dies in the host loader withapp.elf: symbol lookup error: app.elf: undefined symbol: MZb0GKT3mo8when run for 8 s in a bubblewrap sandbox on Linux. A third, PPSA74126 Stremio Plus, reaches it oncesceKernelGetFsSandboxRandomWordis in.Overlap: #1091 (socket events) inserts its test block at the same place in
libkernel/CMakeLists.txtand touchesUdp.cppabove the new code; #1459 and #1708 insert a TechnicalDebt line at the same place; #1128 (clang-format) reformats the whole file. Whichever merges second rebases. #1795 (opened after this PR) adds a Linux-onlysocketpairtogether withlstatin the same files; this PR covers both platforms and registers its test in ctest.Tested
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ONon this branch (based onmain4b005b22):ctest --repeat until-fail:3467/467;tools/check_test_registration.pyandtools/check_conventions.py --base upstream/mainpass.guest_socket_pairtest: a stream pair carrying data both ways,pollidle and readable,MSG_PEEK,recvfromwith length 0, the unnamed address fromgetsocknameandgetpeernamewith full and truncated buffers,fcntlF_GETFL/F_SETFLwithEAGAINon an empty non-blocking end,shutdown(SHUT_WR)giving the peer EOF while the other direction stays open,closegiving EOF and (Linux)EPIPEonsend(the readiness wait before each EOF acceptsPOLLHUPas well asPOLLIN, sinceWSAPollreports the peer's FIN asPOLLHUPalone, recorded in TechnicalDebt),EBADFon a second close; aSOCK_NONBLOCK | SOCK_CLOEXECpair non-blocking on both ends; a datagram pair keeping message boundaries with the unnamed sender fromrecvfrom; aSOCK_SEQPACKETpair (Linux); and the errno forAF_INET,AF_INET6, family 3, type 0, type 3 with and without a protocol, a stray type bit, protocol 6 and a null output, withsvleft untouched. Every receive after a send, shutdown or close waits withpollfirst, since loopback TCP on Windows does not deliver synchronously. Written before the implementation; it failed on the unresolved export and passes with it.libkernel.prxexports the NID (MZb0GKT3mo8).tools/import_audit.pyon five of the 19 catalog titles, absent imports before → after (before: the #1578 audit onmain4b005b22+ #1529; after: this branch): PPSA99039 EVO Player 24 → 23, PPSA99082 OpenNOW 36 → 35, PPSA99810 PSBox 64 → 63, PPSA99420 PS5MC 121 → 120, PPSA99003 ProsperoTV 49 → 48. None of them loads yet; the remaining imports are listed in #1578.main6b56175a), run 37828080042:guest_socket_pairpasses its three repeats with theSOCK_SEQPACKETandEPIPEcases excluded, full suite 474/474. The run of the previous commit (210ea0cf) aborted at the readiness wait after the peer'sshutdown, which acceptedPOLLINonly. hikazey ran 29a11db3 merged ontomainb858fdc4on Windows 11 with MinGW-w64 GCC 15.2.0:guest_socket_pair5/5, the full suite 478/478, and 5/5 failures with theconnect(first → second)removed from the Windows datagram path (comment); their note that a streamsendafter the peer closed reportsECONNABORTEDon Windows is added to the TechnicalDebt line.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T17:26:34Z.
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.
main)docs/dev/TechnicalDebt.mdL347-348Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T19:37:37Z.
Windows run of the loopback emulation, since the description lists Linux only: Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto
mainb858fdc4; onlydocs/dev/TechnicalDebt.mdneeded an auto-merge.guest_socket_pairconnect(first → second)removed from the WindowsSOCK_DGRAMpath, test keptSo
NativePairworks on Windows for both shapes: the stream pair (listener on 127.0.0.1:0 withSO_EXCLUSIVEADDRUSE, connect, accept, peer-port check,TCP_NODELAY) and the connected UDP pair. That covers data both ways,SOCK_NONBLOCKviaFIONBIO(EAGAIN35 on an empty end),getsockname/getpeernamereporting the unnamedAF_UNIXaddress, and the error cases. The test's two#ifndef _WIN32blocks are skipped here, as intended.Related, from #1727: on Windows a
writeafter the peer closed a TCP socket gives errno 53 (ECONNABORTED) rather thanEPIPE. That applies to the stream pair too, next to theECONNRESETline this adds to TechnicalDebt.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T19:54:35Z.
Thanks for the Windows run and the mutation check on the datagram pair. Added to the Tested section, and the
ECONNABORTEDafter the peer's close is now in the TechnicalDebt line (8f316964, docs only).Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T09:36:04Z.
Progress report (
4b6ab6b→8f31696)➖ System libraries: 84.76% (+0.0%, +1 implemented functions)
✅ 1 implemented
socketpair_nid_postfix