fix(libkernel): select descriptors that are not sockets #3462

Merged
exefer merged 1 commit from upstream-pr/3462 into main 2026-10-11 21:24:27 +00:00
exefer commented 2026-10-11 10:59:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by exefer on 2026-10-11T10:59:20Z.


What

Successor to closed #1706, rebased onto current main on top of merged #3455 (which owns the /dev/random, /dev/urandom and descriptor 0-2 special cases, kept unchanged here).

select threw NotImplemented_nid_no_patch("select on descriptors that are not libSceNet sockets") for every descriptor the socket poller did not know. It still throws for those, with one exception: a descriptor the socket poller reports as Unknown that is below GuestSockets::FirstDescriptor (0x10000000) is polled on the host via poll() (Unix; Windows still throws), so regular file and pipe descriptors work. Classification comes from the poller itself, which is the authority for what is a socket: dispatching on the fd number alone was wrong, since socket descriptors can also be small (the guest_sce_net harness covers exactly that, and it caught the first version of this rebase).

An invalid host descriptor (POLLNVAL) fails with EBADF, and mixed host and socket sets are polled in short alternating 10 ms slices so neither side waits out the full slice alone (review point: previously sockets got a 0 ms poll while the host poll waited up to 100 ms).

New test core/libs/tests/GuestSelect.cpp, registered as guest_select beside guest_poll, carried over from #1706 and gated to non-Windows (Windows still throws for non-socket descriptors).

Relationship to #3455

This builds on merged #3455: its device handling and UnknownDescriptor throws are untouched; host fallback is added only for the remaining descriptors the poller does not know. #3476 carried the same commits and also merged; both are in the base.

Tested

Wobbly Life (PPSA29413) on Linux (CachyOS), GCC 16.2.1, Intel i5-12400 + NVIDIA RTX 3060 Ti (615.71.09) stops on main with exactly the log line from #1706's close message:

terminate called after throwing an instance of 'std::runtime_error'
  what():  select on descriptors that are not libSceNet sockets not implemented

With this branch the title proceeds past it into content streaming (menu renders; since #846 and friends, via bring-up #2211). Downstream streaming then hits unrelated, flaky device loss, tracked separately in #3463.

New guest_select unit test passes, and guest_sce_net (with #3455's cases) passes, both verified locally in a BUILD_TESTING=ON build. guest_select is registered Unix-only since Windows still throws for non-socket descriptors, see TechnicalDebt.

Checklist

  • Based on current main; rebases the #1706 change onto merged #3455 (see above)
  • 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 in TechnicalDebt
  • No notes, investigation files or images added to the repository (attach them to this PR)
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: #3455 (merged; this branch builds on it)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818558241 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462). Originally posted by [exefer](https://github.com/exefer) on 2026-10-11T10:59:20Z. --- ### What Successor to closed #1706, rebased onto current `main` on top of merged #3455 (which owns the `/dev/random`, `/dev/urandom` and descriptor 0-2 special cases, kept unchanged here). `select` threw `NotImplemented_nid_no_patch("select on descriptors that are not libSceNet sockets")` for every descriptor the socket poller did not know. It still throws for those, with one exception: a descriptor the socket poller reports as `Unknown` that is below `GuestSockets::FirstDescriptor` (`0x10000000`) is polled on the host via `poll()` (Unix; Windows still throws), so regular file and pipe descriptors work. Classification comes from the poller itself, which is the authority for what is a socket: dispatching on the fd number alone was wrong, since socket descriptors can also be small (the `guest_sce_net` harness covers exactly that, and it caught the first version of this rebase). An invalid host descriptor (`POLLNVAL`) fails with `EBADF`, and mixed host and socket sets are polled in short alternating 10 ms slices so neither side waits out the full slice alone (review point: previously sockets got a 0 ms poll while the host poll waited up to 100 ms). New test `core/libs/tests/GuestSelect.cpp`, registered as `guest_select` beside `guest_poll`, carried over from #1706 and gated to non-Windows (Windows still throws for non-socket descriptors). ### Relationship to #3455 This builds on merged #3455: its device handling and `UnknownDescriptor` throws are untouched; host fallback is added only for the remaining descriptors the poller does not know. #3476 carried the same commits and also merged; both are in the base. ### Tested Wobbly Life (PPSA29413) on Linux (CachyOS), GCC 16.2.1, Intel i5-12400 + NVIDIA RTX 3060 Ti (615.71.09) stops on `main` with exactly the log line from #1706's close message: ```text terminate called after throwing an instance of 'std::runtime_error' what(): select on descriptors that are not libSceNet sockets not implemented ``` With this branch the title proceeds past it into content streaming (menu renders; since #846 and friends, via bring-up #2211). Downstream streaming then hits unrelated, flaky device loss, tracked separately in #3463. New `guest_select` unit test passes, and `guest_sce_net` (with #3455's cases) passes, both verified locally in a `BUILD_TESTING=ON` build. `guest_select` is registered Unix-only since Windows still throws for non-socket descriptors, see TechnicalDebt. ### Checklist - [x] Based on current `main`; rebases the #1706 change onto merged #3455 (see above) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation files or images added to the repository (attach them to this PR) - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: #3455 (merged; this branch builds on it) - [x] AI-assisted: yes
adriadam10 commented 2026-10-11 11:38:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:38:58Z.

Review: CHANGES_REQUESTED


Checked: builds on Linux, guest_select passes, and it fails on main without the Socket.cpp change. Points to fix before this can merge:

  • Overlap with #3455: it rewrites the same select_nid_postfix branch for non-socket descriptors (Socket.cpp, GuestSceNet.cpp). Both cannot land. Please decide with its author how the two combine: #3455 reports fixed values for /dev/random, /dev/urandom and descriptors 0-2 (needed on Windows, titles in #2811), this PR polls the real host descriptor. If you keep yours, rebase on top of #3455 once it merges, replace only the part you want to change (e.g. polling real descriptors instead of fixed values for /dev/*), and list #3455 under Depends on.
  • core/libs/prx/libkernel/CMakeLists.txt:800-809: guest_select is registered on Windows too, where select still throws for pipes (Socket.cpp:132), so the test would abort there. Register it under if(NOT WIN32), or implement the Windows path.
  • Socket.cpp:41-51: RequestedDescriptor and HostPollDescriptor are the same struct; use one.
  • Add a TechnicalDebt line for the non-socket descriptors that still throw on Windows (not at the end of its section).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483157237 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#pullrequestreview-5483157237). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:38:58Z. **Review:** CHANGES_REQUESTED --- Checked: builds on Linux, `guest_select` passes, and it fails on `main` without the `Socket.cpp` change. Points to fix before this can merge: - **Overlap with #3455**: it rewrites the same `select_nid_postfix` branch for non-socket descriptors (`Socket.cpp`, `GuestSceNet.cpp`). Both cannot land. Please decide with its author how the two combine: #3455 reports fixed values for `/dev/random`, `/dev/urandom` and descriptors 0-2 (needed on Windows, titles in #2811), this PR polls the real host descriptor. If you keep yours, rebase on top of #3455 once it merges, replace only the part you want to change (e.g. polling real descriptors instead of fixed values for `/dev/*`), and list #3455 under **Depends on**. - `core/libs/prx/libkernel/CMakeLists.txt:800-809`: `guest_select` is registered on Windows too, where `select` still throws for pipes (`Socket.cpp:132`), so the test would abort there. Register it under `if(NOT WIN32)`, or implement the Windows path. - `Socket.cpp:41-51`: `RequestedDescriptor` and `HostPollDescriptor` are the same struct; use one. - Add a TechnicalDebt line for the non-socket descriptors that still throw on Windows (not at the end of its section).
exefer commented 2026-10-11 11:46:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by exefer on 2026-10-11T11:46:06Z.


Thanks for verifying. All four points are addressed in the updated commit:

  • Overlap: agreed #3455 owns the stdio/random special cases and the titles behind them (#2811). Plan is to rebase this onto #3455 once it lands, keeping its device handling and routing the remaining non-socket descriptors through host poll instead of UnknownDescriptor, and to list #3455 under Depends on at that point. Noting #3476 carries the same commits; this rebases onto whichever lands.
  • guest_select is now registered under if(NOT WIN32) only.
  • RequestedDescriptor and HostPollDescriptor are merged into one PolledDescriptor.
  • TechnicalDebt line added next to the existing select entry: host poll on Unix, still throws on Windows, with the title reference.

Verified locally: check_conventions.py passes, guest_select passes in a BUILD_TESTING=ON build, and the title run still clears the select abort.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108681947 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#issuecomment-6108681947). Originally posted by [exefer](https://github.com/exefer) on 2026-10-11T11:46:06Z. --- Thanks for verifying. All four points are addressed in the updated commit: - Overlap: agreed #3455 owns the stdio/random special cases and the titles behind them (#2811). Plan is to rebase this onto #3455 once it lands, keeping its device handling and routing the remaining non-socket descriptors through host poll instead of `UnknownDescriptor`, and to list #3455 under Depends on at that point. Noting #3476 carries the same commits; this rebases onto whichever lands. - `guest_select` is now registered under `if(NOT WIN32)` only. - `RequestedDescriptor` and `HostPollDescriptor` are merged into one `PolledDescriptor`. - TechnicalDebt line added next to the existing select entry: host poll on Unix, still throws on Windows, with the title reference. Verified locally: `check_conventions.py` passes, `guest_select` passes in a `BUILD_TESTING=ON` build, and the title run still clears the select abort.
adriadam10 commented 2026-10-11 11:50:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:50:57Z.

Review: CHANGES_REQUESTED


Rechecked the updated head: builds on Linux, guest_select passes and fails without the Socket.cpp change, and the earlier points are addressed.

What is left before it can merge:

  • Conflict with #3455 / #3476 (identical commits, same select_nid_postfix branch): both cannot land. Once #3455 merges, please rebase, keep its /dev/random, /dev/urandom and descriptor 0-2 handling (needed on Windows, where this PR still throws) and host-poll only the remaining descriptors below GuestSockets::FirstDescriptor. List #3455 under Depends on.
  • With host and socket descriptors in the same call, sockets are polled with a 0 ms wait while the host poll waits up to 100 ms, so a ready socket can be reported up to 100 ms late. Consider polling the sockets with the same slice, or in short alternating slices.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483190029 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#pullrequestreview-5483190029). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:50:57Z. **Review:** CHANGES_REQUESTED --- Rechecked the updated head: builds on Linux, `guest_select` passes and fails without the `Socket.cpp` change, and the earlier points are addressed. What is left before it can merge: - **Conflict with #3455 / #3476** (identical commits, same `select_nid_postfix` branch): both cannot land. Once #3455 merges, please rebase, keep its `/dev/random`, `/dev/urandom` and descriptor 0-2 handling (needed on Windows, where this PR still throws) and host-poll only the remaining descriptors below `GuestSockets::FirstDescriptor`. List #3455 under Depends on. - With host and socket descriptors in the same call, sockets are polled with a 0 ms wait while the host poll waits up to 100 ms, so a ready socket can be reported up to 100 ms late. Consider polling the sockets with the same slice, or in short alternating slices.
exefer commented 2026-10-11 12:11:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by exefer on 2026-10-11T12:11:16Z.


Rebased onto merged #3455 and addressed the remaining points:

  • Rebase: #3455's device handling and UnknownDescriptor throws are untouched; host fallback applies only to descriptors the socket poller reports as Unknown below GuestSockets::FirstDescriptor (Unix; Windows still throws). Listed under Depends on.
  • Classification comes from the poller, not the fd number. The first version of this rebase dispatched on the number range and broke guest_sce_net: its harness uses small-numbered socket descriptors (fd 38 hit host poll() with POLLNVAL). Now a non-blocking poller probe classifies first; only unknowns fall through to host poll. That probe also confirmed the number-range assumption was wrong, so it is gone.
  • Mixed host/socket calls now alternate in 10 ms slices bounded by the original slice end, so neither side waits out the full slice alone. Single-side calls are unchanged (full wait to their own poller).
  • Points 2-4 from the earlier review are carried over: guest_select under if(NOT WIN32), one shared Entry struct (the two local structs are gone entirely), TechnicalDebt line next to the select entry.

Verified: conventions pass, guest_select and guest_sce_net pass in a BUILD_TESTING=ON build, and Wobbly Life runs 813 file opens with zero select aborts, reaching the in-tutorial MSAA stop (#419).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108882020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#issuecomment-6108882020). Originally posted by [exefer](https://github.com/exefer) on 2026-10-11T12:11:16Z. --- Rebased onto merged #3455 and addressed the remaining points: - Rebase: #3455's device handling and `UnknownDescriptor` throws are untouched; host fallback applies only to descriptors the socket poller reports as `Unknown` below `GuestSockets::FirstDescriptor` (Unix; Windows still throws). Listed under Depends on. - Classification comes from the poller, not the fd number. The first version of this rebase dispatched on the number range and broke `guest_sce_net`: its harness uses small-numbered socket descriptors (fd 38 hit host `poll()` with `POLLNVAL`). Now a non-blocking poller probe classifies first; only unknowns fall through to host poll. That probe also confirmed the number-range assumption was wrong, so it is gone. - Mixed host/socket calls now alternate in 10 ms slices bounded by the original slice end, so neither side waits out the full slice alone. Single-side calls are unchanged (full wait to their own poller). - Points 2-4 from the earlier review are carried over: `guest_select` under `if(NOT WIN32)`, one shared `Entry` struct (the two local structs are gone entirely), TechnicalDebt line next to the select entry. Verified: conventions pass, `guest_select` and `guest_sce_net` pass in a `BUILD_TESTING=ON` build, and Wobbly Life runs 813 file opens with zero select aborts, reaching the in-tutorial MSAA stop (#419).
adriadam10 commented 2026-10-11 21:24:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:24:22Z.

Review: APPROVED


Checked on Linux: builds on current main, guest_select passes and fails without the Socket.cpp change, and guest_sce_net still passes (small-numbered socket descriptors keep going through the poller). Points from the earlier reviews are addressed (rebase on #3455, classification by the poller, EBADF, alternating slices, Unix-only test, TechnicalDebt line). Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5485023535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#pullrequestreview-5485023535). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:24:22Z. **Review:** APPROVED --- Checked on Linux: builds on current `main`, `guest_select` passes and fails without the `Socket.cpp` change, and `guest_sce_net` still passes (small-numbered socket descriptors keep going through the poller). Points from the earlier reviews are addressed (rebase on #3455, classification by the poller, `EBADF`, alternating slices, Unix-only test, TechnicalDebt line). Merging.
Mouhand-Kaddo commented 2026-10-11 21:26:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T21:26:44Z.


Windows build result after this merged: current main 14a7e64dc, Windows 11 x64, MinGW GCC 15.2, Release. cmake --build build-windows --target libs --parallel 4 fails while compiling core/libs/prx/libkernel/Socket/src/Socket.cpp:

Socket.cpp:194:39: error: 'HostPoll' was not declared in this scope
Socket.cpp:212:17: error: 'HostPoll' was not declared in this scope

HostPoll is defined inside #ifndef _WIN32, but the new mixed-host/socket and host-only branches of select_nid_postfix call it outside that guard. The preceding Windows build on b3ae11201 succeeded. Linux was not tested in this comparison.

AI-assisted: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113955777 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#issuecomment-6113955777). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T21:26:44Z. --- Windows build result after this merged: current main `14a7e64dc`, Windows 11 x64, MinGW GCC 15.2, Release. `cmake --build build-windows --target libs --parallel 4` fails while compiling `core/libs/prx/libkernel/Socket/src/Socket.cpp`: ```text Socket.cpp:194:39: error: 'HostPoll' was not declared in this scope Socket.cpp:212:17: error: 'HostPoll' was not declared in this scope ``` `HostPoll` is defined inside `#ifndef _WIN32`, but the new mixed-host/socket and host-only branches of `select_nid_postfix` call it outside that guard. The preceding Windows build on `b3ae11201` succeeded. Linux was not tested in this comparison. AI-assisted: yes (Codex).
Mouhand-Kaddo commented 2026-10-11 21:34:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T21:34:14Z.


The Windows build failure is fixed in #4021. On main 989146c3b, libkernel fails at both HostPoll calls; with the platform guard, the full libs build succeeds and all five focused Windows socket/module tests pass. Local testing was Windows-only. AI-assisted with Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114024334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3462#issuecomment-6114024334). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T21:34:14Z. --- The Windows build failure is fixed in #4021. On main `989146c3b`, `libkernel` fails at both `HostPoll` calls; with the platform guard, the full `libs` build succeeds and all five focused Windows socket/module tests pass. Local testing was Windows-only. AI-assisted with Codex.
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!3462
No description provided.