feat(libkernel): answer TCP_NODELAY, SO_NOSIGPIPE and SO_NBIO on a guest socket #5565
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5565"
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 Dripl1x on 2026-10-14T00:02:16Z.
What
setsockoptandgetsockopton a socket fromsocket()answer the SOL_SOCKET options #4796 added and fail every other option and level withENOPROTOOPT. This PR answers three more, the ones the discussion of #4796 left as a separate change. They are added to #4796's structure: the handling is inSocket/src/SocketOptions.cpp, and the per-socket state is inSocketOptionStateundermodeMutex.TCP_NODELAY(IPPROTO_TCP, 1) is set on the host socket and reads back asTF_NODELAY(4), as FreeBSD 11.4'stcp_default_ctloutputreturns it. TheIPPROTO_TCPlevel on a datagram orAF_UNIXsocket fails withEINVAL, asip_ctloutputanduipc_ctloutputanswer it. Every other TCP option still fails withENOPROTOOPT.setsockoptandgetsockoptpass level 6 to the newSetTcpLevelOptionandGetTcpLevelOption, and SOL_SOCKET to the existing functions.SO_NOSIGPIPE(0x800) is kept inSocketOptionState::noSignaland reads back as its own bit (sogetopt). It takes effect: on Linux asend,sendto,sendmsgorwriteon that socket passesMSG_NOSIGNALto the host, so a broken connection givesEPIPEwithout the host'sSIGPIPEending the title, askern_senditandsoo_writedecide it.sendandsendtoread the flag undermodeMutex;sendmsgandwritego through them. An accepted socket takes the option from its listener, assonewconncopies the options. Windows raises no signal either way.SO_NBIO(0x1200), the console's own non-blocking option, switches the host socket withFIONBIOand reads back as 0 or 1, assceNetSetsockoptandsceNetGetsockopttreat it here. The non-blocking flag moves fromSocketintoSocketOptionState, so this option,fcntl,ioctl(FIONBIO)andacceptuse the same state.SocketOptions.cpp. A value shorter than anintfails withEINVAL(sooptcopyin), and so does a null value.getsockoptcopies as many bytes as the buffer holds. FreeBSD'skern_setsockoptreturnsEFAULTfor a null value instead; that applies to every option here and is recorded in the debt entry rather than changed.guest_socket_optionsexpectedSO_NOSIGPIPEto fail. It now checks that the option reads back as its bit. The debt entry forSocketOptions.cppand the sentence onSIGPIPEin the socket read/write entry are updated.Titles that ask for them:
SO_NBIOon every curl socket and fails the request when the call fails; VITA5 (PPSA39410) returns the error of the same call. Onmainthe call fails withENOPROTOOPT. This is read from their sources; neither title was run.TCP_NODELAY,SO_NOSIGPIPEand option0x1200failing withENOPROTOOPTonmain; curl carries on without them.TCP_NODELAYis set by 29 titles,SO_NOSIGPIPEby 28,SO_NBIOby 18 and read by 12. The level and option were recovered at 840 of 2661setsockoptcall sites, so these are lower bounds. The lists and the method are in this comment.Related:
F_GETFDandF_SETFDin front of theF_GETFLline offcntl. This branch is rebased onto it, and that line reads the flag fromSocketOptionState.SO_SNDTIMEOandSO_RCVTIMEOto the same structure.Tested
Windows 11, Ryzen 7 5800H, WinLibs MinGW-w64 GCC 15.2.0 r7; Ubuntu 26.04 under WSL, GCC 15.2.0. Release,
BUILD_TESTING=ON, root configuration withFFMPEG_PREBUILT_DIRpointed at an already unpacked package. Head7e79f36edonmain4c1de0c0c.guest_socket_stream_optionscovers the three options on a loopback TCP pair, a datagram socket and anAF_UNIXpair. It checks values and read-back, short and truncated arguments, and theEINVALof the TCP level on the other socket kinds. It also checksEAGAINfrom a receive afterSO_NBIOandF_GETFLfollowing it, inheritance by an accepted socket, andEPIPEfromsendandwriteaftershutdown(SHUT_WR). On Linux it counts hostSIGPIPEdeliveries: none whileSO_NOSIGPIPEis set orMSG_NOSIGNALis passed, and one after the option is cleared.SocketOptions.hpp,SocketOptions.cppandUdp.cppfrommainand the tests of this PR,guest_socket_stream_optionsfails on both systems withsocket stream option check failed at line 91, errno 42.guest_socket_optionsfails withsetsockopt of an integer option failed (errno 42).guest_socket_stream_optionsandguest_socket_optionspass 20 of 20 repeated runs. Of the twelve socket tests eleven pass.guest_udptimes out after 20 s, and does so onmaintoo: on this machine a datagram to[::1]is never delivered, even between two plain host sockets outside AnyPS5.guest_udpincluded.git diff --checkpass.Not tested: any title, a console, macOS, the full test suite. Full PR builds need a collaborator's manual Build run.
Checklist
main; no other open PR implements these three options.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T00:02:42Z.
Evidence for head
36ff565feonmaind1670009f. Local paths are replaced with<build>and<source>.Which catalog titles ask for the three options
setsockopt(IPPROTO_TCP, TCP_NODELAY)getsockopt(IPPROTO_TCP, TCP_NODELAY)setsockopt(SOL_SOCKET, SO_NOSIGPIPE)getsockopt(SOL_SOCKET, SO_NOSIGPIPE)setsockopt(SOL_SOCKET, 0x1200)getsockopt(SOL_SOCKET, 0x1200)Method: the 65 release archives listed in ps5-homebrew-catalog were downloaded (SHA-256 equal to the catalog records); 63 of them hold an
eboot.bin, which was unwrapped from its fake-signed container. Nothing was run. Each call site ofsetsockoptandgetsockoptwas found through the import's GOT slot, and the level and option were read from the instructions before it (objdump). That recovers a value only where the compiler loads a constant right before the call: both were recovered at 840 of 2661setsockoptcall sites, so the counts are lower bounds.Tests
Windows: guest_socket_stream_options, 20 repeated runs
Windows: the nine socket tests (guest_udp times out on this machine with main's Udp.cpp too, see the control)
Windows control: Udp.cpp from main, new test
Linux: the ten socket tests
Linux control: Udp.cpp from main, new test
The two controls were run on
mainbfc10637d, before the rebase ontod1670009f;Udp.cppand the test are the same on both.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T00:09:32Z.
The PR overlap check lists four open pull requests against this one, so the checklist declares the order
Depends on: #4796, #4903, #4920, #5403. None is a functional prerequisite; this PR goes after them and is rebased when each lands. Trialgit merge-treeresults for head36ff565fe:79e162110): conflict inUdp.cpponly, where this PR adds one line tosetsockoptand one togetsockoptright before the lines yours replaces. Your PR is the base of this one in substance. After it lands the three options move into yourSocketOptions.cpp, and the check inGuestSocketOptions.cppthatSO_NOSIGPIPEfails changes to this PR's behaviour: here the option is not only kept, on Linux it makes a send or write passMSG_NOSIGNAL, which is what the review of #4796 asked for before accepting it.2cbec36e5), @xXPBSXx #4920 (2e553b97c) and @EagleBearerYS #5403 (ed2b2e5aa): conflict indocs/dev/debt/libkernel.mdonly. This PR corrects the sentence aboutSIGPIPEin the socket read and write entry, and yours add or edit the entries next to it. Keeping both sides resolves each.If one of you prefers this PR first, say so and I drop that number from the line.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:12:04Z.
Review: CHANGES_REQUESTED
#4796 is merged, so this needs a rebase and a port before it can land:
setsockopt/getsockopton main now delegate toGuestSockets::SetSocketLevelOption/GetSocketLevelOptioninSocket/src/SocketOptions.cpp, with the per-socket state inSocket::optionsundermodeMutex(Udp.cppsetsockopt_nid_postfix).Udp.cppconflicts on exactly those lines. Please moveSO_NOSIGPIPE,SO_NBIOand theIPPROTO_TCPhandling into that structure (theSO_NOSIGPIPEflag belongs inSocketOptionState, not a separate atomic read outside the lock) instead of a second dispatcher in front of it.core/libs/tests/GuestSocketOptions.cpp:155on main expectsSO_NOSIGPIPE(0x800) to fail; it has to change with this behaviour, and your new test should keep passing next to it.acceptinheritance and theMSG_NOSIGNALonsend/sendto/write; those parts look right againstkern_sendit/sonewconn.docs/dev/debt/libkernel.mdconflicts with main; "Depends on: #4796, #4903, #4920, #5403" no longer matches (#4796 and #4903 merged, #4920 and #5403 closed). Update it to what is actually open.Once it is rebased on current main with
guest_socket_stream_optionsandguest_socket_optionspassing, it should be ready for another look.Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T15:32:28Z.
@adriadam10 ported to
main84b01f9cdas you described. It is one commit,1e4783573:SO_NOSIGPIPEandSO_NBIOare handled inSetSocketLevelOptionandGetSocketLevelOption.TCP_NODELAYis in newSetTcpLevelOptionandGetTcpLevelOptioninSocketOptions.cpp.setsockoptandgetsockoptpick the function by level, SOL_SOCKET or 6, undermodeMutex. TheOwnOption/SetOwnOption/GetOwnOptiondispatcher is gone.noSignalis a field ofSocketOptionState, andsendandsendtoread it undermodeMutex;sendmsgandwritego through them.nonblockingmoved fromSocketintoSocketOptionStatetoo, soSO_NBIO,fcntl,ioctl(FIONBIO)andacceptshare one flag.acceptcopiesnoSignalin the same locked block that reads the listener'snonblocking.MSG_NOSIGNALonsend/sendtois unchanged.GuestSocketOptions.cpp:SO_NOSIGPIPEis now checked to read back as its bit. The other four options in that loop still fail withENOPROTOOPT.EINVAL. My first version returnedEFAULTthere, afterkern_setsockopt; the debt entry now records that difference for every option.SocketOptions.cppdebt entry and theSIGPIPEsentence of the socket read/write entry are updated.Depends onnow lists only #5020, which changes the lines next to theF_GETFLline this PR touches. #4796 and #4903 are merged, and #4920 and #5403 are closed.Results at
1e4783573:guest_socket_stream_optionsandguest_socket_optionspass 20 of 20 repeated runs, and 11 of the 12 socket tests pass.guest_udptimes out here onmaintoo, because a VPN on this machine drops IPv6 loopback traffic: a datagram to[::1]never arrives, even between two plain host sockets.guest_udpincluded.SocketOptions.hpp,SocketOptions.cppandUdp.cppfrommain, both tests fail on both systems.guest_socket_stream_optionsstops atline 91, errno 42, andguest_socket_optionswithsetsockopt of an integer option failed (errno 42).#5617 is rebased onto this commit.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:17:30Z.
Review: APPROVED
Re-checked on the current head, merged onto main:
SocketOptionStateundermodeMutex; no second dispatcher inUdp.cpp.guest_socket_optionsupdated forSO_NOSIGPIPE;guest_socket_optionsandguest_socket_stream_optionspass, and both fail with theSocketOptions/Udp.cppchanges reverted.acceptinheritance andMSG_NOSIGNALonsend/sendto/writekept; debt doc matches what is open.Merging once the full Build is green.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:08:03Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/tests/GuestSocketOptions.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T14:13:18Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
7e79f36edmerged on mainb08db6a09:This ran after the merge (
1036905b5), so it is a post-merge confirmation. "Before" is main8856f180c(before the merge) and, as a clean control,b08db6a09with onlySocketOptions.hpp,SocketOptions.cppandUdp.cppfrom1036905b5^1. Catalog releases,app0/eboot.binstaged,relinker --windows --registry unused-filter=0, display on, 90 s per run. The host was busy with other builds, so frame counts follow load. To see the calls I wrapped libkernelsetsockopt/getsockoptin a local stderr trace (not part of any PR).ProsperoRadio (PPSA99001)
8856f180c: running at 90 s,ProsperoRadio | FPS: 9.68 (1519), title log[ProsperoRadio][http] non-blocking sockets: NOT set.ProsperoRadio | FPS: 18.99 (1907). 16 curl sockets, each withsetsockopt(fd, 0x6, 0x1, 1) = -1 errno 42,setsockopt(fd, 0xffff, 0x800, 1) = -1 errno 42andsetsockopt(fd, 0xffff, 0x1200, 1) = -1 errno 42;non-blocking sockets: NOT set.b08db6a09, run 1:ProsperoRadio | FPS: 59.95 (4932),[ProsperoRadio][http] non-blocking sockets: set.b08db6a09, run 2 (traced):ProsperoRadio | FPS: 35.48 (493). The same 16 sockets, nowTCP_NODELAY,SO_NOSIGPIPEandSO_NBIOeach= 0, andgetsockopt(fd, 0xffff, 0x1007) = 0 value 0;non-blocking sockets: set./<sandbox>/common/cert/CA_LIST.cerwith every build. That is a separate gap.VITA5 (PPSA39410)
8856f180c: running at 90 s,VITA5 PPSA17035 | FPS: 57.36 (3198).FPS: 49.00 (3670)): 30 IPC sockets, each stopping atsetsockopt(fd, 0xffff, 0x1200, 1) = -1 errno 42, becauseconfigure_socketreturns there.b08db6a09, run 1:FPS: 30.24 (2952).b08db6a09, run 2 (traced,FPS: 45.96 (3669)): 31 sockets with0x1200,TCP_NODELAY,SO_SNDBUF 65536andSO_RCVBUF 262144, all= 0.[VD5] dock attached=0 vita=0in all runs; no Vita is attached here.ProsperoStore (PPSA99000)
8856f180c:ProsperoStore | FPS: 17.17 (1267).b08db6a09:FPS: 15.74 (1007)andFPS: 11.25 (629).setsockoptcall: on this host it logs[STORE] transport elevated=1 ca_list=0 -> sceHttpand fails through sceHttp (http rc=0x80431063 ... The network request failed), so the native-curlSO_NBIOcallback is not reached.No run had a stop line.
Tests
guest_socket_optionsandguest_socket_stream_optionspass 3/3 (--repeat until-fail:3), onb08db6a09and with #5617 on top.1036905b5^1, tests kept): both fail as in the description, withsetsockopt of an integer option failed (errno 42)andsocket stream option check failed at line 91, errno 42.Suite.
ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'on this tree with #5617 merged: 825 tests, 16 failed under host load. 14 of the 16 pass when rerun serially.prx_thread_local_destructorsreports the libSceAgcDrivertraceDrawKeyLookupthread_local, which #6349 fixes afterb08db6a09.hardware_oracle_comparehits its 20 s limit under load.Conventions.
tools/check_conventions.pywith title and description passes.git diff --checkis clean.Review. The FreeBSD links are pinned to
8c639945a(therelease/11.4.0commit), and the cited lines match:TF_NODELAYread back as 4,so_options & SO_NOSIGPIPE,EINVALfromsooptcopyinand fromip_ctloutput/uipc_ctloutputfor the TCP level on UDP and AF_UNIX, andENOPROTOOPTfor the other TCP options. The TCP option is mapped through the host'sIPPROTO_TCP/TCP_NODELAYrather than passed through. StoringSO_NOSIGPIPEwithout effect on Windows is exact, since Winsock raises no signal.SO_NBIOshares the non-blocking flag withfcntl,ioctl(FIONBIO)andacceptundermodeMutex. No concerns.Written with Claude Code assistance.