fix(libSceRudp): cancel and drain poll waiters on destroy and end #13814

Merged
zaryabzip merged 4 commits from upstream-pr/13814 into main 2026-11-08 04:11:39 +00:00
zaryabzip commented 2026-10-31 07:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-31T07:44:08Z.


What

sceRudpPollDestroy and sceRudpEnd now treat waiters as @BunnyFl's firmware 13.42 run of the module shows. That run was under an emulator with imports stubbed, not on a console.

Call Waiters woken with Returns On main
sceRudpPollDestroy(pollId) 0x80770014 (CANCELLED), every waiter of the poll 0, after all of them have left the wait returns at once; waiters get 0x8077001F
sceRudpEnd() 0x80770014, every waiter of every poll (the run had one waiter) 0, after all of them have left the wait returns at once; waiters get 0x80770001

The debt entry for these two already recorded the difference. sceRudpPollCancel already drains this way (#11294), so the change follows its pattern: a destroyed or ended poll's waiters are counted until they leave, and the call waits for that count to reach zero. What happens afterwards is unchanged and matches the run: a wait on the destroyed id returns 0x8077001F, and after sceRudpEnd waits and cancels return 0x80770001.

Unmeasured, and recorded in the rewritten debt entry: calls on a poll while sceRudpPollDestroy drains it (here they already answer as for a destroyed poll), sceRudpInit while sceRudpEnd drains, and real-kernel wake and timeout races. No function changes count.

The new GuestRudpPollDrain.cpp checks both calls from waiters that signal before they wait. Each round starts waiters (two on one poll for destroy, one for end, as in the run), then calls sceRudpPollDestroy or sceRudpEnd. A round where a waiter arrived after the call is skipped; it shows up as 0x8077001F or 0x80770001. The test requires the waiters to return 0x80770014 and to be back by the time the call returns, over up to 20 rounds. GuestRudpPoll.cpp loses its sleep-based waiter checks for destroy and end, and checks instead that a wait after them returns 0x8077001F or 0x80770001.

sceRudpEnd records its waiters before it marks the library uninitialized, so an allocation failure leaves nothing half done.

Overlap: tools/pr_overlap.py finds conflicts only with my own #13718 (the next debt line) and #13799 (sceRudpEnd and the next debt lines). This one doesn't depend on them, and I'll rebase whichever merges later.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 05ffd4d30a merged into main e8c25dd3ba.

  • No warnings in Export.cpp, GuestRudpPoll.cpp or GuestRudpPollDrain.cpp.
  • ctest -R "guest_rudp|rudp_poll" --timeout 120: 7 of 7 pass on WSL2 and 8 of 8 on Windows (plus rudp_poll_wait_exception). guest_rudp_poll_drain and guest_rudp_poll each pass 10 of 10 on --repeat until-fail:10; the drain test takes about 0.05 s on WSL2 and 0.1 s on Windows.
  • Mutants: with both final drain waits deleted, guest_rudp_poll_drain failed 10 of 10 runs on both hosts with sceRudpPollDestroy returned before its waiters had left the wait. With only sceRudpEnd's deleted, it failed 10 of 10 on both with sceRudpEnd returned before its waiter had left the wait.
  • Baseline: on that main with only GuestRudpPollDrain.cpp and its CMakeLists.txt block, the test builds and then aborts with no waiter woken by sceRudpPollDestroy returned 0x80770014 on both hosts (Windows exit 0xc0000409, Linux SIGABRT).
  • tools/check_conventions.py passes; tools/pr_overlap.py is described above.

Rerun after the main merge, by me, at d6cfab2265, which contains main 10163b0973 (comment): ctest -R "^guest_rudp" passes all 9 tests on Windows 11 Home 25H2 (WinLibs GCC 15.2.0 r7, Release) and on WSL2 (GCC 13.3.0, Release).

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5095661926 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13814). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-31T07:44:08Z. --- ### What `sceRudpPollDestroy` and `sceRudpEnd` now treat waiters as @BunnyFl's [firmware 13.42 run](https://github.com/boykopovar/AnyPS5/pull/10954#issuecomment-6399054346) of the module shows. That run was under an emulator with imports stubbed, not on a console. | Call | Waiters woken with | Returns | On `main` | |---|---|---|---| | `sceRudpPollDestroy(pollId)` | `0x80770014` (`CANCELLED`), every waiter of the poll | 0, after all of them have left the wait | returns at once; waiters get `0x8077001F` | | `sceRudpEnd()` | `0x80770014`, every waiter of every poll (the run had one waiter) | 0, after all of them have left the wait | returns at once; waiters get `0x80770001` | The debt entry for these two already recorded the difference. `sceRudpPollCancel` already drains this way (#11294), so the change follows its pattern: a destroyed or ended poll's waiters are counted until they leave, and the call waits for that count to reach zero. What happens afterwards is unchanged and matches the run: a wait on the destroyed id returns `0x8077001F`, and after `sceRudpEnd` waits and cancels return `0x80770001`. Unmeasured, and recorded in the rewritten debt entry: calls on a poll while `sceRudpPollDestroy` drains it (here they already answer as for a destroyed poll), `sceRudpInit` while `sceRudpEnd` drains, and real-kernel wake and timeout races. No function changes count. The new `GuestRudpPollDrain.cpp` checks both calls from waiters that signal before they wait. Each round starts waiters (two on one poll for destroy, one for end, as in the run), then calls `sceRudpPollDestroy` or `sceRudpEnd`. A round where a waiter arrived after the call is skipped; it shows up as `0x8077001F` or `0x80770001`. The test requires the waiters to return `0x80770014` and to be back by the time the call returns, over up to 20 rounds. `GuestRudpPoll.cpp` loses its sleep-based waiter checks for destroy and end, and checks instead that a wait after them returns `0x8077001F` or `0x80770001`. `sceRudpEnd` records its waiters before it marks the library uninitialized, so an allocation failure leaves nothing half done. Overlap: `tools/pr_overlap.py` finds conflicts only with my own #13718 (the next debt line) and #13799 (`sceRudpEnd` and the next debt lines). This one doesn't depend on them, and I'll rebase whichever merges later. ### 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. --> Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 05ffd4d30a merged into `main` e8c25dd3ba. - No warnings in `Export.cpp`, `GuestRudpPoll.cpp` or `GuestRudpPollDrain.cpp`. - `ctest -R "guest_rudp|rudp_poll" --timeout 120`: 7 of 7 pass on WSL2 and 8 of 8 on Windows (plus `rudp_poll_wait_exception`). `guest_rudp_poll_drain` and `guest_rudp_poll` each pass 10 of 10 on `--repeat until-fail:10`; the drain test takes about 0.05 s on WSL2 and 0.1 s on Windows. - Mutants: with both final drain waits deleted, `guest_rudp_poll_drain` failed 10 of 10 runs on both hosts with `sceRudpPollDestroy returned before its waiters had left the wait`. With only `sceRudpEnd`'s deleted, it failed 10 of 10 on both with `sceRudpEnd returned before its waiter had left the wait`. - Baseline: on that `main` with only `GuestRudpPollDrain.cpp` and its `CMakeLists.txt` block, the test builds and then aborts with `no waiter woken by sceRudpPollDestroy returned 0x80770014` on both hosts (Windows exit 0xc0000409, Linux SIGABRT). - `tools/check_conventions.py` passes; `tools/pr_overlap.py` is described above. **Rerun after the `main` merge, by me**, at `d6cfab2265`, which contains `main` `10163b0973` ([comment](https://github.com/boykopovar/AnyPS5/pull/13814#issuecomment-6697649854)): `ctest -R "^guest_rudp"` passes all 9 tests on Windows 11 Home 25H2 (WinLibs GCC 15.2.0 r7, Release) and on WSL2 (GCC 13.3.0, Release). ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-31 07:50:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T07:50:37Z.

Review: APPROVED


Reviewed — looks good

I reviewed head 43f978e556f4bb13c4aa25b51e522720c03c7307; the wait-drain logic matches the reported firmware behavior, and the exact-head test evidence is strong.

What I ran

Head 43f978e556f4bb13c4aa25b51e522720c03c7307; PR base 828ac0b2ae74aac181ba128fb59b08a1534f2041; the current-base merge preview was clean. Environment: Linux x86_64, kernel 6.1.0-54-amd64, Python 3.11.2, GCC 12.2.0. I did not build or run C++ tests locally.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13814
git diff --check 828ac0b2ae74aac181ba128fb59b08a1534f2041...refs/review/pr-13814
python3 tools/check_conventions.py --base 828ac0b2ae74aac181ba128fb59b08a1534f2041 --head refs/review/pr-13814 --title 'fix(libSceRudp): cancel and drain poll waiters on destroy and end' --body <(gh pr view 13814 --repo boykopovar/AnyPS5 --json body --jq .body)
python3 tools/pr_abi_audit.py --base 828ac0b2ae74aac181ba128fb59b08a1534f2041 --head 43f978e556f4bb13c4aa25b51e522720c03c7307 --json
python3 tools/pr_stack_check.py 13814 --repo boykopovar/AnyPS5
python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/libs/tests/GuestRudpPoll.cpp

Results

Check Result
Diff and conventions Passed; no whitespace errors and all convention/template checks passed.
Merge preview Clean against base 828ac0b2ae74aac181ba128fb59b08a1534f2041; no declared dependencies.
ABI audit Passed with no findings; this lexical check does not prove runtime ABI behavior.
Test registration Heuristic warning was a false positive: exact-head CMake registers guest_rudp_poll from GuestRudpPoll.cpp.
Author-reported tests On this head merged into the stated base, the author reports 6/6 CTest cases on WSL2 and 7/7 on Windows; three focused tests each passed five repetitions. On the base with the new test added, it reportedly aborts at the changed cancellation assertion on both hosts. I did not reproduce these runs.
Hosted CI Conventions, portability, intake, labels, eligibility, and report pass. Windows is still in progress; Linux and specialized jobs are skipped.
Precheck helper status Head/base remained stable. The ABI and test-quality subprocesses in the isolated precheck copy could not start because those workspace-only helper scripts are absent there; I ran the ABI and test-quality helpers directly and inspected registration.
Unedited output from local checks
All conventions checks passed.
{
  "findings": [],
  "limitations": [
    "This lexical audit does not parse C++ fully, prove calling-convention or binary ABI correctness, verify runtime version tables, or replace compilation.",
    "An absent source declaration or explicit alias can be intentional for assembly exports, conditional platform code, or generated interfaces; inspect findings before treating them as defects."
  ],
  "status": "passed"
}
{
  "findings": [
    {
      "path": "core/libs/tests/GuestRudpPoll.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

The CMake registration inspected at this head is add_test(NAME guest_rudp_poll COMMAND guest_rudp_poll_tests). git diff --check emitted no output and exited successfully.

Negative control

Assertion Change to code under test Did the new test fail?
Existing waiters return CANCELLED when their poll is destroyed Author reports running the new test on base 828ac0b2ae74aac181ba128fb59b08a1534f2041 with the test file added Yes, the test reportedly aborts at the cancellation assertion on Windows and WSL2. I did not run this control.

Findings

Blocking

None found in the reviewed source and evidence.

Non-blocking

The PR documents concurrent sceRudpInit during sceRudpEnd draining and real-kernel wake/timeout races as unmeasured. The submitted change does not claim those cases were measured; they remain recorded in the library debt entry.

Sources

Not verified

I did not build or run C++ tests locally, reproduce the author’s Windows/WSL2 tests or negative control, test real-kernel races, or test on console hardware. Hosted Windows CI was still running at the final status check; Linux and specialized jobs were skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721875226 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13814#pullrequestreview-5721875226). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T07:50:37Z. **Review:** APPROVED --- # Reviewed — looks good I reviewed head `43f978e556f4bb13c4aa25b51e522720c03c7307`; the wait-drain logic matches the reported firmware behavior, and the exact-head test evidence is strong. ## What I ran Head `43f978e556f4bb13c4aa25b51e522720c03c7307`; PR base `828ac0b2ae74aac181ba128fb59b08a1534f2041`; the current-base merge preview was clean. Environment: Linux x86_64, kernel 6.1.0-54-amd64, Python 3.11.2, GCC 12.2.0. I did not build or run C++ tests locally. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13814 git diff --check 828ac0b2ae74aac181ba128fb59b08a1534f2041...refs/review/pr-13814 python3 tools/check_conventions.py --base 828ac0b2ae74aac181ba128fb59b08a1534f2041 --head refs/review/pr-13814 --title 'fix(libSceRudp): cancel and drain poll waiters on destroy and end' --body <(gh pr view 13814 --repo boykopovar/AnyPS5 --json body --jq .body) python3 tools/pr_abi_audit.py --base 828ac0b2ae74aac181ba128fb59b08a1534f2041 --head 43f978e556f4bb13c4aa25b51e522720c03c7307 --json python3 tools/pr_stack_check.py 13814 --repo boykopovar/AnyPS5 python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/libs/tests/GuestRudpPoll.cpp ``` ## Results | Check | Result | |---|---| | Diff and conventions | Passed; no whitespace errors and all convention/template checks passed. | | Merge preview | Clean against base `828ac0b2ae74aac181ba128fb59b08a1534f2041`; no declared dependencies. | | ABI audit | Passed with no findings; this lexical check does not prove runtime ABI behavior. | | Test registration | Heuristic warning was a false positive: exact-head CMake registers `guest_rudp_poll` from `GuestRudpPoll.cpp`. | | Author-reported tests | On this head merged into the stated base, the author reports 6/6 CTest cases on WSL2 and 7/7 on Windows; three focused tests each passed five repetitions. On the base with the new test added, it reportedly aborts at the changed cancellation assertion on both hosts. I did not reproduce these runs. | | Hosted CI | Conventions, portability, intake, labels, eligibility, and report pass. Windows is still in progress; Linux and specialized jobs are skipped. | | Precheck helper status | Head/base remained stable. The ABI and test-quality subprocesses in the isolated precheck copy could not start because those workspace-only helper scripts are absent there; I ran the ABI and test-quality helpers directly and inspected registration. | <details> <summary>Unedited output from local checks</summary> ```text All conventions checks passed. ``` ```text { "findings": [], "limitations": [ "This lexical audit does not parse C++ fully, prove calling-convention or binary ABI correctness, verify runtime version tables, or replace compilation.", "An absent source declaration or explicit alias can be intentional for assembly exports, conditional platform code, or generated interfaces; inspect findings before treating them as defects." ], "status": "passed" } ``` ```text { "findings": [ { "path": "core/libs/tests/GuestRudpPoll.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` The CMake registration inspected at this head is `add_test(NAME guest_rudp_poll COMMAND guest_rudp_poll_tests)`. `git diff --check` emitted no output and exited successfully. </details> ## Negative control | Assertion | Change to code under test | Did the new test fail? | |---|---|---| | Existing waiters return `CANCELLED` when their poll is destroyed | Author reports running the new test on base `828ac0b2ae74aac181ba128fb59b08a1534f2041` with the test file added | Yes, the test reportedly aborts at the cancellation assertion on Windows and WSL2. I did not run this control. | ## Findings ### Blocking None found in the reviewed source and evidence. ### Non-blocking The PR documents concurrent `sceRudpInit` during `sceRudpEnd` draining and real-kernel wake/timeout races as unmeasured. The submitted change does not claim those cases were measured; they remain recorded in the library debt entry. ## Sources - [Waiter tracking and destruction at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/43f978e556f4bb13c4aa25b51e522720c03c7307/core/libs/prx/libSceRudp/Export.cpp#L92-L145) - [End, wait, and destroy behavior at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/43f978e556f4bb13c4aa25b51e522720c03c7307/core/libs/prx/libSceRudp/Export.cpp#L184-L197) - [Registered poll regression test at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/43f978e556f4bb13c4aa25b51e522720c03c7307/core/libs/CMakeLists.txt#L893-L900) - [PR description and author-reported test results](https://github.com/boykopovar/AnyPS5/pull/13814) - [Firmware 13.42 emulated-module report linked by the PR](https://github.com/boykopovar/AnyPS5/pull/10954#issuecomment-6399054346) ## Not verified I did not build or run C++ tests locally, reproduce the author’s Windows/WSL2 tests or negative control, test real-kernel races, or test on console hardware. Hosted Windows CI was still running at the final status check; Linux and specialized jobs were skipped.
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!13814
No description provided.