Skip to content

fix(libSceNet): set an option on a libkernel socket through sceNetSetsockopt - #6142

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/net-setsockopt-kernel-socket
Oct 18, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/net-setsockopt-kernel-socket

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What

MXGP 26: The Official Game (PPSA30839) opens TCP sockets with libkernel's socket() and turns on TCP_NODELAY on them with sceNetSetsockopt. sceNetSetsockopt only looked in libSceNet's own socket table, so the call failed with SCE_NET_ERROR_EBADF (0x80410109). On the console, libSceNet's calls and libkernel's socket calls work on the same kernel sockets.

Now, when sceNetSetsockopt gets a descriptor that libSceNet doesn't own but libkernel has open as a socket (GuestSocketIsOpen_nid_no_patch), it passes the call to libkernel's setsockopt(). libkernel answers the options it models and fails the rest the way it already does. Any other descriptor still fails with EBADF. The fallback runs after g_mutex is released, as in #6140.

guest_sce_net gains a check:

This is the sceNetSetsockopt half of #6140, which does the same for sceNetSocketClose. The two don't depend on each other and merge cleanly in either order: they share only one identical #include line.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 3c87cdf:

Rebased onto main 82ddae7, with the TCP_NODELAY assertion added (f5e9027): guest_sce_net passes 3 of 3, and all 383 guest_* tests pass.

@karimibrahim07 checked the previous head on Windows (Windows 11 Pro, WinLibs GCC 15.2.0, Release, merged onto 5d9dcc4): guest_sce_net, guest_socket*, guest_tcp and guest_udp pass, 22 of 22. They also found that with #5565 merged, main answers TCP_NODELAY in libkernel, so this PR alone makes the title's TCP_NODELAY calls succeed, and they suggested the assertion above.

sceNetGetsockopt still looks only in libSceNet's table, so a title that reads such an option back would still get EBADF. That is a separate change.

Not checked on a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA30839 (MXGP 26's TCP_NODELAY calls)
  • GPUs tested: none needed (no GPU code); host Ubuntu 24.04, and Windows 11 by @karimibrahim07
  • AI-assisted: yes

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 5836 core/libs/prx/libSceNet/Export.cpp
core/libs/tests/GuestSceNet.cpp
PR 6044 core/libs/tests/GuestSceNet.cpp
PR 6138 core/libs/tests/GuestSceNet.cpp
PR 7201 core/libs/prx/libSceNet/Export.cpp

@karimibrahim07 karimibrahim07 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows check of head 488172b76, merged onto main 5d9dcc42d (clean merge). Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release.

  • guest_sce_net, guest_socket*, guest_tcp and guest_udp pass, 22 of 22.
  • An update to the description: #5565 is merged now, so main already answers TCP_NODELAY in libkernel (SetTcpLevelOption). I added sceNetSetsockopt(kernel, 6 /* IPPROTO_TCP */, 1 /* TCP_NODELAY */, &one, 4) == 0 to CheckKernelSocketOption locally, and it passes on main + this PR. So this PR alone takes MXGP's TCP_NODELAY calls 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_mutex is released and only for descriptors libkernel has open as sockets, so a closed or foreign descriptor still gets EBADF (the test covers that). The errno comes back through fail(*__error_nid_postfix()), which gives 0x8041012a for ENOPROTOOPT, as in your trace. One possible follow-up is sceNetGetsockopt, 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_NODELAY check.

@milescoviello
milescoviello force-pushed the fix/net-setsockopt-kernel-socket branch from 488172b to f5e9027 Compare October 16, 2026 14:19
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @karimibrahim07, both points were right. #5565 being in means this PR alone is enough for MXGP's TCP_NODELAY calls, so I dropped the dependency note. I rebased onto main 82ddae7 and added your exact TCP_NODELAY call to CheckKernelSocketOption (f5e9027). guest_sce_net passes 3 of 3 and all 383 guest_* tests pass here. I left sceNetGetsockopt for a separate PR and noted it in the description.

AI-assisted: yes

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the libkernel fallback in sceNetSetsockopt (errno propagated as NET_ERROR_BASE | errno, unknown descriptors still EBADF) and the new CheckKernelSocketOption: guest_sce_net passes on the merged tree and fails without the Export.cpp change. Windows run by @karimibrahim07 covers the earlier head. Merging.

milescoviello and others added 2 commits October 17, 2026 13:22
…sockopt

MXGP 26 (PPSA30839) opens TCP sockets with libkernel's socket() and
turns on TCP_NODELAY with sceNetSetsockopt. libSceNet only looked in its
own socket table, so the call failed with SCE_NET_ERROR_EBADF. On the
console both calls work on the same kernel sockets.

A descriptor libSceNet does not own but libkernel has open as a socket
now goes to libkernel's setsockopt(), which answers the options it
models. Anything else still fails with EBADF. The fallback runs after
g_mutex is released.

guest_sce_net sets SO_SNDBUF on a libkernel TCP socket through
sceNetSetsockopt, and checks that the call fails with EBADF once the
socket is closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Setsockopt

The call MXGP 26 makes; libkernel answers it since boykopovar#5565.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello
milescoviello force-pushed the fix/net-setsockopt-kernel-socket branch from f5e9027 to 9c9311a Compare October 17, 2026 13:26
@milescoviello

Copy link
Copy Markdown
Contributor Author

Rebased onto main 40315fc (9c9311a). The only conflict was in GuestSceNet.cpp's main(), where main added CheckOnesBroadcast(); next to this PR's CheckKernelSocketOption();. I kept both calls. No other change.

On Ubuntu 24.04 (GCC 13.3, Release), guest_sce_net passes 3 of 3, and ctest -R '^guest_|libc' passes 405 of 405.

AI-assisted: yes (Claude Code)

@oneandonlydean oneandonlydean self-assigned this Oct 18, 2026
@oneandonlydean
oneandonlydean merged commit 3f4a7f3 into boykopovar:main Oct 18, 2026
8 checks passed
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Merged while @adriadam10 is away, after #6140: the review passed and full CI is green on this head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants