From 8d5c63122499169df5fd9ed6e91fb116512a4745 Mon Sep 17 00:00:00 2001 From: Dmitry Muhomor Date: Tue, 19 Sep 2023 18:18:01 +0300 Subject: [PATCH] android: implement fatal_error() via async_safe_fatal() async_safe_fatal() performs the following steps: - logs the error message to stderr and logcat - passes error message to debuggerd via android_set_abort_message(). debuggerd then saves the error message in the crash report file ("tombstone") - calls abort() --- util.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util.c b/util.c index 9df4c2f..a3d6f0c 100644 --- a/util.c +++ b/util.c @@ -10,6 +10,7 @@ #include "util.h" +#ifndef __ANDROID__ static int write_full(int fd, const char *buf, size_t length) { do { ssize_t bytes_written = write(fd, buf, length); @@ -25,14 +26,16 @@ static int write_full(int fd, const char *buf, size_t length) { return 0; } +#endif COLD noreturn void fatal_error(const char *s) { +#ifdef __ANDROID__ + async_safe_fatal("hardened_malloc: fatal allocator error: %s", s); +#else const char *prefix = "fatal allocator error: "; (void)(write_full(STDERR_FILENO, prefix, strlen(prefix)) != -1 && write_full(STDERR_FILENO, s, strlen(s)) != -1 && write_full(STDERR_FILENO, "\n", 1)); -#ifdef __ANDROID__ - async_safe_format_log(ANDROID_LOG_FATAL, "hardened_malloc", "fatal allocator error: %s", s); -#endif abort(); +#endif }