Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-09

unwinding stack from within ExceptProc?

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lukas Zeller

Hello,

I have the following situation: A FPC shared library called from a C main program should catch otherwise unhandled exceptions.

I set up a exception handling routine and assign it to ExceptProc. This works fine so far, the handler is called as expected.

Now the handler routine calls back into a C world routine which does a longjmp (out of my control) that unwinds the stack to before the call into the FPC sharedlib.

The longjmp itself works, but after this has happened once, further exceptions crash the program. I wonder if there is some (FPC) cleanup routine I could or should call before the longjmp that would make the scenario work, or if there is technical evidence that it can't work at all.

Lukas

()

Reply by email

Jonas Maebe
to Lukas Zeller
Lukas Zeller wrote 5 lines
The longjmp itself works, but after this has happened once, further exceptions crash the program. I wonder if there is some (FPC) cleanup routine I could or should call before the longjmp that would make the scenario work, or if there is technical evidence that it can't is no "technical evidence" that it can't work at all, but you

would have to call internal RTL routines which are not for public use, so
a) this is not documented or supported in any way (I can't tell you the names by heart either)
b) if you manage to figure it out, then your code can break with any future FPC version

Jonas

Reply by email

Lukas Zeller
to Jonas Maebe

Thanks, Jonas for the quick response (again)!

Jonas Maebe wrote 10 lines
On 25 Sep 2009, at 18:09, Lukas Zeller wrote: > The longjmp itself works, but after this has happened once, further > exceptions crash the program. I wonder if there is some (FPC) > cleanup routine I could or should call before the longjmp that > would make the scenario work, or if there is technical evidence > that it can't work at all. There is no "technical evidence" that it can't work at all, but you would have to call internal RTL routines [...]

I hope I read that correctly as: "just longjump can't work and leaves a mess behind that might explain crashes on subsequent exceptions"

Show quoted text 5 lines
[...] which are not for public use, so a) this is not documented or supported in any way (I can't tell you the names by heart either) b) if you manage to figure it out, then your code can break with any future FPC version

Yes - if it was "my code", I'd try to avoid the situation. It unfortunately isn't, the calling environment only provides that routine which longjmps to handle a exception situation. So making it work with the current FPC version and risking it'll break in a future version would be better than nothing.

Maybe there's a better solution, but what are the official options I have in ExceptProc other than halt? If I just return from it, how does the call flow continue? At that time the stack must be already unwound, but how far? While I understand ExceptProc is called when a exception falls through all the way down to a pascal main program, I can't really imagine at what point the same happens in a pascal shared lib.

Thanks for any explanations!

Lukas

Reply by email

Bogusław Brandys
to Lukas Zeller

Lukas Zeller pisze:

Show quoted text 45 lines
Thanks, Jonas for the quick response (again)! On Sep 26, 2009, at 15:31 , Jonas Maebe wrote: > On 25 Sep 2009, at 18:09, Lukas Zeller wrote: > >> The longjmp itself works, but after this has happened once, further >> exceptions crash the program. I wonder if there is some (FPC) cleanup >> routine I could or should call before the longjmp that would make the >> scenario work, or if there is technical evidence that it can't work >> at all. > > There is no "technical evidence" that it can't work at all, but you > would have to call internal RTL routines [...] I hope I read that correctly as: "just longjump can't work and leaves a mess behind that might explain crashes on subsequent exceptions" > [...] which are not for public use, so > a) this is not documented or supported in any way (I can't tell you > the names by heart either) > b) if you manage to figure it out, then your code can break with any > future FPC version Yes - if it was "my code", I'd try to avoid the situation. It unfortunately isn't, the calling environment only provides that routine which longjmps to handle a exception situation. So making it work with the current FPC version and risking it'll break in a future version would be better than nothing. Maybe there's a better solution, but what are the official options I have in ExceptProc other than halt? If I just return from it, how does the call flow continue? At that time the stack must be already unwound, but how far? While I understand ExceptProc is called when a exception falls through all the way down to a pascal main program, I can't really imagine at what point the same happens in a pascal shared lib. Thanks for any explanations! Lukas _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Don't know if that help you,but check it :
http://bugs.freepascal.org/view.php?id=13518

Boguslaw

Reply by email