diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp index 4db13aaa5..cd939ef88 100644 --- a/debuggerd/crash_dump.cpp +++ b/debuggerd/crash_dump.cpp @@ -160,6 +160,12 @@ static bool tombstoned_notify_completion(int tombstoned_socket) { return true; } +static void signal_handler(int) { + // We can't log easily, because the heap might be corrupt. + // Just die and let the surrounding log context explain things. + _exit(1); +} + static void abort_handler(pid_t target, const bool& tombstoned_connected, unique_fd& tombstoned_socket, unique_fd& output_fd, const char* abort_msg) { @@ -175,7 +181,6 @@ static void abort_handler(pid_t target, const bool& tombstoned_connected, dprintf(output_fd.get(), "crash_dump failed to dump process %d: %s\n", target, abort_msg); - // Don't dump ourselves. _exit(1); } @@ -201,6 +206,11 @@ int main(int argc, char** argv) { abort_handler(target, tombstoned_connected, tombstoned_socket, output_fd, abort_msg); }); + // Don't try to dump ourselves. + struct sigaction action = {}; + action.sa_handler = signal_handler; + debuggerd_register_handlers(&action); + if (argc != 2) { return 1; } diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp index 83db3a745..c031046f2 100644 --- a/debuggerd/handler/debuggerd_handler.cpp +++ b/debuggerd/handler/debuggerd_handler.cpp @@ -367,15 +367,5 @@ void debuggerd_init(debuggerd_callbacks_t* callbacks) { // Use the alternate signal stack if available so we can catch stack overflows. action.sa_flags |= SA_ONSTACK; - - sigaction(SIGABRT, &action, nullptr); - sigaction(SIGBUS, &action, nullptr); - sigaction(SIGFPE, &action, nullptr); - sigaction(SIGILL, &action, nullptr); - sigaction(SIGSEGV, &action, nullptr); -#if defined(SIGSTKFLT) - sigaction(SIGSTKFLT, &action, nullptr); -#endif - sigaction(SIGTRAP, &action, nullptr); - sigaction(DEBUGGER_SIGNAL, &action, nullptr); + debuggerd_register_handlers(&action); } diff --git a/debuggerd/include/debuggerd/handler.h b/debuggerd/include/debuggerd/handler.h index 302f4c20e..809f67049 100644 --- a/debuggerd/include/debuggerd/handler.h +++ b/debuggerd/include/debuggerd/handler.h @@ -39,4 +39,17 @@ void debuggerd_init(debuggerd_callbacks_t* callbacks); // to the log. #define DEBUGGER_SIGNAL (__SIGRTMIN + 3) +static void __attribute__((__unused__)) debuggerd_register_handlers(struct sigaction* action) { + sigaction(SIGABRT, action, nullptr); + sigaction(SIGBUS, action, nullptr); + sigaction(SIGFPE, action, nullptr); + sigaction(SIGILL, action, nullptr); + sigaction(SIGSEGV, action, nullptr); +#if defined(SIGSTKFLT) + sigaction(SIGSTKFLT, action, nullptr); +#endif + sigaction(SIGTRAP, action, nullptr); + sigaction(DEBUGGER_SIGNAL, action, nullptr); +} + __END_DECLS