feat(libc): export std::_Throw_bad_any_cast and std::_Throw_bad_node_access #15791

Merged
Danigamer05 merged 1 commit from upstream-pr/15791 into main 2026-11-08 00:05:06 +00:00
Danigamer05 commented 2026-11-04 14:55:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-04T14:55:47Z.


What

Export the unversioned std::_Throw_bad_any_cast(const char*) and std::_Throw_bad_node_access(const char*) from libc.

Export NID Original RVA
_ZSt19_Throw_bad_any_castPKc ZEVt6wNNgBk 0x819A0
_ZSt22_Throw_bad_node_accessPKc 4MFvBhXqkmE 0xC39A0

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).

In the module each one copies the message into a new exception and throws it:

  • _Throw_bad_any_cast throws St12bad_any_cast, derived from St8bad_cast;
  • _Throw_bad_node_access throws St16_Bad_node_access, derived from St11logic_error;
  • both what() slots return the copied message.

The module exports neither type, only the throwers, so the two type records and vtables stay internal to StandardExceptions.cpp, next to the other unversioned throwers. Each one is thrown with ThrowMessage, as _Xlength_error and _Xout_of_range are, so it carries this libc's 16-byte message exception. The module's object is 0x30 bytes and holds a std::string. The debt entry records that layout difference and the null message, which is read as empty text here and dereferenced by the module.

#15552 adds the versioned std::__sce_v2::_Throw(const bad_any_cast&), a different export with a different type; this change does not depend on it.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main b11c7bf84f5. Exact tested commit: 00d87368d9d.

  • Built libc, libkernel, their NID-patched production libraries and the related tests. The new guest_bad_any_cast_node_access passes, along with guest_sce_v2_exceptions, guest_filesystem_error, guest_bad_optional_access, exception_personality, windows_exceptions, guest_libc_internal_exception_destructors and public_headers.

  • The new test throws each export through the assembly catch frame of GuestSceV2Exceptions.S and checks the landing selector, the caught type name, its base name and what():

    • bad_any_cast is caught as std::bad_cast, as std::exception and by its own name, and not as std::logic_error, std::runtime_error or _Bad_node_access;
    • _Bad_node_access is caught as std::logic_error, as std::exception and by its own name, and not as std::runtime_error or std::bad_cast;
    • an empty message gives an empty what(), and both keep their own copy of a message whose source is overwritten before the catch reads it.
  • The type names, base classes and what() slots were read from the module's typeinfo, vtables and throwers. The throwers were not run side by side: they end in __cxa_throw, which a host harness cannot catch for the module's frames.

  • Negative control: four lines were altered one at a time:

    • bad_any_cast derived from logic_error;
    • _Bad_node_access derived from runtime_error;
    • bad_any_cast returned its type name from what();
    • _Throw_bad_node_access threw the bad_any_cast table.

    The new CTest failed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test passed again.

  • Code conventions and git diff --check pass.

  • tools/pr_overlap.py read 1,859 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 35 branches that already conflict with main. None of them adds a line naming these exports or types. Merging each of the 35 with this branch and with main using git merge-tree gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667 and #15683.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5156386154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15791). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-04T14:55:47Z. --- ### What Export the unversioned `std::_Throw_bad_any_cast(const char*)` and `std::_Throw_bad_node_access(const char*)` from libc. | Export | NID | Original RVA | | --- | --- | --- | | `_ZSt19_Throw_bad_any_castPKc` | `ZEVt6wNNgBk` | `0x819A0` | | `_ZSt22_Throw_bad_node_accessPKc` | `4MFvBhXqkmE` | `0xC39A0` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). In the module each one copies the message into a new exception and throws it: - `_Throw_bad_any_cast` throws `St12bad_any_cast`, derived from `St8bad_cast`; - `_Throw_bad_node_access` throws `St16_Bad_node_access`, derived from `St11logic_error`; - both `what()` slots return the copied message. The module exports neither type, only the throwers, so the two type records and vtables stay internal to `StandardExceptions.cpp`, next to the other unversioned throwers. Each one is thrown with `ThrowMessage`, as `_Xlength_error` and `_Xout_of_range` are, so it carries this libc's 16-byte message exception. The module's object is 0x30 bytes and holds a `std::string`. The debt entry records that layout difference and the null message, which is read as empty text here and dereferenced by the module. #15552 adds the versioned `std::__sce_v2::_Throw(const bad_any_cast&)`, a different export with a different type; this change does not depend on it. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows x86-64, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, main `b11c7bf84f5`. Exact tested commit: `00d87368d9d`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_bad_any_cast_node_access` passes, along with `guest_sce_v2_exceptions`, `guest_filesystem_error`, `guest_bad_optional_access`, `exception_personality`, `windows_exceptions`, `guest_libc_internal_exception_destructors` and `public_headers`. - The new test throws each export through the assembly catch frame of `GuestSceV2Exceptions.S` and checks the landing selector, the caught type name, its base name and `what()`: - `bad_any_cast` is caught as `std::bad_cast`, as `std::exception` and by its own name, and not as `std::logic_error`, `std::runtime_error` or `_Bad_node_access`; - `_Bad_node_access` is caught as `std::logic_error`, as `std::exception` and by its own name, and not as `std::runtime_error` or `std::bad_cast`; - an empty message gives an empty `what()`, and both keep their own copy of a message whose source is overwritten before the catch reads it. - The type names, base classes and `what()` slots were read from the module's typeinfo, vtables and throwers. The throwers were not run side by side: they end in `__cxa_throw`, which a host harness cannot catch for the module's frames. - Negative control: four lines were altered one at a time: - `bad_any_cast` derived from `logic_error`; - `_Bad_node_access` derived from `runtime_error`; - `bad_any_cast` returned its type name from `what()`; - `_Throw_bad_node_access` threw the `bad_any_cast` table. The new CTest failed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,859 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 35 branches that already conflict with main. None of them adds a line naming these exports or types. Merging each of the 35 with this branch and with main using `git merge-tree` gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667 and #15683. Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15791
No description provided.