public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* X86 fpu registers in a signal handler's ucontext
@ 2013-04-29 14:34 Warlich, Christof
  2013-04-29 17:57 ` Andi Kleen
  2013-05-03  3:18 ` H. Peter Anvin
  0 siblings, 2 replies; 12+ messages in thread
From: Warlich, Christof @ 2013-04-29 14:34 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-05-03  3:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-29 14:34 X86 fpu registers in a signal handler's ucontext Warlich, Christof
2013-04-29 17:57 ` Andi Kleen
2013-04-30  6:35   ` Warlich, Christof
2013-04-30 11:28     ` Mikael Pettersson
2013-04-30 13:45       ` Warlich, Christof
2013-04-30 14:42         ` Mikael Pettersson
2013-05-02  5:42           ` Warlich, Christof
2013-05-02  7:06             ` richard -rw- weinberger
2013-05-02  7:43               ` Warlich, Christof
2013-05-02  9:04               ` Warlich, Christof
2013-05-02 11:12                 ` Mikael Pettersson
2013-05-03  3:18 ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox