]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Attempt to work around issues with xend being executed unconditionally
authorTom Hughes <tom@compton.nu>
Tue, 18 Aug 2015 10:29:20 +0000 (10:29 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 18 Aug 2015 10:29:20 +0000 (10:29 +0000)
when a pthread_rwlock is used in an invalid way.

Recent glibcs use transactional memory instructions to do lock ellision
but will sometimes, when locks are used in an invalid way, may calls to
xend on systems which don't support it, on the grounds that the program
is invalid anyway.

So we try and catch and ignore the resulting SIGILL in our tests that
deliberately work with invalid locks.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15565

15 files changed:
drd/tests/tc12_rwl_trivial.stderr.exp
drd/tests/tc12_rwl_trivial.vgtest
helgrind/tests/safe-pthread.h [new file with mode: 0644]
helgrind/tests/tc12_rwl_trivial.c
helgrind/tests/tc12_rwl_trivial.stderr.exp
helgrind/tests/tc12_rwl_trivial.stderr.exp-solaris
helgrind/tests/tc12_rwl_trivial.vgtest
helgrind/tests/tc20_verifywrap.c
helgrind/tests/tc20_verifywrap.stderr.exp
helgrind/tests/tc20_verifywrap.stderr.exp-glibc-2.18
helgrind/tests/tc20_verifywrap.stderr.exp-mips32
helgrind/tests/tc20_verifywrap.stderr.exp-mips32-b
helgrind/tests/tc20_verifywrap.stderr.exp-s390x
helgrind/tests/tc20_verifywrap.stderr.exp-solaris
helgrind/tests/tc20_verifywrap.vgtest

index 554515d10e93494bd519a7ff10890c423937f0d9..1a67b3d60399bc4256dc79f3efb52c1bc63867a8 100644 (file)
@@ -1,6 +1,7 @@
 
 Reader-writer lock not locked by calling thread: rwlock 0x.........
    at 0x........: pthread_rwlock_unlock (drd_pthread_intercepts.c:?)
+   by 0x........: safe_pthread_rwlock_unlock (safe-pthread.h:43)
    by 0x........: main (tc12_rwl_trivial.c:29)
 rwlock 0x........ was first observed at:
    at 0x........: pthread_rwlock_init (drd_pthread_intercepts.c:?)
index 0cb3825cbf47c0a03fcd93cd0f03a85e40c4431a..21e698113c8477f07661e58339278dcdd0f1e470 100644 (file)
@@ -1,2 +1,3 @@
 prereq: ./supported_libpthread
+vgopts: --sigill-diagnostics=no
 prog: ../../helgrind/tests/tc12_rwl_trivial
diff --git a/helgrind/tests/safe-pthread.h b/helgrind/tests/safe-pthread.h
new file mode 100644 (file)
index 0000000..1210f3a
--- /dev/null
@@ -0,0 +1,56 @@
+#include <pthread.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <errno.h>
+#include <assert.h>
+
+static jmp_buf env;
+
+/*
+ * Starting with glibc 2.20 some pthread calls may execute
+ * an xend instruction unconditionally when a lock is used in
+ * a way that is invalid so defined a sigill handler that can
+ * convert these invalid instructions to a normal error.
+ */
+static void sigill_handler( int signum, siginfo_t *siginfo, void *sigcontext ) {
+   unsigned char *pc = siginfo->si_addr;
+   assert( pc[0] == 0x0f && pc[1] == 0x01 && pc[2] == 0xd5 );
+   longjmp( env, EPERM );
+}
+
+/*
+ * Wrapper for pthread_rwlock_unlock which may execute xend
+ * unconditionally when used on a lock that is not locked.
+ *
+ * Note that we return 0 instead of EPERM because that is what
+ * glibc normally does - error reporting is optional.
+ */
+static int safe_pthread_rwlock_unlock( pthread_rwlock_t *rwlock ) {
+#if __GLIBC_PREREQ(2,20) && ( defined(__i386__) || defined(__x86_64__) )
+   struct sigaction sa;
+   struct sigaction oldsa;
+   int r;
+
+   sa.sa_handler = NULL;
+   sa.sa_sigaction = sigill_handler;
+   sigemptyset( &sa.sa_mask );
+   sa.sa_flags = SA_SIGINFO;
+   sa.sa_restorer = NULL;
+   
+   sigaction( SIGILL, &sa, &oldsa );
+
+   if ( ( r = setjmp( env ) ) == 0 ) {
+     r = pthread_rwlock_unlock( rwlock );
+   } else {
+     r = 0;
+   }
+
+   sigaction( SIGILL, &oldsa, NULL );
+
+   return r;
+#else
+   return pthread_rwlock_unlock( rwlock );
+#endif
+}
+
+#define pthread_rwlock_unlock safe_pthread_rwlock_unlock
index c9c83985f17e4b3e1c88d9579ef7fc20f1bb8439..a84428e018e5fbd56b841f11dbfb259466a98ebe 100644 (file)
@@ -5,7 +5,7 @@
 #define _GNU_SOURCE 1
 
 #include <stdio.h>
-#include <pthread.h>
+#include "safe-pthread.h"
 #include <assert.h>
 
 /* Do trivial stuff with a reader-writer lock. */
index db33a0889e944b4a38dcaaaa02893d5a6de95389..76607e04284007fcda062f30dd02eda8ee324427 100644 (file)
@@ -8,6 +8,7 @@ Thread #x is the program's root thread
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc12_rwl_trivial.c:29)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
index aa16b571c16f62975e627a63246517cd28ee6167..04d2d90e7e8627b5ca6f1ccd8f96b2078568113c 100644 (file)
@@ -8,6 +8,7 @@ Thread #x is the program's root thread
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc12_rwl_trivial.c:29)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init (hg_intercepts.c:...)
index fdcd6446ebba0a394e623f03e103e5b0f3ff4b06..d0009d8145b124da30499263484847e5116bd17e 100644 (file)
@@ -1 +1,2 @@
+vgopts: --sigill-diagnostics=no
 prog: tc12_rwl_trivial
index 899a285a73a573a89e449a100899d408bb8f5f09..3c976a2c3c57d643d9a5d4655754ac201122e4c6 100644 (file)
@@ -15,7 +15,7 @@
 #include <string.h>
 #include <assert.h>
 #include <unistd.h>
-#include <pthread.h>
+#include "safe-pthread.h"
 #include <semaphore.h>
 
 #if !defined(__APPLE__)
index 97c09f4e1709b588aafac186cd2baf9018b9dc28..6d40ac61c726cea59a1a1bdf8b6d9aba5c1fa3f8 100644 (file)
@@ -163,6 +163,7 @@ Thread #x's call to pthread_cond_timedwait failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:189)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -180,6 +181,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:206)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -199,6 +201,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:227)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
index 8869b71d52b0a4552ee13b9e43f55727990b8199..f10967317ae11d8cc3f2c8035907149776879ef2 100644 (file)
@@ -155,6 +155,7 @@ Thread #x's call to pthread_cond_timedwait failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:189)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -169,6 +170,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:206)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
index e0e587bf2fa2fc2a49e0b081d4c8987fa78e0758..52f0b27f635b7377b164f7f544a52c8ecccfccd4 100644 (file)
@@ -165,6 +165,7 @@ Thread #x's call to pthread_cond_timedwait failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:189)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -179,6 +180,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:206)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -195,6 +197,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:227)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
index 01ccd00b9ea8f14ecec1ce6a1eef5c232c115736..07f8db662cf748908a86cc4e1d8bd252067de12e 100644 (file)
@@ -165,6 +165,7 @@ Thread #x's call to pthread_cond_timedwait failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:189)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -179,6 +180,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:206)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -195,6 +197,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:227)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
index d510cddd3101e5185c40bf25c30c204196858c7c..3f60f79457587f82a72a0725757a6b228717c632 100644 (file)
@@ -165,6 +165,7 @@ Thread #x's call to pthread_cond_timedwait failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:189)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -179,6 +180,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:206)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
@@ -195,6 +197,7 @@ Thread #x unlocked a not-locked lock at 0x........
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:227)
   Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...)
index b869be7f916e4f1d0394dac144535c603a59017d..da7db08f6020611b2e7a22d3b30ef3e699c83873 100644 (file)
@@ -155,6 +155,7 @@ Thread #x's call to pthread_cond_timedwait failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:189)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init (hg_intercepts.c:...)
@@ -180,6 +181,7 @@ Thread #x's call to pthread_rwlock_unlock failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:206)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init (hg_intercepts.c:...)
@@ -207,6 +209,7 @@ Thread #x's call to pthread_rwlock_unlock failed
 Thread #x unlocked a not-locked lock at 0x........
    at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...)
    by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...)
+   ...
    by 0x........: main (tc20_verifywrap.c:227)
  Lock at 0x........ was first observed
    at 0x........: pthread_rwlock_init (hg_intercepts.c:...)
index 2accc94f438991ebee58b86011bf65b2dbc626b8..0ee9c143d93f7532ba4ec1669a6305f6023d8f52 100644 (file)
@@ -1,3 +1,3 @@
 prereq: test -e tc20_verifywrap
 prog: tc20_verifywrap
-vgopts: --read-var-info=yes
+vgopts: --read-var-info=yes --sigill-diagnostics=no