From 8fb6e3fdaf6bd965153024ed5bc06753f92dbbc8 Mon Sep 17 00:00:00 2001 From: Woody Lin Date: Fri, 8 May 2020 16:26:56 +0800 Subject: [PATCH] InitFatalReboot: Trigger panic explicitly for init_fatal_panic The exit of init panics the system *after* process context (mm, stack, ...etc.) are recycled, according to Linux kernel's 'do_exit' implementation. To preserve most init process context for debugging, triggers the panic via proc-sysrq explicitly. Note: after this change, there will be no "Attempt to kill init" panic when androidboot.init_fatal_panic is set. Test: Insert data abort fault in init, the full process context is preserved in memory dump captured after panic. Bug: 155940351 Change-Id: I3393bd00f99b8cb432cfa19a105b7d636b411764 (cherry picked from commit be1cf9006ab91e77114c19b8f596f8141d8e0b84) --- init/reboot.cpp | 2 -- init/reboot_utils.cpp | 4 ++++ init/reboot_utils.h | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/init/reboot.cpp b/init/reboot.cpp index e89f74aa0..ffd58a38d 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -66,8 +66,6 @@ #include "sigchld_handler.h" #include "util.h" -#define PROC_SYSRQ "/proc/sysrq-trigger" - using namespace std::literals; using android::base::boot_clock; diff --git a/init/reboot_utils.cpp b/init/reboot_utils.cpp index 485188ba0..76460a5df 100644 --- a/init/reboot_utils.cpp +++ b/init/reboot_utils.cpp @@ -29,6 +29,7 @@ #include #include "capabilities.h" +#include "reboot_utils.h" namespace android { namespace init { @@ -138,6 +139,9 @@ void __attribute__((noreturn)) InitFatalReboot(int signal_number) { LOG(ERROR) << backtrace->FormatFrameData(i); } if (init_fatal_panic) { + LOG(ERROR) << __FUNCTION__ << ": Trigger crash"; + android::base::WriteStringToFile("c", PROC_SYSRQ); + LOG(ERROR) << __FUNCTION__ << ": Sys-Rq failed to crash the system; fallback to exit()."; _exit(signal_number); } RebootSystem(ANDROID_RB_RESTART2, init_fatal_reboot_target); diff --git a/init/reboot_utils.h b/init/reboot_utils.h index 878ad9696..05bb9ae8e 100644 --- a/init/reboot_utils.h +++ b/init/reboot_utils.h @@ -18,6 +18,8 @@ #include +#define PROC_SYSRQ "/proc/sysrq-trigger" + namespace android { namespace init {