fix(libkernel_sys): answer fpathconf on a socket as FreeBSD answers it for a pipe #10427

Merged
Retr0G28 merged 5 commits from upstream-pr/10427 into main 2026-11-01 21:48:44 +00:00
Retr0G28 commented 2026-10-24 00:03:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-24T00:03:08Z.


What

FreeBSD 11's kern_fpathconf answers a pipe and a socket the same way: _PC_ASYNC_IO gives 200112, _PC_PIPE_BUF gives PIPE_BUF (512), and every other name fails with EINVAL. fpathconf and _fpathconf did that for a pipe on every host and for a socket on Linux. On Windows, _fstat64 of a guest socket's descriptor does not report _S_IFIFO, so a socket was answered with the UFS file constants: _PC_LINK_MAX gave 32767, _PC_NAME_MAX 255, and so on.

On Windows, a descriptor that KernelLookupSocketNative_nid_no_patch finds now takes the pipe path. libSceSsl already uses that lookup for a connection's socket. It covers the kernel's own sockets from socket and socketpair, and through libSceNet's registered lookup, sockets from sceNetSocket and sceNetAccept. libSceNet keeps those in its own table, and on Windows their number is the same NUL placeholder. The debt entry says "for a pipe or a socket". Its clause that a guest socket fails the fstat check with EBADF is removed, as that is not what happens.

Test: the pipe checks in guest_kernel_sys move into CheckPipeBufferPathconf. CheckSocketPathconf runs them on an AF_INET stream socket and an AF_INET datagram socket, from both socket and sceNetSocket, through both fpathconf and _fpathconf. guest_kernel_sys_tests now links libSceNet for this.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, -DBUILD_TESTING=ON, on main a23f8fc9fb.

  • With main's Export.cpp, guest_kernel_sys fails in the socket checks: Kernel sys check failed at line 435, the loop over names that must fail with EINVAL. With this PR it passes.
  • With the first commit's Export.cpp (only GuestSocketIsOpen_nid_no_patch), the sceNetSocket checks fail (exit 0xc0000409). With head a8a7d7eb62 they pass.
  • guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and the 27 guest_socket* tests pass on a8a7d7eb62.
  • python tools/check_conventions.py --base origin/main reports no errors.
  • After merging main afc780e681 (head df9dd6a693): guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and guest_socket_pair pass.
  • After merging main 3a2b919816 (head fdeee7478c): the same four pass.
  • Linux: wachi35676 ran the same four tests on 19cfbc7e88 (WSL2 Ubuntu 24.04, GCC 13.3) and they passed; with main's Export.cpp they still pass there, as the S_ISSOCK check already handled sockets. No title or homebrew run.

