tests/vg_regtest: Always evaluate prerequisite expressions with sh
[valgrind.git] / memcheck / tests / badjump2.c
blob2085a30d9e23bd0541c914d455536f64d9c956ac
1 #include <assert.h>
2 #include <setjmp.h>
3 #include <signal.h>
4 #include <stdio.h>
5 #include <stdlib.h>
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.
11 static jmp_buf myjmpbuf;
13 static
14 void SIGSEGV_handler(int signum)
16 longjmp(myjmpbuf, 1);
19 int main(void)
21 struct sigaction sigsegv_new, sigsegv_saved;
22 int res;
24 /* Install own SIGSEGV handler */
25 sigsegv_new.sa_handler = SIGSEGV_handler;
26 sigsegv_new.sa_flags = 0;
27 #if !defined(__APPLE__) && !defined(__sun)
28 sigsegv_new.sa_restorer = NULL;
29 #endif
30 res = sigemptyset( &sigsegv_new.sa_mask );
31 assert(res == 0);
33 res = sigaction( SIGSEGV, &sigsegv_new, &sigsegv_saved );
34 assert(res == 0);
36 if (setjmp(myjmpbuf) == 0) {
37 // Jump to zero; will cause seg fault
38 #if defined(__powerpc64__) && (_CALL_ELF != 2)
39 unsigned long int fn[3];
40 fn[0] = 0;
41 fn[1] = 0;
42 fn[2] = 0;
43 #else
44 void (*fn)(void) = 0;
45 #endif
46 ((void(*)(void)) fn) ();
47 fprintf(stderr, "Got here??\n");
48 } else {
49 fprintf(stderr, "Signal caught, as expected\n");
52 return 0;