1 #include <assert.h> 2 #include <setjmp.h> 3 #include <signal.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 // Regression test for bug 91162: if a client had a SEGV signal handler, 8 // and jumped to a bogus address, Valgrind would abort. With the fix, 9 // the following test runs to completion correctly. 10 11 static jmp_buf myjmpbuf; 12 13 static 14 void SIGSEGV_handler(int signum) 15 { 16 __builtin_longjmp(myjmpbuf, 1); 17 } 18 19 int main(void) 20 { 21 struct sigaction sigsegv_new, sigsegv_saved; 22 int res; 23 24 /* Install own SIGSEGV handler */ 25 sigsegv_new.sa_handler = SIGSEGV_handler; 26 sigsegv_new.sa_flags = 0; 27 #if !defined(_AIX) && !defined(__APPLE__) 28 sigsegv_new.sa_restorer = NULL; 29 #endif 30 res = sigemptyset( &sigsegv_new.sa_mask ); 31 assert(res == 0); 32 33 res = sigaction( SIGSEGV, &sigsegv_new, &sigsegv_saved ); 34 assert(res == 0); 35 36 if (__builtin_setjmp(myjmpbuf) == 0) { 37 // Jump to zero; will cause seg fault 38 #if defined(__powerpc64__) || defined(_AIX) 39 unsigned long int fake_fndescr[3]; 40 fake_fndescr[0] = 0; 41 fake_fndescr[1] = 0; 42 fake_fndescr[2] = 0; 43 ((void(*)(void)) fake_fndescr) (); 44 #else 45 void (*fn)(void) = 0; 46 fn(); 47 #endif 48 fprintf(stderr, "Got here??\n"); 49 } else { 50 fprintf(stderr, "Signal caught, as expected\n"); 51 } 52 53 return 0; 54 } 55 56