Bug 491394i - (vgModuleLocal_addDiCfSI): Assertion 'di->fsm.have_rx_map && di->fsm...
[valgrind.git] / helgrind / tests / safe-semaphore.h
blobc0e003bcbcb3a0594cd9a5f9af090ce0ca4562d0
1 #include <semaphore.h>
2 #include <signal.h>
3 #include <setjmp.h>
4 #include <errno.h>
5 #include <assert.h>
7 static sigjmp_buf env;
9 /*
10 * Newer glibc crashes on really bogus semaphors.
11 * Catch a SIGABRT and turn it into a EINVAL.
13 static void abrt_handler( int signum, siginfo_t *siginfo, void *sigcontext ) {
14 siglongjmp( env, EINVAL );
17 static int safe_sem_post( sem_t *sem ) __attribute__((unused));
18 static int safe_sem_post( sem_t *sem ) {
19 struct sigaction sa;
20 struct sigaction oldsa;
21 int r, e;
23 sa.sa_handler = NULL;
24 sa.sa_sigaction = abrt_handler;
25 sigemptyset( &sa.sa_mask );
26 sa.sa_flags = SA_SIGINFO;
28 sigaction( SIGABRT, &sa, &oldsa );
30 if ( ( e = sigsetjmp( env, 1 ) ) == 0 ) {
31 r = sem_post( sem );
32 } else {
33 r = -1;
35 errno = e;
37 sigaction( SIGABRT, &oldsa, NULL );
39 return r;
42 #define sem_post safe_sem_post