Skip to content

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

Merged
oneandonlydean merged 5 commits into
boykopovar:mainfrom
Retr0G28:fix/fpathconf-socket
Nov 1, 2026
Merged

oneandonlydean merged 5 commits into
boykopovar:mainfrom
Retr0G28:fix/fpathconf-socket

Conversation

@Retr0G28

@Retr0G28 Retr0G28 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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 a23f8fc.

  • 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 a8a7d7e they pass.
  • guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and the 27 guest_socket* tests pass on a8a7d7e.
  • python tools/check_conventions.py --base origin/main reports no errors.
  • After merging main afc780e (head df9dd6a): guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and guest_socket_pair pass.
  • After merging main 3a2b919 (head fdeee74): the same four pass.
  • Linux: wachi35676 ran the same four tests on 19cfbc7 (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):

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

@MarcZX10

Copy link
Copy Markdown
Contributor

The Windows-specific change matches the helper's existing socket registry and the PR's stream/datagram coverage looks appropriate. I independently ran MinGW C++20 syntax checks on the changed libkernel_sys/Export.cpp and GuestKernelSys.cpp; both pass, as do git diff --check and current-head conventions. I could not run guest_kernel_sys: CMake configuration stops because this checkout lacks the SDL2 submodule and XRandR development support.

One contribution-rule follow-up: the overlap report identifies a changed libkernel_sys.md line also changed by open #10196. The body notes that either merge order needs a rebase, but I don't see an agreed landing order or Depends on recorded here. Please coordinate with @orezraey and add the agreed order to the checklist so the shared debt line is carried through cleanly.

@orezraey

Copy link
Copy Markdown
Contributor

Agreed: #10427 can land first. Once it merges I will merge main into #10196 and carry its wording into the shared libkernel_sys.md entry, "for a pipe or a socket" without the EBADF clause, on top of #10196's measured constants. I have set Depends on: #10427 in #10196.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9019 core/libs/prx/libkernel_sys/Export.cpp L38
PR 9097 core/libs/prx/libkernel_sys/Export.cpp L38
PR 14101 docs/dev/debt/libkernel_sys.md L352-354
PR 14299 docs/dev/debt/libkernel_sys.md L353-354

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 5021 core/libs/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.cpp
PR 7275 core/libs/CMakeLists.txt
PR 8650 core/libs/CMakeLists.txt
PR 9156 core/libs/CMakeLists.txt
PR 9162 core/libs/CMakeLists.txt
docs/dev/debt/libkernel_sys.md
PR 9293 core/libs/CMakeLists.txt
PR 9297 core/libs/CMakeLists.txt
docs/dev/debt/libkernel_sys.md
PR 9302 core/libs/CMakeLists.txt
docs/dev/debt/libkernel_sys.md
PR 9383 core/libs/CMakeLists.txt
PR 9389 core/libs/prx/libkernel_sys/Export.cpp
PR 12642 core/libs/CMakeLists.txt
docs/dev/debt/libkernel_sys.md
PR 13129 docs/dev/debt/libkernel_sys.md
PR 13253 core/libs/CMakeLists.txt
docs/dev/debt/libkernel_sys.md
PR 13256 core/libs/CMakeLists.txt
docs/dev/debt/libkernel_sys.md
PR 14212 docs/dev/debt/libkernel_sys.md

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main 11d6efa 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.

@Retr0G28

Copy link
Copy Markdown
Contributor Author

@harisibrar1 Thanks, that was a real gap. In a8a7d7e the Windows branch of _fpathconf asks KernelLookupSocketNative_nid_no_patch instead of GuestSocketIsOpen_nid_no_patch. That lookup checks the kernel GuestSockets map first and falls back to libSceNet's registered lookup, so a descriptor from sceNetSocket is covered too.

CheckSocketPathconf now also runs the pipe-buffer checks on a sceNetSocket stream and datagram socket, and guest_kernel_sys_tests links libSceNet for it. Those checks fail with the first commit's Export.cpp and pass on the head. guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and the guest_socket* tests pass on Windows. The debt entry's "for a pipe or a socket" now holds for both kinds of socket, so it is unchanged.

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked head a8a7d7e against main 6cd36e6:

  • 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.

@github-actions github-actions Bot added build needs rebase Conflicts with main, rebase needed labels Oct 24, 2026
# Conflicts:
#	core/libs/prx/libkernel_sys/Export.cpp
#	core/libs/tests/GuestKernelSys.cpp
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@Retr0G28

Copy link
Copy Markdown
Contributor Author

