Skip to content

Commit 0da9466

Browse files
authored
Make async unsafe more clear (#5610)
1 parent 43597ba commit 0da9466

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

Sources/Sentry/SentryThreadInspector.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ @interface SentryThreadInspector ()
2828

2929
// We need a C function to retrieve information from the stack trace in order to avoid
3030
// calling into not async-signal-safe code while there are suspended threads.
31+
// If asyncUnsafeSymbolicate is `true` the stack will be symbolicated but the function is no longer
32+
// async-signal-safe.
3133
unsigned int
3234
getStackEntriesFromThread(SentryCrashThread thread, struct SentryCrashMachineContext *context,
33-
SentryCrashStackEntry *buffer, unsigned int maxEntries, bool symbolicate)
35+
SentryCrashStackEntry *buffer, unsigned int maxEntries, bool asyncUnsafeSymbolicate)
3436
{
3537
sentrycrashmc_getContextForThread(thread, context, NO);
3638
SentryCrashStackCursor stackCursor;
@@ -41,7 +43,7 @@ @interface SentryThreadInspector ()
4143
while (stackCursor.advanceCursor(&stackCursor)) {
4244
if (entries == maxEntries)
4345
break;
44-
if (symbolicate == false || stackCursor.symbolicate(&stackCursor)) {
46+
if (asyncUnsafeSymbolicate == false || stackCursor.symbolicate(&stackCursor)) {
4547
buffer[entries] = stackCursor.stackEntry;
4648
entries++;
4749
}

Sources/Sentry/SentryUseNSExceptionCallstackWrapper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ - (instancetype)initWithName:(NSExceptionName)aName
4545
enumerateObjectsUsingBlock:^(NSNumber *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
4646
SentryCrashStackCursor stackCursor;
4747
stackCursor.stackEntry.address = [obj unsignedLongValue];
48-
sentrycrashsymbolicator_symbolicate(&stackCursor);
48+
sentrycrashsymbolicator_symbolicate_async_unsafe_sentryDlAddr(&stackCursor);
4949

5050
[frames addObject:[crashStackToEntryMapper
5151
sentryCrashStackEntryToSentryFrame:stackCursor.stackEntry]];

Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void
5656
sentrycrashsc_initCursor(SentryCrashStackCursor *cursor,
5757
void (*resetCursor)(SentryCrashStackCursor *), bool (*advanceCursor)(SentryCrashStackCursor *))
5858
{
59-
cursor->symbolicate = sentrycrashsymbolicator_symbolicate;
59+
cursor->symbolicate = sentrycrashsymbolicator_symbolicate_async_unsafe_sentryDlAddr;
6060
cursor->advanceCursor = advanceCursor != NULL ? advanceCursor : g_advanceCursor;
6161
cursor->resetCursor = resetCursor != NULL ? resetCursor : sentrycrashsc_resetCursor;
6262
cursor->resetCursor(cursor);

Sources/SentryCrash/Recording/Tools/SentryCrashSymbolicator.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#define CALL_INSTRUCTION_FROM_RETURN_ADDRESS(A) (DETAG_INSTRUCTION_ADDRESS((A)) - 1)
5252

5353
static bool
54-
symbolicate_internal(SentryCrashStackCursor *cursor, bool asyncUnsafe)
54+
symbolicate_internal(SentryCrashStackCursor *cursor, bool useDlAddr)
5555
{
5656
if (cursor->stackEntry.address == SentryCrashSC_ASYNC_MARKER) {
5757
cursor->stackEntry.imageAddress = 0;
@@ -65,7 +65,7 @@ symbolicate_internal(SentryCrashStackCursor *cursor, bool asyncUnsafe)
6565

6666
bool symbols_succeed = false;
6767

68-
if (asyncUnsafe) {
68+
if (useDlAddr) {
6969
symbols_succeed = dladdr((void *)cursor->stackEntry.address, &symbolsBuffer) != 0;
7070
} else {
7171
// sentrycrashdl_dladdr isn't async safe, but we've been using it for
@@ -91,13 +91,15 @@ symbolicate_internal(SentryCrashStackCursor *cursor, bool asyncUnsafe)
9191
}
9292

9393
bool
94-
sentrycrashsymbolicator_symbolicate(SentryCrashStackCursor *cursor)
94+
sentrycrashsymbolicator_symbolicate_async_unsafe_sentryDlAddr(SentryCrashStackCursor *cursor)
9595
{
96+
// Symbolicate using `sentrycrashdl_dladdr` note this is not async-signal-safe
9697
return symbolicate_internal(cursor, false);
9798
}
9899

99100
bool
100101
sentrycrashsymbolicator_symbolicate_async_unsafe(SentryCrashStackCursor *cursor)
101102
{
103+
// Symbolicate using `dladdr` note this is not async-signal-safe
102104
return symbolicate_internal(cursor, true);
103105
}

Sources/SentryCrash/Recording/Tools/SentryCrashSymbolicator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ extern "C" {
3939
*
4040
* @return True if successful.
4141
*/
42-
bool sentrycrashsymbolicator_symbolicate(SentryCrashStackCursor *cursor);
42+
bool sentrycrashsymbolicator_symbolicate_async_unsafe_sentryDlAddr(SentryCrashStackCursor *cursor);
4343

44-
/** Same as ``sentrycrashsymbolicator_symbolicate`` but faster and async unsafe.
44+
/** Same as ``sentrycrashsymbolicator_symbolicate_async_unsafe_sentryDlAddr`` but faster.
4545
*/
4646
bool sentrycrashsymbolicator_symbolicate_async_unsafe(SentryCrashStackCursor *cursor);
4747

0 commit comments

Comments
 (0)