test(libc): cover the unwind context accessors #9775

Merged
DavidSamir merged 4 commits from upstream-pr/9775 into main 2026-11-09 11:46:16 +00:00
DavidSamir commented 2026-10-22 14:16:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T14:16:42Z.


What

Adds guest_unwind_accessors, a test for the ten accessors of _Unwind_Context in libc/src/exception/Unwind.cpp that no test named or ran (found by a gcov run of the CPU-side tests, which listed them with zero hits): _Unwind_GetGR, _Unwind_SetGR, _Unwind_GetIP, _Unwind_SetIP, _Unwind_GetIPInfo, _Unwind_GetCFA, _Unwind_GetLanguageSpecificData, _Unwind_GetRegionStart, _Unwind_GetDataRelBase and _Unwind_GetTextRelBase.

It builds a context the way ExceptionPersonality does and checks:

  • every one of the 17 registers reads back the value set, and setting one leaves the others as they were;
  • the instruction pointer is register 16, through SetIP, GetIP and SetGR;
  • _Unwind_GetIPInfo returns the instruction pointer, reports the signal frame flag as the before-instruction flag, and accepts a null flag pointer;
  • each context field comes back through its own accessor, and the accessors do not change the registers.

No source file changes.

Tested

Windows 11, WinLibs GCC 15.2.0, Release, on main 8b3e39832a:

  • guest_unwind_accessors passes 3 of 3.
  • Negative control: with _Unwind_GetDataRelBase returning textBase, it fails at line 77 (GetDataRelBase is 0x8400).
  • python tools/check_conventions.py --base origin/main passes.

Linux (Ubuntu 24.04 in WSL2, GCC 13.3.0, Release): guest_unwind_accessors, exception_runtime and exception_personality pass 3 of 3.

Not run on macOS. An out-of-range register index aborts in the source and is not 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 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:4968882181 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9775). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T14:16:42Z. --- ### What Adds `guest_unwind_accessors`, a test for the ten accessors of `_Unwind_Context` in `libc/src/exception/Unwind.cpp` that no test named or ran (found by a gcov run of the CPU-side tests, which listed them with zero hits): `_Unwind_GetGR`, `_Unwind_SetGR`, `_Unwind_GetIP`, `_Unwind_SetIP`, `_Unwind_GetIPInfo`, `_Unwind_GetCFA`, `_Unwind_GetLanguageSpecificData`, `_Unwind_GetRegionStart`, `_Unwind_GetDataRelBase` and `_Unwind_GetTextRelBase`. It builds a context the way `ExceptionPersonality` does and checks: - every one of the 17 registers reads back the value set, and setting one leaves the others as they were; - the instruction pointer is register 16, through `SetIP`, `GetIP` and `SetGR`; - `_Unwind_GetIPInfo` returns the instruction pointer, reports the signal frame flag as the before-instruction flag, and accepts a null flag pointer; - each context field comes back through its own accessor, and the accessors do not change the registers. No source file changes. ### Tested Windows 11, WinLibs GCC 15.2.0, Release, on `main` `8b3e39832a`: - `guest_unwind_accessors` passes 3 of 3. - **Negative control:** with `_Unwind_GetDataRelBase` returning `textBase`, it fails at line 77 (`GetDataRelBase` is `0x8400`). - `python tools/check_conventions.py --base origin/main` passes. Linux (Ubuntu 24.04 in WSL2, GCC 13.3.0, Release): `guest_unwind_accessors`, `exception_runtime` and `exception_personality` pass 3 of 3. Not run on macOS. An out-of-range register index aborts in the source and is not tested. ### 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) - [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
MarcZX10 commented 2026-10-22 14:34:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:34:59Z.

Review: APPROVED


The test covers all ten named accessors, independent register writes, the IP/register-16 alias, signal-frame behavior and a null before pointer. I compared those expectations with the current implementations in Unwind.cpp; they match. The negative control for the text/data base accessor is also useful.

The hosted register-context suite passes on Ubuntu and macOS Intel in both Debug and Release, and conventions/eligibility/relinker/ASan/write-watch checks pass. Linux and Windows product jobs are skipped by repository policy. I did not run the CTest locally because this checkout has no configured build and less than 1 GB of free disk. No open PR implementing these accessors was found. #9773 also inserts a separate test registration in the same CMake block; the changes compose cleanly and do not require an ordering dependency.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615933995 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9775#pullrequestreview-5615933995). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:34:59Z. **Review:** APPROVED --- The test covers all ten named accessors, independent register writes, the IP/register-16 alias, signal-frame behavior and a null `before` pointer. I compared those expectations with the current implementations in `Unwind.cpp`; they match. The negative control for the text/data base accessor is also useful. The hosted `register-context` suite passes on Ubuntu and macOS Intel in both Debug and Release, and conventions/eligibility/relinker/ASan/write-watch checks pass. Linux and Windows product jobs are skipped by repository policy. I did not run the CTest locally because this checkout has no configured build and less than 1 GB of free disk. No open PR implementing these accessors was found. #9773 also inserts a separate test registration in the same CMake block; the changes compose cleanly and do not require an ordering dependency.
MarcZX10 commented 2026-10-22 16:36:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:36:13Z.

Review: DISMISSED


This test-only addition exercises all ten unwind accessors, each of the 17 general registers and the instruction-pointer/register-16 alias, plus signal-frame behavior and the context-base fields. The CMake registration is consistent with nearby libc tests. Current-main conventions and git diff --check pass. I did not rerun the test locally; the PR reports three passing Windows runs and three passing Linux WSL2 runs. Upstream product jobs are skipped.

This branch is 24 commits behind live main (499b1cf9fc44da935fe6d63813675ad5810e8402). CONTRIBUTING.md requires branches to be based on and kept up to date with main. Please sync it and rerun guest_unwind_accessors on the resulting head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5617630159 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9775#pullrequestreview-5617630159). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T16:36:13Z. **Review:** DISMISSED --- This test-only addition exercises all ten unwind accessors, each of the 17 general registers and the instruction-pointer/register-16 alias, plus signal-frame behavior and the context-base fields. The CMake registration is consistent with nearby libc tests. Current-main conventions and `git diff --check` pass. I did not rerun the test locally; the PR reports three passing Windows runs and three passing Linux WSL2 runs. Upstream product jobs are skipped. This branch is 24 commits behind live `main` (`499b1cf9fc44da935fe6d63813675ad5810e8402`). CONTRIBUTING.md requires branches to be based on and kept up to date with `main`. Please sync it and rerun `guest_unwind_accessors` on the resulting head.
MarcZX10 commented 2026-10-22 16:58:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:58:12Z.

Review: COMMENTED


The exact head 48b936e3945a1f9a3f1d953e3ad7a9cfd8d1b877 has a clean merge tree with current main (11f976b27c16ed91633f00039dba5dfd97dd7cc1); conventions and git diff --check pass. The new test covers all ten accessors, all 17 register slots, IP aliasing, signal-frame reporting and context fields. The PR’s hosted register-context matrix passes on Ubuntu and macOS Intel Debug/Release; product Linux/Windows jobs are skipped. Windows/Linux runs in the description are contributor-reported. This branch is based on 8b3e39832a, 32 commits behind current main. Please rebase and rerun guest_unwind_accessors on the refreshed head before merge. I did not rerun locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5617875300 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9775#pullrequestreview-5617875300). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T16:58:12Z. **Review:** COMMENTED --- The exact head `48b936e3945a1f9a3f1d953e3ad7a9cfd8d1b877` has a clean merge tree with current `main` (`11f976b27c16ed91633f00039dba5dfd97dd7cc1`); conventions and `git diff --check` pass. The new test covers all ten accessors, all 17 register slots, IP aliasing, signal-frame reporting and context fields. The PR’s hosted register-context matrix passes on Ubuntu and macOS Intel Debug/Release; product Linux/Windows jobs are skipped. Windows/Linux runs in the description are contributor-reported. This branch is based on `8b3e39832a`, 32 commits behind current main. Please rebase and rerun `guest_unwind_accessors` on the refreshed head before merge. I did not rerun locally.
THEMANnt commented 2026-10-25 07:05:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T07:05:22Z.

Review: APPROVED


Reviewed 48b936e3945a1f9a3f1d953e3ad7a9cfd8d1b877 against author merge base 8b3e39832af85f404c6195418d11b3e1ebd1924d.

Approve. No actionable findings in this accessor-test addition.

Reviewed the full test/CMake patch and pinned _Unwind_Context plus Unwind.cpp accessors: all 17 register slots, instruction-pointer aliasing, signal-frame before flag (including nullptr output), distinct metadata fields, and preservation of unrelated registers are checked consistently with implementation. This test exercises field access, not stack unwinding.

