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

Merged
milescoviello merged 2 commits from upstream-pr/6142 into main 2026-10-18 15:23:20 +00:00
milescoviello commented 2026-10-14 23:16:57 +00:00 (Migrated from github.com)

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 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:

  • it sets SO_SNDBUF on a libkernel TCP socket through sceNetSetsockopt;
  • it sets TCP_NODELAY on the same socket, the call the title makes, which libkernel answers since #5565;
  • once the socket is closed, the same call fails with EBADF.

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 3c87cdfda:

  • guest_sce_net aborts with main's Export.cpp and passes with the change.
  • All 376 guest_* tests pass.
  • tools/check_conventions.py --base upstream/main passes.
  • PPSA30839 relinked with --to-intel, 90 s, every libSceNet socket call traced under gdb:
    • On main, sceNetSetsockopt(11, IPPROTO_TCP, TCP_NODELAY) returns 0x80410109.
    • With this change, it reaches libkernel and fails with ENOPROTOOPT (0x8041012a), because libkernel's setsockopt() on main models only SOL_SOCKET options.
    • With this change, #5565 (which adds TCP_NODELAY to libkernel) and #6140, it returns 0 for descriptors 11 and 9. The title then also closes descriptor 7 successfully.

Rebased onto main 82ddae75b, with the TCP_NODELAY assertion added (f5e902734): 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 5d9dcc42d): 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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4865846939 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T23:16:57Z. --- ### 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: - it sets `SO_SNDBUF` on a libkernel TCP socket through `sceNetSetsockopt`; - it sets `TCP_NODELAY` on the same socket, the call the title makes, which libkernel answers since #5565; - once the socket is closed, the same call fails with `EBADF`. 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` 3c87cdfda: - `guest_sce_net` aborts with `main`'s `Export.cpp` and passes with the change. - All 376 `guest_*` tests pass. - `tools/check_conventions.py --base upstream/main` passes. - PPSA30839 relinked with `--to-intel`, 90 s, every libSceNet socket call traced under gdb: - On `main`, `sceNetSetsockopt(11, IPPROTO_TCP, TCP_NODELAY)` returns `0x80410109`. - With this change, it reaches libkernel and fails with `ENOPROTOOPT` (`0x8041012a`), because libkernel's `setsockopt()` on `main` models only SOL_SOCKET options. - With this change, #5565 (which adds `TCP_NODELAY` to libkernel) and #6140, it returns 0 for descriptors 11 and 9. The title then also closes descriptor 7 successfully. Rebased onto `main` 82ddae75b, with the `TCP_NODELAY` assertion added (f5e902734): `guest_sce_net` passes 3 of 3, and all 383 `guest_*` tests pass. @karimibrahim07 [checked the previous head on Windows](https://github.com/boykopovar/AnyPS5/pull/6142#pullrequestreview-5548918506) (Windows 11 Pro, WinLibs GCC 15.2.0, Release, merged onto 5d9dcc42d): `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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA30839 (MXGP 26's `TCP_NODELAY` calls) - [x] GPUs tested: none needed (no GPU code); host Ubuntu 24.04, and Windows 11 by @karimibrahim07 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-14 23:23:00 +00:00 (Migrated from github.com)

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.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6180685089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142#issuecomment-6180685089). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T23:23:00Z. --- <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/5836) | `core/libs/prx/libSceNet/Export.cpp`<br>`core/libs/tests/GuestSceNet.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestSceNet.cpp` | | [PR 6138](https://www.github.com/boykopovar/AnyPS5/pull/6138) | `core/libs/tests/GuestSceNet.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceNet/Export.cpp` |
karimibrahim07 commented 2026-10-16 14:08:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T14:08:47Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5548918506 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142#pullrequestreview-5548918506). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-16T14:08:47Z. **Review:** COMMENTED --- 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 commented 2026-10-16 14:19:34 +00:00 (Migrated from github.com)

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_NODELAY calls, so I dropped the dependency note. I rebased onto main 82ddae75b and added your exact TCP_NODELAY call to CheckKernelSocketOption (f5e902734). 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6217510142 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142#issuecomment-6217510142). Originally posted by [milescoviello](https://github.com/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_NODELAY` calls, so I dropped the dependency note. I rebased onto `main` 82ddae75b and added your exact `TCP_NODELAY` call to `CheckKernelSocketOption` (f5e902734). `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 commented 2026-10-16 23:53:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T23:53:43Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226915677 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142#issuecomment-6226915677). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T23:53:43Z. --- 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 commented 2026-10-17 13:27:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T13:27:08Z.


Rebased onto main 40315fcf8c (9c9311af8f). 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234432865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142#issuecomment-6234432865). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T13:27:08Z. --- Rebased onto `main` 40315fcf8c (9c9311af8f). 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 commented 2026-10-18 15:23:28 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251634339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6142#issuecomment-6251634339). Originally posted by [oneandonlydean](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6142
No description provided.