Method Header Attributes

Method Header Attributes

The RVA value of a Method record—if it is nonzero and if the method is not implemented as embedded native code—points to the method body. The method body consists of a method header, IL code, and an optional structured exception handling (SEH) table, as shown in Figure 9-3.

Figure 9-3 Managed method body structure.

Two types of method headers—fat and tiny—are defined in CorHdr.h. The first two bits of the header indicate its type: bits 10 stand for the tiny format, and bits 11 stand for the fat format. Why do we need two bits for a simple dichotomy? Because, speaking hypothetically, the day might come when more method header types are introduced.

A tiny method header is only 1 byte, with the first two (least significant) bits holding the type—10—and the 6 remaining bits holding the method IL code size in bytes. A method is given a tiny header if it has neither local variables nor structured exception handling, if it works fine with the default evaluation stack depth of 8 slots, and if its size is less than 64 bytes. A fat header is 12 bytes in size and has the structure described in Table 9-1. The fat headers must begin at 4-byte boundaries. The structures of both tiny and fat method headers are shown in Figure 9-4.

Table 9-1  The Fat Header Structure

Entry Size

Description

WORD

The lower 2 bits hold the fat header type code (0x3); the next 10 bits hold Flags. The upper 4 bits hold the size of the header in double words and must be set to 3. Currently used flags are 0x2, which indicates that more sections follow the IL code—that is, an SEH table is present—and 0x4, which indicates that local variables must be initialized.

WORD

MaxStack is the maximal evaluation stack depth in slots. Stack size in IL is measured not in bytes but in slots, with each slot able to accept one item regardless of the item’s size. The default value is 8 slots, and it can be set explicitly in ILAsm by the directive .maxstack <integer> used inside the method scope. Be careful about trying to economize the method size by specifying .maxstack lower than the default: if the specified stack depth differs from the default depth, the method automatically gets a fat header even if it has no local variables, no SEH table, and a code size less than 64 bytes.

DWORD

CodeSize is the size of the IL code in bytes.

DWORD

LocalVarSigTok is the token of the local variables signature (token type 0x11000000). The structure of the local variables signature is discussed in Chapter 7. If the method has no local variables, this entry is set to 0.



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