about summary refs log tree commit diff stats
path: root/tests32/test18.c
blob: f609b7544162f7b63f4f2d4d768e97d39309324a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <signal.h>
#include <setjmp.h>
#include <stdio.h>

static jmp_buf context_buf;

static void segv_handler(int sig)
{
	printf("sig = %d\n", sig);
	longjmp(context_buf, 1);
}

void test()
{
	if(!setjmp(context_buf)) {
		int *bad_ptr = (int*)0xdeadbeef;
		printf("*bad_ptr = %d\n", *bad_ptr);
	} else {
		printf("got bad_ptr\n");
	}
}

int main()
{
	if(signal(SIGSEGV, segv_handler) == SIG_ERR)
		printf("Err = %m\n");
	//printf("handler = %p\n", segv_handler);
	test();
	return 0;
}