>I am have trouble handling integer divide by zero exceptions.
>When I execute the following program, it does not terminate.
>Could someone tell me what I'm doing wrong?
What you do is restarting the divide by zero instruction and you
get a new exception.
You need to change the PC and nPC fields in the context.
PC=nPC and nPC = nPC + 4;
handler (int sig, siginfo_t *info, void *ctxt)
struct ucontext *context = ctxt;
fprintf(stderr,"SIGBUS at %x, pc = %x\n", info->si_addr,
/* skip offending instruction */
context->uc_mcontext.gregs[REG_PC] = context->uc_mcontext.gregs[REG_nPC];
struct sigaction sa;
volatile int *foo = (int*) 1;
sa.sa_flags = SA_SIGINFO | SA_NODEFER;
sa.sa_sigaction = handler;
sigaction(SIGBUS, &sa, 0);
*foo = 0;
Casper Dik - Sun Microsystems - via my guest account at the University
Statements on Sun products included here are not gospel and may
be fiction rather than truth.