Repository navigation
feat(libkernel): implement socketpair - #1711
Conversation
210ea0c to
29a11db
Compare
|
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
So Related, from #1727: on Windows a AI-assisted: yes (Claude Code). |
AF_UNIX pairs as FreeBSD 11 makes them: SOCK_STREAM, SOCK_DGRAM and SOCK_SEQPACKET with protocol 0, SOCK_NONBLOCK applied to both ends and SOCK_CLOEXEC accepted, EAFNOSUPPORT for an unknown family, EOPNOTSUPP for AF_INET and AF_INET6, EPROTONOSUPPORT for type 0 or a protocol, EPROTOTYPE for another type, EFAULT for a null output, and nothing written on failure. The ends are guest sockets, so send, recv, shutdown, fcntl, poll and close work on them; getsockname and getpeername report the unnamed AF_UNIX address, recvfrom and recvmsg no address for a stream and the unnamed one for a datagram. On Linux the pair is the host's socketpair; on Windows a loopback TCP connection or two connected UDP sockets, and SOCK_SEQPACKET throws. The remaining differences from the console are recorded in TechnicalDebt. OpenSSL's QUIC notifier in 15 catalog titles creates such a pair. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
29a11db to
8f31696
Compare
|
Thanks for the Windows run and the mutation check on the datagram pair. Added to the Tested section, and the |
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 onmainb858fdc, 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 onmain4b005b2):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 Four open-source homebrew titles stop at start-up on unresolved imports (sysctl, pthread_set_name_np, isatty, mkstemp, signal sets, Opus decoders) #1578 audit onmain4b005b2 + fix(relinker): keep Linux imports declared from host modules off guest exports #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 Four open-source homebrew titles stop at start-up on unresolved imports (sysctl, pthread_set_name_np, isatty, mkstemp, signal sets, Opus decoders) #1578.main6b56175), run 37828080042:guest_socket_pairpasses its three repeats with theSOCK_SEQPACKETandEPIPEcases excluded, full suite 474/474. The run of the previous commit (210ea0c) aborted at the readiness wait after the peer'sshutdown, which acceptedPOLLINonly. hikazey ran 29a11db merged ontomainb858fdc on 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