4 #include <asm/ucontext.h>
6 unsigned int getMethodEntry(void *, char *);
7 void *method_map = NULL;
9 void set_mmap(void *mmap)
11 printf("set_mmap: 0x%08x\n", (unsigned int) mmap);
17 printf("get_mmap: 0x%08x\n", (unsigned int) method_map);
22 void mainresult(unsigned int a)
24 printf("mainresult: 0x%08x\n", a);
27 void callertrap(int nSignal, siginfo_t *info, void *ctx)
29 struct ucontext *uctx = (struct ucontext *) ctx;
30 unsigned int patchme = getMethodEntry(method_map, "fib");
32 printf("callertrap(mctx) by 0x%08x\n", (unsigned int) uctx->uc_mcontext.eip);
33 // printf("callertrap(addr) by 0x%08x\n", info->si_addr);
34 // printf("callertrap(*esp) by 0x%08x\n", * (unsigned int *) uctx->uc_mcontext.esp);
36 unsigned int *to_patch = (unsigned int *) (uctx->uc_mcontext.eip + 2);
37 unsigned char *insn = (unsigned char *) (uctx->uc_mcontext.eip);
41 printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
42 printf("*to_patch: 0x%08x\n", *to_patch);
43 if (*to_patch != 0x00000000) {
44 printf("something is wrong here. abort\n");
47 *to_patch = (unsigned int) patchme - ((unsigned int) insn + 5);
48 printf("*to_patch: 0x%08x\n", *to_patch);
49 uctx->uc_mcontext.eip = (unsigned long) insn;
53 void register_signal(void)
55 struct sigaction segvaction;
56 segvaction.sa_sigaction = callertrap;
57 sigemptyset(&segvaction.sa_mask);
58 segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
59 sigaction(SIGSEGV, &segvaction, NULL);
62 unsigned int getaddr(void)
64 return (unsigned int) mainresult;