Skip to content

feat(libkernel): skip the end of file in poll with POLLINIGNEOF on sockets and pipes, as FreeBSD 11.4 does - #27260

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
kiansaeidnia:feat/libkernel-poll-inignoreeof
Nov 27, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
kiansaeidnia:feat/libkernel-poll-inignoreeof

Conversation

@kiansaeidnia

Copy link
Copy Markdown
Contributor

What

poll threw NotImplemented for POLLINIGNEOF (0x2000) on guest sockets, libSceNet sockets and pipes. FreeBSD 11.4's sopoll_generic and pipe_poll skip their end-of-file block when the bit is set, and poll now does the same:

  • POLLHUP is never reported, and a hung-up descriptor reports POLLOUT.
  • POLLIN/POLLRDNORM follow soreadabledata. A stream needs its SO_RCVLOWAT bytes queued, a datagram socket a queued datagram (an empty one counts), and a listener a pending connection. A pending socket error keeps the socket readable even after the guest's own SHUT_RD.
  • The bit is never forwarded to the host or returned in revents. A wait that the host ends with only dropped readiness is resumed.

macOS's poll does not report a socket error as POLLERR, so there the error is found with a peeking non-blocking recv, which leaves it pending.

A new debt entry lists the host differences that remain. The clause listing POLLINIGNEOF among the inputs poll throws on is removed from the pending fix-libkernel-select-poll-reuse.md fragment, because debt_fold refuses a second fragment that changes the same entry.

Tested

Windows 11, MinGW-w64 GCC 16.2, Release: guest_poll and guest_sce_net_kernel_forwards pass (2/2, run repeatedly). The new checks cover:

  • a pipe after the writer closed;
  • a TCP pair after the peer's SHUT_WR, after its own SHUT_RD, and after SHUT_RDWR;
  • a reset stream;
  • SO_RCVLOWAT;
  • an empty datagram, a listener with and without a pending connection, and a pipe write end after its reader closed;
  • a SOCK_SEQPACKET pair, outside macOS, which has no seqpacket socketpair.

The guest-socket and libSceNet paths are both covered. Udp.cpp and GuestPoll.cpp pass g++ -fsyntax-only for Linux in WSL, and Udp.cpp also passes with the macOS-only blocks forced on. The macOS path has not been run: there is no macOS host here, and CI runs guest_poll only on Linux and Windows. On main, every call with the bit threw.

The overlap check reports #22398 (random-device poll, a different change) on the same line of fix-libkernel-select-poll-reuse.md. Whichever merges second rebases that line.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

…ckets and pipes, as FreeBSD 11.4 does

poll no longer throws for POLLINIGNEOF on a guest socket, a libSceNet
socket or a pipe. As FreeBSD 11.4's sopoll_generic and pipe_poll skip
their end-of-file block when the bit is set, POLLHUP is never reported,
a hung-up descriptor reports POLLOUT, and POLLIN and POLLRDNORM follow
soreadabledata: a stream socket needs its SO_RCVLOWAT bytes queued, a
datagram socket a queued datagram, even an empty one, a sequenced-packet
socket queued bytes, a listener a pending connection, and a pending
socket error keeps the socket readable after the guest's own SHUT_RD.
macOS, whose poll does not report a socket error as POLLERR, finds it
with a peeking non-blocking recv, which leaves the error pending.
A wait that the host ends with only such dropped readiness is resumed.

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: avoid dereferencing a null socket when a forwarded socket has POLLINIGNEOF readiness and a pending error.

What I ran

Reviewed head e5422a9d7c4d2d7602962ae620ab3686fd5b8255 using repo_read.py to inspect the prepared description, commit summary, manifest, diff, and changed source ranges. No tests or builds were run. The author reports tests and syntax checks in the PR description; those were not run during this review.

Results

Check Result Note
Prepared diff and changed code passed Five changed files inspected
Tests and builds not run Author-reported checks only
Platform coverage not run macOS path unconfirmed

