fix(libkernel): keep the SOL_SOCKET flags a PS5 accepts #10330

Merged
orezraey merged 6 commits from upstream-pr/10330 into main 2026-10-24 17:34:53 +00:00
orezraey commented 2026-10-23 18:02:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T18:02:25Z.


What

The SOL_SOCKET flag options measured on a retail PS5 (firmware 13.60) through libkernel_sys.sprx from a payload process. The source and console log are in this gist (pinet4). This branch is on top of #10327 (and so #10320 and #10302), which edit the same debt entry and option state.

On a stream socket the console:

  • accepts SO_DEBUG (0x1), SO_USELOOPBACK (0x40), SO_REUSEPORT (0x200), SO_TIMESTAMP (0x400), SO_BINTIME (0x2000) and option 0x10000, reads each back as 0 at first, as its bit after any non-zero value, and as 0 after 0;
  • accepts options 0x4000 and 0x8000 (SO_NO_OFFLOAD and SO_NO_DDP in FreeBSD) but fails reading them with ENOPROTOOPT;
  • fails 0x1000 (SO_ACCEPTFILTER) with EINVAL, which AnyPS5 still answers with ENOPROTOOPT, as it was not part of this change.

AnyPS5 failed all of them with ENOPROTOOPT. They are now kept per socket as bits and copied to an accepted socket, as FreeBSD 11.4's sonewconn copies so_options. Only SO_REUSEADDR and SO_REUSEPORT change what the socket does, both set on the host (SO_REUSEPORT as SO_REUSEADDR on Windows). The timestamp options add no control message to recvmsg, listed under Silent stubs, and option 0x10000 and SO_ACCEPTFILTER are in the debt entries too.

Tested

Windows 11, MinGW (winlibs).

  • At head c7b39854eb (main merged after #10327 landed): guest_socket_options, guest_socket_stream_options and guest_net_ctl pass three runs in a row on Windows (MinGW) and on Linux (WSL, GCC); the other socket and net tests also pass three runs on Windows.
  • guest_socket_options checks each flag's read-back, the two write-only options and the short value. The socket and net tests pass three runs in a row.
  • The full suite (-E "^agc_|^select_tests$") passes apart from guest_kqueue, which fails only under -j 14, as on main.
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py: #7511, #8448, #8921 touch nearby lines; whichever lands second keeps both.

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: #8448; it edits the same lines too (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4987148085 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10330). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T18:02:25Z. --- ### What The SOL_SOCKET flag options measured on a retail PS5 (firmware 13.60) through `libkernel_sys.sprx` from a payload process. The source and console log are in [this gist](https://gist.github.com/orezraey/d9efe0da49405f19d72cb35279c0db52) (`pinet4`). This branch is on top of #10327 (and so #10320 and #10302), which edit the same debt entry and option state. On a stream socket the console: - accepts `SO_DEBUG` (0x1), `SO_USELOOPBACK` (0x40), `SO_REUSEPORT` (0x200), `SO_TIMESTAMP` (0x400), `SO_BINTIME` (0x2000) and option 0x10000, reads each back as 0 at first, as its bit after any non-zero value, and as 0 after 0; - accepts options 0x4000 and 0x8000 (`SO_NO_OFFLOAD` and `SO_NO_DDP` in FreeBSD) but fails reading them with `ENOPROTOOPT`; - fails 0x1000 (`SO_ACCEPTFILTER`) with `EINVAL`, which AnyPS5 still answers with `ENOPROTOOPT`, as it was not part of this change. AnyPS5 failed all of them with `ENOPROTOOPT`. They are now kept per socket as bits and copied to an accepted socket, as FreeBSD 11.4's `sonewconn` copies `so_options`. Only `SO_REUSEADDR` and `SO_REUSEPORT` change what the socket does, both set on the host (`SO_REUSEPORT` as `SO_REUSEADDR` on Windows). The timestamp options add no control message to `recvmsg`, listed under Silent stubs, and option 0x10000 and `SO_ACCEPTFILTER` are in the debt entries too. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, MinGW (winlibs). - At head c7b39854eb (main merged after #10327 landed): `guest_socket_options`, `guest_socket_stream_options` and `guest_net_ctl` pass three runs in a row on Windows (MinGW) and on Linux (WSL, GCC); the other socket and net tests also pass three runs on Windows. - `guest_socket_options` checks each flag's read-back, the two write-only options and the short value. The socket and net tests pass three runs in a row. - The full suite (`-E "^agc_|^select_tests$"`) passes apart from `guest_kqueue`, which fails only under `-j 14`, as on `main`. - `tools/check_conventions.py` passes. - `tools/pr_overlap.py`: #7511, #8448, #8921 touch nearby lines; whichever lands second keeps both. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #8448; it edits the same lines too (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 05:39:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:39:18Z.

Review: COMMENTED


Checked against main 7c2400d29b, the pinet4 log in your gist, and FreeBSD 11.4 uipc_socket.c (sosetopt, sogetopt, sonewconn):

  • The kept bits, the write-only 0x4000/0x8000, the short-value EINVAL and the copy to accepted sockets all match pinet4 and uipc_socket.c:2554-2575, 2795-2810 and 603.
  • SO_ACCEPTFILTER (0x1000) is measured in pinet4 as EINVAL for both set and get on a non-listening socket, and FreeBSD 11.4 behaves the same (do_setopt_accept_filter / do_getopt_accept_filter), but AnyPS5 still answers ENOPROTOOPT. That's in the PR body but not in either debt entry; could it go into the debt file? The general getsockopt entry also still says SO_REUSEADDR acts on the host and reads back as its bit, which is now the guest's kept bit.
  • SO_TIMESTAMP and SO_BINTIME now succeed, but recvmsg adds no SCM_TIMESTAMP/SCM_BINTIME. Since that changes what a caller receives, not just UI, does it belong under "Silent stubs" rather than Functional? Main already keeps SO_*LOWAT under Functional, so I'll leave that to the maintainers.
  • Option 0x10000 is SO_REUSEPORT_LB in FreeBSD 12+. If the PS5 kernel treats it that way, two sockets that set it would share a port there but get EADDRINUSE here. Maybe worth a debt note, or forwarding it like SO_REUSEPORT.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637036227 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10330#pullrequestreview-5637036227). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T05:39:18Z. **Review:** COMMENTED --- Checked against main 7c2400d29b, the pinet4 log in your gist, and FreeBSD 11.4 uipc_socket.c (sosetopt, sogetopt, sonewconn): - The kept bits, the write-only 0x4000/0x8000, the short-value EINVAL and the copy to accepted sockets all match pinet4 and uipc_socket.c:2554-2575, 2795-2810 and 603. - SO_ACCEPTFILTER (0x1000) is measured in pinet4 as EINVAL for both set and get on a non-listening socket, and FreeBSD 11.4 behaves the same (`do_setopt_accept_filter` / `do_getopt_accept_filter`), but AnyPS5 still answers ENOPROTOOPT. That's in the PR body but not in either debt entry; could it go into the debt file? The general getsockopt entry also still says SO_REUSEADDR acts on the host and reads back as its bit, which is now the guest's kept bit. - SO_TIMESTAMP and SO_BINTIME now succeed, but recvmsg adds no SCM_TIMESTAMP/SCM_BINTIME. Since that changes what a caller receives, not just UI, does it belong under "Silent stubs" rather than Functional? Main already keeps SO_*LOWAT under Functional, so I'll leave that to the maintainers. - Option 0x10000 is SO_REUSEPORT_LB in FreeBSD 12+. If the PS5 kernel treats it that way, two sockets that set it would share a port there but get EADDRINUSE here. Maybe worth a debt note, or forwarding it like SO_REUSEPORT. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!10330
No description provided.