Validation: exact head test compiled and ran successfully with the pinned Unwind.cpp translation unit, using function/data sections and linker garbage collection. The existing development libc DLL supplied ancillary link dependencies; this is not a complete pinned libc rebuild. A prior DLL-only attempt lacked UnwindCursorSlots and was superseded by that source build. Head syntax, conventions, whitespace and registration passed. Baseline has no new test. Hosted native product jobs were skipped; no full exception-unwind/application test is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641995828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9775#pullrequestreview-5641995828). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-25T07:05:22Z. **Review:** APPROVED --- Reviewed `48b936e3945a1f9a3f1d953e3ad7a9cfd8d1b877` against author merge base `8b3e39832af85f404c6195418d11b3e1ebd1924d`. Approve. No actionable findings in this accessor-test addition. Reviewed the full test/CMake patch and pinned _Unwind_Context plus Unwind.cpp accessors: all 17 register slots, instruction-pointer aliasing, signal-frame before flag (including nullptr output), distinct metadata fields, and preservation of unrelated registers are checked consistently with implementation. This test exercises field access, not stack unwinding. Validation: exact head test compiled and ran successfully with the pinned Unwind.cpp translation unit, using function/data sections and linker garbage collection. The existing development libc DLL supplied ancillary link dependencies; this is not a complete pinned libc rebuild. A prior DLL-only attempt lacked UnwindCursorSlots and was superseded by that source build. Head syntax, conventions, whitespace and registration passed. Baseline has no new test. Hosted native product jobs were skipped; no full exception-unwind/application test is claimed.
jotitadev commented 2026-10-30 15:38:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T15:38:40Z.

Review: COMMENTED


This head fails public_headers, both on its own and merged into current main.

Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON. Head 9f7fbe4eba merged (--no-commit) onto main ed1e0ed08f; the merge is clean.

The ten accessors were already declared in prx/libc/include/Api.hpp (lines 1392 to 1401) by #10706, which is in this branch's base 5454cd2e45. The fix-up commit 9f7fbe4eba adds them a second time to exceptions/Unwind.hpp, and the audit requires one declaration per export:

_Unwind_GetGR_nid_postfix: expected exactly one header declaration; found 2: core/libs/prx/libc/include/Api.hpp:1392, core/libs/prx/libc/include/exceptions/Unwind.hpp:239

The same happens for the other nine. Dropping the ten lines from Unwind.hpp and including Api.hpp in the test fixes it:

--- a/core/libs/prx/libc/include/exceptions/Unwind.hpp
+++ b/core/libs/prx/libc/include/exceptions/Unwind.hpp
 extern "C" {
-    _Unwind_Word APS5_VABI _Unwind_GetGR_nid_postfix(_Unwind_Context*, int);
-    ...
-    _Unwind_Ptr APS5_VABI _Unwind_GetTextRelBase_nid_postfix(_Unwind_Context*);
     _Unwind_Reason_Code APS5_VABI __gxx_personality_v0_nid_postfix(...);
--- a/core/libs/tests/GuestUnwindAccessors.cpp
+++ b/core/libs/tests/GuestUnwindAccessors.cpp
-#include "prx/libc/include/exceptions/Unwind.hpp"
+#include "prx/libc/include/Api.hpp"

With that change, on the same merge:

  • The audit reports 0 errors; public_headers and the 64 public_headers_compile_* tests pass (65/65).
  • The test builds, and guest_unwind_accessors passes 3/3.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5714727418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9775#pullrequestreview-5714727418). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-30T15:38:40Z. **Review:** COMMENTED --- This head fails `public_headers`, both on its own and merged into current `main`. Ubuntu 26.04, i7-8700, GCC 15.2, Release, `BUILD_TESTING=ON`. Head `9f7fbe4eba` merged (`--no-commit`) onto `main` `ed1e0ed08f`; the merge is clean. The ten accessors were already declared in `prx/libc/include/Api.hpp` (lines 1392 to 1401) by #10706, which is in this branch's base `5454cd2e45`. The fix-up commit `9f7fbe4eba` adds them a second time to `exceptions/Unwind.hpp`, and the audit requires one declaration per export: ``` _Unwind_GetGR_nid_postfix: expected exactly one header declaration; found 2: core/libs/prx/libc/include/Api.hpp:1392, core/libs/prx/libc/include/exceptions/Unwind.hpp:239 ``` The same happens for the other nine. Dropping the ten lines from `Unwind.hpp` and including `Api.hpp` in the test fixes it: ```diff --- a/core/libs/prx/libc/include/exceptions/Unwind.hpp +++ b/core/libs/prx/libc/include/exceptions/Unwind.hpp extern "C" { - _Unwind_Word APS5_VABI _Unwind_GetGR_nid_postfix(_Unwind_Context*, int); - ... - _Unwind_Ptr APS5_VABI _Unwind_GetTextRelBase_nid_postfix(_Unwind_Context*); _Unwind_Reason_Code APS5_VABI __gxx_personality_v0_nid_postfix(...); --- a/core/libs/tests/GuestUnwindAccessors.cpp +++ b/core/libs/tests/GuestUnwindAccessors.cpp -#include "prx/libc/include/exceptions/Unwind.hpp" +#include "prx/libc/include/Api.hpp" ``` With that change, on the same merge: - The audit reports 0 errors; `public_headers` and the 64 `public_headers_compile_*` tests pass (65/65). - The test builds, and `guest_unwind_accessors` passes 3/3. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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!9775
No description provided.