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 *);
20 unsigned int getFieldAddr(unsigned int, void*);
22 #define NEW_MAP(prefix) \
23 void* prefix ## _map = NULL; \
24 void set_ ## prefix ## map(void *map) \
26 printf("set_%s: 0x%08x\n", #prefix , (unsigned int) map); \
27 prefix ## _map = map; \
29 void *get_ ## prefix ## map() \
31 printf("get_%s: 0x%08x\n", #prefix , (unsigned int) prefix ## _map); \
32 return prefix ## _map; \
40 void mainresult(unsigned int a)
42 printf("mainresult: 0x%08x\n", a);
45 void callertrap(int nSignal, siginfo_t *info, void *ctx)
47 struct ucontext *uctx = (struct ucontext *) ctx;
48 unsigned int from = (unsigned int) uctx->uc_mcontext.eip - 2;
49 unsigned int patchme = getMethodEntry(from, method_map, trap_map);
51 printf("callertrap(mctx) by 0x%08x\n", from);
53 unsigned int *to_patch = (unsigned int *) (from + 1);
54 unsigned char *insn = (unsigned char *) from;
55 *insn = 0xe8; // call opcode
56 printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
57 printf("*to_patch: 0x%08x\n", *to_patch);
58 if (*to_patch != 0x90ffff90) {
59 printf("something is wrong here. abort\n");
62 *to_patch = patchme - (from + 5);
63 printf("*to_patch: 0x%08x\n", *to_patch);
64 uctx->uc_mcontext.eip = (unsigned long) insn;
68 void staticfieldtrap(int nSignal, siginfo_t *info, void *ctx)
70 struct ucontext *uctx = (struct ucontext *) ctx;
71 unsigned int from = (unsigned int) uctx->uc_mcontext.eip;
72 unsigned int patchme = getFieldAddr(from, trap_map);
73 unsigned int *to_patch = (unsigned int *) (from + 2);
75 printf("staticfieldtrap by 0x%08x\n", from);
76 printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
77 printf("*to_patch: 0x%08x\n", *to_patch);
78 if (*to_patch != 0x00000000) {
79 printf("something is wrong here. abort\n");
83 printf("*to_patch: 0x%08x\n", *to_patch);
86 void register_signal(void)
88 struct sigaction illaction;
89 illaction.sa_sigaction = callertrap;
90 sigemptyset(&illaction.sa_mask);
91 illaction.sa_flags = SA_SIGINFO | SA_RESTART;
92 sigaction(SIGILL, &illaction, NULL);
94 struct sigaction segvaction;
95 segvaction.sa_sigaction = staticfieldtrap;
96 sigemptyset(&segvaction.sa_mask);
97 segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
98 sigaction(SIGSEGV, &segvaction, NULL);
101 unsigned int getaddr(void)
103 return (unsigned int) mainresult;