Skip to content

Latest commit

 

History

History
191 lines (96 loc) · 8.92 KB

ii.22.26-methoddef-0x06.md

File metadata and controls

191 lines (96 loc) · 8.92 KB

II.22.26 MethodDef: 0x06

The MethodDef table has the following columns:

  • RVA (a 4-byte constant)

  • ImplFlags (a 2-byte bitmask of type MethodImplAttributes, §II.23.1.11)

  • Flags (a 2-byte bitmask of type MethodAttributes, §II.23.1.10)

  • Name (an index into the String heap)

  • Signature (an index into the Blob heap)

  • ParamList (an index into the Param table). It marks the first of a contiguous run of Parameters owned by this method. The run continues to the smaller of:

    • the last row of the Param table

    • the next run of Parameters, found by inspecting the ParamList of the next row in the MethodDef table

Conceptually, every row in the MethodDef table is owned by one, and only one, row in the TypeDef table.

The rows in the MethodDef table result from .method directives (§II.15). The RVA column is computed when the image for the PE file is emitted and points to the COR_ILMETHOD structure for the body of the method (§II.25.4)

[Note: If Signature is GENERIC (0x10), the generic arguments are described in the GenericParam table (§II.22.20). end note]

This contains informative text only.

  1. The MethodDef table can contain zero or more rows

  2. Each row shall have one, and only one, owner row in the TypeDef table [ERROR]

  3. ImplFlags shall have only those values set that are specified [ERROR]

  4. Flags shall have only those values set that are specified [ERROR]

  5. If Name is .ctor and the method is marked SpecialName, there shall not be a row in the GenericParam table which has this MethodDef as its owner. [ERROR]

  6. The MemberAccessMaskII.23.1.10) subfield of Flags shall contain precisely one of CompilerControlled, Private, FamANDAssem, Assem, Family, FamORAssem, or Public [ERROR]

  7. The following combined bit settings in Flags are invalid [ERROR]

    1. Static | Final

    2. Static | Virtual

    3. Static | NewSlot

    4. Final | Abstract

    5. Abstract | PinvokeImpl

    6. CompilerControlled | SpecialName

    7. CompilerControlled | RTSpecialName

  8. An abstract method shall be virtual. So, if Flags.Abstract = 1 then Flags.Virtual shall also be 1 [ERROR]

  9. If Flags.RTSpecialName = 1 then Flags.SpecialName shall also be 1 [ERROR]

  10. If Flags.HasSecurity = 1, then at least one of the following conditions shall be true: [ERROR]

    • this Method owns at least row in the DeclSecurity table

    • this Method has a custom attribute called SuppressUnmanagedCodeSecurityAttribute

  11. If this Method owns one (or more) rows in the DeclSecurity table then Flags.HasSecurity shall be 1 [ERROR]

  12. If this Method has a custom attribute called SuppressUnmanagedCodeSecurityAttribute then Flags.HasSecurity shall be 1 [ERROR]

  13. A Method can have a custom attribute called DynamicSecurityMethodAttribute, but this has no effect whatsoever upon the value of its Flags.HasSecurity

  14. Name shall index a non-empty string in the String heap [ERROR]

  15. Interfaces cannot have instance constructors. So, if this Method is owned by an Interface, then its Name cannot be .ctor [ERROR]

  16. The Name string shall be a valid CLS identifier (unless Flags.RTSpecialName is set - for example, .cctor is valid) [CLS]

  17. Signature shall index a valid method signature in the Blob heap [ERROR]

  18. If Flags.CompilerControlled = 1, then this row is ignored completely in duplicate checking

  19. If the owner of this method is the internally-generated type called <Module>, it denotes that this method is defined at module scope. [Note: In C++, the method is called global and can be referenced only within its compilation unit, from its point of declaration forwards. end note] In this case:

    1. Flags.Static shall be 1 [ERROR]

    2. Flags.Abstract shall be 0 [ERROR]

    3. Flags.Virtual shall be 0 [ERROR]

    4. Flags.MemberAccessMask subfield shall be one of CompilerControlled, Public, or Private [ERROR]

    5. module-scope methods are not allowed [CLS]

  20. It makes no sense for ValueTypes, which have no identity, to have synchronized methods (unless they are boxed). So, if the owner of this method is a ValueType then the method cannot be synchronized. That is, ImplFlags.Synchronized shall be 0 [ERROR]

  21. There shall be no duplicate rows in the MethodDef table, based upon owner + Name + Signature (where owner is the owning row in the TypeDef table). (Note that the Signature encodes whether or not the method is generic, and for generic methods, it encodes the number of generic parameters.) (Note, however, that if Flags.CompilerControlled = 1, then this row is excluded from duplicate checking) [ERROR]

  22. There shall be no duplicate rows in the MethodDef table, based upon owner + Name + Signature, where Name fields are compared using CLS conflicting-identifierrules; also, the Type defined in the signatures shall be different. So, for example, int i and float i would be considered CLS duplicates; also, the return type of the method is ignored (Note, however, that if Flags.CompilerControlled = 1, this row is excluded from duplicate checking as explained above.) [CLS]

  23. If Final, NewSlot, or Strict are set in Flags, then Flags.Virtual shall also be set [ERROR]

  24. If Flags.PInvokeImpl is set, then Flags.Virtual shall be 0 [ERROR]

  25. If Flags.Abstract ≠ 1 then exactly one of the following shall also be true: [ERROR]

    • RVA ≠ 0

    • Flags.PInvokeImpl = 1

    • ImplFlags.Runtime = 1

  26. If the method is CompilerControlled, then the RVA shall be non-zero or marked with PinvokeImpl = 1 [ERROR]

  27. Signature shall have exactly one of the following managed calling conventions [ERROR]

    1. DEFAULT (0x0)

    2. VARARG (0x5)

    3. GENERIC (0x10)

  28. Signature shall have the calling convention DEFAULT (0x0) or GENERIC (0x10). [CLS]

  29. Signature: If and only if the method is not Static then the calling convention byte in Signature has its HASTHIS (0x20) bit set [ERROR]

  30. Signature: If the method is static, then the HASTHIS (0x20) bit in the calling convention shall be 0 [ERROR]

  31. If EXPLICITTHIS (0x40) in the signature is set, then HASTHIS (0x20) shall also be set (note that if EXPLICITTHIS is set, then the code is not verifiable) [ERROR]

  32. The EXPLICITTHIS (0x40) bit can be set only in signatures for function pointers: signatures whose MethodDefSig is preceded by FNPTR (0x1B) [ERROR]

  33. If RVA = 0, then either: [ERROR]

    • Flags.Abstract = 1, or

    • ImplFlags.Runtime = 1, or

    • Flags.PinvokeImpl = 1, or

  34. If RVA ≠ 0, then: [ERROR]

    1. Flags.Abstract shall be 0, and

    2. ImplFlags.CodeTypeMask shall have exactly one of the following values: Native, CIL, or Runtime, and

    3. RVA shall point into the CIL code stream in this file

  35. If Flags.PinvokeImpl = 1 then [ERROR]

    • RVA = 0 and the method owns a row in the ImplMap table
  36. If Flags.RTSpecialName = 1 then Name shall be one of: [ERROR]

    1. .ctor (an object constructor method)

    2. .cctor (a class constructor method)

  37. Conversely, if Name is any of the above special names then Flags.RTSpecialName shall be set [ERROR]

  38. If Name = .ctor (an object constructor method) then:

    1. return type in Signature shall be ELEMENT_TYPE_VOIDII.23.1.16) [ERROR]

    2. Flags.Static shall be 0 [ERROR]

    3. Flags.Abstract shall be 0 [ERROR]

    4. Flags.Virtual shall be [ERROR]

    5. 'Owner' type shall be a valid Class or ValueType (not <Module> and not an Interface) in the TypeDef table [ERROR]

    6. there can be zero or more .ctors for any given 'owner'

  39. If Name = .cctor (a class constructor method) then:

    1. the return type in Signature shall be ELEMENT_TYPE_VOIDII.23.1.16) [ERROR]

    2. Signature shall have DEFAULT (0x0) for its calling convention [ERROR]

    3. there shall be no parameters supplied in Signature [ERROR]

    4. Flags.Static shall be set [ERROR]

    5. Flags.Virtual shall be clear [ERROR]

    6. Flags.Abstract shall be clear [ERROR]

  40. Among the set of methods owned by any given row in the TypeDef table there can only be 0 or 1 methods named .cctor [ERROR]

End informative text.