Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Source/WTF/wtf/Assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(sizeof(buf)))
len = sizeof(buf) - 1;
Bun__panic(buf, static_cast<size_t>(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)
Expand Down
16 changes: 14 additions & 2 deletions Source/WTF/wtf/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Comment on lines +1023 to +1026
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

BUN path silently discards ... args and drops the isIntegralOrPointerType type guard.

The non-BUN CRASH_WITH_INFO calls WTF::isIntegralOrPointerType(__VA_ARGS__) before crashing, which produces a hard compile error if a caller passes a non-integral/non-pointer type. The BUN path accepts any args without type-checking and silently ignores them. Code written in a BUN-only build environment that passes wrong-typed values to CRASH_WITH_INFO will compile cleanly but break non-BUN builds, making it a potential CI blind spot.

Consider preserving the guard even though the values themselves are intentionally dropped:

🛡️ Proposed fix – retain type guard
 `#define` CRASH_WITH_INFO(...) do { \
+        WTF::isIntegralOrPointerType(__VA_ARGS__); \
         bunPanicFromCrash(__FILE__, __LINE__, WTF_PRETTY_FUNCTION); \
     } while (false)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#define CRASH_WITH_INFO(...) do { \
bunPanicFromCrash(__FILE__, __LINE__, WTF_PRETTY_FUNCTION); \
} while (false)
`#define` CRASH_WITH_INFO(...) do { \
WTF::isIntegralOrPointerType(__VA_ARGS__); \
bunPanicFromCrash(__FILE__, __LINE__, WTF_PRETTY_FUNCTION); \
} while (false)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Source/WTF/wtf/Assertions.h` around lines 1019 - 1022, The BUN macro
CRASH_WITH_INFO currently discards __VA_ARGS__ and omits the type check, so
restore the compile-time guard by invoking
WTF::isIntegralOrPointerType(__VA_ARGS__) (or an equivalent
static_assert/type-trait expression) inside the macro while still not using the
values — for example evaluate the trait in a void-cast or unused constexpr to
force the type-check and then call bunPanicFromCrash(__FILE__, __LINE__,
WTF_PRETTY_FUNCTION); ensure the macro name CRASH_WITH_INFO and the
bunPanicFromCrash call remain unchanged and that only the type-check expression
referencing __VA_ARGS__ is added so non-integral/non-pointer arguments cause a
compile error.

#else

// This is useful if you are going to stuff data into registers before crashing, like the
// crashWithInfo functions below.
#if !VA_OPT_SUPPORTED
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Source/cmake/WebKitCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ()

Expand Down
Loading