fix(libkernel): report urgent data in poll on macOS #9509

Merged
011010 merged 1 commit from upstream-pr/9509 into main 2026-10-26 20:27:42 +00:00
011010 commented 2026-10-21 23:53:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-21T23:53:10Z.


What

XNU's poll never reports POLLPRI for out-of-band data, so a guest poll that asks for it never sees the urgent byte: guest_poll aborts at its OOB case, and a title waiting on priority data would sleep to its timeout.

On macOS the pending byte is now read from SIOCATMARK, and the wait takes the sliced path main already uses for a kqueue wait instead of a second loop of its own:

  • UrgentPending asks SIOCATMARK for the descriptor. It reports a pending urgent byte without consuming it, and it has no descriptor limit: it replaces an fd_set probe, which called FD_SET unchecked and wrote past the fd_set on the stack for a descriptor at or above FD_SETSIZE.
  • waitsForUrgent makes a poll that asks for POLLPRI on a socket count as sliced, on macOS only.
  • anyUrgentPending runs at the top of each slice; a pending byte skips the wait and ends the loop.
  • collect adds POLLPRI and POLLRDBAND from the same check, as FreeBSD 11.4's sopoll_generic does, before mapping the other flags and the errors.
  • Linux and Windows are unchanged: the helper returns false there, waitsForUrgent is constexpr false, and the slice decision is what it was.

This is the poll path only. The other two paths that ask the host for urgent readiness, guest select/pselect through GuestSockets::Poll and libSceNet's PollSockets, still miss urgent data on macOS and are recorded as a gap in the technical-debt entry.

The idea of probing the socket for the urgent byte comes from #7201, which does it with recv(MSG_OOB | MSG_PEEK). I measured that variant on macOS 27.0.1 and it consumes the byte, so this uses SIOCATMARK instead; #7201 may want the same change. kevent with NOTE_OOB does not fire there either, which is why neither is used.

Tested

Linux (Ubuntu 24.04.5, x86-64, GCC 13.3.0, CMake 3.28.3), on this branch rebased onto current main (518d36eaec), device lavapipe:

  • guest_poll passes with the change. This host is the control, not the proof: the Linux poll reports POLLPRI itself, and the helper is compiled out.
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed.

Host mechanisms measured on macOS 27.0.1 (Apple M4), because the probe had to be chosen, not guessed. With one urgent byte sent and the receiver polling for it:

probe reports it consumes the byte descriptor limit
select exception set yes no FD_SETSIZE (1024)
recv(MSG_OOB | MSG_PEEK) yes yes, 5 of 5 none
kevent EVFILT_EXCEPT + NOTE_OOB never fired — none
SIOCATMARK yes no (the byte is still readable with MSG_OOB afterwards) none

The FD_SET overflow the review caught is why the select probe cannot be kept.

macOS: the reworked code is not run here, and I am not claiming it. main does not compile the libraries on macOS yet (link.h in core/libs/prx/libc/src/GuestAllocations.cpp:26), and mugurc/ci/macos-series-2 predates #7605's unified loop, so applying this change to it needs a merge of main into the series rather than a hunk. What has been run on macOS is the same behaviour on the older structure: guest_poll passes with it on the series, and @maximilianfv reported an M1 Pro run on 2026-10-23 where the test aborts without the change at GuestPoll.cpp:202 and passes 2/2 with it.

