xref: /openbsd-src/regress/lib/libpthread/siginfo/siginfo.c (revision b17f6c98146ddc0e3530670a34673ab2c9ea67e8)
1 /* $OpenBSD: siginfo.c,v 1.12 2024/08/29 15:16:43 claudio 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 
23 	CHECKe(sigaction(SIGSEGV, NULL, &sa));
24 	ASSERT(sa.sa_handler == SIG_DFL);
25 	ASSERT(siginfo != NULL);
26 	dprintf(STDOUT_FILENO, "act_handler: signal %d, siginfo %p, "
27 		 "context %p\naddr %p, code %d, trap %d\n", signal, siginfo,
28 		 context, siginfo->si_addr, siginfo->si_code,
29 		 siginfo->si_trapno);
30  	ASSERT(siginfo->si_addr == BOGUS);
31 	ASSERT(siginfo->si_code == SEGV_MAPERR ||
32 	       siginfo->si_code == SEGV_ACCERR);
33 	SUCCEED;
34 }
35 
36 int
37 main(int argc, char **argv)
38 {
39 	struct sigaction act;
40 
41 	act.sa_sigaction = act_handler;
42 	sigemptyset(&act.sa_mask);
43 	act.sa_flags = SA_SIGINFO | SA_RESETHAND | SA_NODEFER;
44 	CHECKe(sigaction(SIGSEGV, &act, NULL));
45 	*BOGUS = 1;
46 	PANIC("How did we get here?");
47 }
48