Skip to content

Commit

Permalink
[TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.2
Browse files Browse the repository at this point in the history
Switch `LongJmp` over to lookup JmpBuf via plain old (unmangled) SP.
This makes the computation of mangled SPs in the TSan assembly files
unnecessary, which will be cleaned up in follow-up revisions.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D63942

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364818 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
yln committed Jul 1, 2019
1 parent 9e72c27 commit 65810c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 4 additions & 7 deletions lib/tsan/rtl/tsan_interceptors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,14 @@ static void JmpBufGarbageCollect(ThreadState *thr, uptr sp) {
}
}

static void SetJmp(ThreadState *thr, uptr sp, uptr mangled_sp) {
static void SetJmp(ThreadState *thr, uptr sp) {
if (!thr->is_inited) // called from libc guts during bootstrap
return;
// Cleanup old bufs.
JmpBufGarbageCollect(thr, sp);
// Remember the buf.
JmpBuf *buf = thr->jmp_bufs.PushBack();
buf->sp = sp;
buf->mangled_sp = mangled_sp;
buf->shadow_stack_pos = thr->shadow_stack_pos;
ThreadSignalContext *sctx = SigCtx(thr);
buf->int_signal_send = sctx ? sctx->int_signal_send : 0;
Expand Down Expand Up @@ -529,12 +528,10 @@ static void LongJmp(ThreadState *thr, uptr *env) {
# endif
#endif
uptr sp = UnmangleLongJmpSp(mangled_sp);
// Find the saved buf by mangled_sp.
// Find the saved buf with matching sp.
for (uptr i = 0; i < thr->jmp_bufs.Size(); i++) {
JmpBuf *buf = &thr->jmp_bufs[i];
if (buf->mangled_sp == mangled_sp) {
CHECK_EQ(buf->sp, sp);
// TODO(yln): Lookup via sp, remove mangled_sp from struct.
if (buf->sp == sp) {
CHECK_GE(thr->shadow_stack_pos, buf->shadow_stack_pos);
// Unwind the stack.
while (thr->shadow_stack_pos > buf->shadow_stack_pos)
Expand All @@ -558,7 +555,7 @@ static void LongJmp(ThreadState *thr, uptr *env) {
// FIXME: put everything below into a common extern "C" block?
extern "C" void __tsan_setjmp(uptr sp, uptr mangled_sp) {
cur_thread_init();
SetJmp(cur_thread(), sp, mangled_sp);
SetJmp(cur_thread(), sp);
}

#if SANITIZER_MAC
Expand Down
1 change: 0 additions & 1 deletion lib/tsan/rtl/tsan_rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ struct ThreadSignalContext;

struct JmpBuf {
uptr sp;
uptr mangled_sp;
int int_signal_send;
bool in_blocking_func;
uptr in_signal_handler;
Expand Down

0 comments on commit 65810c2

Please sign in to comment.