From: Mark Wielaard Date: Wed, 19 Aug 2015 13:26:28 +0000 (+0000) Subject: Also install sigsegv handler in safe-pthread tests wrapper. X-Git-Tag: svn/VALGRIND_3_11_0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b322bb0260bd905ad396e1332c3f5d61d628047;p=thirdparty%2Fvalgrind.git Also install sigsegv handler in safe-pthread tests wrapper. In case we do recognize the xend, but detect it is invalid (used outside a transaction) we generate a segsegv instead of a sigill. Handle that in the same way in the test case. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15570 --- diff --git a/drd/tests/tc12_rwl_trivial.stderr.exp b/drd/tests/tc12_rwl_trivial.stderr.exp index 3f4973f1a1..73163e7b23 100644 --- a/drd/tests/tc12_rwl_trivial.stderr.exp +++ b/drd/tests/tc12_rwl_trivial.stderr.exp @@ -1,7 +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:41) + by 0x........: safe_pthread_rwlock_unlock (safe-pthread.h:58) by 0x........: main (tc12_rwl_trivial.c:29) rwlock 0x........ was first observed at: at 0x........: pthread_rwlock_init (drd_pthread_intercepts.c:?) diff --git a/helgrind/tests/safe-pthread.h b/helgrind/tests/safe-pthread.h index 4c35bd6e00..0634ef6163 100644 --- a/helgrind/tests/safe-pthread.h +++ b/helgrind/tests/safe-pthread.h @@ -18,6 +18,16 @@ static void sigill_handler( int signum, siginfo_t *siginfo, void *sigcontext ) { longjmp( env, EPERM ); } +/* + * Same as above, but in case we do recognize the xend, + * but detect it is invalid (used outside a transaction) + * and generate a segv. Unfortunately then si_addr is, + * just zero, so we cannot add an assert/sanity check. + */ +static void segv_handler( int signum, siginfo_t *siginfo, void *sigcontext ) { + longjmp( env, EPERM ); +} + /* * Wrapper for pthread_rwlock_unlock which may execute xend * unconditionally when used on a lock that is not locked. @@ -26,16 +36,23 @@ static void sigill_handler( int signum, siginfo_t *siginfo, void *sigcontext ) { * glibc normally does - error reporting is optional. */ static int safe_pthread_rwlock_unlock( pthread_rwlock_t *rwlock ) { - struct sigaction sa; - struct sigaction oldsa; + struct sigaction sa_ill, sa_segv; + struct sigaction oldsa_ill, oldsa_segv; int r; - sa.sa_handler = NULL; - sa.sa_sigaction = sigill_handler; - sigemptyset( &sa.sa_mask ); - sa.sa_flags = SA_SIGINFO; + sa_ill.sa_handler = NULL; + sa_ill.sa_sigaction = sigill_handler; + sigemptyset( &sa_ill.sa_mask ); + sa_ill.sa_flags = SA_SIGINFO; - sigaction( SIGILL, &sa, &oldsa ); + sigaction( SIGILL, &sa_ill, &oldsa_ill ); + + sa_segv.sa_handler = NULL; + sa_segv.sa_sigaction = segv_handler; + sigemptyset( &sa_segv.sa_mask ); + sa_segv.sa_flags = SA_SIGINFO; + + sigaction( SIGSEGV, &sa_segv, &oldsa_segv ); if ( ( r = setjmp( env ) ) == 0 ) { r = pthread_rwlock_unlock( rwlock ); @@ -43,7 +60,8 @@ static int safe_pthread_rwlock_unlock( pthread_rwlock_t *rwlock ) { r = 0; } - sigaction( SIGILL, &oldsa, NULL ); + sigaction( SIGILL, &oldsa_ill, NULL ); + sigaction( SIGSEGV, &oldsa_segv, NULL ); return r; }