Skip to content

Commit 695713e

Browse files
committed
Shave a stack frame off asserts.
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
1 parent e300bf8 commit 695713e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

libc/async_safe/async_safe_log.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,9 @@ void async_safe_fatal_va_list(const char* prefix, const char* format, va_list ar
567567
android_set_abort_message(msg);
568568
}
569569

570-
void async_safe_fatal(const char* fmt, ...) {
570+
void async_safe_fatal_no_abort(const char* fmt, ...) {
571571
va_list args;
572572
va_start(args, fmt);
573573
async_safe_fatal_va_list(nullptr, fmt, args);
574574
va_end(args);
575-
abort();
576575
}

libc/async_safe/include/async_safe/log.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdarg.h>
3434
#include <stddef.h>
3535
#include <stdint.h>
36+
#include <stdlib.h>
3637

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

@@ -65,9 +66,19 @@ enum {
6566
};
6667

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

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

0 commit comments

Comments
 (0)