Loading debuggerd/Android.bp +4 −7 Original line number Diff line number Diff line Loading @@ -9,10 +9,6 @@ cc_defaults { "-Os", ], // util.cpp gets async signal safe logging via libc_logging, // which defines its interface in bionic private headers. include_dirs: ["bionic/libc"], local_include_dirs: ["include"], } Loading @@ -26,7 +22,7 @@ cc_library_static { ], whole_static_libs: [ "libc_logging", "libasync_safe", "libcutils", "libbase", ], Loading @@ -39,7 +35,7 @@ cc_library_static { srcs: ["handler/debuggerd_handler.cpp"], whole_static_libs: [ "libc_logging", "libasync_safe", "libdebuggerd", ], Loading Loading @@ -70,6 +66,7 @@ cc_library_static { whole_static_libs: [ "libdebuggerd_handler_core", "libtombstoned_client", "libasync_safe", "libbase", "libdebuggerd", "libbacktrace", Loading Loading @@ -166,6 +163,7 @@ cc_test { "tombstoned_client.cpp", "util.cpp" ], static_libs: ["libasync_safe"], }, }, Loading @@ -178,7 +176,6 @@ cc_test { static_libs: [ "libdebuggerd", "libc_logging", ], local_include_dirs: [ Loading debuggerd/handler/debuggerd_fallback.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ #include <android-base/file.h> #include <android-base/unique_fd.h> #include <async_safe/log.h> #include "debuggerd/handler.h" #include "debuggerd/tombstoned.h" Loading @@ -47,8 +48,6 @@ #include "backtrace.h" #include "tombstone.h" #include "private/libc_logging.h" using android::base::unique_fd; extern "C" void __linker_enable_fallback_allocator(); Loading Loading @@ -81,7 +80,7 @@ static void iterate_siblings(bool (*callback)(pid_t, int), int output_fd) { DIR* dir = opendir(buf); if (!dir) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to open %s: %s", buf, strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to open %s: %s", buf, strerror(errno)); return; } Loading Loading @@ -145,7 +144,8 @@ static void trace_handler(siginfo_t* info, ucontext_t* ucontext) { static pthread_mutex_t trace_mutex = PTHREAD_MUTEX_INITIALIZER; int ret = pthread_mutex_trylock(&trace_mutex); if (ret != 0) { __libc_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_try_lock failed: %s", strerror(ret)); async_safe_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_try_lock failed: %s", strerror(ret)); return; } Loading @@ -167,7 +167,8 @@ static void trace_handler(siginfo_t* info, ucontext_t* ucontext) { // receiving our signal. unique_fd pipe_read, pipe_write; if (!Pipe(&pipe_read, &pipe_write)) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to create pipe: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to create pipe: %s", strerror(errno)); return false; } Loading @@ -180,8 +181,8 @@ static void trace_handler(siginfo_t* info, ucontext_t* ucontext) { siginfo.si_uid = getuid(); if (syscall(__NR_rt_tgsigqueueinfo, getpid(), tid, DEBUGGER_SIGNAL, &siginfo) != 0) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to send trace signal to %d: %s", tid, strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to send trace signal to %d: %s", tid, strerror(errno)); return false; } Loading Loading @@ -209,7 +210,7 @@ static void crash_handler(siginfo_t* info, ucontext_t* ucontext, void* abort_mes static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER; int ret = pthread_mutex_lock(&crash_mutex); if (ret != 0) { __libc_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); async_safe_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); return; } Loading debuggerd/handler/debuggerd_handler.cpp +37 −31 Original line number Diff line number Diff line Loading @@ -48,8 +48,7 @@ #include <sys/wait.h> #include <unistd.h> #include "private/bionic_futex.h" #include "private/libc_logging.h" #include <async_safe/log.h> // see man(2) prctl, specifically the section about PR_GET_NAME #define MAX_TASK_NAME_LEN (16) Loading @@ -62,6 +61,10 @@ #define CRASH_DUMP_PATH "/system/bin/" CRASH_DUMP_NAME static inline void futex_wait(volatile void* ftx, int value) { syscall(__NR_futex, ftx, FUTEX_WAIT, value, nullptr, nullptr, 0); } class ErrnoRestorer { public: ErrnoRestorer() : saved_errno_(errno) { Loading @@ -82,11 +85,12 @@ static debuggerd_callbacks_t g_callbacks; // Mutex to ensure only one crashing thread dumps itself. static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER; // Don't use __libc_fatal because it exits via abort, which might put us back into a signal handler. // Don't use async_safe_fatal because it exits via abort, which might put us back into // a signal handler. static void __noreturn __printflike(1, 2) fatal(const char* fmt, ...) { va_list args; va_start(args, fmt); __libc_format_log_va_list(ANDROID_LOG_FATAL, "libc", fmt, args); async_safe_format_log_va_list(ANDROID_LOG_FATAL, "libc", fmt, args); _exit(1); } Loading @@ -96,7 +100,7 @@ static void __noreturn __printflike(1, 2) fatal_errno(const char* fmt, ...) { va_start(args, fmt); char buf[4096]; __libc_format_buffer_va_list(buf, sizeof(buf), fmt, args); async_safe_format_buffer_va_list(buf, sizeof(buf), fmt, args); fatal("%s: %s", buf, strerror(err)); } Loading @@ -120,7 +124,7 @@ static void log_signal_summary(int signum, const siginfo_t* info) { } if (signum == DEBUGGER_SIGNAL) { __libc_format_log(ANDROID_LOG_INFO, "libc", "Requested dump for tid %d (%s)", gettid(), async_safe_format_log(ANDROID_LOG_INFO, "libc", "Requested dump for tid %d (%s)", gettid(), thread_name); return; } Loading Loading @@ -166,14 +170,14 @@ static void log_signal_summary(int signum, const siginfo_t* info) { char addr_desc[32]; // ", fault addr 0x1234" addr_desc[0] = code_desc[0] = 0; if (info != nullptr) { __libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code); async_safe_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code); if (has_address) { __libc_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr); async_safe_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr); } } __libc_format_log(ANDROID_LOG_FATAL, "libc", "Fatal signal %d (%s)%s%s in tid %d (%s)", signum, signal_name, code_desc, addr_desc, gettid(), thread_name); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "Fatal signal %d (%s)%s%s in tid %d (%s)", signum, signal_name, code_desc, addr_desc, gettid(), thread_name); } /* Loading @@ -182,7 +186,7 @@ static void log_signal_summary(int signum, const siginfo_t* info) { static bool have_siginfo(int signum) { struct sigaction old_action; if (sigaction(signum, nullptr, &old_action) < 0) { __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s", async_safe_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s", strerror(errno)); return false; } Loading @@ -207,7 +211,7 @@ static void raise_caps() { capdata[1].inheritable = capdata[1].permitted; if (capset(&capheader, &capdata[0]) == -1) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "capset failed: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "capset failed: %s", strerror(errno)); } } Loading @@ -217,8 +221,8 @@ static void raise_caps() { for (unsigned long i = 0; i < 64; ++i) { if (capmask & (1ULL << i)) { if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, i, 0, 0) != 0) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to raise ambient capability %lu: %s", i, strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to raise ambient capability %lu: %s", i, strerror(errno)); } } } Loading Loading @@ -260,8 +264,8 @@ static int debuggerd_dispatch_pseudothread(void* arg) { // Don't use fork(2) to avoid calling pthread_atfork handlers. int forkpid = clone(nullptr, nullptr, 0, nullptr); if (forkpid == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "failed to fork in debuggerd signal handler: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "failed to fork in debuggerd signal handler: %s", strerror(errno)); } else if (forkpid == 0) { TEMP_FAILURE_RETRY(dup2(pipefds[1], STDOUT_FILENO)); close(pipefds[0]); Loading @@ -271,8 +275,9 @@ static int debuggerd_dispatch_pseudothread(void* arg) { char main_tid[10]; char pseudothread_tid[10]; __libc_format_buffer(main_tid, sizeof(main_tid), "%d", thread_info->crashing_tid); __libc_format_buffer(pseudothread_tid, sizeof(pseudothread_tid), "%d", thread_info->pseudothread_tid); async_safe_format_buffer(main_tid, sizeof(main_tid), "%d", thread_info->crashing_tid); async_safe_format_buffer(pseudothread_tid, sizeof(pseudothread_tid), "%d", thread_info->pseudothread_tid); execl(CRASH_DUMP_PATH, CRASH_DUMP_NAME, main_tid, pseudothread_tid, nullptr); Loading @@ -282,15 +287,16 @@ static int debuggerd_dispatch_pseudothread(void* arg) { char buf[4]; ssize_t rc = TEMP_FAILURE_RETRY(read(pipefds[0], &buf, sizeof(buf))); if (rc == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe failed: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe failed: %s", strerror(errno)); } else if (rc == 0) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper failed to exec"); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper failed to exec"); } else if (rc != 1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", async_safe_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe returned unexpected value: %zd", rc); } else { if (buf[0] != '\1') { __libc_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper reported failure"); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper reported failure"); } else { thread_info->crash_dump_started = true; } Loading @@ -300,10 +306,10 @@ static int debuggerd_dispatch_pseudothread(void* arg) { // Don't leave a zombie child. int status; if (TEMP_FAILURE_RETRY(waitpid(forkpid, &status, 0)) == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "failed to wait for crash_dump helper: %s", async_safe_format_log(ANDROID_LOG_FATAL, "libc", "failed to wait for crash_dump helper: %s", strerror(errno)); } else if (WIFSTOPPED(status) || WIFSIGNALED(status)) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper crashed or stopped"); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper crashed or stopped"); thread_info->crash_dump_started = false; } } Loading Loading @@ -383,7 +389,7 @@ static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void* c // Only allow one thread to handle a signal at a time. int ret = pthread_mutex_lock(&crash_mutex); if (ret != 0) { __libc_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); async_safe_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); return; } Loading Loading @@ -419,10 +425,10 @@ static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void* c } // Wait for the child to start... __futex_wait(&thread_info.pseudothread_tid, -1, nullptr); futex_wait(&thread_info.pseudothread_tid, -1); // and then wait for it to finish. __futex_wait(&thread_info.pseudothread_tid, child_pid, nullptr); futex_wait(&thread_info.pseudothread_tid, child_pid); // Restore PR_SET_DUMPABLE to its original value. if (prctl(PR_SET_DUMPABLE, orig_dumpable) != 0) { Loading debuggerd/tombstoned_client.cpp +13 −13 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ #include <utility> #include <android-base/unique_fd.h> #include <async_safe/log.h> #include <cutils/sockets.h> #include "debuggerd/protocol.h" #include "debuggerd/util.h" #include "private/libc_logging.h" using android::base::unique_fd; Loading @@ -34,7 +34,7 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp unique_fd sockfd(socket_local_client(kTombstonedCrashSocketName, ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET)); if (sockfd == -1) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to connect to tombstoned: %s", async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to connect to tombstoned: %s", strerror(errno)); return false; } Loading @@ -43,7 +43,7 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp packet.packet_type = CrashPacketType::kDumpRequest; packet.packet.dump_request.pid = pid; if (TEMP_FAILURE_RETRY(write(sockfd, &packet, sizeof(packet))) != sizeof(packet)) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to write DumpRequest packet: %s", async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to write DumpRequest packet: %s", strerror(errno)); return false; } Loading @@ -51,11 +51,11 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp unique_fd tmp_output_fd; ssize_t rc = recv_fd(sockfd, &packet, sizeof(packet), &tmp_output_fd); if (rc == -1) { __libc_format_log(ANDROID_LOG_ERROR, "libc", async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to read response to DumpRequest packet: %s", strerror(errno)); return false; } else if (rc != sizeof(packet)) { __libc_format_log( async_safe_format_log( ANDROID_LOG_ERROR, "libc", "received DumpRequest response packet of incorrect length (expected %zu, got %zd)", sizeof(packet), rc); Loading @@ -67,7 +67,7 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp // a regular fd, and writing to an fd with O_APPEND). int flags = fcntl(tmp_output_fd.get(), F_GETFL); if (fcntl(tmp_output_fd.get(), F_SETFL, flags | O_APPEND) != 0) { __libc_format_log(ANDROID_LOG_WARN, "libc", "failed to set output fd flags: %s", async_safe_format_log(ANDROID_LOG_WARN, "libc", "failed to set output fd flags: %s", strerror(errno)); } Loading debuggerd/util.cpp +0 −2 Original line number Diff line number Diff line Loading @@ -24,8 +24,6 @@ #include <cutils/sockets.h> #include <debuggerd/protocol.h> #include "private/libc_logging.h" using android::base::unique_fd; ssize_t send_fd(int sockfd, const void* data, size_t len, unique_fd fd) { Loading Loading
debuggerd/Android.bp +4 −7 Original line number Diff line number Diff line Loading @@ -9,10 +9,6 @@ cc_defaults { "-Os", ], // util.cpp gets async signal safe logging via libc_logging, // which defines its interface in bionic private headers. include_dirs: ["bionic/libc"], local_include_dirs: ["include"], } Loading @@ -26,7 +22,7 @@ cc_library_static { ], whole_static_libs: [ "libc_logging", "libasync_safe", "libcutils", "libbase", ], Loading @@ -39,7 +35,7 @@ cc_library_static { srcs: ["handler/debuggerd_handler.cpp"], whole_static_libs: [ "libc_logging", "libasync_safe", "libdebuggerd", ], Loading Loading @@ -70,6 +66,7 @@ cc_library_static { whole_static_libs: [ "libdebuggerd_handler_core", "libtombstoned_client", "libasync_safe", "libbase", "libdebuggerd", "libbacktrace", Loading Loading @@ -166,6 +163,7 @@ cc_test { "tombstoned_client.cpp", "util.cpp" ], static_libs: ["libasync_safe"], }, }, Loading @@ -178,7 +176,6 @@ cc_test { static_libs: [ "libdebuggerd", "libc_logging", ], local_include_dirs: [ Loading
debuggerd/handler/debuggerd_fallback.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ #include <android-base/file.h> #include <android-base/unique_fd.h> #include <async_safe/log.h> #include "debuggerd/handler.h" #include "debuggerd/tombstoned.h" Loading @@ -47,8 +48,6 @@ #include "backtrace.h" #include "tombstone.h" #include "private/libc_logging.h" using android::base::unique_fd; extern "C" void __linker_enable_fallback_allocator(); Loading Loading @@ -81,7 +80,7 @@ static void iterate_siblings(bool (*callback)(pid_t, int), int output_fd) { DIR* dir = opendir(buf); if (!dir) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to open %s: %s", buf, strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to open %s: %s", buf, strerror(errno)); return; } Loading Loading @@ -145,7 +144,8 @@ static void trace_handler(siginfo_t* info, ucontext_t* ucontext) { static pthread_mutex_t trace_mutex = PTHREAD_MUTEX_INITIALIZER; int ret = pthread_mutex_trylock(&trace_mutex); if (ret != 0) { __libc_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_try_lock failed: %s", strerror(ret)); async_safe_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_try_lock failed: %s", strerror(ret)); return; } Loading @@ -167,7 +167,8 @@ static void trace_handler(siginfo_t* info, ucontext_t* ucontext) { // receiving our signal. unique_fd pipe_read, pipe_write; if (!Pipe(&pipe_read, &pipe_write)) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to create pipe: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to create pipe: %s", strerror(errno)); return false; } Loading @@ -180,8 +181,8 @@ static void trace_handler(siginfo_t* info, ucontext_t* ucontext) { siginfo.si_uid = getuid(); if (syscall(__NR_rt_tgsigqueueinfo, getpid(), tid, DEBUGGER_SIGNAL, &siginfo) != 0) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to send trace signal to %d: %s", tid, strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to send trace signal to %d: %s", tid, strerror(errno)); return false; } Loading Loading @@ -209,7 +210,7 @@ static void crash_handler(siginfo_t* info, ucontext_t* ucontext, void* abort_mes static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER; int ret = pthread_mutex_lock(&crash_mutex); if (ret != 0) { __libc_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); async_safe_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); return; } Loading
debuggerd/handler/debuggerd_handler.cpp +37 −31 Original line number Diff line number Diff line Loading @@ -48,8 +48,7 @@ #include <sys/wait.h> #include <unistd.h> #include "private/bionic_futex.h" #include "private/libc_logging.h" #include <async_safe/log.h> // see man(2) prctl, specifically the section about PR_GET_NAME #define MAX_TASK_NAME_LEN (16) Loading @@ -62,6 +61,10 @@ #define CRASH_DUMP_PATH "/system/bin/" CRASH_DUMP_NAME static inline void futex_wait(volatile void* ftx, int value) { syscall(__NR_futex, ftx, FUTEX_WAIT, value, nullptr, nullptr, 0); } class ErrnoRestorer { public: ErrnoRestorer() : saved_errno_(errno) { Loading @@ -82,11 +85,12 @@ static debuggerd_callbacks_t g_callbacks; // Mutex to ensure only one crashing thread dumps itself. static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER; // Don't use __libc_fatal because it exits via abort, which might put us back into a signal handler. // Don't use async_safe_fatal because it exits via abort, which might put us back into // a signal handler. static void __noreturn __printflike(1, 2) fatal(const char* fmt, ...) { va_list args; va_start(args, fmt); __libc_format_log_va_list(ANDROID_LOG_FATAL, "libc", fmt, args); async_safe_format_log_va_list(ANDROID_LOG_FATAL, "libc", fmt, args); _exit(1); } Loading @@ -96,7 +100,7 @@ static void __noreturn __printflike(1, 2) fatal_errno(const char* fmt, ...) { va_start(args, fmt); char buf[4096]; __libc_format_buffer_va_list(buf, sizeof(buf), fmt, args); async_safe_format_buffer_va_list(buf, sizeof(buf), fmt, args); fatal("%s: %s", buf, strerror(err)); } Loading @@ -120,7 +124,7 @@ static void log_signal_summary(int signum, const siginfo_t* info) { } if (signum == DEBUGGER_SIGNAL) { __libc_format_log(ANDROID_LOG_INFO, "libc", "Requested dump for tid %d (%s)", gettid(), async_safe_format_log(ANDROID_LOG_INFO, "libc", "Requested dump for tid %d (%s)", gettid(), thread_name); return; } Loading Loading @@ -166,14 +170,14 @@ static void log_signal_summary(int signum, const siginfo_t* info) { char addr_desc[32]; // ", fault addr 0x1234" addr_desc[0] = code_desc[0] = 0; if (info != nullptr) { __libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code); async_safe_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code); if (has_address) { __libc_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr); async_safe_format_buffer(addr_desc, sizeof(addr_desc), ", fault addr %p", info->si_addr); } } __libc_format_log(ANDROID_LOG_FATAL, "libc", "Fatal signal %d (%s)%s%s in tid %d (%s)", signum, signal_name, code_desc, addr_desc, gettid(), thread_name); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "Fatal signal %d (%s)%s%s in tid %d (%s)", signum, signal_name, code_desc, addr_desc, gettid(), thread_name); } /* Loading @@ -182,7 +186,7 @@ static void log_signal_summary(int signum, const siginfo_t* info) { static bool have_siginfo(int signum) { struct sigaction old_action; if (sigaction(signum, nullptr, &old_action) < 0) { __libc_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s", async_safe_format_log(ANDROID_LOG_WARN, "libc", "Failed testing for SA_SIGINFO: %s", strerror(errno)); return false; } Loading @@ -207,7 +211,7 @@ static void raise_caps() { capdata[1].inheritable = capdata[1].permitted; if (capset(&capheader, &capdata[0]) == -1) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "capset failed: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "capset failed: %s", strerror(errno)); } } Loading @@ -217,8 +221,8 @@ static void raise_caps() { for (unsigned long i = 0; i < 64; ++i) { if (capmask & (1ULL << i)) { if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, i, 0, 0) != 0) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to raise ambient capability %lu: %s", i, strerror(errno)); async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to raise ambient capability %lu: %s", i, strerror(errno)); } } } Loading Loading @@ -260,8 +264,8 @@ static int debuggerd_dispatch_pseudothread(void* arg) { // Don't use fork(2) to avoid calling pthread_atfork handlers. int forkpid = clone(nullptr, nullptr, 0, nullptr); if (forkpid == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "failed to fork in debuggerd signal handler: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "failed to fork in debuggerd signal handler: %s", strerror(errno)); } else if (forkpid == 0) { TEMP_FAILURE_RETRY(dup2(pipefds[1], STDOUT_FILENO)); close(pipefds[0]); Loading @@ -271,8 +275,9 @@ static int debuggerd_dispatch_pseudothread(void* arg) { char main_tid[10]; char pseudothread_tid[10]; __libc_format_buffer(main_tid, sizeof(main_tid), "%d", thread_info->crashing_tid); __libc_format_buffer(pseudothread_tid, sizeof(pseudothread_tid), "%d", thread_info->pseudothread_tid); async_safe_format_buffer(main_tid, sizeof(main_tid), "%d", thread_info->crashing_tid); async_safe_format_buffer(pseudothread_tid, sizeof(pseudothread_tid), "%d", thread_info->pseudothread_tid); execl(CRASH_DUMP_PATH, CRASH_DUMP_NAME, main_tid, pseudothread_tid, nullptr); Loading @@ -282,15 +287,16 @@ static int debuggerd_dispatch_pseudothread(void* arg) { char buf[4]; ssize_t rc = TEMP_FAILURE_RETRY(read(pipefds[0], &buf, sizeof(buf))); if (rc == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe failed: %s", strerror(errno)); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe failed: %s", strerror(errno)); } else if (rc == 0) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper failed to exec"); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper failed to exec"); } else if (rc != 1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", async_safe_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe returned unexpected value: %zd", rc); } else { if (buf[0] != '\1') { __libc_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper reported failure"); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper reported failure"); } else { thread_info->crash_dump_started = true; } Loading @@ -300,10 +306,10 @@ static int debuggerd_dispatch_pseudothread(void* arg) { // Don't leave a zombie child. int status; if (TEMP_FAILURE_RETRY(waitpid(forkpid, &status, 0)) == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "failed to wait for crash_dump helper: %s", async_safe_format_log(ANDROID_LOG_FATAL, "libc", "failed to wait for crash_dump helper: %s", strerror(errno)); } else if (WIFSTOPPED(status) || WIFSIGNALED(status)) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper crashed or stopped"); async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper crashed or stopped"); thread_info->crash_dump_started = false; } } Loading Loading @@ -383,7 +389,7 @@ static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void* c // Only allow one thread to handle a signal at a time. int ret = pthread_mutex_lock(&crash_mutex); if (ret != 0) { __libc_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); async_safe_format_log(ANDROID_LOG_INFO, "libc", "pthread_mutex_lock failed: %s", strerror(ret)); return; } Loading Loading @@ -419,10 +425,10 @@ static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void* c } // Wait for the child to start... __futex_wait(&thread_info.pseudothread_tid, -1, nullptr); futex_wait(&thread_info.pseudothread_tid, -1); // and then wait for it to finish. __futex_wait(&thread_info.pseudothread_tid, child_pid, nullptr); futex_wait(&thread_info.pseudothread_tid, child_pid); // Restore PR_SET_DUMPABLE to its original value. if (prctl(PR_SET_DUMPABLE, orig_dumpable) != 0) { Loading
debuggerd/tombstoned_client.cpp +13 −13 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ #include <utility> #include <android-base/unique_fd.h> #include <async_safe/log.h> #include <cutils/sockets.h> #include "debuggerd/protocol.h" #include "debuggerd/util.h" #include "private/libc_logging.h" using android::base::unique_fd; Loading @@ -34,7 +34,7 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp unique_fd sockfd(socket_local_client(kTombstonedCrashSocketName, ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET)); if (sockfd == -1) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to connect to tombstoned: %s", async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to connect to tombstoned: %s", strerror(errno)); return false; } Loading @@ -43,7 +43,7 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp packet.packet_type = CrashPacketType::kDumpRequest; packet.packet.dump_request.pid = pid; if (TEMP_FAILURE_RETRY(write(sockfd, &packet, sizeof(packet))) != sizeof(packet)) { __libc_format_log(ANDROID_LOG_ERROR, "libc", "failed to write DumpRequest packet: %s", async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to write DumpRequest packet: %s", strerror(errno)); return false; } Loading @@ -51,11 +51,11 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp unique_fd tmp_output_fd; ssize_t rc = recv_fd(sockfd, &packet, sizeof(packet), &tmp_output_fd); if (rc == -1) { __libc_format_log(ANDROID_LOG_ERROR, "libc", async_safe_format_log(ANDROID_LOG_ERROR, "libc", "failed to read response to DumpRequest packet: %s", strerror(errno)); return false; } else if (rc != sizeof(packet)) { __libc_format_log( async_safe_format_log( ANDROID_LOG_ERROR, "libc", "received DumpRequest response packet of incorrect length (expected %zu, got %zd)", sizeof(packet), rc); Loading @@ -67,7 +67,7 @@ bool tombstoned_connect(pid_t pid, unique_fd* tombstoned_socket, unique_fd* outp // a regular fd, and writing to an fd with O_APPEND). int flags = fcntl(tmp_output_fd.get(), F_GETFL); if (fcntl(tmp_output_fd.get(), F_SETFL, flags | O_APPEND) != 0) { __libc_format_log(ANDROID_LOG_WARN, "libc", "failed to set output fd flags: %s", async_safe_format_log(ANDROID_LOG_WARN, "libc", "failed to set output fd flags: %s", strerror(errno)); } Loading
debuggerd/util.cpp +0 −2 Original line number Diff line number Diff line Loading @@ -24,8 +24,6 @@ #include <cutils/sockets.h> #include <debuggerd/protocol.h> #include "private/libc_logging.h" using android::base::unique_fd; ssize_t send_fd(int sockfd, const void* data, size_t len, unique_fd fd) { Loading