Ticket #407: small-test.c

File small-test.c, 648 bytes (added by gb, 11 years ago)
Line 
1/* cc -m32 -D_GNU_SOURCE -o small-test small-test.c */
2
3#include <stddef.h>
4#include <sys/signal.h>
5#include <sys/ucontext.h>
6
7
8void
9signal_handler(int signo, siginfo_t *info, struct ucontext *context)
10{
11  /* skip over the int $0xc5 instruction */
12  context->uc_mcontext.gregs[REG_EIP] += 2;
13}
14
15void
16do_trap()
17{
18  __asm__ volatile("int $0xc5");
19}
20
21void
22install_signal_handler(int signo, void *handler)
23{
24  sigset_t mask;
25  struct sigaction sa;
26
27  sigfillset(&mask);
28  sa.sa_sigaction = (void *)handler;
29  sa.sa_flags = SA_SIGINFO;
30  sigaction(signo, &sa, NULL);
31}
32
33main()
34{
35  install_signal_handler(SIGSEGV, (void *)signal_handler);
36  do_trap();
37}