2 Check that a fault signal handler gets the expected info
9 #include "tests/sys_mman.h"
19 static const struct test
*cur_test
;
21 static sigjmp_buf escape
;
23 #define BADADDR ((int *)0x1234)
25 #define FILESIZE (16*1024)
26 #define MAPSIZE (2*FILESIZE)
28 static char volatile *volatile mapping
;
30 static int testsig(int sig
, int want
)
33 fprintf(stderr
, " FAIL: expected signal %d, not %d\n", want
, sig
);
39 static int testcode(int code
, int want
)
42 fprintf(stderr
, " FAIL: expected si_code==%d, not %d\n", want
, code
);
48 static int testaddr(void *addr
, volatile void *want
)
51 fprintf(stderr
, " FAIL: expected si_addr==%p, not %p\n", want
, addr
);
58 static void handler(int sig
, siginfo_t
*si
, void *uc
)
62 ok
= ok
&& testsig(sig
, cur_test
->sig
);
63 ok
= ok
&& testcode(si
->si_code
, cur_test
->code
);
65 ok
= ok
&& testaddr(si
->si_addr
, cur_test
->addr
);
68 fprintf(stderr
, " PASS\n");
70 siglongjmp(escape
, ok
+ 1);
74 extern char test1_ill
;
77 asm volatile("test1_ill: ud2");
82 asm volatile ("int3");
87 asm volatile ("int $0x10");
93 static const int sigs
[] = { SIGSEGV
, SIGILL
, SIGBUS
, SIGFPE
, SIGTRAP
};
96 sa
.sa_sigaction
= handler
;
97 sa
.sa_flags
= SA_SIGINFO
;
98 sigfillset(&sa
.sa_mask
);
100 for(i
= 0; i
< sizeof(sigs
)/sizeof(*sigs
); i
++)
101 sigaction(sigs
[i
], &sa
, NULL
);
103 fd
= open("faultstatus.tmp", O_CREAT
|O_TRUNC
|O_EXCL
, 0600);
108 unlink("faultstatus.tmp");
109 ftruncate(fd
, FILESIZE
);
111 mapping
= mmap(0, MAPSIZE
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
115 const struct test tests
[] = {
116 #define T(n, sig, code, addr) { test##n, sig, code, addr }
117 T(1, SIGILL
, ILL_ILLOPN
, &test1_ill
),
119 T(2, SIGTRAP
, 128, 0), /* TRAP_BRKPT? */
120 T(3, SIGSEGV
, 128, 0),
124 for(i
= 0; i
< sizeof(tests
)/sizeof(*tests
); i
++) {
125 cur_test
= &tests
[i
];
127 if (sigsetjmp(escape
, 1) == 0) {
128 fprintf(stderr
, "Test %d: ", i
+1);
130 fprintf(stderr
, " FAIL: no fault, or handler returned\n");