Metadata Validity Rules

Metadata Validity Rules

Method-related metadata tables discussed in this chapter include the Method, Param, FieldMarshal, Constant, MemberRef, and MethodImpl tables. The records in these tables have the following entries:

  • The Method table: RVA, ImplFlags, Flags, Name, Signature, and ParamList.

  • The Param table: Flags, Sequence, and Names.

  • The FieldMarshal table: Parent and NativeType (native signature).

  • The Constant table: Type, Parent, and Value.

  • The MemberRef table: Class, Name, and Signature.

  • The MethodImpl table: Class, MethodBody, and MethodDecl.

Chapter 8 summarized the validity rules for the FieldMarshal, Constant, and MemberRef tables. The only point to mention here regarding the MemberRef table is that, unlike field-referencing MemberRef records, method-referencing records can have the TypeSpec or Method table referenced in the Parent entry. The Method table can be referenced exclusively by the MemberRef records representing vararg call sites.

Method Table Validity Rules

  • The Flags entry can have only those bits set that are defined in the enumeration CorMethodAttr in CorHdr.h (validity mask 0xFDF7).

  • [run time] The accessibility flag (mask 0x0007) must be one of the following: privatescope, private, famandassem, assembly, family, famorassem, or public.

  • The static flag must not be combined with any of the following flags: final, virtual, newslot, or abstract.

  • The pinvokeimpl flag must be paired with the static flag (but not vice versa).

  • Methods having privatescope accessibility must not have the virtual, final, newslot, specialname, or rtspecialname flag set.

  • The abstract, newslot, and final flags must be paired with the virtual flag.

  • The abstract flag and the implementation flag forwardref are mutually exclusive.

  • [run time] If the flag 0x4000 is set, the method must either have an associated DeclSecurity metadata record that holds security information concerning access to the method or have the associated custom attribute System.Security.SuppressUnmanagedCodeSecurityAttribute. The inverse is true as well.

  • [run time] Methods belonging to interfaces must have either the static flag or the virtual flag set.

  • [run time] Global methods must have the static flag set.

  • If the rtspecialname flag is set, the specialname flag must also be set.

  • The ImplFlags entry must have only those bits set that are defined in the enumeration CorMethodImplAttr in CorHdr.h (validity mask 0x10BF).

  • The implementation flag forwardref is used only during in-memory edit-and-continue scenarios and in object files (generated by the MC++ compiler) and must not be set for any method in a managed PE file.

  • [run time] The implementation flags cil and unmanaged are mutually exclusive.

  • [run time] The implementation flags native and managed are mutually exclusive.

  • The implementation flag native must be paired with the unmanaged flag.

  • [run time] The implementation flag synchronized must not be set for methods belonging to value types.

  • [run time] The implementation flags runtime and internalcall are for internal use only and must not be set for methods defined outside .NET Framework system assemblies.

  • [run time] The Name entry must hold a valid reference to the #Strings stream, indexing a nonempty string no more than 1023 bytes long in UTF-8 encoding.

  • [run time] If the method name is .ctor, .cctor, _VtblGap*, or _Deleted*, the rtspecialname flag must be set, and vice versa.

  • [run time] A method named .ctor—an instance constructor—must not have the static flag or the virtual flag set.

  • [run time] A method named .cctor—a class constructor—must have the static flag set.

  • [run time] The Signature entry must hold a valid reference to the #Blob stream, indexing a valid method signature. Validity rules for method signatures are discussed in Chapter 7.

  • [run time] A method named .ctor—an instance constructor—must return void and must have the default calling convention.

  • [run time] A method named .cctor—a class constructor—must return void, can take no parameters, and must have the default calling convention.

  • No duplicate records—attributed to the same TypeDef and having the same name and signature—should exist unless the accessibility flag is privatescope.

  • [run time] The RVA entry must hold 0 or a valid relative virtual address pointing to a read-only section of the PE file.

  • [run time] The RVA entry holds 0 if and only if

    • The abstract flag is set, or

    • The implementation flag runtime is set, or

    • The implementation flag internalcall is set, or

    • The class owning the method has the import flag set, or

    • The pinvokeimpl flag is set, the implementation flags native and unmanaged are not set, and the ImplMap table contains a record referencing the current Method record.

Param Table Validity Rules

  • The Flags entry can have only those bits set that are defined in the enumeration CorParamAttr in CorHdr.h (validity mask 0x3013).

  • [run time] If the flag 0x2000 (pdHasFieldMarshal) is set, the FieldMarshal table must contain a record referencing this Param record, and vice versa.

  • [run time] If the flag 0x1000 (pdHasDefault) is set, the Constant table must contain a record referencing this Param record, and vice versa.

  • [run time] The Sequence entry must hold a value no larger than the number of mandatory parameters of the method owning the Param record.

  • If the method owning the Param record returns void, the Sequence entry must not hold 0.

  • The Name entry must hold 0 or a valid reference to the #Strings stream, indexing a nonempty string no more than 1023 bytes long in UTF-8 encoding.

MethodImpl Table Validity Rules

  • [run time] The Class entry must hold a valid index to the TypeDef table.

  • [run time] The MethodDecl entry must index a record in the Method or MemberRef table.

  • [run time] The method indexed by MethodDecl must be virtual.

  • [run time] The method indexed by MethodDecl must not be final.

  • [run time] If the parent of the method indexed by MethodDecl is not the TypeDef indexed by Class, the method indexed by MethodDecl must not be private.

  • [run time] The parent of the method indexed by MethodDecl must not be sealed.

  • [run time] The signatures of the methods indexed by MethodDecl and MethodBody must match.

  • [run time] The MethodBody entry must index a record in the Method table.

  • [run time] The method indexed by MethodBody must be virtual.

  • [run time] The parent of the method indexed by MethodBody must be the TypeDef indexed by Class.



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