fix(libkernel): handle fcntl and FIONREAD on a host socket descriptor #7403
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7403"
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 milescoviello on 2026-10-18T04:46:04Z.
What
On Linux and macOS,
fcntlandioctlthrew for a host socket that is not a guest socket:A standard descriptor is such a socket when a service manager connects it to its journal, or when the process starts with a socket as stdin. That makes
guest_kernel_fcntlabort in itsStandardInputFlagscase. Here the fullctest -j8run onmain1e2d9b369bfailed that test 3 runs out of 3, while the test passes on its own:Started with a socket as stdin from Python's
subprocess, the same test binary aborts the same way every time; with/dev/nullas stdin it passes.A socket is now its own descriptor kind in
DescriptorControl.cpp:FIONREADasks the host.EBADF, as for a pipe. FreeBSD'skern_fcntlreturnsEBADFfor these on a descriptor without a vnode.O_ASYNCstill throws, as on a pipe.Guest sockets keep their own path, and Windows classification is unchanged. The
fcntltechnical debt entry describes the new case.Tested
Ubuntu 24.04, GCC 13.3, Release.
guest_kernel_fcntlgainsHostSocketFlags(not on Windows). It runs on a hostsocketpair:F_GETFLreportsO_RDWR;F_SETFLwithO_NONBLOCKreaches the host socket;F_SETFDandF_GETFDround-trip;FIONREADreports the 3 queued bytes;F_SETLKandF_RDAHEADfail withEBADF;O_ASYNCthrows as on a pipe.Results:
main'sDescriptorControl.cppthe test aborts withfcntl: descriptor 5 is neither a file, a directory, a pipe nor a character device. With this PR it passes 3 of 3.After rebasing onto
main4566cc3377: the 419guest_*tests pass. Before that rebase, the full suite passed 1437 of 1437 underctest -j8, includingguest_kernel_fcntl.Windows 11 (MinGW GCC 15.2) and Ubuntu 24.04 (GCC 13.3), this PR merged onto
main9f25d0bf5(run by @wachi35676). On Windows it builds and the socket and fcntl tests pass 38/38; the change and its test are for Linux and macOS only. On Linux,HostSocketFlagsaborts withmain'sDescriptorControl.cppand passes with this PR.guest_kernel_fcntl_testsstarted with a socketpair as stdin aborts onmainand exits 0 with this PR.From the same run: for a datagram socket, Linux's
FIONREADcounts only the next datagram, and FreeBSD'ssoo_ioctlcounts every buffered byte. The fcntl entry indocs/dev/debt/libkernel.mdnow says so (91a9e5608e). The code still passes the host's count through.tools/check_conventions.py --base upstream/mainpasses.#7437 (guest sockets,
F_DUPFDandF_DUP2FDon the libSceNet path) rewrites the samefcntlline indocs/dev/debt/libkernel.md. The code doesn't overlap: this PR only changesDescriptorControl.cppfor host sockets. Whichever PR lands second needs that sentence merged, and I'll rebase this one if it's second.@DavidAmsellem reproduced it and confirmed the fix on Linux Mint 22.3, AMD RX 7900 XT (RADV, Mesa 25.2.8). On plain
main,guest_kernel_fcntlfails underctest -j8in 4 of 4 runs with the reported message, and starting the test with a socket-pair end as stdin aborts every time. With this PR (91a9e5608on0bc3003f8), that start passes 3 of 3 and fullctest -j8passes 1478 of 1480. The two failures happen onmaintoo.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T04:56:16Z.
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.
main)docs/dev/debt/libkernel.mdL199-200Some 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.
docs/dev/debt/libkernel.mdcore/libs/tests/GuestKernelFcntl.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestKernelFcntl.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/DescriptorControl.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestKernelFcntl.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:20:16Z.
Also built and ran on Windows 11 (MinGW GCC 15.2) and Ubuntu 24.04 (GCC 13.3), with this PR merged onto
main9f25d0bf5.HostSocketFlagsaborts withmain'sDescriptorControl.cppand passes with this PR.guest_kernel_fcntl_testsstarted with a socketpair as stdin aborts onmain("descriptor 0 is neither…") and exits 0 with this PR.One small difference you may want in the debt line:
FIONREADon a host socket passes the host's answer through. For a datagram socket, Linux reports only the next datagram: an AF_UNIXSOCK_DGRAMsocket with 3+5 bytes queued gives 3. FreeBSD'ssoo_ioctlreports everything buffered,sbavail(&so->so_rcv)= 8 (sys_socket.c:202-205).AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T12:23:15Z.
Thanks @wachi35676 for the Windows and Linux runs, and for the datagram
FIONREADcase. I added both to the description. Linux gives no direct count of every queued datagram, so the code keeps passing the host's count through, and the fcntl debt entry now records the difference (91a9e5608e, with thesoo_ioctllines you linked).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-18T23:12:58Z.
Independently reproduced and confirmed fixed on another Linux machine.
kernel 7.0.0-38, GCC 13.3
91a9e5608merged intomain0bc3003f8, Release,BUILD_TESTING=ONBefore this PR, on plain
main:ctest -j8failedguest_kernel_fcntlwithSubprocess abortedin 4 runs of 4, and in 3 moreruns of a reduced set, while the test passes when run on its own.
LastTest.logcarries exactly the reported message:fcntl: descriptor 0 is neither a file, a directory, a pipe nor a character device.socketpairend as stdin aborts every time; with/dev/null, aregular file, a pipe, or stdin closed, it passes. That matches the
StandardInputFlagscasecalling
fcntl(0, F_GETFL)on whatever descriptor 0 happens to be.With this PR:
ctest -j8withANYPS5_REQUIRE_VULKAN=1: 1478 of 1480, andguest_kernel_fcntlis nolonger among the failures. The two remaining ones are unrelated to this PR and also fail on
mainhere:agc_pipeline_cache_file(#7676) andagc_driver_guest_memory_lifetime_direct(no read-write access to
/dev/udmabufon this machine).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T01:06:13Z.
Thanks @DavidAmsellem for reproducing it on AMD. The socket-as-stdin start is a clean way to show the cause. I added your runs to the description.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T19:31:33Z.
Checked the diff against FreeBSD's
kern_fcntl/soo_ioctlbehaviour cited in the debt entry:Classifyno longer throws for a host socket, every pipe-only branch on the non-Windows path (status flags, record lock, read-ahead,O_ASYNC,FIONREAD) now covers it, guest sockets and Windows are untouched.HostSocketFlagspins the values and throws onmain; independent runs by @wachi35676 and @DavidAmsellem confirm it. Thelibkernel.mdline only collides with #7437 by adjacency. Merged.