This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Use objc_getRealizedClassList_trylock if available
ClosedPublic

Authored by JDevlieghere on Jun 7 2022, 2:11 PM.

Details

Summary

In order to avoid stranding the Objective-C runtime lock, we switched from objc_copyRealizedClassList to its non locking variant objc_copyRealizedClassList_nolock. Not taking the lock was relatively safe because we run this expression on one thread only, but it was still possible that someone was in the middle of modifying this list while we were trying to read it. Worst case that would result in a crash in the inferior without side-effects and we'd unwind and try again later.

With the introduction of macOS Ventura, we can use objc_getRealizedClassList_trylock instead. It has semantics similar to objc_copyRealizedClassList_nolock, but instead of not locking at all, the function returns if the lock is already taken, which avoids the aforementioned crash without stranding the Objective-C runtime lock. Because LLDB gets to allocate the underlying memory we also avoid stranding the malloc lock.

rdar://89373233

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 7 2022, 2:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 2:11 PM
JDevlieghere requested review of this revision.Jun 7 2022, 2:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 2:11 PM
jingham accepted this revision.Jun 8 2022, 9:44 AM

One grammatical correction and a couple of questions. But I'm also fine with the way it is.

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
2023

Is it worth doing these as exit_scope dingii so we don't have to worry about returning early w/o doing them? There's a fairly long way from the AllocateMemory to the DeallocateMemory.

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
318

grammar

359

You didn't do this, so it's not necessary to address it, but why do we have three identical structure definitions with just different names? Were they going to be different at some point then ended up not being?

This revision is now accepted and ready to land.Jun 8 2022, 9:44 AM
JDevlieghere marked 3 inline comments as done.Jun 8 2022, 11:33 AM

Thanks Jim, I've addressed your comments in the final commit.