Skip to content

Commit

Permalink
Shave a stack frame off asserts.
Browse files Browse the repository at this point in the history
No-one cares about seeing "async_safe_fatal" (which you have to admit is a
pretty confusing name for an app developer anyway).

On arm:

     #00 pc 0001a43c  /system/lib/libc.so (abort+63)
     #1 pc 0001a627  /system/lib/libc.so (__assert+14)

And aarch64:

     #00 pc 000000000001d75c  /system/lib64/libc.so (abort+120)
     #1 pc 000000000001dad0  /system/lib64/libc.so (__assert+44)

Bug: N/A
Test: ran `crasher assert` and `crasher64 assert`
Change-Id: I00be71c566c74cdb00f8e95d634777155bc3da03
  • Loading branch information
enh-google committed Jun 21, 2017
1 parent e300bf8 commit 695713e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions libc/async_safe/async_safe_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,9 @@ void async_safe_fatal_va_list(const char* prefix, const char* format, va_list ar
android_set_abort_message(msg);
}

void async_safe_fatal(const char* fmt, ...) {
void async_safe_fatal_no_abort(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
async_safe_fatal_va_list(nullptr, fmt, args);
va_end(args);
abort();
}
15 changes: 13 additions & 2 deletions libc/async_safe/include/async_safe/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

// These functions do not allocate memory to send data to the log.

Expand Down Expand Up @@ -65,9 +66,19 @@ enum {
};

// Formats a message to the log (priority 'fatal'), then aborts.
__noreturn void async_safe_fatal(const char* _Nonnull fmt, ...) __printflike(1, 2);
// Implemented as a macro so that async_safe_fatal isn't on the stack when we crash:
// we appear to go straight from the caller to abort, saving an uninteresting stack
// frame.
#define async_safe_fatal(...) \
do { \
async_safe_fatal_no_abort(__VA_ARGS__); \
abort(); \
} while (0) \


// This function does return, so callers that want to abort, must do so themselves.
// These functions do return, so callers that want to abort, must do so themselves,
// or use the macro above.
void async_safe_fatal_no_abort(const char* _Nonnull fmt, ...) __printflike(1, 2);
#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__)
void async_safe_fatal_va_list(
const char* _Nullable prefix, const char* _Nonnull fmt, va_list);
Expand Down

0 comments on commit 695713e

Please sign in to comment.