diff --git a/Source/WTF/wtf/Assertions.cpp b/Source/WTF/wtf/Assertions.cpp index 991f99673767..a0d2118045e4 100644 --- a/Source/WTF/wtf/Assertions.cpp +++ b/Source/WTF/wtf/Assertions.cpp @@ -653,6 +653,28 @@ void WTFInitializeLogChannelStatesFromString(WTFLogChannel* channels[], size_t c } // extern "C" +#if USE(BUN_JSC_ADDITIONS) + +#if COMPILER(MSVC) +extern "C" void Bun__panicFallback(const char*, size_t) { CRASH(); } +extern "C" void Bun__panic(const char* message, size_t length); +#pragma comment(linker, "/alternatename:Bun__panic=Bun__panicFallback") +#else +extern "C" __attribute__((__weak__)) void Bun__panic(const char* message, size_t length) { CRASH(); } +#endif + +void bunPanicFromCrash(const char* file, int line, const char* function) +{ + char buf[1024]; + int len = snprintf(buf, sizeof(buf), "RELEASE_ASSERT in %s at %s:%d", function, file, line); + if (len < 0 || len >= static_cast(sizeof(buf))) + len = sizeof(buf) - 1; + Bun__panic(buf, static_cast(len)); + CRASH(); +} + +#endif // USE(BUN_JSC_ADDITIONS) + #if !ASAN_ENABLED && (OS(DARWIN) || PLATFORM(PLAYSTATION)) && (CPU(X86_64) || CPU(ARM64)) void WTFCrashWithInfoImpl(int, const char*, const char*, uint64_t reason, uint64_t misc1, uint64_t misc2, uint64_t misc3, uint64_t misc4, uint64_t misc5, uint64_t misc6) diff --git a/Source/WTF/wtf/Assertions.h b/Source/WTF/wtf/Assertions.h index 58122e8c9c1e..1bac530440f0 100644 --- a/Source/WTF/wtf/Assertions.h +++ b/Source/WTF/wtf/Assertions.h @@ -1010,12 +1010,22 @@ inline void compilerFenceForCrash() asm volatile("" ::: "memory"); } -#ifndef CRASH_WITH_INFO - #define PP_THIRD_ARG(a,b,c,...) c #define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(,),true,false,) #define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?) +#ifndef CRASH_WITH_INFO + +#if USE(BUN_JSC_ADDITIONS) + +WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void bunPanicFromCrash(const char* file, int line, const char* function); + +#define CRASH_WITH_INFO(...) do { \ + bunPanicFromCrash(__FILE__, __LINE__, WTF_PRETTY_FUNCTION); \ + } while (false) + +#else + // This is useful if you are going to stuff data into registers before crashing, like the // crashWithInfo functions below. #if !VA_OPT_SUPPORTED @@ -1031,6 +1041,8 @@ inline void compilerFenceForCrash() WTFCrashWithInfo(__LINE__, __FILE__, WTF_PRETTY_FUNCTION __VA_OPT__(,) __VA_ARGS__); \ } while (false) #endif + +#endif // USE(BUN_JSC_ADDITIONS) #endif // CRASH_WITH_INFO #ifndef CRASH_WITH_SECURITY_IMPLICATION_AND_INFO diff --git a/Source/cmake/WebKitCompilerFlags.cmake b/Source/cmake/WebKitCompilerFlags.cmake index c94cb1924ac5..240dc385e2ec 100644 --- a/Source/cmake/WebKitCompilerFlags.cmake +++ b/Source/cmake/WebKitCompilerFlags.cmake @@ -265,7 +265,8 @@ if (COMPILER_IS_GCC_OR_CLANG) -Wl,-U,_WTFTimer__secondsUntilTimer -Wl,-U,_WTFTimer__cancel -Wl,-U,_Bun__errorInstance__finalize - -Wl,-U,_Bun__reportUnhandledError) + -Wl,-U,_Bun__reportUnhandledError + -Wl,-U,_Bun__panic) else() WEBKIT_PREPEND_GLOBAL_COMPILER_FLAGS(-Wl,-u,_WTFTimer__create -Wl,-u,_WTFTimer__update @@ -274,7 +275,8 @@ if (COMPILER_IS_GCC_OR_CLANG) -Wl,-u,_WTFTimer__secondsUntilTimer -Wl,-u,_WTFTimer__cancel -Wl,-u,_Bun__errorInstance__finalize - -Wl,-u,_Bun__reportUnhandledError) + -Wl,-u,_Bun__reportUnhandledError + -Wl,-u,_Bun__panic) endif() endif ()