Files
ftmemsim-valgrind/helgrind/tests/safe-semaphore.h
Mark Wielaard 235c116f2d Add safe sem_post handler and glibc-2.21 expected output for helgrind tests.
This fixes the tc18 and tc20 testcases.

On some bad semaphores glibc now might just abort, we catch the SIGABRT
and turn it into a EINVAL. The program will see this, but the helgrind
wrapper won't. Which works for tc18 since there is an alternate exp file
with that result (silent bad sem_post). We add a similar alternative exp
file for tc21.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15620
2015-09-04 09:41:42 +00:00

42 lines
811 B
C

#include <semaphore.h>
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include <assert.h>
static sigjmp_buf env;
/*
* Newer glibc crashes on really bogus semaphors.
* Catch a SIGABRT and turn it into a EINVAL.
*/
static void abrt_handler( int signum, siginfo_t *siginfo, void *sigcontext ) {
siglongjmp( env, EINVAL );
}
static int safe_sem_post( sem_t *sem ) {
struct sigaction sa;
struct sigaction oldsa;
int r, e;
sa.sa_handler = NULL;
sa.sa_sigaction = abrt_handler;
sigemptyset( &sa.sa_mask );
sa.sa_flags = SA_SIGINFO;
sigaction( SIGABRT, &sa, &oldsa );
if ( ( e = sigsetjmp( env, 1 ) ) == 0 ) {
r = sem_post( sem );
} else {
r = -1;
}
errno = e;
sigaction( SIGABRT, &oldsa, NULL );
return r;
}
#define sem_post safe_sem_post