Overlap (tools/pr_overlap.py):

  • #10196 has merged and rewrote the same debt entry with the constants measured on a PS5. This branch keeps that wording and changes only its tail to "for a pipe or a socket", without the EBADF clause.
  • #11032 (kenv) and #11296 (fpathconf on a kqueue or shm descriptor) have merged. main is merged here: the CMakeLists.txt link line takes both libSceNet and libSceAmpr, the test keeps both new check functions, and _fpathconf keeps both the socket lookup and #11296's EOPNOTSUPP branch.
  • #11031 (getfsstat) changes lines next to this PR's test in GuestKernelSys.cpp. Agreed with its author: this PR goes first, and it declares Depends on: #10427.
  • None of the PRs it could not compare changes _fpathconf: #5021, #6044, #7201, #8457, #8701, #9019, #9097, #9161, #9297, #9302, #9423, #9442, #9693, #9826, #10016.

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:4990796787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10427). Originally posted by [Retr0G28](https://github.com/Retr0G28) on 2026-10-24T00:03:08Z. --- ### What FreeBSD 11's [`kern_fpathconf`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/kern_descrip.c#L1399-L1433) answers a pipe and a socket the same way: `_PC_ASYNC_IO` gives 200112, `_PC_PIPE_BUF` gives `PIPE_BUF` (512), and every other name fails with `EINVAL`. `fpathconf` and `_fpathconf` did that for a pipe on every host and for a socket on Linux. On Windows, `_fstat64` of a guest socket's descriptor does not report `_S_IFIFO`, so a socket was answered with the UFS file constants: `_PC_LINK_MAX` gave 32767, `_PC_NAME_MAX` 255, and so on. On Windows, a descriptor that `KernelLookupSocketNative_nid_no_patch` finds now takes the pipe path. libSceSsl already uses that lookup for a connection's socket. It covers the kernel's own sockets from `socket` and `socketpair`, and through libSceNet's registered lookup, sockets from `sceNetSocket` and `sceNetAccept`. libSceNet keeps those in its own table, and on Windows their number is the same `NUL` placeholder. The debt entry says "for a pipe or a socket". Its clause that a guest socket fails the `fstat` check with `EBADF` is removed, as that is not what happens. Test: the pipe checks in `guest_kernel_sys` move into `CheckPipeBufferPathconf`. `CheckSocketPathconf` runs them on an `AF_INET` stream socket and an `AF_INET` datagram socket, from both `socket` and `sceNetSocket`, through both `fpathconf` and `_fpathconf`. `guest_kernel_sys_tests` now links libSceNet for this. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, `-DBUILD_TESTING=ON`, on `main` a23f8fc9fb. - With `main`'s `Export.cpp`, `guest_kernel_sys` fails in the socket checks: `Kernel sys check failed at line 435`, the loop over names that must fail with `EINVAL`. With this PR it passes. - With the first commit's `Export.cpp` (only `GuestSocketIsOpen_nid_no_patch`), the `sceNetSocket` checks fail (exit 0xc0000409). With head a8a7d7eb62 they pass. - `guest_kernel_sys`, `guest_net_buffer_validation`, `guest_sce_net` and the 27 `guest_socket*` tests pass on a8a7d7eb62. - `python tools/check_conventions.py --base origin/main` reports no errors. - After merging `main` afc780e681 (head df9dd6a693): `guest_kernel_sys`, `guest_net_buffer_validation`, `guest_sce_net` and `guest_socket_pair` pass. - After merging `main` 3a2b919816 (head fdeee7478c): the same four pass. - Linux: wachi35676 ran the same four tests on 19cfbc7e88 (WSL2 Ubuntu 24.04, GCC 13.3) and they passed; with `main`'s `Export.cpp` they still pass there, as the `S_ISSOCK` check already handled sockets. No title or homebrew run. Overlap (`tools/pr_overlap.py`): - #10196 has merged and rewrote the same debt entry with the constants measured on a PS5. This branch keeps that wording and changes only its tail to "for a pipe or a socket", without the `EBADF` clause. - #11032 (`kenv`) and #11296 (`fpathconf` on a kqueue or `shm` descriptor) have merged. `main` is merged here: the `CMakeLists.txt` link line takes both `libSceNet` and `libSceAmpr`, the test keeps both new check functions, and `_fpathconf` keeps both the socket lookup and #11296's `EOPNOTSUPP` branch. - #11031 (`getfsstat`) changes lines next to this PR's test in `GuestKernelSys.cpp`. Agreed with its author: this PR goes first, and it declares `Depends on: #10427`. - None of the PRs it could not compare changes `_fpathconf`: #5021, #6044, #7201, #8457, #8701, #9019, #9097, #9161, #9297, #9302, #9423, #9442, #9693, #9826, #10016. ### 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
harisibrar1 commented 2026-10-24 01:10:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T01:10:38Z.

Review: COMMENTED


Checked against main 11d6efa06c and FreeBSD release/11.4.0 sys/kern/kern_descrip.c (identical to the 8c639945 copy linked in the description):

  • kern_fpathconf (L1400-1433) answers a descriptor without f_vnode that is DTYPE_PIPE or DTYPE_SOCKET with PIPE_BUF for _PC_PIPE_BUF and EINVAL otherwise, so treating a guest socket like a pipe matches 11.4. On main, the Windows socket number is a NUL placeholder (ReserveNumber in Udp.cpp), which explains why _fstat64 never reported a FIFO. The PR still merges cleanly onto current main.
  • Small gap, for this PR or a follow-up: a descriptor from sceNetSocket is kept in libSceNet's own table (KernelReserveSocketNumber_nid_no_patch, libSceNet Export.cpp L1021), not in the GuestSockets map that GuestSocketIsOpen_nid_no_patch checks. I couldn't run this, but reading the code suggests that on Windows fpathconf on such a descriptor still returns the UFS constants (e.g. _PC_LINK_MAX 32767). Linux is fine, because there the number is a dup of the real socket. KernelFindSocketNative_nid_no_patch is the lookup poll uses for those. Otherwise the debt entry could say the guest-socket case covers only socket() descriptors on Windows.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636032449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10427#pullrequestreview-5636032449). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T01:10:38Z. **Review:** COMMENTED --- Checked against main 11d6efa06c and FreeBSD release/11.4.0 `sys/kern/kern_descrip.c` (identical to the 8c639945 copy linked in the description): - `kern_fpathconf` (L1400-1433) answers a descriptor without `f_vnode` that is `DTYPE_PIPE` or `DTYPE_SOCKET` with `PIPE_BUF` for `_PC_PIPE_BUF` and EINVAL otherwise, so treating a guest socket like a pipe matches 11.4. On main, the Windows socket number is a NUL placeholder (`ReserveNumber` in `Udp.cpp`), which explains why `_fstat64` never reported a FIFO. The PR still merges cleanly onto current main. - Small gap, for this PR or a follow-up: a descriptor from `sceNetSocket` is kept in libSceNet's own table (`KernelReserveSocketNumber_nid_no_patch`, libSceNet `Export.cpp` L1021), not in the `GuestSockets` map that `GuestSocketIsOpen_nid_no_patch` checks. I couldn't run this, but reading the code suggests that on Windows `fpathconf` on such a descriptor still returns the UFS constants (e.g. `_PC_LINK_MAX` 32767). Linux is fine, because there the number is a dup of the real socket. `KernelFindSocketNative_nid_no_patch` is the lookup `poll` uses for those. Otherwise the debt entry could say the guest-socket case covers only `socket()` descriptors on Windows. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
harisibrar1 commented 2026-10-24 13:16:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:16:25Z.

Review: APPROVED


Re-checked head a8a7d7eb62 against main 6cd36e6517:

  • The fix is in: _fpathconf on Windows now asks KernelLookupSocketNative_nid_no_patch (Export.cpp:397-399). That checks the same sockets map as GuestSocketIsOpen first, then falls back to libSceNet's registered FindSocketNativeForKernel, so a sceNetSocket descriptor now gets _PC_PIPE_BUF 512 / EINVAL too.
  • The helper is declared extern "C" in SocketPoll.hpp and defined in libkernel, which libkernel_sys already links; libSceSsl already calls it across modules the same way.
  • The CMakeLists.txt change only adds libSceNet to guest_kernel_sys_tests, and CheckSocketPathconf covers stream and datagram sockets from both socket() and sceNetSocket.
  • The debt wording "for a pipe or a socket" now holds for both kinds, and it still merges cleanly onto current main. Thanks, LGTM.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638382636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10427#pullrequestreview-5638382636). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T13:16:25Z. **Review:** APPROVED --- Re-checked head a8a7d7eb62 against main 6cd36e6517: - The fix is in: `_fpathconf` on Windows now asks `KernelLookupSocketNative_nid_no_patch` (Export.cpp:397-399). That checks the same `sockets` map as `GuestSocketIsOpen` first, then falls back to libSceNet's registered `FindSocketNativeForKernel`, so a `sceNetSocket` descriptor now gets `_PC_PIPE_BUF` 512 / EINVAL too. - The helper is declared `extern "C"` in `SocketPoll.hpp` and defined in libkernel, which libkernel_sys already links; libSceSsl already calls it across modules the same way. - The `CMakeLists.txt` change only adds libSceNet to `guest_kernel_sys_tests`, and `CheckSocketPathconf` covers stream and datagram sockets from both `socket()` and `sceNetSocket`. - The debt wording "for a pipe or a socket" now holds for both kinds, and it still merges cleanly onto current main. Thanks, LGTM. 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!10427
No description provided.