fix(libkernel): keep socket buffer sizes and SO_NBIO as measured on a PS5 #10302

Merged
orezraey merged 2 commits from upstream-pr/10302 into main 2026-10-24 02:25:06 +00:00
orezraey commented 2026-10-23 16:52:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T16:52:45Z.


What

getsockopt and setsockopt measured on a retail PS5 (firmware 13.60) through libkernel_sys.sprx from a payload process. The sources and console logs are in this gist (pinet to pinet3; the address cases of pinet went to #10299). The debt entry had these answers from the FreeBSD 11.4 source, or from the host.

The console:

  • starts a socket with SO_SNDBUF/SO_RCVBUF of 32768/65536 (TCP, IPv4 and IPv6), 9216/42080 (UDP), 8192/8192 (AF_UNIX stream and seqpacket) and 2048/4096 (AF_UNIX datagram), and SO_SNDLOWAT/SO_RCVLOWAT of 2048/1;
  • keeps the size asked for up to 524288 bytes, reads back 524288 for anything larger up to 5592405, fails above that with ENOBUFS (55) and below 1 with EINVAL;
  • limits a low-water mark to its buffer, and lowers it when the buffer shrinks under it;
  • reads SO_NBIO back as 0x100 (SS_NBIO), not 1;
  • fails a null setsockopt value with a length with EFAULT before it looks at the descriptor or the option, and answers a null getsockopt value with success and length 0.

AnyPS5 read the host's buffer sizes, failed the low-water marks with ENOPROTOOPT, read SO_NBIO as 1, and answered both null values with EINVAL. The four sizes are now kept per socket, set on the host as well, and copied to an accepted socket as FreeBSD's sonewconn does. The 6000-character getsockopt, setsockopt debt entry is split by option, keeps only what still differs or was not measured, and now lists the options the console accepts that fail here (SO_REUSEPORT, SO_DEBUG, SO_TIMESTAMP, IP_TTL, IP_TOS, TCP_MAXSEG, TCP_KEEPIDLE).

Tested

Windows 11, MinGW (winlibs).

  • guest_socket_options checks the defaults, the limits, the low-water clipping, the AF_UNIX sizes and the null values; guest_socket_stream_options checks SO_NBIO. The socket and net tests pass three runs in a row.
  • The full suite (-E "^agc_|^select_tests$") passes.
  • 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4986280646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10302). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T16:52:45Z. --- ### What `getsockopt` and `setsockopt` measured on a retail PS5 (firmware 13.60) through `libkernel_sys.sprx` from a payload process. The sources and console logs are in [this gist](https://gist.github.com/orezraey/d9efe0da49405f19d72cb35279c0db52) (`pinet` to `pinet3`; the address cases of `pinet` went to #10299). The debt entry had these answers from the FreeBSD 11.4 source, or from the host. The console: - starts a socket with `SO_SNDBUF`/`SO_RCVBUF` of 32768/65536 (TCP, IPv4 and IPv6), 9216/42080 (UDP), 8192/8192 (`AF_UNIX` stream and seqpacket) and 2048/4096 (`AF_UNIX` datagram), and `SO_SNDLOWAT`/`SO_RCVLOWAT` of 2048/1; - keeps the size asked for up to 524288 bytes, reads back 524288 for anything larger up to 5592405, fails above that with `ENOBUFS` (55) and below 1 with `EINVAL`; - limits a low-water mark to its buffer, and lowers it when the buffer shrinks under it; - reads `SO_NBIO` back as 0x100 (`SS_NBIO`), not 1; - fails a null `setsockopt` value with a length with `EFAULT` before it looks at the descriptor or the option, and answers a null `getsockopt` value with success and length 0. AnyPS5 read the host's buffer sizes, failed the low-water marks with `ENOPROTOOPT`, read `SO_NBIO` as 1, and answered both null values with `EINVAL`. The four sizes are now kept per socket, set on the host as well, and copied to an accepted socket as FreeBSD's `sonewconn` does. The 6000-character `getsockopt, setsockopt` debt entry is split by option, keeps only what still differs or was not measured, and now lists the options the console accepts that fail here (`SO_REUSEPORT`, `SO_DEBUG`, `SO_TIMESTAMP`, `IP_TTL`, `IP_TOS`, `TCP_MAXSEG`, `TCP_KEEPIDLE`). ### 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). - `guest_socket_options` checks the defaults, the limits, the low-water clipping, the `AF_UNIX` sizes and the null values; `guest_socket_stream_options` checks `SO_NBIO`. The socket and net tests pass three runs in a row. - The full suite (`-E "^agc_|^select_tests$"`) passes. - `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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!10302
No description provided.