[PATCH] D15052: [tsan] Fix signals and setjmp/longjmp on OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 29 02:52:21 PST 2015


kubabrecka created this revision.
kubabrecka added reviewers: dvyukov, samsonov, glider, kcc.
kubabrecka added subscribers: llvm-commits, zaks.anna, ismailp.

1) There's a few wrongly defined things in tsan_interceptors.cc,
2) a typo in `tsan_rtl_amd64.S` which calls setjmp instead of sigsetjmp in the interceptor, and
3) on OS X, accessing an mprotected page results in a SIGBUS (and not SIGSEGV).


http://reviews.llvm.org/D15052

Files:
  lib/tsan/rtl/tsan_interceptors.cc
  lib/tsan/rtl/tsan_rtl_amd64.S
  test/tsan/signal_longjmp.cc

Index: test/tsan/signal_longjmp.cc
===================================================================
--- test/tsan/signal_longjmp.cc
+++ test/tsan/signal_longjmp.cc
@@ -12,6 +12,12 @@
 #include <stdio.h>
 #include <sys/mman.h>
 
+#ifdef __APPLE__
+#define SIGNAL_TO_HANDLE SIGBUS
+#else
+#define SIGNAL_TO_HANDLE SIGSEGV
+#endif
+
 sigjmp_buf fault_jmp;
 volatile int fault_expected;
 
@@ -44,7 +50,7 @@
     exit(1);
   }
 
-  if (sigaction(SIGSEGV, &act, NULL)) {
+  if (sigaction(SIGNAL_TO_HANDLE, &act, NULL)) {
     perror("sigaction");
     exit(1);
   }
Index: lib/tsan/rtl/tsan_rtl_amd64.S
===================================================================
--- lib/tsan/rtl/tsan_rtl_amd64.S
+++ lib/tsan/rtl/tsan_rtl_amd64.S
@@ -300,7 +300,7 @@
   movq _ZN14__interception14real_sigsetjmpE at GOTPCREL(%rip), %rdx
   jmp *(%rdx)
 #else
-  jmp ASM_TSAN_SYMBOL(setjmp)
+  jmp ASM_TSAN_SYMBOL(sigsetjmp)
 #endif
   CFI_ENDPROC
 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
Index: lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -160,6 +160,9 @@
 #if SANITIZER_FREEBSD
   int sa_flags;
   __sanitizer_sigset_t sa_mask;
+#elif SANITIZER_MAC
+  __sanitizer_sigset_t sa_mask;
+  int sa_flags;
 #else
   __sanitizer_sigset_t sa_mask;
 #ifndef __mips__
@@ -172,7 +175,7 @@
 const sighandler_t SIG_DFL = (sighandler_t)0;
 const sighandler_t SIG_IGN = (sighandler_t)1;
 const sighandler_t SIG_ERR = (sighandler_t)-1;
-#if SANITIZER_FREEBSD
+#if SANITIZER_FREEBSD || SANITIZER_MAC
 const int SA_SIGINFO = 0x40;
 const int SIG_SETMASK = 3;
 #elif defined(__mips__)
@@ -2033,7 +2036,7 @@
   sigactions[sig].sa_flags = *(volatile int*)&act->sa_flags;
   internal_memcpy(&sigactions[sig].sa_mask, &act->sa_mask,
       sizeof(sigactions[sig].sa_mask));
-#if !SANITIZER_FREEBSD
+#if !SANITIZER_FREEBSD && !SANITIZER_MAC
   sigactions[sig].sa_restorer = act->sa_restorer;
 #endif
   sigaction_t newact;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15052.41343.patch
Type: text/x-patch
Size: 2030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151129/8c9c72fd/attachment.bin>


More information about the llvm-commits mailing list