Skip to content

Commit

Permalink
[WTF] Make Assertion inlined
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270952
rdar://124569636

Reviewed by Keith Miller.

This inlined function with optnone is originally introduced in 203263@main to fix internal build failures.
But these affected code no longer exists. This patch makes WTFCrashWithInfo completely inlined function with
appropriate inline asm so that we can make caller of them optimized.

* Source/WTF/wtf/Assertions.h:

Canonical link: https://commits.webkit.org/276095@main
  • Loading branch information
Constellation committed Mar 14, 2024
1 parent 95dd2f7 commit c5e2f6f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 31 deletions.
29 changes: 0 additions & 29 deletions Source/WTF/wtf/Assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,35 +650,6 @@ void WTFReleaseLogStackTrace(WTFLogChannel* channel)
} // extern "C"

#if (OS(DARWIN) || PLATFORM(PLAYSTATION)) && (CPU(X86_64) || CPU(ARM64))
#if CPU(X86_64)

#define CRASH_INST "int3"

// This ordering was chosen to be consistent with JSC's JIT asserts. We probably shouldn't change this ordering
// since it would make tooling crash reports much harder. If, for whatever reason, we decide to change the ordering
// here we should update the abortWithuint64_t functions.
#define CRASH_GPR0 "r11"
#define CRASH_GPR1 "r10"
#define CRASH_GPR2 "r9"
#define CRASH_GPR3 "r8"
#define CRASH_GPR4 "r15"
#define CRASH_GPR5 "r14"
#define CRASH_GPR6 "r13"

#elif CPU(ARM64) // CPU(X86_64)

#define CRASH_INST "brk #0xc471"

// See comment above on the ordering.
#define CRASH_GPR0 "x16"
#define CRASH_GPR1 "x17"
#define CRASH_GPR2 "x19" // We skip x18, which is reserved on ARM64 for platform use.
#define CRASH_GPR3 "x20"
#define CRASH_GPR4 "x21"
#define CRASH_GPR5 "x22"
#define CRASH_GPR6 "x23"

#endif // CPU(ARM64)

void WTFCrashWithInfoImpl(int, const char*, const char*, int, uint64_t reason, uint64_t misc1, uint64_t misc2, uint64_t misc3, uint64_t misc4, uint64_t misc5, uint64_t misc6)
{
Expand Down
68 changes: 66 additions & 2 deletions Source/WTF/wtf/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,56 @@ WTF_EXPORT_PRIVATE void WTFReleaseLogStackTrace(WTFLogChannel*);

WTF_EXPORT_PRIVATE bool WTFIsDebuggerAttached(void);

#if CPU(X86_64)

#define CRASH_INST "int3"

// This ordering was chosen to be consistent with JSC's JIT asserts. We probably shouldn't change this ordering
// since it would make tooling crash reports much harder. If, for whatever reason, we decide to change the ordering
// here we should update the abortWithuint64_t functions.
#define CRASH_ARG_GPR0 "rdi"
#define CRASH_ARG_GPR1 "rsi"
#define CRASH_ARG_GPR2 "rdx"
#define CRASH_ARG_GPR3 "rcx"

#define CRASH_GPR0 "r11"
#define CRASH_GPR1 "r10"
#define CRASH_GPR2 "r9"
#define CRASH_GPR3 "r8"
#define CRASH_GPR4 "r15"
#define CRASH_GPR5 "r14"
#define CRASH_GPR6 "r13"

#elif CPU(ARM64) // CPU(X86_64)

#define CRASH_INST "brk #0xc471"

// See comment above on the ordering.
#define CRASH_ARG_GPR0 "x0"
#define CRASH_ARG_GPR1 "x1"
#define CRASH_ARG_GPR2 "x2"
#define CRASH_ARG_GPR3 "x3"

#define CRASH_GPR0 "x16"
#define CRASH_GPR1 "x17"
#define CRASH_GPR2 "x19" // We skip x18, which is reserved on ARM64 for platform use.
#define CRASH_GPR3 "x20"
#define CRASH_GPR4 "x21"
#define CRASH_GPR5 "x22"
#define CRASH_GPR6 "x23"

#endif // CPU(ARM64)

#if COMPILER(MSVC)
#define WTFBreakpointTrap() __debugbreak()
#elif ASAN_ENABLED
#define WTFBreakpointTrap() __builtin_trap()
#elif CPU(X86_64) || CPU(X86)
#define WTFBreakpointTrap() asm volatile ("int3")
#define WTFBreakpointTrap() asm volatile (CRASH_INST)
#elif CPU(ARM_THUMB2)
#define WTFBreakpointTrap() asm volatile ("bkpt #0")
#elif CPU(ARM64)
#define WTFBreakpointTrap() asm volatile ("brk #0xc471")
#define WTFBreakpointTrap() asm volatile (CRASH_INST)
#else
#define WTFBreakpointTrap() WTFCrash() // Not implemented.
#endif
Expand Down Expand Up @@ -722,7 +762,11 @@ WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void WTFCrashWithInfoI
WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void WTFCrashWithInfoImpl(int line, const char* file, const char* function, int counter, uint64_t reason, uint64_t misc1, uint64_t misc2);
WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void WTFCrashWithInfoImpl(int line, const char* file, const char* function, int counter, uint64_t reason, uint64_t misc1);
WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void WTFCrashWithInfoImpl(int line, const char* file, const char* function, int counter, uint64_t reason);
#if (OS(DARWIN) || PLATFORM(PLAYSTATION)) && (CPU(X86_64) || CPU(ARM64))
NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter);
#else
NO_RETURN_DUE_TO_CRASH NOT_TAIL_CALLED void WTFCrashWithInfo(int line, const char* file, const char* function, int counter);
#endif

template<typename T>
ALWAYS_INLINE uint64_t wtfCrashArg(T* arg) { return reinterpret_cast<uintptr_t>(arg); }
Expand Down Expand Up @@ -772,6 +816,24 @@ NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char*
WTFCrashWithInfoImpl(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1), wtfCrashArg(misc2), wtfCrashArg(misc3), wtfCrashArg(misc4), wtfCrashArg(misc5), wtfCrashArg(misc6));
}

#if (OS(DARWIN) || PLATFORM(PLAYSTATION)) && (CPU(X86_64) || CPU(ARM64))

NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter)
{
uint64_t x0Value = static_cast<uint64_t>(static_cast<int64_t>(line));
uint64_t x1Value = reinterpret_cast<uintptr_t>(file);
uint64_t x2Value = reinterpret_cast<uintptr_t>(function);
uint64_t x3Value = static_cast<uint64_t>(static_cast<int64_t>(counter));
register uint64_t x0GPR asm(CRASH_ARG_GPR0) = x0Value;
register uint64_t x1GPR asm(CRASH_ARG_GPR1) = x1Value;
register uint64_t x2GPR asm(CRASH_ARG_GPR2) = x2Value;
register uint64_t x3GPR asm(CRASH_ARG_GPR3) = x3Value;
__asm__ volatile (CRASH_INST : : "r"(x0GPR), "r"(x1GPR), "r"(x2GPR), "r"(x3GPR));
__builtin_trap();
}

#else

inline void WTFCrashWithInfo(int, const char*, const char*, int)
#if COMPILER(CLANG)
__attribute__((optnone))
Expand All @@ -780,6 +842,8 @@ inline void WTFCrashWithInfo(int, const char*, const char*, int)
CRASH();
}

#endif

namespace WTF {
inline void isIntegralOrPointerType() { }

Expand Down

0 comments on commit c5e2f6f

Please sign in to comment.