Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
TheAggie:feat/libkernel-poll
Oct 8, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
TheAggie:feat/libkernel-poll

Conversation

@TheAggie

@TheAggie TheAggie commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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 perf(recompiler): loop the BDA byte stores and written-page probes #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 fix(libkernel): accept guest socket addresses whatever their sa_len #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

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Progress report (539cbd8 → 79c0945)

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

✅ 1 implemented
Library Name
libkernel poll_nid_postfix

@hikazey

hikazey commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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).

Translate the FreeBSD pollfd layout and flags to WSAPoll on Windows and
poll on Linux. Closed socket descriptors report POLLNVAL, a timeout below
-1 fails with EINVAL and a null array with EFAULT. Non-socket
descriptors, unknown event bits, POLLPRI on Windows and an infinite wait
without sockets throw; these are recorded in TechnicalDebt.

DOOM (PPSA99666) imports poll for its upload server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 force-pushed the feat/libkernel-poll branch from 79c0945 to 408e305 Compare October 8, 2026 10:35
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants