2013-07-24 11:41:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-06-04 07:36:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-19 23:28:35 +04:00
|
|
|
|
2011-12-28 20:48:54 +04:00
|
|
|
/* Implementations of runtime and static assertion macros for C and C++. */
|
|
|
|
|
2013-07-24 11:41:39 +04:00
|
|
|
#ifndef mozilla_Assertions_h
|
|
|
|
#define mozilla_Assertions_h
|
2011-12-19 23:28:35 +04:00
|
|
|
|
2021-04-20 08:15:28 +03:00
|
|
|
#if (defined(MOZ_HAS_MOZGLUE) || defined(MOZILLA_INTERNAL_API)) && \
|
|
|
|
!defined(__wasi__)
|
2014-05-06 06:02:04 +04:00
|
|
|
# define MOZ_DUMP_ASSERTION_STACK
|
|
|
|
#endif
|
|
|
|
|
2012-02-23 23:32:30 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-01-22 07:42:15 +04:00
|
|
|
#include "mozilla/Compiler.h"
|
2013-04-20 03:20:35 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2014-04-24 12:48:00 +04:00
|
|
|
#include "mozilla/MacroArgs.h"
|
2016-07-25 16:57:30 +03:00
|
|
|
#include "mozilla/StaticAnalysisFunctions.h"
|
2016-11-07 06:57:00 +03:00
|
|
|
#include "mozilla/Types.h"
|
2014-05-06 06:02:04 +04:00
|
|
|
#ifdef MOZ_DUMP_ASSERTION_STACK
|
2021-03-23 00:25:30 +03:00
|
|
|
# include "mozilla/StackWalk.h"
|
2014-05-06 06:02:04 +04:00
|
|
|
#endif
|
2011-12-19 23:28:35 +04:00
|
|
|
|
2016-11-07 06:57:00 +03:00
|
|
|
/*
|
|
|
|
* The crash reason set by MOZ_CRASH_ANNOTATE is consumed by the crash reporter
|
|
|
|
* if present. It is declared here (and defined in Assertions.cpp) to make it
|
|
|
|
* available to all code, even libraries that don't link with the crash reporter
|
|
|
|
* directly.
|
|
|
|
*/
|
|
|
|
MOZ_BEGIN_EXTERN_C
|
|
|
|
extern MFBT_DATA const char* gMozCrashReason;
|
|
|
|
MOZ_END_EXTERN_C
|
2015-10-08 22:21:58 +03:00
|
|
|
|
Bug 1496503 - Change the rust panic hook to delegate to Gecko's crash code. r=froydnj
The current rust panic hook keeps a string for the crash reporter, and
goes on calling the default rust panic hook, which prints out a crash
stack... when RUST_BOOTSTRAP is set *and* when that works. Notably, on
both mac and Windows, it only really works for local builds, but fails
for debug builds from automation, although on automation itself, we also
do stackwalk from crash minidumps, which alleviates the problem.
Artifact debug builds are affected, though.
More importantly, C++ calls to e.g. MOZ_CRASH have a similar but
different behavior, in that they dump a stack trace on debug builds, by
default (with exceptions, see below for one). The format of those stack
traces is understood by the various fix*stack*py scripts under
tools/rb/, that are used by the various test harnesses both on
automation and locally.
Additionally, the current rust panic hook, as it calls the default rust
panic hook, ends up calling abort() on non-Windows platforms, which ends
up being verbosely redirected to mozalloc_abort per
https://dxr.mozilla.org/mozilla-central/rev/237e4c0633fda8e227b2ab3ab57e417c980a2811/memory/mozalloc/mozalloc_abort.cpp#79
which then calls MOZ_CRASH. Theoretically, /that/ would also print a
stack trace, but doesn't because currently the stack trace printing code
lives in libxul, and MOZ_CRASH only calls it when compiled from
libxul-code, which mozalloc_abort is not part of.
With this change, we make the rust panic handler call back into
MOZ_CRASH directly. This has multiple advantages:
- This is more consistent cross-platforms (Windows is not special
anymore).
- This is more consistent between C++ and rust (stack traces all look
the same, and can all be post-processed by fix*stack*py if need be)
- This is more consistent in behavior, where debug builds will show
those stack traces without caring about environment variables.
- It demangles C++ symbols in rust-initiated stack traces (for some
reason that didn't happen with the rust panic handler)
A few downsides:
- the loss of demangling for some rust symbols.
- the loss of addresses in the stacks, although they're not entirely
useful
- extra empty lines.
The first should be fixable later one. The latter two are arguably
something that should be consistent across C++ and rust, and should be
changed if necessary, independently of this patch.
Depends on D11719
Depends on D11719
Differential Revision: https://phabricator.services.mozilla.com/D11720
--HG--
extra : moz-landing-system : lando
2018-11-15 01:35:33 +03:00
|
|
|
#if defined(MOZ_HAS_MOZGLUE) || defined(MOZILLA_INTERNAL_API)
|
2016-11-07 06:57:00 +03:00
|
|
|
static inline void AnnotateMozCrashReason(const char* reason) {
|
|
|
|
gMozCrashReason = reason;
|
|
|
|
}
|
|
|
|
# define MOZ_CRASH_ANNOTATE(...) AnnotateMozCrashReason(__VA_ARGS__)
|
2015-10-08 22:21:58 +03:00
|
|
|
#else
|
2018-02-07 17:15:28 +03:00
|
|
|
# define MOZ_CRASH_ANNOTATE(...) \
|
|
|
|
do { /* nothing */ \
|
|
|
|
} while (false)
|
2015-09-29 18:14:50 +03:00
|
|
|
#endif
|
|
|
|
|
2012-06-12 03:16:46 +04:00
|
|
|
#include <stddef.h>
|
2012-04-12 04:03:07 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2017-01-17 23:33:25 +03:00
|
|
|
#ifdef _MSC_VER
|
2012-06-12 03:16:46 +04:00
|
|
|
/*
|
|
|
|
* TerminateProcess and GetCurrentProcess are defined in <winbase.h>, which
|
|
|
|
* further depends on <windef.h>. We hardcode these few definitions manually
|
|
|
|
* because those headers clutter the global namespace with a significant
|
|
|
|
* number of undesired macros and symbols.
|
|
|
|
*/
|
2017-01-17 23:32:47 +03:00
|
|
|
MOZ_BEGIN_EXTERN_C
|
2014-05-30 09:40:33 +04:00
|
|
|
__declspec(dllimport) int __stdcall TerminateProcess(void* hProcess,
|
|
|
|
unsigned int uExitCode);
|
|
|
|
__declspec(dllimport) void* __stdcall GetCurrentProcess(void);
|
2017-01-17 23:32:47 +03:00
|
|
|
MOZ_END_EXTERN_C
|
2021-04-20 08:15:28 +03:00
|
|
|
#elif defined(__wasi__)
|
|
|
|
/*
|
|
|
|
* On Wasm/WASI platforms, we just call __builtin_trap().
|
|
|
|
*/
|
2012-06-12 03:16:46 +04:00
|
|
|
#else
|
2012-04-12 04:03:07 +04:00
|
|
|
# include <signal.h>
|
|
|
|
#endif
|
|
|
|
#ifdef ANDROID
|
|
|
|
# include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
2017-01-17 23:32:47 +03:00
|
|
|
MOZ_BEGIN_EXTERN_C
|
2011-12-19 23:28:35 +04:00
|
|
|
|
2021-03-23 00:25:30 +03:00
|
|
|
#if defined(ANDROID) && defined(MOZ_DUMP_ASSERTION_STACK)
|
|
|
|
MOZ_MAYBE_UNUSED static void MOZ_ReportAssertionFailurePrintFrame(
|
|
|
|
const char* aBuf) {
|
|
|
|
__android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert", "%s\n", aBuf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-08 01:41:11 +04:00
|
|
|
/*
|
2014-05-30 09:40:33 +04:00
|
|
|
* Prints |aStr| as an assertion failure (using aFilename and aLine as the
|
|
|
|
* location of the assertion) to the standard debug-output channel.
|
2012-06-08 01:41:11 +04:00
|
|
|
*
|
2013-06-29 05:38:30 +04:00
|
|
|
* Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method. This
|
|
|
|
* method is primarily for internal use in this header, and only secondarily
|
|
|
|
* for use in implementing release-build assertions.
|
|
|
|
*/
|
2017-01-17 23:37:54 +03:00
|
|
|
MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void
|
2014-05-30 09:40:33 +04:00
|
|
|
MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename,
|
|
|
|
int aLine) MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS {
|
2015-02-07 02:05:08 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
__android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert",
|
|
|
|
"Assertion failure: %s, at %s:%d\n", aStr, aFilename,
|
|
|
|
aLine);
|
2019-09-24 23:50:41 +03:00
|
|
|
# if defined(MOZ_DUMP_ASSERTION_STACK)
|
2021-04-16 07:06:02 +03:00
|
|
|
MozWalkTheStackWithWriter(MOZ_ReportAssertionFailurePrintFrame, CallerPC(),
|
|
|
|
/* aMaxFrames */ 0);
|
2019-09-24 23:50:41 +03:00
|
|
|
# endif
|
2015-02-07 02:05:08 +03:00
|
|
|
#else
|
|
|
|
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", aStr, aFilename, aLine);
|
2016-02-27 22:12:07 +03:00
|
|
|
# if defined(MOZ_DUMP_ASSERTION_STACK)
|
2021-04-16 07:06:02 +03:00
|
|
|
MozWalkTheStack(stderr, CallerPC(), /* aMaxFrames */ 0);
|
2015-02-07 02:05:08 +03:00
|
|
|
# endif
|
|
|
|
fflush(stderr);
|
|
|
|
#endif
|
2013-06-29 05:38:30 +04:00
|
|
|
}
|
|
|
|
|
2017-01-17 23:37:54 +03:00
|
|
|
MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
|
2014-07-11 06:10:17 +04:00
|
|
|
const char* aStr, const char* aFilename,
|
|
|
|
int aLine) MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS {
|
2013-06-29 05:38:30 +04:00
|
|
|
#ifdef ANDROID
|
2014-05-30 09:40:33 +04:00
|
|
|
__android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH",
|
|
|
|
"Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine);
|
2013-06-29 05:38:30 +04:00
|
|
|
#else
|
2014-05-30 09:40:33 +04:00
|
|
|
fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", aStr, aFilename, aLine);
|
2016-02-27 22:12:07 +03:00
|
|
|
# if defined(MOZ_DUMP_ASSERTION_STACK)
|
2021-04-16 07:06:02 +03:00
|
|
|
MozWalkTheStack(stderr, CallerPC(), /* aMaxFrames */ 0);
|
2014-05-06 06:02:04 +04:00
|
|
|
# endif
|
2013-06-29 05:38:30 +04:00
|
|
|
fflush(stderr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH(). You should
|
|
|
|
* call MOZ_CRASH instead.
|
2012-06-08 01:41:11 +04:00
|
|
|
*/
|
2012-06-18 23:01:57 +04:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
/*
|
|
|
|
* On MSVC use the __debugbreak compiler intrinsic, which produces an inline
|
|
|
|
* (not nested in a system function) breakpoint. This distinctively invokes
|
|
|
|
* Breakpad without requiring system library symbols on all stack-processing
|
2013-06-29 05:38:30 +04:00
|
|
|
* machines, as a nested breakpoint would require.
|
|
|
|
*
|
2017-01-17 23:33:25 +03:00
|
|
|
* We use __LINE__ to prevent the compiler from folding multiple crash sites
|
|
|
|
* together, which would make crash reports hard to understand.
|
|
|
|
*
|
2013-06-29 05:38:30 +04:00
|
|
|
* We use TerminateProcess with the exit code aborting would generate
|
|
|
|
* because we don't want to invoke atexit handlers, destructors, library
|
|
|
|
* unload handlers, and so on when our process might be in a compromised
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* We don't use abort() because it'd cause Windows to annoyingly pop up the
|
|
|
|
* process error dialog multiple times. See bug 345118 and bug 426163.
|
|
|
|
*
|
2012-06-12 03:16:46 +04:00
|
|
|
* (Technically these are Windows requirements, not MSVC requirements. But
|
|
|
|
* practically you need MSVC for debugging, and we only ship builds created
|
|
|
|
* by MSVC, so doing it this way reduces complexity.)
|
2012-06-18 23:01:57 +04:00
|
|
|
*/
|
2013-06-29 05:38:30 +04:00
|
|
|
|
2018-01-30 04:15:51 +03:00
|
|
|
MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE void
|
|
|
|
MOZ_NoReturn(int aLine) {
|
2017-01-17 23:33:25 +03:00
|
|
|
*((volatile int*)NULL) = aLine;
|
|
|
|
TerminateProcess(GetCurrentProcess(), 3);
|
|
|
|
}
|
2013-06-29 05:38:30 +04:00
|
|
|
|
2017-02-21 20:01:38 +03:00
|
|
|
# define MOZ_REALLY_CRASH(line) \
|
2017-01-17 23:33:25 +03:00
|
|
|
do { \
|
|
|
|
__debugbreak(); \
|
2017-02-21 20:01:38 +03:00
|
|
|
MOZ_NoReturn(line); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2021-04-20 08:15:28 +03:00
|
|
|
|
|
|
|
#elif __wasi__
|
|
|
|
|
|
|
|
# define MOZ_REALLY_CRASH(line) __builtin_trap()
|
|
|
|
|
2012-06-08 01:41:11 +04:00
|
|
|
#else
|
2018-10-05 00:52:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MOZ_CRASH_WRITE_ADDR is the address to be used when performing a forced
|
|
|
|
* crash. NULL is preferred however if for some reason NULL cannot be used
|
|
|
|
* this makes choosing another value possible.
|
|
|
|
*
|
|
|
|
* In the case of UBSan certain checks, bounds specifically, cause the compiler
|
|
|
|
* to emit the 'ud2' instruction when storing to 0x0. This causes forced
|
|
|
|
* crashes to manifest as ILL (at an arbitrary address) instead of the expected
|
|
|
|
* SEGV at 0x0.
|
|
|
|
*/
|
|
|
|
# ifdef MOZ_UBSAN
|
|
|
|
# define MOZ_CRASH_WRITE_ADDR 0x1
|
|
|
|
# else
|
|
|
|
# define MOZ_CRASH_WRITE_ADDR NULL
|
|
|
|
# endif
|
2019-01-18 12:16:18 +03:00
|
|
|
|
2012-04-12 04:03:07 +04:00
|
|
|
# ifdef __cplusplus
|
2019-05-22 15:50:43 +03:00
|
|
|
# define MOZ_REALLY_CRASH(line) \
|
|
|
|
do { \
|
|
|
|
*((volatile int*)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \
|
|
|
|
::abort(); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2012-04-12 04:03:07 +04:00
|
|
|
# else
|
2019-05-22 15:50:43 +03:00
|
|
|
# define MOZ_REALLY_CRASH(line) \
|
|
|
|
do { \
|
|
|
|
*((volatile int*)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \
|
|
|
|
abort(); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2012-04-12 04:03:07 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2012-06-08 01:41:11 +04:00
|
|
|
/*
|
2013-06-29 05:38:30 +04:00
|
|
|
* MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a
|
|
|
|
* Breakpad-compatible way, in both debug and release builds.
|
|
|
|
*
|
|
|
|
* MOZ_CRASH is a good solution for "handling" failure cases when you're
|
|
|
|
* unwilling or unable to handle them more cleanly -- for OOM, for likely memory
|
|
|
|
* corruption, and so on. It's also a good solution if you need safe behavior
|
|
|
|
* in release builds as well as debug builds. But if the failure is one that
|
|
|
|
* should be debugged and fixed, MOZ_ASSERT is generally preferable.
|
|
|
|
*
|
|
|
|
* The optional explanation-string, if provided, must be a string literal
|
|
|
|
* explaining why we're crashing. This argument is intended for use with
|
|
|
|
* MOZ_CRASH() calls whose rationale is non-obvious; don't use it if it's
|
|
|
|
* obvious why we're crashing.
|
2012-06-08 01:41:11 +04:00
|
|
|
*
|
2013-06-29 05:38:30 +04:00
|
|
|
* If we're a DEBUG build and we crash at a MOZ_CRASH which provides an
|
|
|
|
* explanation-string, we print the string to stderr. Otherwise, we don't
|
|
|
|
* print anything; this is because we want MOZ_CRASH to be 100% safe in release
|
|
|
|
* builds, and it's hard to print to stderr safely when memory might have been
|
|
|
|
* corrupted.
|
2012-06-08 01:41:11 +04:00
|
|
|
*/
|
2013-06-29 05:38:30 +04:00
|
|
|
#ifndef DEBUG
|
2015-10-08 22:21:58 +03:00
|
|
|
# define MOZ_CRASH(...) \
|
|
|
|
do { \
|
|
|
|
MOZ_CRASH_ANNOTATE("MOZ_CRASH(" __VA_ARGS__ ")"); \
|
2017-02-21 20:01:38 +03:00
|
|
|
MOZ_REALLY_CRASH(__LINE__); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2012-04-12 04:03:07 +04:00
|
|
|
#else
|
2013-06-29 05:38:30 +04:00
|
|
|
# define MOZ_CRASH(...) \
|
|
|
|
do { \
|
|
|
|
MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \
|
2015-10-08 22:21:58 +03:00
|
|
|
MOZ_CRASH_ANNOTATE("MOZ_CRASH(" __VA_ARGS__ ")"); \
|
2017-02-21 20:01:38 +03:00
|
|
|
MOZ_REALLY_CRASH(__LINE__); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2012-04-12 04:03:07 +04:00
|
|
|
#endif
|
|
|
|
|
2017-02-21 20:01:41 +03:00
|
|
|
/*
|
2019-02-03 11:09:37 +03:00
|
|
|
* MOZ_CRASH_UNSAFE(explanation-string) can be used if the explanation string
|
|
|
|
* cannot be a string literal (but no other processing needs to be done on it).
|
|
|
|
* A regular MOZ_CRASH() is preferred wherever possible, as passing arbitrary
|
|
|
|
* strings from a potentially compromised process is not without risk. If the
|
|
|
|
* string being passed is the result of a printf-style function, consider using
|
|
|
|
* MOZ_CRASH_UNSAFE_PRINTF instead.
|
2017-07-07 21:44:26 +03:00
|
|
|
*
|
|
|
|
* @note This macro causes data collection because crash strings are annotated
|
|
|
|
* to crash-stats and are publicly visible. Firefox data stewards must do data
|
|
|
|
* review on usages of this macro.
|
2017-02-21 20:01:41 +03:00
|
|
|
*/
|
2019-04-05 22:25:55 +03:00
|
|
|
static MOZ_ALWAYS_INLINE_EVEN_DEBUG MOZ_COLD MOZ_NORETURN void MOZ_Crash(
|
2019-04-02 22:20:41 +03:00
|
|
|
const char* aFilename, int aLine, const char* aReason) {
|
Bug 1496503 - Move MOZ_CrashOOL to Assertions.h. r=froydnj
Ideally, we'd want the function to stay in Assertions.cpp, but that's
only part of MFBT proper, and that doesn't have access to WalkTheStack
like MOZ_CRASH has from being in Assertion.h, when included from Gecko
code. Moving WalkTheStack to mozglue, putting it close together with
MozStackWalk would be prefered, but that causes problems linking MFBT
tests (which don't have access to mozglue), and other things.
Overall, this was too deep a rabbit hole, and moving MOZ_CrashOOL to
Assertions.h is much simpler. Since it's essentially the same as
MOZ_CRASH, except it allows non-literal strings, we can make it inlined,
and leave it to the compiler to drop the filename argument when it's not
used.
Differential Revision: https://phabricator.services.mozilla.com/D11718
--HG--
extra : moz-landing-system : lando
2018-11-15 01:35:23 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ReportCrash(aReason, aFilename, aLine);
|
2017-02-21 20:01:41 +03:00
|
|
|
#endif
|
Bug 1496503 - Move MOZ_CrashOOL to Assertions.h. r=froydnj
Ideally, we'd want the function to stay in Assertions.cpp, but that's
only part of MFBT proper, and that doesn't have access to WalkTheStack
like MOZ_CRASH has from being in Assertion.h, when included from Gecko
code. Moving WalkTheStack to mozglue, putting it close together with
MozStackWalk would be prefered, but that causes problems linking MFBT
tests (which don't have access to mozglue), and other things.
Overall, this was too deep a rabbit hole, and moving MOZ_CrashOOL to
Assertions.h is much simpler. Since it's essentially the same as
MOZ_CRASH, except it allows non-literal strings, we can make it inlined,
and leave it to the compiler to drop the filename argument when it's not
used.
Differential Revision: https://phabricator.services.mozilla.com/D11718
--HG--
extra : moz-landing-system : lando
2018-11-15 01:35:23 +03:00
|
|
|
MOZ_CRASH_ANNOTATE(aReason);
|
|
|
|
MOZ_REALLY_CRASH(aLine);
|
|
|
|
}
|
2019-02-03 11:09:37 +03:00
|
|
|
#define MOZ_CRASH_UNSAFE(reason) MOZ_Crash(__FILE__, __LINE__, reason)
|
2017-02-21 20:01:41 +03:00
|
|
|
|
|
|
|
static const size_t sPrintfMaxArgs = 4;
|
|
|
|
static const size_t sPrintfCrashReasonSize = 1024;
|
|
|
|
|
2019-04-02 22:20:41 +03:00
|
|
|
MFBT_API MOZ_COLD MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(1, 2) const
|
|
|
|
char* MOZ_CrashPrintf(const char* aFormat, ...);
|
2017-02-21 20:01:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MOZ_CRASH_UNSAFE_PRINTF(format, arg1 [, args]) can be used when more
|
|
|
|
* information is desired than a string literal can supply. The caller provides
|
|
|
|
* a printf-style format string, which must be a string literal and between
|
|
|
|
* 1 and 4 additional arguments. A regular MOZ_CRASH() is preferred wherever
|
|
|
|
* possible, as passing arbitrary strings to printf from a potentially
|
|
|
|
* compromised process is not without risk.
|
2017-07-07 21:44:26 +03:00
|
|
|
*
|
|
|
|
* @note This macro causes data collection because crash strings are annotated
|
|
|
|
* to crash-stats and are publicly visible. Firefox data stewards must do data
|
|
|
|
* review on usages of this macro.
|
2017-02-21 20:01:41 +03:00
|
|
|
*/
|
2019-04-02 22:20:41 +03:00
|
|
|
#define MOZ_CRASH_UNSAFE_PRINTF(format, ...) \
|
|
|
|
do { \
|
|
|
|
static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0, \
|
|
|
|
"Did you forget arguments to MOZ_CRASH_UNSAFE_PRINTF? " \
|
|
|
|
"Or maybe you want MOZ_CRASH instead?"); \
|
|
|
|
static_assert(MOZ_ARG_COUNT(__VA_ARGS__) <= sPrintfMaxArgs, \
|
|
|
|
"Only up to 4 additional arguments are allowed!"); \
|
|
|
|
static_assert(sizeof(format) <= sPrintfCrashReasonSize, \
|
|
|
|
"The supplied format string is too long!"); \
|
|
|
|
MOZ_Crash(__FILE__, __LINE__, MOZ_CrashPrintf("" format, __VA_ARGS__)); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2017-02-21 20:01:41 +03:00
|
|
|
|
2017-01-17 23:32:47 +03:00
|
|
|
MOZ_END_EXTERN_C
|
2011-12-19 23:28:35 +04:00
|
|
|
|
|
|
|
/*
|
2012-01-07 01:51:27 +04:00
|
|
|
* MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in
|
|
|
|
* debug builds. If it is, execution continues. Otherwise, an error message
|
|
|
|
* including the expression and the explanation-string (if provided) is printed,
|
|
|
|
* an attempt is made to invoke any existing debugger, and execution halts.
|
|
|
|
* MOZ_ASSERT is fatal: no recovery is possible. Do not assert a condition
|
|
|
|
* which can correctly be falsy.
|
|
|
|
*
|
2015-02-07 02:05:08 +03:00
|
|
|
* The optional explanation-string, if provided, must be a string literal
|
|
|
|
* explaining the assertion. It is intended for use with assertions whose
|
|
|
|
* correctness or rationale is non-obvious, and for assertions where the "real"
|
|
|
|
* condition being tested is best described prosaically. Don't provide an
|
|
|
|
* explanation if it's not actually helpful.
|
2012-01-07 01:51:27 +04:00
|
|
|
*
|
|
|
|
* // No explanation needed: pointer arguments often must not be NULL.
|
|
|
|
* MOZ_ASSERT(arg);
|
|
|
|
*
|
|
|
|
* // An explanation can be helpful to explain exactly how we know an
|
|
|
|
* // assertion is valid.
|
|
|
|
* MOZ_ASSERT(state == WAITING_FOR_RESPONSE,
|
|
|
|
* "given that <thingA> and <thingB>, we must have...");
|
|
|
|
*
|
|
|
|
* // Or it might disambiguate multiple identical (save for their location)
|
|
|
|
* // assertions of the same expression.
|
|
|
|
* MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(),
|
|
|
|
* "we already set [[PrimitiveThis]] for this Boolean object");
|
|
|
|
* MOZ_ASSERT(getSlot(PRIMITIVE_THIS_SLOT).isUndefined(),
|
|
|
|
* "we already set [[PrimitiveThis]] for this String object");
|
|
|
|
*
|
|
|
|
* MOZ_ASSERT has no effect in non-debug builds. It is designed to catch bugs
|
2013-11-25 21:37:15 +04:00
|
|
|
* *only* during debugging, not "in the field". If you want the latter, use
|
|
|
|
* MOZ_RELEASE_ASSERT, which applies to non-debug builds as well.
|
2015-02-05 00:13:58 +03:00
|
|
|
*
|
|
|
|
* MOZ_DIAGNOSTIC_ASSERT works like MOZ_RELEASE_ASSERT in Nightly/Aurora and
|
|
|
|
* MOZ_ASSERT in Beta/Release - use this when a condition is potentially rare
|
|
|
|
* enough to require real user testing to hit, but is not security-sensitive.
|
|
|
|
* This can cause user pain, so use it sparingly. If a MOZ_DIAGNOSTIC_ASSERT
|
|
|
|
* is firing, it should promptly be converted to a MOZ_ASSERT while the failure
|
|
|
|
* is being investigated, rather than letting users suffer.
|
2017-05-18 05:14:17 +03:00
|
|
|
*
|
|
|
|
* MOZ_DIAGNOSTIC_ASSERT_ENABLED is defined when MOZ_DIAGNOSTIC_ASSERT is like
|
|
|
|
* MOZ_RELEASE_ASSERT rather than MOZ_ASSERT.
|
2011-12-19 23:28:35 +04:00
|
|
|
*/
|
2013-11-25 21:37:16 +04:00
|
|
|
|
2014-05-01 06:39:13 +04:00
|
|
|
/*
|
|
|
|
* Implement MOZ_VALIDATE_ASSERT_CONDITION_TYPE, which is used to guard against
|
|
|
|
* accidentally passing something unintended in lieu of an assertion condition.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2020-03-28 16:57:15 +03:00
|
|
|
# include <type_traits>
|
2014-05-01 06:39:13 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template <typename T>
|
2014-09-07 12:04:09 +04:00
|
|
|
struct AssertionConditionType {
|
2020-03-28 17:16:19 +03:00
|
|
|
using ValueT = std::remove_reference_t<T>;
|
2020-03-28 16:57:17 +03:00
|
|
|
static_assert(!std::is_array_v<ValueT>,
|
2014-05-30 09:40:33 +04:00
|
|
|
"Expected boolean assertion condition, got an array or a "
|
|
|
|
"string!");
|
2020-03-28 16:57:16 +03:00
|
|
|
static_assert(!std::is_function_v<ValueT>,
|
2014-05-30 09:40:33 +04:00
|
|
|
"Expected boolean assertion condition, got a function! Did "
|
|
|
|
"you intend to call that function?");
|
2020-03-28 16:57:15 +03:00
|
|
|
static_assert(!std::is_floating_point_v<ValueT>,
|
2014-05-30 09:40:33 +04:00
|
|
|
"It's often a bad idea to assert that a floating-point number "
|
|
|
|
"is nonzero, because such assertions tend to intermittently "
|
|
|
|
"fail. Shouldn't your code gracefully handle this case instead "
|
|
|
|
"of asserting? Anyway, if you really want to do that, write an "
|
|
|
|
"explicit boolean condition, like !!x or x!=0.");
|
2014-09-07 12:04:09 +04:00
|
|
|
|
|
|
|
static const bool isValid = true;
|
|
|
|
};
|
2014-05-01 06:39:13 +04:00
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace mozilla
|
2014-05-30 09:40:33 +04:00
|
|
|
# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x) \
|
2014-09-07 12:04:09 +04:00
|
|
|
static_assert( \
|
|
|
|
mozilla::detail::AssertionConditionType<decltype(x)>::isValid, \
|
|
|
|
"invalid assertion condition")
|
2014-05-01 06:39:13 +04:00
|
|
|
#else
|
|
|
|
# define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x)
|
|
|
|
#endif
|
|
|
|
|
2017-01-17 23:37:46 +03:00
|
|
|
#if defined(DEBUG) || defined(MOZ_ASAN)
|
|
|
|
# define MOZ_REPORT_ASSERTION_FAILURE(...) \
|
|
|
|
MOZ_ReportAssertionFailure(__VA_ARGS__)
|
|
|
|
#else
|
2018-02-07 17:15:28 +03:00
|
|
|
# define MOZ_REPORT_ASSERTION_FAILURE(...) \
|
|
|
|
do { /* nothing */ \
|
|
|
|
} while (false)
|
2017-01-17 23:37:46 +03:00
|
|
|
#endif
|
|
|
|
|
2013-11-25 21:37:16 +04:00
|
|
|
/* First the single-argument form. */
|
2019-08-06 23:33:34 +03:00
|
|
|
#define MOZ_ASSERT_HELPER1(kind, expr) \
|
2014-05-30 09:40:33 +04:00
|
|
|
do { \
|
|
|
|
MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \
|
2016-07-25 16:57:30 +03:00
|
|
|
if (MOZ_UNLIKELY(!MOZ_CHECK_ASSERT_ASSIGNMENT(expr))) { \
|
2017-01-17 23:37:46 +03:00
|
|
|
MOZ_REPORT_ASSERTION_FAILURE(#expr, __FILE__, __LINE__); \
|
2019-08-06 23:33:34 +03:00
|
|
|
MOZ_CRASH_ANNOTATE(kind "(" #expr ")"); \
|
2017-02-21 20:01:38 +03:00
|
|
|
MOZ_REALLY_CRASH(__LINE__); \
|
2014-05-30 09:40:33 +04:00
|
|
|
} \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2013-11-25 21:37:16 +04:00
|
|
|
/* Now the two-argument form. */
|
2019-08-06 23:33:34 +03:00
|
|
|
#define MOZ_ASSERT_HELPER2(kind, expr, explain) \
|
|
|
|
do { \
|
|
|
|
MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \
|
|
|
|
if (MOZ_UNLIKELY(!MOZ_CHECK_ASSERT_ASSIGNMENT(expr))) { \
|
|
|
|
MOZ_REPORT_ASSERTION_FAILURE(#expr " (" explain ")", __FILE__, \
|
|
|
|
__LINE__); \
|
|
|
|
MOZ_CRASH_ANNOTATE(kind "(" #expr ") (" explain ")"); \
|
|
|
|
MOZ_REALLY_CRASH(__LINE__); \
|
|
|
|
} \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2014-04-24 12:48:00 +04:00
|
|
|
|
2019-08-06 23:33:34 +03:00
|
|
|
#define MOZ_ASSERT_GLUE(a, b) a b
|
2013-11-25 21:37:16 +04:00
|
|
|
#define MOZ_RELEASE_ASSERT(...) \
|
2019-08-06 23:33:34 +03:00
|
|
|
MOZ_ASSERT_GLUE( \
|
2014-05-30 09:40:33 +04:00
|
|
|
MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \
|
2019-08-06 23:33:34 +03:00
|
|
|
("MOZ_RELEASE_ASSERT", __VA_ARGS__))
|
2014-04-24 12:48:00 +04:00
|
|
|
|
2013-11-25 21:37:15 +04:00
|
|
|
#ifdef DEBUG
|
2019-08-06 23:33:34 +03:00
|
|
|
# define MOZ_ASSERT(...) \
|
|
|
|
MOZ_ASSERT_GLUE( \
|
|
|
|
MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \
|
|
|
|
("MOZ_ASSERT", __VA_ARGS__))
|
2011-12-19 23:28:35 +04:00
|
|
|
#else
|
2018-02-07 17:15:28 +03:00
|
|
|
# define MOZ_ASSERT(...) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
2011-12-19 23:28:35 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2019-08-06 23:33:34 +03:00
|
|
|
#if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION) || defined(DEBUG)
|
|
|
|
# define MOZ_DIAGNOSTIC_ASSERT(...) \
|
|
|
|
MOZ_ASSERT_GLUE( \
|
|
|
|
MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \
|
|
|
|
("MOZ_DIAGNOSTIC_ASSERT", __VA_ARGS__))
|
2017-06-06 00:47:02 +03:00
|
|
|
# define MOZ_DIAGNOSTIC_ASSERT_ENABLED 1
|
|
|
|
#else
|
2019-08-06 23:33:34 +03:00
|
|
|
# define MOZ_DIAGNOSTIC_ASSERT(...) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
2015-02-05 00:13:58 +03:00
|
|
|
#endif
|
|
|
|
|
2011-12-20 00:54:12 +04:00
|
|
|
/*
|
|
|
|
* MOZ_ASSERT_IF(cond1, cond2) is equivalent to MOZ_ASSERT(cond2) if cond1 is
|
|
|
|
* true.
|
|
|
|
*
|
|
|
|
* MOZ_ASSERT_IF(isPrime(num), num == 2 || isOdd(num));
|
|
|
|
*
|
|
|
|
* As with MOZ_ASSERT, MOZ_ASSERT_IF has effect only in debug builds. It is
|
|
|
|
* designed to catch bugs during debugging, not "in the field".
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
2012-04-12 04:03:07 +04:00
|
|
|
# define MOZ_ASSERT_IF(cond, expr) \
|
|
|
|
do { \
|
2014-06-13 10:34:08 +04:00
|
|
|
if (cond) { \
|
2012-04-12 04:03:07 +04:00
|
|
|
MOZ_ASSERT(expr); \
|
2014-06-13 10:34:08 +04:00
|
|
|
} \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2011-12-20 00:54:12 +04:00
|
|
|
#else
|
2018-02-07 17:15:28 +03:00
|
|
|
# define MOZ_ASSERT_IF(cond, expr) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
2011-12-20 00:54:12 +04:00
|
|
|
#endif
|
|
|
|
|
2019-04-01 02:17:07 +03:00
|
|
|
/*
|
|
|
|
* MOZ_DIAGNOSTIC_ASSERT_IF is like MOZ_ASSERT_IF, but using
|
|
|
|
* MOZ_DIAGNOSTIC_ASSERT as the underlying assert.
|
|
|
|
*
|
|
|
|
* See the block comment for MOZ_DIAGNOSTIC_ASSERT above for more details on how
|
|
|
|
* diagnostic assertions work and how to use them.
|
|
|
|
*/
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
# define MOZ_DIAGNOSTIC_ASSERT_IF(cond, expr) \
|
|
|
|
do { \
|
|
|
|
if (cond) { \
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(expr); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
#else
|
|
|
|
# define MOZ_DIAGNOSTIC_ASSERT_IF(cond, expr) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
|
|
|
#endif
|
|
|
|
|
2012-06-08 01:41:11 +04:00
|
|
|
/*
|
2014-05-30 09:40:33 +04:00
|
|
|
* MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that
|
|
|
|
* it is undefined behavior for execution to reach this point. No guarantees
|
|
|
|
* are made about what will happen if this is reached at runtime. Most code
|
|
|
|
* should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra
|
|
|
|
* asserts.
|
2012-02-23 23:32:30 +04:00
|
|
|
*/
|
2015-01-10 01:33:12 +03:00
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
2013-06-29 06:20:12 +04:00
|
|
|
# define MOZ_ASSUME_UNREACHABLE_MARKER() __builtin_unreachable()
|
2012-02-23 23:32:30 +04:00
|
|
|
#elif defined(_MSC_VER)
|
2013-06-29 06:20:12 +04:00
|
|
|
# define MOZ_ASSUME_UNREACHABLE_MARKER() __assume(0)
|
2012-06-08 01:41:11 +04:00
|
|
|
#else
|
|
|
|
# ifdef __cplusplus
|
2013-06-29 06:20:12 +04:00
|
|
|
# define MOZ_ASSUME_UNREACHABLE_MARKER() ::abort()
|
2012-06-08 01:41:11 +04:00
|
|
|
# else
|
2013-06-29 06:20:12 +04:00
|
|
|
# define MOZ_ASSUME_UNREACHABLE_MARKER() abort()
|
2012-06-08 01:41:11 +04:00
|
|
|
# endif
|
2012-02-23 23:32:30 +04:00
|
|
|
#endif
|
|
|
|
|
2011-12-20 00:54:12 +04:00
|
|
|
/*
|
2014-04-06 05:07:09 +04:00
|
|
|
* MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE([reason]) tells the compiler that it
|
|
|
|
* can assume that the macro call cannot be reached during execution. This lets
|
|
|
|
* the compiler generate better-optimized code under some circumstances, at the
|
|
|
|
* expense of the program's behavior being undefined if control reaches the
|
|
|
|
* MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE.
|
2011-12-20 00:54:12 +04:00
|
|
|
*
|
2013-06-29 05:38:31 +04:00
|
|
|
* In Gecko, you probably should not use this macro outside of performance- or
|
|
|
|
* size-critical code, because it's unsafe. If you don't care about code size
|
|
|
|
* or performance, you should probably use MOZ_ASSERT or MOZ_CRASH.
|
|
|
|
*
|
|
|
|
* SpiderMonkey is a different beast, and there it's acceptable to use
|
2014-04-06 05:07:09 +04:00
|
|
|
* MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE more widely.
|
2013-06-29 05:38:31 +04:00
|
|
|
*
|
2014-04-06 05:07:09 +04:00
|
|
|
* Note that MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE is noreturn, so it's valid
|
|
|
|
* not to return a value following a MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE
|
|
|
|
* call.
|
2013-06-29 05:38:31 +04:00
|
|
|
*
|
|
|
|
* Example usage:
|
|
|
|
*
|
|
|
|
* enum ValueType {
|
|
|
|
* VALUE_STRING,
|
|
|
|
* VALUE_INT,
|
|
|
|
* VALUE_FLOAT
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* int ptrToInt(ValueType type, void* value) {
|
2011-12-20 00:54:12 +04:00
|
|
|
* {
|
2013-06-29 05:38:31 +04:00
|
|
|
* // We know for sure that type is either INT or FLOAT, and we want this
|
|
|
|
* // code to run as quickly as possible.
|
|
|
|
* switch (type) {
|
|
|
|
* case VALUE_INT:
|
|
|
|
* return *(int*) value;
|
|
|
|
* case VALUE_FLOAT:
|
|
|
|
* return (int) *(float*) value;
|
|
|
|
* default:
|
2014-04-06 05:07:09 +04:00
|
|
|
* MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected ValueType");
|
2013-06-29 05:38:31 +04:00
|
|
|
* }
|
2011-12-20 00:54:12 +04:00
|
|
|
* }
|
|
|
|
*/
|
2014-04-06 05:07:09 +04:00
|
|
|
|
|
|
|
/*
|
2014-06-30 06:21:50 +04:00
|
|
|
* Unconditional assert in debug builds for (assumed) unreachable code paths
|
|
|
|
* that have a safe return without crashing in release builds.
|
2014-04-06 05:07:09 +04:00
|
|
|
*/
|
|
|
|
#define MOZ_ASSERT_UNREACHABLE(reason) \
|
2014-06-30 06:21:50 +04:00
|
|
|
MOZ_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason)
|
2014-04-06 05:07:09 +04:00
|
|
|
|
|
|
|
#define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \
|
|
|
|
do { \
|
|
|
|
MOZ_ASSERT_UNREACHABLE(reason); \
|
|
|
|
MOZ_ASSUME_UNREACHABLE_MARKER(); \
|
2018-02-07 17:15:28 +03:00
|
|
|
} while (false)
|
2014-04-06 05:07:09 +04:00
|
|
|
|
2015-12-27 23:27:17 +03:00
|
|
|
/**
|
|
|
|
* MOZ_FALLTHROUGH_ASSERT is an annotation to suppress compiler warnings about
|
|
|
|
* switch cases that MOZ_ASSERT(false) (or its alias MOZ_ASSERT_UNREACHABLE) in
|
|
|
|
* debug builds, but intentionally fall through in release builds to handle
|
|
|
|
* unexpected values.
|
|
|
|
*
|
2019-12-20 10:16:43 +03:00
|
|
|
* Why do we need MOZ_FALLTHROUGH_ASSERT in addition to [[fallthrough]]? In
|
2018-02-07 17:15:28 +03:00
|
|
|
* release builds, the MOZ_ASSERT(false) will expand to `do { } while (false)`,
|
2019-12-20 10:16:43 +03:00
|
|
|
* requiring a [[fallthrough]] annotation to suppress a -Wimplicit-fallthrough
|
2015-12-27 23:27:17 +03:00
|
|
|
* warning. In debug builds, the MOZ_ASSERT(false) will expand to something like
|
2019-12-20 10:16:43 +03:00
|
|
|
* `if (true) { MOZ_CRASH(); }` and the [[fallthrough]] annotation will cause
|
2015-12-27 23:27:17 +03:00
|
|
|
* a -Wunreachable-code warning. The MOZ_FALLTHROUGH_ASSERT macro breaks this
|
|
|
|
* warning stalemate.
|
|
|
|
*
|
|
|
|
* // Example before MOZ_FALLTHROUGH_ASSERT:
|
|
|
|
* switch (foo) {
|
|
|
|
* default:
|
|
|
|
* // This case wants to assert in debug builds, fall through in release.
|
|
|
|
* MOZ_ASSERT(false); // -Wimplicit-fallthrough warning in release builds!
|
2019-12-20 10:16:43 +03:00
|
|
|
* [[fallthrough]]; // but -Wunreachable-code warning in debug builds!
|
2015-12-27 23:27:17 +03:00
|
|
|
* case 5:
|
|
|
|
* return 5;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // Example with MOZ_FALLTHROUGH_ASSERT:
|
|
|
|
* switch (foo) {
|
|
|
|
* default:
|
|
|
|
* // This case asserts in debug builds, falls through in release.
|
|
|
|
* MOZ_FALLTHROUGH_ASSERT("Unexpected foo value?!");
|
|
|
|
* case 5:
|
|
|
|
* return 5;
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
2018-04-05 12:42:23 +03:00
|
|
|
# define MOZ_FALLTHROUGH_ASSERT(...) \
|
|
|
|
MOZ_CRASH("MOZ_FALLTHROUGH_ASSERT: " __VA_ARGS__)
|
2015-12-27 23:27:17 +03:00
|
|
|
#else
|
2019-12-20 10:16:43 +03:00
|
|
|
# define MOZ_FALLTHROUGH_ASSERT(...) [[fallthrough]]
|
2015-12-27 23:27:17 +03:00
|
|
|
#endif
|
|
|
|
|
2011-12-20 00:54:12 +04:00
|
|
|
/*
|
2020-03-13 20:47:14 +03:00
|
|
|
* MOZ_ALWAYS_TRUE(expr) and friends always evaluate the provided expression,
|
2020-04-09 05:07:00 +03:00
|
|
|
* in debug builds and in release builds both. Then, in debug builds and
|
|
|
|
* Nightly and DevEdition release builds, the value of the expression is
|
|
|
|
* asserted either true or false using MOZ_DIAGNOSTIC_ASSERT.
|
2011-12-20 00:54:12 +04:00
|
|
|
*/
|
2020-04-09 05:07:00 +03:00
|
|
|
#define MOZ_ALWAYS_TRUE(expr) \
|
|
|
|
do { \
|
|
|
|
if (MOZ_LIKELY(expr)) { \
|
2021-03-17 06:01:21 +03:00
|
|
|
/* Silence [[nodiscard]]. */ \
|
2020-04-09 05:07:00 +03:00
|
|
|
} else { \
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(false, #expr); \
|
|
|
|
} \
|
2020-03-13 20:47:14 +03:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define MOZ_ALWAYS_FALSE(expr) MOZ_ALWAYS_TRUE(!(expr))
|
|
|
|
#define MOZ_ALWAYS_OK(expr) MOZ_ALWAYS_TRUE((expr).isOk())
|
|
|
|
#define MOZ_ALWAYS_ERR(expr) MOZ_ALWAYS_TRUE((expr).isErr())
|
2011-12-20 00:54:12 +04:00
|
|
|
|
2014-05-06 06:02:04 +04:00
|
|
|
#undef MOZ_DUMP_ASSERTION_STACK
|
2015-09-29 18:14:50 +03:00
|
|
|
#undef MOZ_CRASH_CRASHREPORT
|
2014-05-06 06:02:04 +04:00
|
|
|
|
2021-09-09 16:29:18 +03:00
|
|
|
/*
|
|
|
|
* This is only used by Array and nsTArray classes, therefore it is not
|
|
|
|
* required when included from C code.
|
|
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace mozilla::detail {
|
|
|
|
MFBT_API MOZ_NORETURN MOZ_COLD void InvalidArrayIndex_CRASH(size_t aIndex,
|
|
|
|
size_t aLength);
|
|
|
|
} // namespace mozilla::detail
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
2013-07-24 11:41:39 +04:00
|
|
|
#endif /* mozilla_Assertions_h */
|