4 // Note by hs: my signal.h includes sys/uconctext which conflicts with
5 // asm/ucontext - this hack kinda solves the problem for me ;-)
6 // so feel free to blame me for that s**t
7 #if defined __USE_XOPEN2K8
10 #warning hs-hack: undefining __USE_XOPEN2K8 for signal.h
14 #define __USE_XOPEN2K8
17 #include <asm/ucontext.h>
19 unsigned int getMethodEntry(unsigned int, void *, void *);
21 void *method_map = NULL;
22 void *caller_map = NULL;
24 void set_mmap(void *mmap)
26 printf("set_mmap: 0x%08x\n", (unsigned int) mmap);
32 printf("get_mmap: 0x%08x\n", (unsigned int) method_map);
36 void set_cmap(void *cmap)
38 printf("set_cmap: 0x%08x\n", (unsigned int) cmap);
44 printf("get_cmap: 0x%08x\n", (unsigned int) caller_map);
49 void mainresult(unsigned int a)
51 printf("mainresult: 0x%08x\n", a);
54 void callertrap(int nSignal, siginfo_t *info, void *ctx)
56 struct ucontext *uctx = (struct ucontext *) ctx;
57 unsigned int from = (unsigned int) uctx->uc_mcontext.eip - 2;
58 unsigned int patchme = getMethodEntry(from, method_map, caller_map);
60 printf("callertrap(mctx) by 0x%08x\n", from);
62 unsigned int *to_patch = (unsigned int *) (from + 1);
63 unsigned char *insn = (unsigned char *) from;
64 *insn = 0xe8; // call opcode
65 printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
66 printf("*to_patch: 0x%08x\n", *to_patch);
67 if (*to_patch != 0x90ffff90) {
68 printf("something is wrong here. abort\n");
71 *to_patch = patchme - (from + 5);
72 printf("*to_patch: 0x%08x\n", *to_patch);
73 uctx->uc_mcontext.eip = (unsigned long) insn;
77 void register_signal(void)
79 struct sigaction segvaction;
80 segvaction.sa_sigaction = callertrap;
81 sigemptyset(&segvaction.sa_mask);
82 segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
83 sigaction(SIGILL, &segvaction, NULL);
86 unsigned int getaddr(void)
88 return (unsigned int) mainresult;