7 #include <sys/ucontext.h>
9 static char* eip_at_sig
= NULL
;
11 static void int_handler(int signum
, siginfo_t
*si
, void *uc_arg
)
13 ucontext_t
*uc
= (ucontext_t
*)uc_arg
;
14 /* Note that uc->uc_mcontext is an embedded struct, not a pointer */
15 mcontext_t
*mc
= &(uc
->uc_mcontext
);
16 void *pc
= (void*)mc
->gregs
[REG_EIP
];
17 printf("in int_handler, EIP is ...\n");
21 static void register_handler(int sig
, void *handler
)
24 sa
.sa_flags
= SA_RESTART
| SA_SIGINFO
;
25 sigfillset(&sa
.sa_mask
);
26 sa
.sa_sigaction
= handler
;
27 sigaction(sig
, &sa
, NULL
);
33 register_handler(SIGTRAP
, int_handler
);
35 "movl $zz_int, %%edx\n"
40 : "m" (intaddr
) /* input: address of var to store target addr to */
41 : /* clobbers */ "edx"
43 /* intaddr is the address of the int 3 insn. eip_at_sig is the PC
44 after the exception, which should be the next insn along.
46 if (intaddr
!= NULL
&& eip_at_sig
!= NULL
47 && eip_at_sig
== intaddr
+1)