sceKernelRaiseException is lost for a target that busy-waits in short sceKernelUsleep calls (Windows) #12131
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 2Swagger on 2026-10-27T22:31:43Z.
What happens
On Windows,
sceKernelRaiseExceptionreturns 0, but the handler never runs: the target keeps running (its loop counter keepsadvancing) and no delivery arrives within 3 s. The first one or two raises usually arrive; a later one is lost.
It happens when the target spends almost all its time in host code with
waitCount == 0, as a thread looping onsceKernelUsleep(200)does: on Windows a sleep under TimedWait's 0.5 msLEAD_NANOSbusy-waits inSleepUntil(
YieldProcessorloop) rather than an alertable wait, so the raise takes the host-code path added in #10666.Repro
Windows 11, WinLibs GCC 15.2.0, Release, Intel i5-10500H; main
f5fefb982.core/libs/tests/GuestRaiseLostRepro.cppand register it in the Windows-only test block ofcore/libs/prx/libkernel/CMakeLists.txtlikeguest_raise_in_host_code(TIMEOUT 60, libkernel on PATH):cmake --build build --target guest_raise_lost_repro_testsandctest --test-dir build -R ^guest_raise_lost_repro$ --output-on-failure.Results
f5fefb982(with #10666): 5 of 5 runs fail after about 3 s withLOST delivery in round 0orround 1(worker progress about 14,700-14,800, still advancing).
273c8c256before merging: 5 of 5 runs fail the same way.a120df348, before #10666 merged: 5 of 5 runs deliver all 200 (15.7-20.3 s, about 80 ms per raise: the old"redirect in host code after the 50 ms limit" behaviour #10666 removed as unsafe).
What it affects
guest_raise_in_host_codeandguest_raise_leaves_host_codepass, and use targets thatreturn to guest code from longer or alertable waits.
case #10666 fixed) raises at every thread and waits for all acknowledgements, so a lost delivery there would hang the
stop; not observed on a title yet.
Best guess at the cause (unverified)
With the target in host code and
waitCount == 0, delivery depends on the return-address breakpoint (DR0) firing at thereturn into guest code, with the deliverer thread's sampling as a fallback. The target is in guest code for only a few
nanoseconds per 200 us, so sampling essentially never sees it there. A lost delivery therefore means the breakpoint did
not fire or was declined: either
ArmReturnBreak/UnwindToGuestdid not arm it from the busy-wait frames (unwind stoppedor the return site was rejected), or
ReturnBreakHandlerdeclined the hit (the review of #10666 noted it "can decline theDR0 hit when neither the live entry nor the remembered ..." and saw 3 of 300
STATUS_SINGLE_STEPexits). A next step:log
SetReturnBreak's result, whether DR0 is set after arming, and whetherReturnBreakHandlersees the hit, for thelost round.
Regression introduced by #10666 (@WallisSkill): main before it delivered all 200 raises, main after it loses them.
Found while testing pthread_suspend_np, which does not use this path.