feat(libc): implement std::_Throw(const std::bad_array_new_length&) #10927

Merged
edubox merged 3 commits from upstream-pr/10927 into main 2026-10-29 23:18:44 +00:00
edubox commented 2026-10-25 10:42:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-25T10:42:44Z.


What

Implement _ZSt6_ThrowRKSt20bad_array_new_length (1cKlQv7Kvmg), imported by Star Wars Racer (PPSA28416) from libc.

The libc.prx bundled with PRAGMATA PPSA02530 exports it as a 52-byte function at 0xcb2d0 (static disassembly): it ignores its argument, allocates the 8-byte exception object, installs the static _ZTVSt20bad_array_new_length, and calls __cxa_throw. The implementation reuses LibcException::ThrowPlain with that vtable, the same path as __cxa_throw_bad_array_new_length; the argument is deliberately unused, as on the console. A guest test checks the type record, base (std::bad_alloc), vtable and that the call throws, and the debt entry records the console evidence.

Overlap: #9416 adds a void* placeholder for _ZSt6_ThrowRKSt20bad_array_new_length to libc/Export.cpp that throws std::runtime_error; I asked its author to drop it (https://github.com/boykopovar/AnyPS5/pull/9416#issuecomment-6396798596). This PR is the real implementation and does not build on #9416, but the two exports cannot both land. #9416 also already conflicts with current main on the ErrorCode layout (pre-existing, not caused by this PR). The other docs/dev/debt/libc.md and CMakeLists.txt overlaps are unrelated entries.

Tested

Linux, CachyOS 7.3.0, GCC 16.2.1, main b2c7a38840 + this PR:

  • guest_throw_bad_array_new_length passes.
  • guest_bad_optional_access passes.
  • python3 tools/check_conventions.py --base origin/main passes.

The console evidence is static disassembly of the retail libc.prx, not a live console measurement; the title itself was not run.

Checklist

  • Based on current main; no other open PR implements it
  • 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: PPSA28416
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5003998369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10927). Originally posted by [edubox](https://github.com/edubox) on 2026-10-25T10:42:44Z. --- ### What Implement `_ZSt6_ThrowRKSt20bad_array_new_length` (`1cKlQv7Kvmg`), imported by Star Wars Racer (PPSA28416) from `libc`. The `libc.prx` bundled with PRAGMATA PPSA02530 exports it as a 52-byte function at `0xcb2d0` (static disassembly): it ignores its argument, allocates the 8-byte exception object, installs the static `_ZTVSt20bad_array_new_length`, and calls `__cxa_throw`. The implementation reuses `LibcException::ThrowPlain` with that vtable, the same path as `__cxa_throw_bad_array_new_length`; the argument is deliberately unused, as on the console. A guest test checks the type record, base (`std::bad_alloc`), vtable and that the call throws, and the debt entry records the console evidence. Overlap: #9416 adds a `void*` placeholder for `_ZSt6_ThrowRKSt20bad_array_new_length` to `libc/Export.cpp` that throws `std::runtime_error`; I asked its author to drop it (https://github.com/boykopovar/AnyPS5/pull/9416#issuecomment-6396798596). This PR is the real implementation and does not build on #9416, but the two exports cannot both land. #9416 also already conflicts with current `main` on the `ErrorCode` layout (pre-existing, not caused by this PR). The other `docs/dev/debt/libc.md` and `CMakeLists.txt` overlaps are unrelated entries. ### Tested Linux, CachyOS 7.3.0, GCC 16.2.1, `main` `b2c7a38840` + this PR: - `guest_throw_bad_array_new_length` passes. - `guest_bad_optional_access` passes. - `python3 tools/check_conventions.py --base origin/main` passes. The console evidence is static disassembly of the retail `libc.prx`, not a live console measurement; the title itself was not run. ### Checklist - [x] Based on current `main`; no other open PR implements it - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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: PPSA28416 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 13:40:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:40:21Z.

Review: DISMISSED


Reviewed exact head 5710c87e1aad77032f6d0e0484494220a8ddfb3a. The export body reuses the existing ThrowPlain path with _ZTVSt20bad_array_new_length, and the type record correctly derives from bad_alloc; the static console evidence and scope are clearly described. I ran g++ -std=c++20 -Wall -Wextra -Werror -Icore/libs -fsyntax-only core/libs/tests/GuestThrowBadArrayNewLength.cpp, tools/check_conventions.py --base upstream/main --head HEAD, and git diff --check upstream/main...HEAD; all passed. I could not run the linked CTest target in this checkout because the third-party submodules are uninitialized.

One test gap: GuestThrowBadArrayNewLength.cpp catches ..., so it passes if the export throws a different exception type (for example, bad_alloc) even though the purpose of this symbol is to throw std::bad_array_new_length. Please assert the caught dynamic type, and fail if a different exception is caught; retaining the RTTI/vtable layout checks is useful but does not verify the type thrown by this entry point.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643450051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10927#pullrequestreview-5643450051). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T13:40:21Z. **Review:** DISMISSED --- Reviewed exact head `5710c87e1aad77032f6d0e0484494220a8ddfb3a`. The export body reuses the existing `ThrowPlain` path with `_ZTVSt20bad_array_new_length`, and the type record correctly derives from `bad_alloc`; the static console evidence and scope are clearly described. I ran `g++ -std=c++20 -Wall -Wextra -Werror -Icore/libs -fsyntax-only core/libs/tests/GuestThrowBadArrayNewLength.cpp`, `tools/check_conventions.py --base upstream/main --head HEAD`, and `git diff --check upstream/main...HEAD`; all passed. I could not run the linked CTest target in this checkout because the third-party submodules are uninitialized. One test gap: `GuestThrowBadArrayNewLength.cpp` catches `...`, so it passes if the export throws a different exception type (for example, `bad_alloc`) even though the purpose of this symbol is to throw `std::bad_array_new_length`. Please assert the caught dynamic type, and fail if a different exception is caught; retaining the RTTI/vtable layout checks is useful but does not verify the type thrown by this entry point.
XairRrR commented 2026-10-29 04:39:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T04:39:24Z.

Review: APPROVED


Reviewed — approved

The export is correct (NID 1cKlQv7Kvmg matches the name, it throws std::bad_array_new_length through the existing ThrowPlain path), it merges cleanly onto current main, and the new test passes and fails under two negative controls. I have one non-blocking note on the wording of the debt entry.

What I ran

Head f94297b8c2138ef9b963c8e25f9df7f40ab132da merged (--no-ff) onto main d71fe2fa87f8d74b14ad86506b5f0ed916b33a70 in a clean worktree. Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, Release, Ninja, BUILD_TESTING=ON.

git fetch origin main pull/10927/head:refs/review/10927
git checkout --detach origin/main
git merge --no-ff --no-edit refs/review/10927
git diff --check origin/main...refs/review/10927
python3 tools/check_conventions.py --base origin/main
cmake -S . -B build
cmake --build build -j10 --target guest_throw_bad_array_new_length_tests guest_bad_optional_access_tests exception_runtime_tests libs
ctest --test-dir build -j4 --output-on-failure -R "guest_throw_bad_array_new_length|guest_bad_optional_access|exception_runtime"
nm -D build/core/libs/libs/libc.prx | grep 1cKlQv7Kvmg
# NID: SHA-1(name + 518D64A635DED8C1E6B039B1C3E55230), first 8 bytes as LE u64, BE base64, '/' -> '-'

Results

Check Result
Merge onto main Clean (core/libs/prx/libc/CMakeLists.txt auto-merged)
git diff --check Clean
check_conventions.py --base origin/main All conventions checks passed
Build (libs and the three test targets) OK, no warnings in the changed files
guest_throw_bad_array_new_length Passed (0.00 s)
guest_bad_optional_access, exception_runtime Passed
NID of _ZSt6_ThrowRKSt20bad_array_new_length Computes to 1cKlQv7Kvmg, matches the description and debt entry
Export in the built libc.prx 0000000000108020 T 1cKlQv7Kvmg
ctest
1/3 Test #627: guest_bad_optional_access ..........   Passed    0.00 sec
2/3 Test #629: guest_throw_bad_array_new_length ...   Passed    0.00 sec
3/3 Test #633: exception_runtime ..................   Passed    0.00 sec

100% tests passed out of 3

Negative control

  1. I restored core/libs/prx/libc/include/Api.hpp and core/libs/prx/libc/src/exception/StandardExceptions.cpp from main. The test no longer compiles (_ZSt6_ThrowRKSt20bad_array_new_length_nid_postfix not declared). This matches the Windows result reported earlier in the thread.
  2. That only shows that the test needs the symbol, so I also checked the type assertion. I changed the new export's body to throw std::bad_alloc (ThrowPlain(_ZTVSt9bad_alloc_nid_postfix)) and rebuilt. guest_throw_bad_array_new_length then fails (Subprocess aborted). This confirms the fix for the earlier review's catch (...) gap: the test now rejects the base type. With the file restored, the test passes again.

Findings

Blocking

None.

Non-blocking

  • docs/dev/debt/libc.md:194: the entry describes the console function and the implementation but never names a gap. CONTRIBUTING.md asks that an entry "states the gap first (what differs from the console, what is unverified, what throws)". The open point is that the evidence is static disassembly of the libc.prx bundled with PPSA02530, while the importer is PPSA28416, and it was not checked at runtime. Suggested wording: lead with "Unverified at runtime; follows static disassembly of the libc.prx bundled with PPSA02530 …". Alternatively, if maintainers consider the behaviour settled, drop the entry and keep the evidence in the PR body.

Not verified

  • Windows and macOS builds. Windows runs were reported in the thread by two contributors; I did not repeat them.
  • The console disassembly of libc.prx (PPSA02530, 0xcb2d0). I have no copy and took the description's reading as given.
  • Running PPSA28416. Not done, per review policy.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692929028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10927#pullrequestreview-5692929028). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T04:39:24Z. **Review:** APPROVED --- # Reviewed — approved The export is correct (NID `1cKlQv7Kvmg` matches the name, it throws `std::bad_array_new_length` through the existing `ThrowPlain` path), it merges cleanly onto current `main`, and the new test passes and fails under two negative controls. I have one non-blocking note on the wording of the debt entry. ## What I ran Head `f94297b8c2138ef9b963c8e25f9df7f40ab132da` merged (`--no-ff`) onto `main` `d71fe2fa87f8d74b14ad86506b5f0ed916b33a70` in a clean worktree. Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, Release, Ninja, `BUILD_TESTING=ON`. ```sh git fetch origin main pull/10927/head:refs/review/10927 git checkout --detach origin/main git merge --no-ff --no-edit refs/review/10927 git diff --check origin/main...refs/review/10927 python3 tools/check_conventions.py --base origin/main cmake -S . -B build cmake --build build -j10 --target guest_throw_bad_array_new_length_tests guest_bad_optional_access_tests exception_runtime_tests libs ctest --test-dir build -j4 --output-on-failure -R "guest_throw_bad_array_new_length|guest_bad_optional_access|exception_runtime" nm -D build/core/libs/libs/libc.prx | grep 1cKlQv7Kvmg # NID: SHA-1(name + 518D64A635DED8C1E6B039B1C3E55230), first 8 bytes as LE u64, BE base64, '/' -> '-' ``` ## Results | Check | Result | |---|---| | Merge onto `main` | Clean (`core/libs/prx/libc/CMakeLists.txt` auto-merged) | | `git diff --check` | Clean | | `check_conventions.py --base origin/main` | All conventions checks passed | | Build (`libs` and the three test targets) | OK, no warnings in the changed files | | `guest_throw_bad_array_new_length` | Passed (0.00 s) | | `guest_bad_optional_access`, `exception_runtime` | Passed | | NID of `_ZSt6_ThrowRKSt20bad_array_new_length` | Computes to `1cKlQv7Kvmg`, matches the description and debt entry | | Export in the built `libc.prx` | `0000000000108020 T 1cKlQv7Kvmg` | <details><summary>ctest</summary> ``` 1/3 Test #627: guest_bad_optional_access .......... Passed 0.00 sec 2/3 Test #629: guest_throw_bad_array_new_length ... Passed 0.00 sec 3/3 Test #633: exception_runtime .................. Passed 0.00 sec 100% tests passed out of 3 ``` </details> ## Negative control 1. I restored `core/libs/prx/libc/include/Api.hpp` and `core/libs/prx/libc/src/exception/StandardExceptions.cpp` from `main`. The test no longer compiles (`_ZSt6_ThrowRKSt20bad_array_new_length_nid_postfix` not declared). This matches the Windows result reported earlier in the thread. 2. That only shows that the test needs the symbol, so I also checked the type assertion. I changed the new export's body to throw `std::bad_alloc` (`ThrowPlain(_ZTVSt9bad_alloc_nid_postfix)`) and rebuilt. `guest_throw_bad_array_new_length` then fails (`Subprocess aborted`). This confirms the fix for the earlier review's `catch (...)` gap: the test now rejects the base type. With the file restored, the test passes again. ## Findings ### Blocking None. ### Non-blocking - [`docs/dev/debt/libc.md:194`](https://github.com/boykopovar/AnyPS5/blob/f94297b8c2138ef9b963c8e25f9df7f40ab132da/docs/dev/debt/libc.md#L194-L194): the entry describes the console function and the implementation but never names a gap. [CONTRIBUTING.md](https://github.com/boykopovar/AnyPS5/blob/d71fe2fa87f8d74b14ad86506b5f0ed916b33a70/CONTRIBUTING.md#L76-L76) asks that an entry "states the gap first (what differs from the console, what is unverified, what throws)". The open point is that the evidence is static disassembly of the `libc.prx` bundled with PPSA02530, while the importer is PPSA28416, and it was not checked at runtime. Suggested wording: lead with "Unverified at runtime; follows static disassembly of the `libc.prx` bundled with PPSA02530 …". Alternatively, if maintainers consider the behaviour settled, drop the entry and keep the evidence in the PR body. ## Not verified - Windows and macOS builds. Windows runs were reported in the thread by two contributors; I did not repeat them. - The console disassembly of `libc.prx` (PPSA02530, `0xcb2d0`). I have no copy and took the description's reading as given. - Running PPSA28416. Not done, per review policy.
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!10927
No description provided.