feat(libkernel): implement poll for guest sockets #1278

Merged
TheAggie merged 1 commit from upstream-pr/1278 into main 2026-10-08 10:37:50 +00:00
TheAggie commented 2026-10-07 21:42:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-07T21:42:03Z.


What

Implements poll (ku7D4q1Y9PI) in libkernel for guest sockets.

  • The guest pollfd array (FreeBSD layout: int fd; short events; short revents) is translated to WSAPoll on Windows and poll on Linux. Requested and returned flags are mapped one by one, since the host values differ (on Windows POLLIN is POLLRDNORM | POLLRDBAND).
  • A negative descriptor is skipped with revents 0. A closed socket descriptor reports POLLNVAL and counts towards the result; the call then returns without waiting.
  • A timeout below -1 fails with EINVAL, and a null array with a nonzero count with EFAULT, as on FreeBSD.
  • Throws: descriptors below the socket range (files, pipes, stdio), event bits other than POLLIN, POLLPRI, POLLOUT, POLLRDNORM, POLLRDBAND and POLLWRBAND (POLLERR, POLLHUP and POLLNVAL in events are ignored), POLLPRI on Windows, which WSAPoll rejects, and an infinite timeout with no socket to wait on. All are recorded in TechnicalDebt.
  • guest_poll: loopback TCP listener and connection; checks no events with a zero timeout, the 50 ms timeout being honoured, the listener becoming readable on connect, POLLOUT, data arriving, POLLIN/POLLHUP after the peer closes, POLLNVAL for a closed descriptor, skipped negative descriptors, EFAULT and EINVAL.

Related to #1091, which adds GuestSockets::Ready and also changes Udp.cpp; whichever merges second rebases.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti, Ryzen 7 7800X3D.

  • guest_poll, guest_udp, guest_tcp, guest_sce_net pass.
  • All 403 registered tests pass on current main with this, MSG_NOSIGNAL and #1265 applied. They were run from the commands and environments in the generated CTestTestfile.cmake files, because antivirus blocks ctest.exe on this machine.
  • DOOM homebrew PPSA99666 v1.1.1 (lowbit/ps5-doom, GPL-2.0): without this, start-up fails with unresolved ELF import ku7D4q1Y9PI from libkernel.prx; with it, the launcher starts and runs. Its upload server waits with poll on its listener and up to 8 connections. Together with the MSG_NOSIGNAL PR and the same change as #1088, it served its upload page and received a 28.8 MB WAD (Freedoom) intact.

Not tested on Linux.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4778834606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1278). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-07T21:42:03Z. --- ### What Implements `poll` (`ku7D4q1Y9PI`) in libkernel for guest sockets. - The guest `pollfd` array (FreeBSD layout: `int fd; short events; short revents`) is translated to `WSAPoll` on Windows and `poll` on Linux. Requested and returned flags are mapped one by one, since the host values differ (on Windows `POLLIN` is `POLLRDNORM | POLLRDBAND`). - A negative descriptor is skipped with `revents` 0. A closed socket descriptor reports `POLLNVAL` and counts towards the result; the call then returns without waiting. - A timeout below -1 fails with `EINVAL`, and a null array with a nonzero count with `EFAULT`, as on FreeBSD. - Throws: descriptors below the socket range (files, pipes, stdio), event bits other than `POLLIN`, `POLLPRI`, `POLLOUT`, `POLLRDNORM`, `POLLRDBAND` and `POLLWRBAND` (`POLLERR`, `POLLHUP` and `POLLNVAL` in `events` are ignored), `POLLPRI` on Windows, which `WSAPoll` rejects, and an infinite timeout with no socket to wait on. All are recorded in TechnicalDebt. - `guest_poll`: loopback TCP listener and connection; checks no events with a zero timeout, the 50 ms timeout being honoured, the listener becoming readable on connect, `POLLOUT`, data arriving, `POLLIN`/`POLLHUP` after the peer closes, `POLLNVAL` for a closed descriptor, skipped negative descriptors, `EFAULT` and `EINVAL`. Related to #1091, which adds `GuestSockets::Ready` and also changes `Udp.cpp`; whichever merges second rebases. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti, Ryzen 7 7800X3D. - `guest_poll`, `guest_udp`, `guest_tcp`, `guest_sce_net` pass. - All 403 registered tests pass on current `main` with this, `MSG_NOSIGNAL` and #1265 applied. They were run from the commands and environments in the generated `CTestTestfile.cmake` files, because antivirus blocks `ctest.exe` on this machine. - DOOM homebrew PPSA99666 v1.1.1 ([lowbit/ps5-doom](https://github.com/lowbit/ps5-doom), GPL-2.0): without this, start-up fails with `unresolved ELF import ku7D4q1Y9PI from libkernel.prx`; with it, the launcher starts and runs. Its upload server waits with `poll` on its listener and up to 8 connections. Together with the `MSG_NOSIGNAL` PR and the same change as #1088, it served its upload page and received a 28.8 MB WAD (Freedoom) intact. Not tested on Linux. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [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 `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-08 04:36:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T04:36:40Z.


