[Mono-list] help needed
Soeren Sandmann
sandmann@daimi.au.dk
23 Nov 2001 18:19:09 +0100
Dietmar Maurer <dietmar@ximian.com> writes:
> One theory is that the handler returns to the same instruction how
> caused the signal, so the same instruction raises the same signal again
> and again?
>
> If so, how can I modify the IP to point to a new location?
I don't think you can do that.
You'll need to make sure that the signal won't be raised again, for
example by changing the value of b so that it won't divide by zero
again.
If the code at IP is writable, you could also modify the
instruction to be something harmless, a jump for instance.
Here is an example that will raise the signal once and modify the
value of b.
#include <stdio.h>
#include <signal.h>
static int *b_addr;
static void
fp_signal_handler (int sig, siginfo_t *si, struct sigcontext *ctx)
{
printf ("TEST %d %p %p\n", si->si_code, si->si_addr, ctx->eip);
*b_addr = 2;
return;
}
int
main ()
{
int a = 5, b = 0, c;
struct sigaction sa, sao;
b_addr = &b;
sa.sa_sigaction = fp_signal_handler;
sigemptyset (&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction (SIGFPE, &sa, NULL);
c = a/b;
printf ("c is %d\n", c);
return 0;
}