fix(libSceNet): read an option of a libkernel socket through sceNetGetsockopt #11243

Merged
parl0v merged 1 commit from upstream-pr/11243 into main 2026-10-26 22:05:27 +00:00
parl0v commented 2026-10-25 22:28:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-25T22:28:47Z.


What

sceNetGetsockopt on a descriptor that libSceNet doesn't own, but libkernel has open as a socket, now goes to libkernel's getsockopt(), which answers the options it models. Any other descriptor still fails with EBADF. The fallback runs after g_mutex is released. It's the getter counterpart of 3573289f2f, which added the same fallback to sceNetSetsockopt for MXGP 26 (PPSA30839).

Why

Human Fall Flat (PPSA02429) opens its sockets with libkernel's socket() and reads options of them with sceNetGetsockopt. On upstream main every one of those calls fails with SCE_NET_ERROR_EBADF: the game printed sceNetGetsockopt failed with 0x80410109 18 times in its first 60 s on my test box. On the console both libraries work on the same kernel sockets. That's the position 8b81fa09bf and 3573289f2f already take.

Tested

  • New CheckKernelSocketGetOption in guest_sce_net, on a libkernel TCP socket:
    • It sets SO_SNDBUF through sceNetSetsockopt and reads it back through sceNetGetsockopt, and the value matches libkernel's own getsockopt.
    • It sets TCP_NODELAY and reads it back as nonzero.
    • An unknown level fails with EINVAL.
    • After close() the call fails with EBADF.
  • On main with only the test applied, guest_sce_net fails. With the fix it passes. MinGW Release build, Windows 10.
  • Human Fall Flat with this change and the epoll change: 0 sceNetGetsockopt failures over 150 s.
  • python tools/check_conventions.py --base upstream/main passes.
  • #9515 does the reverse direction (libkernel getsockopt on libSceNet sockets). The two compose: this fallback only runs when libkernel owns the descriptor, so the calls can't loop. Its hunk in sceNetGetsockopt is in the option switch, and this one is at the table lookup at the top.

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 (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3060 12 GB, NVIDIA 617.42, Windows 10 (title run); the change itself is CPU-side
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009356994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11243). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-25T22:28:47Z. --- ### What `sceNetGetsockopt` on a descriptor that libSceNet doesn't own, but libkernel has open as a socket, now goes to libkernel's `getsockopt()`, which answers the options it models. Any other descriptor still fails with `EBADF`. The fallback runs after `g_mutex` is released. It's the getter counterpart of 3573289f2f, which added the same fallback to `sceNetSetsockopt` for MXGP 26 (PPSA30839). ### Why Human Fall Flat (PPSA02429) opens its sockets with libkernel's `socket()` and reads options of them with `sceNetGetsockopt`. On upstream main every one of those calls fails with `SCE_NET_ERROR_EBADF`: the game printed `sceNetGetsockopt failed with 0x80410109` 18 times in its first 60 s on my test box. On the console both libraries work on the same kernel sockets. That's the position 8b81fa09bf and 3573289f2f already take. ### Tested - New `CheckKernelSocketGetOption` in `guest_sce_net`, on a libkernel TCP socket: - It sets `SO_SNDBUF` through `sceNetSetsockopt` and reads it back through `sceNetGetsockopt`, and the value matches libkernel's own `getsockopt`. - It sets `TCP_NODELAY` and reads it back as nonzero. - An unknown level fails with `EINVAL`. - After `close()` the call fails with `EBADF`. - On main with only the test applied, `guest_sce_net` fails. With the fix it passes. MinGW Release build, Windows 10. - Human Fall Flat with this change and the epoll change: 0 `sceNetGetsockopt` failures over 150 s. - `python tools/check_conventions.py --base upstream/main` passes. ### Related - #9515 does the reverse direction (libkernel `getsockopt` on libSceNet sockets). The two compose: this fallback only runs when libkernel owns the descriptor, so the calls can't loop. Its hunk in `sceNetGetsockopt` is in the option switch, and this one is at the table lookup at the top. ### 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 (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3060 12 GB, NVIDIA 617.42, Windows 10 (title run); the change itself is CPU-side - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 22:32:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:32:15Z.

Review: APPROVED


Reviewed exact head 6cbb4ff7fd81271de710d65a9ff0784fc7b4ee28. The fallback is limited to descriptors absent from libSceNet’s table that libkernel still recognizes as sockets, and it runs after releasing g_mutex, avoiding a lock inversion; native errno is translated through the libSceNet error path. The test compares SO_SNDBUF readback against libkernel and covers TCP_NODELAY, unsupported levels, and a closed descriptor. Current-main conventions/diff-check pass. Hosted product tests were skipped by path policy; the author reports the focused Windows test and title run, which I did not rerun locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645691561 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11243#pullrequestreview-5645691561). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:32:15Z. **Review:** APPROVED --- Reviewed exact head `6cbb4ff7fd81271de710d65a9ff0784fc7b4ee28`. The fallback is limited to descriptors absent from libSceNet’s table that libkernel still recognizes as sockets, and it runs after releasing `g_mutex`, avoiding a lock inversion; native errno is translated through the libSceNet error path. The test compares SO_SNDBUF readback against libkernel and covers TCP_NODELAY, unsupported levels, and a closed descriptor. Current-main conventions/diff-check pass. Hosted product tests were skipped by path policy; the author reports the focused Windows test and title run, which I did not rerun locally.
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!11243
No description provided.