fix(libkernel): give guest sockets ordinary descriptor numbers below FD_SETSIZE #4391

Merged
MarcZX10 merged 5 commits from upstream-pr/4391 into main 2026-10-13 06:52:09 +00:00
MarcZX10 commented 2026-10-12 08:50:55 +00:00 (Migrated from github.com)

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_SETSIZE while fewer than 1024 descriptors are open. Descriptor dispatch now checks socket-table membership; select handles 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 current main.

Carries screamm's implementation commit 20378375b with its original author preserved. Integration changes update the setsockopt ownership check, return EBADF from fstat for a closed low-numbered socket descriptor, and route descriptor cleanup through the current equeue behavior. Socket fstat remains 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 current main c13dc7e6b:

  • Built libkernel, libSceNet, libScePosixForWebKit and the focused socket/event test executables (148 Ninja steps).
  • CTest passed 10/10: guest_sce_net, guest_posix_filesystem, guest_socket_events, guest_poll, guest_select, guest_socket_pair, guest_dup, guest_kqueue, guest_socket_descriptors and guest_fstatfs.
  • python3 tools/check_conventions.py --base upstream/main passed.
  • git diff --check upstream/main...HEAD passed.

No Windows build or title run was performed on this head.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw or are documented as technical debt
  • No private notes or investigation artifacts added
  • New third-party code is a submodule built from source (none added)
  • Generic behavior, not title-specific
  • Depends on: none
  • Unblocks: PPSA99002 #4366
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4827070244 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391). Originally posted by [MarcZX10](https://github.com/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_SETSIZE` while fewer than 1024 descriptors are open. Descriptor dispatch now checks socket-table membership; `select` handles 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 current `main`. Carries screamm's implementation commit `20378375b` with its original author preserved. Integration changes update the `setsockopt` ownership check, return `EBADF` from `fstat` for a closed low-numbered socket descriptor, and route descriptor cleanup through the current equeue behavior. Socket `fstat` remains 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 current `main` `c13dc7e6b`: - Built `libkernel`, `libSceNet`, `libScePosixForWebKit` and the focused socket/event test executables (148 Ninja steps). - CTest passed 10/10: `guest_sce_net`, `guest_posix_filesystem`, `guest_socket_events`, `guest_poll`, `guest_select`, `guest_socket_pair`, `guest_dup`, `guest_kqueue`, `guest_socket_descriptors` and `guest_fstatfs`. - `python3 tools/check_conventions.py --base upstream/main` passed. - `git diff --check upstream/main...HEAD` passed. No Windows build or title run was performed on this head. ### Checklist - [x] Based on current `main`; no other open PR implements the same behavior - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw or are documented as technical debt - [x] No private notes or investigation artifacts added - [x] New third-party code is a submodule built from source (none added) - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] Unblocks: PPSA99002 #4366 - [x] AI-assisted: yes
LeandroLP23 commented 2026-10-12 09:59:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T09:59:56Z.


Windows run of this head (71b717ce5) merged onto current main (9aa5fd290): Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, full build including libs.

  • 15 socket, file and network tests pass 3/3: 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.
  • With the ten production files reverted to 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) and guest_fstatfs (line 119). So the new cases exercise the change on Windows.
  • The whole non-AGC suite passes: 513/513 (ctest -E '^agc_' -j 4). The change touches no AGC code.
  • Titles, 60 s each:
    • ProsperoTV (PPSA99003) and ProsperoRadio (PPSA99001) stop on main with poll: descriptor 4 / descriptor 3 is not a socket. With this change both get past poll and reach their lapy.elf probe, which needs a jailbroken environment.
    • PSXS5 (PPSA97510) still stops on 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6121975945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6121975945). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-12T09:59:56Z. --- Windows run of this head (`71b717ce5`) merged onto current `main` (`9aa5fd290`): Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, full build including `libs`. - 15 socket, file and network tests pass 3/3: `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`. - With the ten production files reverted to `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) and `guest_fstatfs` (line 119). So the new cases exercise the change on Windows. - The whole non-AGC suite passes: 513/513 (`ctest -E '^agc_' -j 4`). The change touches no AGC code. - Titles, 60 s each: - ProsperoTV (PPSA99003) and ProsperoRadio (PPSA99001) stop on `main` with `poll: descriptor 4` / `descriptor 3 is not a socket`. With this change both get past `poll` and reach their `lapy.elf` probe, which needs a jailbroken environment. - PSXS5 (PPSA97510) still stops on `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.
xXPBSXx commented 2026-10-12 10:38:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T10:38:42Z.


Windows test: head 71b717ce5 merged onto current main e7c70a2df (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j4: full build 0 errors; ctest with the filter guest_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/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6122602155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6122602155). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T10:38:42Z. --- Windows test: head `71b717ce5` merged onto current `main` `e7c70a2df` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j4`: full build 0 errors; ctest with the filter `guest_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/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-12 11:54:46 +00:00 (Migrated from github.com)

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). sceKernelFcntl in Open.cpp conflicts with the FcntlArgumentOf rework, and main now has three more FirstDescriptor comparisons 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_postfix and ioctl_nid_postfix
  • Stdio.cpp: the F_DUPFD branch of fcntl (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_tcp and guest_udp pass (12 of 12 in that filter). This is a local merge, not pushed.

2. The Mound (PPSA26223), 150 s each, observation only.

  • Head 71b717ce5 on its own base: no FATAL, no RtcNetworkThread fault; the title ran the whole 150 s and was stopped by the time limit. The #1794 stop (FD_SET with 0x10000005) is gone.
  • Head merged with main 3d8ffeb27 (resolution above): RtcNetworkThread is 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 whether select is fixed there.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6123746985 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6123746985). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T11:54:46Z. --- Two findings on head `71b717ce5`. **1. It no longer merges onto current `main` (`3d8ffeb27`).** `sceKernelFcntl` in `Open.cpp` conflicts with the `FcntlArgumentOf` rework, and `main` now has three more `FirstDescriptor` comparisons 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_postfix` and `ioctl_nid_postfix` - `Stdio.cpp`: the `F_DUPFD` branch of `fcntl` (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_tcp` and `guest_udp` pass (12 of 12 in that filter). This is a local merge, not pushed. **2. The Mound (PPSA26223), 150 s each, observation only.** - Head `71b717ce5` on its own base: no `FATAL`, no `RtcNetworkThread` fault; the title ran the whole 150 s and was stopped by the time limit. The #1794 stop (`FD_SET` with `0x10000005`) is gone. - Head merged with `main` `3d8ffeb27` (resolution above): `RtcNetworkThread` is 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 whether `select` is fixed there. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-12 13:11:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T13:11:06Z.


