fix(libkernel_sys): answer fpathconf on a socket as FreeBSD answers it for a pipe #10427
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10427"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-24T00:03:08Z.
What
FreeBSD 11's
kern_fpathconfanswers a pipe and a socket the same way:_PC_ASYNC_IOgives 200112,_PC_PIPE_BUFgivesPIPE_BUF(512), and every other name fails withEINVAL.fpathconfand_fpathconfdid that for a pipe on every host and for a socket on Linux. On Windows,_fstat64of a guest socket's descriptor does not report_S_IFIFO, so a socket was answered with the UFS file constants:_PC_LINK_MAXgave 32767,_PC_NAME_MAX255, and so on.On Windows, a descriptor that
KernelLookupSocketNative_nid_no_patchfinds now takes the pipe path. libSceSsl already uses that lookup for a connection's socket. It covers the kernel's own sockets fromsocketandsocketpair, and through libSceNet's registered lookup, sockets fromsceNetSocketandsceNetAccept. libSceNet keeps those in its own table, and on Windows their number is the sameNULplaceholder. The debt entry says "for a pipe or a socket". Its clause that a guest socket fails thefstatcheck withEBADFis removed, as that is not what happens.Test: the pipe checks in
guest_kernel_sysmove intoCheckPipeBufferPathconf.CheckSocketPathconfruns them on anAF_INETstream socket and anAF_INETdatagram socket, from bothsocketandsceNetSocket, through bothfpathconfand_fpathconf.guest_kernel_sys_testsnow links libSceNet for this.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, onmaina23f8fc9fb.main'sExport.cpp,guest_kernel_sysfails in the socket checks:Kernel sys check failed at line 435, the loop over names that must fail withEINVAL. With this PR it passes.Export.cpp(onlyGuestSocketIsOpen_nid_no_patch), thesceNetSocketchecks fail (exit 0xc0000409). With heada8a7d7eb62they pass.guest_kernel_sys,guest_net_buffer_validation,guest_sce_netand the 27guest_socket*tests pass ona8a7d7eb62.python tools/check_conventions.py --base origin/mainreports no errors.mainafc780e681(headdf9dd6a693):guest_kernel_sys,guest_net_buffer_validation,guest_sce_netandguest_socket_pairpass.main3a2b919816(headfdeee7478c): the same four pass.19cfbc7e88(WSL2 Ubuntu 24.04, GCC 13.3) and they passed; withmain'sExport.cppthey still pass there, as theS_ISSOCKcheck already handled sockets. No title or homebrew run.Overlap (
tools/pr_overlap.py):EBADFclause.kenv) and #11296 (fpathconfon a kqueue orshmdescriptor) have merged.mainis merged here: theCMakeLists.txtlink line takes bothlibSceNetandlibSceAmpr, the test keeps both new check functions, and_fpathconfkeeps both the socket lookup and #11296'sEOPNOTSUPPbranch.getfsstat) changes lines next to this PR's test inGuestKernelSys.cpp. Agreed with its author: this PR goes first, and it declaresDepends on: #10427._fpathconf: #5021, #6044, #7201, #8457, #8701, #9019, #9097, #9161, #9297, #9302, #9423, #9442, #9693, #9826, #10016.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T01:10:38Z.
Review: COMMENTED
Checked against main
11d6efa06cand FreeBSD release/11.4.0sys/kern/kern_descrip.c(identical to the 8c639945 copy linked in the description):kern_fpathconf(L1400-1433) answers a descriptor withoutf_vnodethat isDTYPE_PIPEorDTYPE_SOCKETwithPIPE_BUFfor_PC_PIPE_BUFand EINVAL otherwise, so treating a guest socket like a pipe matches 11.4. On main, the Windows socket number is a NUL placeholder (ReserveNumberinUdp.cpp), which explains why_fstat64never reported a FIFO. The PR still merges cleanly onto current main.sceNetSocketis kept in libSceNet's own table (KernelReserveSocketNumber_nid_no_patch, libSceNetExport.cppL1021), not in theGuestSocketsmap thatGuestSocketIsOpen_nid_no_patchchecks. I couldn't run this, but reading the code suggests that on Windowsfpathconfon such a descriptor still returns the UFS constants (e.g._PC_LINK_MAX32767). Linux is fine, because there the number is a dup of the real socket.KernelFindSocketNative_nid_no_patchis the lookuppolluses for those. Otherwise the debt entry could say the guest-socket case covers onlysocket()descriptors on Windows.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:16:25Z.
Review: APPROVED
Re-checked head
a8a7d7eb62against main6cd36e6517:_fpathconfon Windows now asksKernelLookupSocketNative_nid_no_patch(Export.cpp:397-399). That checks the samesocketsmap asGuestSocketIsOpenfirst, then falls back to libSceNet's registeredFindSocketNativeForKernel, so asceNetSocketdescriptor now gets_PC_PIPE_BUF512 / EINVAL too.extern "C"inSocketPoll.hppand defined in libkernel, which libkernel_sys already links; libSceSsl already calls it across modules the same way.CMakeLists.txtchange only adds libSceNet toguest_kernel_sys_tests, andCheckSocketPathconfcovers stream and datagram sockets from bothsocket()andsceNetSocket.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.