test(libc): cover C++ rethrow, exception_ptr and _Doraise #25087

Merged
MarrasFederico merged 4 commits from upstream-pr/25087 into main 2026-11-25 09:48:30 +00:00
MarrasFederico commented 2026-11-21 16:23:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-21T16:23:15Z.


What

Add guest regression tests covering libc C++ exception runtime (libSceLibcInternal):

50-R08 (core/libs/tests/GuestLibcRethrow.cpp, guest_libc_rethrow_tests)

  • __cxa_rethrow_nid_postfix inside nested catch blocks (identity preservation, __cxa_uncaught_exceptions == 1 during unwind, single destruction), plus set_terminate invocation via setjmp/longjmp when no active exception exists.
  • __cxa_allocate_dependent_exception_nid_postfix / __cxa_free_dependent_exception_nid_postfix zero-initialization and nullptr free safety.
  • __cxa_current_primary_exception_nid_postfix, __cxa_rethrow_primary_exception_nid_postfix (including explicit nullptr no-op verification without invoking terminate or changing uncaught count), and __cxa_increment_exception_refcount_nid_postfix / __cxa_decrement_exception_refcount_nid_postfix exact destructor trigger on final release.

50-R09 (core/libs/tests/GuestExceptionPointer.cpp, guest_exception_pointer_tests)

  • _ZSt17current_exceptionv_nid_postfix outside vs inside catch, survival past catch exit, _ZNSt15__exception_ptr13exception_ptrC1EPv_nid_postfix / _M_get / _M_addref / _M_release, and _ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE_nid_postfix refcount balance and single APS5_VABI destructor execution on final release.

50-R15 (core/libs/tests/GuestLibcDoraiseSystemError.cpp, guest_libc_doraise_system_error_tests)

  • All four exported _Doraise handlers (_ZNKSt9exception8_DoraiseEv, _ZNKSt8bad_cast8_DoraiseEv, _ZNKSt11logic_error8_DoraiseEv, _ZNKSt8ios_base7failure8_DoraiseEv) for null-pointer std::invalid_argument rejection and guest exception cloning/dispatch.
  • _ZNSt12system_errorC2ERKS__nid_postfix copy construction preserving error code/category after source destruction.

Tested

  • Linux: guest_libc_rethrow_tests, guest_exception_pointer_tests, and guest_libc_doraise_system_error_tests built cleanly and ctest -R "^(guest_libc_rethrow|guest_exception_pointer|guest_libc_doraise_system_error)$" --repeat until-fail:3 passed 3/3.
  • Windows: MSYS2 UCRT64 guest_libc_rethrow_tests, guest_exception_pointer_tests, and guest_libc_doraise_system_error_tests built cleanly and ctest -R "^(guest_libc_rethrow|guest_exception_pointer|guest_libc_doraise_system_error)$" --repeat until-fail:3 passed 3/3 (9/9 runs).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5429940004 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25087). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-21T16:23:15Z. --- ### What Add guest regression tests covering `libc` C++ exception runtime (`libSceLibcInternal`): #### 50-R08 (`core/libs/tests/GuestLibcRethrow.cpp`, `guest_libc_rethrow_tests`) - `__cxa_rethrow_nid_postfix` inside nested `catch` blocks (identity preservation, `__cxa_uncaught_exceptions == 1` during unwind, single destruction), plus `set_terminate` invocation via `setjmp`/`longjmp` when no active exception exists. - `__cxa_allocate_dependent_exception_nid_postfix` / `__cxa_free_dependent_exception_nid_postfix` zero-initialization and `nullptr` free safety. - `__cxa_current_primary_exception_nid_postfix`, `__cxa_rethrow_primary_exception_nid_postfix` (including explicit `nullptr` no-op verification without invoking terminate or changing uncaught count), and `__cxa_increment_exception_refcount_nid_postfix` / `__cxa_decrement_exception_refcount_nid_postfix` exact destructor trigger on final release. #### 50-R09 (`core/libs/tests/GuestExceptionPointer.cpp`, `guest_exception_pointer_tests`) - `_ZSt17current_exceptionv_nid_postfix` outside vs inside `catch`, survival past `catch` exit, `_ZNSt15__exception_ptr13exception_ptrC1EPv_nid_postfix` / `_M_get` / `_M_addref` / `_M_release`, and `_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE_nid_postfix` refcount balance and single `APS5_VABI` destructor execution on final release. #### 50-R15 (`core/libs/tests/GuestLibcDoraiseSystemError.cpp`, `guest_libc_doraise_system_error_tests`) - All four exported `_Doraise` handlers (`_ZNKSt9exception8_DoraiseEv`, `_ZNKSt8bad_cast8_DoraiseEv`, `_ZNKSt11logic_error8_DoraiseEv`, `_ZNKSt8ios_base7failure8_DoraiseEv`) for null-pointer `std::invalid_argument` rejection and guest exception cloning/dispatch. - `_ZNSt12system_errorC2ERKS__nid_postfix` copy construction preserving error code/category after source destruction. ### Tested - Linux: `guest_libc_rethrow_tests`, `guest_exception_pointer_tests`, and `guest_libc_doraise_system_error_tests` built cleanly and `ctest -R "^(guest_libc_rethrow|guest_exception_pointer|guest_libc_doraise_system_error)$" --repeat until-fail:3` passed 3/3. - Windows: MSYS2 UCRT64 `guest_libc_rethrow_tests`, `guest_exception_pointer_tests`, and `guest_libc_doraise_system_error_tests` built cleanly and `ctest -R "^(guest_libc_rethrow|guest_exception_pointer|guest_libc_doraise_system_error)$" --repeat until-fail:3` passed 3/3 (9/9 runs). ### 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) 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
PrivacyOnion commented 2026-11-21 17:44:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T17:44:32Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_exception_pointer_tests, guest_libc_doraise_system_error_tests, guest_libc_rethrow_tests built cleanly.
  • CTest (guest_libc_rethrow, guest_exception_pointer, guest_libc_doraise_system_error):
    1/3 Test #1434: guest_libc_rethrow ................   Passed    0.03 sec
    2/3 Test #1435: guest_exception_pointer ...........   Passed    0.04 sec
    3/3 Test #1436: guest_libc_doraise_system_error ...   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 3
    
  • Code reading:
    • Verified core/libs/prx/libc/CMakeLists.txt test registrations: guarded non-Apple tests (guest_libc_rethrow_tests, guest_libc_doraise_system_error_tests), Windows unwind config, timeout properties, and environment prepend for Windows DLL discovery.
    • Inspected core/libs/tests/GuestExceptionPointer.cpp: validated reference counting logic across _ZNSt15__exception_ptr13exception_ptrC1EPv_nid_postfix, _M_addref, _M_release, current_exception within and outside catch blocks, and confirmed exact destructor trigger and null pointer safety.
    • Inspected core/libs/tests/GuestLibcRethrow.cpp: checked nested try-catch rethrow semantics, uncaught exception count accounting via __cxa_uncaught_exceptions_nid_postfix, primary exception increment/decrement refcounts, and set_terminate handling via setjmp/longjmp when rethrowing with no active exception.
    • Inspected core/libs/tests/GuestLibcDoraiseSystemError.cpp: audited _Doraise polymorphic dispatch for std::exception, std::bad_cast, std::logic_error, and std::system_error (ios_base::failure), custom ApplicationHeap registration, nullptr rejection, and what() error formatting.
    • Confirmed compliance with AGENTS.md conventions: no prohibited inline comments, proper test-only additions, and no regressions introduced into existing build targets.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6007052907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25087#pullrequestreview-6007052907). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T17:44:32Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `0eedfc4362`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_exception_pointer_tests`, `guest_libc_doraise_system_error_tests`, `guest_libc_rethrow_tests` built cleanly. - **CTest** (`guest_libc_rethrow`, `guest_exception_pointer`, `guest_libc_doraise_system_error`): ``` 1/3 Test #1434: guest_libc_rethrow ................ Passed 0.03 sec 2/3 Test #1435: guest_exception_pointer ........... Passed 0.04 sec 3/3 Test #1436: guest_libc_doraise_system_error ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 3 ``` - **Code reading**: - Verified core/libs/prx/libc/CMakeLists.txt test registrations: guarded non-Apple tests (guest_libc_rethrow_tests, guest_libc_doraise_system_error_tests), Windows unwind config, timeout properties, and environment prepend for Windows DLL discovery. - Inspected core/libs/tests/GuestExceptionPointer.cpp: validated reference counting logic across _ZNSt15__exception_ptr13exception_ptrC1EPv_nid_postfix, _M_addref, _M_release, current_exception within and outside catch blocks, and confirmed exact destructor trigger and null pointer safety. - Inspected core/libs/tests/GuestLibcRethrow.cpp: checked nested try-catch rethrow semantics, uncaught exception count accounting via __cxa_uncaught_exceptions_nid_postfix, primary exception increment/decrement refcounts, and set_terminate handling via setjmp/longjmp when rethrowing with no active exception. - Inspected core/libs/tests/GuestLibcDoraiseSystemError.cpp: audited _Doraise polymorphic dispatch for std::exception, std::bad_cast, std::logic_error, and std::system_error (ios_base::failure), custom ApplicationHeap registration, nullptr rejection, and what() error formatting. - Confirmed compliance with AGENTS.md conventions: no prohibited inline comments, proper test-only additions, and no regressions introduced into existing build targets. Looks Good To Me
MarcZX10 commented 2026-11-23 00:35:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T00:35:21Z.

Review: APPROVED


Reviewed — looks good

The reviewed changes add three guest regression tests, and the inspected diff shows no blocking defect.

What I ran

Reviewed head 0eedfc436252f4c3ee2374ddf1135e0885974970 against the prepared diff. No commands or tests were run; Linux and Windows test results are author-reported.

Results

Check Result Note
Diff review passed Four changed files inspected
Test execution not run Results in the description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed review/description.md, review/commits.md, review/manifest.json, and review/diff.patch. The diff includes all changed files: core/libs/prx/libc/CMakeLists.txt, core/libs/tests/GuestExceptionPointer.cpp, core/libs/tests/GuestLibcDoraiseSystemError.cpp, and core/libs/tests/GuestLibcRethrow.cpp. No files were excluded from the manifest.

Not verified

Builds and tests were not run as part of this review. No repository files were excluded from review.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015393182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25087#pullrequestreview-6015393182). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T00:35:21Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed changes add three guest regression tests, and the inspected diff shows no blocking defect. ## What I ran Reviewed head `0eedfc436252f4c3ee2374ddf1135e0885974970` against the prepared diff. No commands or tests were run; Linux and Windows test results are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | Four changed files inspected | | Test execution | not run | Results in the description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Sources Reviewed `review/description.md`, `review/commits.md`, `review/manifest.json`, and `review/diff.patch`. The diff includes all changed files: `core/libs/prx/libc/CMakeLists.txt`, `core/libs/tests/GuestExceptionPointer.cpp`, `core/libs/tests/GuestLibcDoraiseSystemError.cpp`, and `core/libs/tests/GuestLibcRethrow.cpp`. No files were excluded from the manifest. ## Not verified Builds and tests were not run as part of this review. No repository files were excluded from review. ## 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!25087
No description provided.