feat(libSceLibcInternal): implement bad_exception::_Doraise and its deleting destructor #24043

Merged
PostMalloy merged 1 commit from upstream-pr/24043 into main 2026-11-20 17:51:38 +00:00
PostMalloy commented 2026-11-20 01:59:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PostMalloy on 2026-11-20T01:59:36Z.


What

Two std::bad_exception exports of libSceLibcInternal were stubs:

  • _ZNKSt13bad_exception8_DoraiseEv (NID kTlQY47fo88) threw through NotImplemented_nid_no_patch.
  • _ZNSt13bad_exceptionD0Ev (NID lX9M5u0e48k) was the inventory stub libSceLibcInternalInventory_020, which threw too.

_Doraise now throws a new std::bad_exception, as Dinkumware's _RAISE(*this) does for a class with no state of its own. It mirrors the existing bad_alloc and bad_typeid _Doraise exports in ExceptionVirtuals.cpp, including the std::invalid_argument for a null object.

  • libc gains a St13bad_exception type record, with St9exception as its base, and a plain 8-byte vtable. Guest catch matching compares type names, so a guest catch (std::bad_exception&) or catch (std::exception&) catches the object.
  • A new LibcThrowBadException_nid_no_patch helper, like LibcThrowOverflowError_nid_no_patch, throws it.
  • what() returns bad exception, the default message in Microsoft STL's <exception>, the Dinkumware-derived library the debt file already cites for _Xoverflow_error. The console's string is unverified, and the debt entry says so.
  • The type record and vtable are not exported. Which library exports _ZTISt13bad_exception and _ZTVSt13bad_exception on the console is unknown, and exporting them from the wrong one would not resolve a title's import anyway.

D0 releases the object through operator delete. The existing debt entry "Empty facet and exception members" records bad_exception's D1 and D2 as a bare ret in firmware 13.42, and those stay as they are. The Itanium deleting destructor is D1 followed by operator delete, so D0 calls _ZdlPv, as the bad_variant_access D0 in ExceptionDestructors.cpp does.

The debt fragment drops _Doraise from its "Additional 3.20 imports" entry and adds an entry describing both exports.

#23809 is the only open PR I found that touches this area. It implements the two istreambuf_iterator::equal exports listed in the same debt entry, and its fragment changes that entry to keep only _Doraise. This PR's fragment changes it from the other side, so whichever merges second has to drop the entry; tools/debt_fold.py refuses the pair until then. Its code changes are in other lines, so the two PRs do not conflict in code. #17300, which already conflicts with main, renames the libSceLibcInternal inventory stubs after their mangled names, including libSceLibcInternalInventory_020 to _ZNSt13bad_exceptionD0Ev. It keeps that stub throwing, so it does not implement D0, but it will need to drop that rename after this PR. gh search prs finds no other open PR mentioning bad_exception::_Doraise, _ZNKSt13bad_exception8_DoraiseEv or _ZNSt13bad_exceptionD0Ev, and pr_overlap.py --branch against the 100 most recent open PRs reports no overlap.

Tested

Windows 11 x64 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0, Release.

  • guest_libc_internal_exception_virtuals, new CheckBadExceptionDoraise:
    • _Doraise on an object throws a new object.
    • A host catch (const std::bad_exception&) catches it, with type name St13bad_exception and what() bad exception.
    • A catch (const std::exception&) also catches it.
    • A null object throws std::invalid_argument.
  • guest_libc_internal_libc_forwards, new CheckBadException: D0 on an operator new block releases exactly that block once through the registered application heap.
  • As a negative control, changing the what() string makes guest_libc_internal_exception_virtuals fail at the new check.
  • On current main with this commit, after a full build: all 95 tests matching guest_libc_internal, guest_exception_vtable, guest_sce_v2_exceptions, exception_personality, windows_exceptions, guest_exception_handler, guest_raise_exception, guest_mutex_raise_exception and undeliverable_host_exception pass.
  • tools/check_conventions.py --base origin/main and tools/debt_fold.py --check pass.
  • tools/nid_names.py gives lX9M5u0e48k for _ZNSt13bad_exceptionD0Ev and kTlQY47fo88 for _ZNKSt13bad_exception8_DoraiseEv, the NIDs the stubs exported.

