4 #include <asm/ucontext.h>
6 unsigned int getMethodEntry(unsigned int, void *, void *);
8 void *method_map = NULL;
9 void *caller_map = NULL;
11 void set_mmap(void *mmap)
13 printf("set_mmap: 0x%08x\n", (unsigned int) mmap);
19 printf("get_mmap: 0x%08x\n", (unsigned int) method_map);
23 void set_cmap(void *cmap)
25 printf("set_cmap: 0x%08x\n", (unsigned int) cmap);
31 printf("get_cmap: 0x%08x\n", (unsigned int) caller_map);
36 void mainresult(unsigned int a)
38 printf("mainresult: 0x%08x\n", a);
41 void callertrap(int nSignal, siginfo_t *info, void *ctx)
43 struct ucontext *uctx = (struct ucontext *) ctx;
44 unsigned int from = (unsigned int) uctx->uc_mcontext.eip;
45 unsigned int patchme = getMethodEntry(from, method_map, caller_map);
47 printf("callertrap(mctx) by 0x%08x\n", from);
48 // printf("callertrap(addr) by 0x%08x\n", info->si_addr);
49 // printf("callertrap(*esp) by 0x%08x\n", * (unsigned int *) uctx->uc_mcontext.esp);
51 unsigned int *to_patch = (unsigned int *) (uctx->uc_mcontext.eip + 2);
52 unsigned char *insn = (unsigned char *) (uctx->uc_mcontext.eip);
56 printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
57 printf("*to_patch: 0x%08x\n", *to_patch);
58 if (*to_patch != 0x00000000) {
59 printf("something is wrong here. abort\n");
62 *to_patch = (unsigned int) patchme - ((unsigned int) insn + 5);
63 printf("*to_patch: 0x%08x\n", *to_patch);
64 uctx->uc_mcontext.eip = (unsigned long) insn;
68 void register_signal(void)
70 struct sigaction segvaction;
71 segvaction.sa_sigaction = callertrap;
72 sigemptyset(&segvaction.sa_mask);
73 segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
74 sigaction(SIGSEGV, &segvaction, NULL);
77 unsigned int getaddr(void)
79 return (unsigned int) mainresult;