blob: 361966b6c14b17870a87f2d2a00f5751d302ed41 [file] [log] [blame]
nethercote4d714382004-10-13 09:47:24 +00001#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
11static jmp_buf myjmpbuf;
12
13static
14void SIGSEGV_handler(int signum)
15{
16 __builtin_longjmp(myjmpbuf, 1);
17}
18
19int 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 sigsegv_new.sa_restorer = NULL;
28 res = sigemptyset( &sigsegv_new.sa_mask );
29 assert(res == 0);
30
31 res = sigaction( SIGSEGV, &sigsegv_new, &sigsegv_saved );
32 assert(res == 0);
33
34 if (__builtin_setjmp(myjmpbuf) == 0) {
35 // Jump to zero; will cause seg fault
36 void (*fn)(void) = 0;
37 fn();
38 fprintf(stderr, "Got here??\n");
39 } else {
40 fprintf(stderr, "Signal caught, as expected\n");
41 }
42
43 return 0;
44}
45