One measurement a macOS run may need to weigh: in my probe the urgent byte failed to arrive at all in about half of fresh loopback connections, independent of the probe used, so guest_poll's OOB case may be flaky on a Mac for a reason this change does not address.

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 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959927759 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509). Originally posted by [011010](https://github.com/011010) on 2026-10-21T23:53:10Z. --- ### What XNU's `poll` never reports `POLLPRI` for out-of-band data, so a guest poll that asks for it never sees the urgent byte: `guest_poll` aborts at its OOB case, and a title waiting on priority data would sleep to its timeout. On macOS the pending byte is now read from `SIOCATMARK`, and the wait takes the sliced path `main` already uses for a kqueue wait instead of a second loop of its own: - `UrgentPending` asks `SIOCATMARK` for the descriptor. It reports a pending urgent byte without consuming it, and it has **no descriptor limit**: it replaces an `fd_set` probe, which called `FD_SET` unchecked and wrote past the `fd_set` on the stack for a descriptor at or above `FD_SETSIZE`. - `waitsForUrgent` makes a poll that asks for `POLLPRI` on a socket count as sliced, on macOS only. - `anyUrgentPending` runs at the top of each slice; a pending byte skips the wait and ends the loop. - `collect` adds `POLLPRI` and `POLLRDBAND` from the same check, as FreeBSD 11.4's `sopoll_generic` does, before mapping the other flags and the errors. - Linux and Windows are unchanged: the helper returns false there, `waitsForUrgent` is `constexpr false`, and the slice decision is what it was. This is the `poll` path only. The other two paths that ask the host for urgent readiness, guest `select`/`pselect` through `GuestSockets::Poll` and libSceNet's `PollSockets`, still miss urgent data on macOS and are recorded as a gap in the technical-debt entry. The idea of probing the socket for the urgent byte comes from #7201, which does it with `recv(MSG_OOB | MSG_PEEK)`. I measured that variant on macOS 27.0.1 and it consumes the byte, so this uses `SIOCATMARK` instead; #7201 may want the same change. `kevent` with `NOTE_OOB` does not fire there either, which is why neither is used. ### Tested **Linux** (Ubuntu 24.04.5, x86-64, GCC 13.3.0, CMake 3.28.3), on this branch rebased onto current `main` (`518d36eaec`), device lavapipe: - `guest_poll` **passes** with the change. This host is the control, not the proof: the Linux `poll` reports `POLLPRI` itself, and the helper is compiled out. - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. **Host mechanisms measured on macOS 27.0.1 (Apple M4), because the probe had to be chosen, not guessed.** With one urgent byte sent and the receiver polling for it: | probe | reports it | consumes the byte | descriptor limit | |---|---|---|---| | `select` exception set | yes | no | `FD_SETSIZE` (1024) | | `recv(MSG_OOB \| MSG_PEEK)` | yes | **yes, 5 of 5** | none | | `kevent` `EVFILT_EXCEPT` + `NOTE_OOB` | **never fired** | — | none | | `SIOCATMARK` | yes | **no** (the byte is still readable with `MSG_OOB` afterwards) | none | The `FD_SET` overflow the review caught is why the `select` probe cannot be kept. **macOS: the reworked code is not run here, and I am not claiming it.** `main` does not compile the libraries on macOS yet (`link.h` in `core/libs/prx/libc/src/GuestAllocations.cpp:26`), and `mugurc/ci/macos-series-2` predates #7605's unified loop, so applying this change to it needs a merge of `main` into the series rather than a hunk. What has been run on macOS is the same behaviour on the older structure: `guest_poll` passes with it on the series, and @maximilianfv reported an M1 Pro run on 2026-10-23 where the test aborts without the change at `GuestPoll.cpp:202` and passes 2/2 with it. One measurement a macOS run may need to weigh: in my probe the urgent byte failed to arrive at all in about half of fresh loopback connections, independent of the probe used, so `guest_poll`'s OOB case may be flaky on a Mac for a reason this change does not address. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 00:09:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:09:24Z.

Review: APPROVED


Reviewed the current macOS path. UrgentPending checks only sockets that requested POLLPRI and whose poll result omitted it; the zero-timeout exception-set check supplies the missing readiness bit, while the 10 ms slices are limited to macOS waits that requested priority data. Finite deadlines, zero timeout, pre-ready descriptors, and infinite waits are handled without changing other platforms’ wait path. The PR reports a macOS Rosetta regression run that fails before and passes after, a Linux unchanged-path control, and a standalone select/poll probe; hosted eligibility, intake, conventions, labels, and report checks pass, while product build jobs are skipped. I did not run tests locally. The declared #7605 and #8483 dependencies must be resolved before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607736470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#pullrequestreview-5607736470). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T00:09:24Z. **Review:** APPROVED --- Reviewed the current macOS path. `UrgentPending` checks only sockets that requested `POLLPRI` and whose `poll` result omitted it; the zero-timeout exception-set check supplies the missing readiness bit, while the 10 ms slices are limited to macOS waits that requested priority data. Finite deadlines, zero timeout, pre-ready descriptors, and infinite waits are handled without changing other platforms’ wait path. The PR reports a macOS Rosetta regression run that fails before and passes after, a Linux unchanged-path control, and a standalone select/poll probe; hosted eligibility, intake, conventions, labels, and report checks pass, while product build jobs are skipped. I did not run tests locally. The declared #7605 and #8483 dependencies must be resolved before merge.
MarcZX10 commented 2026-10-22 02:06:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:06:24Z.


Your #7605 dependency and prior #8483 coordination are now documented. The latest overlap scan also flags three open edits to the same libkernel debt paragraph: #7049, #8658 and #9101. These appear to be documentation-line overlaps rather than behavioral prerequisites; please confirm they only require a debt-file rebase/preservation of both descriptions, and record that plan in the overlap note so the checklist’s Depends on: #7605, #8483 remains accurate for actual behavior/order.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330943719 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#issuecomment-6330943719). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:06:24Z. --- Your #7605 dependency and prior #8483 coordination are now documented. The latest overlap scan also flags three open edits to the same libkernel debt paragraph: #7049, #8658 and #9101. These appear to be documentation-line overlaps rather than behavioral prerequisites; please confirm they only require a debt-file rebase/preservation of both descriptions, and record that plan in the overlap note so the checklist’s `Depends on: #7605, #8483` remains accurate for actual behavior/order.
MarcZX10 commented 2026-10-22 02:06:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:06:25Z.

Review: APPROVED


The macOS path is narrow: on Apple platforms only, requested POLLPRI omitted by poll is supplied by select’s exception set, and only waits that request priority data use 10 ms polling slices. The author reports macOS before/after guest_poll, unchanged Linux control, and a focused host probe; policy checks pass and hosted product jobs are skipped. I did not run local tests. #7605/#8483 order is recorded; please preserve the remaining adjacent libkernel debt edits from #7049/#8658/#9101 when rebasing.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608452463 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#pullrequestreview-5608452463). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T02:06:25Z. **Review:** APPROVED --- The macOS path is narrow: on Apple platforms only, requested `POLLPRI` omitted by `poll` is supplied by `select`’s exception set, and only waits that request priority data use 10 ms polling slices. The author reports macOS before/after `guest_poll`, unchanged Linux control, and a focused host probe; policy checks pass and hosted product jobs are skipped. I did not run local tests. #7605/#8483 order is recorded; please preserve the remaining adjacent libkernel debt edits from #7049/#8658/#9101 when rebasing.
MarcZX10 commented 2026-10-22 04:21:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:21:18Z.

Review: DISMISSED


The macOS-only readiness path remains consistent with the earlier review: requested POLLPRI omitted by poll is supplied via select's exception set, and only affected waits use short slices. The reported macOS before/after run and unchanged Linux control remain author-reported.

Two repository requirements are still open:

  1. This branch and its reported checks use the earlier main snapshot, while current upstream main is c61d20f548. Please rebase/update and rerun the focused poll/conventions/overlap checks on the current base.
  2. The live overlap report flags the libkernel debt paragraph shared with #7049, #8658 and #9101. My earlier request asked you to confirm these require only preserving/rebasing adjacent documentation edits and to record that in the overlap note; I do not see that confirmation yet. Please inspect the exact hunks, coordinate if any changed line needs ordering, and document the result.

I found no new behavior defect and did not rerun local tests. Product jobs are skipped in the hosted checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609223269 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#pullrequestreview-5609223269). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:21:18Z. **Review:** DISMISSED --- The macOS-only readiness path remains consistent with the earlier review: requested POLLPRI omitted by poll is supplied via select's exception set, and only affected waits use short slices. The reported macOS before/after run and unchanged Linux control remain author-reported. Two repository requirements are still open: 1. This branch and its reported checks use the earlier main snapshot, while current upstream main is c61d20f54801efc3798555829f6fedcff71ad7ff. Please rebase/update and rerun the focused poll/conventions/overlap checks on the current base. 2. The live overlap report flags the libkernel debt paragraph shared with #7049, #8658 and #9101. My earlier request asked you to confirm these require only preserving/rebasing adjacent documentation edits and to record that in the overlap note; I do not see that confirmation yet. Please inspect the exact hunks, coordinate if any changed line needs ordering, and document the result. I found no new behavior defect and did not rerun local tests. Product jobs are skipped in the hosted checks.
maximilianfv commented 2026-10-25 10:58:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-25T10:58:37Z.

Review: DISMISSED


The collect part is right, and with it guest_poll gets past the urgent-data check on macOS. The diff no longer applies to main, though, and the rebase has to change how #7605's loop decides to return. Guest select still misses urgent data, and the helper fails silently for host descriptors at or above 1024.

Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)

Base: mugurc's macOS series (27e968974) merged with main at 2742004ed2, plus other open macOS fixes. I then toggled only this PR.

At fa0ee571ad, git apply fails on the fourth Udp.cpp hunk, the sliced wait. That hunk conflicts with main itself, not with the macOS series: #7605 replaced the single non-Windows poll with the shared sliced loop. So the "with" state below is a local rebase:

  • hunks 1-3 and the debt bullet, verbatim;
  • hunk 4 replaced by the two changes that are its equivalent on main:
    • sliced is also set on __APPLE__ when a socket asks for POLLPRI;
    • the per-slice socketReady count also counts a socket whose host revents are empty but UrgentPending is true.

I ran 20 tests three times each: guest_poll, guest_select, guest_select_wait, guest_kernel_sys_pselect, guest_tcp, guest_udp and the 14 guest_socket_* tests.

guest_poll the other 19
Without this PR 3/3 abort at GuestPoll.cpp:219: after send(MSG_OOB), poll(POLLPRI, 1000) returns 0 guest_socket_port_zero and guest_socket_pair fail both ways; guest_socket_read_write failed once, a flake
With this PR (rebased as above) 3/3 pass the urgent-data check, then abort later at GuestPoll.cpp:246 same as without, nothing new fails

The later stop at line 246 is a separate macOS gap, not this PR's. After the peer's shutdown(SHUT_WR), XNU reports POLLIN|POLLHUP (0x11), where the test expects In alone. A native probe gives the same result. #9512 handles a related Linux case but not this one, and I found no open PR that does. My comment of 2026-10-23 reported guest_poll passing with this PR. That test file predates PollsAStreamWhosePeerClosed: the urgent check was at line 202 then and is at line 219 now.

