Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / regress / lib / libc / siginfo / sigsegv / sigsegv.c
blob919e621aa71e0737dceacde93aa766bf0055b946
1 /* $NetBSD: sigsegv.c,v 1.4 2003/11/13 06:48:31 simonb Exp $ */
3 #include <sys/ucontext.h>
5 #include <assert.h>
6 #include <signal.h>
7 #include <stdio.h>
8 #include <stdlib.h>
10 void
11 sigsegv(int signo, siginfo_t *info, void *ptr)
13 #ifdef DEBUG
14 printf("%d %p %p\n", signo, info, ptr);
15 if (info != NULL) {
16 printf("si_signo=%d\n", info->si_signo);
17 printf("si_errno=%d\n", info->si_errno);
18 printf("si_code=%d\n", info->si_code);
19 printf("si_trap=%d\n", info->si_trap);
20 printf("si_addr=%p\n", info->si_addr);
22 if (ptr != NULL) {
23 ucontext_t *ctx = ptr;
24 int i;
25 mcontext_t *mc = &ctx->uc_mcontext;
26 printf("uc_flags 0x%x\n", ctx->uc_flags);
27 printf("uc_link %p\n", ctx->uc_link);
28 for (i = 0; i < sizeof(ctx->uc_sigmask.__bits) /
29 sizeof(ctx->uc_sigmask.__bits[0]); i++)
30 printf("uc_sigmask[%d] 0x%x\n", i,
31 ctx->uc_sigmask.__bits[i]);
32 printf("uc_stack %p %lu 0x%x\n", ctx->uc_stack.ss_sp,
33 (unsigned long)ctx->uc_stack.ss_size,
34 ctx->uc_stack.ss_flags);
35 for (i = 0; i < sizeof(mc->__gregs)/sizeof(mc->__gregs[0]); i++)
36 printf("uc_mcontext.greg[%d] 0x%x\n", i,
37 mc->__gregs[i]);
39 #endif
40 assert(info->si_signo == SIGSEGV);
41 assert(info->si_errno == 0);
42 assert(info->si_code == SEGV_MAPERR);
43 assert(info->si_addr == (void *)0);
44 exit(0);
47 int
48 main(void)
50 struct sigaction sa;
51 sa.sa_flags = SA_SIGINFO;
52 sa.sa_sigaction = sigsegv;
53 sigemptyset(&sa.sa_mask);
54 sigaction(SIGSEGV, &sa, NULL);
55 *(long *)0 = 0;
56 return 0;