No title was found calling either export, and no PS5 hardware was used.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5406358431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24043). Originally posted by [PostMalloy](https://github.com/PostMalloy) on 2026-11-20T01:59:36Z. --- ### What Two `std::bad_exception` exports of `libSceLibcInternal` were stubs: - `_ZNKSt13bad_exception8_DoraiseEv` (NID `kTlQY47fo88`) threw through `NotImplemented_nid_no_patch`. - `_ZNSt13bad_exceptionD0Ev` (NID `lX9M5u0e48k`) was the inventory stub `libSceLibcInternalInventory_020`, which threw too. **`_Doraise`** now throws a new `std::bad_exception`, as Dinkumware's `_RAISE(*this)` does for a class with no state of its own. It mirrors the existing `bad_alloc` and `bad_typeid` `_Doraise` exports in `ExceptionVirtuals.cpp`, including the `std::invalid_argument` for a null object. - `libc` gains a `St13bad_exception` type record, with `St9exception` as its base, and a plain 8-byte vtable. Guest catch matching compares type names, so a guest `catch (std::bad_exception&)` or `catch (std::exception&)` catches the object. - A new `LibcThrowBadException_nid_no_patch` helper, like `LibcThrowOverflowError_nid_no_patch`, throws it. - `what()` returns `bad exception`, the default message in [Microsoft STL's `<exception>`](https://github.com/microsoft/STL/blob/54d74d7a58e828857a73f979eccc2ba1c02e256d/stl/inc/exception#L138), the Dinkumware-derived library the debt file already cites for `_Xoverflow_error`. The console's string is unverified, and the debt entry says so. - The type record and vtable are not exported. Which library exports `_ZTISt13bad_exception` and `_ZTVSt13bad_exception` on the console is unknown, and exporting them from the wrong one would not resolve a title's import anyway. **`D0`** releases the object through `operator delete`. The existing debt entry "Empty facet and exception members" records `bad_exception`'s `D1` and `D2` as a bare `ret` in firmware 13.42, and those stay as they are. The Itanium deleting destructor is `D1` followed by `operator delete`, so `D0` calls `_ZdlPv`, as the `bad_variant_access` `D0` in `ExceptionDestructors.cpp` does. The debt fragment drops `_Doraise` from its "Additional 3.20 imports" entry and adds an entry describing both exports. #23809 is the only open PR I found that touches this area. It implements the two `istreambuf_iterator::equal` exports listed in the same debt entry, and its fragment changes that entry to keep only `_Doraise`. This PR's fragment changes it from the other side, so whichever merges second has to drop the entry; `tools/debt_fold.py` refuses the pair until then. Its code changes are in other lines, so the two PRs do not conflict in code. #17300, which already conflicts with `main`, renames the `libSceLibcInternal` inventory stubs after their mangled names, including `libSceLibcInternalInventory_020` to `_ZNSt13bad_exceptionD0Ev`. It keeps that stub throwing, so it does not implement `D0`, but it will need to drop that rename after this PR. `gh search prs` finds no other open PR mentioning `bad_exception::_Doraise`, `_ZNKSt13bad_exception8_DoraiseEv` or `_ZNSt13bad_exceptionD0Ev`, and `pr_overlap.py --branch` against the 100 most recent open PRs reports no overlap. ### 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 11 x64 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0, Release. - `guest_libc_internal_exception_virtuals`, new `CheckBadExceptionDoraise`: - `_Doraise` on an object throws a new object. - A host `catch (const std::bad_exception&)` catches it, with type name `St13bad_exception` and `what()` `bad exception`. - A `catch (const std::exception&)` also catches it. - A null object throws `std::invalid_argument`. - `guest_libc_internal_libc_forwards`, new `CheckBadException`: `D0` on an `operator new` block releases exactly that block once through the registered application heap. - As a negative control, changing the `what()` string makes `guest_libc_internal_exception_virtuals` fail at the new check. - On current `main` with this commit, after a full build: all 95 tests matching `guest_libc_internal`, `guest_exception_vtable`, `guest_sce_v2_exceptions`, `exception_personality`, `windows_exceptions`, `guest_exception_handler`, `guest_raise_exception`, `guest_mutex_raise_exception` and `undeliverable_host_exception` pass. - `tools/check_conventions.py --base origin/main` and `tools/debt_fold.py --check` pass. - `tools/nid_names.py` gives `lX9M5u0e48k` for `_ZNSt13bad_exceptionD0Ev` and `kTlQY47fo88` for `_ZNKSt13bad_exception8_DoraiseEv`, the NIDs the stubs exported. No title was found calling either export, and no PS5 hardware was used. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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)
PrivacyOnion commented 2026-11-20 02:17:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T02:17:14Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c8229fea33:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_exception_virtuals_tests, guest_libc_internal_libc_forwards_tests built cleanly.
  • CTest (guest_libc_internal_exception_virtuals, guest_libc_internal_libc_forwards):
    1/2 Test #4391: guest_libc_internal_exception_virtuals ...   Passed    0.06 sec
    2/2 Test #4394: guest_libc_internal_libc_forwards ........   Passed    0.06 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp, core/libs/prx/libSceLibcInternal/ExceptionVirtuals.cpp, core/libs/prx/libSceLibcInternal/InventoryExports.cpp, core/libs/prx/libSceLibcInternal/InventoryExports2.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/ExceptionVirtuals.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports2.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/exception/StandardExceptions.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified _ZNSt13bad_exceptionD0Ev_nid_postfix correctly frees self using _ZdlPv_nid_postfix matching D0 deleting destructor semantics in ExceptionDestructors.cpp
    • Verified _ZNKSt13bad_exception8_DoraiseEv_nid_postfix checks self for null and raises std::invalid_argument, matching sibling _Doraise implementations in ExceptionVirtuals.cpp
    • Verified LibcThrowBadException_nid_no_patch correctly sets up typeinfo St13bad_exception inheriting from St9exception and PlainWhat returns 'bad exception'
    • Verified removal of stubs from InventoryExports.cpp and InventoryExports2.cpp and header declarations in Api.hpp and ExceptionVirtuals.hpp
    • Verified documentation fragment in docs/dev/debt/changes/ and unit tests in GuestLibcInternalExceptionVirtuals.cpp and GuestLibcInternalLibcForwards.cpp

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5986539964 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24043#pullrequestreview-5986539964). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T02:17:14Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c8229fea33`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_exception_virtuals_tests`, `guest_libc_internal_libc_forwards_tests` built cleanly. - **CTest** (`guest_libc_internal_exception_virtuals`, `guest_libc_internal_libc_forwards`): ``` 1/2 Test #4391: guest_libc_internal_exception_virtuals ... Passed 0.06 sec 2/2 Test #4394: guest_libc_internal_libc_forwards ........ Passed 0.06 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp`, `core/libs/prx/libSceLibcInternal/ExceptionVirtuals.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports2.cpp`, `core/libs/prx/libSceLibcInternal/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/include/ExceptionVirtuals.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports2.hpp`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/exception/StandardExceptions.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified _ZNSt13bad_exceptionD0Ev_nid_postfix correctly frees self using _ZdlPv_nid_postfix matching D0 deleting destructor semantics in ExceptionDestructors.cpp - Verified _ZNKSt13bad_exception8_DoraiseEv_nid_postfix checks self for null and raises std::invalid_argument, matching sibling _Doraise implementations in ExceptionVirtuals.cpp - Verified LibcThrowBadException_nid_no_patch correctly sets up typeinfo St13bad_exception inheriting from St9exception and PlainWhat returns 'bad exception' - Verified removal of stubs from InventoryExports.cpp and InventoryExports2.cpp and header declarations in Api.hpp and ExceptionVirtuals.hpp - Verified documentation fragment in docs/dev/debt/changes/ and unit tests in GuestLibcInternalExceptionVirtuals.cpp and GuestLibcInternalLibcForwards.cpp Looks Good To Me
MarcZX10 commented 2026-11-20 06:38:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:38:46Z.

Review: APPROVED


Reviewed — looks good

The reviewed changes at c8229fea336681cffc1e505a1635900515a89161 implement the two described exports and their tests; I found no blocking defect in the inspected code.

What I ran

Read the prepared diff and relevant source ranges through repo_read.py. No commands or tests were run by me.

Results

Check Result Note
Source review passed Relevant implementation paths inspected
Automated tests not run Results in the PR description are author-reported
Hardware behavior not run No PS5 hardware validation reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

The PR description reports Windows tests, conventions and debt checks, but I did not run them. Console behavior and the console’s what() string remain unverified as noted by the author. All 13 changed files in manifest.json were included; I read the diff and relevant ranges, not every full file. The files.json path was unavailable in the review folder; the folder listing confirms the changed-file inventory.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988532231 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24043#pullrequestreview-5988532231). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T06:38:46Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed changes at `c8229fea336681cffc1e505a1635900515a89161` implement the two described exports and their tests; I found no blocking defect in the inspected code. ## What I ran Read the prepared diff and relevant source ranges through `repo_read.py`. No commands or tests were run by me. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Relevant implementation paths inspected | | Automated tests | not run | Results in the PR description are author-reported | | Hardware behavior | not run | No PS5 hardware validation reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The PR description reports Windows tests, conventions and debt checks, but I did not run them. Console behavior and the console’s `what()` string remain unverified as noted by the author. All 13 changed files in `manifest.json` were included; I read the diff and relevant ranges, not every full file. The `files.json` path was unavailable in the review folder; the folder listing confirms the changed-file inventory. ## To get this to a good state Nothing is required.
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!24043
No description provided.