Skip to content

Commit

Permalink
Merge remote-tracking branch 'LineageOS/lineage-21.0' into lineage-21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalvat-M committed Jun 23, 2024
2 parents c1f6e0b + 2557334 commit d735a46
Show file tree
Hide file tree
Showing 151 changed files with 10,356 additions and 2,399 deletions.
89 changes: 41 additions & 48 deletions bootstat/bootstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ std::string getSubreason(const std::string& content, size_t pos, bool quoted) {
return subReason;
}

bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) {
void addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) {
// Check for kernel panic types to refine information
if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) ||
(console.rfind("PC is at sysrq_handle_crash+") != std::string::npos)) {
Expand All @@ -842,63 +842,61 @@ bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) {
if (pos != std::string::npos) {
ret += "," + getSubreason(console, pos + strlen(sysrqSubreason), /* quoted */ true);
}
return true;
return;
}
if (console.rfind("Unable to handle kernel NULL pointer dereference at virtual address") !=
std::string::npos) {
ret = "kernel_panic,null";
return true;
return;
}
if (console.rfind("Kernel BUG at ") != std::string::npos) {
ret = "kernel_panic,bug";
return true;
return;
}

std::string panic("Kernel panic - not syncing: ");
auto pos = console.rfind(panic);
if (pos != std::string::npos) {
static const std::vector<std::pair<const std::string, const std::string>> panicReasons = {
{"Out of memory", "oom"},
{"out of memory", "oom"},
{"Oh boy, that early out of memory", "oom"}, // omg
{"BUG!", "bug"},
{"hung_task: blocked tasks", "hung"},
{"audit: ", "audit"},
{"scheduling while atomic", "atomic"},
{"Attempted to kill init!", "init"},
{"Requested init", "init"},
{"No working init", "init"},
{"Could not decompress init", "init"},
{"RCU Stall", "hung,rcu"},
{"stack-protector", "stack"},
{"kernel stack overflow", "stack"},
{"Corrupt kernel stack", "stack"},
{"low stack detected", "stack"},
{"corrupted stack end", "stack"},
{"subsys-restart: Resetting the SoC - modem crashed.", "modem"},
{"subsys-restart: Resetting the SoC - adsp crashed.", "adsp"},
{"subsys-restart: Resetting the SoC - dsps crashed.", "dsps"},
{"subsys-restart: Resetting the SoC - wcnss crashed.", "wcnss"},
};
if (pos == std::string::npos) return;

static const std::vector<std::pair<const std::string, const std::string>> panicReasons = {
{"Out of memory", "oom"},
{"out of memory", "oom"},
{"Oh boy, that early out of memory", "oom"}, // omg
{"BUG!", "bug"},
{"hung_task: blocked tasks", "hung"},
{"audit: ", "audit"},
{"scheduling while atomic", "atomic"},
{"Attempted to kill init!", "init"},
{"Requested init", "init"},
{"No working init", "init"},
{"Could not decompress init", "init"},
{"RCU Stall", "hung,rcu"},
{"stack-protector", "stack"},
{"kernel stack overflow", "stack"},
{"Corrupt kernel stack", "stack"},
{"low stack detected", "stack"},
{"corrupted stack end", "stack"},
{"subsys-restart: Resetting the SoC - modem crashed.", "modem"},
{"subsys-restart: Resetting the SoC - adsp crashed.", "adsp"},
{"subsys-restart: Resetting the SoC - dsps crashed.", "dsps"},
{"subsys-restart: Resetting the SoC - wcnss crashed.", "wcnss"},
};

ret = "kernel_panic";
for (auto& s : panicReasons) {
if (console.find(panic + s.first, pos) != std::string::npos) {
ret += "," + s.second;
return true;
}
ret = "kernel_panic";
for (auto& s : panicReasons) {
if (console.find(panic + s.first, pos) != std::string::npos) {
ret += "," + s.second;
return;
}
auto reason = getSubreason(console, pos + panic.length(), /* newline */ false);
if (reason.length() > 3) {
ret += "," + reason;
}
return true;
}
return false;
auto reason = getSubreason(console, pos + panic.length(), /* newline */ false);
if (reason.length() > 3) {
ret += "," + reason;
}
}

bool addKernelPanicSubReason(const std::string& content, std::string& ret) {
return addKernelPanicSubReason(pstoreConsole(content), ret);
void addKernelPanicSubReason(const std::string& content, std::string& ret) {
addKernelPanicSubReason(pstoreConsole(content), ret);
}

const char system_reboot_reason_property[] = "sys.boot.reason";
Expand Down Expand Up @@ -1079,12 +1077,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
}

// Check for kernel panics, allowed to override reboot command.
if (!addKernelPanicSubReason(console, ret) &&
// check for long-press power down
((console.rfind("Power held for ") != std::string::npos) ||
(console.rfind("charger: [") != std::string::npos))) {
ret = "cold";
}
(void)addKernelPanicSubReason(console, ret);
}