For anyone carrying this: the merge of head 71b717ce5 onto current main (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: sceKernelFcntl keeps main's FcntlArgumentOf and tests !GuestSockets::IsOpen(d); sceKernelClose (new on main) tests IsOpen(d).
  • Udp.cpp: fcntl_nid_postfix and ioctl_nid_postfix test !GuestSockets::IsOpen(...); Stdio.cpp: the non-Windows F_DUPFD range throw is dropped (FirstDescriptor no 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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124956741 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6124956741). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T13:11:06Z. --- For anyone carrying this: the merge of head `71b717ce5` onto current `main` (`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`: `sceKernelFcntl` keeps `main`'s `FcntlArgumentOf` and tests `!GuestSockets::IsOpen(d)`; `sceKernelClose` (new on `main`) tests `IsOpen(d)`. - `Udp.cpp`: `fcntl_nid_postfix` and `ioctl_nid_postfix` test `!GuestSockets::IsOpen(...)`; `Stdio.cpp`: the non-Windows `F_DUPFD` range throw is dropped (`FirstDescriptor` no 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).
xXPBSXx commented 2026-10-12 13:26:26 +00:00 (Migrated from github.com)

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-tree against the merge of this head with current main (9d6fa7c3f on my fork, see above); nothing was built for these combinations:

PR Merges with main Merges after this PR Conflicting files
#3649 (poll on files, Windows pipe read ends) yes no Socket/src/Udp.cpp, tests/GuestPoll.cpp, TechnicalDebt.md
#3644 (poll pipe descriptors) no (TechnicalDebt.md) no Socket/src/Udp.cpp, tests/GuestPoll.cpp, TechnicalDebt.md
#4351 (fstat on a guest socket) yes no File/src/Stdio.cpp, Socket/include/SocketRuntime.hpp, TechnicalDebt.md
#4053 (close guest sockets in sceKernelClose) yes yes none
  • #3644 and #3649 also conflict with each other in the same three files: both make poll accept non-socket descriptors, so only one of them can be merged first.
  • This PR makes poll throw for an open descriptor that is not a guest socket and fstat throw 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 the FirstDescriptor range; the poll descriptor-below-the-socket-range check is gone here.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125218729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6125218729). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T13:26:26Z. --- Interaction of this PR with the other open descriptor PRs, from `git merge-tree` against the merge of this head with current `main` (`9d6fa7c3f` on my fork, see above); nothing was built for these combinations: | PR | Merges with `main` | Merges after this PR | Conflicting files | |---|---|---|---| | #3649 (poll on files, Windows pipe read ends) | yes | no | `Socket/src/Udp.cpp`, `tests/GuestPoll.cpp`, `TechnicalDebt.md` | | #3644 (poll pipe descriptors) | no (`TechnicalDebt.md`) | no | `Socket/src/Udp.cpp`, `tests/GuestPoll.cpp`, `TechnicalDebt.md` | | #4351 (fstat on a guest socket) | yes | no | `File/src/Stdio.cpp`, `Socket/include/SocketRuntime.hpp`, `TechnicalDebt.md` | | #4053 (close guest sockets in `sceKernelClose`) | yes | yes | none | - #3644 and #3649 also conflict with each other in the same three files: both make `poll` accept non-socket descriptors, so only one of them can be merged first. - This PR makes `poll` throw for an open descriptor that is not a guest socket and `fstat` throw 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 the `FirstDescriptor` range; the `poll` descriptor-below-the-socket-range check is gone here. AI-assisted (Claude Code).
blawesom commented 2026-10-12 14:36:30 +00:00 (Migrated from github.com)

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, but main landed the opposite direction this morning — 591e8ddad ("feat(libkernel): support fcntl on non-socket descriptors") and 01b7bb3e2 ("support ioctl on non-socket descriptors") route sockets through GuestSockets::FirstDescriptor (high descriptor numbers, membership by range check).

A plain rebase therefore isn't mechanical: every d >= GuestSockets::FirstDescriptor range check main added (in sceKernelClose, sceKernelFcntl, sceKernelIoctl, …) collides with this PR's GuestSockets::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 FirstDescriptor scheme (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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126434706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6126434706). Originally posted by [blawesom](https://github.com/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`, but `main` landed the opposite direction this morning — `591e8ddad` ("feat(libkernel): support fcntl on non-socket descriptors") and `01b7bb3e2` ("support ioctl on non-socket descriptors") route sockets through `GuestSockets::FirstDescriptor` (high descriptor numbers, membership by range check). A plain rebase therefore isn't mechanical: every `d >= GuestSockets::FirstDescriptor` range check main added (in `sceKernelClose`, `sceKernelFcntl`, `sceKernelIoctl`, …) collides with this PR's `GuestSockets::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 `FirstDescriptor` scheme (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.
MarcZX10 commented 2026-10-12 20:38:10 +00:00 (Migrated from github.com)

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 routes fcntl and ioctl through socket-table membership, so those calls no longer depend on FirstDescriptor ranges.

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 --check pass. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132205389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6132205389). Originally posted by [MarcZX10](https://github.com/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 routes `fcntl` and `ioctl` through socket-table membership, so those calls no longer depend on `FirstDescriptor` ranges. 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 --check` pass. 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.
MarcZX10 commented 2026-10-12 20:45:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T20:45:16Z.


Updated the rebased branch to current main at c952c2b0e after 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/main also passes. Windows still needs validation on this latest head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132307485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6132307485). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T20:45:16Z. --- Updated the rebased branch to current `main` at `c952c2b0e` after 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/main` also passes. Windows still needs validation on this latest head.
oneandonlydean commented 2026-10-13 00:19:55 +00:00 (Migrated from github.com)

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.cpp and File/src/Stdio.cpp; please rebase once more. The kqueue code that landed since brought new GuestSockets::FirstDescriptor range checks (Equeue/src/Kqueue.cpp:121, :138 and :328, Equeue/src/FileEvent.cpp:562 and :650), and they need the GuestSockets::IsOpen test as well. Lowest-free numbers as in FreeBSD's fdalloc is the scheme to keep.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135171961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6135171961). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:19:55Z. --- Conflicts with main again, in `core/libs/prx/libkernel/CMakeLists.txt`, `File/src/Open.cpp` and `File/src/Stdio.cpp`; please rebase once more. The kqueue code that landed since brought new `GuestSockets::FirstDescriptor` range checks (`Equeue/src/Kqueue.cpp:121`, `:138` and `:328`, `Equeue/src/FileEvent.cpp:562` and `:650`), and they need the `GuestSockets::IsOpen` test as well. Lowest-free numbers as in FreeBSD's `fdalloc` is the scheme to keep.
nicolasfalesy commented 2026-10-13 02:39:35 +00:00 (Migrated from github.com)

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 main 37dd48308 (Arch Linux, Release, catalog release relinked with --to-intel) it aborts with

what():  fcntl: descriptor 35 is neither a file, a directory, a pipe nor a character device

(the message only reaches the log with #4792; on main it needs gdb). Cause, traced with gdb and strace:

  • The title opens its sockets with sceNetSocket, which numbers them from g_next_sock = 32 in its own table. The fourth one is 35.
  • It then makes that socket non-blocking with plain fcntl: fcntl(35, F_GETFL) followed by fcntl(35, F_SETFL, O_NONBLOCK) (arguments read at fcntl_nid_postfix). On the console a libSceNet socket is a kernel descriptor, so this works.
  • fcntl treats 35 as a host descriptor. On Linux host fd 35 at that moment is an anonymous-inode descriptor of the Vulkan driver (fstat mode 0600, Mesa ANV dups it), so Classify throws. On Windows the same call presumably fails with EBADF, which the title ignores, so it gets further there.

As a check, starting g_next_sock at 0x20000000 locally (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 and fcntl F_GETFL/F_SETFL with O_NONBLOCK to 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6136999824 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6136999824). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T02:39:35Z. --- A Linux title this would unblock, for the `Unblocks:` line: **ProsperoLight (PPSA99002)**. On `main` 37dd48308 (Arch Linux, Release, catalog release relinked with `--to-intel`) it aborts with ``` what(): fcntl: descriptor 35 is neither a file, a directory, a pipe nor a character device ``` (the message only reaches the log with #4792; on `main` it needs `gdb`). Cause, traced with `gdb` and `strace`: - The title opens its sockets with `sceNetSocket`, which numbers them from `g_next_sock = 32` in its own table. The fourth one is 35. - It then makes that socket non-blocking with plain `fcntl`: `fcntl(35, F_GETFL)` followed by `fcntl(35, F_SETFL, O_NONBLOCK)` (arguments read at `fcntl_nid_postfix`). On the console a libSceNet socket is a kernel descriptor, so this works. - `fcntl` treats 35 as a host descriptor. On Linux host fd 35 at that moment is an anonymous-inode descriptor of the Vulkan driver (`fstat` mode `0600`, Mesa ANV dups it), so `Classify` throws. On Windows the same call presumably fails with `EBADF`, which the title ignores, so it gets further there. As a check, starting `g_next_sock` at `0x20000000` locally (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 *and* `fcntl` `F_GETFL`/`F_SETFL` with `O_NONBLOCK` to 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.
MarcZX10 commented 2026-10-13 03:29:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:29:06Z.


Rebased onto current main c13dc7e6b and pushed head e0ec0c809. The rebase keeps low-numbered socket descriptors and routes the new kqueue/file-event checks through GuestSockets::IsOpen, including the range checks called out above. The low-descriptor test setup and current main'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_filesystem and guest_fstatfs. Conventions and git diff --check pass. I have not run Windows or a title on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137549879 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6137549879). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T03:29:06Z. --- Rebased onto current `main` `c13dc7e6b` and pushed head `e0ec0c809`. The rebase keeps low-numbered socket descriptors and routes the new kqueue/file-event checks through `GuestSockets::IsOpen`, including the range checks called out above. The low-descriptor test setup and current `main`'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_filesystem` and `guest_fstatfs`. Conventions and `git diff --check` pass. I have not run Windows or a title on this head.
github-actions[bot] commented 2026-10-13 03:40:45 +00:00 (Migrated from github.com)

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#4525 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md L140-142
#4585 docs/dev/debt/libkernel.md L126-128
#4719 core/libs/prx/libkernel/File/src/Stdio.cpp L726-732
#4754 core/libs/prx/libkernel/Socket/src/Socket.cpp L248-250
#4818 core/libs/prx/libkernel/File/src/Stdio.cpp L759-762
#4903 core/libs/prx/libkernel/File/src/Stdio.cpp L645-646, L807
core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp L4, L17-18
docs/dev/debt/libkernel.md L140-142
#4908 core/libs/prx/libkernel/Equeue/Equeue.cpp L599-602
#4910 core/libs/prx/libkernel/Equeue/Equeue.cpp L596-597, L599-605
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp L121-122, L138-142
core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp L18
core/libs/prx/libkernel/Socket/src/Udp.cpp L539
#4929 core/libs/prx/libkernel/File/src/Stdio.cpp L643-646, L759-762
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137692393 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6137692393). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T03:40:45Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #4525 | `core/libs/prx/libkernel/Socket/src/Udp.cpp` <br>`docs/dev/debt/libkernel.md` [L140-142](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/docs/dev/debt/libkernel.md#L140-L142) | | | | #4585 | `docs/dev/debt/libkernel.md` [L126-128](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/docs/dev/debt/libkernel.md#L126-L128) | | | | #4719 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L726-732](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/File/src/Stdio.cpp#L726-L732) | | | | #4754 | `core/libs/prx/libkernel/Socket/src/Socket.cpp` [L248-250](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Socket/src/Socket.cpp#L248-L250) | | | | #4818 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L759-762](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/File/src/Stdio.cpp#L759-L762) | | | | #4903 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L645-646](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/File/src/Stdio.cpp#L645-L646), [L807](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/File/src/Stdio.cpp#L807)<br>`core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp` [L4](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp#L4), [L17-18](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp#L17-L18)<br>`docs/dev/debt/libkernel.md` [L140-142](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/docs/dev/debt/libkernel.md#L140-L142) | | | | #4908 | `core/libs/prx/libkernel/Equeue/Equeue.cpp` [L599-602](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Equeue/Equeue.cpp#L599-L602) | | | | #4910 | `core/libs/prx/libkernel/Equeue/Equeue.cpp` [L596-597](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Equeue/Equeue.cpp#L596-L597), [L599-605](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Equeue/Equeue.cpp#L599-L605)<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp` [L121-122](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L121-L122), [L138-142](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Equeue/src/Kqueue.cpp#L138-L142)<br>`core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp` [L18](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Socket/include/SocketRuntime.hpp#L18)<br>`core/libs/prx/libkernel/Socket/src/Udp.cpp` [L539](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/Socket/src/Udp.cpp#L539) | | | | #4929 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L643-646](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/File/src/Stdio.cpp#L643-L646), [L759-762](https://github.com/boykopovar/AnyPS5/blob/ea2bbefb2b5d1fbe40b3e9e4b6b4bab98f5c80c1/core/libs/prx/libkernel/File/src/Stdio.cpp#L759-L762) | | |
nicolasfalesy commented 2026-10-13 04:16:09 +00:00 (Migrated from github.com)

Imported 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

what():  fcntl: descriptor 47 is neither a file, a directory, a pipe nor a character device

(41 in one run). strace shows 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's fcntl(47, F_GETFL) / fcntl(47, F_SETFL, O_NONBLOCK) reaches File::Fcntl, whose Linux Classify sees S_IFSOCK and throws. So for this title the remaining piece is fcntl F_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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6138106551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6138106551). Originally posted by [nicolasfalesy](https://github.com/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 ``` what(): fcntl: descriptor 47 is neither a file, a directory, a pipe nor a character device ``` (41 in one run). `strace` shows 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's `fcntl(47, F_GETFL)` / `fcntl(47, F_SETFL, O_NONBLOCK)` reaches `File::Fcntl`, whose Linux `Classify` sees `S_IFSOCK` and throws. So for this title the remaining piece is `fcntl` `F_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.
nicolasfalesy commented 2026-10-13 04:30:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T04:30:00Z.


Opened #4924 on top of this branch for the fcntl part (libSceNet registers a status control with libkernel, like its option setter). With it ProsperoLight gets past fcntl and stops next on poll: descriptor 47 is neither a socket nor a pipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6138256525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6138256525). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T04:30:00Z. --- Opened #4924 on top of this branch for the `fcntl` part (libSceNet registers a status control with libkernel, like its option setter). With it ProsperoLight gets past `fcntl` and stops next on `poll: descriptor 47 is neither a socket nor a pipe`.
nicolasfalesy commented 2026-10-13 05:14:58 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6138769224 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4391#issuecomment-6138769224). Originally posted by [nicolasfalesy](https://github.com/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.
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!4391
No description provided.