Uh oh!
There was an error while loading. Please reload this page.
[mono] Restore signal handlers during crash chaining - #125835
Conversation
Tagging subscribers to this area: @akoeplinger, @matouskozak, @simonrozsival |
There was a problem hiding this comment.
Pull request overview
This PR fixes Mono’s native-crash handling behavior when crash chaining is enabled so that Mono does not reset key signal handlers to SIG_DFL during mono_handle_native_crash, which can otherwise cause secondary signals (notably on Android) to terminate the process before crash chaining completes.
Changes:
- Guard signal-handler resets in
mono_handle_native_crashbehind!mono_do_crash_chaining. - Add an Android functional test that installs a pre-Mono
SIGSEGVhandler, triggers a native crash, and validatesSIGABRTwas not reset toSIG_DFL. - Wire the test via the Android app template using an environment-variable gate (
TEST_CRASH_CHAINING).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/mono/mono/mini/mini-exceptions.c | Avoids resetting signal handlers to defaults when crash chaining is enabled. |
| src/tasks/AndroidAppBuilder/Templates/monodroid.c | Adds a crash-chaining functional test path (env-gated) and native test helpers. |
| src/tests/FunctionalTests/Android/Device_Emulator/CrashChaining/Program.cs | Managed entrypoint invoking the native test and mapping success to exit code 42. |
| src/tests/FunctionalTests/Android/Device_Emulator/CrashChaining/Android.Device_Emulator.CrashChaining.Test.csproj | New Android functional test project definition + env var injection. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jpnurmi
commented
Mar 23, 2026
@dotnet-policy-service agree company="Sentry" |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Mono: chain-at-start (preload requires dotnet/runtime#125835) - CoreCLR: preload (chain-at-start blocked by libsigchain) - Auto-build the NDK AAR for preload tests
- Mono: chain-at-start (preload requires dotnet/runtime#125835) - CoreCLR: preload (chain-at-start blocked by libsigchain) - Auto-build the NDK AAR for preload tests
23c53f4 to
d7d452dCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jpnurmi
commented
Apr 23, 2026
Hi, is there anything I can do to help land this? The CI failures all look unrelated. Happy to rebase again if that helps. |
lateralusX
commented
Apr 23, 2026
Give it a rebase and I make sure to carry it through. |
Expose static remove_signal_handler as mono_runtime_posix_restore_handler and use it in mono_handle_native_crash to restore pre-Mono signal handlers instead of resetting to SIG_DFL. The saved handlers are kept in the hash table so that mono_chain_signal can still chain to them if needed. When signal chaining is disabled, there are no saved handlers, so it falls back to SIG_DFL, same as before. Includes an Android functional test (CrashChaining) that installs pre-Mono SIGSEGV and SIGABRT handlers and verifies they are preserved during crash chaining.
d7d452d to
2faff44ComparelateralusX
commented
Apr 24, 2026
This only affects Mono related sources and CoreCLR failures appears in other PR's, System.Diagnostics.Tests.ProcessWaitingTests.ProcessSafeHandle_WaitForExitOrKillOnCancellationAsync_KillsOnCancellation. |
lateralusX
commented
Apr 24, 2026
/ba-g #127287 |
This change is part of the effort to fix native crash reporting for .NET Android apps (getsentry/sentry-dotnet#3954). Sentry would like to install signal handlers before Mono to capture native crashes. However,
mono_handle_native_crashunconditionally resetsSIGABRT,SIGILL,SIGCHLD, andSIGQUITtoSIG_DFL, even whencrash_chainingis enabled, killing the process before the chained handler can run.Expose static
remove_signal_handlerasmono_runtime_posix_restore_handlerand use it inmono_handle_native_crashto restore pre-Mono signal handlers instead of resetting toSIG_DFL. The saved handlers are kept in the hash table so thatmono_chain_signalcan still chain to them if needed. When signal chaining is disabled, there are no saved handlers, so it falls back toSIG_DFL, same as before.Includes an Android functional test (
CrashChaining) that verifies signal handlers are preserved during crash chaining.