Merged main f26434a to clear conflicts in Export.cpp and GuestKernelSys.cpp, where main moved declarations into the shared headers. The test now includes prx/libSceNet/include/Net.hpp for sceNetInit_nid_postfix, sceNetSocket and sceNetSocketClose, as other tests do; otherwise the diff against main is unchanged. Head 19cfbc7, Windows 11, GCC 15.2.0: guest_kernel_sys, guest_net_buffer_validation, guest_sce_net, guest_socket_options and guest_socket_pair pass.

@Gruzzberry

Copy link
Copy Markdown
Contributor

Hi @Retr0G28, the overlap check shows my open PRs next to this one:

The changes are separate. Only the neighbouring lines overlap. Proposed merge order: this PR first, then #11031 and #11032, which I'll rebase onto it after it merges. I've recorded that under Depends on in #11031 and #11032. If you'd prefer to go second, say so and I'll switch it.

@wachi35676

Copy link
Copy Markdown
Contributor

Tested head 19cfbc7e88 merged onto main 49d1f9b07e, Windows 11 (WinLibs GCC 15.2.0, Release) and WSL2 Ubuntu 24.04 (GCC 13.3), BUILD_TESTING=ON.

  • guest_kernel_sys, guest_net_buffer_validation, guest_socket_pair, guest_sce_net: 4/4 pass, 3 runs, on both hosts.
  • With libkernel_sys/Export.cpp from main, guest_kernel_sys fails on Windows. On Linux all 4 still pass, which fits the description: Linux already answered sockets through S_ISSOCK, and the new checks run there unchanged.

A related gap, already on main and fine for a follow-up: two more descriptor kinds without a vnode still get the UFS constants. On both hosts:

call here FreeBSD 11.4
fpathconf(kqueue_nid_postfix(), _PC_LINK_MAX / _PC_NAME_MAX / _PC_PIPE_BUF) 32767 / 255 / 512 -1, EOPNOTSUPP
fpathconf(shm_open(SHM_ANON, O_RDWR, 0600), same names) 32767 / 255 / 512 -1, EOPNOTSUPP
either, _PC_ASYNC_IO 200112 200112

In kern_fpathconf (kern_descrip.c:1411-1429), only _PC_ASYNC_IO is answered for every descriptor. After that comes VOP_PATHCONF for a descriptor with f_vnode, then the pipe/socket branch this PR follows, and EOPNOTSUPP for everything else. A DTYPE_KQUEUE or DTYPE_SHM file has no f_vnode.

AI-assisted: yes (Claude Code); results above were run on this machine.

# Conflicts:
#	docs/dev/debt/libkernel_sys.md
@Retr0G28

Copy link
Copy Markdown
Contributor Author

@Gruzzberry Agreed: this PR first, then #11031 and #11032. I've noted it in the description.

@wachi35676 Thanks for the Linux run and the kqueue and shm table. #11296 already takes that follow-up, so I've left it out of this PR.

Merged main afc780e to clear the conflict in libkernel_sys.md, where #10196 rewrote the pathconf entry with the PS5 measurements. The resolution keeps that wording and changes only its tail to "for a pipe or a socket, only _PC_PIPE_BUF 512", without the "a guest socket fails fstat with EBADF" clause this PR fixes. The Export.cpp change merged cleanly. Head df9dd6a, Windows 11 (GCC 15.2.0): guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and guest_socket_pair pass, and check_conventions.py passes.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 26, 2026
# Conflicts:
#	core/libs/CMakeLists.txt
#	core/libs/prx/libkernel_sys/Export.cpp
#	core/libs/tests/GuestKernelSys.cpp
@Retr0G28

Copy link
Copy Markdown
Contributor Author

Merged main 3a2b919 to clear the new conflicts with #11032 (kenv) and #11296 (fpathconf on a kqueue or shm descriptor), which both merged yesterday:

  • CMakeLists.txt: guest_kernel_sys_tests now links libSceNet (this PR) and libSceAmpr (main).
  • Export.cpp: both sets of includes stay. _fpathconf keeps the socket lookup from this PR and fix(libkernel_sys): fail fpathconf on a kqueue or shm descriptor with EOPNOTSUPP #11296's EOPNOTSUPP answer for a kqueue or shm descriptor.
  • GuestKernelSys.cpp: CheckSocketPathconf, CheckKernelEnvironment and CheckUnsupportedPathconf all stay, and main runs the socket checks before the kqueue and shm ones.

The debt entry merged cleanly. Head fdeee74, Windows 11 (GCC 15.2.0): guest_kernel_sys, guest_net_buffer_validation, guest_sce_net and guest_socket_pair pass, and check_conventions.py passes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 29, 2026
@oneandonlydean
oneandonlydean merged commit ba75ea7 into boykopovar:main Nov 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants