fix(libc): export the remaining exception entry points natively on Windows #2615

Merged
oneandonlydean merged 1 commit from upstream-pr/2615 into main 2026-10-10 08:42:25 +00:00
oneandonlydean commented 2026-10-10 08:27:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T08:27:57Z.


Carrying @AlxcBTW's fix for #2597 while PR intake is paused. The change is theirs (from AlxcBTW/AnyPS5:fix/libc-native-exception-exports-v2, 400fce30).

What

  • On Windows, libc exports __cxa_init_primary_exception, std::uncaught_exception and std::uncaught_exceptions under their native names too, next to __cxa_throw, __cxa_begin_catch and the rest.
  • __cxa_init_primary_exception sets the reference count to 0, as the Itanium ABI, libstdc++ and libc++abi do.

Why

GCC_GLOBAL_ALIAS is empty on Windows, so these three were exported only as _nid_postfix symbols and host modules (libSceAgcDriver.prx, libSceVideoOut.prx, libkernel.prx) bound libstdc++-6.dll's versions instead. This is the same class of problem as #2540, fixed in #2570.

  • std::uncaught_exceptions() read libstdc++'s thread state, which libc's throws never touch, so it returned 0 during unwinding and recordDeferredLabels' guard could not tell a failed record from a finished one.
  • std::make_exception_ptr allocated with libc and initialized with libstdc++'s __cxa_init_primary_exception, whose header layout differs. Rethrowing such an exception dies with 0xc0000005.
  • On every platform the reference count started at 1, so the exception_ptr created next added a second reference and a made exception was never destroyed.

Tested

  • The author's full CI on c72d5ce1 passed; on d5c8e42d Linux and macOS pass, and the one Windows failure (agc_driver_prepared_shaders_deferred_undecodable) fails on every main run at the moment.
  • windows_exceptions gains two cases: a made, rethrown and released exception destroys its argument and stored copy once each, and std::uncaught_exceptions() is 1 in a destructor that runs during unwinding. Without the change it dies with 0xc0000005; with only the exports it fails with made exception destroyed an incorrect number of times.
  • exception_runtime (Linux/macOS) gains the same made-exception check.
  • After the change all three modules import the symbols from libc.prx, and patched_libraries loads every patched library.
  • tools/check_conventions.py passes, and the branch merges cleanly with current main.

Fixes #2597

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 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4809890530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2615). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T08:27:57Z. --- Carrying @AlxcBTW's fix for #2597 while PR intake is paused. The change is theirs (from `AlxcBTW/AnyPS5:fix/libc-native-exception-exports-v2`, 400fce30). ### What - On Windows, libc exports `__cxa_init_primary_exception`, `std::uncaught_exception` and `std::uncaught_exceptions` under their native names too, next to `__cxa_throw`, `__cxa_begin_catch` and the rest. - `__cxa_init_primary_exception` sets the reference count to 0, as the Itanium ABI, libstdc++ and libc++abi do. ### Why `GCC_GLOBAL_ALIAS` is empty on Windows, so these three were exported only as `_nid_postfix` symbols and host modules (`libSceAgcDriver.prx`, `libSceVideoOut.prx`, `libkernel.prx`) bound libstdc++-6.dll's versions instead. This is the same class of problem as #2540, fixed in #2570. - `std::uncaught_exceptions()` read libstdc++'s thread state, which libc's throws never touch, so it returned 0 during unwinding and `recordDeferredLabels`' guard could not tell a failed record from a finished one. - `std::make_exception_ptr` allocated with libc and initialized with libstdc++'s `__cxa_init_primary_exception`, whose header layout differs. Rethrowing such an exception dies with `0xc0000005`. - On every platform the reference count started at 1, so the `exception_ptr` created next added a second reference and a made exception was never destroyed. ### Tested - The author's full CI on c72d5ce1 passed; on d5c8e42d Linux and macOS pass, and the one Windows failure (`agc_driver_prepared_shaders_deferred_undecodable`) fails on every `main` run at the moment. - `windows_exceptions` gains two cases: a made, rethrown and released exception destroys its argument and stored copy once each, and `std::uncaught_exceptions()` is 1 in a destructor that runs during unwinding. Without the change it dies with `0xc0000005`; with only the exports it fails with `made exception destroyed an incorrect number of times`. - `exception_runtime` (Linux/macOS) gains the same made-exception check. - After the change all three modules import the symbols from libc.prx, and `patched_libraries` loads every patched library. - `tools/check_conventions.py` passes, and the branch merges cleanly with current `main`. Fixes #2597 ### Checklist - [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) - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-10 08:42:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:42:22Z.


Checked the build and ctest for libc/libs on Linux (57 tests green); exception_runtime fails without the change and passes with it. The Windows side (windows_exceptions) is covered by @Yuva1024's full ctest run on Windows 11 (658/658). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095781403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2615#issuecomment-6095781403). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T08:42:22Z. --- Checked the build and ctest for libc/libs on Linux (57 tests green); `exception_runtime` fails without the change and passes with it. The Windows side (`windows_exceptions`) is covered by @Yuva1024's full ctest run on Windows 11 (658/658). Merging once CI 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!2615
No description provided.