SEH Clause Internal Representation

SEH Clause Internal Representation

Structured exception handling tables are located immediately after a method’s IL code, with the beginning of the table aligned on a double word boundary. It would be more accurate to say that “additional sections” are located after the method IL code, but the first release of the common language runtime allows only one kind of additional section—the exception handling section.

This additional section begins with the section header, which contains two entries, Kind and DataSize. In a small header, DataSize is represented by 1 byte, whereas in a fat header, DataSize is 3 bytes long. A Kind entry can contain the following binary flags:

  • Reserved (0x00)

  • EHTable (0x01)  The section contains an exception handling table. This bit must be set.

  • OptILTable (0x02)  Not used in the first release of the runtime. This bit must not be set.

  • FatFormat (0x40)  The section header has a fat format—that is, DataSize is represented by 3 bytes.

  • MoreSects (0x80)  More sections follow this one.

The section header—padded with 2 bytes if small—is followed by a sequence of exception handling (EH) clauses, which can also have small or fat format. Each EH clause describes a single triad made up of a guarded block, an exception identification, and an exception handler. The entries of small and fat EH clauses have the same names and meanings but different sizes, as shown in Table 11-1.

Table 11-1  EH Clause Entries

EH Clause Entry

Size in Small Clause (bytes)

Size in Fat Clause (bytes)

Description

Flags

2

4

Binary flags specifying the type of the EH clause, which is the type of the exception identification method.

TryOffset

2

4

Offset, in bytes, of the beginning of the guarded code block from the beginning of the method IL code. The guarded block can begin only at code points where the evaluation stack is empty.

TryLength

1

4

Length, in bytes, of the guarded block.

HandlerOffset

2

4

Offset of the exception handler block.

HandlerLength

1

4

Length of the exception handler block.

ClassToken/FilterOffset

4

4

Exception type token or offset of the exception filtering block, depending on the type of the EH clause.

Branching into or out of guarded blocks and handler blocks is illegal. A guarded block must be entered “through the top”—that is, through the instruction located at TryOffset—and handler blocks are entered only when they are engaged by the exception handling subsystem of the execution engine. To exit guarded and handler blocks, you must use the instruction leave (or leave.s). You might recall that in Chapter 2, “Enhancing the Code,” this principle was formulated as “leave only by leave.” Another way to leave any block is to throw an exception using the throw or rethrow instruction.



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net