support Android's logging system for fatal_error

This commit is contained in:
Daniel Micay 2020-10-19 07:25:15 -04:00
parent b072022022
commit 8d0314295e
2 changed files with 8 additions and 0 deletions

View File

@ -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: {

7
util.c
View File

@ -4,6 +4,10 @@
#include <unistd.h>
#ifdef __ANDROID__
#include <async_safe/log.h>
#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();
}