-
-
Save anonymous/569e860dd7e73bde0d8d098f95143662 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/mono/mini/jit.h b/mono/mini/jit.h | |
index ed5eca5..c63d927 100644 | |
--- a/mono/mini/jit.h | |
+++ b/mono/mini/jit.h | |
@@ -91,6 +91,9 @@ mono_get_jit_info_from_method (MonoDomain *domain, MonoMethod *method); | |
MONO_API MONO_RT_EXTERNAL_ONLY void * | |
mono_aot_get_method (MonoDomain *domain, MonoMethod *method); | |
+MONO_API MONO_RT_EXTERNAL_ONLY void | |
+mono_runtime_install_crash_handler (mono_bool (*crash_cb) (int dummy, void *info, void *context)); | |
+ | |
MONO_END_DECLS | |
#endif | |
diff --git a/mono/mini/mini-posix.c b/mono/mini/mini-posix.c | |
index 6f6e266..8c82133 100644 | |
--- a/mono/mini/mini-posix.c | |
+++ b/mono/mini/mini-posix.c | |
@@ -222,9 +222,8 @@ MONO_SIG_HANDLER_FUNC (static, sigabrt_signal_handler) | |
if (mono_thread_internal_current ()) | |
ji = mono_jit_info_table_find_internal (mono_domain_get (), (char *)mono_arch_ip_from_context (ctx), TRUE, TRUE); | |
if (!ji) { | |
- if (mono_chain_signal (MONO_SIG_HANDLER_PARAMS)) | |
+ if (mono_run_crash_handlers (MONO_SIG_HANDLER_PARAMS)) | |
return; | |
- mono_handle_native_sigsegv (SIGABRT, ctx, info); | |
} | |
} | |
@@ -367,6 +366,7 @@ MONO_SIG_HANDLER_FUNC (static, profiler_signal_handler) | |
mono_hazard_pointer_restore_for_signal_handler (hp_save_index); | |
errno = old_errno; | |
+ /* Non fatal */ | |
mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
} | |
@@ -383,6 +383,7 @@ MONO_SIG_HANDLER_FUNC (static, sigquit_signal_handler) | |
mono_threads_request_thread_dump (); | |
+ /* Non fatal */ | |
mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
} | |
@@ -392,6 +393,7 @@ MONO_SIG_HANDLER_FUNC (static, sigusr2_signal_handler) | |
mono_trace_enable (!enabled); | |
+ /* Non fatal */ | |
mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
} | |
diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c | |
index a9c8701..43af695 100644 | |
--- a/mono/mini/mini-runtime.c | |
+++ b/mono/mini/mini-runtime.c | |
@@ -2742,6 +2742,45 @@ mono_llvmonly_get_imt_trampoline (MonoVTable *vtable, MonoDomain *domain, MonoIM | |
return res; | |
} | |
+ | |
+ | |
+static mono_bool (*mono_crash_handler) (int dummy, void *info, void *context); | |
+/** | |
+ * mono_runtime_install_crash_handler: | |
+ * | |
+ * Installs a crash handler that will be called when the runtime detects a fatal error. | |
+ * | |
+ * If @crash_rb returns TRUE the runtime will not perform signal chaining or run it's normal crash dumping. | |
+ * The runtime will not try to recover when TRUE is returned. | |
+ * The callback is called once, before signal chaining and built'in crash handling. | |
+ * | |
+ * On posix systems @info is a siginfo_t | |
+ * On windows systems @info is a EXCEPTION_POINTERS | |
+ */ | |
+void | |
+mono_runtime_install_crash_handler (mono_bool (*crash_cb) (int dummy, void *info, void *context)) | |
+{ | |
+ mono_crash_handler = crash_cb; | |
+} | |
+ | |
+static gboolean | |
+MONO_SIG_HANDLER_SIGNATURE (mono_run_crash_handlers) | |
+{ | |
+ if (mono_crash_handler && mono_crash_handler (MONO_SIG_HANDLER_PARAMS)) | |
+ return TRUE; | |
+ | |
+ if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS)) | |
+ return TRUE; | |
+ | |
+ mono_handle_native_sigsegv (MONO_SIG_HANDLER_PARAMS); | |
+ if (mono_do_crash_chaining) { | |
+ mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
+ return; | |
+ } | |
+ | |
+ return FALSE; | |
+} | |
+ | |
MONO_SIG_HANDLER_FUNC (, mono_sigfpe_signal_handler) | |
{ | |
MonoException *exc = NULL; | |
@@ -2765,14 +2804,8 @@ MONO_SIG_HANDLER_FUNC (, mono_sigfpe_signal_handler) | |
#endif | |
if (!ji) { | |
- if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS)) | |
- return; | |
- | |
- mono_handle_native_sigsegv (SIGSEGV, ctx, info); | |
- if (mono_do_crash_chaining) { | |
- mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
+ if (mono_run_crash_handlers (MONO_SIG_HANDLER_PARAMS)) | |
return; | |
- } | |
} | |
mono_arch_handle_exception (ctx, exc); | |
@@ -2832,13 +2865,8 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler) | |
/* The thread might no be registered with the runtime */ | |
if (!mono_domain_get () || !jit_tls) { | |
- if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS)) | |
+ if (mono_run_crash_handlers (MONO_SIG_HANDLER_PARAMS)) | |
return; | |
- mono_handle_native_sigsegv (SIGSEGV, ctx, info); | |
- if (mono_do_crash_chaining) { | |
- mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
- return; | |
- } | |
} | |
#endif | |
@@ -2870,7 +2898,7 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler) | |
g_assert_not_reached (); | |
} else { | |
/* The original handler might not like that it is executed on an altstack... */ | |
- if (!ji && mono_chain_signal (MONO_SIG_HANDLER_PARAMS)) | |
+ if (!ji && mono_run_crash_handlers (MONO_SIG_HANDLER_PARAMS)) | |
return; | |
mono_arch_handle_altstack_exception (ctx, info, info->si_addr, FALSE); | |
@@ -2878,15 +2906,8 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler) | |
#else | |
if (!ji) { | |
- if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS)) | |
+ if (mono_run_crash_handlers (MONO_SIG_HANDLER_PARAMS)) | |
return; | |
- | |
- mono_handle_native_sigsegv (SIGSEGV, ctx, info); | |
- | |
- if (mono_do_crash_chaining) { | |
- mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | |
- return; | |
- } | |
} | |
mono_arch_handle_exception (ctx, NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment