summaryrefslogtreecommitdiff
path: root/regress/sys/kern/signal/siginfo_addr/siginfo_addr.c
blob: 473d22cb0dd5a68d8fbbc5da3148d328a45686bf (plain)
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
31
32
33
34
35
36
37
38
39
40
#include <sys/types.h>
#include <sys/signal.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#define FAULTADDR	0x123123

static void
handler(int sig, siginfo_t *sip, void *scp)
{
	char buf[1024];

	if (sip == NULL)
		_exit(1);
	if (sip->si_addr == 0)		/* wrong address */
		_exit(1);

	// snprintf(buf, sizeof buf, "addr %p\n", sip->si_addr);
	// write(STDOUT_FILENO, buf, strlen(buf));
	_exit(0);
}


int
main(int argc, char *argv[])
{
	struct sigaction sa;

	memset(&sa, 0, sizeof sa);
	sigfillset(&sa.sa_mask);
	sa.sa_sigaction = handler;
	sa.sa_flags = SA_SIGINFO;

	sigaction(SIGSEGV, &sa, NULL);
	sigaction(SIGBUS, &sa, NULL);

	*(char *)FAULTADDR = 0;
}