fix(libc): report host C++ exceptions that Windows cannot deliver #4693
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4693"
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 EagleBearerYS on 2026-10-12T19:08:57Z.
What
Planet of Lana (PPSA19450) sometimes ends during a save load with exit code
541541187and nothing inrun.log. That is0x20474343,STATUS_GCC_THROW: libgcc raises C++ exceptions from the MinGW runtime DLLs as SEH exceptions, and the system dispatcher delivers them by unwinding frame by frame with each function's unwind data.A local diagnostic named the exception:
std::bad_allocfromoperator newinlibstdc++-6.dll, thrown whileAgcDriver::Graphics::StorageTexture::uploadresized its CPU copy (Texture.cpp), when the PC's commit limit was exhausted. The dispatcher walkedKERNELBASE->libgcc_s_seh-1->libstdc++-6->libSceAgcDriver.prx+0x2010de, which has no function entry. The libraries are built with-fno-asynchronous-unwind-tablesand unwind with DWARF, so their functions have no SEH unwind data. Windows cannot unwind past such a frame. No handler, no unhandled-exception filter and nostd::terminateruns, and the process ends without output.The vectored crash handler (
ReportCrash,CrashReport.cpp) now follows a GCC exception through the runtime frames that raise it (KERNELBASE.dll,libgcc_s_seh-1.dll,libstdc++-6.dll, matched by module handle), withRtlLookupFunctionEntryandRtlVirtualUnwind. If the first frame outside them has no function entry, it printsfollowed by the stack's return-address candidates. It then returns
EXCEPTION_CONTINUE_SEARCHas before, so delivery is unchanged. An exception thrown into a frame that has unwind data prints nothing.The type name comes from the
__cxa_exceptionheader in front of libgcc's unwind header. The header's class must beGNUCC++\0; on x86-64,exceptionTypesits 80 bytes before the unwind header. Every pointer is read only after anIsReadablecheck.The test,
undeliverable_host_exception(Windows only), loadslibc.prxand calls a function built with the libraries' flags. In that function, libstdc++'soperator newthrowsstd::bad_alloc, and the test expects the FATAL line namingSt9bad_allocand that function's frame.#4511 is related but doesn't overlap: it lets guest exceptions unwind through Windows DLL frames, while this reports host exceptions that cannot unwind through AnyPS5 frames.
Tested
Windows 11 Home (10.0.26300), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
BUILD_TESTING=ON, onmain2a5eca11c.main'sCrashReport.cpp,undeliverable_host_exceptionfails. The test prints nothing and exits with0x20474343, the game's silent exit reproduced.FATAL: C++ exception St9bad_alloc raised on thread 5428 cannot be delivered: ... libSceAgcDriver.prx+0x20c193 has no unwind datainstead of exiting silently.python tools/check_conventions.py --base origin/mainpasses.Not tested on Linux or macOS, where the change does not apply.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (no unimplemented paths or stubs added).mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:21:34Z.
Code review location:
core/libs/prx/libc/src/specifics/windows/CrashReport.cpp; line 259IsReadable(name)only verifies the memory region containing the first byte.%sthen scans until a NUL with no bound or page checks; if the RTTI name is truncated at an unreadable page (or the exception metadata is damaged), this crash handler can itself access-violate while trying to report the original exception. Could the name be copied through a bounded readable-memory helper, falling back tounknown typeif no terminator is found?Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-12T19:34:58Z.
Code review location:
core/libs/prx/libc/src/specifics/windows/CrashReport.cpp; line 259Good catch, thanks.
6a9781cdcreads all of the metadata throughReadCode, which stops at the first unreadable page and at the requested size: the exception class, thetype_infopointer and the name pointer as 8-byte reads, then the name into a 256-byte buffer. The name is used only if that copy holds its terminator; otherwise the report keepsof unknown type.undeliverable_host_exception,guest_exception_handlerandpatched_librariespass 3 runs in a row, and the FATAL line still namesSt9bad_alloc.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:35:44Z.
Code review location:
core/libs/prx/libc/src/specifics/windows/CrashReport.cpp; line 259Thanks for the bounded metadata reads and the regression test. I checked the updated path: the name is capped at 256 bytes and only replaces the fallback when the copied bytes include a NUL terminator. That resolves my concern.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:00:45Z.
Reviewed the diff: the GCC exception walk only runs for
0x20474343-family codes, reads all metadata through boundedReadCodecalls, and still returnsEXCEPTION_CONTINUE_SEARCH, so delivery is unchanged. The new test is registered in ctest and gets the same unwind-table flags as the libraries. Linux build and ctest are green (change does not apply there); the Windows job of the full Build decides the merge. Merging once it is green.