fix(libkernel): report unwind information for guest and host addresses on macOS #9263

Merged
imellag merged 2 commits from upstream-pr/9263 into main 2026-10-27 05:19:29 +00:00
imellag commented 2026-10-21 16:55:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-21T16:55:28Z.


What

On macOS a C++ exception that a title throws and catches itself can end the process: two unwind queries the title's own unwinder makes give it nothing to work with.

  • sceKernelGetModuleInfoForUnwind found the relinked image and its PT_GNU_EH_FRAME header, but left eh_frame_addr and eh_frame_size at zero, so the title's unwinder found no FDE for its own frames. The tables are now read with EhFrame::ReadTables over the image's load segments, as ModuleInfo does on Linux. eh_frame_size includes the zero terminator, as on Linux and as the existing debt entry records for firmware 13.60.
  • sceSysmoduleGetModuleInfoForUnwind read /proc/self/maps everywhere except Windows, so on macOS every call threw (failed to open /proc/self/maps). It now answers from mach_vm_region, with the image path from dladdr, as the Linux branch answers from the mapping.

Every library change is behind __APPLE__. The only line that changes on Linux and Windows is in GuestSysmodule.cpp: CheckUnwindInfo() is now called on every host, because macOS gets its own variant.

Carried over from #7332/#8481, which the open-PR limit closed.

Overlap: #7201 contains the same eh_frame read inside its macOS port; its review asks for that PR to be split into topics, and this is the unwind piece, plus the sysmodule fix #7201 does not have.

Tested

Current main (2026-10-26): I looked for the smallest set of open PRs that boots titles on macOS from main 035ac96edd: #10366, #10552, #7631, #7804, #11249, #10669, #10540, #11447, #11047, #11048, #10876 and this PR, plus a local VulkanDevice.cpp patch that no open PR covers yet. With it, Planet of Lana and God of War Sons of Sparta, relinked with that tree, start from New Game and run without errors (Lana in gameplay for 120 s, GoW to the Cyclops fight in 145 s). Without this PR, Lana still runs, but GoW stops with Terminating due to uncaught exception of type Il2CppExceptionWrapper.

Machine: Apple M4 Pro (24 GB), macOS 27.0.1, x86-64 under Rosetta 2, Apple clang 21.0.0. main does not build the libraries on macOS by itself, so everything ran on top of #8658 (0a6c0fdd2) with #9193 and the macOS RTLD_GLOBAL loader change from #7332 (2d500a0d36), which FMOD titles need to load at all.

  • guest_unwind_module_info (new on macOS): the test executable carries the __APS5DATA,__meta program headers that the macOS dl_iterate_phdr reads from a relinked image. It checks the header and frame addresses, a one-record and a two-record table (sizes 20 and 36, terminator included), an image without PT_GNU_EH_FRAME (all zero), and a table whose terminator lies outside the load segment (throws). Passes; with Module.cpp from main it fails ("wrong EH frame address").
  • guest_sysmodule (macOS variant of CheckUnwindInfo): a function in the test executable, one in the library, an anonymous page (empty name) and an unmapped address (throws), checked against mach_vm_region and dladdr. Passes; with Export.cpp from main it aborts.
  • Also pass: guest_dynamic_loader, guest_dynamic_loader_variant_names, unwind_record_bounds, unwind_callback_abi_*.
  • God of War Sons of Sparta (PPSA28997): without this change it stops about 4 s after start with Terminating due to uncaught exception of type Il2CppExceptionWrapper; the managed exception, read from sceKernelDebugWriteCppExceptionInfo with a local log line, is FMODUnity.BusNotFoundException, which the title normally catches. Without only the sysmodule part it stops with libc++abi: terminating due to uncaught exception of type std::runtime_error: sceSysmoduleGetModuleInfoForUnwind: failed to open /proc/self/maps. With both it opens its 38 FMOD banks and plays through to the Cyclops fight (27.0 fps in the fight, frame dumps checked).
  • python3 tools/check_conventions.py --base origin/main: all checks pass.

Not tested: Linux and Windows builds (no library change there), the full CTest suite.

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: #10419 and the later PRs split from #8658 (to build and run on macOS)
  • Fixes: none
  • Unblocks: PPSA28997 #1742, PPSA21703 #3745 (on macOS)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955240894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9263). Originally posted by [imellag](https://github.com/imellag) on 2026-10-21T16:55:28Z. --- ### What On macOS a C++ exception that a title throws and catches itself can end the process: two unwind queries the title's own unwinder makes give it nothing to work with. - **`sceKernelGetModuleInfoForUnwind`** found the relinked image and its `PT_GNU_EH_FRAME` header, but left `eh_frame_addr` and `eh_frame_size` at zero, so the title's unwinder found no FDE for its own frames. The tables are now read with `EhFrame::ReadTables` over the image's load segments, as `ModuleInfo` does on Linux. `eh_frame_size` includes the zero terminator, as on Linux and as the existing debt entry records for firmware 13.60. - **`sceSysmoduleGetModuleInfoForUnwind`** read `/proc/self/maps` everywhere except Windows, so on macOS every call threw (`failed to open /proc/self/maps`). It now answers from `mach_vm_region`, with the image path from `dladdr`, as the Linux branch answers from the mapping. Every library change is behind `__APPLE__`. The only line that changes on Linux and Windows is in `GuestSysmodule.cpp`: `CheckUnwindInfo()` is now called on every host, because macOS gets its own variant. Carried over from #7332/#8481, which the open-PR limit closed. Overlap: #7201 contains the same `eh_frame` read inside its macOS port; its review asks for that PR to be split into topics, and this is the unwind piece, plus the sysmodule fix #7201 does not have. ### Tested **Current `main` (2026-10-26):** I looked for the smallest set of open PRs that boots titles on macOS from `main` `035ac96edd`: #10366, #10552, #7631, #7804, #11249, #10669, #10540, #11447, #11047, #11048, #10876 and this PR, plus a local `VulkanDevice.cpp` patch that no open PR covers yet. With it, Planet of Lana and God of War Sons of Sparta, relinked with that tree, start from New Game and run without errors (Lana in gameplay for 120 s, GoW to the Cyclops fight in 145 s). Without this PR, Lana still runs, but GoW stops with `Terminating due to uncaught exception of type Il2CppExceptionWrapper`. **Machine:** Apple M4 Pro (24 GB), macOS 27.0.1, x86-64 under Rosetta 2, Apple clang 21.0.0. `main` does not build the libraries on macOS by itself, so everything ran on top of #8658 (0a6c0fdd2) with #9193 and the macOS `RTLD_GLOBAL` loader change from #7332 (2d500a0d36), which FMOD titles need to load at all. - `guest_unwind_module_info` (new on macOS): the test executable carries the `__APS5DATA,__meta` program headers that the macOS `dl_iterate_phdr` reads from a relinked image. It checks the header and frame addresses, a one-record and a two-record table (sizes 20 and 36, terminator included), an image without `PT_GNU_EH_FRAME` (all zero), and a table whose terminator lies outside the load segment (throws). Passes; with `Module.cpp` from `main` it fails ("wrong EH frame address"). - `guest_sysmodule` (macOS variant of `CheckUnwindInfo`): a function in the test executable, one in the library, an anonymous page (empty name) and an unmapped address (throws), checked against `mach_vm_region` and `dladdr`. Passes; with `Export.cpp` from `main` it aborts. - Also pass: `guest_dynamic_loader`, `guest_dynamic_loader_variant_names`, `unwind_record_bounds`, `unwind_callback_abi_*`. - **God of War Sons of Sparta (PPSA28997):** without this change it stops about 4 s after start with `Terminating due to uncaught exception of type Il2CppExceptionWrapper`; the managed exception, read from `sceKernelDebugWriteCppExceptionInfo` with a local log line, is `FMODUnity.BusNotFoundException`, which the title normally catches. Without only the sysmodule part it stops with `libc++abi: terminating due to uncaught exception of type std::runtime_error: sceSysmoduleGetModuleInfoForUnwind: failed to open /proc/self/maps`. With both it opens its 38 FMOD banks and plays through to the Cyclops fight (27.0 fps in the fight, frame dumps checked). - `python3 tools/check_conventions.py --base origin/main`: all checks pass. Not tested: Linux and Windows builds (no library change there), the full CTest suite. ### 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: #10419 and the later PRs split from #8658 (to build and run on macOS) - [x] Fixes: none - [x] Unblocks: PPSA28997 #1742, PPSA21703 #3745 (on macOS) - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!9263
No description provided.