PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/dna/MetaDataTables.h

https://bitbucket.org/cosi2/dotnetanywhere-wb
C Header | 563 lines | 299 code | 51 blank | 213 comment | 0 complexity | 57c5111bd61056b6fc86342d20c30bd2 MD5 | raw file
  1. // Copyright (c) 2009 DotNetAnywhere
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. #if !defined(__METADATATABLES_H)
  21. #define __METADATATABLES_H
  22. // Forward typedef's (anything used in MetaData.h must be here)
  23. typedef struct tMD_MethodDef_ tMD_MethodDef;
  24. typedef struct tMD_FieldDef_ tMD_FieldDef;
  25. typedef struct tMD_TypeDef_ tMD_TypeDef;
  26. typedef struct tMD_MethodSpec_ tMD_MethodSpec;
  27. typedef struct tMD_ImplMap_ tMD_ImplMap;
  28. #include "Types.h"
  29. #include "JIT.h"
  30. #include "MetaData.h"
  31. #include "Generics.h"
  32. // First, the combined tables
  33. typedef struct tMDC_ToFieldDef_ tMDC_ToFieldDef;
  34. struct tMDC_ToFieldDef_ {
  35. tMD_FieldDef *pFieldDef;
  36. };
  37. typedef struct tMDC_ToMethodDef_ tMDC_ToMethodDef;
  38. struct tMDC_ToMethodDef_ {
  39. tMD_MethodDef *pMethodDef;
  40. };
  41. typedef struct tMDC_ToTypeDef_ tMDC_ToTypeDef;
  42. struct tMDC_ToTypeDef_ {
  43. tMD_TypeDef *pTypeDef;
  44. };
  45. // Second, the raw metadata tables
  46. // Table 0x00 - Module
  47. struct tMD_Module_ {
  48. // Module name - index into string heap
  49. STRING name;
  50. // GUID for module version - index into GUID heap
  51. GUID_ mvID;
  52. };
  53. typedef struct tMD_Module_ tMD_Module;
  54. // Table 0x01 - TypeRef
  55. struct tMD_TypeRef_ {
  56. // Combined
  57. tMD_TypeDef *pTypeDef;
  58. // Table index into various tables
  59. IDX_TABLE resolutionScope;
  60. // Name of type ref - index into string heap
  61. STRING name;
  62. // Namespace of type ref - index into string heap
  63. STRING nameSpace;
  64. };
  65. typedef struct tMD_TypeRef_ tMD_TypeRef;
  66. #define MD_TABLE_TYPEREF 0x01
  67. // Table 0x02 - TypeDef
  68. struct tMD_TypeDef_ {
  69. // Combined
  70. tMD_TypeDef *pTypeDef;
  71. // MetaData pointer
  72. tMetaData *pMetaData;
  73. // Type attribute flags
  74. FLAGS32 flags;
  75. // Name of type def - index into string heap
  76. STRING name;
  77. // Namespace of type def - index into string heap
  78. STRING nameSpace;
  79. // The type that this type extends (inherits from)
  80. IDX_TABLE extends;
  81. // The first entry in the Field table of the fields of this type def
  82. IDX_TABLE fieldList;
  83. // The first entry in the Method table of the methods of this type def
  84. IDX_TABLE methodList;
  85. // Has this entry had its extended info filled?
  86. U8 isFilled;
  87. // Is this the last entry in this table?
  88. U8 isLast;
  89. // Is this a value type?
  90. U8 isValueType;
  91. // The type of evaluation stack entry needed for this type
  92. U8 stackType;
  93. // Total memory size of instances of this type (its in-memory representation) (not static fields)
  94. U32 instanceMemSize;
  95. // The parent type definition
  96. tMD_TypeDef *pParent;
  97. // The virtual method table
  98. tMD_MethodDef **pVTable;
  99. // The number of virtual methods in the vTable
  100. U32 numVirtualMethods;
  101. // Pointer to the memory for any static fields in this type. This will be NULL if type has no static fields
  102. PTR pStaticFields;
  103. // Has the static constructor been executed yet?
  104. U8 isTypeInitialised;
  105. // Is this a generic definition (a generic core type)?
  106. U8 isGenericDefinition;
  107. // Is this TypeDef primed - this means that:
  108. // numPrimedFields, numPrimedMethods, numVirtualMethods
  109. // have been pre-set.
  110. U8 isPrimed;
  111. // padding
  112. U8 padding0[1];
  113. // If this type has a static constructor, then store it here. NULL if no static constructor
  114. tMD_MethodDef *pStaticConstructor;
  115. // The size of this type when in an array
  116. U32 arrayElementSize;
  117. // The size of this type when on the stack (or in a field)
  118. U32 stackSize;
  119. // How many interfaces does this type implement
  120. U32 numInterfaces;
  121. // All interfaces that this type implements are mapped here
  122. tInterfaceMap *pInterfaceMaps;
  123. // The original table index of this TypeDef
  124. IDX_TABLE tableIndex;
  125. // If this is a generic type definition, then store any instantiatations here (in a linked list)
  126. tGenericInstance *pGenericInstances;
  127. // If this is a generic instance, then store link to its core definition type
  128. tMD_TypeDef *pGenericDefinition;
  129. // If this is a generic instance, then store the class type args
  130. tMD_TypeDef **ppClassTypeArgs;
  131. // If this type is System.Array, then this stores the element type
  132. tMD_TypeDef *pArrayElementType;
  133. // The number of fields in this type. This includes and static fields, but not inherited fields
  134. U32 numFields;
  135. // Links to all the fields (in memory order), including statics (not inherited)
  136. tMD_FieldDef **ppFields;
  137. // The memory needed for static fields, in bytes
  138. U32 staticFieldSize;
  139. // The number of methods in this type. This includes static methods, but not inherited methods
  140. U32 numMethods;
  141. // Links to all method in this type, including statics, not inherited
  142. tMD_MethodDef **ppMethods;
  143. // If this is a nested class, this records which type it is nested within.
  144. tMD_TypeDef *pNestedIn;
  145. // If this type has a finalizer, point to it here
  146. tMD_MethodDef *pFinalizer;
  147. // Pointer to the heap object which is the Type class object for this type.
  148. // This is only allocated as needed, so defaults to NULL
  149. HEAP_PTR typeObject;
  150. };
  151. #define MD_TABLE_TYPEDEF 0x02
  152. struct tMD_FieldDef_ {
  153. // Combined
  154. tMD_FieldDef *pFieldDef;
  155. // MetaData pointer
  156. tMetaData *pMetaData;
  157. // Flags - FieldAttributes
  158. FLAGS16 flags;
  159. // Padding dummy entry
  160. I16 padding0;
  161. // Name of the field
  162. STRING name;
  163. // Signature of the field
  164. BLOB_ signature;
  165. // The type of this field
  166. tMD_TypeDef *pType;
  167. // The type that contains this field
  168. tMD_TypeDef *pParentType;
  169. // The field offset within its containing type
  170. U32 memOffset;
  171. // The size in bytes that this field takes up in the memory representation
  172. U32 memSize;
  173. // The original table index of this FieldDef
  174. IDX_TABLE tableIndex;
  175. // If this is a static field, then the absolute address of this field is stored here.
  176. // If this field has an RVA, then the pointer to the memory location is stored here.
  177. // If this is a literal field, then this is a pointer to the tMD_Constant literal definition.
  178. PTR pMemory;
  179. };
  180. #define MD_TABLE_FIELDDEF 0x04
  181. // Table 0x06 - MethodDef
  182. struct tMD_MethodDef_ {
  183. // Combined
  184. tMD_MethodDef *pMethodDef;
  185. // MetaData pointer
  186. tMetaData *pMetaData;
  187. // RVA converted to pointer. Code for this method
  188. U8 *pCIL;
  189. // Flags - MethodImplAttributes
  190. FLAGS16 implFlags;
  191. // Flags - MethodAttribute
  192. FLAGS16 flags;
  193. // Name of method
  194. STRING name;
  195. // Signature of method
  196. BLOB_ signature;
  197. // The first entry in the Param table of the parameters of this method def
  198. IDX_TABLE paramList;
  199. // If this method has been JITted, then this points to it
  200. tJITted *pJITted;
  201. // Has the extra infomation in this method been filled in yet?
  202. U8 isFilled;
  203. // Set true if this method has generic parameters
  204. U8 isGenericDefinition;
  205. // The number of parameters for this method. This includes the 'this' parameter if non-static method
  206. U16 numberOfParameters;
  207. // The parameter information for this method, including the 'this' parameter if non-static method
  208. tParameter *pParams;
  209. // The size in bytes needed for the parameters, including the 'this' parameter if non-static method
  210. U32 parameterStackSize;
  211. // The method return type
  212. tMD_TypeDef *pReturnType;
  213. // The type that this method is a part of
  214. tMD_TypeDef *pParentType;
  215. // The original table index of this MethodDef
  216. IDX_TABLE tableIndex;
  217. // If this is a virtual method then this contains the offset into the vTable for this method.
  218. // This offset is the table index - not the byte offset.
  219. U32 vTableOfs;
  220. // If this is method has generic parameters, then store the method type args
  221. tMD_TypeDef **ppMethodTypeArgs;
  222. // If this is a generic core method, then store type instances here.
  223. tGenericMethodInstance *pGenericMethodInstances;
  224. #ifdef GEN_COMBINED_OPCODES
  225. // The number of times this method is on the call stack of all threads
  226. U32 callStackCount;
  227. // The number of times this method has been called
  228. U64 genCallCount;
  229. // Pointer to the method that has the next highest number of calls
  230. tMD_MethodDef *pNextHighestCalls;
  231. // Pointer to the method that has the prev highest number of calls
  232. tMD_MethodDef *pPrevHighestCalls;
  233. // If this method currently has a combined opcode JIT version, then point to it here.
  234. tJITted *pJITtedCombined;
  235. #endif
  236. #ifdef DIAG_METHOD_CALLS
  237. // Number of times this method has been called
  238. U32 callCount;
  239. // Total time (inclusive of children) in this function
  240. U64 totalTime;
  241. #endif
  242. };
  243. #define MD_TABLE_METHODDEF 0x06
  244. // Table 0x08 - Param
  245. #define MD_TABLE_PARAM 0x08
  246. typedef struct tMD_Param_ tMD_Param;
  247. struct tMD_Param_ {
  248. // Flags - ParamAttributes
  249. FLAGS16 flags;
  250. // The sequence number of the parameter. 0 is the return value, 1+ are the parameters
  251. U16 sequence;
  252. // The name of the parameter (optional)
  253. STRING name;
  254. };
  255. // Table 0x09 - InterfaceImpl
  256. #define MD_TABLE_INTERFACEIMPL 0x09
  257. typedef struct tMD_InterfaceImpl_ tMD_InterfaceImpl;
  258. struct tMD_InterfaceImpl_ {
  259. // The class that implements...
  260. IDX_TABLE class_;
  261. // ...this interface
  262. IDX_TABLE interface_;
  263. };
  264. // Table 0x0A - MemberRef
  265. struct tMD_MemberRef_ {
  266. // Combined
  267. union {
  268. tMD_MethodDef *pMethodDef;
  269. tMD_FieldDef *pFieldDef;
  270. } u;
  271. // Type of member, coded index: MemberRefParent
  272. IDX_TABLE class_;
  273. // Name of the member
  274. STRING name;
  275. // Signature of the member
  276. BLOB_ signature;
  277. };
  278. typedef struct tMD_MemberRef_ tMD_MemberRef;
  279. #define MD_TABLE_MEMBERREF 0x0a
  280. // Table 0x0B - Constant
  281. struct tMD_Constant_ {
  282. // The ELEMENT_TYPE of the constant - 'void' is ELEMENT_TYPE_CLASS with a 0 blob index
  283. U8 type;
  284. // Padding
  285. U8 padding0[3];
  286. // The parent of this constant - HasConstant encoded table index
  287. IDX_TABLE parent;
  288. // The value of the constant, index in the BLOB heap
  289. BLOB_ value;
  290. };
  291. typedef struct tMD_Constant_ tMD_Constant;
  292. #define MD_TABLE_CONSTANT 0x0b
  293. // Table 0x0C - CustomAttribute
  294. struct tMD_CustomAttribute_ {
  295. // Parent
  296. IDX_TABLE parent;
  297. // Type
  298. IDX_TABLE type;
  299. // value of attribute
  300. BLOB_ value;
  301. };
  302. typedef struct tMD_CustomAttribute_ tMD_CustomAttribute;
  303. #define MD_TABLE_CUSTOMATTRIBUTE 0x0c
  304. #define MD_TABLE_DECLSECURITY 0x0e
  305. typedef struct tMD_DeclSecurity_ tMD_DeclSecurity;
  306. struct tMD_DeclSecurity_ {
  307. // The security action
  308. U16 action;
  309. // Padding
  310. U16 padding0;
  311. // The parent typedef, methoddef or assembly of this security info - HasDeclSecurity coded index
  312. IDX_TABLE parent;
  313. // The security permission set
  314. BLOB_ permissionSet;
  315. };
  316. // Table 0x0F - ClassLayout
  317. struct tMD_ClassLayout_ {
  318. // The packing size
  319. U16 packingSize;
  320. // Padding
  321. U16 padding0;
  322. // The class size
  323. U32 classSize;
  324. // The parent TypeDef
  325. IDX_TABLE parent;
  326. };
  327. typedef struct tMD_ClassLayout_ tMD_ClassLayout;
  328. // Table 0x11 - StandAloneSig
  329. struct tMD_StandAloneSig_ {
  330. BLOB_ signature;
  331. };
  332. typedef struct tMD_StandAloneSig_ tMD_StandAloneSig;
  333. // Table 0x12 - EventMap
  334. struct tMD_EventMap_ {
  335. // Index into TypeDef table
  336. IDX_TABLE parent;
  337. // Index into Event table. Marks the start of a continuous run of events owned by this type.
  338. IDX_TABLE eventList;
  339. };
  340. typedef struct tMD_EventMap_ tMD_EventMap;
  341. // Table 0x14 - Event
  342. struct tMD_Event_ {
  343. // Flags of type eventAttributes
  344. FLAGS16 eventFlags;
  345. // Padding
  346. U16 padding0;
  347. // The name of the event
  348. STRING name;
  349. // The type of this event. A TypeDefOrRef index. This is NOT the type to which this event belongs.
  350. IDX_TABLE eventType;
  351. };
  352. typedef struct tMD_Event_ tMD_Event;
  353. // Table 0x15 - PropertyMap
  354. struct tMD_PropertyMap_ {
  355. // Parent - index into TypeDef table
  356. IDX_TABLE parent;
  357. // PropertyList - index into Property table
  358. IDX_TABLE propertyList;
  359. };
  360. typedef struct tMD_PropertyMap tMD_PropertyMap;
  361. // Table 0x17 - Property
  362. struct tMD_Property_ {
  363. // Flags - PropertyAttributes
  364. FLAGS16 flags;
  365. // Padding dummy entry
  366. I16 padding0;
  367. // Name
  368. STRING name;
  369. // The type signature
  370. BLOB_ typeSig;
  371. };
  372. typedef struct tMD_Property_ tMD_Property;
  373. #define MD_TABLE_PROPERTY 0x17
  374. // Table 0x18 - MethodSemantics
  375. struct tMD_MethodSemantics_ {
  376. // semantics flags - MethodSemanticsAttributes
  377. FLAGS16 semantics;
  378. // Padding dummy entry
  379. I16 padding0;
  380. // method - entry into MethodDef table
  381. IDX_TABLE method;
  382. // HasSemantics coded entry - index into Event or Property tables
  383. IDX_TABLE association;
  384. };
  385. typedef struct tMD_MethodSemantics_ tMD_MethodSemantics;
  386. #define MD_TABLE_METHODSEMANTICS 0x18
  387. // Table 0x19 - MethodImpl
  388. #define MD_TABLE_METHODIMPL 0x19
  389. typedef struct tMD_MethodImpl_ tMD_MethodImpl;
  390. struct tMD_MethodImpl_ {
  391. // Index into TypeDef table
  392. IDX_TABLE class_;
  393. // The method to use as the interface implementation. Coded index MethodDefOrRef
  394. IDX_TABLE methodBody;
  395. // The method declaration that is being overriden. Coded index MethodDefOrRef
  396. IDX_TABLE methodDeclaration;
  397. };
  398. #define MD_TABLE_MODULEREF 0x1a
  399. typedef struct tMD_ModuleRef_ tMD_ModuleRef;
  400. struct tMD_ModuleRef_ {
  401. // The module name referenced
  402. STRING name;
  403. };
  404. // Table 0x1B - TypeSpec
  405. #define MD_TABLE_TYPESPEC 0x1b
  406. typedef struct tMD_TypeSpec_ tMD_TypeSpec;
  407. struct tMD_TypeSpec_ {
  408. // Combined
  409. tMD_TypeDef *pTypeDef;
  410. // MetaData pointer
  411. tMetaData *pMetaData;
  412. // The signature of the type
  413. BLOB_ signature;
  414. };
  415. #define MD_TABLE_IMPLMAP 0x1c
  416. struct tMD_ImplMap_ {
  417. // Mapping flags of type PInvokeAttributes
  418. U16 mappingFlags;
  419. // padding
  420. U16 padding;
  421. // A MemberForwarded coded index, specifying which member is forwarded. Note that only members are allowed.
  422. IDX_TABLE memberForwarded;
  423. // The import name
  424. STRING importName;
  425. // The module ref (scope) of the import
  426. IDX_TABLE importScope;
  427. };
  428. // Table 0x1D - FieldRVA
  429. struct tMD_FieldRVA_ {
  430. // The RVA of the initial data for the field
  431. U32 rva;
  432. // Index into the field table
  433. IDX_TABLE field;
  434. };
  435. typedef struct tMD_FieldRVA_ tMD_FieldRVA;
  436. #define MD_TABLE_FIELDRVA 0x1d
  437. // Table 0x20 - Assembly
  438. struct tMD_Assembly_ {
  439. // Hash algorithm ID of type AssemblyHashAlgorithm
  440. U32 hashAlgID;
  441. // Version info
  442. U16 majorVersion, minorVersion, buildNumber, revisionNumber;
  443. // Flags - AssemblyFlags
  444. FLAGS32 flags;
  445. // Public key
  446. BLOB_ publicKey;
  447. // Name
  448. STRING name;
  449. // Culture
  450. STRING culture;
  451. };
  452. typedef struct tMD_Assembly_ tMD_Assembly;
  453. #define MD_TABLE_ASSEMBLY 0x20
  454. struct tMD_AssemblyRef_ {
  455. // Version info
  456. U16 majorVersion, minorVersion, buildNumber, revisionNumber;
  457. // Flags - AssemblyFlags
  458. FLAGS32 flags;
  459. // Public key or token
  460. BLOB_ publicKeyOrToken;
  461. // Name
  462. STRING name;
  463. // Culture
  464. STRING culture;
  465. // Hash value
  466. BLOB_ hashValue;
  467. };
  468. typedef struct tMD_AssemblyRef_ tMD_AssemblyRef;
  469. #define MD_TABLE_ASSEMBLYREF 0x23
  470. typedef struct tMD_NestedClass_ tMD_NestedClass;
  471. struct tMD_NestedClass_ {
  472. // The TypeDef of the class that is nested
  473. IDX_TABLE nestedClass;
  474. // The TypeDef of the class in which nestedClass is enclosed
  475. IDX_TABLE enclosingClass;
  476. };
  477. #define MD_TABLE_NESTEDCLASS 0x29
  478. // Table 0x2A - Generic param
  479. #define MD_TABLE_GENERICPARAM 0x2A
  480. typedef struct tMD_GenericParam_ tMD_GenericParam;
  481. struct tMD_GenericParam_ {
  482. // The number of this generic parameter. Numbered left-to-right, starting from 0
  483. U16 number;
  484. // Flags - GenericParamAttributes
  485. FLAGS16 flags;
  486. // Owner - the TypeDef or MethodDef that owns this parameter - TypeOrMethodDef coded index
  487. IDX_TABLE owner;
  488. // The name of the parameter
  489. STRING name;
  490. };
  491. // Table 0x2B - MethodSpec
  492. #define MD_TABLE_METHODSPEC 0x2B
  493. struct tMD_MethodSpec_ {
  494. // Combined
  495. tMD_MethodDef *pMethodDef;
  496. // MetaData pointer
  497. tMetaData *pMetaData;
  498. // Index into MethodDef or MethodRef specifying which method this spec refers to
  499. IDX_TABLE method;
  500. // Index into blob heap, holding the signature of this instantiation
  501. BLOB_ instantiation;
  502. };
  503. // Table 0x2C - GenericParamConstraint
  504. #define MD_TABLE_GENERICPARAMCONSTRAINT 0x2C
  505. typedef struct tMD_GenericParamConstraint_ tMD_GenericParamConstraint;
  506. struct tMD_GenericParamConstraint_ {
  507. // The generic param that this constraint applies to
  508. tMD_GenericParam *pGenericParam;
  509. // The type of the constraint (coded index TypeDefOrRef)
  510. IDX_TABLE constraint;
  511. };
  512. #endif