fix(libc): report host C++ exceptions that Windows cannot deliver #4693

Merged
EagleBearerYS merged 2 commits from upstream-pr/4693 into main 2026-10-14 05:04:39 +00:00
EagleBearerYS commented 2026-10-12 19:08:57 +00:00 (Migrated from github.com)

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 541541187 and nothing in run.log. That is 0x20474343, 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_alloc from operator new in libstdc++-6.dll, thrown while AgcDriver::Graphics::StorageTexture::upload resized its CPU copy (Texture.cpp), when the PC's commit limit was exhausted. The dispatcher walked KERNELBASE -> libgcc_s_seh-1 -> libstdc++-6 -> libSceAgcDriver.prx+0x2010de, which has no function entry. The libraries are built with -fno-asynchronous-unwind-tables and 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 no std::terminate runs, 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), with RtlLookupFunctionEntry and RtlVirtualUnwind. If the first frame outside them has no function entry, it prints

FATAL: C++ exception <type> raised on thread <n> cannot be delivered: <frame> has no unwind data

followed by the stack's return-address candidates. It then returns EXCEPTION_CONTINUE_SEARCH as before, so delivery is unchanged. An exception thrown into a frame that has unwind data prints nothing.

The type name comes from the __cxa_exception header in front of libgcc's unwind header. The header's class must be GNUCC++\0; on x86-64, exceptionType sits 80 bytes before the unwind header. Every pointer is read only after an IsReadable check.

The test, undeliverable_host_exception (Windows only), loads libc.prx and calls a function built with the libraries' flags. In that function, libstdc++'s operator new throws std::bad_alloc, and the test expects the FATAL line naming St9bad_alloc and 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, on main 2a5eca11c.

  • Without the fix: with main's CrashReport.cpp, undeliverable_host_exception fails. The test prints nothing and exits with 0x20474343, the game's silent exit reproduced.
  • With the fix: it passes.
  • Full suite: all 975 ctest tests pass. That build also had two unrelated libSceAgcDriver commits of mine.
  • Title: on a Planet of Lana test build carrying this commit, a run that ran out of memory printed FATAL: C++ exception St9bad_alloc raised on thread 5428 cannot be delivered: ... libSceAgcDriver.prx+0x20c193 has no unwind data instead of exiting silently.
  • python tools/check_conventions.py --base origin/main passes.

Not tested on Linux or macOS, where the change does not apply.

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 in TechnicalDebt (no unimplemented paths or stubs added)
  • 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 (no third-party code added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833868847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4693). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-12T19:08:57Z. --- ### What Planet of Lana (PPSA19450) sometimes ends during a save load with exit code `541541187` and nothing in `run.log`. That is `0x20474343`, `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_alloc` from `operator new` in `libstdc++-6.dll`, thrown while `AgcDriver::Graphics::StorageTexture::upload` resized its CPU copy (`Texture.cpp`), when the PC's commit limit was exhausted. The dispatcher walked `KERNELBASE` -> `libgcc_s_seh-1` -> `libstdc++-6` -> `libSceAgcDriver.prx+0x2010de`, which has no function entry. The libraries are built with `-fno-asynchronous-unwind-tables` and 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 no `std::terminate` runs, 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), with `RtlLookupFunctionEntry` and `RtlVirtualUnwind`. If the first frame outside them has no function entry, it prints ``` FATAL: C++ exception <type> raised on thread <n> cannot be delivered: <frame> has no unwind data ``` followed by the stack's return-address candidates. It then returns `EXCEPTION_CONTINUE_SEARCH` as before, so delivery is unchanged. An exception thrown into a frame that has unwind data prints nothing. The type name comes from the `__cxa_exception` header in front of libgcc's unwind header. The header's class must be `GNUCC++\0`; on x86-64, `exceptionType` sits 80 bytes before the unwind header. Every pointer is read only after an `IsReadable` check. The test, `undeliverable_host_exception` (Windows only), loads `libc.prx` and calls a function built with the libraries' flags. In that function, libstdc++'s `operator new` throws `std::bad_alloc`, and the test expects the FATAL line naming `St9bad_alloc` and 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`, on `main` 2a5eca11c. - **Without the fix:** with `main`'s `CrashReport.cpp`, `undeliverable_host_exception` fails. The test prints nothing and exits with `0x20474343`, the game's silent exit reproduced. - **With the fix:** it passes. - **Full suite:** all 975 ctest tests pass. That build also had two unrelated libSceAgcDriver commits of mine. - **Title:** on a Planet of Lana test build carrying this commit, a run that ran out of memory printed `FATAL: C++ exception St9bad_alloc raised on thread 5428 cannot be delivered: ... libSceAgcDriver.prx+0x20c193 has no unwind data` instead of exiting silently. - `python tools/check_conventions.py --base origin/main` passes. Not tested on Linux or macOS, where the change does not apply. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (no unimplemented paths or stubs added) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (no third-party code added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-12 19:21:34 +00:00 (Migrated from github.com)

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 259

@@ -223,6 +225,47 @@ void TraceSse4a(std::uint64_t rip, const sse4a::Instruction& instruction, const
     Report("[sse4a] #%llu %s %s (length %u, index %u, %u bytes) at %s on thread %lu\n", count, mnemonic, operands, field.length, field.index, static_cast<unsigned>(instruction.size), line, GetCurrentThreadId());
 }
 
+constexpr DWORD GccExceptionMask = 0x20ffffffu;
+constexpr DWORD GccException = 0x20474343u;
+constexpr std::uint64_t GccExceptionClass = 0x474e5543432b2b00ull;
+constexpr std::uint64_t CxaExceptionTypeOffset = 80;
+
+std::uint64_t FrameWithoutUnwindData(const CONTEXT& start) {
+    const HMODULE runtime[] = {GetModuleHandleA("KERNELBASE.dll"), GetModuleHandleA("libgcc_s_seh-1.dll"), GetModuleHandleA("libstdc++-6.dll")};
+    CONTEXT context = start;
+    for (int depth = 0; depth < 64 && context.Rip != 0; ++depth) {
+        HMODULE module = nullptr;
+        GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(context.Rip), &module);
+        DWORD64 imageBase = 0;
+        const auto entry = RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr);
+        if (module == nullptr || std::find(std::begin(runtime), std::end(runtime), module) == std::end(runtime)) return entry == nullptr ? context.Rip : 0;
+        if (entry == nullptr) return 0;
+        PVOID handlerData = nullptr;
+        DWORD64 establisher = 0;
+        RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, context.Rip, entry, &context, &handlerData, &establisher, nullptr);
+    }
+    return 0;
+}
+
+void ReportUndeliverableException(const EXCEPTION_POINTERS* info, std::uint64_t frame) {
+    const auto* record = info->ExceptionRecord;
+    char type[256] = "of unknown type";
+    if (record->NumberParameters >= 1) {
+        const auto header = static_cast<std::uint64_t>(record->ExceptionInformation[0]);
+        if (IsReadable(header) && IsReadable(header - CxaExceptionTypeOffset) && *reinterpret_cast<const std::uint64_t*>(header) == GccExceptionClass) {
+            const auto typeInfo = *reinterpret_cast<const std::uint64_t*>(header - CxaExceptionTypeOffset);
+            if (IsReadable(typeInfo) && IsReadable(typeInfo + 8)) {
+                const auto name = *reinterpret_cast<const std::uint64_t*>(typeInfo + 8);
+                if (IsReadable(name)) std::snprintf(type, sizeof(type), "%s", reinterpret_cast<const char*>(name));

IsReadable(name) only verifies the memory region containing the first byte. %s then 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 to unknown type if no terminator is found?

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251571370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4693#discussion_r4251571370). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:21:34Z. **Code review location:** `core/libs/prx/libc/src/specifics/windows/CrashReport.cpp`; line 259 ~~~~diff @@ -223,6 +225,47 @@ void TraceSse4a(std::uint64_t rip, const sse4a::Instruction& instruction, const Report("[sse4a] #%llu %s %s (length %u, index %u, %u bytes) at %s on thread %lu\n", count, mnemonic, operands, field.length, field.index, static_cast<unsigned>(instruction.size), line, GetCurrentThreadId()); } +constexpr DWORD GccExceptionMask = 0x20ffffffu; +constexpr DWORD GccException = 0x20474343u; +constexpr std::uint64_t GccExceptionClass = 0x474e5543432b2b00ull; +constexpr std::uint64_t CxaExceptionTypeOffset = 80; + +std::uint64_t FrameWithoutUnwindData(const CONTEXT& start) { + const HMODULE runtime[] = {GetModuleHandleA("KERNELBASE.dll"), GetModuleHandleA("libgcc_s_seh-1.dll"), GetModuleHandleA("libstdc++-6.dll")}; + CONTEXT context = start; + for (int depth = 0; depth < 64 && context.Rip != 0; ++depth) { + HMODULE module = nullptr; + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(context.Rip), &module); + DWORD64 imageBase = 0; + const auto entry = RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr); + if (module == nullptr || std::find(std::begin(runtime), std::end(runtime), module) == std::end(runtime)) return entry == nullptr ? context.Rip : 0; + if (entry == nullptr) return 0; + PVOID handlerData = nullptr; + DWORD64 establisher = 0; + RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, context.Rip, entry, &context, &handlerData, &establisher, nullptr); + } + return 0; +} + +void ReportUndeliverableException(const EXCEPTION_POINTERS* info, std::uint64_t frame) { + const auto* record = info->ExceptionRecord; + char type[256] = "of unknown type"; + if (record->NumberParameters >= 1) { + const auto header = static_cast<std::uint64_t>(record->ExceptionInformation[0]); + if (IsReadable(header) && IsReadable(header - CxaExceptionTypeOffset) && *reinterpret_cast<const std::uint64_t*>(header) == GccExceptionClass) { + const auto typeInfo = *reinterpret_cast<const std::uint64_t*>(header - CxaExceptionTypeOffset); + if (IsReadable(typeInfo) && IsReadable(typeInfo + 8)) { + const auto name = *reinterpret_cast<const std::uint64_t*>(typeInfo + 8); + if (IsReadable(name)) std::snprintf(type, sizeof(type), "%s", reinterpret_cast<const char*>(name)); ~~~~ --- `IsReadable(name)` only verifies the memory region containing the first byte. `%s` then 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 to `unknown type` if no terminator is found?
EagleBearerYS commented 2026-10-12 19:34:58 +00:00 (Migrated from github.com)

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 259

@@ -223,6 +225,47 @@ void TraceSse4a(std::uint64_t rip, const sse4a::Instruction& instruction, const
     Report("[sse4a] #%llu %s %s (length %u, index %u, %u bytes) at %s on thread %lu\n", count, mnemonic, operands, field.length, field.index, static_cast<unsigned>(instruction.size), line, GetCurrentThreadId());
 }
 
+constexpr DWORD GccExceptionMask = 0x20ffffffu;
+constexpr DWORD GccException = 0x20474343u;
+constexpr std::uint64_t GccExceptionClass = 0x474e5543432b2b00ull;
+constexpr std::uint64_t CxaExceptionTypeOffset = 80;
+
+std::uint64_t FrameWithoutUnwindData(const CONTEXT& start) {
+    const HMODULE runtime[] = {GetModuleHandleA("KERNELBASE.dll"), GetModuleHandleA("libgcc_s_seh-1.dll"), GetModuleHandleA("libstdc++-6.dll")};
+    CONTEXT context = start;
+    for (int depth = 0; depth < 64 && context.Rip != 0; ++depth) {
+        HMODULE module = nullptr;
+        GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(context.Rip), &module);
+        DWORD64 imageBase = 0;
+        const auto entry = RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr);
+        if (module == nullptr || std::find(std::begin(runtime), std::end(runtime), module) == std::end(runtime)) return entry == nullptr ? context.Rip : 0;
+        if (entry == nullptr) return 0;
+        PVOID handlerData = nullptr;
+        DWORD64 establisher = 0;
+        RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, context.Rip, entry, &context, &handlerData, &establisher, nullptr);
+    }
+    return 0;
+}
+
+void ReportUndeliverableException(const EXCEPTION_POINTERS* info, std::uint64_t frame) {
+    const auto* record = info->ExceptionRecord;
+    char type[256] = "of unknown type";
+    if (record->NumberParameters >= 1) {
+        const auto header = static_cast<std::uint64_t>(record->ExceptionInformation[0]);
+        if (IsReadable(header) && IsReadable(header - CxaExceptionTypeOffset) && *reinterpret_cast<const std::uint64_t*>(header) == GccExceptionClass) {
+            const auto typeInfo = *reinterpret_cast<const std::uint64_t*>(header - CxaExceptionTypeOffset);
+            if (IsReadable(typeInfo) && IsReadable(typeInfo + 8)) {
+                const auto name = *reinterpret_cast<const std::uint64_t*>(typeInfo + 8);
+                if (IsReadable(name)) std::snprintf(type, sizeof(type), "%s", reinterpret_cast<const char*>(name));

Good catch, thanks. 6a9781cdc reads all of the metadata through ReadCode, which stops at the first unreadable page and at the requested size: the exception class, the type_info pointer 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 keeps of unknown type. undeliverable_host_exception, guest_exception_handler and patched_libraries pass 3 runs in a row, and the FATAL line still names St9bad_alloc.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251668500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4693#discussion_r4251668500). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-12T19:34:58Z. **Code review location:** `core/libs/prx/libc/src/specifics/windows/CrashReport.cpp`; line 259 ~~~~diff @@ -223,6 +225,47 @@ void TraceSse4a(std::uint64_t rip, const sse4a::Instruction& instruction, const Report("[sse4a] #%llu %s %s (length %u, index %u, %u bytes) at %s on thread %lu\n", count, mnemonic, operands, field.length, field.index, static_cast<unsigned>(instruction.size), line, GetCurrentThreadId()); } +constexpr DWORD GccExceptionMask = 0x20ffffffu; +constexpr DWORD GccException = 0x20474343u; +constexpr std::uint64_t GccExceptionClass = 0x474e5543432b2b00ull; +constexpr std::uint64_t CxaExceptionTypeOffset = 80; + +std::uint64_t FrameWithoutUnwindData(const CONTEXT& start) { + const HMODULE runtime[] = {GetModuleHandleA("KERNELBASE.dll"), GetModuleHandleA("libgcc_s_seh-1.dll"), GetModuleHandleA("libstdc++-6.dll")}; + CONTEXT context = start; + for (int depth = 0; depth < 64 && context.Rip != 0; ++depth) { + HMODULE module = nullptr; + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(context.Rip), &module); + DWORD64 imageBase = 0; + const auto entry = RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr); + if (module == nullptr || std::find(std::begin(runtime), std::end(runtime), module) == std::end(runtime)) return entry == nullptr ? context.Rip : 0; + if (entry == nullptr) return 0; + PVOID handlerData = nullptr; + DWORD64 establisher = 0; + RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, context.Rip, entry, &context, &handlerData, &establisher, nullptr); + } + return 0; +} + +void ReportUndeliverableException(const EXCEPTION_POINTERS* info, std::uint64_t frame) { + const auto* record = info->ExceptionRecord; + char type[256] = "of unknown type"; + if (record->NumberParameters >= 1) { + const auto header = static_cast<std::uint64_t>(record->ExceptionInformation[0]); + if (IsReadable(header) && IsReadable(header - CxaExceptionTypeOffset) && *reinterpret_cast<const std::uint64_t*>(header) == GccExceptionClass) { + const auto typeInfo = *reinterpret_cast<const std::uint64_t*>(header - CxaExceptionTypeOffset); + if (IsReadable(typeInfo) && IsReadable(typeInfo + 8)) { + const auto name = *reinterpret_cast<const std::uint64_t*>(typeInfo + 8); + if (IsReadable(name)) std::snprintf(type, sizeof(type), "%s", reinterpret_cast<const char*>(name)); ~~~~ --- Good catch, thanks. 6a9781cdc reads all of the metadata through `ReadCode`, which stops at the first unreadable page and at the requested size: the exception class, the `type_info` pointer 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 keeps `of unknown type`. `undeliverable_host_exception`, `guest_exception_handler` and `patched_libraries` pass 3 runs in a row, and the FATAL line still names `St9bad_alloc`.
MarcZX10 commented 2026-10-12 19:35:44 +00:00 (Migrated from github.com)

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 259

@@ -223,6 +225,47 @@ void TraceSse4a(std::uint64_t rip, const sse4a::Instruction& instruction, const
     Report("[sse4a] #%llu %s %s (length %u, index %u, %u bytes) at %s on thread %lu\n", count, mnemonic, operands, field.length, field.index, static_cast<unsigned>(instruction.size), line, GetCurrentThreadId());
 }
 
+constexpr DWORD GccExceptionMask = 0x20ffffffu;
+constexpr DWORD GccException = 0x20474343u;
+constexpr std::uint64_t GccExceptionClass = 0x474e5543432b2b00ull;
+constexpr std::uint64_t CxaExceptionTypeOffset = 80;
+
+std::uint64_t FrameWithoutUnwindData(const CONTEXT& start) {
+    const HMODULE runtime[] = {GetModuleHandleA("KERNELBASE.dll"), GetModuleHandleA("libgcc_s_seh-1.dll"), GetModuleHandleA("libstdc++-6.dll")};
+    CONTEXT context = start;
+    for (int depth = 0; depth < 64 && context.Rip != 0; ++depth) {
+        HMODULE module = nullptr;
+        GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(context.Rip), &module);
+        DWORD64 imageBase = 0;
+        const auto entry = RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr);
+        if (module == nullptr || std::find(std::begin(runtime), std::end(runtime), module) == std::end(runtime)) return entry == nullptr ? context.Rip : 0;
+        if (entry == nullptr) return 0;
+        PVOID handlerData = nullptr;
+        DWORD64 establisher = 0;
+        RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, context.Rip, entry, &context, &handlerData, &establisher, nullptr);
+    }
+    return 0;
+}
+
+void ReportUndeliverableException(const EXCEPTION_POINTERS* info, std::uint64_t frame) {
+    const auto* record = info->ExceptionRecord;
+    char type[256] = "of unknown type";
+    if (record->NumberParameters >= 1) {
+        const auto header = static_cast<std::uint64_t>(record->ExceptionInformation[0]);
+        if (IsReadable(header) && IsReadable(header - CxaExceptionTypeOffset) && *reinterpret_cast<const std::uint64_t*>(header) == GccExceptionClass) {
+            const auto typeInfo = *reinterpret_cast<const std::uint64_t*>(header - CxaExceptionTypeOffset);
+            if (IsReadable(typeInfo) && IsReadable(typeInfo + 8)) {
+                const auto name = *reinterpret_cast<const std::uint64_t*>(typeInfo + 8);
+                if (IsReadable(name)) std::snprintf(type, sizeof(type), "%s", reinterpret_cast<const char*>(name));

Thanks 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4251673876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4693#discussion_r4251673876). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:35:44Z. **Code review location:** `core/libs/prx/libc/src/specifics/windows/CrashReport.cpp`; line 259 ~~~~diff @@ -223,6 +225,47 @@ void TraceSse4a(std::uint64_t rip, const sse4a::Instruction& instruction, const Report("[sse4a] #%llu %s %s (length %u, index %u, %u bytes) at %s on thread %lu\n", count, mnemonic, operands, field.length, field.index, static_cast<unsigned>(instruction.size), line, GetCurrentThreadId()); } +constexpr DWORD GccExceptionMask = 0x20ffffffu; +constexpr DWORD GccException = 0x20474343u; +constexpr std::uint64_t GccExceptionClass = 0x474e5543432b2b00ull; +constexpr std::uint64_t CxaExceptionTypeOffset = 80; + +std::uint64_t FrameWithoutUnwindData(const CONTEXT& start) { + const HMODULE runtime[] = {GetModuleHandleA("KERNELBASE.dll"), GetModuleHandleA("libgcc_s_seh-1.dll"), GetModuleHandleA("libstdc++-6.dll")}; + CONTEXT context = start; + for (int depth = 0; depth < 64 && context.Rip != 0; ++depth) { + HMODULE module = nullptr; + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCSTR>(context.Rip), &module); + DWORD64 imageBase = 0; + const auto entry = RtlLookupFunctionEntry(context.Rip, &imageBase, nullptr); + if (module == nullptr || std::find(std::begin(runtime), std::end(runtime), module) == std::end(runtime)) return entry == nullptr ? context.Rip : 0; + if (entry == nullptr) return 0; + PVOID handlerData = nullptr; + DWORD64 establisher = 0; + RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, context.Rip, entry, &context, &handlerData, &establisher, nullptr); + } + return 0; +} + +void ReportUndeliverableException(const EXCEPTION_POINTERS* info, std::uint64_t frame) { + const auto* record = info->ExceptionRecord; + char type[256] = "of unknown type"; + if (record->NumberParameters >= 1) { + const auto header = static_cast<std::uint64_t>(record->ExceptionInformation[0]); + if (IsReadable(header) && IsReadable(header - CxaExceptionTypeOffset) && *reinterpret_cast<const std::uint64_t*>(header) == GccExceptionClass) { + const auto typeInfo = *reinterpret_cast<const std::uint64_t*>(header - CxaExceptionTypeOffset); + if (IsReadable(typeInfo) && IsReadable(typeInfo + 8)) { + const auto name = *reinterpret_cast<const std::uint64_t*>(typeInfo + 8); + if (IsReadable(name)) std::snprintf(type, sizeof(type), "%s", reinterpret_cast<const char*>(name)); ~~~~ --- Thanks 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.
adriadam10 commented 2026-10-13 15:00:45 +00:00 (Migrated from github.com)

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 bounded ReadCode calls, and still returns EXCEPTION_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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148518259 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4693#issuecomment-6148518259). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T15:00:45Z. --- Reviewed the diff: the GCC exception walk only runs for `0x20474343`-family codes, reads all metadata through bounded `ReadCode` calls, and still returns `EXCEPTION_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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4693
No description provided.