Delete FriendAccessAllowedAttribute and associated dead code (#15101)
[platform/upstream/coreclr.git] / src / inc / corhdr.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 /*****************************************************************************
6  **                                                                         **
7  ** CorHdr.h - contains definitions for the Runtime structures,             **
8 ** 
9
10  **            needed to work with metadata.                                **
11  **                                                                         **
12  *****************************************************************************/
13 //
14 // The top most managed code structure in a EXE or DLL is the IMAGE_COR20_HEADER 
15 // see code:#ManagedHeader for more 
16
17 #ifndef __CORHDR_H__
18 #define __CORHDR_H__
19
20 #define FRAMEWORK_REGISTRY_KEY          "Software\\Microsoft\\.NETFramework"
21 #define FRAMEWORK_REGISTRY_KEY_W        L"Software\\Microsoft\\.NETFramework"
22
23 // keys for HKCU
24 #ifdef _WIN64    
25 #define USER_FRAMEWORK_REGISTRY_KEY             "Software\\Microsoft\\.NETFramework64"
26 #define USER_FRAMEWORK_REGISTRY_KEY_W        L"Software\\Microsoft\\.NETFramework64"
27 #else
28 #define USER_FRAMEWORK_REGISTRY_KEY             "Software\\Microsoft\\.NETFramework"
29 #define USER_FRAMEWORK_REGISTRY_KEY_W        L"Software\\Microsoft\\.NETFramework"
30 #endif
31
32
33 #ifdef _MSC_VER
34 #pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union.
35 #endif
36 typedef LPVOID  mdScope;                // Obsolete; not used in the runtime.
37 typedef ULONG32 mdToken;                // Generic token
38
39
40 // Token  definitions
41
42
43 typedef mdToken mdModule;               // Module token (roughly, a scope)
44 typedef mdToken mdTypeRef;              // TypeRef reference (this or other scope)
45 typedef mdToken mdTypeDef;              // TypeDef in this scope
46 typedef mdToken mdFieldDef;             // Field in this scope
47 typedef mdToken mdMethodDef;            // Method in this scope
48 typedef mdToken mdParamDef;             // param token
49 typedef mdToken mdInterfaceImpl;        // interface implementation token
50
51 typedef mdToken mdMemberRef;            // MemberRef (this or other scope)
52 typedef mdToken mdCustomAttribute;      // attribute token
53 typedef mdToken mdPermission;           // DeclSecurity
54
55 typedef mdToken mdSignature;            // Signature object
56 typedef mdToken mdEvent;                // event token
57 typedef mdToken mdProperty;             // property token
58
59 typedef mdToken mdModuleRef;            // Module reference (for the imported modules)
60
61 // Assembly tokens.
62 typedef mdToken mdAssembly;             // Assembly token.
63 typedef mdToken mdAssemblyRef;          // AssemblyRef token.
64 typedef mdToken mdFile;                 // File token.
65 typedef mdToken mdExportedType;         // ExportedType token.
66 typedef mdToken mdManifestResource;     // ManifestResource token.
67
68 typedef mdToken mdTypeSpec;             // TypeSpec object
69
70 typedef mdToken mdGenericParam;         // formal parameter to generic type or method
71 typedef mdToken mdMethodSpec;           // instantiation of a generic method
72 typedef mdToken mdGenericParamConstraint; // constraint on a formal generic parameter
73
74 // Application string.
75 typedef mdToken mdString;               // User literal string token.
76
77 typedef mdToken mdCPToken;              // constantpool token
78
79 #ifndef MACROS_NOT_SUPPORTED
80 typedef ULONG RID;
81 #else
82 typedef unsigned RID;
83 #endif // MACROS_NOT_SUPPORTED
84
85 typedef enum ReplacesGeneralNumericDefines
86 {
87 // Directory entry macro for CLR data.
88 #ifndef IMAGE_DIRECTORY_ENTRY_COMHEADER
89     IMAGE_DIRECTORY_ENTRY_COMHEADER     =14,
90 #endif // IMAGE_DIRECTORY_ENTRY_COMHEADER
91 } ReplacesGeneralNumericDefines;
92
93
94 // The COMIMAGE_FLAGS_32BITREQUIRED and COMIMAGE_FLAGS_32BITPREFERRED flags defined below interact as a pair
95 // in order to get the performance profile we desire for platform neutral assemblies while retaining backwards
96 // compatibility with pre-4.5 runtimes/OSs, which don't know about COMIMAGE_FLAGS_32BITPREFERRED.
97 //
98 // COMIMAGE_FLAGS_32BITREQUIRED originally meant "this assembly is x86-only" (required to distinguish platform
99 // neutral assemblies which also mark their PE MachineType as IMAGE_FILE_MACHINE_I386).
100 //
101 // COMIMAGE_FLAGS_32BITPREFERRED has been added so we can create a sub-class of platform neutral assembly that
102 // prefers to be loaded into 32-bit environment for perf reasons, but is still compatible with 64-bit
103 // environments.
104 //
105 // In order to retain maximum backwards compatibility you cannot simply read or write one of these flags
106 // however. You must treat them as a pair, a two-bit field with the following meanings:
107 //
108 //  32BITREQUIRED  32BITPREFERRED
109 //        0               0         :   no special meaning, MachineType and ILONLY flag determine image requirements
110 //        0               1         :   illegal, reserved for future use
111 //        1               0         :   image is x86-specific
112 //        1               1         :   image is platform neutral and prefers to be loaded 32-bit when possible
113 //
114 // To simplify manipulation of these flags the following macros are provided below.
115
116 #define COR_IS_32BIT_REQUIRED(_flags) \
117     (((_flags) & (COMIMAGE_FLAGS_32BITREQUIRED|COMIMAGE_FLAGS_32BITPREFERRED)) == (COMIMAGE_FLAGS_32BITREQUIRED))
118
119 #define COR_IS_32BIT_PREFERRED(_flags) \
120     (((_flags) & (COMIMAGE_FLAGS_32BITREQUIRED|COMIMAGE_FLAGS_32BITPREFERRED)) == (COMIMAGE_FLAGS_32BITREQUIRED|COMIMAGE_FLAGS_32BITPREFERRED))
121
122 #define COR_SET_32BIT_REQUIRED(_flagsfield) \
123     do { _flagsfield = (_flagsfield & ~COMIMAGE_FLAGS_32BITPREFERRED) | COMIMAGE_FLAGS_32BITREQUIRED; } while (false)
124
125 #define COR_SET_32BIT_PREFERRED(_flagsfield) \
126     do { _flagsfield |= COMIMAGE_FLAGS_32BITPREFERRED|COMIMAGE_FLAGS_32BITREQUIRED; } while (false)
127
128 #define COR_CLEAR_32BIT_REQUIRED(_flagsfield) \
129     do { _flagsfield &= ~(COMIMAGE_FLAGS_32BITREQUIRED|COMIMAGE_FLAGS_32BITPREFERRED); } while (false)
130
131 #define COR_CLEAR_32BIT_PREFERRED(_flagsfield) \
132     do { _flagsfield &= ~(COMIMAGE_FLAGS_32BITREQUIRED|COMIMAGE_FLAGS_32BITPREFERRED); } while (false)
133
134
135 #ifndef __IMAGE_COR20_HEADER_DEFINED__
136 #define __IMAGE_COR20_HEADER_DEFINED__
137
138 typedef enum ReplacesCorHdrNumericDefines
139 {
140 // COM+ Header entry point flags.
141     COMIMAGE_FLAGS_ILONLY               =0x00000001,
142     COMIMAGE_FLAGS_32BITREQUIRED        =0x00000002,    // *** Do not manipulate this bit directly (see notes above)
143     COMIMAGE_FLAGS_IL_LIBRARY           =0x00000004,
144     COMIMAGE_FLAGS_STRONGNAMESIGNED     =0x00000008,
145     COMIMAGE_FLAGS_NATIVE_ENTRYPOINT    =0x00000010,
146     COMIMAGE_FLAGS_TRACKDEBUGDATA       =0x00010000,
147     COMIMAGE_FLAGS_32BITPREFERRED       =0x00020000,    // *** Do not manipulate this bit directly (see notes above)
148     
149
150 // Version flags for image.
151     COR_VERSION_MAJOR_V2                =2,
152     COR_VERSION_MAJOR                   =COR_VERSION_MAJOR_V2,
153     COR_VERSION_MINOR                   =5,
154     COR_DELETED_NAME_LENGTH             =8,
155     COR_VTABLEGAP_NAME_LENGTH           =8,
156
157 // Maximum size of a NativeType descriptor.
158     NATIVE_TYPE_MAX_CB                  =1,   
159     COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE=0xFF,
160
161 // V-table constants
162     COR_VTABLE_32BIT                    =0x01,          // V-table slots are 32-bits in size.   
163     COR_VTABLE_64BIT                    =0x02,          // V-table slots are 64-bits in size.   
164     COR_VTABLE_FROM_UNMANAGED           =0x04,          // If set, transition from unmanaged.
165     COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN=0x08,    // NEW
166     COR_VTABLE_CALL_MOST_DERIVED        =0x10,          // Call most derived method described by
167
168 // Max name lengths    
169     //@todo: Change to unlimited name lengths.
170     MAX_CLASS_NAME                      =1024,
171     MAX_PACKAGE_NAME                    =1024,
172 } ReplacesCorHdrNumericDefines;
173
174 // #ManagedHeader
175 // 
176 // A managed code EXE or DLL uses the same basic format that unmanaged executables use call the Portable
177 // Executable (PE) format. See http://en.wikipedia.org/wiki/Portable_Executable or
178 // http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx for more on this format and RVAs.
179 // 
180 // PE files define fixed table of well known entry pointers call Directory entries. Each entry holds the
181 // relative virtual address (RVA) and length of a blob of data within the PE file. You can see these using
182 // the command
183 // 
184 // link /dump /headers <EXENAME>
185 //  
186 //  
187 // Managed code has defined one of these entries (the 14th see code:IMAGE_DIRECTORY_ENTRY_COMHEADER) and the RVA points
188 // that the IMAGE_COR20_HEADER.  This header shows up in the previous dump as the following line
189 // 
190 // // Managed code is identified by is following line
191 // 
192 //             2008 [      48] RVA [size] of COM Descriptor Directory
193 //
194 // The IMAGE_COR20_HEADER is mostly just RVA:Length pairs (pointers) to other interesting data structures. 
195 // The most important of these is the MetaData tables.   The easiest way of looking at meta-data is using
196 // the IlDasm.exe tool.   
197 // 
198 // MetaData holds most of the information in the IL image.  THe exceptions are resource blobs and the IL
199 // instructions streams for individual methods.  Intstead the Meta-data for a method holds an RVA to a 
200 // code:IMAGE_COR_ILMETHOD which holds all the IL stream (and exception handling information).  
201 // 
202 // Precompiled (NGEN) images use the same IMAGE_COR20_HEADER but also use the ManagedNativeHeader field to
203 // point at structures that only exist in precompiled images. 
204 //  
205 typedef struct IMAGE_COR20_HEADER
206 {
207     // Header versioning
208     DWORD                   cb;              
209     WORD                    MajorRuntimeVersion;
210     WORD                    MinorRuntimeVersion;
211     
212     // Symbol table and startup information
213     IMAGE_DATA_DIRECTORY    MetaData;        
214     DWORD                   Flags;           
215   
216         // The main program if it is an EXE (not used if a DLL?)
217     // If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is not set, EntryPointToken represents a managed entrypoint.
218         // If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is set, EntryPointRVA represents an RVA to a native entrypoint
219         // (depricated for DLLs, use modules constructors intead). 
220     union {
221         DWORD               EntryPointToken;
222         DWORD               EntryPointRVA;
223     };
224     
225     // This is the blob of managed resources. Fetched using code:AssemblyNative.GetResource and
226     // code:PEFile.GetResource and accessible from managed code from
227         // System.Assembly.GetManifestResourceStream.  The meta data has a table that maps names to offsets into
228         // this blob, so logically the blob is a set of resources. 
229     IMAGE_DATA_DIRECTORY    Resources;
230         // IL assemblies can be signed with a public-private key to validate who created it.  The signature goes
231         // here if this feature is used. 
232     IMAGE_DATA_DIRECTORY    StrongNameSignature;
233
234     IMAGE_DATA_DIRECTORY    CodeManagerTable;                   // Depricated, not used 
235         // Used for manged codee that has unmaanaged code inside it (or exports methods as unmanaged entry points)
236     IMAGE_DATA_DIRECTORY    VTableFixups;
237     IMAGE_DATA_DIRECTORY    ExportAddressTableJumps;
238
239         // null for ordinary IL images.  NGEN images it points at a code:CORCOMPILE_HEADER structure
240     IMAGE_DATA_DIRECTORY    ManagedNativeHeader;
241     
242 } IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
243
244 #else // !__IMAGE_COR20_HEADER_DEFINED__
245
246 // <TODO>@TODO: This is required because we pull in the COM+ 2.0 PE header
247 // definition from WinNT.h, and these constants have not yet propogated to there.</TODO>
248 // 
249 #define COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN 0x08
250 #define COMIMAGE_FLAGS_32BITPREFERRED              0x00020000
251
252 #endif // __IMAGE_COR20_HEADER_DEFINED__
253
254
255 // The most recent version.
256
257 #define COR_CTOR_METHOD_NAME        ".ctor"
258 #define COR_CTOR_METHOD_NAME_W      L".ctor"
259 #define COR_CCTOR_METHOD_NAME       ".cctor"
260 #define COR_CCTOR_METHOD_NAME_W     L".cctor"
261
262 #define COR_ENUM_FIELD_NAME         "value__"
263 #define COR_ENUM_FIELD_NAME_W       L"value__"
264
265 // The predefined name for deleting a typeDef,MethodDef, FieldDef, Property and Event
266 #define COR_DELETED_NAME_A          "_Deleted"
267 #define COR_DELETED_NAME_W          L"_Deleted"
268 #define COR_VTABLEGAP_NAME_A        "_VtblGap"
269 #define COR_VTABLEGAP_NAME_W        L"_VtblGap"
270
271 // We intentionally use strncmp so that we will ignore any suffix
272 #define IsDeletedName(strName)      (strncmp(strName, COR_DELETED_NAME_A, COR_DELETED_NAME_LENGTH) == 0)
273 #define IsVtblGapName(strName)      (strncmp(strName, COR_VTABLEGAP_NAME_A, COR_VTABLEGAP_NAME_LENGTH) == 0)
274
275 // TypeDef/ExportedType attr bits, used by DefineTypeDef.
276 typedef enum CorTypeAttr
277 {
278     // Use this mask to retrieve the type visibility information.
279     tdVisibilityMask        =   0x00000007,
280     tdNotPublic             =   0x00000000,     // Class is not public scope.
281     tdPublic                =   0x00000001,     // Class is public scope.
282     tdNestedPublic          =   0x00000002,     // Class is nested with public visibility.
283     tdNestedPrivate         =   0x00000003,     // Class is nested with private visibility.
284     tdNestedFamily          =   0x00000004,     // Class is nested with family visibility.
285     tdNestedAssembly        =   0x00000005,     // Class is nested with assembly visibility.
286     tdNestedFamANDAssem     =   0x00000006,     // Class is nested with family and assembly visibility.
287     tdNestedFamORAssem      =   0x00000007,     // Class is nested with family or assembly visibility.
288
289     // Use this mask to retrieve class layout information
290     tdLayoutMask            =   0x00000018,
291     tdAutoLayout            =   0x00000000,     // Class fields are auto-laid out
292     tdSequentialLayout      =   0x00000008,     // Class fields are laid out sequentially
293     tdExplicitLayout        =   0x00000010,     // Layout is supplied explicitly
294     // end layout mask
295
296     // Use this mask to retrieve class semantics information.
297     tdClassSemanticsMask    =   0x00000020,
298     tdClass                 =   0x00000000,     // Type is a class.
299     tdInterface             =   0x00000020,     // Type is an interface.
300     // end semantics mask
301
302     // Special semantics in addition to class semantics.
303     tdAbstract              =   0x00000080,     // Class is abstract
304     tdSealed                =   0x00000100,     // Class is concrete and may not be extended
305     tdSpecialName           =   0x00000400,     // Class name is special.  Name describes how.
306
307     // Implementation attributes.
308     tdImport                =   0x00001000,     // Class / interface is imported
309     tdSerializable          =   0x00002000,     // The class is Serializable.
310     tdWindowsRuntime        =   0x00004000,     // The type is a Windows Runtime type
311
312     // Use tdStringFormatMask to retrieve string information for native interop
313     tdStringFormatMask      =   0x00030000,
314     tdAnsiClass             =   0x00000000,     // LPTSTR is interpreted as ANSI in this class
315     tdUnicodeClass          =   0x00010000,     // LPTSTR is interpreted as UNICODE
316     tdAutoClass             =   0x00020000,     // LPTSTR is interpreted automatically
317     tdCustomFormatClass     =   0x00030000,     // A non-standard encoding specified by CustomFormatMask
318     tdCustomFormatMask      =   0x00C00000,     // Use this mask to retrieve non-standard encoding information for native interop. The meaning of the values of these 2 bits is unspecified.
319
320     // end string format mask
321
322     tdBeforeFieldInit       =   0x00100000,     // Initialize the class any time before first static field access.
323     tdForwarder             =   0x00200000,     // This ExportedType is a type forwarder.
324
325     // Flags reserved for runtime use.
326     tdReservedMask          =   0x00040800,
327     tdRTSpecialName         =   0x00000800,     // Runtime should check name encoding.
328     tdHasSecurity           =   0x00040000,     // Class has security associate with it.
329 } CorTypeAttr;
330
331
332 // Macros for accessing the members of the CorTypeAttr.
333 #define IsTdNotPublic(x)                    (((x) & tdVisibilityMask) == tdNotPublic)
334 #define IsTdPublic(x)                       (((x) & tdVisibilityMask) == tdPublic)
335 #define IsTdNestedPublic(x)                 (((x) & tdVisibilityMask) == tdNestedPublic)
336 #define IsTdNestedPrivate(x)                (((x) & tdVisibilityMask) == tdNestedPrivate)
337 #define IsTdNestedFamily(x)                 (((x) & tdVisibilityMask) == tdNestedFamily)
338 #define IsTdNestedAssembly(x)               (((x) & tdVisibilityMask) == tdNestedAssembly)
339 #define IsTdNestedFamANDAssem(x)            (((x) & tdVisibilityMask) == tdNestedFamANDAssem)
340 #define IsTdNestedFamORAssem(x)             (((x) & tdVisibilityMask) == tdNestedFamORAssem)
341 #define IsTdNested(x)                       (((x) & tdVisibilityMask) >= tdNestedPublic)
342
343 #define IsTdAutoLayout(x)                   (((x) & tdLayoutMask) == tdAutoLayout)
344 #define IsTdSequentialLayout(x)             (((x) & tdLayoutMask) == tdSequentialLayout)
345 #define IsTdExplicitLayout(x)               (((x) & tdLayoutMask) == tdExplicitLayout)
346
347 #define IsTdClass(x)                        (((x) & tdClassSemanticsMask) == tdClass)
348 #define IsTdInterface(x)                    (((x) & tdClassSemanticsMask) == tdInterface)
349
350 #define IsTdAbstract(x)                     ((x) & tdAbstract)
351 #define IsTdSealed(x)                       ((x) & tdSealed)
352 #define IsTdSpecialName(x)                  ((x) & tdSpecialName)
353
354 #define IsTdImport(x)                       ((x) & tdImport)
355 #define IsTdSerializable(x)                 ((x) & tdSerializable)
356 #define IsTdWindowsRuntime(x)               ((x) & tdWindowsRuntime)
357
358 #define IsTdAnsiClass(x)                    (((x) & tdStringFormatMask) == tdAnsiClass)
359 #define IsTdUnicodeClass(x)                 (((x) & tdStringFormatMask) == tdUnicodeClass)
360 #define IsTdAutoClass(x)                    (((x) & tdStringFormatMask) == tdAutoClass)
361 #define IsTdCustomFormatClass(x)            (((x) & tdStringFormatMask) == tdCustomFormatClass)
362 #define IsTdBeforeFieldInit(x)              ((x) & tdBeforeFieldInit)
363 #define IsTdForwarder(x)                    ((x) & tdForwarder)
364
365 #define IsTdRTSpecialName(x)                ((x) & tdRTSpecialName)
366 #define IsTdHasSecurity(x)                  ((x) & tdHasSecurity)
367
368 // MethodDef attr bits, Used by DefineMethod.
369 typedef enum CorMethodAttr
370 {
371     // member access mask - Use this mask to retrieve accessibility information.
372     mdMemberAccessMask          =   0x0007,
373     mdPrivateScope              =   0x0000,     // Member not referenceable.
374     mdPrivate                   =   0x0001,     // Accessible only by the parent type.
375     mdFamANDAssem               =   0x0002,     // Accessible by sub-types only in this Assembly.
376     mdAssem                     =   0x0003,     // Accessibly by anyone in the Assembly.
377     mdFamily                    =   0x0004,     // Accessible only by type and sub-types.
378     mdFamORAssem                =   0x0005,     // Accessibly by sub-types anywhere, plus anyone in assembly.
379     mdPublic                    =   0x0006,     // Accessibly by anyone who has visibility to this scope.
380     // end member access mask
381
382     // method contract attributes.
383     mdStatic                    =   0x0010,     // Defined on type, else per instance.
384     mdFinal                     =   0x0020,     // Method may not be overridden.
385     mdVirtual                   =   0x0040,     // Method virtual.
386     mdHideBySig                 =   0x0080,     // Method hides by name+sig, else just by name.
387
388     // vtable layout mask - Use this mask to retrieve vtable attributes.
389     mdVtableLayoutMask          =   0x0100,
390     mdReuseSlot                 =   0x0000,     // The default.
391     mdNewSlot                   =   0x0100,     // Method always gets a new slot in the vtable.
392     // end vtable layout mask
393
394     // method implementation attributes.
395     mdCheckAccessOnOverride     =   0x0200,     // Overridability is the same as the visibility.
396     mdAbstract                  =   0x0400,     // Method does not provide an implementation.
397     mdSpecialName               =   0x0800,     // Method is special.  Name describes how.
398
399     // interop attributes
400     mdPinvokeImpl               =   0x2000,     // Implementation is forwarded through pinvoke.
401     mdUnmanagedExport           =   0x0008,     // Managed method exported via thunk to unmanaged code.
402
403     // Reserved flags for runtime use only.
404     mdReservedMask              =   0xd000,
405     mdRTSpecialName             =   0x1000,     // Runtime should check name encoding.
406     mdHasSecurity               =   0x4000,     // Method has security associate with it.
407     mdRequireSecObject          =   0x8000,     // Method calls another method containing security code.
408
409 } CorMethodAttr;
410
411 // Macros for accessing the members of CorMethodAttr.
412 #define IsMdPrivateScope(x)                 (((x) & mdMemberAccessMask) == mdPrivateScope)
413 #define IsMdPrivate(x)                      (((x) & mdMemberAccessMask) == mdPrivate)
414 #define IsMdFamANDAssem(x)                  (((x) & mdMemberAccessMask) == mdFamANDAssem)
415 #define IsMdAssem(x)                        (((x) & mdMemberAccessMask) == mdAssem)
416 #define IsMdFamily(x)                       (((x) & mdMemberAccessMask) == mdFamily)
417 #define IsMdFamORAssem(x)                   (((x) & mdMemberAccessMask) == mdFamORAssem)
418 #define IsMdPublic(x)                       (((x) & mdMemberAccessMask) == mdPublic)
419
420 #define IsMdStatic(x)                       ((x) & mdStatic)
421 #define IsMdFinal(x)                        ((x) & mdFinal)
422 #define IsMdVirtual(x)                      ((x) & mdVirtual)
423 #define IsMdHideBySig(x)                    ((x) & mdHideBySig)
424
425 #define IsMdReuseSlot(x)                    (((x) & mdVtableLayoutMask) == mdReuseSlot)
426 #define IsMdNewSlot(x)                      (((x) & mdVtableLayoutMask) == mdNewSlot)
427
428 #define IsMdCheckAccessOnOverride(x)        ((x) & mdCheckAccessOnOverride)
429 #define IsMdAbstract(x)                     ((x) & mdAbstract)
430 #define IsMdSpecialName(x)                  ((x) & mdSpecialName)
431
432 #define IsMdPinvokeImpl(x)                  ((x) & mdPinvokeImpl)
433 #define IsMdUnmanagedExport(x)              ((x) & mdUnmanagedExport)
434
435 #define IsMdRTSpecialName(x)                ((x) & mdRTSpecialName)
436 #define IsMdInstanceInitializer(x, str)     (((x) & mdRTSpecialName) && !strcmp((str), COR_CTOR_METHOD_NAME))
437 #define IsMdInstanceInitializerW(x, str)    (((x) & mdRTSpecialName) && !wcscmp((str), COR_CTOR_METHOD_NAME_W))
438 #define IsMdClassConstructor(x, str)        (((x) & mdRTSpecialName) && !strcmp((str), COR_CCTOR_METHOD_NAME))
439 #define IsMdClassConstructorW(x, str)       (((x) & mdRTSpecialName) && !wcscmp((str), COR_CCTOR_METHOD_NAME_W))
440 #define IsMdHasSecurity(x)                  ((x) & mdHasSecurity)
441 #define IsMdRequireSecObject(x)             ((x) & mdRequireSecObject)
442
443 // FieldDef attr bits, used by DefineField.
444 typedef enum CorFieldAttr
445 {
446     // member access mask - Use this mask to retrieve accessibility information.
447     fdFieldAccessMask           =   0x0007,
448     fdPrivateScope              =   0x0000,     // Member not referenceable.
449     fdPrivate                   =   0x0001,     // Accessible only by the parent type.
450     fdFamANDAssem               =   0x0002,     // Accessible by sub-types only in this Assembly.
451     fdAssembly                  =   0x0003,     // Accessibly by anyone in the Assembly.
452     fdFamily                    =   0x0004,     // Accessible only by type and sub-types.
453     fdFamORAssem                =   0x0005,     // Accessibly by sub-types anywhere, plus anyone in assembly.
454     fdPublic                    =   0x0006,     // Accessibly by anyone who has visibility to this scope.
455     // end member access mask
456
457     // field contract attributes.
458     fdStatic                    =   0x0010,     // Defined on type, else per instance.
459     fdInitOnly                  =   0x0020,     // Field may only be initialized, not written to after init.
460     fdLiteral                   =   0x0040,     // Value is compile time constant.
461     fdNotSerialized             =   0x0080,     // Field does not have to be serialized when type is remoted.
462
463     fdSpecialName               =   0x0200,     // field is special.  Name describes how.
464
465     // interop attributes
466     fdPinvokeImpl               =   0x2000,     // Implementation is forwarded through pinvoke.
467
468     // Reserved flags for runtime use only.
469     fdReservedMask              =   0x9500,
470     fdRTSpecialName             =   0x0400,     // Runtime(metadata internal APIs) should check name encoding.
471     fdHasFieldMarshal           =   0x1000,     // Field has marshalling information.
472     fdHasDefault                =   0x8000,     // Field has default.
473     fdHasFieldRVA               =   0x0100,     // Field has RVA.
474 } CorFieldAttr;
475
476 // Macros for accessing the members of CorFieldAttr.
477 #define IsFdPrivateScope(x)                 (((x) & fdFieldAccessMask) == fdPrivateScope)
478 #define IsFdPrivate(x)                      (((x) & fdFieldAccessMask) == fdPrivate)
479 #define IsFdFamANDAssem(x)                  (((x) & fdFieldAccessMask) == fdFamANDAssem)
480 #define IsFdAssembly(x)                     (((x) & fdFieldAccessMask) == fdAssembly)
481 #define IsFdFamily(x)                       (((x) & fdFieldAccessMask) == fdFamily)
482 #define IsFdFamORAssem(x)                   (((x) & fdFieldAccessMask) == fdFamORAssem)
483 #define IsFdPublic(x)                       (((x) & fdFieldAccessMask) == fdPublic)
484
485 #define IsFdStatic(x)                       ((x) & fdStatic)
486 #define IsFdInitOnly(x)                     ((x) & fdInitOnly)
487 #define IsFdLiteral(x)                      ((x) & fdLiteral)
488 #define IsFdNotSerialized(x)                ((x) & fdNotSerialized)
489
490 #define IsFdPinvokeImpl(x)                  ((x) & fdPinvokeImpl)
491 #define IsFdSpecialName(x)                  ((x) & fdSpecialName)
492 #define IsFdHasFieldRVA(x)                  ((x) & fdHasFieldRVA)
493
494 #define IsFdRTSpecialName(x)                ((x) & fdRTSpecialName)
495 #define IsFdHasFieldMarshal(x)              ((x) & fdHasFieldMarshal)
496 #define IsFdHasDefault(x)                   ((x) & fdHasDefault)
497
498 // Param attr bits, used by DefineParam.
499 typedef enum CorParamAttr
500 {
501     pdIn                        =   0x0001,     // Param is [In]
502     pdOut                       =   0x0002,     // Param is [out]
503     pdOptional                  =   0x0010,     // Param is optional
504
505     // Reserved flags for Runtime use only.
506     pdReservedMask              =   0xf000,
507     pdHasDefault                =   0x1000,     // Param has default value.
508     pdHasFieldMarshal           =   0x2000,     // Param has FieldMarshal.
509
510     pdUnused                    =   0xcfe0,
511 } CorParamAttr;
512
513 // Macros for accessing the members of CorParamAttr.
514 #define IsPdIn(x)                           ((x) & pdIn)
515 #define IsPdOut(x)                          ((x) & pdOut)
516 #define IsPdOptional(x)                     ((x) & pdOptional)
517
518 #define IsPdHasDefault(x)                   ((x) & pdHasDefault)
519 #define IsPdHasFieldMarshal(x)              ((x) & pdHasFieldMarshal)
520
521
522 // Property attr bits, used by DefineProperty.
523 typedef enum CorPropertyAttr
524 {
525     prSpecialName           =   0x0200,     // property is special.  Name describes how.
526
527     // Reserved flags for Runtime use only.
528     prReservedMask          =   0xf400,
529     prRTSpecialName         =   0x0400,     // Runtime(metadata internal APIs) should check name encoding.
530     prHasDefault            =   0x1000,     // Property has default
531
532     prUnused                =   0xe9ff,
533 } CorPropertyAttr;
534
535 // Macros for accessing the members of CorPropertyAttr.
536 #define IsPrSpecialName(x)                  ((x) & prSpecialName)
537
538 #define IsPrRTSpecialName(x)                ((x) & prRTSpecialName)
539 #define IsPrHasDefault(x)                   ((x) & prHasDefault)
540
541 // Event attr bits, used by DefineEvent.
542 typedef enum CorEventAttr
543 {
544     evSpecialName           =   0x0200,     // event is special.  Name describes how.
545
546     // Reserved flags for Runtime use only.
547     evReservedMask          =   0x0400,
548     evRTSpecialName         =   0x0400,     // Runtime(metadata internal APIs) should check name encoding.
549 } CorEventAttr;
550
551 // Macros for accessing the members of CorEventAttr.
552 #define IsEvSpecialName(x)                  ((x) & evSpecialName)
553
554 #define IsEvRTSpecialName(x)                ((x) & evRTSpecialName)
555
556
557 // MethodSemantic attr bits, used by DefineProperty, DefineEvent.
558 typedef enum CorMethodSemanticsAttr
559 {
560     msSetter    =   0x0001,     // Setter for property
561     msGetter    =   0x0002,     // Getter for property
562     msOther     =   0x0004,     // other method for property or event
563     msAddOn     =   0x0008,     // AddOn method for event
564     msRemoveOn  =   0x0010,     // RemoveOn method for event
565     msFire      =   0x0020,     // Fire method for event
566 } CorMethodSemanticsAttr;
567
568 // Macros for accessing the members of CorMethodSemanticsAttr.
569 #define IsMsSetter(x)                       ((x) & msSetter)
570 #define IsMsGetter(x)                       ((x) & msGetter)
571 #define IsMsOther(x)                        ((x) & msOther)
572 #define IsMsAddOn(x)                        ((x) & msAddOn)
573 #define IsMsRemoveOn(x)                     ((x) & msRemoveOn)
574 #define IsMsFire(x)                         ((x) & msFire)
575
576
577 // DeclSecurity attr bits, used by DefinePermissionSet.
578 typedef enum CorDeclSecurity
579 {
580     dclActionMask               =   0x001f,     // Mask allows growth of enum.
581     dclActionNil                =   0x0000,     //
582     dclRequest                  =   0x0001,     //
583     dclDemand                   =   0x0002,     //
584     dclAssert                   =   0x0003,     //
585     dclDeny                     =   0x0004,     //
586     dclPermitOnly               =   0x0005,     //
587     dclLinktimeCheck            =   0x0006,     //
588     dclInheritanceCheck         =   0x0007,     //
589     dclRequestMinimum           =   0x0008,     //
590     dclRequestOptional          =   0x0009,     //
591     dclRequestRefuse            =   0x000a,     //
592     dclPrejitGrant              =   0x000b,     // Persisted grant set at prejit time
593     dclPrejitDenied             =   0x000c,     // Persisted denied set at prejit time
594     dclNonCasDemand             =   0x000d,     //
595     dclNonCasLinkDemand         =   0x000e,     //
596     dclNonCasInheritance        =   0x000f,     //
597     dclMaximumValue             =   0x000f,     // Maximum legal value
598 } CorDeclSecurity;
599
600 // Macros for accessing the members of CorDeclSecurity.
601 #define IsDclActionNil(x)                   (((x) & dclActionMask) == dclActionNil)
602
603 // Is this a demand that can trigger a stackwalk?
604 #define IsDclActionAnyStackModifier(x)              ((((x) & dclActionMask) == dclAssert) || \
605                                                     (((x) & dclActionMask) == dclDeny)  || \
606                                                     (((x) & dclActionMask) == dclPermitOnly))
607
608 // Is this an assembly level attribute (i.e. not applicable on Type/Member)?
609 #define IsAssemblyDclAction(x)              (((x) >= dclRequestMinimum)  && \
610                                              ((x) <= dclRequestRefuse))
611
612 // Is this an NGen only attribute?
613 #define IsNGenOnlyDclAction(x)              (((x) == dclPrejitGrant)  || \
614                                              ((x) == dclPrejitDenied))
615
616
617 // MethodImpl attr bits, used by DefineMethodImpl.
618 typedef enum CorMethodImpl
619 {
620     // code impl mask
621     miCodeTypeMask       =   0x0003,   // Flags about code type.
622     miIL                 =   0x0000,   // Method impl is IL.
623     miNative             =   0x0001,   // Method impl is native.
624     miOPTIL              =   0x0002,   // Method impl is OPTIL
625     miRuntime            =   0x0003,   // Method impl is provided by the runtime.
626     // end code impl mask
627
628     // managed mask
629     miManagedMask        =   0x0004,   // Flags specifying whether the code is managed or unmanaged.
630     miUnmanaged          =   0x0004,   // Method impl is unmanaged, otherwise managed.
631     miManaged            =   0x0000,   // Method impl is managed.
632     // end managed mask
633
634     // implementation info and interop
635     miForwardRef         =   0x0010,   // Indicates method is defined; used primarily in merge scenarios.
636     miPreserveSig        =   0x0080,   // Indicates method sig is not to be mangled to do HRESULT conversion.
637
638     miInternalCall       =   0x1000,   // Reserved for internal use.
639
640     miSynchronized       =   0x0020,   // Method is single threaded through the body.
641     miNoInlining         =   0x0008,   // Method may not be inlined.
642     miAggressiveInlining =   0x0100,   // Method should be inlined if possible.
643     miNoOptimization     =   0x0040,   // Method may not be optimized.
644
645     // These are the flags that are allowed in MethodImplAttribute's Value
646     // property. This should include everything above except the code impl
647     // flags (which are used for MethodImplAttribute's MethodCodeType field).
648     miUserMask           =   miManagedMask | miForwardRef | miPreserveSig |
649                              miInternalCall | miSynchronized |
650                              miNoInlining | miAggressiveInlining |
651                              miNoOptimization,
652
653     miMaxMethodImplVal   =   0xffff,   // Range check value
654 } CorMethodImpl;
655
656 // Macros for accesing the members of CorMethodImpl.
657 #define IsMiIL(x)                           (((x) & miCodeTypeMask) == miIL)
658 #define IsMiNative(x)                       (((x) & miCodeTypeMask) == miNative)
659 #define IsMiOPTIL(x)                        (((x) & miCodeTypeMask) == miOPTIL)
660 #define IsMiRuntime(x)                      (((x) & miCodeTypeMask) == miRuntime)
661
662 #define IsMiUnmanaged(x)                    (((x) & miManagedMask) == miUnmanaged)
663 #define IsMiManaged(x)                      (((x) & miManagedMask) == miManaged)
664
665 #define IsMiForwardRef(x)                   ((x) & miForwardRef)
666 #define IsMiPreserveSig(x)                  ((x) & miPreserveSig)
667
668 #define IsMiInternalCall(x)                 ((x) & miInternalCall)
669
670 #define IsMiSynchronized(x)                 ((x) & miSynchronized)
671 #define IsMiNoInlining(x)                   ((x) & miNoInlining)
672 #define IsMiAggressiveInlining(x)           ((x) & miAggressiveInlining)
673 #define IsMiNoOptimization(x)               ((x) & miNoOptimization)
674
675 // PinvokeMap attr bits, used by DefinePinvokeMap.
676 typedef enum  CorPinvokeMap
677 {
678     pmNoMangle          = 0x0001,   // Pinvoke is to use the member name as specified.
679
680     // Use this mask to retrieve the CharSet information.
681     pmCharSetMask       = 0x0006,
682     pmCharSetNotSpec    = 0x0000,
683     pmCharSetAnsi       = 0x0002,
684     pmCharSetUnicode    = 0x0004,
685     pmCharSetAuto       = 0x0006,
686
687
688     pmBestFitUseAssem   = 0x0000,
689     pmBestFitEnabled    = 0x0010,
690     pmBestFitDisabled   = 0x0020,
691     pmBestFitMask       = 0x0030,
692
693     pmThrowOnUnmappableCharUseAssem   = 0x0000,
694     pmThrowOnUnmappableCharEnabled    = 0x1000,
695     pmThrowOnUnmappableCharDisabled   = 0x2000,
696     pmThrowOnUnmappableCharMask       = 0x3000,
697
698     pmSupportsLastError = 0x0040,   // Information about target function. Not relevant for fields.
699
700     // None of the calling convention flags is relevant for fields.
701     pmCallConvMask      = 0x0700,
702     pmCallConvWinapi    = 0x0100,   // Pinvoke will use native callconv appropriate to target windows platform.
703     pmCallConvCdecl     = 0x0200,
704     pmCallConvStdcall   = 0x0300,
705     pmCallConvThiscall  = 0x0400,   // In M9, pinvoke will raise exception.
706     pmCallConvFastcall  = 0x0500,
707
708     pmMaxValue          = 0xFFFF,
709 } CorPinvokeMap;
710
711 // Macros for accessing the members of CorPinvokeMap
712 #define IsPmNoMangle(x)                     ((x) & pmNoMangle)
713
714 #define IsPmCharSetNotSpec(x)               (((x) & pmCharSetMask) == pmCharSetNotSpec)
715 #define IsPmCharSetAnsi(x)                  (((x) & pmCharSetMask) == pmCharSetAnsi)
716 #define IsPmCharSetUnicode(x)               (((x) & pmCharSetMask) == pmCharSetUnicode)
717 #define IsPmCharSetAuto(x)                  (((x) & pmCharSetMask) == pmCharSetAuto)
718
719 #define IsPmSupportsLastError(x)            ((x) & pmSupportsLastError)
720
721 #define IsPmCallConvWinapi(x)               (((x) & pmCallConvMask) == pmCallConvWinapi)
722 #define IsPmCallConvCdecl(x)                (((x) & pmCallConvMask) == pmCallConvCdecl)
723 #define IsPmCallConvStdcall(x)              (((x) & pmCallConvMask) == pmCallConvStdcall)
724 #define IsPmCallConvThiscall(x)             (((x) & pmCallConvMask) == pmCallConvThiscall)
725 #define IsPmCallConvFastcall(x)             (((x) & pmCallConvMask) == pmCallConvFastcall)
726
727 #define IsPmBestFitEnabled(x)                 (((x) & pmBestFitMask) == pmBestFitEnabled)
728 #define IsPmBestFitDisabled(x)                (((x) & pmBestFitMask) == pmBestFitDisabled)
729 #define IsPmBestFitUseAssem(x)                (((x) & pmBestFitMask) == pmBestFitUseAssem)
730
731 #define IsPmThrowOnUnmappableCharEnabled(x)   (((x) & pmThrowOnUnmappableCharMask) == pmThrowOnUnmappableCharEnabled)
732 #define IsPmThrowOnUnmappableCharDisabled(x)  (((x) & pmThrowOnUnmappableCharMask) == pmThrowOnUnmappableCharDisabled)
733 #define IsPmThrowOnUnmappableCharUseAssem(x)  (((x) & pmThrowOnUnmappableCharMask) == pmThrowOnUnmappableCharUseAssem)
734
735 // Assembly attr bits, used by DefineAssembly.
736 typedef enum CorAssemblyFlags
737 {
738     afPublicKey             =   0x0001,     // The assembly ref holds the full (unhashed) public key.
739     
740     afPA_None               =   0x0000,     // Processor Architecture unspecified
741     afPA_MSIL               =   0x0010,     // Processor Architecture: neutral (PE32)
742     afPA_x86                =   0x0020,     // Processor Architecture: x86 (PE32)
743     afPA_IA64               =   0x0030,     // Processor Architecture: Itanium (PE32+)
744     afPA_AMD64              =   0x0040,     // Processor Architecture: AMD X64 (PE32+)
745     afPA_ARM                =   0x0050,     // Processor Architecture: ARM (PE32)
746     afPA_NoPlatform         =   0x0070,      // applies to any platform but cannot run on any (e.g. reference assembly), should not have "specified" set
747     afPA_Specified          =   0x0080,     // Propagate PA flags to AssemblyRef record
748     afPA_Mask               =   0x0070,     // Bits describing the processor architecture
749     afPA_FullMask           =   0x00F0,     // Bits describing the PA incl. Specified
750     afPA_Shift              =   0x0004,     // NOT A FLAG, shift count in PA flags <--> index conversion
751
752     afEnableJITcompileTracking   =  0x8000, // From "DebuggableAttribute".
753     afDisableJITcompileOptimizer =  0x4000, // From "DebuggableAttribute".
754     afDebuggableAttributeMask    =  0xc000,
755
756     afRetargetable          =   0x0100,     // The assembly can be retargeted (at runtime) to an
757                                             //  assembly from a different publisher.
758
759     afContentType_Default         = 0x0000, 
760     afContentType_WindowsRuntime  = 0x0200, 
761     afContentType_Mask            = 0x0E00, // Bits describing ContentType
762 } CorAssemblyFlags;
763
764 // Macros for accessing the members of CorAssemblyFlags.
765 #define IsAfRetargetable(x)                 ((x) & afRetargetable)
766 #define IsAfContentType_Default(x)          (((x) & afContentType_Mask) == afContentType_Default)
767 #define IsAfContentType_WindowsRuntime(x)   (((x) & afContentType_Mask) == afContentType_WindowsRuntime)
768
769 // Macros for accessing the Processor Architecture flags of CorAssemblyFlags.
770 #define IsAfPA_MSIL(x) (((x) & afPA_Mask) == afPA_MSIL)
771 #define IsAfPA_x86(x) (((x) & afPA_Mask) == afPA_x86)
772 #define IsAfPA_IA64(x) (((x) & afPA_Mask) == afPA_IA64)
773 #define IsAfPA_AMD64(x) (((x) & afPA_Mask) == afPA_AMD64)
774 #define IsAfPA_ARM(x) (((x) & afPA_Mask) == afPA_ARM)
775 #define IsAfPA_NoPlatform(x) (((x) & afPA_FullMask) == afPA_NoPlatform)
776 #define IsAfPA_Specified(x) ((x) & afPA_Specified)
777 #define PAIndex(x) (((x) & afPA_Mask) >> afPA_Shift)
778 #define PAFlag(x)  (((x) << afPA_Shift) & afPA_Mask)
779 #define PrepareForSaving(x) ((x) & (((x) & afPA_Specified) ? ~afPA_Specified : ~afPA_FullMask))
780
781 #define IsAfEnableJITcompileTracking(x)     ((x) & afEnableJITcompileTracking)
782 #define IsAfDisableJITcompileOptimizer(x)   ((x) & afDisableJITcompileOptimizer)
783
784 // Macros for accessing the public key flags of CorAssemblyFlags.
785 #define IsAfPublicKey(x)                    ((x) & afPublicKey)
786 #define IsAfPublicKeyToken(x)               (((x) & afPublicKey) == 0)
787
788
789 // ManifestResource attr bits, used by DefineManifestResource.
790 typedef enum CorManifestResourceFlags
791 {
792     mrVisibilityMask        =   0x0007,
793     mrPublic                =   0x0001,     // The Resource is exported from the Assembly.
794     mrPrivate               =   0x0002,     // The Resource is private to the Assembly.
795 } CorManifestResourceFlags;
796
797 // Macros for accessing the members of CorManifestResourceFlags.
798 #define IsMrPublic(x)                       (((x) & mrVisibilityMask) == mrPublic)
799 #define IsMrPrivate(x)                      (((x) & mrVisibilityMask) == mrPrivate)
800
801
802 // File attr bits, used by DefineFile.
803 typedef enum CorFileFlags
804 {
805     ffContainsMetaData      =   0x0000,     // This is not a resource file
806     ffContainsNoMetaData    =   0x0001,     // This is a resource file or other non-metadata-containing file
807 } CorFileFlags;
808
809 // Macros for accessing the members of CorFileFlags.
810 #define IsFfContainsMetaData(x)             (!((x) & ffContainsNoMetaData))
811 #define IsFfContainsNoMetaData(x)           ((x) & ffContainsNoMetaData)
812
813 // PE file kind bits, returned by IMetaDataImport2::GetPEKind()
814 typedef enum CorPEKind
815 {
816     peNot       = 0x00000000,   // not a PE file
817     peILonly    = 0x00000001,   // flag IL_ONLY is set in COR header
818     pe32BitRequired=0x00000002,  // flag 32BITREQUIRED is set and 32BITPREFERRED is clear in COR header
819     pe32Plus    = 0x00000004,   // PE32+ file (64 bit)
820     pe32Unmanaged=0x00000008,    // PE32 without COR header
821     pe32BitPreferred=0x00000010  // flags 32BITREQUIRED and 32BITPREFERRED are set in COR header
822 } CorPEKind;
823
824
825 // GenericParam bits, used by DefineGenericParam.
826 typedef enum CorGenericParamAttr
827 {
828     // Variance of type parameters, only applicable to generic parameters 
829     // for generic interfaces and delegates
830     gpVarianceMask          =   0x0003,
831     gpNonVariant            =   0x0000, 
832     gpCovariant             =   0x0001,
833     gpContravariant         =   0x0002,
834
835     // Special constraints, applicable to any type parameters
836     gpSpecialConstraintMask =  0x001C,
837     gpNoSpecialConstraint   =   0x0000,      
838     gpReferenceTypeConstraint = 0x0004,      // type argument must be a reference type
839     gpNotNullableValueTypeConstraint   =   0x0008,      // type argument must be a value type but not Nullable
840     gpDefaultConstructorConstraint = 0x0010, // type argument must have a public default constructor
841 } CorGenericParamAttr;
842
843 // structures and enums moved from COR.H
844 typedef unsigned __int8 COR_SIGNATURE;
845
846 typedef COR_SIGNATURE* PCOR_SIGNATURE;      // pointer to a cor sig.  Not void* so that
847                                             // the bytes can be incremented easily
848 typedef const COR_SIGNATURE* PCCOR_SIGNATURE;
849
850
851 typedef const char * MDUTF8CSTR;
852 typedef char * MDUTF8STR;
853
854 //*****************************************************************************
855 //
856 // Element type for Cor signature
857 //
858 //*****************************************************************************
859
860 typedef enum CorElementType
861 {
862     ELEMENT_TYPE_END            = 0x00,
863     ELEMENT_TYPE_VOID           = 0x01,
864     ELEMENT_TYPE_BOOLEAN        = 0x02,
865     ELEMENT_TYPE_CHAR           = 0x03,
866     ELEMENT_TYPE_I1             = 0x04,
867     ELEMENT_TYPE_U1             = 0x05,
868     ELEMENT_TYPE_I2             = 0x06,
869     ELEMENT_TYPE_U2             = 0x07,
870     ELEMENT_TYPE_I4             = 0x08,
871     ELEMENT_TYPE_U4             = 0x09,
872     ELEMENT_TYPE_I8             = 0x0a,
873     ELEMENT_TYPE_U8             = 0x0b,
874     ELEMENT_TYPE_R4             = 0x0c,
875     ELEMENT_TYPE_R8             = 0x0d,
876     ELEMENT_TYPE_STRING         = 0x0e,
877
878     // every type above PTR will be simple type
879     ELEMENT_TYPE_PTR            = 0x0f,     // PTR <type>
880     ELEMENT_TYPE_BYREF          = 0x10,     // BYREF <type>
881
882     // Please use ELEMENT_TYPE_VALUETYPE. ELEMENT_TYPE_VALUECLASS is deprecated.
883     ELEMENT_TYPE_VALUETYPE      = 0x11,     // VALUETYPE <class Token>
884     ELEMENT_TYPE_CLASS          = 0x12,     // CLASS <class Token>
885     ELEMENT_TYPE_VAR            = 0x13,     // a class type variable VAR <number>
886     ELEMENT_TYPE_ARRAY          = 0x14,     // MDARRAY <type> <rank> <bcount> <bound1> ... <lbcount> <lb1> ...
887     ELEMENT_TYPE_GENERICINST    = 0x15,     // GENERICINST <generic type> <argCnt> <arg1> ... <argn>
888     ELEMENT_TYPE_TYPEDBYREF     = 0x16,     // TYPEDREF  (it takes no args) a typed referece to some other type
889
890     ELEMENT_TYPE_I              = 0x18,     // native integer size
891     ELEMENT_TYPE_U              = 0x19,     // native unsigned integer size
892     ELEMENT_TYPE_FNPTR          = 0x1b,     // FNPTR <complete sig for the function including calling convention>
893     ELEMENT_TYPE_OBJECT         = 0x1c,     // Shortcut for System.Object
894     ELEMENT_TYPE_SZARRAY        = 0x1d,     // Shortcut for single dimension zero lower bound array
895                                             // SZARRAY <type>
896     ELEMENT_TYPE_MVAR           = 0x1e,     // a method type variable MVAR <number>
897
898     // This is only for binding
899     ELEMENT_TYPE_CMOD_REQD      = 0x1f,     // required C modifier : E_T_CMOD_REQD <mdTypeRef/mdTypeDef>
900     ELEMENT_TYPE_CMOD_OPT       = 0x20,     // optional C modifier : E_T_CMOD_OPT <mdTypeRef/mdTypeDef>
901
902     // This is for signatures generated internally (which will not be persisted in any way).
903     ELEMENT_TYPE_INTERNAL       = 0x21,     // INTERNAL <typehandle>
904
905     // Note that this is the max of base type excluding modifiers
906     ELEMENT_TYPE_MAX            = 0x22,     // first invalid element type
907
908
909     ELEMENT_TYPE_MODIFIER       = 0x40,
910     ELEMENT_TYPE_SENTINEL       = 0x01 | ELEMENT_TYPE_MODIFIER, // sentinel for varargs
911     ELEMENT_TYPE_PINNED         = 0x05 | ELEMENT_TYPE_MODIFIER,
912
913 } CorElementType;
914
915
916 //*****************************************************************************
917 //
918 // Serialization types for Custom attribute support
919 //
920 //*****************************************************************************
921
922 typedef enum CorSerializationType
923 {
924     SERIALIZATION_TYPE_UNDEFINED    = 0,
925     SERIALIZATION_TYPE_BOOLEAN      = ELEMENT_TYPE_BOOLEAN,
926     SERIALIZATION_TYPE_CHAR         = ELEMENT_TYPE_CHAR,
927     SERIALIZATION_TYPE_I1           = ELEMENT_TYPE_I1,
928     SERIALIZATION_TYPE_U1           = ELEMENT_TYPE_U1,
929     SERIALIZATION_TYPE_I2           = ELEMENT_TYPE_I2,
930     SERIALIZATION_TYPE_U2           = ELEMENT_TYPE_U2,
931     SERIALIZATION_TYPE_I4           = ELEMENT_TYPE_I4,
932     SERIALIZATION_TYPE_U4           = ELEMENT_TYPE_U4,
933     SERIALIZATION_TYPE_I8           = ELEMENT_TYPE_I8,
934     SERIALIZATION_TYPE_U8           = ELEMENT_TYPE_U8,
935     SERIALIZATION_TYPE_R4           = ELEMENT_TYPE_R4,
936     SERIALIZATION_TYPE_R8           = ELEMENT_TYPE_R8,
937     SERIALIZATION_TYPE_STRING       = ELEMENT_TYPE_STRING,
938     SERIALIZATION_TYPE_SZARRAY      = ELEMENT_TYPE_SZARRAY, // Shortcut for single dimension zero lower bound array
939     SERIALIZATION_TYPE_TYPE         = 0x50,
940     SERIALIZATION_TYPE_TAGGED_OBJECT= 0x51,
941     SERIALIZATION_TYPE_FIELD        = 0x53,
942     SERIALIZATION_TYPE_PROPERTY     = 0x54,
943     SERIALIZATION_TYPE_ENUM         = 0x55
944 } CorSerializationType;
945
946 //
947 // Calling convention flags.
948 //
949
950
951 typedef enum CorCallingConvention
952 {
953     IMAGE_CEE_CS_CALLCONV_DEFAULT       = 0x0,
954
955     IMAGE_CEE_CS_CALLCONV_VARARG        = 0x5,
956     IMAGE_CEE_CS_CALLCONV_FIELD         = 0x6,
957     IMAGE_CEE_CS_CALLCONV_LOCAL_SIG     = 0x7,
958     IMAGE_CEE_CS_CALLCONV_PROPERTY      = 0x8,
959     IMAGE_CEE_CS_CALLCONV_UNMGD         = 0x9,
960     IMAGE_CEE_CS_CALLCONV_GENERICINST   = 0xa,  // generic method instantiation
961     IMAGE_CEE_CS_CALLCONV_NATIVEVARARG  = 0xb,  // used ONLY for 64bit vararg PInvoke calls
962     IMAGE_CEE_CS_CALLCONV_MAX           = 0xc,  // first invalid calling convention
963
964
965         // The high bits of the calling convention convey additional info
966     IMAGE_CEE_CS_CALLCONV_MASK      = 0x0f,  // Calling convention is bottom 4 bits
967     IMAGE_CEE_CS_CALLCONV_HASTHIS   = 0x20,  // Top bit indicates a 'this' parameter
968     IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS = 0x40,  // This parameter is explicitly in the signature
969     IMAGE_CEE_CS_CALLCONV_GENERIC   = 0x10,  // Generic method sig with explicit number of type arguments (precedes ordinary parameter count)
970     // 0x80 is reserved for internal use
971 } CorCallingConvention;
972
973 #define IMAGE_CEE_CS_CALLCONV_INSTANTIATION IMAGE_CEE_CS_CALLCONV_GENERICINST
974
975 typedef enum CorUnmanagedCallingConvention
976 {
977     IMAGE_CEE_UNMANAGED_CALLCONV_C         = 0x1,
978     IMAGE_CEE_UNMANAGED_CALLCONV_STDCALL   = 0x2,
979     IMAGE_CEE_UNMANAGED_CALLCONV_THISCALL  = 0x3,
980     IMAGE_CEE_UNMANAGED_CALLCONV_FASTCALL  = 0x4,
981
982     IMAGE_CEE_CS_CALLCONV_C         = IMAGE_CEE_UNMANAGED_CALLCONV_C,
983     IMAGE_CEE_CS_CALLCONV_STDCALL   = IMAGE_CEE_UNMANAGED_CALLCONV_STDCALL,
984     IMAGE_CEE_CS_CALLCONV_THISCALL  = IMAGE_CEE_UNMANAGED_CALLCONV_THISCALL,
985     IMAGE_CEE_CS_CALLCONV_FASTCALL  = IMAGE_CEE_UNMANAGED_CALLCONV_FASTCALL,
986
987 } CorUnmanagedCallingConvention;
988
989
990 typedef enum CorArgType
991 {
992     IMAGE_CEE_CS_END        = 0x0,
993     IMAGE_CEE_CS_VOID       = 0x1,
994     IMAGE_CEE_CS_I4         = 0x2,
995     IMAGE_CEE_CS_I8         = 0x3,
996     IMAGE_CEE_CS_R4         = 0x4,
997     IMAGE_CEE_CS_R8         = 0x5,
998     IMAGE_CEE_CS_PTR        = 0x6,
999     IMAGE_CEE_CS_OBJECT     = 0x7,
1000     IMAGE_CEE_CS_STRUCT4    = 0x8,
1001     IMAGE_CEE_CS_STRUCT32   = 0x9,
1002     IMAGE_CEE_CS_BYVALUE    = 0xA,
1003 } CorArgType;
1004
1005
1006 //*****************************************************************************
1007 //
1008 // Native type for N-Direct
1009 //
1010 //*****************************************************************************
1011
1012 typedef enum CorNativeType
1013 {
1014
1015     // Kepp this in-synch with ndp\clr\src\BCL\System\runtime\interopservices\attributes.cs
1016
1017     NATIVE_TYPE_END         = 0x0,    //DEPRECATED
1018     NATIVE_TYPE_VOID        = 0x1,    //DEPRECATED
1019     NATIVE_TYPE_BOOLEAN     = 0x2,    // (4 byte boolean value: TRUE = non-zero, FALSE = 0)
1020     NATIVE_TYPE_I1          = 0x3,
1021     NATIVE_TYPE_U1          = 0x4,
1022     NATIVE_TYPE_I2          = 0x5,
1023     NATIVE_TYPE_U2          = 0x6,
1024     NATIVE_TYPE_I4          = 0x7,
1025     NATIVE_TYPE_U4          = 0x8,
1026     NATIVE_TYPE_I8          = 0x9,
1027     NATIVE_TYPE_U8          = 0xa,
1028     NATIVE_TYPE_R4          = 0xb,
1029     NATIVE_TYPE_R8          = 0xc,
1030     NATIVE_TYPE_SYSCHAR     = 0xd,    //DEPRECATED
1031     NATIVE_TYPE_VARIANT     = 0xe,    //DEPRECATED
1032     NATIVE_TYPE_CURRENCY    = 0xf,
1033     NATIVE_TYPE_PTR         = 0x10,   //DEPRECATED
1034
1035     NATIVE_TYPE_DECIMAL     = 0x11,   //DEPRECATED
1036     NATIVE_TYPE_DATE        = 0x12,   //DEPRECATED
1037     NATIVE_TYPE_BSTR        = 0x13,   //COMINTEROP
1038     NATIVE_TYPE_LPSTR       = 0x14,
1039     NATIVE_TYPE_LPWSTR      = 0x15,
1040     NATIVE_TYPE_LPTSTR      = 0x16,
1041     NATIVE_TYPE_FIXEDSYSSTRING  = 0x17,
1042     NATIVE_TYPE_OBJECTREF   = 0x18,   //DEPRECATED
1043     NATIVE_TYPE_IUNKNOWN    = 0x19,   //COMINTEROP
1044     NATIVE_TYPE_IDISPATCH   = 0x1a,   //COMINTEROP
1045     NATIVE_TYPE_STRUCT      = 0x1b,
1046     NATIVE_TYPE_INTF        = 0x1c,   //COMINTEROP
1047     NATIVE_TYPE_SAFEARRAY   = 0x1d,   //COMINTEROP
1048     NATIVE_TYPE_FIXEDARRAY  = 0x1e,
1049     NATIVE_TYPE_INT         = 0x1f,
1050     NATIVE_TYPE_UINT        = 0x20,
1051
1052     NATIVE_TYPE_NESTEDSTRUCT  = 0x21, //DEPRECATED (use NATIVE_TYPE_STRUCT)
1053
1054     NATIVE_TYPE_BYVALSTR    = 0x22,   //COMINTEROP
1055
1056     NATIVE_TYPE_ANSIBSTR    = 0x23,   //COMINTEROP
1057
1058     NATIVE_TYPE_TBSTR       = 0x24, // select BSTR or ANSIBSTR depending on platform
1059                                       //COMINTEROP
1060
1061     NATIVE_TYPE_VARIANTBOOL = 0x25, // (2-byte boolean value: TRUE = -1, FALSE = 0)
1062                                       //COMINTEROP
1063     NATIVE_TYPE_FUNC        = 0x26,
1064
1065     NATIVE_TYPE_ASANY       = 0x28,
1066
1067     NATIVE_TYPE_ARRAY       = 0x2a,
1068     NATIVE_TYPE_LPSTRUCT    = 0x2b,
1069
1070     NATIVE_TYPE_CUSTOMMARSHALER = 0x2c,  // Custom marshaler native type. This must be followed
1071                                          // by a string of the following format:
1072                                          // "Native type name/0Custom marshaler type name/0Optional cookie/0"
1073                                          // Or
1074                                          // "{Native type GUID}/0Custom marshaler type name/0Optional cookie/0"
1075
1076     NATIVE_TYPE_ERROR       = 0x2d, // This native type coupled with ELEMENT_TYPE_I4 will map to VT_HRESULT
1077                                     //COMINTEROP
1078
1079     NATIVE_TYPE_IINSPECTABLE = 0x2e,
1080     NATIVE_TYPE_HSTRING     = 0x2f,
1081     NATIVE_TYPE_LPUTF8STR   = 0x30, // utf-8 string
1082     NATIVE_TYPE_MAX         = 0x50, // first invalid element type
1083 } CorNativeType;
1084
1085
1086 enum
1087 {
1088     DESCR_GROUP_METHODDEF = 0,          // DESCR group for MethodDefs
1089     DESCR_GROUP_METHODIMPL,             // DESCR group for MethodImpls
1090 };
1091
1092 /***********************************************************************************/
1093 // a COR_ILMETHOD_SECT is a generic container for attributes that are private
1094 // to a particular method.  The COR_ILMETHOD structure points to one of these
1095 // (see GetSect()).  COR_ILMETHOD_SECT can decode the Kind of attribute (but not
1096 // its internal data layout, and can skip past the current attibute to find the
1097 // Next one.   The overhead for COR_ILMETHOD_SECT is a minimum of 2 bytes.
1098
1099 typedef enum CorILMethodSect                             // codes that identify attributes
1100 {
1101     CorILMethod_Sect_Reserved    = 0,
1102     CorILMethod_Sect_EHTable     = 1,
1103     CorILMethod_Sect_OptILTable  = 2,
1104
1105     CorILMethod_Sect_KindMask    = 0x3F,        // The mask for decoding the type code
1106     CorILMethod_Sect_FatFormat   = 0x40,        // fat format
1107     CorILMethod_Sect_MoreSects   = 0x80,        // there is another attribute after this one
1108 } CorILMethodSect;
1109
1110 /************************************/
1111 /* NOTE this structure must be DWORD aligned!! */
1112
1113 typedef struct IMAGE_COR_ILMETHOD_SECT_SMALL
1114 {
1115     BYTE Kind;
1116     BYTE DataSize;
1117
1118 } IMAGE_COR_ILMETHOD_SECT_SMALL;
1119
1120
1121
1122 /************************************/
1123 /* NOTE this structure must be DWORD aligned!! */
1124 typedef struct IMAGE_COR_ILMETHOD_SECT_FAT
1125 {
1126     unsigned Kind : 8;
1127     unsigned DataSize : 24;
1128
1129 } IMAGE_COR_ILMETHOD_SECT_FAT;
1130
1131
1132
1133 /***********************************************************************************/
1134 /* If COR_ILMETHOD_SECT_HEADER::Kind() = CorILMethod_Sect_EHTable then the attribute
1135    is a list of exception handling clauses.  There are two formats, fat or small
1136 */
1137 typedef enum CorExceptionFlag                       // definitions for the Flags field below (for both big and small)
1138 {
1139     COR_ILEXCEPTION_CLAUSE_NONE,                    // This is a typed handler
1140     COR_ILEXCEPTION_CLAUSE_OFFSETLEN = 0x0000,      // Deprecated
1141     COR_ILEXCEPTION_CLAUSE_DEPRECATED = 0x0000,     // Deprecated
1142     COR_ILEXCEPTION_CLAUSE_FILTER  = 0x0001,        // If this bit is on, then this EH entry is for a filter
1143     COR_ILEXCEPTION_CLAUSE_FINALLY = 0x0002,        // This clause is a finally clause
1144     COR_ILEXCEPTION_CLAUSE_FAULT = 0x0004,          // Fault clause (finally that is called on exception only)
1145     COR_ILEXCEPTION_CLAUSE_DUPLICATED = 0x0008,     // duplicated clause. This clause was duplicated to a funclet which was pulled out of line
1146 } CorExceptionFlag;
1147
1148 /***********************************/
1149 typedef struct IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_FAT
1150 {
1151     CorExceptionFlag    Flags;
1152     DWORD               TryOffset;
1153     DWORD               TryLength;      // relative to start of try block
1154     DWORD               HandlerOffset;
1155     DWORD               HandlerLength;  // relative to start of handler
1156     union {
1157         DWORD           ClassToken;     // use for type-based exception handlers
1158         DWORD           FilterOffset;   // use for filter-based exception handlers (COR_ILEXCEPTION_FILTER is set)
1159     };
1160 } IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_FAT;
1161
1162 typedef struct IMAGE_COR_ILMETHOD_SECT_EH_FAT
1163 {
1164     IMAGE_COR_ILMETHOD_SECT_FAT   SectFat;
1165     IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_FAT Clauses[1];     // actually variable size
1166 } IMAGE_COR_ILMETHOD_SECT_EH_FAT;
1167
1168 /***********************************/
1169 typedef struct IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL
1170 {
1171 #ifdef _WIN64
1172     unsigned            Flags         : 16;
1173 #else // !_WIN64
1174     CorExceptionFlag    Flags         : 16;
1175 #endif
1176     unsigned            TryOffset     : 16;
1177     unsigned            TryLength     : 8;  // relative to start of try block
1178     unsigned            HandlerOffset : 16;
1179     unsigned            HandlerLength : 8;  // relative to start of handler
1180     union {
1181         DWORD       ClassToken;
1182         DWORD       FilterOffset;
1183     };
1184 } IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL;
1185
1186 /***********************************/
1187 typedef struct IMAGE_COR_ILMETHOD_SECT_EH_SMALL
1188 {
1189     IMAGE_COR_ILMETHOD_SECT_SMALL SectSmall;
1190     WORD Reserved;
1191     IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL Clauses[1];   // actually variable size
1192 } IMAGE_COR_ILMETHOD_SECT_EH_SMALL;
1193
1194
1195
1196 typedef union IMAGE_COR_ILMETHOD_SECT_EH
1197 {
1198     IMAGE_COR_ILMETHOD_SECT_EH_SMALL Small;
1199     IMAGE_COR_ILMETHOD_SECT_EH_FAT Fat;
1200 } IMAGE_COR_ILMETHOD_SECT_EH;
1201
1202
1203 /***********************************************************************************/
1204 // Legal values for 
1205 // * code:IMAGE_COR_ILMETHOD_FAT::Flags or 
1206 // * code:IMAGE_COR_ILMETHOD_TINY::Flags_CodeSize fields. 
1207 // 
1208 // The only semantic flag at present is CorILMethod_InitLocals
1209 typedef enum CorILMethodFlags
1210 {
1211     CorILMethod_InitLocals      = 0x0010,           // call default constructor on all local vars
1212     CorILMethod_MoreSects       = 0x0008,           // there is another attribute after this one
1213
1214     CorILMethod_CompressedIL    = 0x0040,           // Not used.  
1215
1216         // Indicates the format for the COR_ILMETHOD header
1217     CorILMethod_FormatShift     = 3,
1218     CorILMethod_FormatMask      = ((1 << CorILMethod_FormatShift) - 1),
1219     CorILMethod_TinyFormat      = 0x0002,         // use this code if the code size is even
1220     CorILMethod_SmallFormat     = 0x0000,
1221     CorILMethod_FatFormat       = 0x0003,
1222     CorILMethod_TinyFormat1     = 0x0006,         // use this code if the code size is odd
1223 } CorILMethodFlags;
1224
1225 /***************************************************************************/
1226 /* Used when the method is tiny (< 64 bytes), and there are no local vars */
1227 typedef struct IMAGE_COR_ILMETHOD_TINY
1228 {
1229     BYTE Flags_CodeSize;
1230 } IMAGE_COR_ILMETHOD_TINY;
1231
1232 /************************************/
1233 // This strucuture is the 'fat' layout, where no compression is attempted.
1234 // Note that this structure can be added on at the end, thus making it extensible
1235 typedef struct IMAGE_COR_ILMETHOD_FAT
1236 {
1237     unsigned Flags    : 12;     // Flags see code:CorILMethodFlags
1238     unsigned Size     :  4;     // size in DWords of this structure (currently 3)
1239     unsigned MaxStack : 16;     // maximum number of items (I4, I, I8, obj ...), on the operand stack
1240     DWORD   CodeSize;           // size of the code
1241     mdSignature   LocalVarSigTok;     // token that indicates the signature of the local vars (0 means none)
1242
1243 } IMAGE_COR_ILMETHOD_FAT;
1244
1245 // an IMAGE_COR_ILMETHOD holds the IL instructions for a individual method.  To save space they come in two
1246 // flavors Fat and Tiny.  Conceptually Tiny is just a compressed version of Fat, so code:IMAGE_COR_ILMETHOD_FAT
1247 // is the logical structure for all headers.  Conceptually this blob holds the IL, the Exception Handling
1248 // Tables, the local variable information and some flags.  
1249 typedef union IMAGE_COR_ILMETHOD
1250 {
1251     IMAGE_COR_ILMETHOD_TINY       Tiny;
1252     IMAGE_COR_ILMETHOD_FAT        Fat;
1253 } IMAGE_COR_ILMETHOD;
1254
1255 //*****************************************************************************
1256 // Non VOS v-table entries.  Define an array of these pointed to by
1257 // IMAGE_COR20_HEADER.VTableFixups.  Each entry describes a contiguous array of
1258 // v-table slots.  The slots start out initialized to the meta data token value
1259 // for the method they need to call.  At image load time, the CLR Loader will
1260 // turn each entry into a pointer to machine code for the CPU and can be
1261 // called directly.
1262 //*****************************************************************************
1263
1264 typedef struct IMAGE_COR_VTABLEFIXUP
1265 {
1266     ULONG       RVA;                    // Offset of v-table array in image.
1267     USHORT      Count;                  // How many entries at location.
1268     USHORT      Type;                   // COR_VTABLE_xxx type of entries.
1269 } IMAGE_COR_VTABLEFIXUP;
1270
1271
1272
1273
1274
1275 //*****************************************************************************
1276 //*****************************************************************************
1277 //
1278 // M E T A - D A T A    D E C L A R A T I O N S
1279 //
1280 //*****************************************************************************
1281 //*****************************************************************************
1282
1283 //*****************************************************************************
1284 //
1285 // Enums for SetOption API.
1286 //
1287 //*****************************************************************************
1288
1289 // flags for MetaDataCheckDuplicatesFor
1290 typedef enum CorCheckDuplicatesFor
1291 {
1292     MDDupAll                    = 0xffffffff,
1293     MDDupENC                    = MDDupAll,
1294     MDNoDupChecks               = 0x00000000,
1295     MDDupTypeDef                = 0x00000001,
1296     MDDupInterfaceImpl          = 0x00000002,
1297     MDDupMethodDef              = 0x00000004,
1298     MDDupTypeRef                = 0x00000008,
1299     MDDupMemberRef              = 0x00000010,
1300     MDDupCustomAttribute        = 0x00000020,
1301     MDDupParamDef               = 0x00000040,
1302     MDDupPermission             = 0x00000080,
1303     MDDupProperty               = 0x00000100,
1304     MDDupEvent                  = 0x00000200,
1305     MDDupFieldDef               = 0x00000400,
1306     MDDupSignature              = 0x00000800,
1307     MDDupModuleRef              = 0x00001000,
1308     MDDupTypeSpec               = 0x00002000,
1309     MDDupImplMap                = 0x00004000,
1310     MDDupAssemblyRef            = 0x00008000,
1311     MDDupFile                   = 0x00010000,
1312     MDDupExportedType           = 0x00020000,
1313     MDDupManifestResource       = 0x00040000,
1314     MDDupGenericParam           = 0x00080000,
1315     MDDupMethodSpec             = 0x00100000,
1316     MDDupGenericParamConstraint = 0x00200000,
1317     // gap for debug junk
1318     MDDupAssembly               = 0x10000000,
1319
1320     // This is the default behavior on metadata. It will check duplicates for TypeRef, MemberRef, Signature, TypeSpec and MethodSpec.
1321     MDDupDefault = MDNoDupChecks | MDDupTypeRef | MDDupMemberRef | MDDupSignature | MDDupTypeSpec | MDDupMethodSpec,
1322 } CorCheckDuplicatesFor;
1323
1324 // flags for MetaDataRefToDefCheck
1325 typedef enum CorRefToDefCheck
1326 {
1327     // default behavior is to always perform TypeRef to TypeDef and MemberRef to MethodDef/FieldDef optimization
1328     MDRefToDefDefault           = 0x00000003,
1329     MDRefToDefAll               = 0xffffffff,
1330     MDRefToDefNone              = 0x00000000,
1331     MDTypeRefToDef              = 0x00000001,
1332     MDMemberRefToDef            = 0x00000002
1333 } CorRefToDefCheck;
1334
1335
1336 // MetaDataNotificationForTokenMovement
1337 typedef enum CorNotificationForTokenMovement
1338 {
1339     // default behavior is to notify TypeRef, MethodDef, MemberRef, and FieldDef token remaps
1340     MDNotifyDefault             = 0x0000000f,
1341     MDNotifyAll                 = 0xffffffff,
1342     MDNotifyNone                = 0x00000000,
1343     MDNotifyMethodDef           = 0x00000001,
1344     MDNotifyMemberRef           = 0x00000002,
1345     MDNotifyFieldDef            = 0x00000004,
1346     MDNotifyTypeRef             = 0x00000008,
1347
1348     MDNotifyTypeDef             = 0x00000010,
1349     MDNotifyParamDef            = 0x00000020,
1350     MDNotifyInterfaceImpl       = 0x00000040,
1351     MDNotifyProperty            = 0x00000080,
1352     MDNotifyEvent               = 0x00000100,
1353     MDNotifySignature           = 0x00000200,
1354     MDNotifyTypeSpec            = 0x00000400,
1355     MDNotifyCustomAttribute     = 0x00000800,
1356     MDNotifySecurityValue       = 0x00001000,
1357     MDNotifyPermission          = 0x00002000,
1358     MDNotifyModuleRef           = 0x00004000,
1359
1360     MDNotifyNameSpace           = 0x00008000,
1361
1362     MDNotifyAssemblyRef         = 0x01000000,
1363     MDNotifyFile                = 0x02000000,
1364     MDNotifyExportedType        = 0x04000000,
1365     MDNotifyResource            = 0x08000000,
1366 } CorNotificationForTokenMovement;
1367
1368
1369 typedef enum CorSetENC
1370 {
1371     MDSetENCOn                  = 0x00000001,   // Deprecated name.
1372     MDSetENCOff                 = 0x00000002,   // Deprecated name.
1373
1374     MDUpdateENC                 = 0x00000001,   // ENC mode.  Tokens don't move; can be updated.
1375     MDUpdateFull                = 0x00000002,   // "Normal" update mode.
1376     MDUpdateExtension           = 0x00000003,   // Extension mode.  Tokens don't move, adds only.
1377     MDUpdateIncremental         = 0x00000004,   // Incremental compilation
1378     MDUpdateDelta               = 0x00000005,   // If ENC on, save only deltas.
1379     MDUpdateMask                = 0x00000007,
1380
1381
1382 } CorSetENC;
1383
1384 #define IsENCDelta(x)                       (((x) & MDUpdateMask) == MDUpdateDelta)
1385
1386 // flags used in SetOption when pair with MetaDataErrorIfEmitOutOfOrder guid
1387 typedef enum CorErrorIfEmitOutOfOrder
1388 {
1389     MDErrorOutOfOrderDefault    = 0x00000000,   // default not to generate any error
1390     MDErrorOutOfOrderNone       = 0x00000000,   // do not generate error for out of order emit
1391     MDErrorOutOfOrderAll        = 0xffffffff,   // generate out of order emit for method, field, param, property, and event
1392     MDMethodOutOfOrder          = 0x00000001,   // generate error when methods are emitted out of order
1393     MDFieldOutOfOrder           = 0x00000002,   // generate error when fields are emitted out of order
1394     MDParamOutOfOrder           = 0x00000004,   // generate error when params are emitted out of order
1395     MDPropertyOutOfOrder        = 0x00000008,   // generate error when properties are emitted out of order
1396     MDEventOutOfOrder           = 0x00000010,   // generate error when events are emitted out of order
1397 } CorErrorIfEmitOutOfOrder;
1398
1399
1400 // flags used in SetOption when pair with MetaDataImportOption guid
1401 typedef enum CorImportOptions
1402 {
1403     MDImportOptionDefault       = 0x00000000,   // default to skip over deleted records
1404     MDImportOptionAll           = 0xFFFFFFFF,   // Enumerate everything
1405     MDImportOptionAllTypeDefs   = 0x00000001,   // all of the typedefs including the deleted typedef
1406     MDImportOptionAllMethodDefs = 0x00000002,   // all of the methoddefs including the deleted ones
1407     MDImportOptionAllFieldDefs  = 0x00000004,   // all of the fielddefs including the deleted ones
1408     MDImportOptionAllProperties = 0x00000008,   // all of the properties including the deleted ones
1409     MDImportOptionAllEvents     = 0x00000010,   // all of the events including the deleted ones
1410     MDImportOptionAllCustomAttributes = 0x00000020, // all of the custom attributes including the deleted ones
1411     MDImportOptionAllExportedTypes  = 0x00000040,   // all of the ExportedTypes including the deleted ones
1412
1413 } CorImportOptions;
1414
1415
1416 // flags for MetaDataThreadSafetyOptions
1417 typedef enum CorThreadSafetyOptions
1418 {
1419     // default behavior is to have thread safety turn off. This means that MetaData APIs will not take reader/writer
1420     // lock. Clients is responsible to make sure the properly thread synchornization when using MetaData APIs.
1421     MDThreadSafetyDefault       = 0x00000000,
1422     MDThreadSafetyOff           = 0x00000000,
1423     MDThreadSafetyOn            = 0x00000001,
1424 } CorThreadSafetyOptions;
1425
1426
1427 // flags for MetaDataLinkerOptions
1428 typedef enum CorLinkerOptions
1429 {
1430     // default behavior is not to keep private types
1431     MDAssembly          = 0x00000000,
1432     MDNetModule         = 0x00000001,
1433 } CorLinkerOptions;
1434
1435 // flags for MetaDataMergeOptions
1436 typedef enum MergeFlags
1437 {
1438     MergeFlagsNone      =   0,
1439     MergeManifest       =   0x00000001,     
1440     DropMemberRefCAs    =   0x00000002,
1441     NoDupCheck          =   0x00000004,
1442     MergeExportedTypes  =   0x00000008
1443 } MergeFlags;
1444
1445 // flags for MetaDataPreserveLocalRefs
1446 typedef enum CorLocalRefPreservation
1447 {
1448     MDPreserveLocalRefsNone     = 0x00000000,
1449     MDPreserveLocalTypeRef      = 0x00000001,
1450     MDPreserveLocalMemberRef    = 0x00000002
1451 } CorLocalRefPreservation;
1452
1453 //
1454 // struct used to retrieve field offset
1455 // used by GetClassLayout and SetClassLayout
1456 //
1457
1458 #ifndef _COR_FIELD_OFFSET_
1459 #define _COR_FIELD_OFFSET_
1460
1461 typedef struct COR_FIELD_OFFSET
1462 {
1463     mdFieldDef  ridOfField;
1464     ULONG       ulOffset;
1465 } COR_FIELD_OFFSET;
1466
1467 #endif
1468
1469
1470 //
1471 // Token tags.
1472 //
1473 typedef enum CorTokenType
1474 {
1475     mdtModule               = 0x00000000,       //
1476     mdtTypeRef              = 0x01000000,       //
1477     mdtTypeDef              = 0x02000000,       //
1478     mdtFieldDef             = 0x04000000,       //
1479     mdtMethodDef            = 0x06000000,       //
1480     mdtParamDef             = 0x08000000,       //
1481     mdtInterfaceImpl        = 0x09000000,       //
1482     mdtMemberRef            = 0x0a000000,       //
1483     mdtCustomAttribute      = 0x0c000000,       //
1484     mdtPermission           = 0x0e000000,       //
1485     mdtSignature            = 0x11000000,       //
1486     mdtEvent                = 0x14000000,       //
1487     mdtProperty             = 0x17000000,       //
1488     mdtMethodImpl           = 0x19000000,       //
1489     mdtModuleRef            = 0x1a000000,       //
1490     mdtTypeSpec             = 0x1b000000,       //
1491     mdtAssembly             = 0x20000000,       //
1492     mdtAssemblyRef          = 0x23000000,       //
1493     mdtFile                 = 0x26000000,       //
1494     mdtExportedType         = 0x27000000,       //
1495     mdtManifestResource     = 0x28000000,       //
1496     mdtGenericParam         = 0x2a000000,       //
1497     mdtMethodSpec           = 0x2b000000,       //
1498     mdtGenericParamConstraint = 0x2c000000,
1499
1500     mdtString               = 0x70000000,       //
1501     mdtName                 = 0x71000000,       //
1502     mdtBaseType             = 0x72000000,       // Leave this on the high end value. This does not correspond to metadata table
1503 } CorTokenType;
1504
1505 //
1506 // Build / decompose tokens.
1507 //
1508 #define RidToToken(rid,tktype) ((rid) |= (tktype))
1509 #define TokenFromRid(rid,tktype) ((rid) | (tktype))
1510 #define RidFromToken(tk) ((RID) ((tk) & 0x00ffffff))
1511 #define TypeFromToken(tk) ((ULONG32)((tk) & 0xff000000))
1512 #define IsNilToken(tk) ((RidFromToken(tk)) == 0)
1513
1514 //
1515 // Nil tokens
1516 //
1517 #define mdTokenNil                  ((mdToken)0)
1518 #define mdModuleNil                 ((mdModule)mdtModule)
1519 #define mdTypeRefNil                ((mdTypeRef)mdtTypeRef)
1520 #define mdTypeDefNil                ((mdTypeDef)mdtTypeDef)
1521 #define mdFieldDefNil               ((mdFieldDef)mdtFieldDef)
1522 #define mdMethodDefNil              ((mdMethodDef)mdtMethodDef)
1523 #define mdParamDefNil               ((mdParamDef)mdtParamDef)
1524 #define mdInterfaceImplNil          ((mdInterfaceImpl)mdtInterfaceImpl)
1525 #define mdMemberRefNil              ((mdMemberRef)mdtMemberRef)
1526 #define mdCustomAttributeNil        ((mdCustomAttribute)mdtCustomAttribute)
1527 #define mdPermissionNil             ((mdPermission)mdtPermission)
1528 #define mdSignatureNil              ((mdSignature)mdtSignature)
1529 #define mdEventNil                  ((mdEvent)mdtEvent)
1530 #define mdPropertyNil               ((mdProperty)mdtProperty)
1531 #define mdModuleRefNil              ((mdModuleRef)mdtModuleRef)
1532 #define mdTypeSpecNil               ((mdTypeSpec)mdtTypeSpec)
1533 #define mdAssemblyNil               ((mdAssembly)mdtAssembly)
1534 #define mdAssemblyRefNil            ((mdAssemblyRef)mdtAssemblyRef)
1535 #define mdFileNil                   ((mdFile)mdtFile)
1536 #define mdExportedTypeNil           ((mdExportedType)mdtExportedType)
1537 #define mdManifestResourceNil       ((mdManifestResource)mdtManifestResource)
1538
1539 #define mdGenericParamNil           ((mdGenericParam)mdtGenericParam)
1540 #define mdGenericParamConstraintNil ((mdGenericParamConstraint)mdtGenericParamConstraint)
1541 #define mdMethodSpecNil             ((mdMethodSpec)mdtMethodSpec)
1542
1543 #define mdStringNil                 ((mdString)mdtString)
1544
1545 //
1546 // Open bits.
1547 //
1548 typedef enum CorOpenFlags
1549 {
1550     ofRead              =   0x00000000,     // Open scope for read
1551     ofWrite             =   0x00000001,     // Open scope for write.
1552     ofReadWriteMask     =   0x00000001,     // Mask for read/write bit.
1553
1554     ofCopyMemory        =   0x00000002,     // Open scope with memory. Ask metadata to maintain its own copy of memory.
1555
1556     ofReadOnly          =   0x00000010,     // Open scope for read. Will be unable to QI for a IMetadataEmit* interface
1557     ofTakeOwnership     =   0x00000020,     // The memory was allocated with CoTaskMemAlloc and will be freed by the metadata
1558         
1559     // These are obsolete and are ignored.
1560     // ofCacheImage     =   0x00000004,     // EE maps but does not do relocations or verify image
1561     // ofManifestMetadata = 0x00000008,     // Open scope on ngen image, return the manifest metadata instead of the IL metadata
1562     ofNoTypeLib         =   0x00000080,     // Don't OpenScope on a typelib.
1563     ofNoTransform       =   0x00001000,     // Disable automatic transforms of .winmd files.
1564
1565     // Internal bits
1566     ofReserved1         =   0x00000100,     // Reserved for internal use.
1567     ofReserved2         =   0x00000200,     // Reserved for internal use.
1568     ofReserved3         =   0x00000400,     // Reserved for internal use.
1569     ofReserved          =   0xffffef40      // All the reserved bits.
1570
1571 } CorOpenFlags;
1572
1573 #define IsOfRead(x)                         (((x) & ofReadWriteMask) == ofRead)
1574 #define IsOfReadWrite(x)                    (((x) & ofReadWriteMask) == ofWrite)
1575
1576 #define IsOfCopyMemory(x)                   ((x) & ofCopyMemory)
1577
1578 #define IsOfReadOnly(x)                     ((x) & ofReadOnly)
1579 #define IsOfTakeOwnership(x)                ((x) & ofTakeOwnership)
1580
1581 #define IsOfReserved(x)                     (((x) & ofReserved) != 0)
1582
1583 // 
1584 // Type of file mapping returned by code:IMetaDataInfo::GetFileMapping.
1585 // 
1586 typedef enum CorFileMapping
1587 {
1588     fmFlat            = 0,  // Flat file mapping - file is mapped as data file (code:SEC_IMAGE flag was not 
1589                             // passed to code:CreateFileMapping).
1590     fmExecutableImage = 1,  // Executable image file mapping - file is mapped for execution 
1591                             // (either via code:LoadLibrary or code:CreateFileMapping with code:SEC_IMAGE flag).
1592 } CorFileMapping;
1593
1594
1595 typedef CorTypeAttr CorRegTypeAttr;
1596
1597 //
1598 // Opaque type for an enumeration handle.
1599 //
1600 typedef void *HCORENUM;
1601
1602
1603 // Note that this must be kept in sync with System.AttributeTargets.
1604 typedef enum CorAttributeTargets
1605 {
1606     catAssembly      = 0x0001,
1607     catModule        = 0x0002,
1608     catClass         = 0x0004,
1609     catStruct        = 0x0008,
1610     catEnum          = 0x0010,
1611     catConstructor   = 0x0020,
1612     catMethod        = 0x0040,
1613     catProperty      = 0x0080,
1614     catField         = 0x0100,
1615     catEvent         = 0x0200,
1616     catInterface     = 0x0400,
1617     catParameter     = 0x0800,
1618     catDelegate      = 0x1000,
1619     catGenericParameter = 0x4000,
1620
1621     catAll           = catAssembly | catModule | catClass | catStruct | catEnum | catConstructor |
1622                     catMethod | catProperty | catField | catEvent | catInterface | catParameter | catDelegate | catGenericParameter,
1623     catClassMembers  = catClass | catStruct | catEnum | catConstructor | catMethod | catProperty | catField | catEvent | catDelegate | catInterface,
1624
1625 } CorAttributeTargets;
1626
1627 #ifndef MACROS_NOT_SUPPORTED
1628 //
1629 // Some well-known custom attributes
1630 //
1631 #ifndef IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS
1632   #define IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS (IMAGE_CEE_CS_CALLCONV_DEFAULT | IMAGE_CEE_CS_CALLCONV_HASTHIS)
1633 #endif
1634
1635 #define INTEROP_DISPID_TYPE_W                   L"System.Runtime.InteropServices.DispIdAttribute"
1636 #define INTEROP_DISPID_TYPE                     "System.Runtime.InteropServices.DispIdAttribute"
1637 #define INTEROP_DISPID_SIG                      {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I4}
1638
1639 #define INTEROP_INTERFACETYPE_TYPE_W            L"System.Runtime.InteropServices.InterfaceTypeAttribute"
1640 #define INTEROP_INTERFACETYPE_TYPE              "System.Runtime.InteropServices.InterfaceTypeAttribute"
1641 #define INTEROP_INTERFACETYPE_SIG               {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1642
1643 #define INTEROP_CLASSINTERFACE_TYPE_W           L"System.Runtime.InteropServices.ClassInterfaceAttribute"
1644 #define INTEROP_CLASSINTERFACE_TYPE             "System.Runtime.InteropServices.ClassInterfaceAttribute"
1645 #define INTEROP_CLASSINTERFACE_SIG              {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1646
1647 #define INTEROP_COMVISIBLE_TYPE_W               L"System.Runtime.InteropServices.ComVisibleAttribute"
1648 #define INTEROP_COMVISIBLE_TYPE                 "System.Runtime.InteropServices.ComVisibleAttribute"
1649 #define INTEROP_COMVISIBLE_SIG                  {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_BOOLEAN}
1650
1651 #define INTEROP_COMREGISTERFUNCTION_TYPE_W      L"System.Runtime.InteropServices.ComRegisterFunctionAttribute"
1652 #define INTEROP_COMREGISTERFUNCTION_TYPE        "System.Runtime.InteropServices.ComRegisterFunctionAttribute"
1653 #define INTEROP_COMREGISTERFUNCTION_SIG         {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1654
1655 #define INTEROP_COMUNREGISTERFUNCTION_TYPE_W    L"System.Runtime.InteropServices.ComUnregisterFunctionAttribute"
1656 #define INTEROP_COMUNREGISTERFUNCTION_TYPE      "System.Runtime.InteropServices.ComUnregisterFunctionAttribute"
1657 #define INTEROP_COMUNREGISTERFUNCTION_SIG       {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1658
1659 #define INTEROP_IMPORTEDFROMTYPELIB_TYPE_W      L"System.Runtime.InteropServices.ImportedFromTypeLibAttribute"
1660 #define INTEROP_IMPORTEDFROMTYPELIB_TYPE        "System.Runtime.InteropServices.ImportedFromTypeLibAttribute"
1661 #define INTEROP_IMPORTEDFROMTYPELIB_SIG         {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1662
1663 #define INTEROP_PRIMARYINTEROPASSEMBLY_TYPE_W   L"System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute"
1664 #define INTEROP_PRIMARYINTEROPASSEMBLY_TYPE     "System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute"
1665 #define INTEROP_PRIMARYINTEROPASSEMBLY_SIG      {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 2, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I4, ELEMENT_TYPE_I4}
1666
1667 #define INTEROP_IDISPATCHIMPL_TYPE_W            L"System.Runtime.InteropServices.IDispatchImplAttribute"
1668 #define INTEROP_IDISPATCHIMPL_TYPE              "System.Runtime.InteropServices.IDispatchImplAttribute"
1669 #define INTEROP_IDISPATCHIMPL_SIG               {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1670
1671 #define INTEROP_COMSOURCEINTERFACES_TYPE_W      L"System.Runtime.InteropServices.ComSourceInterfacesAttribute"
1672 #define INTEROP_COMSOURCEINTERFACES_TYPE        "System.Runtime.InteropServices.ComSourceInterfacesAttribute"
1673 #define INTEROP_COMSOURCEINTERFACES_SIG         {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1674
1675 #define INTEROP_COMDEFAULTINTERFACE_TYPE_W      L"System.Runtime.InteropServices.ComDefaultInterfaceAttribute"
1676 #define INTEROP_COMDEFAULTINTERFACE_TYPE        "System.Runtime.InteropServices.ComDefaultInterfaceAttribute"
1677
1678 #define INTEROP_COMCONVERSIONLOSS_TYPE_W        L"System.Runtime.InteropServices.ComConversionLossAttribute"
1679 #define INTEROP_COMCONVERSIONLOSS_TYPE          "System.Runtime.InteropServices.ComConversionLossAttribute"
1680 #define INTEROP_COMCONVERSIONLOSS_SIG           {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1681
1682 #define INTEROP_BESTFITMAPPING_TYPE_W           L"System.Runtime.InteropServices.BestFitMappingAttribute"
1683 #define INTEROP_BESTFITMAPPING_TYPE             "System.Runtime.InteropServices.BestFitMappingAttribute"
1684 #define INTEROP_BESTFITMAPPING_SIG              {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 2, ELEMENT_TYPE_VOID, ELEMENT_TYPE_BOOLEAN, ELEMENT_TYPE_BOOLEAN}
1685
1686 #define INTEROP_TYPELIBTYPE_TYPE_W              L"System.Runtime.InteropServices.TypeLibTypeAttribute"
1687 #define INTEROP_TYPELIBTYPE_TYPE                "System.Runtime.InteropServices.TypeLibTypeAttribute"
1688 #define INTEROP_TYPELIBTYPE_SIG                 {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1689
1690 #define INTEROP_TYPELIBFUNC_TYPE_W              L"System.Runtime.InteropServices.TypeLibFuncAttribute"
1691 #define INTEROP_TYPELIBFUNC_TYPE                "System.Runtime.InteropServices.TypeLibFuncAttribute"
1692 #define INTEROP_TYPELIBFUNC_SIG                 {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1693
1694 #define INTEROP_TYPELIBVAR_TYPE_W               L"System.Runtime.InteropServices.TypeLibVarAttribute"
1695 #define INTEROP_TYPELIBVAR_TYPE                 "System.Runtime.InteropServices.TypeLibVarAttribute"
1696 #define INTEROP_TYPELIBVAR_SIG                  {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1697
1698 #define INTEROP_MARSHALAS_TYPE_W                L"System.Runtime.InteropServices.MarshalAsAttribute"
1699 #define INTEROP_MARSHALAS_TYPE                  "System.Runtime.InteropServices.MarshalAsAttribute"
1700 #define INTEROP_MARSHALAS_SIG                   {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2}
1701
1702 #define INTEROP_COMIMPORT_TYPE_W                L"System.Runtime.InteropServices.ComImportAttribute"
1703 #define INTEROP_COMIMPORT_TYPE                  "System.Runtime.InteropServices.ComImportAttribute"
1704 #define INTEROP_COMIMPORT_SIG                   {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1705
1706 #define INTEROP_GUID_TYPE_W                     W("System.Runtime.InteropServices.GuidAttribute")
1707 #define INTEROP_GUID_TYPE                       "System.Runtime.InteropServices.GuidAttribute"
1708 #define INTEROP_GUID_SIG                        {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1709
1710 #define INTEROP_DEFAULTMEMBER_TYPE_W            L"System.Reflection.DefaultMemberAttribute"
1711 #define INTEROP_DEFAULTMEMBER_TYPE              "System.Reflection.DefaultMemberAttribute"
1712 #define INTEROP_DEFAULTMEMBER_SIG               {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1713
1714 #define INTEROP_COMEMULATE_TYPE_W               L"System.Runtime.InteropServices.ComEmulateAttribute"
1715 #define INTEROP_COMEMULATE_TYPE                 "System.Runtime.InteropServices.ComEmulateAttribute"
1716 #define INTEROP_COMEMULATE_SIG                  {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1717
1718 #define INTEROP_PRESERVESIG_TYPE_W              L"System.Runtime.InteropServices.PreserveSigAttribure"
1719 #define INTEROP_PRESERVESIG_TYPE                "System.Runtime.InteropServices.PreserveSigAttribure"
1720 #define INTEROP_PRESERVESIG_SIG                 {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_BOOLEAN}
1721
1722 #define INTEROP_IN_TYPE_W                       L"System.Runtime.InteropServices.InAttribute"
1723 #define INTEROP_IN_TYPE                         "System.Runtime.InteropServices.InAttribute"
1724 #define INTEROP_IN_SIG                          {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1725
1726 #define INTEROP_OUT_TYPE_W                      L"System.Runtime.InteropServices.OutAttribute"
1727 #define INTEROP_OUT_TYPE                        "System.Runtime.InteropServices.OutAttribute"
1728 #define INTEROP_OUT_SIG                         {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1729
1730 #define INTEROP_COMALIASNAME_TYPE_W             L"System.Runtime.InteropServices.ComAliasNameAttribute"
1731 #define INTEROP_COMALIASNAME_TYPE               "System.Runtime.InteropServices.ComAliasNameAttribute"
1732 #define INTEROP_COMALIASNAME_SIG                {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1733
1734 #define INTEROP_PARAMARRAY_TYPE_W               L"System.ParamArrayAttribute"
1735 #define INTEROP_PARAMARRAY_TYPE                 "System.ParamArrayAttribute"
1736 #define INTEROP_PARAMARRAY_SIG                  {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1737
1738 #define INTEROP_LCIDCONVERSION_TYPE_W           L"System.Runtime.InteropServices.LCIDConversionAttribute"
1739 #define INTEROP_LCIDCONVERSION_TYPE             "System.Runtime.InteropServices.LCIDConversionAttribute"
1740 #define INTEROP_LCIDCONVERSION_SIG              {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I4}
1741
1742 #define INTEROP_COMSUBSTITUTABLEINTERFACE_TYPE_W    L"System.Runtime.InteropServices.ComSubstitutableInterfaceAttribute"
1743 #define INTEROP_COMSUBSTITUTABLEINTERFACE_TYPE      "System.Runtime.InteropServices.ComSubstitutableInterfaceAttribute"
1744 #define INTEROP_COMSUBSTITUTABLEINTERFACE_SIG       {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1745
1746 #define INTEROP_DECIMALVALUE_TYPE_W             L"System.Runtime.CompilerServices.DecimalConstantAttribute"
1747 #define INTEROP_DECIMALVALUE_TYPE               "System.Runtime.CompilerServices.DecimalConstantAttribute"
1748 #define INTEROP_DECIMALVALUE_SIG                {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 5, ELEMENT_TYPE_VOID, ELEMENT_TYPE_U1, ELEMENT_TYPE_U1, ELEMENT_TYPE_U4, ELEMENT_TYPE_U4, ELEMENT_TYPE_U4}
1749
1750 #define INTEROP_DATETIMEVALUE_TYPE_W            L"System.Runtime.CompilerServices.DateTimeConstantAttribute"
1751 #define INTEROP_DATETIMEVALUE_TYPE              "System.Runtime.CompilerServices.DateTimeConstantAttribute"
1752 #define INTEROP_DATETIMEVALUE_SIG               {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I8}
1753
1754 #define INTEROP_IUNKNOWNVALUE_TYPE_W            L"System.Runtime.CompilerServices.IUnknownConstantAttribute"
1755 #define INTEROP_IUNKNOWNVALUE_TYPE               "System.Runtime.CompilerServices.IUnknownConstantAttribute"
1756 #define INTEROP_IUNKNOWNVALUE_SIG               {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1757
1758 #define INTEROP_IDISPATCHVALUE_TYPE_W           L"System.Runtime.CompilerServices.IDispatchConstantAttribute"
1759 #define INTEROP_IDISPATCHVALUE_TYPE              "System.Runtime.CompilerServices.IDispatchConstantAttribute"
1760 #define INTEROP_IDISPATCHVALUE_SIG              {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1761
1762 #define INTEROP_AUTOPROXY_TYPE_W                L"System.Runtime.InteropServices.AutomationProxyAttribute"
1763 #define INTEROP_AUTOPROXY_TYPE                  "System.Runtime.InteropServices.AutomationProxyAttribute"
1764 #define INTEROP_AUTOPROXY_SIG                   {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_BOOLEAN}
1765
1766 #define INTEROP_TYPELIBIMPORTCLASS_TYPE_W       L"System.Runtime.InteropServices.TypeLibImportClassAttribute"
1767 #define INTEROP_TYPELIBIMPORTCLASS_TYPE         "System.Runtime.InteropServices.TypeLibImportClassAttribute"
1768
1769
1770 #define INTEROP_TYPELIBVERSION_TYPE_W           L"System.Runtime.InteropServices.TypeLibVersionAttribute"
1771 #define INTEROP_TYPELIBVERSION_TYPE             "System.Runtime.InteropServices.TypeLibVersionAttribute"
1772 #define INTEROP_TYPELIBVERSION_SIG              {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 2, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2, ELEMENT_TYPE_I2}
1773
1774 #define INTEROP_COMCOMPATIBLEVERSION_TYPE_W     L"System.Runtime.InteropServices.ComCompatibleVersionAttribute"
1775 #define INTEROP_COMCOMPATIBLEVERSION_TYPE       "System.Runtime.InteropServices.ComCompatibleVersionAttribute"
1776 #define INTEROP_COMCOMPATIBLEVERSION_SIG        {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 4, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I2, ELEMENT_TYPE_I2, ELEMENT_TYPE_I2, ELEMENT_TYPE_I2}
1777
1778 #define INTEROP_COMEVENTINTERFACE_TYPE_W        L"System.Runtime.InteropServices.ComEventInterfaceAttribute"
1779 #define INTEROP_COMEVENTINTERFACE_TYPE          "System.Runtime.InteropServices.ComEventInterfaceAttribute"
1780
1781 #define INTEROP_COCLASS_TYPE_W                  L"System.Runtime.InteropServices.CoClassAttribute"
1782 #define INTEROP_COCLASS_TYPE                    "System.Runtime.InteropServices.CoClassAttribute"
1783
1784 #define INTEROP_SERIALIZABLE_TYPE_W             L"System.SerializableAttribute"
1785 #define INTEROP_SERIALIZABLE_TYPE               "System.SerializableAttribute"
1786 #define INTEROP_SERIALIZABLE_SIG                {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1787
1788 #define INTEROP_SETWIN32CONTEXTINIDISPATCHATTRIBUTE_TYPE_W  L"System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute"
1789 #define INTEROP_SETWIN32CONTEXTINIDISPATCHATTRIBUTE_TYPE     "System.Runtime.InteropServices.SetWin32ContextInIDispatchAttribute"
1790 #define INTEROP_SETWIN32CONTEXTINIDISPATCHATTRIBUTE_SIG     {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1791
1792 #define FORWARD_INTEROP_STUB_METHOD_TYPE_W      L"System.Runtime.InteropServices.ManagedToNativeComInteropStubAttribute"
1793 #define FORWARD_INTEROP_STUB_METHOD_TYPE        "System.Runtime.InteropServices.ManagedToNativeComInteropStubAttribute"
1794
1795 #define FRIEND_ASSEMBLY_TYPE_W                  L"System.Runtime.CompilerServices.InternalsVisibleToAttribute"
1796 #define FRIEND_ASSEMBLY_TYPE                     "System.Runtime.CompilerServices.InternalsVisibleToAttribute"
1797 #define FRIEND_ASSEMBLY_SIG                     {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 2, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING, ELEMENT_TYPE_BOOLEAN}
1798
1799 #define SUBJECT_ASSEMBLY_TYPE_W                 L"System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"
1800 #define SUBJECT_ASSEMBLY_TYPE                    "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"
1801 #define SUBJECT_ASSEMBLY_SIG                    {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_STRING}
1802
1803 #define DISABLED_PRIVATE_REFLECTION_TYPE_W      L"System.Runtime.CompilerServices.DisablePrivateReflectionAttribute"
1804 #define DISABLED_PRIVATE_REFLECTION_TYPE         "System.Runtime.CompilerServices.DisablePrivateReflectionAttribute"
1805 #define DISABLED_PRIVATE_REFLECTION_SIG         {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1806
1807 #define DEFAULTDOMAIN_STA_TYPE_W                L"System.STAThreadAttribute"
1808 #define DEFAULTDOMAIN_STA_TYPE                   "System.STAThreadAttribute"
1809 #define DEFAULTDOMAIN_STA_SIG                   {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1810
1811 #define DEFAULTDOMAIN_MTA_TYPE_W                L"System.MTAThreadAttribute"
1812 #define DEFAULTDOMAIN_MTA_TYPE                   "System.MTAThreadAttribute"
1813 #define DEFAULTDOMAIN_MTA_SIG                   {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 0, ELEMENT_TYPE_VOID}
1814
1815 #define DEFAULTDOMAIN_LOADEROPTIMIZATION_TYPE_W L"System.LoaderOptimizationAttribute"
1816 #define DEFAULTDOMAIN_LOADEROPTIMIZATION_TYPE    "System.LoaderOptimizationAttribute"
1817 #define DEFAULTDOMAIN_LOADEROPTIMIZATION_SIG    {IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS, 1, ELEMENT_TYPE_VOID, ELEMENT_TYPE_I1}
1818
1819 #define NONVERSIONABLE_TYPE_W                   L"System.Runtime.Versioning.NonVersionableAttribute"
1820 #define NONVERSIONABLE_TYPE                      "System.Runtime.Versioning.NonVersionableAttribute"
1821
1822 // Keep in sync with CompilationRelaxations.cs
1823 typedef enum CompilationRelaxationsEnum
1824 {
1825     CompilationRelaxations_NoStringInterning       = 0x0008,
1826         
1827 } CompilationRelaxationEnum;
1828
1829 #define COMPILATIONRELAXATIONS_TYPE_W           L"System.Runtime.CompilerServices.CompilationRelaxationsAttribute"
1830 #define COMPILATIONRELAXATIONS_TYPE             "System.Runtime.CompilerServices.CompilationRelaxationsAttribute"
1831
1832
1833 // Keep in sync with RuntimeCompatibilityAttribute.cs
1834 #define RUNTIMECOMPATIBILITY_TYPE_W             L"System.Runtime.CompilerServices.RuntimeCompatibilityAttribute"
1835 #define RUNTIMECOMPATIBILITY_TYPE               "System.Runtime.CompilerServices.RuntimeCompatibilityAttribute"
1836
1837
1838 // Keep in sync with AssemblySettingAttributes.cs
1839
1840 typedef enum NGenHintEnum
1841 {    
1842     NGenDefault             = 0x0000, // No preference specified
1843
1844     NGenEager               = 0x0001, // NGen at install time
1845     NGenLazy                = 0x0002, // NGen after install time
1846     NGenNever               = 0x0003  // Assembly should not be ngened      
1847 } NGenHintEnum;
1848
1849 typedef enum LoadHintEnum
1850 {
1851     LoadDefault             = 0x0000, // No preference specified
1852
1853     LoadAlways              = 0x0001, // Dependency is always loaded
1854     LoadSometimes           = 0x0002, // Dependency is sometimes loaded
1855     LoadNever               = 0x0003  // Dependency is never loaded
1856 } LoadHintEnum;
1857
1858 #define DEFAULTDEPENDENCY_TYPE_W                L"System.Runtime.CompilerServices.DefaultDependencyAttribute"
1859 #define DEFAULTDEPENDENCY_TYPE                  "System.Runtime.CompilerServices.DefaultDependencyAttribute"
1860
1861 #define DEPENDENCY_TYPE_W                       L"System.Runtime.CompilerServices.DependencyAttribute"
1862 #define DEPENDENCY_TYPE                         "System.Runtime.CompilerServices.DependencyAttribute"
1863
1864 #define TARGET_FRAMEWORK_TYPE_W                 L"System.Runtime.Versioning.TargetFrameworkAttribute"
1865 #define TARGET_FRAMEWORK_TYPE                   "System.Runtime.Versioning.TargetFrameworkAttribute"
1866
1867 #define ASSEMBLY_METADATA_TYPE_W                L"System.Reflection.AssemblyMetadataAttribute"
1868 #define ASSEMBLY_METADATA_TYPE                  "System.Reflection.AssemblyMetadataAttribute"
1869
1870
1871 #define CMOD_CALLCONV_NAMESPACE_OLD             "System.Runtime.InteropServices"
1872 #define CMOD_CALLCONV_NAMESPACE                 "System.Runtime.CompilerServices"
1873 #define CMOD_CALLCONV_NAME_CDECL                "CallConvCdecl"
1874 #define CMOD_CALLCONV_NAME_STDCALL              "CallConvStdcall"
1875 #define CMOD_CALLCONV_NAME_THISCALL             "CallConvThiscall"
1876 #define CMOD_CALLCONV_NAME_FASTCALL             "CallConvFastcall"
1877
1878 #endif // MACROS_NOT_SUPPORTED
1879
1880 //
1881 // GetSaveSize accuracy
1882 //
1883 #ifndef _CORSAVESIZE_DEFINED_
1884 #define _CORSAVESIZE_DEFINED_
1885 typedef enum CorSaveSize
1886 {
1887     cssAccurate             = 0x0000,               // Find exact save size, accurate but slower.
1888     cssQuick                = 0x0001,               // Estimate save size, may pad estimate, but faster.
1889     cssDiscardTransientCAs  = 0x0002,               // remove all of the CAs of discardable types
1890 } CorSaveSize;
1891 #endif
1892
1893 #define COR_IS_METHOD_MANAGED_IL(flags)         ((flags & 0xf) == (miIL | miManaged))
1894 #define COR_IS_METHOD_MANAGED_OPTIL(flags)      ((flags & 0xf) == (miOPTIL | miManaged))
1895 #define COR_IS_METHOD_MANAGED_NATIVE(flags)     ((flags & 0xf) == (miNative | miManaged))
1896 #define COR_IS_METHOD_UNMANAGED_NATIVE(flags)   ((flags & 0xf) == (miNative | miUnmanaged))
1897
1898 //
1899 // Enum used with NATIVE_TYPE_ARRAY.
1900 //
1901 typedef enum NativeTypeArrayFlags
1902 {
1903     ntaSizeParamIndexSpecified = 0x0001,
1904     ntaReserved                = 0xfffe      // All the reserved bits.
1905 } NativeTypeArrayFlags;
1906
1907 //
1908 // Opaque types for security properties and values.
1909 //
1910 typedef void  *  PSECURITY_PROPS ;
1911 typedef void  *  PSECURITY_VALUE ;
1912 typedef void ** PPSECURITY_PROPS ;
1913 typedef void ** PPSECURITY_VALUE ;
1914
1915 //-------------------------------------
1916 //--- Security data structures
1917 //-------------------------------------
1918
1919 // Descriptor for a single security custom attribute.
1920 typedef struct COR_SECATTR {
1921     mdMemberRef     tkCtor;         // Ref to constructor of security attribute.
1922     const void      *pCustomAttribute;  // Blob describing ctor args and field/property values.
1923     ULONG           cbCustomAttribute;  // Length of the above blob.
1924 } COR_SECATTR;
1925
1926 #endif // __CORHDR_H__
1927