mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-10 05:37:06 +00:00
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
42 lines
811 B
C
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
|