// TODO: use the HAL to get battery level (http://b/77725702).
Expand Down
24 changes: 17 additions & 7 deletions debuggerd/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ cc_defaults {
local_include_dirs: ["include"],
product_variables: {
debuggable: {
cflags: ["-UANDROID_DEBUGGABLE", "-DANDROID_DEBUGGABLE=1"],
}
cflags: [
"-UANDROID_DEBUGGABLE",
"-DANDROID_DEBUGGABLE=1",
],
},
},
}

Expand All @@ -32,9 +35,10 @@ cc_library_headers {
recovery_available: true,
vendor_ramdisk_available: true,
apex_available: [
"com.android.runtime",
"com.android.virt",
"//apex_available:platform",
],
],
}

cc_library_shared {
Expand Down Expand Up @@ -85,6 +89,7 @@ cc_library_static {

export_header_lib_headers: ["libdebuggerd_common_headers"],
export_include_dirs: ["tombstoned/include"],
apex_available: ["com.android.runtime"],
}

// Core implementation, linked into libdebuggerd_handler and the dynamic linker.
Expand All @@ -110,6 +115,9 @@ cc_library_static {

export_header_lib_headers: ["libdebuggerd_common_headers"],
export_include_dirs: ["include"],
apex_available: [
"com.android.runtime",
],
}

// Implementation with a no-op fallback.
Expand Down Expand Up @@ -251,7 +259,7 @@ cc_library_static {
],

static_libs: [
"libdexfile_support", // libunwindstack dependency
"libdexfile_support", // libunwindstack dependency
"libunwindstack",
"liblzma",
"libbase",
Expand Down Expand Up @@ -294,7 +302,7 @@ cc_library_static {
},
android: {
runtime_libs: [
"libdexfile", // libdexfile_support dependency
"libdexfile", // libdexfile_support dependency
],
},
},
Expand All @@ -311,6 +319,9 @@ cc_library_static {
header_libs: ["scudo_headers"],
},
},
apex_available: [
"com.android.runtime",
],
}

