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 mallocObject(int);
25 unsigned int mateHandler(unsigned int, unsigned int, unsigned int, unsigned int);
28 #define dprintf(args...) do { printf (args); } while (0);
30 #define dprintf(args...)
33 void mainresult(unsigned int a)
35 dprintf("mainresult: 0x%08x\n", a);
38 void chandler(int nSignal, siginfo_t *info, void *ctx)
40 mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
42 unsigned int eip = (unsigned int) mctx->gregs[REG_EIP];
43 unsigned int eax = (unsigned int) mctx->gregs[REG_EAX];
44 unsigned int ebx = (unsigned int) mctx->gregs[REG_EBX];
45 unsigned int esp = (unsigned int) mctx->gregs[REG_ESP];
46 dprintf("trap: type %d, eip 0x%08x, eax 0x%08x, ebx 0x%08x, "
47 "esp 0x%08x, *esp 0x%08x\n", nSignal, eip,
48 eax, ebx, esp, *(unsigned int*) esp);
50 mctx->gregs[REG_EIP] = mateHandler(eip, eax, ebx, esp);
53 void register_signal(void)
55 struct sigaction illaction;
56 illaction.sa_sigaction = chandler;
57 sigemptyset(&illaction.sa_mask);
58 illaction.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
59 sigaction(SIGILL, &illaction, NULL);
61 struct sigaction segvaction;
62 segvaction.sa_sigaction = chandler;
63 sigemptyset(&segvaction.sa_mask);
64 segvaction.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
65 sigaction(SIGSEGV, &segvaction, NULL);
68 unsigned int getaddr(void)
70 return (unsigned int) mainresult;
73 unsigned int getMallocObjectAddr(void)
75 return (unsigned int) mallocObject;