Skip to content

Commit

Permalink
support Android's logging system for fatal_error
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 19, 2020
1 parent b072022 commit b5735c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Android.bp
Expand Up @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions util.c
Expand Up @@ -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) {
Expand All @@ -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_fatal("fatal allocator error: %s", s);
#endif
abort();
}

0 comments on commit b5735c5

Please sign in to comment.