Findings

Blocking

  • core/libs/prx/libkernel/Socket/src/Udp.cpp:3295 can dereference a null socket. Forwarded sockets are added to forwardedSockets, but not guestSockets, so guestAt[i] is null for them. If a forwarded socket reports readable readiness while errorPending is true, the code skips the preceding PollDataQueued branch and reaches socket->type here. This can crash polling libSceNet sockets on that path. Guard the socket-specific low-water check or derive the socket type without assuming a guest socket.

Non-blocking

None.

Not verified

  • No tests or builds were run; author-reported Windows test results and Linux syntax checks were not independently confirmed.
  • macOS behavior is unconfirmed, as the PR description also states.
  • The prepared manifest lists five changed files, and all five full texts were readable and inspected. files.json was not available through the reader, so the excluded-file list was not verified.

To get this to a good state

Guard the socket-specific access at Udp.cpp:3295, then rerun the relevant poll tests, including the forwarded-socket error case.

@RavenCurseBurg

RavenCurseBurg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

I tested the poll implementation from e5422a9d7c through the real guest libc, libkernel and libSceNet on Intel macOS 15. The build used the libc++abi declaration from #26739. The new pipe, queued-data, low-water, listener and datagram cases passed three consecutive runs. With POLLINIGNEOF, an empty gracefully closed stream returned only the requested writable bit. A reset stream returned readable and writable, and the subsequent real receive still returned guest ECONNRESET (54). Guest runtime comparison

I found one portability issue in the new forwarded-socket test. It calls SHUT_RD and then SHUT_RDWR on the same accepted socket. Through libSceNet, Darwin returns ENOTCONN (57) on the second call. Shutting the remaining send side with SHUT_WR reaches the intended both-sides-closed state and preserves every poll assertion. With this one-line change the complete forwarded-socket CTest passed five times each on macOS, Ubuntu and Windows. The complete guest_poll CTest also passed five times on Ubuntu and Windows on both the original and updated fixture. Test-only cherry-pick · Linux run

One older assertion still stops the full Darwin guest_poll executable. After a TCP reset, a plain poll with events=0 returns zero where the test expects POLLHUP. The stock test on the PR's parent, 098c73473f, fails at exactly that assertion. Running the remaining reset assertions in a separate process passed three times on the PR. Darwin full tests and stock-parent control

On the pending-error review point, the low-water block is guarded by !errorPending. When socket is empty, lowWater also stays at its initial value of 1, so the lowWater > 1 operand short-circuits before socket->type. Control flow at the reviewed head

I also tested the complete Darwin integration. Adding the existing #20161 fix for the zero-interest hangup to the shutdown adjustment above made the stock guest_poll and guest_sce_net_kernel_forwards CTests pass five times each. The same run included guest_getrusage, six wait variants and guest_dynamic_cast. All ten CTests passed five consecutive executions on Intel macOS 15 (50 passes, 42.91 s). Combined run and full log

@oneandonlydean
oneandonlydean dismissed MarcZX10’s stale review November 25, 2026 19:03

MarcZX10 CHANGES_REQUESTED 2026-11-25T16:26Z on e5422a9 (review 6061131544): null dereference of socket at Udp.cpp:3295. Checked at source: lowWater starts at 1 and is raised only inside if (socket) (Udp.cpp:3290-3293), so for a forwarded socket (socket null) lowWater > 1 is false and the && short-circuits before socket->type is read. No defect; RavenCurseBurg reached the same reading in the thread. Fresh PASS: notes/27260-e5422a9d7c.md.

The fixture already closed the receive side. Closing the send side next reaches the same final state on macOS for sockets forwarded through libSceNet.

AI-assisted: Codex + GPT-6.2 Astra (xhigh)
@kiansaeidnia

Copy link
Copy Markdown
Contributor Author

Thanks, @RavenCurseBurg, for the macOS runs. I cherry-picked the test-only change (eb54118: SHUT_WR instead of a second SHUT_RDWR on the accepted socket) with its authorship. guest_sce_net_kernel_forwards and guest_poll pass three runs in a row on Windows 11.

On the earlier null-socket finding: as you showed, that low-water block is guarded by !errorPending, and for a forwarded socket lowWater stays at 1, so lowWater > 1 short-circuits before socket->type is read. That path cannot dereference a null socket, so I left the code unchanged. The Darwin events=0 reset assertion fails on the parent too, and #20161 covers it.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

The reviewed change adds POLLINIGNEOF handling for sockets and pipes; I found no verified blocking defect, but the macOS-specific behavior remains unverified.

What I ran

Reviewed head ad768c99ccfb9e27f179ad6ec013cbc8dd5f4048 against base main. No commands or tests were run in this review; test results in the PR description are author-reported.

Results

Check Result Note
Changed behavior review passed Relevant implementation and added lines inspected
Test execution not run No tests run in this review
Windows and Linux behavior not run Author reports tests and syntax checks
macOS behavior not run Author reports no macOS host was available

Negative control

Not run; no test was executed in this review.

Findings

Blocking

None identified in the code reviewed.

Non-blocking

  • The macOS-specific pending-error detection and poll behavior have not been run on macOS. The PR description also notes that CI does not run guest_poll on macOS. Please verify that path on a macOS host or CI before relying on the stated cross-platform behavior. Relevant changed code: core/libs/prx/libkernel/Socket/src/Udp.cpp:3091 and core/libs/prx/libkernel/Socket/src/Udp.cpp:3284.

Sources

  • core/libs/prx/libkernel/Socket/src/Udp.cpp: pipe readiness, queue inspection, error detection, and poll result filtering.
  • core/libs/tests/GuestPoll.cpp: added pipe, socket, low-water, datagram, and listener coverage.
  • core/libs/tests/GuestNetKernelForwards.cpp: added guest socket and libSceNet coverage.
  • docs/dev/debt/changes/feat-libkernel-poll-inignoreeof.md and docs/dev/debt/changes/fix-libkernel-select-poll-reuse.md: documented host differences and updated debt entry.

Not verified

  • Tests and builds were not run in this review. The author reports Windows 11 tests and Linux syntax checks; those results were not independently verified.
  • macOS-specific runtime behavior was not verified.
  • Read the prepared description, commits, manifest, full diff, and all added lines for the five changed files; inspected relevant head ranges in the implementation and test files. Did not read the complete contents of the changed source and test files.

To get this to a good state

Nothing is required. Optional: verify the macOS path on a macOS host or CI.

@github-actions

Copy link
Copy Markdown

Progress report (15cd49f → ad768c9)

📉 System libraries: 46.97% (-0.0025%, -1 reverted function)

⚠️ 1 went back to stubs
Library Name
libkernel poll_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libkernel 754/797 (94.60%) 753/797 (94.48%) -0.13%

@oneandonlydean
oneandonlydean merged commit 572c139 into boykopovar:main Nov 27, 2026
15 checks passed
videogamer10293 added a commit to videogamer10293/AnyPS5 that referenced this pull request Dec 3, 2026
…as a stub

always_stub_calls read every preprocessor combination of each function that
might reach NotImplemented_nid_no_patch before checking whether all of them
call a stub. A helper that calls it only behind a condition, with more than
256 combinations, aborted the whole audit, although its first combination
already shows it is not an always-stub helper. Since boykopovar#27260 libkernel's
PollDescriptors is such a helper, so import_audit.py and audit_dump.py stop
for every title.

A combination with no call to a function that might reach a stub can never
be satisfied, so reading stops there and the helper is left out, as the full
read would have decided. Every body is still parsed first, so an unmatched
#if in a later overload still fails the audit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants