Mail Archives: djgpp/1998/11/22/09:01:05
On 22 Nov 1998, david sharp wrote:
> Say I want to handle floating point exceptions in a program
> (compiled with DJGPP). If the program has a handler for SIGFPE's
> that directs the program to clear the directly affected
> variables, and then the program runs _control87() to clear
> FPU registers, and returns from the function where the
> offense occured, is that enough?
No. Handlers for real CPU exceptions, like SIGFPE and SIGSEGV, cannot
return; if they do, the program will be aborted anyway.
This is because the way exceptions work on x86, when the handler
returns, the EIP is set to the same instruction that triggered the
exception in the first place, so you get the same exception again and
again.
So if your handler doesn't exit, it must longjmp, to avoid crashing
your program.
A better way to write a program that handles FP problems gracefully
is to disable all FP exceptions at the beginning, and then use a
custom-written `matherr' function to recover from FP problems (and
link with -lm, since the normal math functions in libc.a don't
support `matherr').
- Raw text -