I also added a temporary probe to the test: a guest socket, an urgent byte sent from a native peer, and timing with steady_clock. Results:

poll(POLLPRI, 3000), byte sent at 200 ms select exceptfds, byte already pending select exceptfds (3 s), byte sent at 200 ms
Without returns 0 after 3002 ms 0, bit clear 0 after 3001 ms
With (rebased) returns 1, revents 0x2, after 202 ms 0, bit clear 0 after 3001 ms
Hunks 1-3 only, no wait change returns 1, revents 0x2, after 3001 ms 0, bit clear 0 after 3001 ms

The last row is why the wait change matters. Without it, the urgent byte is only noticed when the full timeout expires. By the same code path, a wait with timeout -1 would not return at all (not run).

Findings

  1. The diff conflicts with main, and the rebase needs more than moving the loop. GitHub reports this branch CONFLICTING. On main, poll_nid_postfix decides whether to return at Udp.cpp:1875, before collect runs, and socketReady counts host revents only (Udp.cpp:1873). If UrgentPending stays only inside collect, an urgent byte with no host event never ends a slice, so the wait runs to its deadline. Three changes are needed:

    • set sliced (Udp.cpp:1829) when a socket asks for POLLPRI;
    • count UrgentPending in the per-slice exit test;
    • make the debt entry's 10 ms match the slice the loop actually uses (1 ms on main).

    With those changes the 202 ms row above holds. The "Based on current main" box needs re-ticking after the rebase.

  2. Host descriptors at or above FD_SETSIZE silently lose urgent data (Udp.cpp:554-556 at the PR head). OpenFileLimit.cpp raises RLIMIT_NOFILE to kern.maxfilesperproc, which is 61440 here, so host socket descriptors above 1023 can occur. I dup'ed a socket to descriptor 1500 in a standalone probe:

    • FD_SET leaves the bit clear, because the SDK's overflow check skips it;
    • select fails with EINVAL;
    • UrgentPending returns false, which is the old wrong answer.

    Two checks work at descriptor 1500 on this Mac:

    • kevent with EVFILT_READ and fflags = NOTE_OOB reports NOTE_OOB (0x2) in fflags while the byte is pending. kqueue has no FD_SETSIZE ceiling and can block, so it could be the basis for a wait without slices. EVFILT_READ also fires on ordinary data, so it is not a drop-in POLLPRI-only wait. At the PR head, a POLLIN|POLLPRI wait with timeout -1 wakes every 10 ms for as long as it waits; with main's slices it would wake every 1 ms.
    • recv(fd, &b, 1, MSG_OOB | MSG_PEEK | MSG_DONTWAIT) returns 1.

    If you keep select, at least handle descriptor >= FD_SETSIZE explicitly instead of returning false.

  3. Guest select and pselect still miss urgent data on macOS, and the title suggests they are fixed. Guest select sends exceptfds through KernelSockets (Socket.cpp:68-70) to GuestSockets::Poll. That function still maps Urgent to a bare host POLLPRI (Udp.cpp:1026 and 1043 on main). PollSockets in libSceNet (Export.cpp:724) does the same for sceNet sockets. The probe above shows guest select leaves the exceptfds bit clear in both states, both for a pending byte and for one that arrives during the wait. Put the check in one helper that all three paths call, or list the two remaining paths in the debt entry. If only poll is fixed, the title should name poll.

  4. The debt entry describes a divergence that does not exist (docs/dev/debt/libkernel.md:253 at the PR head). The entry says macOS reports urgent data "until it is read". In a native probe on this Mac ("ab", then "u" sent with MSG_OOB, then "cd"), select's exception bit:

    • stays set after reading the 2 bytes before the mark;
    • clears after reading past the mark;
    • stays clear afterwards, and recv(MSG_OOB) then fails.

    That is the same rule as FreeBSD 11.4's sopoll_generic (so_oobmark || SBS_RCVATMARK). Per CONTRIBUTING, the entry should open with the gap that remains: urgent data is noticed one slice late, POLLRDBAND is not synthesized, and the select paths are not fixed. It should not open with the implementation.

  5. Question about POLLRDBAND. FreeBSD 11.4's sopoll_generic (sys/kern/uipc_socket.c:3076-3078) sets events & (POLLPRI | POLLRDBAND) on the same condition. This PR synthesizes only POLLPRI (Udp.cpp:1791), so a guest that asks for 0x80 alone still gets nothing on macOS. Was that left out on purpose?

  6. Question about prior art. #7201 (opened 2026-10-17) already adds a macOS UrgentPending, using recv(MSG_OOB | MSG_PEEK), and a POLLPRI-only sliced loop in poll_nid_postfix with the same 10 ms and clamp(left, 0, 10) shape. Could you mention it in the body, and credit it if this change was based on it?

  7. Your SIOCATMARK measurement differs from mine. You measured it as 0 while the byte was pending on your M4. On this M1 Pro under Rosetta it reads 1 with the byte pending. Using select was still the right call either way.

