fix(libc): unwind guest exceptions through Windows DLL frames #4511
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4511"
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 rebelittle on 2026-10-12T13:52:37Z.
What
On Windows, a guest exception could not cross a frame of a module without the project's
.ehmeta/.ehframtables: the libc unwinder found no FDE there and stopped, so the exception was reported as unhandled. WinLibs GCC 15.2'slibstdc++-6.dllandlibwinpthread-1.dllhave empty.eh_framesections and only PE unwind data, sostd::call_once(through__once_proxyandpthread_once) was enough to hit it. #3411 found this through thestd::call_oncetest of #1423; #3415 replaced that test with guest-only frames and recorded the gap in TechnicalDebt, and #3411 was closed with it.When
DecodeFramefinds no FDE and the frame's image has no.ehmetaor.ehframsection, the unwinder now looks up the frame'sRUNTIME_FUNCTION(RtlLookupFunctionEntry) and gets the caller's registers fromRtlVirtualUnwind, including the Windows nonvolatilersi,rdiandxmm6-xmm15thatLibcRestoreRegistersrestores. Such a frame has no personality, so both phases step through it. The fallback is limited to images without those sections, so a guest or project frame without an FDE still stops the walk as before.Windows exception and termination handlers are not run, so a frame whose unwind data has one (
RtlVirtualUnwindreturns its handler forUNW_FLAG_EHANDLER | UNW_FLAG_UHANDLER) still stops the walk, and the exception is reported as unhandled as it was before. In the WinLibs runtime DLLs and Windows 10'sucrtbase.dll:std::call_oncepathlibwinpthread-1.dllpthread_once: nonelibstdc++-6.dll__gxx_personality_seh0)__once_proxy: noneucrtbase.dllqsorthas one,bsearchnonewindows_exceptionsgets thestd::call_oncecase of #1423 back, next to the guest-frame case of #3415: an exception thrown in thestd::call_oncecallable is caught at depths 0, 1, 7 and 64, and every destructor on the way runs. The TechnicalDebt entry now describes the remaining gap (frames with handlers).Tested
Windows 10 22H2 (19045), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, based onmainc6efe068a:windows_exceptionswith the restored case: fails without the change ([libc] unhandled exception 'St13runtime_error' ... what(): through runtime frames), passes 3/3 with it.cteston an NVIDIA RTX 3090 (driver 610.47,ANYPS5_GPU=3090): 968 tests, 961 passed, 7 skipped (the video out tests without a display or Vulkan device, andagc_driver_stencil_ref_export, as this driver lacksVK_EXT_shader_stencil_export), 0 failed;tools/check_skips.py --job windowspasses.bsearchinucrtbase.dllthe exception is caught, where it was reported as unhandled without the change; throughqsort, whose frame has a handler, it is reported as unhandled as before._WIN32.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 in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T16:03:16Z.
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/prx/libc/src/exception/Unwind.cppL83-142docs/dev/TechnicalDebt.mdL485-486Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T16:27:21Z.
Windows test of head
74392900dmerged onto currentmain(2a5eca11c, clean merge; built together with two other open PRs, so the run is for the combination): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build 0 errors,-j2.windows_exceptions(the test this PR changes) passes. The 25 tests matching^(guest_memory|guest_np_auth|windows_exceptions|guest_exception|guest_kernel)all pass.Not checked: that the test fails without the change, Linux, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T16:31:34Z.
Windows test: head
74392900dmerged onto currentmain2a5eca11c(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterwindows_exception: windows_exceptions passed (1 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).