[PATCH] D63942: [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.2

Julian Lettner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 10:29:02 PDT 2019


yln created this revision.
Herald added subscribers: llvm-commits, Sanitizers, kubamracek.
Herald added projects: Sanitizers, LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63942

Files:
  compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
  compiler-rt/lib/tsan/rtl/tsan_rtl.h


Index: compiler-rt/lib/tsan/rtl/tsan_rtl.h
===================================================================
--- compiler-rt/lib/tsan/rtl/tsan_rtl.h
+++ compiler-rt/lib/tsan/rtl/tsan_rtl.h
@@ -325,7 +325,6 @@
 
 struct JmpBuf {
   uptr sp;
-  uptr mangled_sp;
   int int_signal_send;
   bool in_blocking_func;
   uptr in_signal_handler;
Index: compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
+++ compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
@@ -486,7 +486,7 @@
   }
 }
 
-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.
@@ -494,7 +494,6 @@
   // 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;
@@ -529,12 +528,10 @@
 # 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)
@@ -558,7 +555,7 @@
 // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63942.207094.patch
Type: text/x-patch
Size: 1933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190628/1f25b566/attachment-0001.bin>


More information about the llvm-commits mailing list