28 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 c4884040ee Mac/iOS: Hook up the memory fault handler, including on ARM64
Apple platforms now use the same SIGSEGV/SIGBUS handler as Linux instead of
a Mach exception port. The Mach port was only set on the installing thread,
which is the loader thread, not the one running JIT code. ARM64 had no
context definition at all.

Also pass the thread state (not the mcontext) to the handler, accept SIGBUS
fault codes, and fix restoring a disabled altstack on Darwin.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-28 13:54:23 -06:00
Henrik Rydgård c8e0a35808 ExceptionHandlerSetup: chain signals we don't handle instead of returning
The POSIX handler returned early for any si_code other than SEGV_MAPERR/SEGV_ACCERR,
without passing the signal on. Returning from a fault handler re-executes the
faulting instruction, so anything that keeps faulting - an MTE fault on Android
arm64, a protection-key or shadow-stack fault - became a livelock at 100% CPU rather
than a crash with a usable report. It also swallowed SIGSEGV sent via kill()
(si_code SI_USER), and meant whatever handler was installed before us, such as a
crash reporter, never ran.

The code to chain properly was already there, just inside the 'we couldn't handle
this address' branch further down - factored out and used for both.
2026-08-31 12:56:01 +02:00
Henrik RydgårdandClaude Opus 5 a96dfc1390 Share SetupCRT with the unit tests so they can't pop a modal dialog
UnitTest.exe runs on CI and from tooling, where an assert or an abort() puts
up a message box that nothing will ever click, and the run just hangs until it
is killed. Headless already solved this; move its SetupCRT() into Common
(ExceptionHandlerSetup, which is where the rest of the process-level fault
setup lives) and call it from the unit tests too.

No behaviour change for headless. The OS-level SetErrorMode() call is now
guarded for UWP, which doesn't have it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 13:11:16 +02:00
Henrik Rydgård 34454f9d03 Claude's crazy exception handler hack 2026-07-27 23:41:13 +02:00
Jean-André Santoni 00b18e9f15 Backup and restore signal stack 2026-05-21 10:14:41 +02:00
oltolm 0230d5d464 ASAN 2025-04-23 22:08:40 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård cee71cbfc3 Add some extra room to the alt stack for exception handlers.
Motivated by some crashes seen in Google Play reports.
2022-12-30 11:25:45 +01:00
Henrik Rydgård f4b78bacd7 MacOSX: Apply potential fix for #16376
See #16376.

Tested not to break anything on MacOS Mojave. Unfortunately I can't test on Ventura on my x64 mac, it's too old.
2022-11-26 10:38:23 +01:00
Jan Beich 303efbc268 Common: add explicit <signal.h> for BSDs after 3ed7435012
Common/ExceptionHandlerSetup.cpp:298:6: error: no matching constructor for initialization of 'sigaltstack'
        if (sigaltstack(&signal_stack, nullptr)) {
            ^           ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/sys/signal.h:449:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
struct __stack_t {
       ^
/usr/include/sys/signal.h:434:19: note: expanded from macro '__stack_t'
 #define __stack_t sigaltstack
                   ^
/usr/include/sys/signal.h:449:8: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
/usr/include/sys/signal.h:434:19: note: expanded from macro '__stack_t'
 #define __stack_t sigaltstack
                   ^
/usr/include/sys/signal.h:449:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided
/usr/include/sys/signal.h:434:19: note: expanded from macro '__stack_t'
 #define __stack_t sigaltstack
                   ^
2022-07-09 16:09:37 +00:00
Henrik Rydgård f4a6d291e1 Common: Capitalize setCurrentThreadName(). 2021-04-30 23:02:36 -07:00
Henrik Rydgård 15382d5f94 Move threading utils from native to Common 2020-10-01 09:27:25 +02:00
Unknown W. Brackets 90344fdee5 Exception: Don't trust sigaltstack().
Let's just track our allocation separately and free it, always.
2020-08-26 21:44:38 -07:00
Henrik Rydgård e8a9845d93 First step of cleaning up Log.h. Plus a few other bits and bobs. 2020-08-16 14:48:54 +02:00
Henrik Rydgård b2d6eef65d UninstallExceptionHandler: Zero-initialize some structs. I've seen some weird crashes on the free() on Android. 2020-08-10 21:54:49 +02:00
Henrik Rydgård 49ab71dc7c ExceptionHandler uninstall: Don't crash if no exception handler already installed. 2020-07-27 16:54:50 +02:00
Henrik Rydgård 617bbcfb87 Step 1 of removing PanicAlert 2020-07-19 20:33:25 +02:00
Henrik Rydgård f5fd27c3b6 Buildfix. Checking _POSIX_VERSION is not recommended anyway. 2020-07-15 13:53:20 +02:00
Henrik Rydgård 056999a691 Refactor MachineContext.h to reduce ifdefs elsewhere.
Also fixes Windows on ARM64 (at least the build).
2020-07-14 13:47:25 +02:00
Henrik Rydgård 6f97c3d422 Various platform buildfixes 2020-07-14 09:25:59 +02:00
Henrik Rydgård a56f391713 Make fastmem memory exceptions report the exceptions to Core correctly. 2020-07-14 09:25:45 +02:00
Henrik Rydgard 15c7358e80 Try USE_SIGACTION_ON_APPLE on IOS. 2020-07-14 09:25:45 +02:00
Henrik Rydgard fdcf4f06f2 Add x64Analyzer to Android.mk. Some minor cleanup 2020-07-14 09:25:45 +02:00
Henrik Rydgård 96a40bb36d Exceptions: A bit more consistency in callback registeration. 2020-07-14 09:25:45 +02:00
Henrik Rydgård c3016fe6a5 Mac/Linux buildfixes 2020-07-14 09:25:45 +02:00
Henrik Rydgard c988d42b04 ARM/ARM64 instruction analysis, hook up to handler 2020-07-14 09:25:45 +02:00
Henrik Rydgard aa802ecc0f Skip bad reads/writes by the guest executable. 2020-07-14 09:25:45 +02:00
Henrik Rydgard 1fce6de8b1 Simple exception handler so we can ignore accesses that happen within the PSP memory space. 2020-07-14 09:25:45 +02:00