From 8d0314295ebf2a84604aeb7eef3b759daef92f1a Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 19 Oct 2020 07:25:15 -0400 Subject: [PATCH] support Android's logging system for fatal_error --- Android.bp | 1 + util.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Android.bp b/Android.bp index 3096c83..2768607 100644 --- a/Android.bp +++ b/Android.bp @@ -56,6 +56,7 @@ cc_library { defaults: ["hardened_malloc_defaults"], srcs: lib_src_files, export_include_dirs: ["include"], + static_libs: ["libasync_safe"], target: { android: { shared: { diff --git a/util.c b/util.c index 4d4360f..9df4c2f 100644 --- a/util.c +++ b/util.c @@ -4,6 +4,10 @@ #include +#ifdef __ANDROID__ +#include +#endif + #include "util.h" static int write_full(int fd, const char *buf, size_t length) { @@ -27,5 +31,8 @@ COLD noreturn void fatal_error(const char *s) { (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(); }