Skip to content

Commit

Permalink
Revert "[crashing] Improve crash chaining (#19973)"
Browse files Browse the repository at this point in the history
This reverts commit 7a0425e.

This change was causing this android issue: #20275
  • Loading branch information
naricc authored and marek-safar committed Sep 16, 2020
1 parent cdeef84 commit be2226b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 38 deletions.
4 changes: 2 additions & 2 deletions mono/mini/exceptions-amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static LONG CALLBACK seh_unhandled_exception_filter(EXCEPTION_POINTERS* ep)
#endif

if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), NULL, NULL, NULL);
mono_handle_native_crash (mono_get_signame (SIGSEGV), NULL, NULL);

return EXCEPTION_CONTINUE_SEARCH;
}
Expand Down Expand Up @@ -876,7 +876,7 @@ altstack_handle_and_restore (MonoContext *ctx, MonoObject *obj, guint32 flags)

if (!ji || (!stack_ovf && !nullref)) {
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), ctx, NULL, NULL);
mono_handle_native_crash (mono_get_signame (SIGSEGV), ctx, NULL);
// if couldn't dump or if mono_handle_native_crash returns, abort
abort ();
}
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/exceptions-ppc.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *s
}
if (!ji)
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), (MonoContext*)sigctx, siginfo, sigctx);
mono_handle_native_crash (mono_get_signame (SIGSEGV), (MonoContext*)sigctx, siginfo);
/* setup a call frame on the real stack so that control is returned there
* and exception handling can continue.
* The frame looks like:
Expand Down
4 changes: 2 additions & 2 deletions mono/mini/exceptions-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static LONG CALLBACK seh_unhandled_exception_filter(EXCEPTION_POINTERS* ep)
}
#endif
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), NULL, NULL, NULL);
mono_handle_native_crash (mono_get_signame (SIGSEGV), NULL, NULL);

return EXCEPTION_CONTINUE_SEARCH;
}
Expand Down Expand Up @@ -1140,7 +1140,7 @@ mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *s
MonoContext mctx;
mono_sigctx_to_monoctx (sigctx, &mctx);
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, siginfo, sigctx);
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, siginfo);
else
abort ();
}
Expand Down
25 changes: 11 additions & 14 deletions mono/mini/mini-exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3374,7 +3374,7 @@ print_stack_frame_to_string (StackFrameInfo *frame, MonoContext *ctx, gpointer d
* printing diagnostic information and aborting.
*/
void
mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, void *context)
mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info)
{
MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();

Expand All @@ -3384,20 +3384,17 @@ mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLE
sigemptyset (&sa.sa_mask);
sa.sa_flags = 0;

/* Mono has crashed - remove our handlers except SIGTERM, which is used by crash reporting */
/* TODO: Combine with mono_runtime_cleanup_handlers (but with an option to not de-allocate anything) */
if (mini_debug_options.handle_sigint) {
g_assert (sigaction (SIGINT, &sa, NULL) != -1);
}

/* Remove our SIGABRT handler */
g_assert (sigaction (SIGABRT, &sa, NULL) != -1);
g_assert (sigaction (SIGFPE, &sa, NULL) != -1);
g_assert (sigaction (SIGSYS, &sa, NULL) != -1);
g_assert (sigaction (SIGSEGV, &sa, NULL) != -1);
g_assert (sigaction (SIGQUIT, &sa, NULL) != -1);
g_assert (sigaction (SIGBUS, &sa, NULL) != -1);

/* On some systems we get a SIGILL when calling abort (), because it might
* fail to raise SIGABRT */
g_assert (sigaction (SIGILL, &sa, NULL) != -1);

/* Remove SIGCHLD, it uses the finalizer thread */
g_assert (sigaction (SIGCHLD, &sa, NULL) != -1);

/* Remove SIGQUIT, we are already dumping threads */
g_assert (sigaction (SIGQUIT, &sa, NULL) != -1);

#endif
Expand Down Expand Up @@ -3437,13 +3434,13 @@ mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLE
g_async_safe_printf ("=================================================================\n");
}

mono_post_native_crash_handler (signal, mctx, info, mono_do_crash_chaining, context);
mono_post_native_crash_handler (signal, mctx, info, mono_do_crash_chaining);
}

#else

