1 /* $OpenBSD: siginfo.c,v 1.10 2003/07/31 21:48:06 deraadt Exp $ */
2 /* PUBLIC DOMAIN Oct 2002 <marc@snafu.org> */
3 
4 /*
5  * test SA_SIGINFO support.   Also check that SA_RESETHAND does the right
6  * thing.
7  */
8 
9 #include <signal.h>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <stdlib.h>
13 
14 #include "test.h"
15 
16 #define BOGUS	(char *)0x987230
17 
18 static void
19 act_handler(int signal, siginfo_t *siginfo, void *context)
20 {
21 	struct sigaction sa;
22 	char * str;
23 
24 	CHECKe(sigaction(SIGSEGV, NULL, &sa));
25 	ASSERT(sa.sa_handler == SIG_DFL);
26 	ASSERT(siginfo != NULL);
27 	asprintf(&str, "act_handler: signal %d, siginfo %p, context %p\n"
28 		 "addr %p, code %d, trap %d\n", signal, siginfo, context,
29 		 siginfo->si_addr, siginfo->si_code, siginfo->si_trapno);
30 	write(STDOUT_FILENO, str, strlen(str));
31 	free(str);
32  	ASSERT(siginfo->si_addr == BOGUS);
33 	ASSERT(siginfo->si_code != SI_USER);
34 	ASSERT(siginfo->si_code > 0 && siginfo->si_code <= NSIGSEGV);
35 	SUCCEED;
36 }
37 
38 int
39 main(int argc, char **argv)
40 {
41 	struct sigaction act;
42 
43 	act.sa_sigaction = act_handler;
44 	sigemptyset(&act.sa_mask);
45 	act.sa_flags = SA_SIGINFO | SA_RESETHAND | SA_NODEFER;
46 	CHECKe(sigaction(SIGSEGV, &act, NULL));
47 	*BOGUS = 1;
48 	PANIC("How did we get here?");
49 }
50