feat(libc): implement std::bad_weak_ptr and _Throw_bad_weak_ptr #1143

Merged
reyani-dev merged 1 commit from upstream-pr/1143 into main 2026-10-08 08:30:42 +00:00
reyani-dev commented 2026-10-07 14:11:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-07T14:11:39Z.


What

tools/nid_names.py resolves the libc stub BnMAMrsfVWo (sceLibcUnknown_BnMAMrsfVWo in HeapDiagnostics.cpp) to _ZSt19_Throw_bad_weak_ptrv, i.e. std::_Throw_bad_weak_ptr(), which std::shared_ptr's constructor from an expired weak_ptr calls.

  • Replaces the stub with _ZSt19_Throw_bad_weak_ptrv_nid_postfix, which throws a guest std::bad_weak_ptr through LibcException::ThrowPlain, like _Xbad_function_call and _Xbad_alloc.
  • Adds std::bad_weak_ptr: type info (St12bad_weak_ptr, base std::exception), vtable, D0/D1/D2 and what(). what() returns "bad_weak_ptr", as libc++ and libstdc++ do.
  • Removes the BnMAMrsfVWo entry from TechnicalDebt.

Note: #545 and #407 add throwing stubs named _ZTVSt12bad_weak_ptr_nid_postfix and _ZNSt12bad_weak_ptrD1Ev_nid_postfix (as functions). This PR defines the vtable as data in libc, so whichever lands second needs to drop the stubs.

Tested

Added a case to exception_runtime_tests: calling _Throw_bad_weak_ptr is caught as a host std::bad_weak_ptr and what() is "bad_weak_ptr". I have no local toolchain on this machine, so I'm relying on CI (Linux and Windows) for the build and tests. No title tested.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4773898328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1143). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-07T14:11:39Z. --- ### What `tools/nid_names.py` resolves the libc stub `BnMAMrsfVWo` (`sceLibcUnknown_BnMAMrsfVWo` in `HeapDiagnostics.cpp`) to `_ZSt19_Throw_bad_weak_ptrv`, i.e. `std::_Throw_bad_weak_ptr()`, which `std::shared_ptr`'s constructor from an expired `weak_ptr` calls. - Replaces the stub with `_ZSt19_Throw_bad_weak_ptrv_nid_postfix`, which throws a guest `std::bad_weak_ptr` through `LibcException::ThrowPlain`, like `_Xbad_function_call` and `_Xbad_alloc`. - Adds `std::bad_weak_ptr`: type info (`St12bad_weak_ptr`, base `std::exception`), vtable, `D0`/`D1`/`D2` and `what()`. `what()` returns `"bad_weak_ptr"`, as libc++ and libstdc++ do. - Removes the `BnMAMrsfVWo` entry from TechnicalDebt. Note: #545 and #407 add throwing stubs named `_ZTVSt12bad_weak_ptr_nid_postfix` and `_ZNSt12bad_weak_ptrD1Ev_nid_postfix` (as functions). This PR defines the vtable as data in libc, so whichever lands second needs to drop the stubs. ### Tested Added a case to `exception_runtime_tests`: calling `_Throw_bad_weak_ptr` is caught as a host `std::bad_weak_ptr` and `what()` is `"bad_weak_ptr"`. I have no local toolchain on this machine, so I'm relying on CI (Linux and Windows) for the build and tests. No title tested. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-07 14:33:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T14:33:49Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1391 core/libs/prx/libc/src/exception/StandardExceptions.cpp L291
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6040214656 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1143#issuecomment-6040214656). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T14:33:49Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1391 | `core/libs/prx/libc/src/exception/StandardExceptions.cpp` [L291](https://github.com/boykopovar/AnyPS5/blob/6b57386237a652f11ecdd2c420f43376adb972e6/core/libs/prx/libc/src/exception/StandardExceptions.cpp#L291) | | |
github-actions[bot] commented 2026-10-08 04:36:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T04:36:13Z.


Progress report (8e22498 → df570de)

📈 System libraries: 85.2% (+0.05%, +5 implemented, -1 removed functions)

✅ 5 implemented
Library Name
libc _ZNKSt12bad_weak_ptr4whatEv_nid_postfix
libc _ZNSt12bad_weak_ptrD0Ev_nid_postfix
libc _ZNSt12bad_weak_ptrD1Ev_nid_postfix
libc _ZNSt12bad_weak_ptrD2Ev_nid_postfix
libc _ZSt19_Throw_bad_weak_ptrv_nid_postfix
🗑️ 1 removed
Library Name
libc sceLibcUnknown_BnMAMrsfVWo
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052338204 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1143#issuecomment-6052338204). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T04:36:13Z. --- <!-- progress-report --> ### Progress report (8e22498 → df570de) 📈 **System libraries**: 85.2% (+0.05%, +5 implemented, -1 removed functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libc | `_ZNKSt12bad_weak_ptr4whatEv_nid_postfix` | | libc | `_ZNSt12bad_weak_ptrD0Ev_nid_postfix` | | libc | `_ZNSt12bad_weak_ptrD1Ev_nid_postfix` | | libc | `_ZNSt12bad_weak_ptrD2Ev_nid_postfix` | | libc | `_ZSt19_Throw_bad_weak_ptrv_nid_postfix` | </details> <details> <summary>🗑️ 1 removed</summary> | Library | Name | | - | - | | libc | `sceLibcUnknown_BnMAMrsfVWo` | </details>
adriadam10 commented 2026-10-08 08:15:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:15:40Z.


Checked: the stub BnMAMrsfVWo is gone with its TechnicalDebt line, std::bad_weak_ptr follows the existing bad_function_call pattern (type info with std::exception base, vtable, D0/D1/D2, what() = "bad_weak_ptr" as in MS STL, libc++ and libstdc++), and the new case in exception_runtime_tests fails to link without the change.
Rebased onto current main (the only conflicts were adjacency with the _Xbad_function_call additions in StandardExceptions.cpp and ExceptionRuntime.cpp); build and ctest pass (424/424). Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6055709339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1143#issuecomment-6055709339). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T08:15:40Z. --- Checked: the stub `BnMAMrsfVWo` is gone with its TechnicalDebt line, `std::bad_weak_ptr` follows the existing `bad_function_call` pattern (type info with `std::exception` base, vtable, D0/D1/D2, `what()` = `"bad_weak_ptr"` as in MS STL, libc++ and libstdc++), and the new case in `exception_runtime_tests` fails to link without the change. Rebased onto current `main` (the only conflicts were adjacency with the `_Xbad_function_call` additions in `StandardExceptions.cpp` and `ExceptionRuntime.cpp`); build and ctest pass (424/424). Merging once CI is green on the rebased head.
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!1143
No description provided.