NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: Borneq on December 11, 2012, 04:19:57 PM

Title: Exceptions
Post by: Borneq on December 11, 2012, 04:19:57 PM
I am interested both: handling exceptions in Windows using Structured Exceptions Handling and in Linux without system aid. On Windows I see example: http://ry.pl/~omega/asm/exc.zip
Title: Re: Exceptions
Post by: Frank Kotler on December 11, 2012, 05:47:05 PM
Well... you're probably familiar with the section in the Friendly Manual?
http://www.nasm.us/xdoc/2.10.06/html/nasmdoc7.html#section-7.5.2
That's about all I know about exception handling, safe or otherwise (including Linux). Randy Hyde's HLA uses it. There's some "boilerplate" that has to go in your Nasm code if you want to use the  HLA Standard Library from Nasm code. I never figured out what it did besides "keep the library happy". Could delve into that, if all else fails. :)

I've got some 64-bit code, "exception.asm" and "exceptions.inc" - I don't recall where I got 'em... probably right here. Check the "Example Code" section...

I note that your example is for "-f obj" format (and includes "omeg.inc" which doesn't seem to be in the .zip). Might be a good thing to "upgrade" it to "-f win32" format(?).

Best,
Frank

Title: Re: Exceptions
Post by: Borneq on December 11, 2012, 06:06:40 PM
Thank for info about HLA and Nasm documentation, examples I give is from http://ry.pl/~omega/?what=asm&lang=en, include is http://ry.pl/~omega/asm/inc.zip
Title: Re: Exceptions
Post by: Bryant Keller on December 11, 2012, 08:53:30 PM
Probably the best document about Win32 exception handling was written by Jeremy Gordon (developer of GoASM). It's a really good document and explains things in a clear and easy to follow structure.

Structured Exception Handling (http://godevtool.com/ExceptFrame.htm)
Title: Re: Exceptions
Post by: Borneq on December 12, 2012, 11:14:59 PM
Probably the best document about Win32 exception handling was written by Jeremy Gordon (developer of GoASM). It's a really good document and explains things in a clear and easy to follow structure.

Structured Exception Handling (http://godevtool.com/ExceptFrame.htm)
Yes, this document is OK.
Title: Re: Exceptions
Post by: Borneq on December 13, 2012, 10:00:13 PM
I try to write code with unwind. I wrote raise http://forum.nasm.us/index.php?topic=1545.0 (http://forum.nasm.us/index.php?topic=1545.0) example but are problems.
In http://godevtool.com/ExceptFrame.htm (http://godevtool.com/ExceptFrame.htm) is "Now we are ready to see how the handler can ensure that execution continues from a safe-place, instead of allowing the process to close, should an exception occur. "
- safe place is a finally place or other?
- RtlUnwind need params: pointer to ERR structure, pointer to exception record. How can give this parameters to RtlUnwind?
pointer to ERR structure I can - it is on stack, but pointer to exception record? I call RtlUnwind not from safe place but from handler, but still are problem - return from RaiseException.
Title: Re: Exceptions
Post by: Bryant Keller on December 14, 2012, 02:34:33 AM
- safe place is a finally place or other?

Safe place is the location that your exception handler will continue executing if it was able to recover from the exception.

- RtlUnwind need params: pointer to ERR structure, pointer to exception record. How can give this parameters to RtlUnwind?
pointer to ERR structure I can - it is on stack, but pointer to exception record? I call RtlUnwind not from safe place but from handler, but still are problem - return from RaiseException.

The pointer to the exception record is on the stack at [ebp+8].