www.digitalmars.com         C & C++   DMDScript  

c++.dos.32-bits - Fault handler

reply "Gisle Vanem" <gvanem eunet.no> writes:
Programming with X32VM and DMC 8.33 I install an exception
handler using  _x32_fault_intercept().

Then in my handler I longjmp() out to a main exception handler
(in case the stack was screwed up before my handler got called).
Before I call _exit(), I print the registers and call only critical exit
handlers.

Q: Is it safe to use longjmp()?

--gv
Apr 23 2003
parent reply Larry Brasfield <larry_brasfield snotmail.com> writes:
In article <b87cpd$r9l$1 digitaldaemon.com>, 
Gisle Vanem (gvanem eunet.no) says...
 Programming with X32VM and DMC 8.33 I install an exception
 handler using  _x32_fault_intercept().
 
 Then in my handler I longjmp() out to a main exception handler
 (in case the stack was screwed up before my handler got called).
 Before I call _exit(), I print the registers and call only critical exit
 handlers.
 
 Q: Is it safe to use longjmp()?
Once memory has been corrupted by stray writes thru bad pointers, (such as would "screw up" the stack), then longjump's data structure may also have been hit and the longjump() may fail. However, understanding that any stack unwinding (dtor calls) will be bypassed by a longjump(), it is among the safer things you can do other than just terminating the process. If it was crucial, you could add some redundancy to the longjump struct and validate it before the longjump(). -- -Larry Brasfield (address munged, s/sn/h/ to reply)
Apr 23 2003
parent "Gisle Vanem" <gvanem eunet.no> writes:
"Larry Brasfield" <larry_brasfield snotmail.com> wrote:

 Once memory has been corrupted by
 stray writes thru bad pointers, (such
 as would "screw up" the stack), then
 longjump's data structure may also
 have been hit and the longjump() may
 fail.  However, understanding that any
 stack unwinding (dtor calls) will be
 bypassed by a longjump(), it is among
 the safer things you can do other than
 just terminating the process.
Thanks for the info. I was a bit uncertain if _x32_fault_intercept() required the handler to return to do some internal house-keeping. But some test convinced m it's not needed. --gv
Apr 24 2003