Progress report (539cbd8 → 79c0945)

📈 System libraries: 86.15% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel poll_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052343184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1278#issuecomment-6052343184). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T04:36:40Z. --- <!-- progress-report --> ### Progress report (539cbd8 → 79c0945) 📈 **System libraries**: 86.15% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `poll_nid_postfix` | </details>
hikazey commented 2026-10-08 09:22:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T09:22:55Z.


Linux data point: this is required to start DOOM Shareware PPSA99666 v1.1.1 (lowbit/ps5-doom) on Linux. On current main (0e173a46) the Linux relink fails at load with ./app.elf: symbol lookup error: undefined symbol: ku7D4q1Y9PI (poll). With this PR merged locally (only docs/dev/TechnicalDebt.md conflicts; I kept both entries), plus #1279 and #1307, the title starts and reaches E1M1 on Linux (Ubuntu 24.04 container, GCC 14.2, Mesa llvmpipe). Reaching E1M1 also needs the bundled libc.prx excluded (#1497).

I haven't exercised the upload server path that waits on poll, only start-up and gameplay.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056791909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1278#issuecomment-6056791909). Originally posted by [hikazey](https://github.com/hikazey) on 2026-10-08T09:22:55Z. --- Linux data point: this is required to start DOOM Shareware PPSA99666 v1.1.1 (lowbit/ps5-doom) on Linux. On current `main` (`0e173a46`) the Linux relink fails at load with `./app.elf: symbol lookup error: undefined symbol: ku7D4q1Y9PI` (`poll`). With this PR merged locally (only `docs/dev/TechnicalDebt.md` conflicts; I kept both entries), plus #1279 and #1307, the title starts and reaches E1M1 on Linux (Ubuntu 24.04 container, GCC 14.2, Mesa llvmpipe). Reaching E1M1 also needs the bundled `libc.prx` excluded (#1497). I haven't exercised the upload server path that waits on `poll`, only start-up and gameplay. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-08 10:35:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T10:35:45Z.


Checked: build + full ctest on current main + this PR (439/439), guest_poll passes and doesn't even link without the Udp.cpp change. Flag values and pollfd layout match FreeBSD (sys/poll.h); negative descriptors are skipped, a closed socket reports POLLNVAL, unmodelled cases throw and are in TechnicalDebt. Linux and Windows CI green.

The only conflict with main was the TechnicalDebt line at the end of the section; I rebased and moved it a few lines up. Merging once CI is green on the rebased head. #1091 also touches Udp.cpp, so whichever of the two lands second rebases.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6057993748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1278#issuecomment-6057993748). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T10:35:45Z. --- Checked: build + full ctest on current main + this PR (439/439), `guest_poll` passes and doesn't even link without the `Udp.cpp` change. Flag values and `pollfd` layout match FreeBSD (`sys/poll.h`); negative descriptors are skipped, a closed socket reports `POLLNVAL`, unmodelled cases throw and are in TechnicalDebt. Linux and Windows CI green. The only conflict with main was the TechnicalDebt line at the end of the section; I rebased and moved it a few lines up. Merging once CI is green on the rebased head. #1091 also touches `Udp.cpp`, so whichever of the two lands second rebases.
github-actions[bot] commented 2026-10-08 10:36:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T10:36:35Z.


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
#1459 docs/dev/TechnicalDebt.md L311
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6058007400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1278#issuecomment-6058007400). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T10:36:35Z. --- <!-- 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 | |---|---|---|---| | #1459 | `docs/dev/TechnicalDebt.md` [L311](https://github.com/boykopovar/AnyPS5/blob/4ffc9a14f87ef2af703fb75f716a408c392c82e5/docs/dev/TechnicalDebt.md#L311) | | |
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!1278
No description provided.