fix(libkernel): give guest sockets ordinary descriptor numbers below FD_SETSIZE #4391
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4391"
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 MarcZX10 on 2026-10-12T08:50:55Z.
What
Fixes the socket descriptor overflow reported in #4366. Libkernel sockets, socket pairs, accepted sockets, and libSceNet sockets reserve ordinary host descriptor numbers from the shared descriptor table, keeping them within
FD_SETSIZEwhile fewer than 1024 descriptors are open. Descriptor dispatch now checks socket-table membership;selecthandles libkernel sockets alongside the existing descriptor groups. The kqueue and file-event paths also identify sockets by table membership so the low-numbered descriptors work with currentmain.Carries screamm's implementation commit
20378375bwith its original author preserved. Integration changes update thesetsockoptownership check, returnEBADFfromfstatfor a closed low-numbered socket descriptor, and route descriptor cleanup through the current equeue behavior. Socketfstatremains unsupported, as in the issue's proposed scope.Tested
Linux, Debian 12, GCC 12.2, Release, Ninja,
BUILD_TESTING=ON, configured from this rebased head on currentmainc13dc7e6b:libkernel,libSceNet,libScePosixForWebKitand the focused socket/event test executables (148 Ninja steps).guest_sce_net,guest_posix_filesystem,guest_socket_events,guest_poll,guest_select,guest_socket_pair,guest_dup,guest_kqueue,guest_socket_descriptorsandguest_fstatfs.python3 tools/check_conventions.py --base upstream/mainpassed.git diff --check upstream/main...HEADpassed.No Windows build or title run was performed on this head.
Checklist
main; no other open PR implements the same behaviorImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T09:59:56Z.
Windows run of this head (
71b717ce5) merged onto currentmain(9aa5fd290): Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, full build includinglibs.guest_socket_descriptors,guest_poll,guest_dup,guest_socket_pair,guest_sce_net,guest_fstatfs,guest_posix_filesystem,guest_tcp,guest_udp,guest_aio,guest_aio_bad_descriptors,guest_resolver,guest_http,guest_http2,guest_http_response_header.main, 7 of them fail:guest_socket_descriptors(line 77),guest_poll,guest_dup,guest_socket_pair,guest_sce_net,guest_posix_filesystem(line 113, errno 25) andguest_fstatfs(line 119). So the new cases exercise the change on Windows.ctest -E '^agc_' -j 4). The change touches no AGC code.mainwithpoll: descriptor 4/descriptor 3 is not a socket. With this change both get pastpolland reach theirlapy.elfprobe, which needs a jailbroken environment.poll: descriptor 6 is not a socket, a descriptor that isn't a socket at all (#3644, #3649).Upstream skips the Windows job on PRs, so this is the first Windows run of this branch.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T10:38:42Z.
Windows test: head
71b717ce5merged onto currentmaine7c70a2df(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j4: full build 0 errors; ctest with the filterguest_dup, guest_fstatfs, guest_poll, guest_posix_filesystem, guest_sce_net, guest_select, guest_socket_descriptors, guest_socket_pair(matched 7 tests): 7/7 passed;python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T11:54:46Z.
Two findings on head
71b717ce5.1. It no longer merges onto current
main(3d8ffeb27).sceKernelFcntlinOpen.cppconflicts with theFcntlArgumentOfrework, andmainnow has three moreFirstDescriptorcomparisons that this PR removes from the header, so a plain merge also fails to compile:Open.cpp:sceKernelFcntl(d < GuestSockets::FirstDescriptor)Udp.cpp:fcntl_nid_postfixandioctl_nid_postfixStdio.cpp: theF_DUPFDbranch offcntl(non-Windows only)I resolved these locally by testing
GuestSockets::IsOpen(d)instead (and dropping the non-Windows range throw). Windows 10, GCC 15.2.0 (WinLibs r7), Release, full build 0 errors;guest_socket_descriptors,guest_socket_read_write,guest_socket_pair,guest_socket_events,guest_poll,guest_dup,guest_fstatfs,guest_posix_filesystem,guest_filesystem,guest_equeue_events,guest_tcpandguest_udppass (12 of 12 in that filter). This is a local merge, not pushed.2. The Mound (PPSA26223), 150 s each, observation only.
71b717ce5on its own base: noFATAL, noRtcNetworkThreadfault; the title ran the whole 150 s and was stopped by the time limit. The #1794 stop (FD_SETwith0x10000005) is gone.main3d8ffeb27(resolution above):RtcNetworkThreadis alive in the thread dump when the title aborts, and the abort is an unrelated GPU one (storage image access to depth/stencil surface ... is not implemented).Palworld (PPSA23126) with the same merge (plus the three file/event export declarations from
Rohan03x's branch) binds all imports, but aborts earlier in the shader recompiler (packed pixel ancillary input has an unsupported live use) before any EOS thread starts, so it does not show whetherselectis fixed there.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T13:11:06Z.
For anyone carrying this: the merge of head
71b717ce5onto currentmain(0ef9dc928) is on my fork as one merge commit, https://github.com/xXPBSXx/AnyPS5/tree/fix/socket-descriptors-4391-on-main (9d6fa7c3f). Nothing was changed beyond resolving the conflicts:Open.cpp:sceKernelFcntlkeepsmain'sFcntlArgumentOfand tests!GuestSockets::IsOpen(d);sceKernelClose(new onmain) testsIsOpen(d).Udp.cpp:fcntl_nid_postfixandioctl_nid_postfixtest!GuestSockets::IsOpen(...);Stdio.cpp: the non-WindowsF_DUPFDrange throw is dropped (FirstDescriptorno longer exists).TechnicalDebt.md:main's new send/sendto entry kept next to this PR's socket-number and poll entries.Windows 10, GCC 15.2.0 (WinLibs r7), Release: full build 0 errors, 26 of 26 tests in the socket, poll, dup, fstatfs, file system, TCP/UDP and libSceNet filter pass. No title run on this exact merge.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T13:26:26Z.
Interaction of this PR with the other open descriptor PRs, from
git merge-treeagainst the merge of this head with currentmain(9d6fa7c3fon my fork, see above); nothing was built for these combinations:mainSocket/src/Udp.cpp,tests/GuestPoll.cpp,TechnicalDebt.mdTechnicalDebt.md)Socket/src/Udp.cpp,tests/GuestPoll.cpp,TechnicalDebt.mdFile/src/Stdio.cpp,Socket/include/SocketRuntime.hpp,TechnicalDebt.mdsceKernelClose)pollaccept non-socket descriptors, so only one of them can be merged first.pollthrow for an open descriptor that is not a guest socket andfstatthrow for a guest socket (TechnicalDebt.md), the two behaviours #3649/#3644 and #4351 change. Whichever lands second needs the table-membership test (GuestSockets::IsOpen) instead of theFirstDescriptorrange; thepolldescriptor-below-the-socket-range check is gone here.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T14:36:30Z.
Heads-up before review: this PR reworks the guest-socket descriptor scheme to ordinary numbers below
FD_SETSIZE, butmainlanded the opposite direction this morning —591e8ddad("feat(libkernel): support fcntl on non-socket descriptors") and01b7bb3e2("support ioctl on non-socket descriptors") route sockets throughGuestSockets::FirstDescriptor(high descriptor numbers, membership by range check).A plain rebase therefore isn't mechanical: every
d >= GuestSockets::FirstDescriptorrange check main added (insceKernelClose,sceKernelFcntl,sceKernelIoctl, …) collides with this PR'sGuestSockets::IsOpen(d)membership checks — the two schemes are mutually exclusive across the ~20 files this PR touches.Options as I see them: either this PR is a deliberate counter-proposal to the
FirstDescriptorscheme (in which case the maintainers should weigh the two designs before anyone spends rebase effort), or it predates awareness of the new scheme and wants reworking on top of it. Flagging so that's visible either way — happy to attempt the full semantic rebase if the ordinary-numbers design is the one that should win.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T20:38:10Z.
I rebased the branch onto current
main(42496c5e5) and pushed the updated head. I kept main’s resolver-state changes and the newer Windows directory-descriptor debt note, while retaining this PR’s ordinary low descriptor allocation. The follow-up routesfcntlandioctlthrough socket-table membership, so those calls no longer depend onFirstDescriptorranges.Linux Release build passed for the focused targets, and 17 CTests passed: descriptor allocation, poll/select, dup, socket pair/error/read-write, TCP/UDP, datagram/SceNet, socket events, fstatfs, and terminal. Conventions and
git diff --checkpass. I did not run a Windows build here. This remains a deliberate change from main’s high-range allocator, so the design choice should be reviewed explicitly.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T20:45:16Z.
Updated the rebased branch to current
mainatc952c2b0eafter it advanced again. The Linux focused build completed; 13 current socket/network regression tests passed (descriptor allocation, poll, select, dup, socket pair, socket error/read/write, SceNet, terminal, UDP/TCP, socket events and fstatfs).check_conventions.py --base upstream/mainalso passes. Windows still needs validation on this latest head.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:19:55Z.
Conflicts with main again, in
core/libs/prx/libkernel/CMakeLists.txt,File/src/Open.cppandFile/src/Stdio.cpp; please rebase once more. The kqueue code that landed since brought newGuestSockets::FirstDescriptorrange checks (Equeue/src/Kqueue.cpp:121,:138and:328,Equeue/src/FileEvent.cpp:562and:650), and they need theGuestSockets::IsOpentest as well. Lowest-free numbers as in FreeBSD'sfdallocis the scheme to keep.Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T02:39:35Z.
A Linux title this would unblock, for the
Unblocks:line: ProsperoLight (PPSA99002).On
main37dd48308(Arch Linux, Release, catalog release relinked with--to-intel) it aborts with(the message only reaches the log with #4792; on
mainit needsgdb). Cause, traced withgdbandstrace:sceNetSocket, which numbers them fromg_next_sock = 32in its own table. The fourth one is 35.fcntl:fcntl(35, F_GETFL)followed byfcntl(35, F_SETFL, O_NONBLOCK)(arguments read atfcntl_nid_postfix). On the console a libSceNet socket is a kernel descriptor, so this works.fcntltreats 35 as a host descriptor. On Linux host fd 35 at that moment is an anonymous-inode descriptor of the Vulkan driver (fstatmode0600, Mesa ANV dups it), soClassifythrows. On Windows the same call presumably fails withEBADF, which the title ignores, so it gets further there.As a check, starting
g_next_sockat0x20000000locally (not a fix, only moves the numbers away from host descriptors) lets the title run the full 40 s. So for this title the change needs libSceNet sockets to get real descriptor numbers andfcntlF_GETFL/F_SETFLwithO_NONBLOCKto work on them, as libkernel sockets do. I'm happy to rerun it on Linux once the branch is rebased.Traced with Claude Code assistance.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:29:06Z.
Rebased onto current
mainc13dc7e6band pushed heade0ec0c809. The rebase keeps low-numbered socket descriptors and routes the new kqueue/file-event checks throughGuestSockets::IsOpen, including the range checks called out above. The low-descriptor test setup and currentmain's pipe-poll behavior are both retained.Linux Debian 12 / GCC 12.2 Release: built the affected libraries and focused test targets (148 Ninja steps); CTest passed 10/10, including
guest_kqueue,guest_socket_descriptors,guest_socket_events,guest_poll,guest_select,guest_dup,guest_socket_pair,guest_sce_net,guest_posix_filesystemandguest_fstatfs. Conventions andgit diff --checkpass. I have not run Windows or a title on this head.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T03:40:45Z.
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)core/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdL140-142docs/dev/debt/libkernel.mdL126-128core/libs/prx/libkernel/File/src/Stdio.cppL726-732core/libs/prx/libkernel/Socket/src/Socket.cppL248-250core/libs/prx/libkernel/File/src/Stdio.cppL759-762core/libs/prx/libkernel/File/src/Stdio.cppL645-646, L807core/libs/prx/libkernel/Socket/include/SocketRuntime.hppL4, L17-18docs/dev/debt/libkernel.mdL140-142core/libs/prx/libkernel/Equeue/Equeue.cppL599-602core/libs/prx/libkernel/Equeue/Equeue.cppL596-597, L599-605core/libs/prx/libkernel/Equeue/src/Kqueue.cppL121-122, L138-142core/libs/prx/libkernel/Socket/include/SocketRuntime.hppL18core/libs/prx/libkernel/Socket/src/Udp.cppL539core/libs/prx/libkernel/File/src/Stdio.cppL643-646, L759-762Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T04:16:09Z.
Reran ProsperoLight (PPSA99002) on this head (
e0ec0c809) on Linux (Arch, Release, relinked with--to-intel): 3 of 3 runs still abort, now with(41 in one run).
straceshows the libSceNet socket now gets a low descriptor as intended (socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 46,fcntl(46, F_DUPFD_CLOEXEC, 0) = 47), and the guest'sfcntl(47, F_GETFL)/fcntl(47, F_SETFL, O_NONBLOCK)reachesFile::Fcntl, whose LinuxClassifyseesS_IFSOCKand throws. So for this title the remaining piece isfcntlF_GETFL/F_SETFL(O_NONBLOCK) on socket descriptors, routed through the socket table like the equeue checks. Happy to rerun once that's in, here or in a follow-up.Tested with Claude Code assistance.
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T04:30:00Z.
Opened #4924 on top of this branch for the
fcntlpart (libSceNet registers a status control with libkernel, like its option setter). With it ProsperoLight gets pastfcntland stops next onpoll: descriptor 47 is neither a socket nor a pipe.Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T05:14:58Z.
With #4924 (fcntl) and #4933 (poll) on top of this branch, ProsperoLight (PPSA99002) runs 3 of 3 times for 60 s on Linux and reaches its main screen ("Your PCs", Sunshine discovery running). So on Linux this branch plus those two clears every socket stop this title hits.