Windows: exceptions raised inside libstdc++-6.dll (regex_error, filesystem_error, …) can't reach AnyPS5 catch sites #25728

Closed
opened 2026-11-22 15:45:20 +00:00 by JJenkx · 0 comments
JJenkx commented 2026-11-22 15:45:20 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-22T15:45:20Z.


On Windows, an exception that is raised inside libstdc++-6.dll isn't delivered to a catch in AnyPS5 code, even when the catch is one frame up. The process aborts with:

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

I hit this twice on 2026-11-22. In both cases the code was correct C++ and works on Linux.

1. libSceNKWebKit.prx (#25548, head a2e45c2255). ParsePredicate in src/JscConfigFile.cpp wraps std::regex::assign in catch (const std::regex_error&). On an invalid pattern, nkwebkit_jscconfigfile aborts in every run, locally and in Windows CI. Stack, innermost first: libstdc++-6.dll (__throw_regex_error) → libgcc_s_seh-1.dll → KERNELBASE!RaiseException; the first non-runtime frame is libSceNKWebKit.prx+0x2c829e.

2. A host tool executable (#25559, head 9acd199d07). agc_pipeline_journal_replay's main was a try { … } catch (const std::exception&). Under ANSI code page 1252, a Cyrillic path argument made std::filesystem::exists throw filesystem_error from inside the libstdc++ DLL, and the process aborted with the same message instead of reaching the catch. (That PR has since switched to wmain, so the throw no longer happens there.)

Why: AnyPS5's own throws go through the libc Windows exception unwinder, which reads the DWARF unwind data that configure_windows_unwind keeps in .ehfram. An exception raised by libstdc++-6.dll goes through libgcc_s_seh and Windows SEH dispatch instead, which needs .pdata for each frame. Project modules have almost none: libSceNKWebKit.prx has 0x5d0 bytes of .pdata for 3.4 MB of .text. The dispatch stops at the first project frame. docs/dev/debt/libc.md already documents the reverse case: a handler in an unmarked module such as libstdc++-6.dll stops an AnyPS5 unwind. This report is about exceptions thrown from inside that module.

Possible scope, not verified one by one. On main, non-test code under core/libs/prx has catch sites for exception types that, in practice, only libstdc++ raises:

Type catch sites
std::filesystem::filesystem_error 18 (libc Filesystem.cpp, General.cpp, RealPath.cpp, Rename.cpp, FileAndHeap.cpp; libkernel SharedMemory.cpp, DynamicLoader.cpp; libSceSaveData.native; libSceContentExport)
std::bad_alloc 143 (operator new lives in the libstdc++ DLL)
std::system_error 21

There is also std::stoull in libc/src/GuestAllocations.cpp:141. A site is only affected if its try block reaches a throwing libstdc++ call, such as a non-error_code filesystem overload or allocation failure. Many may never do so. Each of these needs checking against the actual calls; this list is candidates only.

Directions, none tried:

  • in library code, prefer non-throwing forms: error_code filesystem overloads, std::nothrow allocation, std::from_chars, and a non-throwing regex engine such as ICU uregex_*;
  • or have the libc Windows exception filter recognise a GCC exception raised in libstdc++-6.dll and hand it to its own DWARF unwinder, the way it delivers AnyPS5 throws;
  • or link libstdc++ statically into the modules that catch its exceptions, so the throwing code is covered by the module's own unwind data. I haven't checked how that interacts with the guest personalities.

Setup for both reproductions: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT r7, Release, main 2c08875217 and e83839c042.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6544355586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/25728). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-22T15:45:20Z. --- On Windows, an exception that is **raised inside `libstdc++-6.dll`** isn't delivered to a `catch` in AnyPS5 code, even when the `catch` is one frame up. The process aborts with: ``` FATAL: C++ exception <type> raised on thread … cannot be delivered: <project frame> has no unwind data ``` I hit this twice on 2026-11-22. In both cases the code was correct C++ and works on Linux. **1. `libSceNKWebKit.prx` (#25548, head `a2e45c2255`).** `ParsePredicate` in `src/JscConfigFile.cpp` wraps `std::regex::assign` in `catch (const std::regex_error&)`. On an invalid pattern, `nkwebkit_jscconfigfile` aborts in every run, locally and in Windows CI. Stack, innermost first: `libstdc++-6.dll` (`__throw_regex_error`) → `libgcc_s_seh-1.dll` → `KERNELBASE!RaiseException`; the first non-runtime frame is `libSceNKWebKit.prx+0x2c829e`. **2. A host tool executable (#25559, head `9acd199d07`).** `agc_pipeline_journal_replay`'s `main` was a `try { … } catch (const std::exception&)`. Under ANSI code page 1252, a Cyrillic path argument made `std::filesystem::exists` throw `filesystem_error` from inside the libstdc++ DLL, and the process aborted with the same message instead of reaching the `catch`. (That PR has since switched to `wmain`, so the throw no longer happens there.) **Why:** AnyPS5's own throws go through the libc Windows exception unwinder, which reads the DWARF unwind data that `configure_windows_unwind` keeps in `.ehfram`. An exception raised by `libstdc++-6.dll` goes through `libgcc_s_seh` and Windows SEH dispatch instead, which needs `.pdata` for each frame. Project modules have almost none: `libSceNKWebKit.prx` has 0x5d0 bytes of `.pdata` for 3.4 MB of `.text`. The dispatch stops at the first project frame. `docs/dev/debt/libc.md` already documents the reverse case: a handler in an unmarked module such as `libstdc++-6.dll` stops an AnyPS5 unwind. This report is about exceptions thrown from inside that module. **Possible scope, not verified one by one.** On `main`, non-test code under `core/libs/prx` has `catch` sites for exception types that, in practice, only libstdc++ raises: | Type | `catch` sites | |---|---| | `std::filesystem::filesystem_error` | 18 (libc `Filesystem.cpp`, `General.cpp`, `RealPath.cpp`, `Rename.cpp`, `FileAndHeap.cpp`; libkernel `SharedMemory.cpp`, `DynamicLoader.cpp`; `libSceSaveData.native`; `libSceContentExport`) | | `std::bad_alloc` | 143 (`operator new` lives in the libstdc++ DLL) | | `std::system_error` | 21 | There is also `std::stoull` in `libc/src/GuestAllocations.cpp:141`. A site is only affected if its `try` block reaches a throwing libstdc++ call, such as a non-`error_code` filesystem overload or allocation failure. Many may never do so. Each of these needs checking against the actual calls; this list is candidates only. **Directions, none tried:** - in library code, prefer non-throwing forms: `error_code` filesystem overloads, `std::nothrow` allocation, `std::from_chars`, and a non-throwing regex engine such as ICU `uregex_*`; - or have the libc Windows exception filter recognise a GCC exception raised in `libstdc++-6.dll` and hand it to its own DWARF unwinder, the way it delivers AnyPS5 throws; - or link libstdc++ statically into the modules that catch its exceptions, so the throwing code is covered by the module's own unwind data. I haven't checked how that interacts with the guest personalities. Setup for both reproductions: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT r7, Release, `main` `2c08875217` and `e83839c042`. AI-assisted: yes.
Sign in to join this conversation.
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#25728
No description provided.