fix(libkernel): report a reset stream socket as hung up and keep POLLOUT on a half-closed one as measured on a PS5 #11247

Merged
orezraey merged 7 commits from upstream-pr/11247 into main 2026-11-14 03:36:13 +00:00
orezraey commented 2026-10-25 22:33:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T22:33:31Z.


What

poll on a guest stream socket now reports a reset connection as a retail PS5 (firmware 13.60) does: POLLHUP plus the requested read bits, never POLLERR and never POLLOUT. On Windows it also keeps POLLOUT for a socket whose peer closed while it can still send. Measured with a homebrew probe from a payload process, over loopback TCP, with events 0, POLLIN and POLLIN|POLLOUT; the source and console log are in this gist (ppollhup).

On the console:

  • Open connection: 0, 0 and 0x4.
  • Peer closed, or peer shut its sending side: 0, 0x1 and 0x5 (readable and writable, no POLLHUP). recv returns 0.
  • Local sending side shut: 0, 0 and 0x4.
  • Both directions shut: 0x10, 0x11 and 0x11.
  • Reset (the peer closes with SO_LINGER {1, 0}): 0x10, 0x11 and 0x11, with no POLLERR. The first recv fails with ECONNRESET (54).

FreeBSD's sopoll_generic never sets POLLERR, and pollscan clears POLLOUT whenever it reports POLLHUP. Before this change:

  • On Linux, a reset reported 0x18, 0x19 and 0x19, because the host's POLLERR reached the guest as 0x8. A host POLLERR on a guest stream socket now becomes POLLHUP with the requested read bits, as was already done for pipes.
  • On Windows, WSAPoll reports a peer's close as POLLHUP alone, so POLLIN|POLLOUT gave 0x1, and a reset kept POLLHUP|POLLERR plus POLLOUT. The half-closed case now adds the requested POLLOUT while the socket has not shut its own sending side. A remaining POLLHUP on a stream socket clears POLLOUT on Windows too.

Datagram sockets were not measured and are unchanged. Both debt entries said "not measured on a console". The Linux one is closed and removed. The Windows one now records the measured behaviour and starts with what still differs (libSceNet sockets, early return with no events).

Before and after

poll result for events 0 / POLLIN / POLLIN|POLLOUT PS5 AnyPS5 before AnyPS5 now
Reset, Linux 0x10 / 0x11 / 0x11 0x18 / 0x19 / 0x19 0x10 / 0x11 / 0x11
Reset, Windows 0x10 / 0x11 / 0x11 POLLHUP|POLLERR, with POLLOUT 0x10 / 0x11 / 0x11
Peer closed, Windows 0 / 0x1 / 0x5 0 / 0x1 / 0x1 0 / 0x1 / 0x5
Open connection, local send side shut, both sides shut as listed above the same the same

Tested

  • Head e9177a54e9: main was merged in, with #14206. main() in GuestPoll.cpp now calls PollsAPipeClosedDuringTheWait after PollsAResetStream, and PollsAHungUpSocketWithoutPollout stays unguarded as in this PR. guest_poll passes three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC); check_conventions passes.
  • Head 38a1d55d1e: main was merged in, with #12741. Only libkernel.md met: it keeps #12741's macOS EV_CLEAR wording and this PR's single poll entry. guest_poll passes three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC); check_conventions passes.
    Windows 11, WinLibs GCC 15.2, full build. The poll and socket tests pass 3 times out of 3 (62 of 63 matching poll|socket|select). select_tests is the Python tool test tools/tests/test_select_tests.py, matched by name. It fails the same way without this change (a FileExistsError in its temporary directory on this machine).

guest_poll has a new PollsAResetStream, which checks:

  • a closed peer gives POLLIN and POLLIN|POLLOUT;
  • a reset gives 0x11, 0x10 and 0x11, then recv gives ECONNRESET.

PollsAHungUpSocketWithoutPollout used to be Linux only and now runs and passes on Windows too. tools/check_conventions.py passes.

Those runs were at head e014d678ab on main b90d009d9f. After #10456 landed, main 2b5225605b was merged in (head 3bc4280f10, the poll debt entry conflict resolved keeping main's descriptor 0 to 2 text): guest_poll passes 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL), and tools/check_conventions.py passes.

  • At head 2ac12a0f9a: main merged in after #9509 and #10456 landed (their revents collect step kept, the stream POLLERR/POLLHUP mapping re-applied on top). guest_poll passes three runs in a row on Windows 11 (MinGW) and on Linux (WSL, GCC); tools/check_conventions.py passes.
  • At head 79435a2bcb: main ca96807e83 merged in after #13738 landed (its first poll debt entry and fstat wording kept, this PR's single Windows poll entry kept, the Linux entry stays removed). guest_poll passes three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL, GCC); tools/check_conventions.py passes.

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: #11223 (it edits the poll code in Udp.cpp and the poll debt entries next to these), #13560 (it rewrites the two kevent debt entries right after these poll entries in docs/dev/debt/libkernel.md), #15518 (it rewrites the kevent EV_CLEAR debt entry right after these poll entries); merge order only
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009388980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11247). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T22:33:31Z. --- ### What `poll` on a guest stream socket now reports a reset connection as a retail PS5 (firmware 13.60) does: `POLLHUP` plus the requested read bits, never `POLLERR` and never `POLLOUT`. On Windows it also keeps `POLLOUT` for a socket whose peer closed while it can still send. Measured with a homebrew probe from a payload process, over loopback TCP, with events 0, `POLLIN` and `POLLIN|POLLOUT`; the source and console log are in [this gist](https://gist.github.com/orezraey/f3c55cb6b4ca8690188e564b75658580) (`ppollhup`). On the console: - **Open connection:** 0, 0 and 0x4. - **Peer closed, or peer shut its sending side:** 0, 0x1 and 0x5 (readable and writable, no `POLLHUP`). `recv` returns 0. - **Local sending side shut:** 0, 0 and 0x4. - **Both directions shut:** 0x10, 0x11 and 0x11. - **Reset** (the peer closes with `SO_LINGER` {1, 0}): 0x10, 0x11 and 0x11, with no `POLLERR`. The first `recv` fails with `ECONNRESET` (54). FreeBSD's `sopoll_generic` never sets `POLLERR`, and `pollscan` clears `POLLOUT` whenever it reports `POLLHUP`. Before this change: - On Linux, a reset reported 0x18, 0x19 and 0x19, because the host's `POLLERR` reached the guest as 0x8. A host `POLLERR` on a guest stream socket now becomes `POLLHUP` with the requested read bits, as was already done for pipes. - On Windows, `WSAPoll` reports a peer's close as `POLLHUP` alone, so `POLLIN|POLLOUT` gave 0x1, and a reset kept `POLLHUP|POLLERR` plus `POLLOUT`. The half-closed case now adds the requested `POLLOUT` while the socket has not shut its own sending side. A remaining `POLLHUP` on a stream socket clears `POLLOUT` on Windows too. Datagram sockets were not measured and are unchanged. Both debt entries said "not measured on a console". The Linux one is closed and removed. The Windows one now records the measured behaviour and starts with what still differs (libSceNet sockets, early return with no events). **Before and after** | `poll` result for events 0 / `POLLIN` / `POLLIN\|POLLOUT` | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | Reset, Linux | 0x10 / 0x11 / 0x11 | 0x18 / 0x19 / 0x19 | 0x10 / 0x11 / 0x11 | | Reset, Windows | 0x10 / 0x11 / 0x11 | `POLLHUP\|POLLERR`, with `POLLOUT` | 0x10 / 0x11 / 0x11 | | Peer closed, Windows | 0 / 0x1 / 0x5 | 0 / 0x1 / 0x1 | 0 / 0x1 / 0x5 | | Open connection, local send side shut, both sides shut | as listed above | the same | the same | ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Head `e9177a54e9`: `main` was merged in, with #14206. `main()` in `GuestPoll.cpp` now calls `PollsAPipeClosedDuringTheWait` after `PollsAResetStream`, and `PollsAHungUpSocketWithoutPollout` stays unguarded as in this PR. `guest_poll` passes three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC); `check_conventions` passes. - Head `38a1d55d1e`: `main` was merged in, with #12741. Only `libkernel.md` met: it keeps #12741's macOS `EV_CLEAR` wording and this PR's single `poll` entry. `guest_poll` passes three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC); `check_conventions` passes. Windows 11, WinLibs GCC 15.2, full build. The `poll` and socket tests pass 3 times out of 3 (62 of 63 matching `poll|socket|select`). `select_tests` is the Python tool test `tools/tests/test_select_tests.py`, matched by name. It fails the same way without this change (a `FileExistsError` in its temporary directory on this machine). `guest_poll` has a new `PollsAResetStream`, which checks: - a closed peer gives `POLLIN` and `POLLIN|POLLOUT`; - a reset gives 0x11, 0x10 and 0x11, then `recv` gives `ECONNRESET`. `PollsAHungUpSocketWithoutPollout` used to be Linux only and now runs and passes on Windows too. `tools/check_conventions.py` passes. Those runs were at head `e014d678ab` on `main` `b90d009d9f`. After #10456 landed, `main` `2b5225605b` was merged in (head `3bc4280f10`, the `poll` debt entry conflict resolved keeping `main`'s descriptor 0 to 2 text): `guest_poll` passes 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL), and `tools/check_conventions.py` passes. - At head 2ac12a0f9a: main merged in after #9509 and #10456 landed (their `revents` collect step kept, the stream `POLLERR`/`POLLHUP` mapping re-applied on top). `guest_poll` passes three runs in a row on Windows 11 (MinGW) and on Linux (WSL, GCC); `tools/check_conventions.py` passes. - At head 79435a2bcb: main ca96807e83 merged in after #13738 landed (its first `poll` debt entry and `fstat` wording kept, this PR's single Windows `poll` entry kept, the Linux entry stays removed). `guest_poll` passes three runs in a row on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL, GCC); `tools/check_conventions.py` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #11223 (it edits the `poll` code in `Udp.cpp` and the `poll` debt entries next to these), #13560 (it rewrites the two `kevent` debt entries right after these `poll` entries in `docs/dev/debt/libkernel.md`), #15518 (it rewrites the `kevent EV_CLEAR` debt entry right after these `poll` entries); merge order only - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 22:36:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:36:32Z.

