Sign in Join

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

Mailing lists / fpc-pascal / 2010-09

SEH

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Bernd Kreuss

Hi,

I was bored and I played around with SEH exceptions. It might be useful in some cases when you can't catch an exception in a dll but there might also be easier methods in some cases. I though before the code will be forgotten and deleted again I post it here:

the unit seh.pas contains the handler. This handler is very simple, it will handle all exceptions and always restore the stack to the state it was when the handler was installed and use the address that was pushed to the stack to continue execution.

the file sehtest.pas uses this unit and sets up a try/except construct with two asm blocks and some labels and then triggers an exception somewhere deeper in the callstack (to test the proper restoring of the stack). If FPC had more flexible macros then it could be made a bit nicer but it fulfills its purpose.

Bernd

Bernd Kreuss
to Bernd Kreuss
Bernd Kreuss wrote
the unit seh.pas contains the handler. This handler is very simple, it will handle all exceptions and always restore the stack to the state it was when the handler was installed and use the address that was pushed to the stack to continue execution.

There might be still something missing: Maybe the Handler should also pull the pushed ebp out of the stack (the same way it pulls the except address for the instruction pointer eip) and restore it or local variables might not work anymore after __expept.