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 be1cf9006a)
This commit is contained in:
Woody Lin 2020-05-08 16:26:56 +08:00
parent c00d57d353
commit 8fb6e3fdaf
3 changed files with 6 additions and 2 deletions

View file

@ -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;

View file

@ -29,6 +29,7 @@
#include <cutils/android_reboot.h>
#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);

View file

@ -18,6 +18,8 @@
#include <string>
#define PROC_SYSRQ "/proc/sysrq-trigger"
namespace android {
namespace init {