6 /* TODO(bernhard): use {u,}int* types */
9 // Note by hs: my signal.h includes sys/uconctext which conflicts with
10 // asm/ucontext - this hack kinda solves the problem for me ;-)
11 // so feel free to blame me for that s**t
12 #if defined __USE_XOPEN2K8
15 #warning hs-hack: undefining __USE_XOPEN2K8 for signal.h
19 #define __USE_XOPEN2K8
22 #include <sys/ucontext.h>
24 unsigned int mateHandler(unsigned int, unsigned int, unsigned int, unsigned int);
27 #define dprintf(args...) do { printf (args); } while (0);
29 #define dprintf(args...)
32 void chandler(int nSignal, siginfo_t *info, void *ctx)
34 mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
36 unsigned int eip = (unsigned int) mctx->gregs[REG_EIP];
37 unsigned int eax = (unsigned int) mctx->gregs[REG_EAX];
38 unsigned int ebx = (unsigned int) mctx->gregs[REG_EBX];
39 unsigned int esp = (unsigned int) mctx->gregs[REG_ESP];
40 dprintf("trap: type %d, eip 0x%08x, eax 0x%08x, ebx 0x%08x, "
41 "esp 0x%08x, *esp 0x%08x\n", nSignal, eip,
42 eax, ebx, esp, *(unsigned int*) esp);
44 mctx->gregs[REG_EIP] = mateHandler(eip, eax, ebx, esp);
47 void register_signal(void)
49 struct sigaction illaction;
50 illaction.sa_sigaction = chandler;
51 sigemptyset(&illaction.sa_mask);
52 illaction.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
53 sigaction(SIGILL, &illaction, NULL);
55 struct sigaction segvaction;
56 segvaction.sa_sigaction = chandler;
57 sigemptyset(&segvaction.sa_mask);
58 segvaction.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
59 sigaction(SIGSEGV, &segvaction, NULL);