fix(libkernel): defer raises while a thread holds the address-wait lock on Windows #5756
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5756"
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 oneandonlydean on 2026-10-14T09:35:29Z.
What
Fixes #1488. On Windows,
sceKernelRaiseExceptionredirects a thread wherever it was stopped. A thread stopped insidesceKernelSyncOnAddressWake,sceKernelSyncOnAddressWaitor_umtx_opwhile it held the address-wait lock ran the handler with the lock held, so a handler that waits, as a stop-the-world GC handler does, blocked every other thread that waits on or wakes an address. After #1562, LeandroLP23's reproducer in #1488 still blocked 35 of 300 rounds, all insidesceKernelSyncOnAddressWake.The address-wait lock is now taken under the
DeliveryDeferralthat the guest mutex park queues already use (#5429): while it is held the thread's wait count is raised, so a raise queues an APC instead of redirecting the thread. The APC runs in the condition wait, where the lock is released, or after the lock is released on the way out of the call, before it returns to the guest. Nothing is delivered from inside the unlock or between the condition's enqueue and its wait (the points raised in the #4888 review).DeliveryDeferralandDeliverDeferredmove fromTimedWait.cppintoTimedWait.hppfor this.Linux is unchanged: delivery there runs in the target's SIGUSR1 handler and the debt entry for it stays. Other emulator locks can take the same deferral when a case shows up. The Windows
sceKernelRaiseExceptionentry indocs/dev/debt/libkernel.mdnow names the deferred locks.Tested
guest_raise_exception: a guest thread loops onsceKernelSyncOnAddressWake, or on a 20 µssceKernelSyncOnAddressWait; for 100 rounds each the test raises at it, holds the handler, and requires a wake on another address from another thread to return within 500 ms.guest_raise_exceptionpasses on Windows). Test without the fix:guest_raise_exceptionfails on Windows in run 38543474956 (completed failure).ctestexceptagc_driver*: 724 of 724 (6 VideoOut tests skipped, no display). The new phases are Windows only.tools/check_conventions.pyandtools/check_test_registration.pypass.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T09:40:58Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/tests/GuestRaiseException.cppL662