6.2.1 Win64 Structured Exception Handling (SEH)

Asmc Macro Assembler

6.2.1 Win64 Structured Exception Handling (SEH)

SEH in Win64 differs significantly from the implementation in Win32. It's very well possible to ignore Win64 SEH for assembly. However, if an assembly routine wants to comply to these rules, a thorough understanding of the Win64 ABI is necessary. Masm ( the 64-bit version ) supplies some "primitives" for SEH support (.ALLOCSTACK, .PUSHREG, .SAVEREG, ...), along with a new FRAME attribute for the PROC directive. These features are also supported by JWasm. See sample Win64_3 how the "primitives" are to be used for SEH support.

The big disadvantage is that using the FRAME keyword in Masm "disables" most of the other high level features combined with PROC (function parameters, locals and registers saved with USES) because no function prologues and epilogues are generated anymore. Additionally, the implementation in some Masm versions seems to be a bit buggy. Because of this and to ease the usage of SEH in Win64 there is a new directive implemented in JWasm:

 
        OPTION FRAME:AUTO

If this option is set, JWasm will create Win64 SEH-compatible prologues and epilogues. If the option is off, JWasm will behave Masm-compatible, that is, FRAME found in a PROC directive will disable automatic prologue/epilogue generation. See sample Win64_3e how this option is supposed to be used.

As for the PROC syntax: The Masm documentation states that FRAME can be used in combination with USES and procedure parameters and must be located behind all parameters. However, this syntax isn't accepted by any Masm version. The only syntax which Masm will accept without being confused is FRAME as the one and only parameter for PROC. Therefore JWasm doesn't follow the Masm documentation in this point: the optional FRAME keyword is expected *before* the procedure parameters. The syntax in JWasm is:

 
    procname PROC [public] FRAME[:exc_handler] [USES <reglist>] [parameters]

The SEH "primitives" will generate some additional data in segments .pdata and .xdata. This data is somewhat hidden, but JWasm will display the corresponding data definitions in the listing if option -Sg is set.