feat(libSceRudp): implement sceRudpPollCancel as firmware 13.42's library does #11294
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11294"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-26T00:39:31Z.
What
sceRudpPollCancelis a parameterless placeholder that throws. This implements it as firmware 13.42'slibSceRudp.sprxbehaves in @BunnyFl's runs on #10954: the detailed report (module hash, export offsets, raw output of two identical runs) and the drain clarification. Those runs execute the real library with its kernel and libc imports stubbed and waits scheduled by a script. They are firmware-library execution, not a console measurement, and the debt entry says so. @AZLisme agreed in #10954 that I takesceRudpPollCancel, crediting @BunnyFl.int sceRudpPollCancel(int pollId), the Orbital prototype, which the trace confirms (only the low 32 bits are read, the result is an int):sceRudpInit:0x80770001. Negative id:0x80770004. Unknown or destroyed id:0x8077001F.sceRudpPollWaiton that poll returns0x80770014at once, also with a zero timeout, and the wait after it is normal again. Other polls are unaffected.0x80770014. The cancel returns 0 once none is left inside the wait, and nothing stays pending.In
Export.cpp, eachRudpPollgains a waiter count, a draining count, a cancel generation and a pending flag.sceRudpPollWaitconsumes a pending cancel before waiting. Otherwise it registers as a waiter and returns0x80770014when the generation changed while it waited. It looks the poll up by id again after every wake-up, so a poll destroyed during the wait is never touched through a stale reference.sceRudpPollCancelbumps the generation and moves the waits registered at that moment to the draining count. It then wakes everyone and waits until the draining count is 0, the poll is gone or the library has ended. A wait that starts during the drain is neither cancelled nor counted; that case is unmeasured on the console and the debt entry says so.Not changed: on 13.42,
sceRudpPollDestroyandsceRudpEndalso wake waiters with0x80770014and wait for them to leave. Here they still return at once and wake waiters with0x8077001F/0x80770001, as #10954 records. That's a separate change.Tested
Windows 11, WinLibs GCC 15.2.0 r7, full Release build of
e31fad5ae8(currentmainmerged in): no failed steps.GuestRudpPoll.cppgains: cancel before init; negative,INT_MINand unknown ids; two idle cancels leaving one, consumed by the next wait, also bywait(0), with another poll unaffected; two waiters (infinite and 10 s) both returning0x80770014, the cancel returning within 500 ms, and a later wait timing out normally; cancel on a destroyed poll; cancel aftersceRudpEnd.rudp_poll_wait_exception. It compiles the productionExport.cppandTimedWait.cppwith anoperator newthat fails on one thread. After a wait throws insideTimedWait, a cancel must return at once and keep its pending cancellation.guest_rudp*/rudp_poll_wait_exceptiontests pass, 5 runs. With the pre-fixExport.cpp(0c85096011),rudp_poll_wait_exceptionfails (2 of 2) andguest_rudp_pollfails at the late-arrival check (5 of 5).Export.cpp(only the placeholder's signature changed so the test links),guest_rudp_pollaborts with "sceRudpPollCancel not implemented".tools/check_conventions.py --base origin/mainpasses.Overlap
mainis merged in, and its cancel/destroy/end debt entry now covers destroy and end only, with its gaps kept; PollCancel has its own entry.sceRudpSetMaxSegmentSizeits parameter on the next line ofinclude/Api.hppand edits the same debt line, so git reports a conflict there. Both are text merges that keep both changes; it doesn't touch the poll code. Whichever lands second takes them.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)mainis merged in)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:42:00Z.
Review: DISMISSED
The waiter-drain can be held open indefinitely by a wait that starts after cancellation begins.
sceRudpPollCancelincrementspoll.cancels, broadcasts, and waits untilpoll.waiters == 0. If a newsceRudpPollWaitacquires the mutex before the original waiter(s) have drained, it snapshots the already-incremented generation and blocks normally; it is not woken by this cancellation. The original waiter decrements the count, but the new infinite waiter keeps it nonzero, sosceRudpPollCancelcannot return until that unrelated wait times out or some later operation destroys the poll. This is possible with concurrent poll users and can turn cancellation into an indefinite hang.The added two-waiter test starts both waits before calling cancel, so it does not exercise this interleaving. Please make the drain/wakeup semantics robust for waiters arriving while cancellation is in progress, and add a bounded regression for that ordering. The firmware report establishes behavior for waiters already blocked when cancel is called, but does not settle arrivals during the drain; please keep that boundary explicit if the exact console behavior remains unknown.
Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-26T01:04:09Z.
Review: DISMISSED
I found a separate exception-cleanup hang on exact head
344acf3e661e8b1a240f2cd0436df76d3c31c9b8, in addition to Marc's late-arrival finding.sceRudpPollWaitincrements the poll's waiter count before enteringTimedWait::Condition, but decrements it only on the normal path. On Windows, first-use wait state allocates real C++ objects. If that allocation throws, the call exits while its registration remains. A subsequentsceRudpPollCancelsees a waiter that can never drain.I reproduced this with the complete production
Export.cppandTimedWait.cpp, actual Windows waits and thread-local state, and thread-scopedoperator newfaults. Four cases cover finite/infinite waits and the 80-byte waiter / 16-byte thread-state allocations. All four catchbad_allocand leave cancel blocked past the 200 ms observation window. Destroying the poll releases the cancel thread, so the regression itself finishes normally. The 16-byte failure occurs afterCondition::Waithas unlocked the mutex: cleanup must reacquire it before touching the poll map.Tested repair: 57ee4b745ff7, on branch codex/review-rudp-wait-cleanup. One commit, three files, 140 insertions / 2 deletions. Its parent is a clean integration of this exact head and main
5b85225ef39b9321d8f5c251ecb391b8331e8aea; both histories are retained. The scope registration releases the count and notifies drain waiters on every exit, reacquiring the lock when necessary. It preserves the existing exception rather than inventing an SDK error result. The commit also registers the Windows native allocation regression.Fresh Windows 11 build 26200 / GCC 16.2.0-6 UCRT64 / CMake 4.3.1 / Ninja 1.13.2 / Python 3.14.7 results:
WindowsTestExit.cppand SEH personality object: 1/1 passes, 0.15 s total, zero skips. This uses the actual committed regression file and production sources. It is an isolated registration check, not a full product configure/build.origin/main(the pinned main above), whitespace and the public-header audit pass (368 libraries, 12,223 exports). No new public export declarations are introduced.The isolated fixture's sole library adapter is
NotImplemented_nid_no_patchthrowingruntime_errorfor the existing unsupported-option tests. RUDP and TimedWait bodies are complete; neither waits nor the faulted allocations are replaced by fake implementations. The test keeps the failed wait's worker thread alive until cleanup, so its native wait-state object remains valid while checking the broken head.This repair covers exception cleanup. Marc's separate cancellation/late-arrival finding remains unresolved, and the linked 13.42 library report does not establish that arrival policy. No console/title, full product/DLL runtime, Linux/macOS runtime, performance or hosted-CI result is claimed. AI-assisted: yes.
Isolated native replay
Check out this PR head as
beforeand the support commit asafter. Save the CMake file below andSupport.cppin a fixture directory. Copyafter/core/libs/tests/RudpPollWaitAllocation.cppto that directory asFaultTest.cpp. With the GCC/CMake/Ninja binaries on PATH andAPS5_COARSE_TIMED_WAITSunset:The before run should fail only
rudp_wait_allocation_cleanup; the after run should pass all six. The production regression returns skip code 77 if coarse waits are explicitly enabled.CMakeLists.txt:Support.cpp:Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T01:06:59Z.
Review: COMMENTED
Linux run of the current head, since the description says Linux was not tested.
Machine: Linux x86_64, i7-8700 (6 cores / 12 threads, AVX2), Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON. Head4fe05b3bemerged ontomaincb45ae2dd.guest_rudp*tests pass, including #10954'sguest_rudp_empty_poll.guest_rudp_pollrelies on a 100 ms sleep before the cancel and a 500 ms bound on it, so I ran it repeatedly: 200 of 200 sequential runs, and 300 of 300 with 12 copies at a time on a loaded machine (25 rounds). No hang and no failed timing check.sceRudpPollCancel's body withNotImplemented_nid_no_patchand keeping the test aborts withsceRudpPollCancel not implemented.This does not cover the late-arrival and exception-cleanup cases raised above; the test does not exercise them.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T08:15:45Z.
Review: CHANGES_REQUESTED
Two real problems in
sceRudpPollWait/sceRudpPollCancelremain on this head (both also raised by @MarcZX10 and @thepoppfish):Export.cpp:538-544: Cancel drains untilpoll.waiters == 0, but asceRudpPollWaitthat arrives after the cancel starts snapshots the already-incrementedcancels(Export.cpp:458), blocks normally and keepswaitersabove 0, so Cancel can be held until that unrelated wait ends (forever for an infinite one). Cancel should only wait for the waiters that were inside the wait when it ran, e.g. give each wait a ticket and drain until no active ticket at or below the cancel's cutoff is left; late arrivals must not count.Export.cpp:459-482:++waitersis undone only on the normal return. IfTimedWaitthrows (first-use wait state allocation on Windows), the registration stays and every later Cancel on that poll never drains. Undo the registration on every exit path (a scope guard that re-finds the poll under the lock).Please add a test for each (a wait started after Cancel began must not extend it). The rest checked out: prototype and error values match the cited #10954 report, the debt entries split cleanly, and the new test fails on main (placeholder throws). Happy to look again once these are in.