libSceAmpr: std::_Throw_Cpp_error is a stub (Deathloop, Minecraft Legends); fix branch ready #3346

Closed
opened 2026-10-11 08:23:59 +00:00 by screamm · 1 comment
screamm commented 2026-10-11 08:23:59 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T08:23:59Z.


std::_Throw_Cpp_error(int) (_ZSt16_Throw_Cpp_errori, exported by libSceAmpr, Export.cpp) is a NotImplemented_nid_no_patch stub. Deathloop (PPSA01670) and Minecraft Legends import it; Dinkumware's std::thread/std::mutex wrappers call it to turn a _Thrd_result into a std::system_error.

Fix branch ready: screamm:feat/ampr-throw-cpp-error (bed1deaf, one commit on main 2bb78d2c). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. This one touches the guest exception runtime, so it deserves a careful look.

  • The export is [[noreturn]] and calls a new libc helper ThrowCppError_nid_no_patch (src/exception/StandardExceptions.cpp). For codes 0 to 6 it throws a guest std::system_error through the existing __cxa_allocate_exception/__cxa_throw path typed _ZTISt12system_error, so a title's catch (std::system_error&), catch (std::runtime_error&) or catch (std::exception&) catches it. The object is 32 bytes: the existing 16-byte runtime_error part, the error value at 16 and the category pointer at 24; the value is the FreeBSD errno (busy 16, invalid argument 22, no such process 3, not enough memory 12, operation not permitted 1, deadlock 11, try again 35) and what() is "message: message" as VC12 composes it. Other codes throw a host std::out_of_range. A static generic error_category with VC12's virtual order is added (name() "generic", default_error_condition and both equivalent overloads; message() throws because the guest std::string layout is not modelled; the deleting destructor throws). The existing system_error copy constructors and assignment now copy the error code, which they left uninitialised. Sources: VC12 Dinkumware thread0.cpp, system_error, syserror.cpp (ganboing/crt.vc12 f1d47126), microsoft/STL thread0.cpp/xthreads.h (da52dc0f), aerolib's _Error_objects<int>::_Generic_object and _Syserror_map names confirming the VC12 model. TechnicalDebt records that the category is not the console's object (so e.code() == std::errc::... compares unequal until generic_category() is exported), the virtual order, the layout and the host out_of_range.
  • New MinGW-only guest_ampr_cpp_error (C++ plus a .S with a guest personality and LSDA, like libc's message destructor test) catches all seven codes as system_error, plus one each as runtime_error and exception, checking type name, what() through the guest vtable, the errno value, the category's name and comparisons, the throwing message() and deleting destructor, copy and assignment keeping the code, and -1/7 throwing out_of_range.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_ampr_cpp_error, guest_ampr_markers, guest_ampr_threads 5/5 and the 24 exception-runtime tests 3/3 (one guest_ampr_markers run aborted once in the first repeat batch and passed on every rerun; I could not reproduce it); ctest -j8 -E "^agc_driver_|^video_out_flip" 508/508 (with the #3329 test fix applied locally so the tree builds); with main's Export.cpp the new test fails; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux, where the test is not built.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5799368059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3346). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T08:23:59Z. --- `std::_Throw_Cpp_error(int)` (`_ZSt16_Throw_Cpp_errori`, exported by libSceAmpr, [Export.cpp](https://github.com/boykopovar/AnyPS5/blob/main/core/libs/prx/libSceAmpr/Export.cpp)) is a `NotImplemented_nid_no_patch` stub. Deathloop (PPSA01670) and Minecraft Legends import it; Dinkumware's `std::thread`/`std::mutex` wrappers call it to turn a `_Thrd_result` into a `std::system_error`. **Fix branch ready:** [`screamm:feat/ampr-throw-cpp-error`](https://github.com/screamm/AnyPS5/tree/feat/ampr-throw-cpp-error) (`bed1deaf`, one commit on `main` `2bb78d2c`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. This one touches the guest exception runtime, so it deserves a careful look. - The export is `[[noreturn]]` and calls a new libc helper `ThrowCppError_nid_no_patch` (`src/exception/StandardExceptions.cpp`). For codes 0 to 6 it throws a guest `std::system_error` through the existing `__cxa_allocate_exception`/`__cxa_throw` path typed `_ZTISt12system_error`, so a title's `catch (std::system_error&)`, `catch (std::runtime_error&)` or `catch (std::exception&)` catches it. The object is 32 bytes: the existing 16-byte runtime_error part, the error value at 16 and the category pointer at 24; the value is the FreeBSD errno (busy 16, invalid argument 22, no such process 3, not enough memory 12, operation not permitted 1, deadlock 11, try again 35) and `what()` is "message: message" as VC12 composes it. Other codes throw a host `std::out_of_range`. A static generic `error_category` with VC12's virtual order is added (`name()` "generic", `default_error_condition` and both `equivalent` overloads; `message()` throws because the guest `std::string` layout is not modelled; the deleting destructor throws). The existing `system_error` copy constructors and assignment now copy the error code, which they left uninitialised. Sources: VC12 Dinkumware `thread0.cpp`, `system_error`, `syserror.cpp` (ganboing/crt.vc12 `f1d47126`), microsoft/STL `thread0.cpp`/`xthreads.h` (`da52dc0f`), aerolib's `_Error_objects<int>::_Generic_object` and `_Syserror_map` names confirming the VC12 model. TechnicalDebt records that the category is not the console's object (so `e.code() == std::errc::...` compares unequal until `generic_category()` is exported), the virtual order, the layout and the host `out_of_range`. - New MinGW-only `guest_ampr_cpp_error` (C++ plus a `.S` with a guest personality and LSDA, like libc's message destructor test) catches all seven codes as `system_error`, plus one each as `runtime_error` and `exception`, checking type name, `what()` through the guest vtable, the errno value, the category's name and comparisons, the throwing `message()` and deleting destructor, copy and assignment keeping the code, and -1/7 throwing `out_of_range`. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_ampr_cpp_error`, `guest_ampr_markers`, `guest_ampr_threads` 5/5 and the 24 exception-runtime tests 3/3 (one `guest_ampr_markers` run aborted once in the first repeat batch and passed on every rerun; I could not reproduce it); `ctest -j8 -E "^agc_driver_|^video_out_flip"` 508/508 (with the #3329 test fix applied locally so the tree builds); with `main`'s `Export.cpp` the new test fails; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux, where the test is not built. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
blawesom commented 2026-10-11 09:52:47 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T09:52:47Z.


Independent verification on Linux (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Rebased bed1deaf onto current main (the branch was 239 commits behind): applies cleanly, no conflicts.
  • tools/check_conventions.py --base origin/main and git diff --check pass.
  • guest_ampr_markers, guest_ampr_threads and the exception-runtime tests pass. guest_ampr_cpp_error itself is MinGW-only (if(MINGW) in the CMakeLists), so as the report notes it is not built on Linux and could not be run here.
  • Full suite mirroring the Windows run (ctest -j8 -E "^agc_driver_|^video_out_flip"): 520/520 passed.

The rebased branch is available at blawesom:verify/3346 for anyone carrying — the commit is otherwise unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107768908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3346#issuecomment-6107768908). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T09:52:47Z. --- Independent verification on **Linux** (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Rebased `bed1deaf` onto current `main` (the branch was 239 commits behind): applies cleanly, no conflicts. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. - `guest_ampr_markers`, `guest_ampr_threads` and the exception-runtime tests pass. `guest_ampr_cpp_error` itself is MinGW-only (`if(MINGW)` in the CMakeLists), so as the report notes it is not built on Linux and could not be run here. - Full suite mirroring the Windows run (`ctest -j8 -E "^agc_driver_|^video_out_flip"`): **520/520 passed**. The rebased branch is available at [`blawesom:verify/3346`](https://github.com/blawesom/AnyPS5/tree/verify/3346) for anyone carrying — the commit is otherwise unchanged.
Sign in to join this conversation.
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#3346
No description provided.