X86 fpu registers in a signal handler's ucontext

From: Warlich, Christof
Date: Mon Apr 29 2013 - 10:51:34 EST


Hi,

I want my signal handler to return from a SIGFPE and continue normal
execution right _after_ the instruction that caused the signal.

My first attempt workes quite well: I just modify the EIP register
though the ucontext pointer being passed to the signal handler:

void fpeHandler(int, siginfo_t *info, void *context) {
// The following function calculates the size of the instruction being pointed to.
int size = instructionSize((unsigned char *) info->si_addr);
((ucontext_t *) context)->uc_mcontext.gregs[REG_EIP] += size;
}

Doing this, my main program continues as expected as long as no other
floating point instructions are involved, but as the exception
condition is still active in the FP status register, any subsequent
and _valid_ floating point calculation cause another exception.

Thus, I tried to clear the exceptions in a similar way:

void fpeHandler(int, siginfo_t *info, void *context) {
// This function calculates the size of the instruction being poined to.
int size = instructionSize((unsigned char *) info->si_addr);
((ucontext_t *) context)->uc_mcontext.gregs[REG_EIP] += size;
((ucontext_t *) context)->uc_mcontext.fpregs->status &= ~FE_ALL_EXCEPT
}

But unfortunately, this doesn't work:

First, this link:
http://valgrind.10908.n7.nabble.com/need-FPU-and-SSE-state-in-sigcontext-ucontext-td19844.html
suggests that unlike the GPRs, the FP registers are _not_ restored after
returnung from the signal handler.

Second, only FP state seems to be available through ucontext_t, and I would
need to clear exceptions for SSE as well.

Can anyone give me some advice on how to I could proceed?

Thanks a lot,

Chris--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/