fix(libSceNet): set an option on a libkernel socket through sceNetSetsockopt #6142
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6142"
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 milescoviello on 2026-10-14T23:16:57Z.
What
MXGP 26: The Official Game (PPSA30839) opens TCP sockets with libkernel's
socket()and turns onTCP_NODELAYon them withsceNetSetsockopt.sceNetSetsockoptonly looked in libSceNet's own socket table, so the call failed withSCE_NET_ERROR_EBADF(0x80410109). On the console, libSceNet's calls and libkernel's socket calls work on the same kernel sockets.Now, when
sceNetSetsockoptgets a descriptor that libSceNet doesn't own but libkernel has open as a socket (GuestSocketIsOpen_nid_no_patch), it passes the call to libkernel'ssetsockopt(). libkernel answers the options it models and fails the rest the way it already does. Any other descriptor still fails withEBADF. The fallback runs afterg_mutexis released, as in #6140.guest_sce_netgains a check:SO_SNDBUFon a libkernel TCP socket throughsceNetSetsockopt;TCP_NODELAYon the same socket, the call the title makes, which libkernel answers since #5565;EBADF.This is the
sceNetSetsockopthalf of #6140, which does the same forsceNetSocketClose. The two don't depend on each other and merge cleanly in either order: they share only one identical#includeline.Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on
main3c87cdfda:guest_sce_netaborts withmain'sExport.cppand passes with the change.guest_*tests pass.tools/check_conventions.py --base upstream/mainpasses.--to-intel, 90 s, every libSceNet socket call traced under gdb:main,sceNetSetsockopt(11, IPPROTO_TCP, TCP_NODELAY)returns0x80410109.ENOPROTOOPT(0x8041012a), because libkernel'ssetsockopt()onmainmodels only SOL_SOCKET options.TCP_NODELAYto libkernel) and #6140, it returns 0 for descriptors 11 and 9. The title then also closes descriptor 7 successfully.Rebased onto
main82ddae75b, with theTCP_NODELAYassertion added (f5e902734):guest_sce_netpasses 3 of 3, and all 383guest_*tests pass.@karimibrahim07 checked the previous head on Windows (Windows 11 Pro, WinLibs GCC 15.2.0, Release, merged onto
5d9dcc42d):guest_sce_net,guest_socket*,guest_tcpandguest_udppass, 22 of 22. They also found that with #5565 merged,mainanswersTCP_NODELAYin libkernel, so this PR alone makes the title'sTCP_NODELAYcalls succeed, and they suggested the assertion above.sceNetGetsockoptstill looks only in libSceNet's table, so a title that reads such an option back would still getEBADF. That is a separate change.Not checked on a console.
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)TCP_NODELAYcalls)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T23:23:00Z.
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/libSceNet/Export.cppcore/libs/tests/GuestSceNet.cppcore/libs/tests/GuestSceNet.cppcore/libs/tests/GuestSceNet.cppcore/libs/prx/libSceNet/Export.cppImported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T14:08:47Z.
Review: COMMENTED
Windows check of head
488172b76, merged ontomain5d9dcc42d(clean merge). Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release.guest_sce_net,guest_socket*,guest_tcpandguest_udppass, 22 of 22.mainalready answersTCP_NODELAYin libkernel (SetTcpLevelOption). I addedsceNetSetsockopt(kernel, 6 /* IPPROTO_TCP */, 1 /* TCP_NODELAY */, &one, 4) == 0toCheckKernelSocketOptionlocally, and it passes onmain+ this PR. So this PR alone takes MXGP'sTCP_NODELAYcalls to 0, and the "Depends on" note about #5565 can go. Worth adding that line to the test, since it's the exact call the title makes.Code: the fallback runs after
g_mutexis released and only for descriptors libkernel has open as sockets, so a closed or foreign descriptor still getsEBADF(the test covers that). The errno comes back throughfail(*__error_nid_postfix()), which gives0x8041012aforENOPROTOOPT, as in your trace. One possible follow-up issceNetGetsockopt, which still looks only in libSceNet's table. A title that sets an option this way might also read it back.AI-assisted: yes. I ran the build and tests above, including the extra
TCP_NODELAYcheck.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T14:19:34Z.
Thanks @karimibrahim07, both points were right. #5565 being in means this PR alone is enough for MXGP's
TCP_NODELAYcalls, so I dropped the dependency note. I rebased ontomain82ddae75band added your exactTCP_NODELAYcall toCheckKernelSocketOption(f5e902734).guest_sce_netpasses 3 of 3 and all 383guest_*tests pass here. I leftsceNetGetsockoptfor a separate PR and noted it in the description.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T23:53:43Z.
Checked the libkernel fallback in
sceNetSetsockopt(errno propagated asNET_ERROR_BASE | errno, unknown descriptors stillEBADF) and the newCheckKernelSocketOption:guest_sce_netpasses on the merged tree and fails without theExport.cppchange. Windows run by @karimibrahim07 covers the earlier head. Merging.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T13:27:08Z.
Rebased onto
main40315fcf8c(9c9311af8f). The only conflict was inGuestSceNet.cpp'smain(), wheremainaddedCheckOnesBroadcast();next to this PR'sCheckKernelSocketOption();. I kept both calls. No other change.On Ubuntu 24.04 (GCC 13.3, Release),
guest_sce_netpasses 3 of 3, andctest -R '^guest_|libc'passes 405 of 405.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T15:23:28Z.
Merged while @adriadam10 is away, after #6140: the review passed and full CI is green on this head.