AI-assisted: yes (Claude Code rebased the PR locally, ran the tests and probes, read the code and wrote this review).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642836332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#pullrequestreview-5642836332). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-25T10:58:37Z. **Review:** DISMISSED --- The `collect` part is right, and with it `guest_poll` gets past the urgent-data check on macOS. The diff no longer applies to `main`, though, and the rebase has to change how #7605's loop decides to return. Guest `select` still misses urgent data, and the helper fails silently for host descriptors at or above 1024. ### Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2) Base: mugurc's macOS series (`27e968974`) merged with `main` at `2742004ed2`, plus other open macOS fixes. I then toggled only this PR. At `fa0ee571ad`, `git apply` fails on the fourth `Udp.cpp` hunk, the sliced wait. That hunk conflicts with `main` itself, not with the macOS series: #7605 replaced the single non-Windows `poll` with the shared sliced loop. So the "with" state below is a local rebase: - hunks 1-3 and the debt bullet, verbatim; - hunk 4 replaced by the two changes that are its equivalent on `main`: - `sliced` is also set on `__APPLE__` when a socket asks for `POLLPRI`; - the per-slice `socketReady` count also counts a socket whose host `revents` are empty but `UrgentPending` is true. I ran 20 tests three times each: `guest_poll`, `guest_select`, `guest_select_wait`, `guest_kernel_sys_pselect`, `guest_tcp`, `guest_udp` and the 14 `guest_socket_*` tests. | | `guest_poll` | the other 19 | |---|---|---| | Without this PR | 3/3 abort at `GuestPoll.cpp:219`: after `send(MSG_OOB)`, `poll(POLLPRI, 1000)` returns 0 | `guest_socket_port_zero` and `guest_socket_pair` fail both ways; `guest_socket_read_write` failed once, a flake | | With this PR (rebased as above) | 3/3 pass the urgent-data check, then abort later at `GuestPoll.cpp:246` | same as without, nothing new fails | The later stop at line 246 is a separate macOS gap, not this PR's. After the peer's `shutdown(SHUT_WR)`, XNU reports `POLLIN|POLLHUP` (0x11), where the test expects `In` alone. A native probe gives the same result. #9512 handles a related Linux case but not this one, and I found no open PR that does. My comment of 2026-10-23 reported `guest_poll` passing with this PR. That test file predates `PollsAStreamWhosePeerClosed`: the urgent check was at line 202 then and is at line 219 now. I also added a temporary probe to the test: a guest socket, an urgent byte sent from a native peer, and timing with `steady_clock`. Results: | | `poll(POLLPRI, 3000)`, byte sent at 200 ms | `select` exceptfds, byte already pending | `select` exceptfds (3 s), byte sent at 200 ms | |---|---|---|---| | Without | returns 0 after 3002 ms | 0, bit clear | 0 after 3001 ms | | With (rebased) | returns 1, `revents` 0x2, after 202 ms | 0, bit clear | 0 after 3001 ms | | Hunks 1-3 only, no wait change | returns 1, `revents` 0x2, after 3001 ms | 0, bit clear | 0 after 3001 ms | The last row is why the wait change matters. Without it, the urgent byte is only noticed when the full timeout expires. By the same code path, a wait with timeout -1 would not return at all (not run). ### Findings 1. **The diff conflicts with `main`, and the rebase needs more than moving the loop.** GitHub reports this branch `CONFLICTING`. On `main`, `poll_nid_postfix` decides whether to return at `Udp.cpp:1875`, before `collect` runs, and `socketReady` counts host `revents` only (`Udp.cpp:1873`). If `UrgentPending` stays only inside `collect`, an urgent byte with no host event never ends a slice, so the wait runs to its deadline. Three changes are needed: - set `sliced` (`Udp.cpp:1829`) when a socket asks for `POLLPRI`; - count `UrgentPending` in the per-slice exit test; - make the debt entry's 10 ms match the slice the loop actually uses (1 ms on `main`). With those changes the 202 ms row above holds. The "Based on current `main`" box needs re-ticking after the rebase. 2. **Host descriptors at or above `FD_SETSIZE` silently lose urgent data** (`Udp.cpp:554-556` at the PR head). `OpenFileLimit.cpp` raises `RLIMIT_NOFILE` to `kern.maxfilesperproc`, which is 61440 here, so host socket descriptors above 1023 can occur. I dup'ed a socket to descriptor 1500 in a standalone probe: - `FD_SET` leaves the bit clear, because the SDK's overflow check skips it; - `select` fails with `EINVAL`; - `UrgentPending` returns `false`, which is the old wrong answer. Two checks work at descriptor 1500 on this Mac: - `kevent` with `EVFILT_READ` and `fflags = NOTE_OOB` reports `NOTE_OOB` (0x2) in `fflags` while the byte is pending. kqueue has no `FD_SETSIZE` ceiling and can block, so it could be the basis for a wait without slices. `EVFILT_READ` also fires on ordinary data, so it is not a drop-in `POLLPRI`-only wait. At the PR head, a `POLLIN|POLLPRI` wait with timeout -1 wakes every 10 ms for as long as it waits; with `main`'s slices it would wake every 1 ms. - `recv(fd, &b, 1, MSG_OOB | MSG_PEEK | MSG_DONTWAIT)` returns 1. If you keep `select`, at least handle `descriptor >= FD_SETSIZE` explicitly instead of returning `false`. 3. **Guest `select` and `pselect` still miss urgent data on macOS, and the title suggests they are fixed.** Guest `select` sends exceptfds through `KernelSockets` (`Socket.cpp:68-70`) to `GuestSockets::Poll`. That function still maps `Urgent` to a bare host `POLLPRI` (`Udp.cpp:1026` and `1043` on `main`). `PollSockets` in libSceNet (`Export.cpp:724`) does the same for sceNet sockets. The probe above shows guest `select` leaves the exceptfds bit clear in both states, both for a pending byte and for one that arrives during the wait. Put the check in one helper that all three paths call, or list the two remaining paths in the debt entry. If only `poll` is fixed, the title should name `poll`. 4. **The debt entry describes a divergence that does not exist** (`docs/dev/debt/libkernel.md:253` at the PR head). The entry says macOS reports urgent data "until it is read". In a native probe on this Mac (`"ab"`, then `"u"` sent with `MSG_OOB`, then `"cd"`), `select`'s exception bit: - stays set after reading the 2 bytes before the mark; - clears after reading past the mark; - stays clear afterwards, and `recv(MSG_OOB)` then fails. That is the same rule as FreeBSD 11.4's `sopoll_generic` (`so_oobmark || SBS_RCVATMARK`). Per CONTRIBUTING, the entry should open with the gap that remains: urgent data is noticed one slice late, `POLLRDBAND` is not synthesized, and the `select` paths are not fixed. It should not open with the implementation. 5. **Question about `POLLRDBAND`.** FreeBSD 11.4's `sopoll_generic` (`sys/kern/uipc_socket.c:3076-3078`) sets `events & (POLLPRI | POLLRDBAND)` on the same condition. This PR synthesizes only `POLLPRI` (`Udp.cpp:1791`), so a guest that asks for `0x80` alone still gets nothing on macOS. Was that left out on purpose? 6. **Question about prior art.** #7201 (opened 2026-10-17) already adds a macOS `UrgentPending`, using `recv(MSG_OOB | MSG_PEEK)`, and a `POLLPRI`-only sliced loop in `poll_nid_postfix` with the same 10 ms and `clamp(left, 0, 10)` shape. Could you mention it in the body, and credit it if this change was based on it? 7. **Your `SIOCATMARK` measurement differs from mine.** You measured it as 0 while the byte was pending on your M4. On this M1 Pro under Rosetta it reads 1 with the byte pending. Using `select` was still the right call either way. AI-assisted: yes (Claude Code rebased the PR locally, ran the tests and probes, read the code and wrote this review).
adriadam10 commented 2026-10-25 15:16:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-25T15:16:24Z.

Review: CHANGES_REQUESTED


Thanks for the fix. Agreeing with @maximilianfv's review (the evidence there is from a macOS run); this needs a rewrite on top of current main, not just a rebase:

  • Udp.cpp hunk 4 (the separate Apple slicing loop) no longer applies: #7605 merged the paths into one for (;;) loop with a sliced flag. Set sliced (Udp.cpp:1827-1829 on main) when a socket asks for POLLPRI on macOS, and count UrgentPending in the per-slice exit test next to socketReady (Udp.cpp:1871-1875). With only the collect change an urgent byte is noticed at the full timeout (3001 ms vs 202 ms in the reported probe).
  • UrgentPending (Udp.cpp:554-556): a descriptor >= FD_SETSIZE makes FD_SET a no-op and select fail with EINVAL, so it returns false silently. Handle it explicitly (e.g. recv(MSG_OOB | MSG_PEEK | MSG_DONTWAIT) or kevent with NOTE_OOB, both reported to work at fd 1500).
  • Guest select/pselect (via GuestSockets::Poll, which still maps Urgent to bare POLLPRI) and libSceNet's PollSockets still miss urgent data. Put the check in one helper all paths call, or rename the PR to poll and list the other paths in the debt entry.
  • docs/dev/debt/libkernel.md:253: the "reported until it is read" divergence was not reproduced (the exception bit clears once the stream passes the mark, as in FreeBSD's sopoll_generic). Open the entry with the remaining gap (noticed one slice late, POLLRDBAND not synthesized, the select paths) and use the slice length the loop really uses (1 ms on main).
  • sopoll_generic also sets POLLRDBAND on the same condition; please synthesize it or say why not.
  • Please mention #7201, which adds a similar macOS UrgentPending, and credit it if this builds on it.

Tick "Based on current main" again after the rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643825245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#pullrequestreview-5643825245). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-25T15:16:24Z. **Review:** CHANGES_REQUESTED --- Thanks for the fix. Agreeing with @maximilianfv's review (the evidence there is from a macOS run); this needs a rewrite on top of current `main`, not just a rebase: - `Udp.cpp` hunk 4 (the separate Apple slicing loop) no longer applies: #7605 merged the paths into one `for (;;)` loop with a `sliced` flag. Set `sliced` (`Udp.cpp:1827-1829` on main) when a socket asks for `POLLPRI` on macOS, and count `UrgentPending` in the per-slice exit test next to `socketReady` (`Udp.cpp:1871-1875`). With only the `collect` change an urgent byte is noticed at the full timeout (3001 ms vs 202 ms in the reported probe). - `UrgentPending` (`Udp.cpp:554-556`): a descriptor >= `FD_SETSIZE` makes `FD_SET` a no-op and `select` fail with `EINVAL`, so it returns `false` silently. Handle it explicitly (e.g. `recv(MSG_OOB | MSG_PEEK | MSG_DONTWAIT)` or `kevent` with `NOTE_OOB`, both reported to work at fd 1500). - Guest `select`/`pselect` (via `GuestSockets::Poll`, which still maps `Urgent` to bare `POLLPRI`) and libSceNet's `PollSockets` still miss urgent data. Put the check in one helper all paths call, or rename the PR to `poll` and list the other paths in the debt entry. - `docs/dev/debt/libkernel.md:253`: the "reported until it is read" divergence was not reproduced (the exception bit clears once the stream passes the mark, as in FreeBSD's `sopoll_generic`). Open the entry with the remaining gap (noticed one slice late, `POLLRDBAND` not synthesized, the `select` paths) and use the slice length the loop really uses (1 ms on main). - `sopoll_generic` also sets `POLLRDBAND` on the same condition; please synthesize it or say why not. - Please mention #7201, which adds a similar macOS `UrgentPending`, and credit it if this builds on it. Tick "Based on current `main`" again after the rebase.
adriadam10 commented 2026-10-26 18:29:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-26T18:29:05Z.

Review: CHANGES_REQUESTED


Thanks, the single-loop rework fixes the slicing point (sliced plus urgent in the exit test is what I meant). What is still open:

  • Udp.cpp:571-577: UrgentPending still calls FD_SET on any descriptor. On macOS FD_SET does not check fd >= FD_SETSIZE, so a high descriptor now writes past the fd_set on the stack instead of silently returning false. Handle it explicitly (e.g. recv(MSG_OOB | MSG_PEEK | MSG_DONTWAIT) or kevent with NOTE_OOB, both reported to work at fd 1500).
  • Guest select/pselect (GuestSockets::Poll, which still maps Urgent to bare POLLPRI) and libSceNet's PollSockets still miss urgent data. Call one helper from all paths, or rename the PR to poll and list the other paths in the debt entry.
  • sopoll_generic also sets POLLRDBAND on the same condition; please synthesize it in collect or say why not.
  • docs/dev/debt/libkernel.md:306: "it is reported until it is read" was not reproduced (the exception bit clears once the stream passes the mark, as in FreeBSD). Open the entry with the remaining gap (the select paths, POLLRDBAND, wake-up on a 1 ms slice) instead.
  • Please mention #7201 (a similar macOS UrgentPending) in the body, and credit it if this builds on it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657062653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9509#pullrequestreview-5657062653). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-26T18:29:05Z. **Review:** CHANGES_REQUESTED --- Thanks, the single-loop rework fixes the slicing point (`sliced` plus `urgent` in the exit test is what I meant). What is still open: - `Udp.cpp:571-577`: `UrgentPending` still calls `FD_SET` on any descriptor. On macOS `FD_SET` does not check `fd >= FD_SETSIZE`, so a high descriptor now writes past the `fd_set` on the stack instead of silently returning `false`. Handle it explicitly (e.g. `recv(MSG_OOB | MSG_PEEK | MSG_DONTWAIT)` or `kevent` with `NOTE_OOB`, both reported to work at fd 1500). - Guest `select`/`pselect` (`GuestSockets::Poll`, which still maps `Urgent` to bare `POLLPRI`) and libSceNet's `PollSockets` still miss urgent data. Call one helper from all paths, or rename the PR to `poll` and list the other paths in the debt entry. - `sopoll_generic` also sets `POLLRDBAND` on the same condition; please synthesize it in `collect` or say why not. - `docs/dev/debt/libkernel.md:306`: "it is reported until it is read" was not reproduced (the exception bit clears once the stream passes the mark, as in FreeBSD). Open the entry with the remaining gap (the `select` paths, `POLLRDBAND`, wake-up on a 1 ms slice) instead. - Please mention #7201 (a similar macOS `UrgentPending`) in the body, and credit it if this builds on it.
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!9509
No description provided.