[mono] Restore signal handlers during crash chaining#125835
Open
jpnurmi wants to merge 1 commit intodotnet:mainfrom
Open
[mono] Restore signal handlers during crash chaining#125835jpnurmi wants to merge 1 commit intodotnet:mainfrom
jpnurmi wants to merge 1 commit intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @akoeplinger, @matouskozak, @simonrozsival |
Contributor
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. |
This was referenced Mar 20, 2026
Author
|
@dotnet-policy-service agree company="Sentry" |
This was referenced Mar 25, 2026
Open
lateralusX
reviewed
Mar 31, 2026
jpnurmi
added a commit
to getsentry/sentry-native
that referenced
this pull request
Mar 31, 2026
- 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
src/tests/FunctionalTests/Android/Device_Emulator/CrashChaining/test_crash_chaining.c
Outdated
Show resolved
Hide resolved
src/tests/FunctionalTests/Android/Device_Emulator/CrashChaining/test_crash_chaining.c
Outdated
Show resolved
Hide resolved
lateralusX
reviewed
Mar 31, 2026
jpnurmi
commented
Mar 31, 2026
jpnurmi
added a commit
to getsentry/sentry-native
that referenced
this pull request
Mar 31, 2026
- 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
jpnurmi
added a commit
to getsentry/sentry-native
that referenced
this pull request
Mar 31, 2026
- 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
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.
23c53f4 to
d7d452d
Compare
This was referenced Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.