Skip to content

Commit

Permalink
Add asm-volatile trick
Browse files Browse the repository at this point in the history
  • Loading branch information
bamx23 committed May 23, 2024
1 parent 9337991 commit 9f493ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static void captureStackTrace(void*, std::type_info*, void (*)(void*)) __attribu
{
kssc_initSelfThread(&g_stackCursor, 2);
}
__asm__ __volatile__(""); // thwart tail-call optimization
}

typedef void (*cxa_throw_type)(void*, std::type_info*, void (*)(void*));
Expand All @@ -103,6 +104,7 @@ extern "C"
orig_cxa_throw = (cxa_throw_type) dlsym(RTLD_NEXT, "__cxa_throw");
}
orig_cxa_throw(thrown_exception, tinfo, dest);
__asm__ __volatile__(""); // thwart tail-call optimization
__builtin_unreachable();
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/KSCrashRecordingCore/KSStackCursor_SelfThread.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ void kssc_initSelfThread(KSStackCursor *cursor, int skipEntries) __attribute__((
SelfThreadContext* context = (SelfThreadContext*)cursor->context;
int backtraceLength = backtrace((void**)context->backtrace, MAX_BACKTRACE_LENGTH);
kssc_initWithBacktrace(cursor, context->backtrace, backtraceLength, skipEntries + 1);
__asm__ __volatile__(""); // thwart tail-call optimization
}

0 comments on commit 9f493ba

Please sign in to comment.