Re: how to disable floating point exceptions?
Re: how to disable floating point exceptions?
- Subject: Re: how to disable floating point exceptions?
- From: Rua Haszard Morris <email@hidden>
- Date: Thu, 16 Aug 2007 11:52:34 +1200
Thanks for all your suggestions on and off list.
Short version: my only option is to prevent divide-by-zero (etc) in
the code, there is no way to inhibit fp exceptions or the mach signal
EXC_ARITHMETIC (please correct me if I am wrong about any of this).
Here's my summary:
1. This is a useful reference for the rumour that PPC doesn't crash
and will just return zero:
http://developer.apple.com/documentation/MacOSX/Conceptual/
universal_binary/universal_binary_diffs/chapter_3_section_9.html#//
apple_ref/doc/uid/TP40002217-CH240-281261
That specific document doesn't suggest any way of avoiding the crash
other than fixing the bug (implying there isn't a way to do so).
2. fesetenv() (fenv.h) may provide access to disable exceptions
This didn't seem to work, probably because the mach exception
(EXC_ARITHMETIC) was still occuring.
Most of the links provided pointed at information regarding
_enabling_ exception behaviour on PPC, whereas I am interested in the
opposite, _inhibiting_ exceptions on intel... however it has been
enlightening.
Thanks
Rua HM.
On 16/08/2007, at 10:27 AM, Kyle Sluder wrote:
EXC_ARITMETIC is a Mach exception, not a signal. Your process is
dying before the signal handler is called. The 387 is historically
more inflexible about floating-point exceptions than PowerPC anyway.
A quick Google search brought this up:
http://lists.apple.com/archives/Darwin-dev/2007/May/msg00044.html
...which referenced this:
http://developer.apple.com/documentation/Performance/Conceptual/
Mac_OSX_Numerics/Mac_OSX_Numerics.pdf
Don't forget, this is the Xcode mailing list. You might have better
luck if you posted this to the correct mailing list.
--Kyle Sluder
On 8/15/07, alex <email@hidden> wrote:
Wouldn't it be easier to just adjust your math or simply check for
zero before dividing rather than fiddling with the processor??
a
At 9:47 AM +1200 8/16/07, Rua Haszard Morris wrote:
Is it possible to prevent an application crashing on
EXC_ARITHMETIC (e.g. divide by zero) on i386?
I believe that on PPC there is no crash, and no crash when
running in rosetta (this is somewhat beside the point however).
I have tried installing a signal handler using sigaction, and
calling sigaction specifying SIG_IGN to hopefully ignore the
exception (see code snippet below).
The signal handler approach mostly worked, in that my signal
handler was called, but the crash behaviour remained, in that I
wasn't able to call an emergency exit function from within the
signal handler; the app didn't disappear, but wasn't responsive,
and either the call to emergency quit wasn't effective or didn't
happen. Also the "App has unexpectedly quit" crash handler kicked
in as per normal.
SIG_IGN didn't seem to have any effect different than normal
exception behaviour (it must mean that only the _app_ ignores the
signal).
Does anyone know how to intercept floating point exceptions when
running on i386 such that the program flow can be resumed enough
to inform the user and quit the app a little more gracefully?
Is my problem that I don't know how to (or can't) circumvent
crashreporter handling the exception?
any hints would be greatly appreciated
Rua HM.
// example code. acknowledgements to http://gcc.gnu.org/ml/gcc-
help/2002-04/msg00003.html
void fpeHandler (int, siginfo_t*, void*)
{
FAIL( "Floating-point exception" ); // essentially an assert
(false), string appears in console successfully
CleanUpAndExit(false); // quit-now-but-please-don't-crash
function, is called, but app doesn't quit nicely
}
void initFpe()
{
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = fpeHandler; // this results in my
callback (sig handler) being called, but crashreporter still
takes over
sigaction (SIGFPE, &sa, 0);
}
main()
{
....
initFpe();
// run app etc
// perform complex sequence of actions leading to divide-by-
zero ...
...
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden