Skip to content

Commit

Permalink
Add logging when mach exception thread adoption fails
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=272494
rdar://126089415

Reviewed by Justin Michaud.

We're seeing crashes from these asserts but it's not clear what the state is at that
time. Adding some extra logging.

* Source/WTF/wtf/Assertions.h:
(wtfCrashArg):
* Source/WTF/wtf/threads/Signals.cpp:
(WTF::setExceptionPorts):
(WTF::registerThreadForMachExceptionHandling):

Canonical link: https://commits.webkit.org/277333@main
  • Loading branch information
kmiller68 committed Apr 10, 2024
1 parent 15650dc commit a922441
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/WTF/wtf/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ template<typename T>
ALWAYS_INLINE uint64_t wtfCrashArg(T* arg) { return reinterpret_cast<uintptr_t>(arg); }

template<typename T>
ALWAYS_INLINE uint64_t wtfCrashArg(T arg) { return arg; }
ALWAYS_INLINE uint64_t wtfCrashArg(T arg) { return static_cast<uint64_t>(arg); }

template<typename T>
NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason)
Expand Down
6 changes: 3 additions & 3 deletions Source/WTF/wtf/threads/Signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ inline void setExceptionPorts(const AbstractLocker& threadGroupLocker, Thread& t
// Otherwise use the new style
const exception_behavior_t newBehavior = MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY_PROTECTED;
kern_return_t result = thread_adopt_exception_handler(thread.machThread(), handlers.exceptionPort, handlers.addedExceptions & activeExceptions, newBehavior, MACHINE_THREAD_STATE);
RELEASE_ASSERT_WITH_MESSAGE(result == KERN_SUCCESS, "thread adopt port failed due to %s", mach_error_string(result));
RELEASE_ASSERT(result == KERN_SUCCESS, result, handlers.exceptionPort, handlers.addedExceptions, activeExceptions);
return;
}
#endif // CPU(ARM64) && HAVE(HARDENED_MACH_EXCEPTIONS)

const exception_behavior_t newBehavior = MACH_EXCEPTION_CODES | EXCEPTION_STATE;
kern_return_t result = thread_set_exception_ports(thread.machThread(), handlers.addedExceptions & activeExceptions, handlers.exceptionPort, newBehavior, MACHINE_THREAD_STATE);
RELEASE_ASSERT_WITH_MESSAGE(result == KERN_SUCCESS, "thread set port failed due to %s", mach_error_string(result));
RELEASE_ASSERT(result == KERN_SUCCESS, result, handlers.exceptionPort, handlers.addedExceptions, activeExceptions);
}

static ThreadGroup& activeThreads()
Expand All @@ -392,7 +392,7 @@ static ThreadGroup& activeThreads()

void registerThreadForMachExceptionHandling(Thread& thread)
{
RELEASE_ASSERT(g_wtfConfig.signalHandlers.initState == SignalHandlers::InitState::AddedHandlers);
RELEASE_ASSERT(g_wtfConfig.signalHandlers.initState == SignalHandlers::InitState::AddedHandlers, g_wtfConfig.signalHandlers.initState);
Locker locker { activeThreads().getLock() };
if (activeThreads().add(locker, thread) == ThreadGroupAddResult::NewlyAdded)
setExceptionPorts(locker, thread);
Expand Down

0 comments on commit a922441

Please sign in to comment.