]>
git.proxmox.com Git - qemu.git/blob - tests/testsig.c
8 #include <sys/ucontext.h>
12 void alarm_handler(int sig
)
14 printf("alarm signal=%d\n", sig
);
18 void dump_regs(struct ucontext
*uc
)
20 printf("EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
21 "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
22 "EFL=%08x EIP=%08x\n",
23 uc
->uc_mcontext
.gregs
[EAX
],
24 uc
->uc_mcontext
.gregs
[EBX
],
25 uc
->uc_mcontext
.gregs
[ECX
],
26 uc
->uc_mcontext
.gregs
[EDX
],
27 uc
->uc_mcontext
.gregs
[ESI
],
28 uc
->uc_mcontext
.gregs
[EDI
],
29 uc
->uc_mcontext
.gregs
[EBP
],
30 uc
->uc_mcontext
.gregs
[ESP
],
31 uc
->uc_mcontext
.gregs
[EFL
],
32 uc
->uc_mcontext
.gregs
[EIP
]);
35 void sig_handler(int sig
, siginfo_t
*info
, void *puc
)
37 struct ucontext
*uc
= puc
;
39 printf("%s: si_signo=%d si_errno=%d si_code=%d si_addr=0x%08lx\n",
40 strsignal(info
->si_signo
),
41 info
->si_signo
, info
->si_errno
, info
->si_code
,
42 (unsigned long)info
->si_addr
);
49 int main(int argc
, char **argv
)
54 /* test division by zero reporting */
55 if (setjmp(jmp_env
) == 0) {
56 act
.sa_sigaction
= sig_handler
;
57 sigemptyset(&act
.sa_mask
);
58 act
.sa_flags
= SA_SIGINFO
| SA_ONESHOT
;
59 sigaction(SIGFPE
, &act
, NULL
);
61 /* now divide by zero */
66 /* test illegal instruction reporting */
67 if (setjmp(jmp_env
) == 0) {
68 act
.sa_sigaction
= sig_handler
;
69 sigemptyset(&act
.sa_mask
);
70 act
.sa_flags
= SA_SIGINFO
| SA_ONESHOT
;
71 sigaction(SIGILL
, &act
, NULL
);
73 /* now execute an invalid instruction */
77 /* test SEGV reporting */
78 if (setjmp(jmp_env
) == 0) {
79 act
.sa_sigaction
= sig_handler
;
80 sigemptyset(&act
.sa_mask
);
81 act
.sa_flags
= SA_SIGINFO
| SA_ONESHOT
;
82 sigaction(SIGSEGV
, &act
, NULL
);
84 /* now store in an invalid address */
88 act
.sa_handler
= alarm_handler
;
89 sigemptyset(&act
.sa_mask
);
91 sigaction(SIGALRM
, &act
, NULL
);
93 for(i
= 0;i
< 2; i
++) {