From aed6b765c8c43050e42145b40edf94d12caa129d Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Sun, 19 Apr 2026 16:22:08 +0900 Subject: [PATCH] [Base/macOS] Align ucontext_t copy in arm64 signal handler Co-Authored-By: Will Martin --- src/xenia/base/exception_handler_posix.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/xenia/base/exception_handler_posix.cc b/src/xenia/base/exception_handler_posix.cc index 5e84f0b52..4167711cd 100644 --- a/src/xenia/base/exception_handler_posix.cc +++ b/src/xenia/base/exception_handler_posix.cc @@ -35,8 +35,17 @@ std::pair handlers_[kMaxHandlerCount]; static void ExceptionHandlerCallback(int signal_number, siginfo_t* signal_info, void* signal_context) { +#if XE_PLATFORM_MAC && XE_ARCH_ARM64 + // The Darwin kernel may pass an unaligned ucontext_t pointer to signal + // handlers; copy into an aligned local before reading. mcontext_t is a + // pointer on Mac, so writes still reach kernel storage via the pointer. + alignas(16) ucontext_t ucontext_storage; + std::memcpy(&ucontext_storage, signal_context, sizeof(ucontext_t)); + mcontext_t& mcontext = ucontext_storage.uc_mcontext; +#else mcontext_t& mcontext = reinterpret_cast(signal_context)->uc_mcontext; +#endif HostThreadContext thread_context;