void
mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, void *context)
mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info)
{
g_assert_not_reached ();
}
Expand Down
11 changes: 3 additions & 8 deletions mono/mini/mini-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ MONO_SIG_HANDLER_FUNC (static, sigabrt_signal_handler)
return;
mono_sigctx_to_monoctx (ctx, &mctx);
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (info->si_signo), &mctx, info, ctx);
mono_handle_native_crash (mono_get_signame (info->si_signo), &mctx, info);
else
abort ();
}
Expand All @@ -253,7 +253,7 @@ MONO_SIG_HANDLER_FUNC (static, sigterm_signal_handler)
// running. Returns FALSE on unrecoverable error.
if (mono_dump_start ()) {
// Process was killed from outside since crash reporting wasn't running yet.
mono_handle_native_crash (mono_get_signame (info->si_signo), &mctx, NULL, ctx);
mono_handle_native_crash (mono_get_signame (info->si_signo), &mctx, NULL);
} else {
// Crash reporting already running and we got a second SIGTERM from as part of thread-summarizing
if (!mono_threads_summarize_execute (&mctx, &output, &hashes, FALSE, NULL, 0))
Expand Down Expand Up @@ -1158,7 +1158,7 @@ mono_dump_native_crash_info (const char *signal, MonoContext *mctx, MONO_SIG_HAN
}

void
mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, gboolean crash_chaining, void *context)
mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, gboolean crash_chaining)
{
if (!crash_chaining) {
/*Android abort is a fluke, it doesn't abort, it triggers another segv. */
Expand All @@ -1168,11 +1168,6 @@ mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_
abort ();
#endif
}
mono_chain_signal (info->si_signo, info, context);

// we remove Mono's signal handlers from crashing signals in mono_handle_native_crash(), so re-raising will now allow the OS to handle the crash
// TODO: perhaps we can always use this to abort, instead of explicit exit()/abort() as we do above
raise (info->si_signo);
}
#endif /* !MONO_CROSS_COMPILE */

Expand Down
36 changes: 28 additions & 8 deletions mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3228,8 +3228,11 @@ MONO_SIG_HANDLER_FUNC (, mono_sigfpe_signal_handler)

mono_sigctx_to_monoctx (ctx, &mctx);
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGFPE), &mctx, info, ctx);
goto exit;
mono_handle_native_crash (mono_get_signame (SIGFPE), &mctx, info);
if (mono_do_crash_chaining) {
mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
goto exit;
}
}

mono_arch_handle_exception (ctx, exc);
Expand All @@ -3250,10 +3253,14 @@ MONO_SIG_HANDLER_FUNC (, mono_crashing_signal_handler)
mono_sigctx_to_monoctx (ctx, &mctx);
if (mono_dump_start ())
#if defined(HAVE_SIG_INFO) && !defined(HOST_WIN32) // info is a siginfo_t
mono_handle_native_crash (mono_get_signame (info->si_signo), &mctx, info, ctx);
mono_handle_native_crash (mono_get_signame (info->si_signo), &mctx, info);
#else
mono_handle_native_crash (mono_get_signame (SIGTERM), &mctx, info, ctx);
mono_handle_native_crash (mono_get_signame (SIGTERM), &mctx, info);
#endif
if (mono_do_crash_chaining) {
mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}

#if defined(MONO_ARCH_USE_SIGACTION) || defined(HOST_WIN32)
Expand Down Expand Up @@ -3333,7 +3340,11 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler)
if (!mono_do_crash_chaining && mono_chain_signal (MONO_SIG_HANDLER_PARAMS))
return;
if (mono_dump_start())
mono_handle_native_crash (mono_get_signame (signo), &mctx, info, ctx);
mono_handle_native_crash (mono_get_signame (signo), &mctx, info);
if (mono_do_crash_chaining) {
mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}
#endif

Expand Down Expand Up @@ -3372,7 +3383,7 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler)
} else {
// FIXME: This shouldn't run on the altstack
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, info, ctx);
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, info);
}
#endif
}
Expand All @@ -3383,14 +3394,23 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler)
return;

if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, (MONO_SIG_HANDLER_INFO_TYPE*)info, ctx);
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, (MONO_SIG_HANDLER_INFO_TYPE*)info);

if (mono_do_crash_chaining) {
mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}

if (mono_is_addr_implicit_null_check (fault_addr)) {
mono_arch_handle_exception (ctx, NULL);
} else {
if (mono_dump_start ())
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, (MONO_SIG_HANDLER_INFO_TYPE*)info, ctx);
mono_handle_native_crash (mono_get_signame (SIGSEGV), &mctx, (MONO_SIG_HANDLER_INFO_TYPE*)info);
if (mono_do_crash_chaining) {
mono_chain_signal (MONO_SIG_HANDLER_PARAMS);
return;
}
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/mini-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void
mono_dump_native_crash_info (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info);

void
mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, gboolean crash_chaining, void *context);
mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, gboolean crash_chaining);

gboolean
mono_is_addr_implicit_null_check (void *addr);
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/mini-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ mono_dump_native_crash_info (const char *signal, MonoContext *mctx, MONO_SIG_HAN
}

void
mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, gboolean crash_chaining, void *context)
mono_post_native_crash_handler (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *info, gboolean crash_chaining)
{
if (!crash_chaining)
abort ();
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ typedef gboolean (*MonoJitStackWalk) (StackFrameInfo *frame, MonoCont

void mono_exceptions_init (void);
gboolean mono_handle_exception (MonoContext *ctx, gpointer obj);
void mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo, void *context);
void mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo);
MONO_API void mono_print_thread_dump (void *sigctx);
MONO_API void mono_print_thread_dump_from_ctx (MonoContext *ctx);
void mono_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnwindOptions unwind_options, void *user_data);
Expand Down

0 comments on commit be2226b

Please sign in to comment.