]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/testsig.c
8 #include <sys/ucontext.h>
12 void alarm_handler(int sig
)
14 printf("alarm signal=%d\n", sig
);
31 void dump_regs(struct ucontext
*uc
)
33 printf("EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
34 "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
35 "EFL=%08x EIP=%08x\n",
36 uc
->uc_mcontext
.gregs
[REG_EAX
],
37 uc
->uc_mcontext
.gregs
[REG_EBX
],
38 uc
->uc_mcontext
.gregs
[REG_ECX
],
39 uc
->uc_mcontext
.gregs
[REG_EDX
],
40 uc
->uc_mcontext
.gregs
[REG_ESI
],
41 uc
->uc_mcontext
.gregs
[REG_EDI
],
42 uc
->uc_mcontext
.gregs
[REG_EBP
],
43 uc
->uc_mcontext
.gregs
[REG_ESP
],
44 uc
->uc_mcontext
.gregs
[REG_EFL
],
45 uc
->uc_mcontext
.gregs
[REG_EIP
]);
48 void sig_handler(int sig
, siginfo_t
*info
, void *puc
)
50 struct ucontext
*uc
= puc
;
52 printf("%s: si_signo=%d si_errno=%d si_code=%d si_addr=0x%08lx\n",
53 strsignal(info
->si_signo
),
54 info
->si_signo
, info
->si_errno
, info
->si_code
,
55 (unsigned long)info
->si_addr
);
62 int main(int argc
, char **argv
)
67 /* test division by zero reporting */
68 if (setjmp(jmp_env
) == 0) {
69 act
.sa_sigaction
= sig_handler
;
70 sigemptyset(&act
.sa_mask
);
71 act
.sa_flags
= SA_SIGINFO
| SA_ONESHOT
;
72 sigaction(SIGFPE
, &act
, NULL
);
74 /* now divide by zero */
79 /* test illegal instruction reporting */
80 if (setjmp(jmp_env
) == 0) {
81 act
.sa_sigaction
= sig_handler
;
82 sigemptyset(&act
.sa_mask
);
83 act
.sa_flags
= SA_SIGINFO
| SA_ONESHOT
;
84 sigaction(SIGILL
, &act
, NULL
);
86 /* now execute an invalid instruction */
90 /* test SEGV reporting */
91 if (setjmp(jmp_env
) == 0) {
92 act
.sa_sigaction
= sig_handler
;
93 sigemptyset(&act
.sa_mask
);
94 act
.sa_flags
= SA_SIGINFO
| SA_ONESHOT
;
95 sigaction(SIGSEGV
, &act
, NULL
);
97 /* now store in an invalid address */
101 act
.sa_handler
= alarm_handler
;
102 sigemptyset(&act
.sa_mask
);
104 sigaction(SIGALRM
, &act
, NULL
);
106 for(i
= 0;i
< 2; i
++) {