cc_binary {
Expand Down Expand Up @@ -486,7 +497,7 @@ cc_defaults {

header_libs: [
"bionic_libc_platform_headers",
"libdebuggerd_common_headers"
"libdebuggerd_common_headers",
],

static_libs: [
Expand Down Expand Up @@ -544,7 +555,6 @@ prebuilt_etc {
},
}


// This installs the "other" architecture (so 32-bit on 64-bit device).
prebuilt_etc {
name: "crash_dump.policy_other",
Expand Down
13 changes: 6 additions & 7 deletions debuggerd/client/debuggerd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ static std::string get_wchan_data(int fd, pid_t pid) {

bool debuggerd_trigger_dump(pid_t tid, DebuggerdDumpType dump_type, unsigned int timeout_ms,
unique_fd output_fd) {
pid_t pid = tid;
if (dump_type == kDebuggerdJavaBacktrace) {
// Java dumps always get sent to the tgid, so we need to resolve our tid to a tgid.
android::procinfo::ProcessInfo procinfo;
Expand All @@ -125,10 +124,10 @@ bool debuggerd_trigger_dump(pid_t tid, DebuggerdDumpType dump_type, unsigned int
log_error(output_fd, 0, "failed to get process info: %s", error.c_str());
return false;
}
pid = procinfo.pid;
tid = procinfo.pid;
}

LOG(INFO) << TAG "started dumping process " << pid;
LOG(INFO) << TAG "started dumping process " << tid;

// Rather than try to deal with poll() all the way through the flow, we update
// the socket timeout between each step (and only use poll() during the final
Expand Down Expand Up @@ -172,7 +171,7 @@ bool debuggerd_trigger_dump(pid_t tid, DebuggerdDumpType dump_type, unsigned int

InterceptRequest req = {
.dump_type = dump_type,
.pid = pid,
.pid = tid,
};

// Create an intermediate pipe to pass to the other end.
Expand Down Expand Up @@ -235,8 +234,8 @@ bool debuggerd_trigger_dump(pid_t tid, DebuggerdDumpType dump_type, unsigned int
// Send the signal.
const int signal = (dump_type == kDebuggerdJavaBacktrace) ? SIGQUIT : BIONIC_SIGNAL_DEBUGGER;
sigval val = {.sival_int = (dump_type == kDebuggerdNativeBacktrace) ? 1 : 0};
if (sigqueue(pid, signal, val) != 0) {
log_error(output_fd, errno, "failed to send signal to pid %d", pid);
if (sigqueue(tid, signal, val) != 0) {
log_error(output_fd, errno, "failed to send signal to pid %d", tid);
return false;
}

Expand Down Expand Up @@ -299,7 +298,7 @@ bool debuggerd_trigger_dump(pid_t tid, DebuggerdDumpType dump_type, unsigned int
}
}

LOG(INFO) << TAG "done dumping process " << pid;
LOG(INFO) << TAG "done dumping process " << tid;

return true;
}
Expand Down
1 change: 1 addition & 0 deletions debuggerd/crash_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ static void ReadCrashInfo(unique_fd& fd, siginfo_t* siginfo,
process_info->scudo_ring_buffer = crash_info->data.d.scudo_ring_buffer;
process_info->scudo_ring_buffer_size = crash_info->data.d.scudo_ring_buffer_size;
*recoverable_gwp_asan_crash = crash_info->data.d.recoverable_gwp_asan_crash;
process_info->crash_detail_page = crash_info->data.d.crash_detail_page;
FALLTHROUGH_INTENDED;
case 1:
case 2:
Expand Down
2 changes: 1 addition & 1 deletion debuggerd/crasher/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cc_defaults {
"-fstack-protector-all",
"-Wno-date-time",
],
tidy: false, // crasher.cpp tests many memory access errors
tidy: false, // crasher.cpp tests many memory access errors
srcs: ["crasher.cpp"],
arch: {
arm: {
Expand Down
9 changes: 9 additions & 0 deletions debuggerd/debuggerd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ int main(int argc, char* argv[]) {
}
}

// unfreeze if pid is frozen.
const std::string freeze_file = android::base::StringPrintf(
"/sys/fs/cgroup/uid_%d/pid_%d/cgroup.freeze", proc_info.uid, proc_info.pid);
if (std::string freeze_status;
android::base::ReadFileToString(freeze_file, &freeze_status) && freeze_status[0] == '1') {
android::base::WriteStringToFile("0", freeze_file);
// we don't restore the frozen state as this is considered a benign change.
}

unique_fd output_fd(fcntl(STDOUT_FILENO, F_DUPFD_CLOEXEC, 0));
if (output_fd.get() == -1) {
err(1, "failed to fcntl dup stdout");
Expand Down
Loading

0 comments on commit d735a46

Please sign in to comment.