Skip to content

fix(libkernel): treat a raise target that is already terminating as exited on Windows - #12069

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
dantdmdarealguy:fix/raise-terminating-target-windows
Oct 28, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
dantdmdarealguy:fix/raise-terminating-target-windows

Conversation

@dantdmdarealguy

Copy link
Copy Markdown
Contributor

What

guest_raise_exception fails intermittently on Windows CI on current main. Every failure aborts at the same place, Exception.cpp:700:

[exception] signal 0x1e: sceKernelRaiseException: cannot suspend the target thread
FATAL: abort() (SIGABRT) on thread 8624

It failed in 9 of the 193 Windows jobs of build.yml runs on main on 2026-10-27, including two runs on 2ee8e9751a (jobs 122272870002 and 122272290778). It failed in none of the 114 Windows jobs on 2026-10-26. The jobs that passed ran the same commits as the failing ones.

Since #10666 (1b9c5feb30), a raise whose target is in host code is handed to a background deliverer. The deliverer sweeps the target with TryDeliver until the handler is taken or the thread exits. Each sweep starts with SuspendThread. When that fails, TryDeliver only counts the target as gone if its handle is already signaled; otherwise it throws, and the deliverer aborts the process.

A thread that has begun to exit sits in a window where SuspendThread already fails with ERROR_ACCESS_DENIED (NtSuspendThread returns STATUS_THREAD_IS_TERMINATING, 0xC000004B), but its handle is not signaled yet and GetExitCodeThread still returns STILL_ACTIVE. A standalone probe on Windows 11 measured this: 20,000 threads, each suspended in a loop while it returned. 9,977 SuspendThread failures (all GetLastError 5) and 9,973 NtSuspendThread failures (all 0xC000004B) came before the handle was signaled. Every handle was signaled shortly afterwards.

guest_raise_exception hits the window when a thread it raised at exits while the deliverer still has that raise in its sweep list. For example, the handler was delivered at the thread's return breakpoint, and the test stopped and joined the thread before the next sweep retired the raise.

TryDeliver now suspends through NtSuspendThread. It takes STATUS_THREAD_IS_TERMINATING as Attempt::Exited, which is what it already did for a signaled handle: the deliverer drops the raise, and a direct sceKernelRaiseException returns ESRCH. Any other suspend failure still throws. DisarmReturnBreak already tolerated a failed suspend and is unchanged.

guest_raise_exiting_thread (new, Windows) reproduces the abort directly. In each of 100 rounds it starts 32 guest threads that block in a host WaitForSingleObject, raises SIGUSR1 at each (so every raise goes to the deliverer), then releases them all and joins them. Every raise must return 0 and the process must not abort. It takes about 0.4 s.

Closed #1802 (October 9) handled the same Windows behaviour in the code from before the deliverer, as part of a larger change. It was closed because no title hit the race and its branch merged other pull requests. The race now fails main's Windows CI, through a path #10666 added.

This is separate from #11813 and #12005. #11813 is the address waking round N: the handler did not run within 5 s abort of the same test, and #12005 speeds up delivery to busy host-code targets. Neither touches the suspend failure. This change neither depends on #12005 nor overlaps its lines.

Tested

Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON, SDL_AUDIODRIVER=dummy, on main 2ee8e9751a.

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, some AI assistance was used

…xited on Windows

SuspendThread fails with STATUS_THREAD_IS_TERMINATING for a thread that
has begun to exit while its handle is not signaled yet. TryDeliver took
only the signaled handle as an exit, so the raise deliverer, which keeps
sweeping a target in host code until delivery or exit, threw "cannot
suspend the target thread" and aborted the process when that target
exited in between. The suspension now reads the NTSTATUS from
NtSuspendThread and treats a terminating target as exited; other
failures still throw.

guest_raise_exiting_thread raises at 32 threads per round that block in
a host wait and exit after it, for 100 rounds.
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4563 core/libs/prx/libkernel/CMakeLists.txt
PR 4630 core/libs/prx/libkernel/System/src/Exception.cpp
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/System/src/Exception.cpp
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/System/src/Exception.cpp
PR 8592 core/libs/prx/libkernel/System/src/Exception.cpp
PR 9019 core/libs/prx/libkernel/CMakeLists.txt
PR 9156 core/libs/prx/libkernel/CMakeLists.txt
PR 9284 core/libs/prx/libkernel/CMakeLists.txt
PR 9293 core/libs/prx/libkernel/CMakeLists.txt
PR 9297 core/libs/prx/libkernel/CMakeLists.txt
PR 9302 core/libs/prx/libkernel/CMakeLists.txt
PR 9383 core/libs/prx/libkernel/CMakeLists.txt
PR 9389 core/libs/prx/libkernel/CMakeLists.txt
PR 9557 core/libs/prx/libkernel/CMakeLists.txt
PR 9566 core/libs/prx/libkernel/CMakeLists.txt
PR 9575 core/libs/prx/libkernel/CMakeLists.txt
PR 11002 core/libs/prx/libkernel/CMakeLists.txt
PR 11625 core/libs/prx/libkernel/CMakeLists.txt
PR 11969 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/System/src/Exception.cpp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status handling is consistent with NTSTATUS semantics: STATUS_THREAD_IS_TERMINATING is classified as an exited target, while other failed suspends still require a signaled handle or remain errors. The Windows stress test raises at 32 blocked guest threads over 100 release rounds; the reported 100/100 baseline aborts and 0/100 changed runs directly exercise the race, with additional repeated/concurrent runs reported. I checked the exact-head diff, current-main merge preview, check_conventions.py, and git diff --check.

The hosted Windows job is green but did not run this test: its changed-test selection, libs build, and CTest steps were skipped. This approval relies on the detailed Windows 11 build and repeated test results recorded by the author; I could not independently execute this Windows-only test in the Linux environment.

@B-Howell

Copy link
Copy Markdown
Contributor

Independent Windows run on AMD, with a control.

Setup: Windows 11 Pro 26300, AMD Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON, libs rebuilt. Head 95a785104ca651d759c191c127637ec8268f43db merged onto main cccdaa2734a71d27e6c907325c60fdf2d3baf0af (clean).

Test: ctest -R '^guest_raise_exiting_thread$' --repeat until-fail:20

  • PR merged onto main: passes all 20 runs (0.65 to 0.8 s each).
  • Control: core/libs/prx/libkernel/System/src/Exception.cpp restored from main, test kept: aborts (0xc0000409) on the first run. A rerun of the control build prints ...KernelRaiseException: cannot suspend the target thread, the CI signature from the description.

Not tested: the other guest_raise_* tests on this head, Linux and macOS (Windows-only path), any title.

AI-assisted (Claude Code).

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@oneandonlydean
oneandonlydean merged commit e4a00a5 into boykopovar:main Oct 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants