Bug 1536675 - Take the crashing out of MOZ_CrashPrintf r=froydnj

It would be helpful if MOZ_CRASH_UNSAFE_PRINTF would do its crashing inline at the caller, so that CI failure logs can blame the right code.

Before this patch, MOZ_CRASH_UNSAFE_PRINTF calls MOZ_CrashPrintf, which does the printf work and crashes.

This patch pulls out the crashing piece at the end, so that MOZ_CrashPrintf only does the printf work, and returns the string to the caller, who will MOZ_Crash inline.

Differential Revision: https://phabricator.services.mozilla.com/D25329
This commit is contained in:
David Major
2019-04-02 19:20:41 +00:00
parent 0343050a58
commit 285133078b
2 changed files with 18 additions and 40 deletions

View File

@@ -27,19 +27,12 @@ static mozilla::Atomic<bool, mozilla::SequentiallyConsistent,
mozilla::recordreplay::Behavior::DontPreserve>
sCrashing(false);
#ifndef DEBUG
MFBT_API MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(
2, 3) void MOZ_CrashPrintf(int aLine, const char* aFormat, ...)
#else
MFBT_API MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE
MOZ_FORMAT_PRINTF(3, 4) void MOZ_CrashPrintf(const char* aFilename, int aLine,
const char* aFormat, ...)
#endif
{
MFBT_API MOZ_COLD MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(1, 2) const
char* MOZ_CrashPrintf(const char* aFormat, ...) {
if (!sCrashing.compareExchange(false, true)) {
// In the unlikely event of a race condition, skip
// setting the crash reason and just crash safely.
MOZ_REALLY_CRASH(aLine);
MOZ_RELEASE_ASSERT(false);
}
va_list aArgs;
va_start(aArgs, aFormat);
@@ -49,11 +42,7 @@ MOZ_FORMAT_PRINTF(3, 4) void MOZ_CrashPrintf(const char* aFilename, int aLine,
MOZ_RELEASE_ASSERT(
ret >= 0 && size_t(ret) < sPrintfCrashReasonSize,
"Could not write the explanation string to the supplied buffer!");
#ifdef DEBUG
MOZ_Crash(aFilename, aLine, sPrintfCrashReason);
#else
MOZ_Crash(nullptr, aLine, sPrintfCrashReason);
#endif
return sPrintfCrashReason;
}
MOZ_END_EXTERN_C

View File

@@ -304,9 +304,8 @@ MOZ_NoReturn(int aLine) {
* to crash-stats and are publicly visible. Firefox data stewards must do data
* review on usages of this macro.
*/
static inline MOZ_COLD MOZ_NORETURN void MOZ_Crash(const char* aFilename,
int aLine,
const char* aReason) {
static MOZ_ALWAYS_INLINE MOZ_COLD MOZ_NORETURN void MOZ_Crash(
const char* aFilename, int aLine, const char* aReason) {
#ifdef DEBUG
MOZ_ReportCrash(aReason, aFilename, aLine);
#endif
@@ -318,18 +317,8 @@ static inline MOZ_COLD MOZ_NORETURN void MOZ_Crash(const char* aFilename,
static const size_t sPrintfMaxArgs = 4;
static const size_t sPrintfCrashReasonSize = 1024;
#ifndef DEBUG
MFBT_API MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(
2, 3) void MOZ_CrashPrintf(int aLine, const char* aFormat, ...);
# define MOZ_CALL_CRASH_PRINTF(format, ...) \
MOZ_CrashPrintf(__LINE__, format, __VA_ARGS__)
#else
MFBT_API MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(
3, 4) void MOZ_CrashPrintf(const char* aFilename, int aLine,
const char* aFormat, ...);
# define MOZ_CALL_CRASH_PRINTF(format, ...) \
MOZ_CrashPrintf(__FILE__, __LINE__, format, __VA_ARGS__)
#endif
MFBT_API MOZ_COLD MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(1, 2) const
char* MOZ_CrashPrintf(const char* aFormat, ...);
/*
* MOZ_CRASH_UNSAFE_PRINTF(format, arg1 [, args]) can be used when more
@@ -352,7 +341,7 @@ MFBT_API MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(
"Only up to 4 additional arguments are allowed!"); \
static_assert(sizeof(format) <= sPrintfCrashReasonSize, \
"The supplied format string is too long!"); \
MOZ_CALL_CRASH_PRINTF("" format, __VA_ARGS__); \
MOZ_Crash(__FILE__, __LINE__, MOZ_CrashPrintf("" format, __VA_ARGS__)); \
} while (false)
MOZ_END_EXTERN_C