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;
58 unsigned int patchme = getMethodEntry(from, method_map, caller_map);
60 printf("callertrap(mctx) by 0x%08x\n", from);
61 // printf("callertrap(addr) by 0x%08x\n", info->si_addr);
62 // printf("callertrap(*esp) by 0x%08x\n", * (unsigned int *) uctx->uc_mcontext.esp);
64 unsigned int *to_patch = (unsigned int *) (uctx->uc_mcontext.eip + 2);
65 unsigned char *insn = (unsigned char *) (uctx->uc_mcontext.eip);
69 printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
70 printf("*to_patch: 0x%08x\n", *to_patch);
71 if (*to_patch != 0x00000000) {
72 printf("something is wrong here. abort\n");
75 *to_patch = (unsigned int) patchme - ((unsigned int) insn + 5);
76 printf("*to_patch: 0x%08x\n", *to_patch);
77 uctx->uc_mcontext.eip = (unsigned long) insn;
81 void register_signal(void)
83 struct sigaction segvaction;
84 segvaction.sa_sigaction = callertrap;
85 sigemptyset(&segvaction.sa_mask);
86 segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
87 sigaction(SIGSEGV, &segvaction, NULL);
90 unsigned int getaddr(void)
92 return (unsigned int) mainresult;