macOS: host code cannot inspect or catch guest exceptions, so four guest exception tests fail #21538

Open
opened 2026-11-16 11:17:32 +00:00 by kurexw · 0 comments
kurexw commented 2026-11-16 11:17:32 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T11:17:32Z.


What fails

On macOS (Apple Silicon M4, macOS 27.2, full x86-64 build under Rosetta 2, main 04f7633c01), these tests fail. The Linux and Windows CI jobs don't run them on macOS:

Test Failure
guest_throw_bad_array_new_length inside catch (...), __cxa_current_exception_type_nid_postfix() returns null
guest_kernel_app_archive_mmap mmap_nid_postfix correctly refuses the archive-backed file and throws; the terminate handler's __cxa_current_exception_type_nid_postfix() is null, so the test exits 1
guest_libc_internal_exception_virtuals a guest-thrown std::future_error is not caught by host catch (const std::future_error&) and reaches std::terminate
run_report (not traced; possibly related) child-uncaught-missing-function: the report of a run that ended in std::terminate lacks "exit": "abort"

Cause

#927 keeps libc++abi as the host runtime on macOS, because libc++ binds __cxa_throw two-level. GCC_GLOBAL_ALIAS is defined only for __linux__, and the host __gxx_personality_v0 forward is #ifndef __APPLE__. Guest throws go through libc.prx (exception class ANYPC++\0). When a host frame catches one:

  • the guest personality installs the host landing pad (CallPersonality maps the host personality to __gxx_personality_v0_nid_postfix);
  • the landing pad calls libc++abi's __cxa_begin_catch, which treats ANYPC++\0 as a foreign exception and records it in libc++abi's own globals;
  • LibcException::globals.caught stays empty, so the guest __cxa_current_exception_type and __cxa_current_primary_exception see nothing;
  • host catch (const T&) compares libc++'s typeid(T) with the guest TypeRecord, which never match, so typed host catches of guest standard exceptions fail.

On Linux the aliases put host and guest code on the same runtime, so the tests pass there.

Options I see

  1. On Apple, when globals.caught is empty, have the guest current_exception queries read libc++abi's caught exception. __cxa_get_globals()->caughtExceptions is Itanium ABI. Recovering the _Unwind_Exception from it needs libc++abi's private sizeof(__cxa_exception), which ties libc to libc++abi internals. This doesn't fix typed host catches.
  2. Have the guest personality record a handler-frame catch in a host image in globals.caught, and drop that record from the exception's cleanup when libc++abi's __cxa_end_catch calls _Unwind_DeleteException. This needs care with rethrow and with cleanup-only frames. It doesn't fix typed host catches either.
  3. Treat these tests as Linux/Windows-only, because they rely on host code sharing the guest runtime, and skip them on Apple with a reason.

Is this a gap you'd like closed (and if so, which approach would you accept), or should the tests be marked as not applicable on macOS? I can take whichever you prefer.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6420032344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/21538). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-16T11:17:32Z. --- ### What fails On macOS (Apple Silicon M4, macOS 27.2, full x86-64 build under Rosetta 2, `main` 04f7633c01), these tests fail. The Linux and Windows CI jobs don't run them on macOS: | Test | Failure | |---|---| | `guest_throw_bad_array_new_length` | inside `catch (...)`, `__cxa_current_exception_type_nid_postfix()` returns null | | `guest_kernel_app_archive_mmap` | `mmap_nid_postfix` correctly refuses the archive-backed file and throws; the terminate handler's `__cxa_current_exception_type_nid_postfix()` is null, so the test exits 1 | | `guest_libc_internal_exception_virtuals` | a guest-thrown `std::future_error` is not caught by host `catch (const std::future_error&)` and reaches `std::terminate` | | `run_report` (not traced; possibly related) | `child-uncaught-missing-function`: the report of a run that ended in `std::terminate` lacks `"exit": "abort"` | ### Cause #927 keeps libc++abi as the host runtime on macOS, because libc++ binds `__cxa_throw` two-level. `GCC_GLOBAL_ALIAS` is defined only for `__linux__`, and the host `__gxx_personality_v0` forward is `#ifndef __APPLE__`. Guest throws go through libc.prx (exception class `ANYPC++\0`). When a host frame catches one: - the guest personality installs the host landing pad (`CallPersonality` maps the host personality to `__gxx_personality_v0_nid_postfix`); - the landing pad calls libc++abi's `__cxa_begin_catch`, which treats `ANYPC++\0` as a foreign exception and records it in libc++abi's own globals; - `LibcException::globals.caught` stays empty, so the guest `__cxa_current_exception_type` and `__cxa_current_primary_exception` see nothing; - host `catch (const T&)` compares libc++'s `typeid(T)` with the guest `TypeRecord`, which never match, so typed host catches of guest standard exceptions fail. On Linux the aliases put host and guest code on the same runtime, so the tests pass there. ### Options I see 1. On Apple, when `globals.caught` is empty, have the guest `current_exception` queries read libc++abi's caught exception. `__cxa_get_globals()->caughtExceptions` is Itanium ABI. Recovering the `_Unwind_Exception` from it needs libc++abi's private `sizeof(__cxa_exception)`, which ties libc to libc++abi internals. This doesn't fix typed host catches. 2. Have the guest personality record a handler-frame catch in a host image in `globals.caught`, and drop that record from the exception's cleanup when libc++abi's `__cxa_end_catch` calls `_Unwind_DeleteException`. This needs care with rethrow and with cleanup-only frames. It doesn't fix typed host catches either. 3. Treat these tests as Linux/Windows-only, because they rely on host code sharing the guest runtime, and skip them on Apple with a reason. Is this a gap you'd like closed (and if so, which approach would you accept), or should the tests be marked as not applicable on macOS? I can take whichever you prefer.
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#21538
No description provided.