4 #include <asm/ucontext.h>
6 unsigned int patchme = 0;
7 void print_foo(unsigned int addr)
9 // printf("\n\nprint foo: 0x%08x\n", addr);
13 void callertrap(int nSignal, siginfo_t *info, void *ctx)
15 struct ucontext *uctx = (struct ucontext *) ctx;
17 printf("callertrap(mctx) by 0x%08x\n", uctx->uc_mcontext.eip);
18 // printf("callertrap(addr) by 0x%08x\n", info->si_addr);
19 // printf("callertrap(*esp) by 0x%08x\n", * (unsigned int *) uctx->uc_mcontext.esp);
21 unsigned int *to_patch = (unsigned int *) (uctx->uc_mcontext.eip + 2);
22 unsigned char *insn = (unsigned int *) (uctx->uc_mcontext.eip);
26 printf(" to_patch: 0x%08x\n", to_patch);
27 printf("*to_patch: 0x%08x\n", *to_patch);
28 if (*to_patch != 0x00000000) {
29 printf("something is wrong here. abort\n");
32 *to_patch = (unsigned int) patchme - ((unsigned int) insn + 5);
33 printf("*to_patch: 0x%08x\n", *to_patch);
34 uctx->uc_mcontext.eip = insn;
38 void register_signal(void)
40 struct sigaction segvaction;
41 segvaction.sa_sigaction = callertrap;
42 sigemptyset(&segvaction.sa_mask);
43 segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
44 sigaction(SIGSEGV, &segvaction, NULL);
47 unsigned int getaddr(void)
49 return (unsigned int) print_foo;