I wrote a signal handler to catch FPE errors. I need to continue execution, even if this happens. I get the ucontext_t parameter like, can I change the bad operand from 0 to another value, but the FPU context is still bad, and am I starting an infinite loop?
Does anyone already handle the ucontext_t structure on Linux?
I finally found a way to handle these situations by clearing the ucontext_t status flag as follows:
...
const long int cFPUStatusFlag = 0x3F;
aContext->uc_mcontext.fpregs->sw &= ~cFPUStatusFlag;
...
0x3F is negated to put 0 in 6 bits of the FPU status register (x87). To do this, check the FPE exceptions after calculation.
source
share