This source file includes following definitions.
- WTFReportFatalError
- UNREACHABLE_FOR_PLATFORM
#ifndef WTF_Assertions_h
#define WTF_Assertions_h
#include "wtf/Compiler.h"
#include "wtf/WTFExport.h"
#ifdef NDEBUG
#define ASSERTIONS_DISABLED_DEFAULT 1
#else
#define ASSERTIONS_DISABLED_DEFAULT 0
#endif
#ifndef BACKTRACE_DISABLED
#define BACKTRACE_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef ASSERT_DISABLED
#define ASSERT_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#define ASSERT_ENABLED !ASSERT_DISABLED
#ifndef ASSERT_MSG_DISABLED
#define ASSERT_MSG_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef ASSERT_ARG_DISABLED
#define ASSERT_ARG_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef FATAL_DISABLED
#define FATAL_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef ERROR_DISABLED
#define ERROR_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef LOG_DISABLED
#define LOG_DISABLED ASSERTIONS_DISABLED_DEFAULT
#endif
#if COMPILER(GCC) && !defined(__OBJC__)
#define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__((__format__(printf, formatStringArgument, extraArguments)))
#else
#define WTF_ATTRIBUTE_PRINTF(formatStringArgument, extraArguments)
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { WTFLogChannelOff, WTFLogChannelOn } WTFLogChannelState;
typedef struct {
WTFLogChannelState state;
} WTFLogChannel;
WTF_EXPORT void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion);
WTF_EXPORT void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
WTF_EXPORT void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
WTF_EXPORT void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
WTF_EXPORT void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
WTF_EXPORT void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
WTF_EXPORT void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
WTF_EXPORT void WTFLogAlways(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
WTF_EXPORT void WTFGetBacktrace(void** stack, int* size);
WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31);
WTF_EXPORT void WTFPrintBacktrace(void** stack, int size);
typedef void (*WTFCrashHookFunction)();
WTF_EXPORT void WTFSetCrashHook(WTFCrashHookFunction);
WTF_EXPORT void WTFInvokeCrashHook();
WTF_EXPORT void WTFInstallReportBacktraceOnCrashHook();
#ifdef __cplusplus
}
#endif
#ifndef IMMEDIATE_CRASH
#if COMPILER(GCC)
#define IMMEDIATE_CRASH() __builtin_trap()
#else
#define IMMEDIATE_CRASH() ((void(*)())0)()
#endif
#endif
#ifndef CRASH
#define CRASH() \
(WTFReportBacktrace(), \
WTFInvokeCrashHook(), \
(*(int*)0xfbadbeef = 0), \
IMMEDIATE_CRASH())
#endif
#if COMPILER(CLANG)
#define NO_RETURN_DUE_TO_CRASH NO_RETURN
#else
#define NO_RETURN_DUE_TO_CRASH
#endif
#if BACKTRACE_DISABLED
#define BACKTRACE() ((void)0)
#else
#define BACKTRACE() do { \
WTFReportBacktrace(); \
} while(false)
#endif
#if OS(WIN)
#undef ASSERT
#endif
#if ASSERT_DISABLED
#define ASSERT(assertion) ((void)0)
#define ASSERT_AT(assertion, file, line, function) ((void)0)
#define ASSERT_NOT_REACHED() ((void)0)
#define NO_RETURN_DUE_TO_ASSERT
#define ASSERT_UNUSED(variable, assertion) ((void)variable)
#else
#define ASSERT(assertion) \
(!(assertion) ? \
(WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
CRASH()) : \
(void)0)
#define ASSERT_AT(assertion, file, line, function) \
(!(assertion) ? \
(WTFReportAssertionFailure(file, line, function, #assertion), \
CRASH()) : \
(void)0)
#define ASSERT_NOT_REACHED() do { \
WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
CRASH(); \
} while (0)
#define ASSERT_UNUSED(variable, assertion) ASSERT(assertion)
#define NO_RETURN_DUE_TO_ASSERT NO_RETURN_DUE_TO_CRASH
#endif
#ifdef ADDRESS_SANITIZER
#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) \
(!(assertion) ? \
(WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
CRASH()) : \
(void)0)
#define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT_WITH_SECURITY_IMPLICATION(assertion)
#else
#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ASSERT(assertion)
#define RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(assertion) RELEASE_ASSERT(assertion)
#endif
#if defined(ADDRESS_SANITIZER) || ASSERT_ENABLED
#define SECURITY_ASSERT_ENABLED 1
#else
#define SECURITY_ASSERT_ENABLED 0
#endif
#if ASSERT_MSG_DISABLED
#define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
#else
#define ASSERT_WITH_MESSAGE(assertion, ...) do \
if (!(assertion)) { \
WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
CRASH(); \
} \
while (0)
#endif
#if ASSERT_MSG_DISABLED
#define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable)
#else
#define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \
if (!(assertion)) { \
WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
CRASH(); \
} \
while (0)
#endif
#if ASSERT_ARG_DISABLED
#define ASSERT_ARG(argName, assertion) ((void)0)
#else
#define ASSERT_ARG(argName, assertion) do \
if (!(assertion)) { \
WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
CRASH(); \
} \
while (0)
#endif
#ifndef COMPILE_ASSERT
#if COMPILER_SUPPORTS(C_STATIC_ASSERT)
#define COMPILE_ASSERT(exp, name) _Static_assert((exp), #name)
#elif COMPILER_SUPPORTS(CXX_STATIC_ASSERT)
#define COMPILE_ASSERT(exp, name) static_assert((exp), #name)
#else
#define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1]
#endif
#endif
#if FATAL_DISABLED
#define FATAL(...) ((void)0)
#else
#define FATAL(...) do { \
WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__); \
CRASH(); \
} while (0)
#endif
#if ERROR_DISABLED
#define WTF_LOG_ERROR(...) ((void)0)
#else
#define WTF_LOG_ERROR(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
#endif
#if LOG_DISABLED
#define WTF_LOG(channel, ...) ((void)0)
#else
#define WTF_LOG(channel, ...) WTFLog(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), __VA_ARGS__)
#define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
#define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
#endif
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
static inline void UNREACHABLE_FOR_PLATFORM()
{
ASSERT_NOT_REACHED();
}
#pragma clang diagnostic pop
#else
#define UNREACHABLE_FOR_PLATFORM() ASSERT_NOT_REACHED()
#endif
#if ASSERT_DISABLED
#define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0)
#define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion)
#define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH()
#else
#define RELEASE_ASSERT(assertion) ASSERT(assertion)
#define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertion, __VA_ARGS__)
#define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED()
#endif
#define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate, referencePredicate) \
inline thisType* to##thisType(argumentType* argumentName) \
{ \
ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \
return static_cast<thisType*>(argumentName); \
} \
inline const thisType* to##thisType(const argumentType* argumentName) \
{ \
ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \
return static_cast<const thisType*>(argumentName); \
} \
inline thisType& to##thisType(argumentType& argumentName) \
{ \
ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
return static_cast<thisType&>(argumentName); \
} \
inline const thisType& to##thisType(const argumentType& argumentName) \
{ \
ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
return static_cast<const thisType&>(argumentName); \
} \
void to##thisType(const thisType*); \
void to##thisType(const thisType&)
#endif