views:

29

answers:

0

I wrote a signal handler to catch FPE errors. I need to continue execution even if this happens. I receive a ucontext_t as parameter, I can change the bad operand from 0 to another value but the FPU context is still bad and I run into an infinite loop ?

Does someone already manupulate the ucontext_t structure on Linux ?

I finally found a way to handle these situations by clearing the status flag of ucontext_t like this:

...
const long int cFPUStatusFlag = 0x3F;
aContext->uc_mcontext.fpregs->sw &= ~cFPUStatusFlag;
...

0x3F is negated to put 0 in the 6 bits of the status register of the FPU (x87). Doing this implies to check for FPE exceptions after calculation.