Review: APPROVED


I checked the source and console log in the linked ppollhup gist: the probe requests no events, POLLIN, and POLLIN|POLLOUT across an open socket, peer close, each shutdown direction and an abortive reset. The observed reset result (0x10/0x11/0x11, then ECONNRESET) matches the new test and mapping. The Windows translation is restricted to registered stream sockets; datagrams and pipes retain their separate handling. git diff --check and current-main conventions pass. Hosted eligibility, conventions, intake, labels and report pass; product builds are skipped by policy. The author reports the focused Windows tests passing; I did not rerun them locally. No concrete defect found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645704379 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11247#pullrequestreview-5645704379). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:36:32Z. **Review:** APPROVED --- I checked the source and console log in the linked `ppollhup` gist: the probe requests no events, `POLLIN`, and `POLLIN|POLLOUT` across an open socket, peer close, each shutdown direction and an abortive reset. The observed reset result (0x10/0x11/0x11, then `ECONNRESET`) matches the new test and mapping. The Windows translation is restricted to registered stream sockets; datagrams and pipes retain their separate handling. `git diff --check` and current-main conventions pass. Hosted eligibility, conventions, intake, labels and report pass; product builds are skipped by policy. The author reports the focused Windows tests passing; I did not rerun them locally. No concrete defect found.
MarcZX10 commented 2026-10-25 23:49:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:49:57Z.

Review: APPROVED


Re-reviewed exact head 3bc4280f10a2dfa04c8bdc8dcf51876ec971e4b8 after the merge of #10456. The stream-socket mapping still matches the recorded console results: peer half-close preserves requested POLLOUT, local send shutdown or reset clears it, and reset POLLERR maps to POLLHUP while retaining requested read bits. The added reset test checks both returned masks and the subsequent ECONNRESET; the Windows closed-peer test now covers its previous platform gap. The author reports the focused poll tests 3/3 on Windows and Linux after the main merge. #9509 and #11223 remain listed as merge-order dependencies; #10456 is now merged and present in the base. Hosted policy checks pass; product checks are skipped by path policy, and I did not independently rerun the guest tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646006434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11247#pullrequestreview-5646006434). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T23:49:57Z. **Review:** APPROVED --- Re-reviewed exact head `3bc4280f10a2dfa04c8bdc8dcf51876ec971e4b8` after the merge of #10456. The stream-socket mapping still matches the recorded console results: peer half-close preserves requested `POLLOUT`, local send shutdown or reset clears it, and reset `POLLERR` maps to `POLLHUP` while retaining requested read bits. The added reset test checks both returned masks and the subsequent `ECONNRESET`; the Windows closed-peer test now covers its previous platform gap. The author reports the focused poll tests 3/3 on Windows and Linux after the main merge. #9509 and #11223 remain listed as merge-order dependencies; #10456 is now merged and present in the base. Hosted policy checks pass; product checks are skipped by path policy, and I did not independently rerun the guest tests.
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!11247
No description provided.