2 * metadata.c: Routines for accessing the metadata
5 * Miguel de Icaza (miguel@ximian.com)
6 * Paolo Molaro (lupus@ximian.com)
8 * (C) 2001-2002 Ximian, Inc.
17 #include "tabledefs.h"
18 #include "mono-endian.h"
20 #include "tokentype.h"
21 #include "metadata-internals.h"
22 #include "class-internals.h"
25 static void do_mono_metadata_parse_type (MonoType *type, MonoImage *m, MonoGenericContext *generic_context,
26 const char *ptr, const char **rptr);
28 static gboolean do_mono_metadata_type_equal (MonoType *t1, MonoType *t2, gboolean signature_only);
29 static gboolean mono_metadata_class_equal (MonoClass *c1, MonoClass *c2, gboolean signature_only);
30 static gboolean _mono_metadata_generic_class_equal (const MonoGenericClass *g1, const MonoGenericClass *g2,
31 gboolean signature_only);
34 * This enumeration is used to describe the data types in the metadata
45 /* Index into Blob heap */
48 /* Index into String heap */
54 /* Pointer into a table */
57 /* HasConstant:Parent pointer (Param, Field or Property) */
60 /* HasCustomAttribute index. Indexes any table except CustomAttribute */
63 /* CustomAttributeType encoded index */
66 /* HasDeclSecurity index: TypeDef Method or Assembly */
69 /* Implementation coded index: File, Export AssemblyRef */
72 /* HasFieldMarshal coded index: Field or Param table */
75 /* MemberForwardedIndex: Field or Method */
78 /* TypeDefOrRef coded index: typedef, typeref, typespec */
81 /* MemberRefParent coded index: typeref, moduleref, method, memberref, typesepc, typedef */
84 /* MethodDefOrRef coded index: Method or Member Ref table */
87 /* HasSemantic coded index: Event or Property */
90 /* ResolutionScope coded index: Module, ModuleRef, AssemblytRef, TypeRef */
94 const static unsigned char AssemblySchema [] = {
95 MONO_MT_UINT32, /* "HashId" }, */
96 MONO_MT_UINT16, /* "Major" }, */
97 MONO_MT_UINT16, /* "Minor" }, */
98 MONO_MT_UINT16, /* "BuildNumber" }, */
99 MONO_MT_UINT16, /* "RevisionNumber" }, */
100 MONO_MT_UINT32, /* "Flags" }, */
101 MONO_MT_BLOB_IDX, /* "PublicKey" }, */
102 MONO_MT_STRING_IDX, /* "Name" }, */
103 MONO_MT_STRING_IDX, /* "Culture" }, */
107 const static unsigned char AssemblyOSSchema [] = {
108 MONO_MT_UINT32, /* "OSPlatformID" }, */
109 MONO_MT_UINT32, /* "OSMajor" }, */
110 MONO_MT_UINT32, /* "OSMinor" }, */
114 const static unsigned char AssemblyProcessorSchema [] = {
115 MONO_MT_UINT32, /* "Processor" }, */
119 const static unsigned char AssemblyRefSchema [] = {
120 MONO_MT_UINT16, /* "Major" }, */
121 MONO_MT_UINT16, /* "Minor" }, */
122 MONO_MT_UINT16, /* "Build" }, */
123 MONO_MT_UINT16, /* "Revision" }, */
124 MONO_MT_UINT32, /* "Flags" }, */
125 MONO_MT_BLOB_IDX, /* "PublicKeyOrToken" }, */
126 MONO_MT_STRING_IDX, /* "Name" }, */
127 MONO_MT_STRING_IDX, /* "Culture" }, */
128 MONO_MT_BLOB_IDX, /* "HashValue" }, */
132 const static unsigned char AssemblyRefOSSchema [] = {
133 MONO_MT_UINT32, /* "OSPlatformID" }, */
134 MONO_MT_UINT32, /* "OSMajorVersion" }, */
135 MONO_MT_UINT32, /* "OSMinorVersion" }, */
136 MONO_MT_TABLE_IDX, /* "AssemblyRef:AssemblyRef" }, */
140 const static unsigned char AssemblyRefProcessorSchema [] = {
141 MONO_MT_UINT32, /* "Processor" }, */
142 MONO_MT_TABLE_IDX, /* "AssemblyRef:AssemblyRef" }, */
146 const static unsigned char ClassLayoutSchema [] = {
147 MONO_MT_UINT16, /* "PackingSize" }, */
148 MONO_MT_UINT32, /* "ClassSize" }, */
149 MONO_MT_TABLE_IDX, /* "Parent:TypeDef" }, */
153 const static unsigned char ConstantSchema [] = {
154 MONO_MT_UINT8, /* "Type" }, */
155 MONO_MT_UINT8, /* "PaddingZero" }, */
156 MONO_MT_CONST_IDX, /* "Parent" }, */
157 MONO_MT_BLOB_IDX, /* "Value" }, */
161 const static unsigned char CustomAttributeSchema [] = {
162 MONO_MT_HASCAT_IDX, /* "Parent" }, */
163 MONO_MT_CAT_IDX, /* "Type" }, */
164 MONO_MT_BLOB_IDX, /* "Value" }, */
168 const static unsigned char DeclSecuritySchema [] = {
169 MONO_MT_UINT16, /* "Action" }, */
170 MONO_MT_HASDEC_IDX, /* "Parent" }, */
171 MONO_MT_BLOB_IDX, /* "PermissionSet" }, */
175 const static unsigned char EventMapSchema [] = {
176 MONO_MT_TABLE_IDX, /* "Parent:TypeDef" }, */
177 MONO_MT_TABLE_IDX, /* "EventList:Event" }, */
181 const static unsigned char EventSchema [] = {
182 MONO_MT_UINT16, /* "EventFlags#EventAttribute" }, */
183 MONO_MT_STRING_IDX, /* "Name" }, */
184 MONO_MT_TABLE_IDX, /* "EventType" }, TypeDef or TypeRef */
188 const static unsigned char ExportedTypeSchema [] = {
189 MONO_MT_UINT32, /* "Flags" }, */
190 MONO_MT_TABLE_IDX, /* "TypeDefId" }, */
191 MONO_MT_STRING_IDX, /* "TypeName" }, */
192 MONO_MT_STRING_IDX, /* "TypeNameSpace" }, */
193 MONO_MT_IMPL_IDX, /* "Implementation" }, */
197 const static unsigned char FieldSchema [] = {
198 MONO_MT_UINT16, /* "Flags" }, */
199 MONO_MT_STRING_IDX, /* "Name" }, */
200 MONO_MT_BLOB_IDX, /* "Signature" }, */
203 const static unsigned char FieldLayoutSchema [] = {
204 MONO_MT_UINT32, /* "Offset" }, */
205 MONO_MT_TABLE_IDX, /* "Field:Field" }, */
209 const static unsigned char FieldMarshalSchema [] = {
210 MONO_MT_HFM_IDX, /* "Parent" }, */
211 MONO_MT_BLOB_IDX, /* "NativeType" }, */
214 const static unsigned char FieldRVASchema [] = {
215 MONO_MT_UINT32, /* "RVA" }, */
216 MONO_MT_TABLE_IDX, /* "Field:Field" }, */
220 const static unsigned char FileSchema [] = {
221 MONO_MT_UINT32, /* "Flags" }, */
222 MONO_MT_STRING_IDX, /* "Name" }, */
223 MONO_MT_BLOB_IDX, /* "Value" }, */
227 const static unsigned char ImplMapSchema [] = {
228 MONO_MT_UINT16, /* "MappingFlag" }, */
229 MONO_MT_MF_IDX, /* "MemberForwarded" }, */
230 MONO_MT_STRING_IDX, /* "ImportName" }, */
231 MONO_MT_TABLE_IDX, /* "ImportScope:ModuleRef" }, */
235 const static unsigned char InterfaceImplSchema [] = {
236 MONO_MT_TABLE_IDX, /* "Class:TypeDef" }, */
237 MONO_MT_TDOR_IDX, /* "Interface=TypeDefOrRef" }, */
241 const static unsigned char ManifestResourceSchema [] = {
242 MONO_MT_UINT32, /* "Offset" }, */
243 MONO_MT_UINT32, /* "Flags" }, */
244 MONO_MT_STRING_IDX, /* "Name" }, */
245 MONO_MT_IMPL_IDX, /* "Implementation" }, */
249 const static unsigned char MemberRefSchema [] = {
250 MONO_MT_MRP_IDX, /* "Class" }, */
251 MONO_MT_STRING_IDX, /* "Name" }, */
252 MONO_MT_BLOB_IDX, /* "Signature" }, */
256 const static unsigned char MethodSchema [] = {
257 MONO_MT_UINT32, /* "RVA" }, */
258 MONO_MT_UINT16, /* "ImplFlags#MethodImplAttributes" }, */
259 MONO_MT_UINT16, /* "Flags#MethodAttribute" }, */
260 MONO_MT_STRING_IDX, /* "Name" }, */
261 MONO_MT_BLOB_IDX, /* "Signature" }, */
262 MONO_MT_TABLE_IDX, /* "ParamList:Param" }, */
266 const static unsigned char MethodImplSchema [] = {
267 MONO_MT_TABLE_IDX, /* "Class:TypeDef" }, */
268 MONO_MT_MDOR_IDX, /* "MethodBody" }, */
269 MONO_MT_MDOR_IDX, /* "MethodDeclaration" }, */
273 const static unsigned char MethodSemanticsSchema [] = {
274 MONO_MT_UINT16, /* "MethodSemantic" }, */
275 MONO_MT_TABLE_IDX, /* "Method:Method" }, */
276 MONO_MT_HS_IDX, /* "Association" }, */
280 const static unsigned char ModuleSchema [] = {
281 MONO_MT_UINT16, /* "Generation" }, */
282 MONO_MT_STRING_IDX, /* "Name" }, */
283 MONO_MT_GUID_IDX, /* "MVID" }, */
284 MONO_MT_GUID_IDX, /* "EncID" }, */
285 MONO_MT_GUID_IDX, /* "EncBaseID" }, */
289 const static unsigned char ModuleRefSchema [] = {
290 MONO_MT_STRING_IDX, /* "Name" }, */
294 const static unsigned char NestedClassSchema [] = {
295 MONO_MT_TABLE_IDX, /* "NestedClass:TypeDef" }, */
296 MONO_MT_TABLE_IDX, /* "EnclosingClass:TypeDef" }, */
300 const static unsigned char ParamSchema [] = {
301 MONO_MT_UINT16, /* "Flags" }, */
302 MONO_MT_UINT16, /* "Sequence" }, */
303 MONO_MT_STRING_IDX, /* "Name" }, */
307 const static unsigned char PropertySchema [] = {
308 MONO_MT_UINT16, /* "Flags" }, */
309 MONO_MT_STRING_IDX, /* "Name" }, */
310 MONO_MT_BLOB_IDX, /* "Type" }, */
314 const static unsigned char PropertyMapSchema [] = {
315 MONO_MT_TABLE_IDX, /* "Parent:TypeDef" }, */
316 MONO_MT_TABLE_IDX, /* "PropertyList:Property" }, */
320 const static unsigned char StandaloneSigSchema [] = {
321 MONO_MT_BLOB_IDX, /* "Signature" }, */
325 const static unsigned char TypeDefSchema [] = {
326 MONO_MT_UINT32, /* "Flags" }, */
327 MONO_MT_STRING_IDX, /* "Name" }, */
328 MONO_MT_STRING_IDX, /* "Namespace" }, */
329 MONO_MT_TDOR_IDX, /* "Extends" }, */
330 MONO_MT_TABLE_IDX, /* "FieldList:Field" }, */
331 MONO_MT_TABLE_IDX, /* "MethodList:Method" }, */
335 const static unsigned char TypeRefSchema [] = {
336 MONO_MT_RS_IDX, /* "ResolutionScope=ResolutionScope" }, */
337 MONO_MT_STRING_IDX, /* "Name" }, */
338 MONO_MT_STRING_IDX, /* "Namespace" }, */
342 const static unsigned char TypeSpecSchema [] = {
343 MONO_MT_BLOB_IDX, /* "Signature" }, */
347 const static unsigned char GenericParamSchema [] = {
348 MONO_MT_UINT16, /* "Number" }, */
349 MONO_MT_UINT16, /* "Flags" }, */
350 MONO_MT_TABLE_IDX, /* "Owner" }, TypeDef or MethodDef */
351 MONO_MT_STRING_IDX, /* "Name" }, */
356 const static unsigned char MethodSpecSchema [] = {
357 MONO_MT_MDOR_IDX, /* "Method" }, */
358 MONO_MT_BLOB_IDX, /* "Signature" }, */
362 const static unsigned char GenericParamConstraintSchema [] = {
363 MONO_MT_TABLE_IDX, /* "GenericParam" }, */
364 MONO_MT_TDOR_IDX, /* "Constraint" }, */
368 const static struct {
369 const unsigned char *description;
372 /* 0 */ { ModuleSchema, "Module" },
373 /* 1 */ { TypeRefSchema, "TypeRef" },
374 /* 2 */ { TypeDefSchema, "TypeDef" },
375 /* 3 */ { NULL, NULL },
376 /* 4 */ { FieldSchema, "Field" },
377 /* 5 */ { NULL, NULL },
378 /* 6 */ { MethodSchema, "Method" },
379 /* 7 */ { NULL, NULL },
380 /* 8 */ { ParamSchema, "Param" },
381 /* 9 */ { InterfaceImplSchema, "InterfaceImpl" },
382 /* A */ { MemberRefSchema, "MemberRef" },
383 /* B */ { ConstantSchema, "Constant" },
384 /* C */ { CustomAttributeSchema, "CustomAttribute" },
385 /* D */ { FieldMarshalSchema, "FieldMarshal" },
386 /* E */ { DeclSecuritySchema, "DeclSecurity" },
387 /* F */ { ClassLayoutSchema, "ClassLayout" },
388 /* 10 */ { FieldLayoutSchema, "FieldLayout" },
389 /* 11 */ { StandaloneSigSchema, "StandaloneSig" },
390 /* 12 */ { EventMapSchema, "EventMap" },
391 /* 13 */ { NULL, NULL },
392 /* 14 */ { EventSchema, "Event" },
393 /* 15 */ { PropertyMapSchema, "PropertyMap" },
394 /* 16 */ { NULL, NULL },
395 /* 17 */ { PropertySchema, "PropertyTable" },
396 /* 18 */ { MethodSemanticsSchema, "MethodSemantics" },
397 /* 19 */ { MethodImplSchema, "MethodImpl" },
398 /* 1A */ { ModuleRefSchema, "ModuleRef" },
399 /* 1B */ { TypeSpecSchema, "TypeSpec" },
400 /* 1C */ { ImplMapSchema, "ImplMap" },
401 /* 1D */ { FieldRVASchema, "FieldRVA" },
402 /* 1E */ { NULL, NULL },
403 /* 1F */ { NULL, NULL },
404 /* 20 */ { AssemblySchema, "Assembly" },
405 /* 21 */ { AssemblyProcessorSchema, "AssemblyProcessor" },
406 /* 22 */ { AssemblyOSSchema, "AssemblyOS" },
407 /* 23 */ { AssemblyRefSchema, "AssemblyRef" },
408 /* 24 */ { AssemblyRefProcessorSchema, "AssemblyRefProcessor" },
409 /* 25 */ { AssemblyRefOSSchema, "AssemblyRefOS" },
410 /* 26 */ { FileSchema, "File" },
411 /* 27 */ { ExportedTypeSchema, "ExportedType" },
412 /* 28 */ { ManifestResourceSchema, "ManifestResource" },
413 /* 29 */ { NestedClassSchema, "NestedClass" },
414 /* 2A */ { GenericParamSchema, "GenericParam" },
415 /* 2B */ { MethodSpecSchema, "MethodSpec" },
416 /* 2C */ { GenericParamConstraintSchema, "GenericParamConstraint" },
420 * mono_meta_table_name:
421 * @table: table index
423 * Returns: the name for the @table index
426 mono_meta_table_name (int table)
428 if ((table < 0) || (table > 0x2c))
431 return tables [table].name;
434 /* The guy who wrote the spec for this should not be allowed near a
437 If e is a coded token(see clause 23.1.7) that points into table ti out of n possible tables t0, .. tn-1,
438 then it is stored as e << (log n) & tag{ t0, .. tn-1}[ ti] using 2 bytes if the maximum number of
439 rows of tables t0, ..tn-1, is less than 2^16 - (log n), and using 4 bytes otherwise. The family of
440 finite maps tag{ t0, ..tn-1} is defined below. Note that to decode a physical row, you need the
441 inverse of this mapping.
444 #define rtsize(s,b) (((s) < (1 << (b)) ? 2 : 4))
445 #define idx_size(tableidx) (meta->tables [(tableidx)].rows < 65536 ? 2 : 4)
447 /* Reference: Partition II - 23.2.6 */
449 * mono_metadata_compute_size:
450 * @meta: metadata context
451 * @tableindex: metadata table number
452 * @result_bitfield: pointer to guint32 where to store additional info
454 * mono_metadata_compute_size() computes the lenght in bytes of a single
455 * row in a metadata table. The size of each column is encoded in the
456 * @result_bitfield return value along with the number of columns in the table.
457 * the resulting bitfield should be handed to the mono_metadata_table_size()
458 * and mono_metadata_table_count() macros.
461 mono_metadata_compute_size (MonoImage *meta, int tableindex, guint32 *result_bitfield)
463 guint32 bitfield = 0;
464 int size = 0, field_size = 0;
467 const unsigned char *description = tables [tableindex].description;
469 for (i = 0; (code = description [i]) != MONO_MT_END; i++){
472 field_size = 4; break;
475 field_size = 2; break;
478 field_size = 1; break;
480 case MONO_MT_BLOB_IDX:
481 field_size = meta->idx_blob_wide ? 4 : 2; break;
483 case MONO_MT_STRING_IDX:
484 field_size = meta->idx_string_wide ? 4 : 2; break;
486 case MONO_MT_GUID_IDX:
487 field_size = meta->idx_guid_wide ? 4 : 2; break;
489 case MONO_MT_TABLE_IDX:
490 /* Uhm, a table index can point to other tables besides the current one
491 * so, it's not correct to use the rowcount of the current table to
492 * get the size for this column - lupus
494 switch (tableindex) {
495 case MONO_TABLE_ASSEMBLYREFOS:
497 field_size = idx_size (MONO_TABLE_ASSEMBLYREF); break;
498 case MONO_TABLE_ASSEMBLYPROCESSOR:
500 field_size = idx_size (MONO_TABLE_ASSEMBLYREF); break;
501 case MONO_TABLE_CLASSLAYOUT:
503 field_size = idx_size (MONO_TABLE_TYPEDEF); break;
504 case MONO_TABLE_EVENTMAP:
505 g_assert (i == 0 || i == 1);
506 field_size = i ? idx_size (MONO_TABLE_EVENT):
507 idx_size(MONO_TABLE_TYPEDEF);
509 case MONO_TABLE_EVENT:
511 field_size = MAX (idx_size (MONO_TABLE_TYPEDEF), idx_size(MONO_TABLE_TYPEREF));
512 field_size = MAX (field_size, idx_size(MONO_TABLE_TYPESPEC));
514 case MONO_TABLE_EXPORTEDTYPE:
516 /* the index is in another metadata file, so it must be 4 */
517 field_size = 4; break;
518 case MONO_TABLE_FIELDLAYOUT:
520 field_size = idx_size (MONO_TABLE_FIELD); break;
521 case MONO_TABLE_FIELDRVA:
523 field_size = idx_size (MONO_TABLE_FIELD); break;
524 case MONO_TABLE_IMPLMAP:
526 field_size = idx_size (MONO_TABLE_MODULEREF); break;
527 case MONO_TABLE_INTERFACEIMPL:
529 field_size = idx_size (MONO_TABLE_TYPEDEF); break;
530 case MONO_TABLE_METHOD:
532 field_size = idx_size (MONO_TABLE_PARAM); break;
533 case MONO_TABLE_METHODIMPL:
535 field_size = idx_size (MONO_TABLE_TYPEDEF); break;
536 case MONO_TABLE_METHODSEMANTICS:
538 field_size = idx_size (MONO_TABLE_METHOD); break;
539 case MONO_TABLE_NESTEDCLASS:
540 g_assert (i == 0 || i == 1);
541 field_size = idx_size (MONO_TABLE_TYPEDEF); break;
542 case MONO_TABLE_PROPERTYMAP:
543 g_assert (i == 0 || i == 1);
544 field_size = i ? idx_size (MONO_TABLE_PROPERTY):
545 idx_size(MONO_TABLE_TYPEDEF);
547 case MONO_TABLE_TYPEDEF:
548 g_assert (i == 4 || i == 5);
549 field_size = i == 4 ? idx_size (MONO_TABLE_FIELD):
550 idx_size(MONO_TABLE_METHOD);
552 case MONO_TABLE_GENERICPARAM:
553 g_assert (i == 2 || i == 4 || i == 5);
555 field_size = MAX (idx_size (MONO_TABLE_METHOD), idx_size (MONO_TABLE_TYPEDEF));
557 field_size = idx_size (MONO_TABLE_TYPEDEF);
559 field_size = idx_size (MONO_TABLE_TYPEDEF);
562 case MONO_TABLE_GENERICPARAMCONSTRAINT:
564 field_size = idx_size (MONO_TABLE_GENERICPARAM);
568 g_assert_not_reached ();
573 * HasConstant: ParamDef, FieldDef, Property
575 case MONO_MT_CONST_IDX:
576 n = MAX (meta->tables [MONO_TABLE_PARAM].rows,
577 meta->tables [MONO_TABLE_FIELD].rows);
578 n = MAX (n, meta->tables [MONO_TABLE_PROPERTY].rows);
580 /* 2 bits to encode tag */
581 field_size = rtsize (n, 16-2);
585 * HasCustomAttribute: points to any table but
588 case MONO_MT_HASCAT_IDX:
590 * We believe that since the signature and
591 * permission are indexing the Blob heap,
592 * we should consider the blob size first
594 /* I'm not a believer - lupus
595 if (meta->idx_blob_wide){
600 n = MAX (meta->tables [MONO_TABLE_METHOD].rows,
601 meta->tables [MONO_TABLE_FIELD].rows);
602 n = MAX (n, meta->tables [MONO_TABLE_TYPEREF].rows);
603 n = MAX (n, meta->tables [MONO_TABLE_TYPEDEF].rows);
604 n = MAX (n, meta->tables [MONO_TABLE_PARAM].rows);
605 n = MAX (n, meta->tables [MONO_TABLE_INTERFACEIMPL].rows);
606 n = MAX (n, meta->tables [MONO_TABLE_MEMBERREF].rows);
607 n = MAX (n, meta->tables [MONO_TABLE_MODULE].rows);
608 n = MAX (n, meta->tables [MONO_TABLE_DECLSECURITY].rows);
609 n = MAX (n, meta->tables [MONO_TABLE_PROPERTY].rows);
610 n = MAX (n, meta->tables [MONO_TABLE_EVENT].rows);
611 n = MAX (n, meta->tables [MONO_TABLE_STANDALONESIG].rows);
612 n = MAX (n, meta->tables [MONO_TABLE_MODULEREF].rows);
613 n = MAX (n, meta->tables [MONO_TABLE_TYPESPEC].rows);
614 n = MAX (n, meta->tables [MONO_TABLE_ASSEMBLY].rows);
615 n = MAX (n, meta->tables [MONO_TABLE_ASSEMBLYREF].rows);
616 n = MAX (n, meta->tables [MONO_TABLE_FILE].rows);
617 n = MAX (n, meta->tables [MONO_TABLE_EXPORTEDTYPE].rows);
618 n = MAX (n, meta->tables [MONO_TABLE_MANIFESTRESOURCE].rows);
620 /* 5 bits to encode */
621 field_size = rtsize (n, 16-5);
625 * CustomAttributeType: TypeDef, TypeRef, MethodDef,
626 * MemberRef and String.
628 case MONO_MT_CAT_IDX:
629 /* String is a heap, if it is wide, we know the size */
631 if (meta->idx_string_wide){
636 n = MAX (meta->tables [MONO_TABLE_TYPEREF].rows,
637 meta->tables [MONO_TABLE_TYPEDEF].rows);
638 n = MAX (n, meta->tables [MONO_TABLE_METHOD].rows);
639 n = MAX (n, meta->tables [MONO_TABLE_MEMBERREF].rows);
641 /* 3 bits to encode */
642 field_size = rtsize (n, 16-3);
646 * HasDeclSecurity: Typedef, MethodDef, Assembly
648 case MONO_MT_HASDEC_IDX:
649 n = MAX (meta->tables [MONO_TABLE_TYPEDEF].rows,
650 meta->tables [MONO_TABLE_METHOD].rows);
651 n = MAX (n, meta->tables [MONO_TABLE_ASSEMBLY].rows);
653 /* 2 bits to encode */
654 field_size = rtsize (n, 16-2);
658 * Implementation: File, AssemblyRef, ExportedType
660 case MONO_MT_IMPL_IDX:
661 n = MAX (meta->tables [MONO_TABLE_FILE].rows,
662 meta->tables [MONO_TABLE_ASSEMBLYREF].rows);
663 n = MAX (n, meta->tables [MONO_TABLE_EXPORTEDTYPE].rows);
665 /* 2 bits to encode tag */
666 field_size = rtsize (n, 16-2);
670 * HasFieldMarshall: FieldDef, ParamDef
672 case MONO_MT_HFM_IDX:
673 n = MAX (meta->tables [MONO_TABLE_FIELD].rows,
674 meta->tables [MONO_TABLE_PARAM].rows);
676 /* 1 bit used to encode tag */
677 field_size = rtsize (n, 16-1);
681 * MemberForwarded: FieldDef, MethodDef
684 n = MAX (meta->tables [MONO_TABLE_FIELD].rows,
685 meta->tables [MONO_TABLE_METHOD].rows);
687 /* 1 bit used to encode tag */
688 field_size = rtsize (n, 16-1);
692 * TypeDefOrRef: TypeDef, ParamDef, TypeSpec
694 * It is TypeDef, _TypeRef_, TypeSpec, instead.
696 case MONO_MT_TDOR_IDX:
697 n = MAX (meta->tables [MONO_TABLE_TYPEDEF].rows,
698 meta->tables [MONO_TABLE_TYPEREF].rows);
699 n = MAX (n, meta->tables [MONO_TABLE_TYPESPEC].rows);
701 /* 2 bits to encode */
702 field_size = rtsize (n, 16-2);
706 * MemberRefParent: TypeDef, TypeRef, MethodDef, ModuleRef, TypeSpec, MemberRef
708 case MONO_MT_MRP_IDX:
709 n = MAX (meta->tables [MONO_TABLE_TYPEDEF].rows,
710 meta->tables [MONO_TABLE_TYPEREF].rows);
711 n = MAX (n, meta->tables [MONO_TABLE_METHOD].rows);
712 n = MAX (n, meta->tables [MONO_TABLE_MODULEREF].rows);
713 n = MAX (n, meta->tables [MONO_TABLE_TYPESPEC].rows);
714 n = MAX (n, meta->tables [MONO_TABLE_MEMBERREF].rows);
716 /* 3 bits to encode */
717 field_size = rtsize (n, 16 - 3);
721 * MethodDefOrRef: MethodDef, MemberRef
723 case MONO_MT_MDOR_IDX:
724 n = MAX (meta->tables [MONO_TABLE_METHOD].rows,
725 meta->tables [MONO_TABLE_MEMBERREF].rows);
727 /* 1 bit used to encode tag */
728 field_size = rtsize (n, 16-1);
732 * HasSemantics: Property, Event
735 n = MAX (meta->tables [MONO_TABLE_PROPERTY].rows,
736 meta->tables [MONO_TABLE_EVENT].rows);
738 /* 1 bit used to encode tag */
739 field_size = rtsize (n, 16-1);
743 * ResolutionScope: Module, ModuleRef, AssemblyRef, TypeRef
746 n = MAX (meta->tables [MONO_TABLE_MODULE].rows,
747 meta->tables [MONO_TABLE_MODULEREF].rows);
748 n = MAX (n, meta->tables [MONO_TABLE_ASSEMBLYREF].rows);
749 n = MAX (n, meta->tables [MONO_TABLE_TYPEREF].rows);
751 /* 2 bits used to encode tag (ECMA spec claims 3) */
752 field_size = rtsize (n, 16 - 2);
757 * encode field size as follows (we just need to
764 bitfield |= (field_size-1) << shift;
767 /*g_print ("table %02x field %d size %d\n", tableindex, i, field_size);*/
770 *result_bitfield = (i << 24) | bitfield;
775 * mono_metadata_compute_table_bases:
776 * @meta: metadata context to compute table values
778 * Computes the table bases for the metadata structure.
779 * This is an internal function used by the image loader code.
782 mono_metadata_compute_table_bases (MonoImage *meta)
785 const char *base = meta->tables_base;
787 for (i = 0; i < MONO_TABLE_NUM; i++){
788 if (meta->tables [i].rows == 0)
791 meta->tables [i].row_size = mono_metadata_compute_size (
792 meta, i, &meta->tables [i].size_bitfield);
793 meta->tables [i].base = base;
794 base += meta->tables [i].rows * meta->tables [i].row_size;
799 * mono_metadata_locate:
800 * @meta: metadata context
801 * @table: table code.
802 * @idx: index of element to retrieve from @table.
804 * Returns: a pointer to the @idx element in the metadata table
805 * whose code is @table.
808 mono_metadata_locate (MonoImage *meta, int table, int idx)
810 /* idx == 0 refers always to NULL */
811 g_return_val_if_fail (idx > 0 && idx <= meta->tables [table].rows, "");
813 return meta->tables [table].base + (meta->tables [table].row_size * (idx - 1));
817 * mono_metadata_locate_token:
818 * @meta: metadata context
819 * @token: metadata token
821 * Returns: a pointer to the data in the metadata represented by the
825 mono_metadata_locate_token (MonoImage *meta, guint32 token)
827 return mono_metadata_locate (meta, token >> 24, token & 0xffffff);
831 * mono_metadata_string_heap:
832 * @meta: metadata context
833 * @index: index into the string heap.
835 * Returns: an in-memory pointer to the @index in the string heap.
838 mono_metadata_string_heap (MonoImage *meta, guint32 index)
840 g_return_val_if_fail (index < meta->heap_strings.size, "");
841 return meta->heap_strings.data + index;
845 * mono_metadata_user_string:
846 * @meta: metadata context
847 * @index: index into the user string heap.
849 * Returns: an in-memory pointer to the @index in the user string heap ("#US").
852 mono_metadata_user_string (MonoImage *meta, guint32 index)
854 g_return_val_if_fail (index < meta->heap_us.size, "");
855 return meta->heap_us.data + index;
859 * mono_metadata_blob_heap:
860 * @meta: metadata context
861 * @index: index into the blob.
863 * Returns: an in-memory pointer to the @index in the Blob heap.
866 mono_metadata_blob_heap (MonoImage *meta, guint32 index)
868 g_return_val_if_fail (index < meta->heap_blob.size, "");
869 return meta->heap_blob.data + index;
873 * mono_metadata_guid_heap:
874 * @meta: metadata context
875 * @index: index into the guid heap.
877 * Returns: an in-memory pointer to the @index in the guid heap.
880 mono_metadata_guid_heap (MonoImage *meta, guint32 index)
883 index *= 16; /* adjust for guid size and 1-based index */
884 g_return_val_if_fail (index < meta->heap_guid.size, "");
885 return meta->heap_guid.data + index;
889 dword_align (const char *ptr)
891 #if SIZEOF_VOID_P == 8
892 return (const char *) (((guint64) (ptr + 3)) & ~3);
894 return (const char *) (((guint32) (ptr + 3)) & ~3);
899 * mono_metadata_decode_row:
900 * @t: table to extract information from.
901 * @idx: index in table.
902 * @res: array of @res_size cols to store the results in
904 * This decompresses the metadata element @idx in table @t
905 * into the guint32 @res array that has res_size elements
908 mono_metadata_decode_row (const MonoTableInfo *t, int idx, guint32 *res, int res_size)
910 guint32 bitfield = t->size_bitfield;
911 int i, count = mono_metadata_table_count (bitfield);
912 const char *data = t->base + idx * t->row_size;
914 g_assert (res_size == count);
916 for (i = 0; i < count; i++){
917 int n = mono_metadata_table_size (bitfield, i);
921 res [i] = *data; break;
923 res [i] = read16 (data); break;
926 res [i] = read32 (data); break;
929 g_assert_not_reached ();
936 * mono_metadata_decode_row_col:
937 * @t: table to extract information from.
938 * @idx: index for row in table.
939 * @col: column in the row.
941 * This function returns the value of column @col from the @idx
942 * row in the table @t.
945 mono_metadata_decode_row_col (const MonoTableInfo *t, int idx, guint col)
947 guint32 bitfield = t->size_bitfield;
949 register const char *data = t->base + idx * t->row_size;
952 g_assert (col < mono_metadata_table_count (bitfield));
954 n = mono_metadata_table_size (bitfield, 0);
955 for (i = 0; i < col; ++i) {
957 n = mono_metadata_table_size (bitfield, i + 1);
963 return read16 (data);
965 return read32 (data);
967 g_assert_not_reached ();
972 * mono_metadata_decode_blob_size:
973 * @ptr: pointer to a blob object
974 * @rptr: the new position of the pointer
976 * This decodes a compressed size as described by 23.1.4 (a blob or user string object)
978 * Returns: the size of the blob object
981 mono_metadata_decode_blob_size (const char *xptr, const char **rptr)
983 const unsigned char *ptr = (const unsigned char *)xptr;
986 if ((*ptr & 0x80) == 0){
987 size = ptr [0] & 0x7f;
989 } else if ((*ptr & 0x40) == 0){
990 size = ((ptr [0] & 0x3f) << 8) + ptr [1];
993 size = ((ptr [0] & 0x1f) << 24) +
1006 * mono_metadata_decode_value:
1007 * @ptr: pointer to decode from
1008 * @rptr: the new position of the pointer
1010 * This routine decompresses 32-bit values as specified in the "Blob and
1011 * Signature" section (22.2)
1013 * Returns: the decoded value
1016 mono_metadata_decode_value (const char *_ptr, const char **rptr)
1018 const unsigned char *ptr = (const unsigned char *) _ptr;
1019 unsigned char b = *ptr;
1022 if ((b & 0x80) == 0){
1025 } else if ((b & 0x40) == 0){
1026 len = ((b & 0x3f) << 8 | ptr [1]);
1029 len = ((b & 0x1f) << 24) |
1042 * mono_metadata_parse_typedef_or_ref:
1043 * @m: a metadata context.
1044 * @ptr: a pointer to an encoded TypedefOrRef in @m
1045 * @rptr: pointer updated to match the end of the decoded stream
1047 * Returns: a token valid in the @m metadata decoded from
1048 * the compressed representation.
1051 mono_metadata_parse_typedef_or_ref (MonoImage *m, const char *ptr, const char **rptr)
1054 token = mono_metadata_decode_value (ptr, &ptr);
1057 return mono_metadata_token_from_dor (token);
1061 * mono_metadata_parse_custom_mod:
1062 * @m: a metadata context.
1063 * @dest: storage where the info about the custom modifier is stored (may be NULL)
1064 * @ptr: a pointer to (possibly) the start of a custom modifier list
1065 * @rptr: pointer updated to match the end of the decoded stream
1067 * Checks if @ptr points to a type custom modifier compressed representation.
1069 * Returns: #TRUE if a custom modifier was found, #FALSE if not.
1072 mono_metadata_parse_custom_mod (MonoImage *m, MonoCustomMod *dest, const char *ptr, const char **rptr)
1074 MonoCustomMod local;
1075 if ((*ptr == MONO_TYPE_CMOD_OPT) ||
1076 (*ptr == MONO_TYPE_CMOD_REQD)) {
1079 dest->required = *ptr == MONO_TYPE_CMOD_REQD ? 1 : 0;
1080 dest->token = mono_metadata_parse_typedef_or_ref (m, ptr + 1, rptr);
1087 * mono_metadata_parse_array:
1088 * @m: a metadata context.
1089 * @ptr: a pointer to an encoded array description.
1090 * @rptr: pointer updated to match the end of the decoded stream
1092 * Decodes the compressed array description found in the metadata @m at @ptr.
1094 * Returns: a #MonoArrayType structure describing the array type
1098 mono_metadata_parse_array_full (MonoImage *m, MonoGenericContext *generic_context,
1099 const char *ptr, const char **rptr)
1102 MonoArrayType *array = g_new0 (MonoArrayType, 1);
1105 etype = mono_metadata_parse_type_full (m, generic_context, MONO_PARSE_TYPE, 0, ptr, &ptr);
1106 array->eklass = mono_class_from_mono_type (etype);
1107 array->rank = mono_metadata_decode_value (ptr, &ptr);
1109 array->numsizes = mono_metadata_decode_value (ptr, &ptr);
1110 if (array->numsizes)
1111 array->sizes = g_new0 (int, array->numsizes);
1112 for (i = 0; i < array->numsizes; ++i)
1113 array->sizes [i] = mono_metadata_decode_value (ptr, &ptr);
1115 array->numlobounds = mono_metadata_decode_value (ptr, &ptr);
1116 if (array->numlobounds)
1117 array->lobounds = g_new0 (int, array->numlobounds);
1118 for (i = 0; i < array->numlobounds; ++i)
1119 array->lobounds [i] = mono_metadata_decode_value (ptr, &ptr);
1127 mono_metadata_parse_array (MonoImage *m, const char *ptr, const char **rptr)
1129 return mono_metadata_parse_array_full (m, NULL, ptr, rptr);
1133 * mono_metadata_free_array:
1134 * @array: array description
1136 * Frees the array description returned from mono_metadata_parse_array().
1139 mono_metadata_free_array (MonoArrayType *array)
1141 g_free (array->sizes);
1142 g_free (array->lobounds);
1147 * need to add common field and param attributes combinations:
1150 * public static literal
1153 * private static literal
1155 static const MonoType
1157 /* data, attrs, type, nmods, byref, pinned */
1158 {{NULL}, 0, MONO_TYPE_VOID, 0, 0, 0},
1159 {{NULL}, 0, MONO_TYPE_BOOLEAN, 0, 0, 0},
1160 {{NULL}, 0, MONO_TYPE_BOOLEAN, 0, 1, 0},
1161 {{NULL}, 0, MONO_TYPE_CHAR, 0, 0, 0},
1162 {{NULL}, 0, MONO_TYPE_CHAR, 0, 1, 0},
1163 {{NULL}, 0, MONO_TYPE_I1, 0, 0, 0},
1164 {{NULL}, 0, MONO_TYPE_I1, 0, 1, 0},
1165 {{NULL}, 0, MONO_TYPE_U1, 0, 0, 0},
1166 {{NULL}, 0, MONO_TYPE_U1, 0, 1, 0},
1167 {{NULL}, 0, MONO_TYPE_I2, 0, 0, 0},
1168 {{NULL}, 0, MONO_TYPE_I2, 0, 1, 0},
1169 {{NULL}, 0, MONO_TYPE_U2, 0, 0, 0},
1170 {{NULL}, 0, MONO_TYPE_U2, 0, 1, 0},
1171 {{NULL}, 0, MONO_TYPE_I4, 0, 0, 0},
1172 {{NULL}, 0, MONO_TYPE_I4, 0, 1, 0},
1173 {{NULL}, 0, MONO_TYPE_U4, 0, 0, 0},
1174 {{NULL}, 0, MONO_TYPE_U4, 0, 1, 0},
1175 {{NULL}, 0, MONO_TYPE_I8, 0, 0, 0},
1176 {{NULL}, 0, MONO_TYPE_I8, 0, 1, 0},
1177 {{NULL}, 0, MONO_TYPE_U8, 0, 0, 0},
1178 {{NULL}, 0, MONO_TYPE_U8, 0, 1, 0},
1179 {{NULL}, 0, MONO_TYPE_R4, 0, 0, 0},
1180 {{NULL}, 0, MONO_TYPE_R4, 0, 1, 0},
1181 {{NULL}, 0, MONO_TYPE_R8, 0, 0, 0},
1182 {{NULL}, 0, MONO_TYPE_R8, 0, 1, 0},
1183 {{NULL}, 0, MONO_TYPE_STRING, 0, 0, 0},
1184 {{NULL}, 0, MONO_TYPE_STRING, 0, 1, 0},
1185 {{NULL}, 0, MONO_TYPE_OBJECT, 0, 0, 0},
1186 {{NULL}, 0, MONO_TYPE_OBJECT, 0, 1, 0},
1187 {{NULL}, 0, MONO_TYPE_TYPEDBYREF, 0, 0, 0},
1188 {{NULL}, 0, MONO_TYPE_I, 0, 0, 0},
1189 {{NULL}, 0, MONO_TYPE_I, 0, 1, 0},
1190 {{NULL}, 0, MONO_TYPE_U, 0, 0, 0},
1191 {{NULL}, 0, MONO_TYPE_U, 0, 1, 0},
1194 #define NBUILTIN_TYPES() (sizeof (builtin_types) / sizeof (builtin_types [0]))
1196 static GHashTable *type_cache = NULL;
1197 static GHashTable *generic_inst_cache = NULL;
1198 static GHashTable *generic_class_cache = NULL;
1199 static int next_generic_inst_id = 0;
1202 * MonoTypes with modifies are never cached, so we never check or use that field.
1205 mono_type_hash (gconstpointer data)
1207 const MonoType *type = (const MonoType *) data;
1208 return type->type | (type->byref << 8) | (type->attrs << 9);
1212 mono_type_equal (gconstpointer ka, gconstpointer kb)
1214 const MonoType *a = (const MonoType *) ka;
1215 const MonoType *b = (const MonoType *) kb;
1217 if (a->type != b->type || a->byref != b->byref || a->attrs != b->attrs || a->pinned != b->pinned)
1219 /* need other checks */
1224 mono_generic_inst_hash (gconstpointer data)
1226 const MonoGenericInst *ginst = (const MonoGenericInst *) data;
1227 return ginst->type_argc | (ginst->is_open << 8);
1231 mono_generic_inst_equal (gconstpointer ka, gconstpointer kb)
1233 const MonoGenericInst *a = (const MonoGenericInst *) ka;
1234 const MonoGenericInst *b = (const MonoGenericInst *) kb;
1237 if ((a->is_open != b->is_open) || (a->type_argc != b->type_argc) || (a->is_reference != b->is_reference))
1239 for (i = 0; i < a->type_argc; ++i) {
1240 if (!do_mono_metadata_type_equal (a->type_argv [i], b->type_argv [i], FALSE))
1247 mono_generic_class_hash (gconstpointer data)
1249 const MonoGenericClass *gclass = (const MonoGenericClass *) data;
1250 return mono_metadata_type_hash (&gclass->container_class->byval_arg);
1254 mono_generic_class_equal (gconstpointer ka, gconstpointer kb)
1256 const MonoGenericClass *a = (const MonoGenericClass *) ka;
1257 const MonoGenericClass *b = (const MonoGenericClass *) kb;
1259 return _mono_metadata_generic_class_equal (a, b, FALSE);
1263 * mono_metadata_init:
1265 * Initialize the global variables of this module.
1268 mono_metadata_init (void)
1272 type_cache = g_hash_table_new (mono_type_hash, mono_type_equal);
1273 generic_inst_cache = g_hash_table_new (mono_generic_inst_hash, mono_generic_inst_equal);
1274 generic_class_cache = g_hash_table_new (mono_generic_class_hash, mono_generic_class_equal);
1276 for (i = 0; i < NBUILTIN_TYPES (); ++i)
1277 g_hash_table_insert (type_cache, (gpointer) &builtin_types [i], (gpointer) &builtin_types [i]);
1281 * mono_metadata_parse_type:
1282 * @m: metadata context
1283 * @mode: king of type that may be found at @ptr
1284 * @opt_attrs: optional attributes to store in the returned type
1285 * @ptr: pointer to the type representation
1286 * @rptr: pointer updated to match the end of the decoded stream
1288 * Decode a compressed type description found at @ptr in @m.
1289 * @mode can be one of MONO_PARSE_MOD_TYPE, MONO_PARSE_PARAM, MONO_PARSE_RET,
1290 * MONO_PARSE_FIELD, MONO_PARSE_LOCAL, MONO_PARSE_TYPE.
1291 * This function can be used to decode type descriptions in method signatures,
1292 * field signatures, locals signatures etc.
1294 * To parse a generic type, `generic_container' points to the current class'es
1295 * (the `generic_container' field in the MonoClass) or the current generic method's
1296 * (the `generic_container' field in the MonoMethodNormal) generic container.
1297 * When we encounter any MONO_TYPE_VAR or MONO_TYPE_MVAR's, they're looked up in
1298 * this MonoGenericContainer.
1300 * Returns: a #MonoType structure representing the decoded type.
1303 mono_metadata_parse_type_full (MonoImage *m, MonoGenericContext *generic_context, MonoParseTypeMode mode,
1304 short opt_attrs, const char *ptr, const char **rptr)
1306 MonoType *type, *cached;
1308 gboolean byref = FALSE;
1309 gboolean pinned = FALSE;
1310 const char *tmp_ptr;
1315 * According to the spec, custom modifiers should come before the byref
1316 * flag, but the IL produced by ilasm from the following signature:
1317 * object modopt(...) &
1318 * starts with a byref flag, followed by the modifiers. (bug #49802)
1319 * Also, this type seems to be different from 'object & modopt(...)'. Maybe
1320 * it would be better to treat byref as real type constructor instead of
1322 * Also, pinned should come before anything else, but some MSV++ produced
1323 * assemblies violate this (#bug 61990).
1326 /* Count the modifiers first */
1331 case MONO_TYPE_PINNED:
1332 case MONO_TYPE_BYREF:
1335 case MONO_TYPE_CMOD_REQD:
1336 case MONO_TYPE_CMOD_OPT:
1338 mono_metadata_parse_custom_mod (m, NULL, tmp_ptr, &tmp_ptr);
1346 type = g_malloc0 (sizeof (MonoType) + ((gint32)count - MONO_ZERO_LEN_ARRAY) * sizeof (MonoCustomMod));
1347 type->num_mods = count;
1349 g_warning ("got more than 64 modifiers in type");
1353 memset (type, 0, sizeof (MonoType));
1356 /* Parse pinned, byref and custom modifiers */
1361 case MONO_TYPE_PINNED:
1365 case MONO_TYPE_BYREF:
1369 case MONO_TYPE_CMOD_REQD:
1370 case MONO_TYPE_CMOD_OPT:
1371 mono_metadata_parse_custom_mod (m, &(type->modifiers [count]), ptr, &ptr);
1379 type->attrs = opt_attrs;
1380 type->byref = byref;
1381 type->pinned = pinned ? 1 : 0;
1383 do_mono_metadata_parse_type (type, m, generic_context, ptr, &ptr);
1389 /* FIXME: remove the != MONO_PARSE_PARAM condition, this accounts for
1390 * almost 10k (about 2/3rds) of all MonoType's we create.
1392 if (mode != MONO_PARSE_PARAM && !type->num_mods) {
1393 /* no need to free type here, because it is on the stack */
1394 if ((type->type == MONO_TYPE_CLASS || type->type == MONO_TYPE_VALUETYPE) && !type->pinned && !type->attrs) {
1396 return &type->data.klass->this_arg;
1398 return &type->data.klass->byval_arg;
1400 /* No need to use locking since nobody is modifying the hash table */
1401 if ((cached = g_hash_table_lookup (type_cache, type)))
1405 /*printf ("%x%c %s\n", type->attrs, type->pinned ? 'p' : ' ', mono_type_full_name (type));*/
1408 type = g_memdup (&stype, sizeof (MonoType));
1413 mono_metadata_parse_type (MonoImage *m, MonoParseTypeMode mode, short opt_attrs,
1414 const char *ptr, const char **rptr)
1416 return mono_metadata_parse_type_full (m, NULL, mode, opt_attrs, ptr, rptr);
1420 * mono_metadata_parse_signature:
1421 * @image: metadata context
1422 * @toke: metadata token
1424 * Decode a method signature stored in the STANDALONESIG table
1426 * Returns: a MonoMethodSignature describing the signature.
1428 MonoMethodSignature *
1429 mono_metadata_parse_signature_full (MonoImage *image, MonoGenericContext *generic_context, guint32 token)
1431 MonoTableInfo *tables = image->tables;
1432 guint32 idx = mono_metadata_token_index (token);
1437 return mono_lookup_dynamic_token (image, token);
1439 g_assert (mono_metadata_token_table(token) == MONO_TABLE_STANDALONESIG);
1441 sig = mono_metadata_decode_row_col (&tables [MONO_TABLE_STANDALONESIG], idx - 1, 0);
1443 ptr = mono_metadata_blob_heap (image, sig);
1444 mono_metadata_decode_blob_size (ptr, &ptr);
1446 return mono_metadata_parse_method_signature_full (image, generic_context, FALSE, ptr, NULL);
1449 MonoMethodSignature *
1450 mono_metadata_parse_signature (MonoImage *image, guint32 token)
1452 return mono_metadata_parse_signature_full (image, NULL, token);
1455 MonoMethodSignature*
1456 mono_metadata_signature_alloc (MonoImage *m, guint32 nparams)
1458 MonoMethodSignature *sig;
1460 /* later we want to allocate signatures with mempools */
1461 sig = g_malloc0 (sizeof (MonoMethodSignature) + ((gint32)nparams - MONO_ZERO_LEN_ARRAY) * sizeof (MonoType*));
1462 sig->param_count = nparams;
1463 sig->sentinelpos = -1;
1468 MonoMethodSignature*
1469 mono_metadata_signature_dup (MonoMethodSignature *sig)
1473 sigsize = sizeof (MonoMethodSignature) + sig->param_count * sizeof (MonoType *);
1474 return g_memdup (sig, sigsize);
1478 * mono_metadata_parse_method_signature:
1479 * @m: metadata context
1480 * @def: the MethodDef index or 0 for Ref signatures.
1481 * @ptr: pointer to the signature metadata representation
1482 * @rptr: pointer updated to match the end of the decoded stream
1484 * Decode a method signature stored at @ptr.
1486 * Returns: a MonoMethodSignature describing the signature.
1488 MonoMethodSignature *
1489 mono_metadata_parse_method_signature_full (MonoImage *m, MonoGenericContext *generic_context,
1490 int def, const char *ptr, const char **rptr)
1492 MonoMethodSignature *method;
1493 int i, ret_attrs = 0, *pattrs = NULL;
1494 guint32 hasthis = 0, explicit_this = 0, call_convention, param_count;
1495 guint32 gen_param_count = 0;
1496 gboolean is_open = FALSE;
1497 MonoGenericContext *context = NULL;
1500 gen_param_count = 1;
1505 call_convention = *ptr & 0x0F;
1507 if (gen_param_count)
1508 gen_param_count = mono_metadata_decode_value (ptr, &ptr);
1509 param_count = mono_metadata_decode_value (ptr, &ptr);
1510 pattrs = g_new0 (int, param_count);
1513 MonoTableInfo *paramt = &m->tables [MONO_TABLE_PARAM];
1514 MonoTableInfo *methodt = &m->tables [MONO_TABLE_METHOD];
1515 guint32 cols [MONO_PARAM_SIZE];
1516 guint lastp, param_index = mono_metadata_decode_row_col (methodt, def - 1, MONO_METHOD_PARAMLIST);
1518 if (def < methodt->rows)
1519 lastp = mono_metadata_decode_row_col (methodt, def, MONO_METHOD_PARAMLIST);
1521 lastp = paramt->rows + 1;
1522 for (i = param_index; i < lastp; ++i) {
1523 mono_metadata_decode_row (paramt, i - 1, cols, MONO_PARAM_SIZE);
1524 if (!cols [MONO_PARAM_SEQUENCE])
1525 ret_attrs = cols [MONO_PARAM_FLAGS];
1527 pattrs [cols [MONO_PARAM_SEQUENCE] - 1] = cols [MONO_PARAM_FLAGS];
1530 method = mono_metadata_signature_alloc (m, param_count);
1531 method->hasthis = hasthis;
1532 method->explicit_this = explicit_this;
1533 method->call_convention = call_convention;
1534 method->generic_param_count = gen_param_count;
1536 if (gen_param_count)
1537 method->has_type_parameters = 1;
1539 if (gen_param_count && (!generic_context || !generic_context->container->is_method)) {
1540 MonoGenericContainer *container = g_new0 (MonoGenericContainer, 1);
1542 if (generic_context)
1543 container->parent = generic_context->container;
1544 container->is_signature = 1;
1546 context = &container->context;
1547 container->context.container = container;
1549 container->type_argc = gen_param_count;
1550 container->type_params = g_new0 (MonoGenericParam, gen_param_count);
1552 for (i = 0; i < gen_param_count; i++) {
1553 container->type_params [i].owner = container;
1554 container->type_params [i].num = i;
1557 context = generic_context;
1559 if (call_convention != 0xa) {
1560 method->ret = mono_metadata_parse_type_full (m, context, MONO_PARSE_RET, ret_attrs, ptr, &ptr);
1561 is_open = mono_class_is_open_constructed_type (method->ret);
1564 if (method->param_count) {
1565 method->sentinelpos = -1;
1567 for (i = 0; i < method->param_count; ++i) {
1568 if (*ptr == MONO_TYPE_SENTINEL) {
1569 if (method->call_convention != MONO_CALL_VARARG || def)
1570 g_error ("found sentinel for methoddef or no vararg method");
1571 method->sentinelpos = i;
1574 method->params [i] = mono_metadata_parse_type_full (
1575 m, context, MONO_PARSE_PARAM, pattrs [i], ptr, &ptr);
1577 is_open = mono_class_is_open_constructed_type (method->params [i]);
1581 method->has_type_parameters = is_open;
1583 if (def && (method->call_convention == MONO_CALL_VARARG))
1584 method->sentinelpos = method->param_count;
1591 * Add signature to a cache and increase ref count...
1596 MonoMethodSignature *
1597 mono_metadata_parse_method_signature (MonoImage *m, int def, const char *ptr, const char **rptr)
1599 return mono_metadata_parse_method_signature_full (m, NULL, def, ptr, rptr);
1603 * mono_metadata_free_method_signature:
1604 * @sig: signature to destroy
1606 * Free the memory allocated in the signature @sig.
1609 mono_metadata_free_method_signature (MonoMethodSignature *sig)
1612 mono_metadata_free_type (sig->ret);
1613 for (i = 0; i < sig->param_count; ++i)
1614 mono_metadata_free_type (sig->params [i]);
1620 mono_metadata_lookup_generic_inst (MonoGenericInst *ginst)
1622 MonoGenericInst *cached;
1625 cached = g_hash_table_lookup (generic_inst_cache, ginst);
1627 for (i = 0; i < ginst->type_argc; i++)
1628 mono_metadata_free_type (ginst->type_argv [i]);
1629 g_free (ginst->type_argv);
1634 ginst->id = ++next_generic_inst_id;
1635 g_hash_table_insert (generic_inst_cache, ginst, ginst);
1641 mono_metadata_lookup_generic_class (MonoGenericClass *gclass)
1643 MonoGenericClass *cached;
1645 cached = g_hash_table_lookup (generic_class_cache, gclass);
1649 g_hash_table_insert (generic_class_cache, gclass, gclass);
1654 mono_metadata_inflate_generic_inst (MonoGenericInst *ginst, MonoGenericContext *context)
1656 MonoGenericInst *nginst;
1659 nginst = g_new0 (MonoGenericInst, 1);
1660 nginst->type_argc = ginst->type_argc;
1661 nginst->type_argv = g_new0 (MonoType*, nginst->type_argc);
1662 nginst->is_reference = 1;
1664 for (i = 0; i < nginst->type_argc; i++) {
1665 MonoType *t = mono_class_inflate_generic_type (ginst->type_argv [i], context);
1667 if (!nginst->is_open)
1668 nginst->is_open = mono_class_is_open_constructed_type (t);
1669 if (nginst->is_reference)
1670 nginst->is_reference = MONO_TYPE_IS_REFERENCE (t);
1672 nginst->type_argv [i] = t;
1675 return mono_metadata_lookup_generic_inst (nginst);
1679 mono_metadata_parse_generic_inst (MonoImage *m, MonoGenericContext *generic_context,
1680 int count, const char *ptr, const char **rptr)
1682 MonoGenericInst *ginst;
1685 ginst = g_new0 (MonoGenericInst, 1);
1686 ginst->type_argc = count;
1687 ginst->type_argv = g_new0 (MonoType*, count);
1688 ginst->is_reference = 1;
1690 for (i = 0; i < ginst->type_argc; i++) {
1691 MonoType *t = mono_metadata_parse_type_full (m, generic_context, MONO_PARSE_TYPE, 0, ptr, &ptr);
1693 ginst->type_argv [i] = t;
1694 if (!ginst->is_open)
1695 ginst->is_open = mono_class_is_open_constructed_type (t);
1696 if (ginst->is_reference)
1697 ginst->is_reference = MONO_TYPE_IS_REFERENCE (t);
1703 return mono_metadata_lookup_generic_inst (ginst);
1707 do_mono_metadata_parse_generic_class (MonoType *type, MonoImage *m, MonoGenericContext *generic_context,
1708 const char *ptr, const char **rptr)
1710 MonoGenericClass *gclass = g_new0 (MonoGenericClass, 1);
1711 MonoGenericClass *cached;
1716 type->data.generic_class = gclass;
1718 gclass->context = g_new0 (MonoGenericContext, 1);
1719 gclass->context->gclass = gclass;
1721 gclass->klass = g_new0 (MonoClass, 1);
1723 gtype = mono_metadata_parse_type_full (m, generic_context, MONO_PARSE_TYPE, 0, ptr, &ptr);
1724 gclass->container_class = gklass = mono_class_from_mono_type (gtype);
1726 g_assert ((gclass->context->container = gklass->generic_container) != NULL);
1727 count = mono_metadata_decode_value (ptr, &ptr);
1730 * Create the klass before parsing the type arguments.
1731 * This is required to support "recursive" definitions.
1732 * See mcs/tests/gen-23.cs for an example.
1735 mono_class_create_generic (gclass);
1737 gclass->inst = mono_metadata_parse_generic_inst (m, generic_context, count, ptr, &ptr);
1743 * We may be called multiple times on different metadata to create the same
1744 * instantiated type. This happens for instance if we're part of a method or
1745 * local variable signature.
1747 * It's important to return the same MonoGenericClass * for each particualar
1748 * instantiation of a generic type (ie "Stack<Int32>") to make static fields
1751 * According to the spec ($26.1.5), a static variable in a generic class
1752 * declaration is shared amongst all instances of the same closed constructed
1756 cached = g_hash_table_lookup (generic_class_cache, gclass);
1758 g_free (gclass->klass);
1761 type->data.generic_class = cached;
1764 g_hash_table_insert (generic_class_cache, gclass, gclass);
1766 mono_stats.generic_instance_count++;
1767 mono_stats.generics_metadata_size += sizeof (MonoGenericClass) +
1768 sizeof (MonoGenericContext) +
1769 gclass->inst->type_argc * sizeof (MonoType);
1774 * do_mono_metadata_parse_generic_param:
1775 * @generic_container: Our MonoClass's or MonoMethodNormal's MonoGenericContainer;
1776 * see mono_metadata_parse_type_full() for details.
1777 * Internal routine to parse a generic type parameter.
1779 static MonoGenericParam *
1780 mono_metadata_parse_generic_param (MonoImage *m, MonoGenericContext *generic_context,
1781 gboolean is_mvar, const char *ptr, const char **rptr)
1783 MonoGenericContainer *generic_container;
1786 index = mono_metadata_decode_value (ptr, &ptr);
1790 g_assert (generic_context);
1791 if (generic_context->gmethod)
1792 generic_container = generic_context->gmethod->container;
1793 else if (generic_context->gclass)
1794 generic_container = generic_context->gclass->container_class->generic_container;
1796 generic_container = generic_context->container;
1799 g_assert (generic_container);
1800 if (generic_container->parent) {
1802 * The current MonoGenericContainer is a generic method -> its `parent'
1803 * points to the containing class'es container.
1805 generic_container = generic_container->parent;
1807 g_assert (generic_container && !generic_container->is_method);
1808 g_assert (index < generic_container->type_argc);
1810 return &generic_container->type_params [index];
1812 g_assert (generic_container && (generic_container->is_method || generic_container->is_signature));
1813 g_assert (index < generic_container->type_argc);
1815 return &generic_container->type_params [index];
1820 * do_mono_metadata_parse_type:
1821 * @type: MonoType to be filled in with the return value
1823 * Internal routine used to "fill" the contents of @type from an
1824 * allocated pointer. This is done this way to avoid doing too
1825 * many mini-allocations (particularly for the MonoFieldType which
1826 * most of the time is just a MonoType, but sometimes might be augmented).
1828 * This routine is used by mono_metadata_parse_type and
1829 * mono_metadata_parse_field_type
1831 * This extracts a Type as specified in Partition II (22.2.12)
1834 do_mono_metadata_parse_type (MonoType *type, MonoImage *m, MonoGenericContext *generic_context,
1835 const char *ptr, const char **rptr)
1837 type->type = mono_metadata_decode_value (ptr, &ptr);
1839 switch (type->type){
1840 case MONO_TYPE_VOID:
1841 case MONO_TYPE_BOOLEAN:
1842 case MONO_TYPE_CHAR:
1855 case MONO_TYPE_STRING:
1856 case MONO_TYPE_OBJECT:
1857 case MONO_TYPE_TYPEDBYREF:
1859 case MONO_TYPE_VALUETYPE:
1860 case MONO_TYPE_CLASS: {
1862 token = mono_metadata_parse_typedef_or_ref (m, ptr, &ptr);
1863 type->data.klass = mono_class_get (m, token);
1866 case MONO_TYPE_SZARRAY: {
1867 MonoType *etype = mono_metadata_parse_type_full (m, generic_context, MONO_PARSE_MOD_TYPE, 0, ptr, &ptr);
1868 type->data.klass = mono_class_from_mono_type (etype);
1869 mono_metadata_free_type (etype);
1873 type->data.type = mono_metadata_parse_type_full (m, generic_context, MONO_PARSE_MOD_TYPE, 0, ptr, &ptr);
1875 case MONO_TYPE_FNPTR:
1876 type->data.method = mono_metadata_parse_method_signature_full (m, generic_context, 0, ptr, &ptr);
1878 case MONO_TYPE_ARRAY:
1879 type->data.array = mono_metadata_parse_array_full (m, generic_context, ptr, &ptr);
1882 case MONO_TYPE_MVAR:
1883 type->data.generic_param = mono_metadata_parse_generic_param (m, generic_context, TRUE, ptr, &ptr);
1887 type->data.generic_param = mono_metadata_parse_generic_param (m, generic_context, FALSE, ptr, &ptr);
1890 case MONO_TYPE_GENERICINST:
1891 do_mono_metadata_parse_generic_class (type, m, generic_context, ptr, &ptr);
1895 g_error ("type 0x%02x not handled in do_mono_metadata_parse_type", type->type);
1903 * mono_metadata_free_type:
1904 * @type: type to free
1906 * Free the memory allocated for type @type.
1909 mono_metadata_free_type (MonoType *type)
1911 if (type >= builtin_types && type < builtin_types + NBUILTIN_TYPES ())
1914 switch (type->type){
1915 case MONO_TYPE_OBJECT:
1916 case MONO_TYPE_STRING:
1917 if (!type->data.klass)
1920 case MONO_TYPE_CLASS:
1921 case MONO_TYPE_VALUETYPE:
1922 if (type == &type->data.klass->byval_arg || type == &type->data.klass->this_arg)
1926 mono_metadata_free_type (type->data.type);
1928 case MONO_TYPE_FNPTR:
1929 mono_metadata_free_method_signature (type->data.method);
1931 case MONO_TYPE_ARRAY:
1932 mono_metadata_free_array (type->data.array);
1940 hex_dump (const char *buffer, int base, int count)
1942 int show_header = 1;
1950 for (i = 0; i < count; i++){
1953 printf ("\n0x%08x: ", (unsigned char) base + i);
1955 printf ("%02x ", (unsigned char) (buffer [i]));
1962 * @mh: The Method header
1963 * @ptr: Points to the beginning of the Section Data (25.3)
1966 parse_section_data (MonoImage *m, MonoMethodHeader *mh, const unsigned char *ptr)
1968 unsigned char sect_data_flags;
1969 const unsigned char *sptr;
1971 guint32 sect_data_len;
1974 /* align on 32-bit boundary */
1975 /* FIXME: not 64-bit clean code */
1976 sptr = ptr = dword_align (ptr);
1977 sect_data_flags = *ptr;
1980 is_fat = sect_data_flags & METHOD_HEADER_SECTION_FAT_FORMAT;
1982 sect_data_len = (ptr [2] << 16) | (ptr [1] << 8) | ptr [0];
1985 sect_data_len = ptr [0];
1989 g_print ("flags: %02x, len: %d\n", sect_data_flags, sect_data_len);
1990 hex_dump (sptr, 0, sect_data_len+8);
1991 g_print ("\nheader: ");
1992 hex_dump (sptr-4, 0, 4);
1996 if (sect_data_flags & METHOD_HEADER_SECTION_EHTABLE) {
1997 const unsigned char *p = dword_align (ptr);
1999 mh->num_clauses = is_fat ? sect_data_len / 24: sect_data_len / 12;
2000 /* we could just store a pointer if we don't need to byteswap */
2001 mh->clauses = g_new0 (MonoExceptionClause, mh->num_clauses);
2002 for (i = 0; i < mh->num_clauses; ++i) {
2003 MonoExceptionClause *ec = &mh->clauses [i];
2006 ec->flags = read32 (p);
2008 ec->try_offset = read32 (p);
2010 ec->try_len = read32 (p);
2012 ec->handler_offset = read32 (p);
2014 ec->handler_len = read32 (p);
2016 tof_value = read32 (p);
2019 ec->flags = read16 (p);
2021 ec->try_offset = read16 (p);
2025 ec->handler_offset = read16 (p);
2027 ec->handler_len = *p;
2029 tof_value = read32 (p);
2032 if (ec->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
2033 ec->data.filter_offset = tof_value;
2034 } else if (ec->flags == MONO_EXCEPTION_CLAUSE_NONE) {
2035 ec->data.catch_class = tof_value? mono_class_get (m, tof_value): 0;
2037 ec->data.catch_class = NULL;
2039 /* g_print ("try %d: %x %04x-%04x %04x\n", i, ec->flags, ec->try_offset, ec->try_offset+ec->try_len, ec->try_len); */
2043 if (sect_data_flags & METHOD_HEADER_SECTION_MORE_SECTS)
2044 ptr += sect_data_len - 4; /* LAMESPEC: it seems the size includes the header */
2051 * mono_metadata_parse_mh:
2052 * @m: metadata context
2053 * @ptr: pointer to the method header.
2055 * Decode the method header at @ptr, including pointer to the IL code,
2056 * info about local variables and optional exception tables.
2058 * Returns: a MonoMethodHeader.
2061 mono_metadata_parse_mh_full (MonoImage *m, MonoGenericContext *generic_context, const char *ptr)
2063 MonoMethodHeader *mh;
2064 unsigned char flags = *(const unsigned char *) ptr;
2065 unsigned char format = flags & METHOD_HEADER_FORMAT_MASK;
2067 guint32 local_var_sig_tok, max_stack, code_size, init_locals;
2068 const unsigned char *code;
2071 g_return_val_if_fail (ptr != NULL, NULL);
2074 case METHOD_HEADER_TINY_FORMAT:
2075 mh = g_new0 (MonoMethodHeader, 1);
2078 local_var_sig_tok = 0;
2079 mh->code_size = flags >> 2;
2082 case METHOD_HEADER_TINY_FORMAT1:
2083 mh = g_new0 (MonoMethodHeader, 1);
2086 local_var_sig_tok = 0;
2089 * The spec claims 3 bits, but the Beta2 is
2092 mh->code_size = flags >> 2;
2095 case METHOD_HEADER_FAT_FORMAT:
2096 fat_flags = read16 (ptr);
2098 hsize = (fat_flags >> 12) & 0xf;
2099 max_stack = read16 (ptr);
2101 code_size = read32 (ptr);
2103 local_var_sig_tok = read32 (ptr);
2106 if (fat_flags & METHOD_HEADER_INIT_LOCALS)
2113 if (!(fat_flags & METHOD_HEADER_MORE_SECTS))
2117 * There are more sections
2119 ptr = code + code_size;
2127 if (local_var_sig_tok) {
2128 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
2129 const char *locals_ptr;
2130 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
2131 int len=0, i, bsize;
2133 mono_metadata_decode_row (t, (local_var_sig_tok & 0xffffff)-1, cols, 1);
2134 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
2135 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
2136 if (*locals_ptr != 0x07)
2137 g_warning ("wrong signature for locals blob");
2139 len = mono_metadata_decode_value (locals_ptr, &locals_ptr);
2140 mh = g_malloc0 (sizeof (MonoMethodHeader) + (len - MONO_ZERO_LEN_ARRAY) * sizeof (MonoType*));
2141 mh->num_locals = len;
2142 for (i = 0; i < len; ++i)
2143 mh->locals [i] = mono_metadata_parse_type_full (
2144 m, generic_context, MONO_PARSE_LOCAL, 0, locals_ptr, &locals_ptr);
2146 mh = g_new0 (MonoMethodHeader, 1);
2149 mh->code_size = code_size;
2150 mh->max_stack = max_stack;
2151 mh->init_locals = init_locals;
2152 if (fat_flags & METHOD_HEADER_MORE_SECTS)
2153 parse_section_data (m, mh, (const unsigned char*)ptr);
2158 mono_metadata_parse_mh (MonoImage *m, const char *ptr)
2160 return mono_metadata_parse_mh_full (m, NULL, ptr);
2164 * mono_metadata_free_mh:
2165 * @mh: a method header
2167 * Free the memory allocated for the method header.
2170 mono_metadata_free_mh (MonoMethodHeader *mh)
2173 for (i = 0; i < mh->num_locals; ++i)
2174 mono_metadata_free_type (mh->locals[i]);
2175 g_free (mh->clauses);
2180 * mono_metadata_parse_field_type:
2181 * @m: metadata context to extract information from
2182 * @ptr: pointer to the field signature
2183 * @rptr: pointer updated to match the end of the decoded stream
2185 * Parses the field signature, and returns the type information for it.
2187 * Returns: The MonoType that was extracted from @ptr.
2190 mono_metadata_parse_field_type (MonoImage *m, short field_flags, const char *ptr, const char **rptr)
2192 return mono_metadata_parse_type (m, MONO_PARSE_FIELD, field_flags, ptr, rptr);
2196 * mono_metadata_parse_param:
2197 * @m: metadata context to extract information from
2198 * @ptr: pointer to the param signature
2199 * @rptr: pointer updated to match the end of the decoded stream
2201 * Parses the param signature, and returns the type information for it.
2203 * Returns: The MonoType that was extracted from @ptr.
2206 mono_metadata_parse_param (MonoImage *m, const char *ptr, const char **rptr)
2208 return mono_metadata_parse_type (m, MONO_PARSE_PARAM, 0, ptr, rptr);
2212 * mono_metadata_token_from_dor:
2213 * @dor_token: A TypeDefOrRef coded index
2215 * dor_token is a TypeDefOrRef coded index: it contains either
2216 * a TypeDef, TypeRef or TypeSpec in the lower bits, and the upper
2217 * bits contain an index into the table.
2219 * Returns: an expanded token
2222 mono_metadata_token_from_dor (guint32 dor_index)
2226 table = dor_index & 0x03;
2227 idx = dor_index >> 2;
2230 case 0: /* TypeDef */
2231 return MONO_TOKEN_TYPE_DEF | idx;
2233 case 1: /* TypeRef */
2234 return MONO_TOKEN_TYPE_REF | idx;
2236 case 2: /* TypeSpec */
2237 return MONO_TOKEN_TYPE_SPEC | idx;
2240 g_assert_not_reached ();
2247 * We use this to pass context information to the row locator
2250 int idx; /* The index that we are trying to locate */
2251 int col_idx; /* The index in the row where idx may be stored */
2252 MonoTableInfo *t; /* pointer to the table */
2257 * How the row locator works.
2262 * ___|___------> _______
2265 * A column in the rows of table A references an index in table B.
2266 * For example A may be the TYPEDEF table and B the METHODDEF table.
2268 * Given an index in table B we want to get the row in table A
2269 * where the column n references our index in B.
2271 * In the locator_t structure:
2273 * col_idx is the column number
2274 * index is the index in table B
2275 * result will be the index in table A
2278 * Table A Table B column (in table A)
2279 * TYPEDEF METHODDEF MONO_TYPEDEF_METHOD_LIST
2280 * TYPEDEF FIELD MONO_TYPEDEF_FIELD_LIST
2281 * PROPERTYMAP PROPERTY MONO_PROPERTY_MAP_PROPERTY_LIST
2282 * INTERFIMPL TYPEDEF MONO_INTERFACEIMPL_CLASS
2283 * METHODSEM PROPERTY ASSOCIATION (encoded index)
2285 * Note that we still don't support encoded indexes.
2289 typedef_locator (const void *a, const void *b)
2291 locator_t *loc = (locator_t *) a;
2292 const char *bb = (const char *) b;
2293 int typedef_index = (bb - loc->t->base) / loc->t->row_size;
2294 guint32 col, col_next;
2296 col = mono_metadata_decode_row_col (loc->t, typedef_index, loc->col_idx);
2302 * Need to check that the next row is valid.
2304 if (typedef_index + 1 < loc->t->rows) {
2305 col_next = mono_metadata_decode_row_col (loc->t, typedef_index + 1, loc->col_idx);
2306 if (loc->idx >= col_next)
2309 if (col == col_next)
2313 loc->result = typedef_index;
2319 table_locator (const void *a, const void *b)
2321 locator_t *loc = (locator_t *) a;
2322 const char *bb = (const char *) b;
2323 guint32 table_index = (bb - loc->t->base) / loc->t->row_size;
2326 col = mono_metadata_decode_row_col (loc->t, table_index, loc->col_idx);
2328 if (loc->idx == col) {
2329 loc->result = table_index;
2339 declsec_locator (const void *a, const void *b)
2341 locator_t *loc = (locator_t *) a;
2342 const char *bb = (const char *) b;
2343 guint32 table_index = (bb - loc->t->base) / loc->t->row_size;
2346 col = mono_metadata_decode_row_col (loc->t, table_index, loc->col_idx);
2348 if (loc->idx == col) {
2349 loc->result = table_index;
2359 * mono_metadata_typedef_from_field:
2360 * @meta: metadata context
2361 * @index: FieldDef token
2363 * Returns: the 1-based index into the TypeDef table of the type that
2364 * declared the field described by @index, or 0 if not found.
2367 mono_metadata_typedef_from_field (MonoImage *meta, guint32 index)
2369 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_TYPEDEF];
2375 loc.idx = mono_metadata_token_index (index);
2376 loc.col_idx = MONO_TYPEDEF_FIELD_LIST;
2379 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator))
2380 g_assert_not_reached ();
2382 /* loc_result is 0..1, needs to be mapped to table index (that is +1) */
2383 return loc.result + 1;
2387 * mono_metadata_typedef_from_method:
2388 * @meta: metadata context
2389 * @index: MethodDef token
2391 * Returns: the 1-based index into the TypeDef table of the type that
2392 * declared the method described by @index. 0 if not found.
2395 mono_metadata_typedef_from_method (MonoImage *meta, guint32 index)
2397 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_TYPEDEF];
2403 loc.idx = mono_metadata_token_index (index);
2404 loc.col_idx = MONO_TYPEDEF_METHOD_LIST;
2407 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator))
2408 g_assert_not_reached ();
2410 /* loc_result is 0..1, needs to be mapped to table index (that is +1) */
2411 return loc.result + 1;
2415 * mono_metadata_interfaces_from_typedef:
2416 * @meta: metadata context
2417 * @index: typedef token
2419 * Returns: and array of interfaces that the @index typedef token implements.
2420 * The number of elemnts in the array is returned in @count.
2423 mono_metadata_interfaces_from_typedef_full (MonoImage *meta, guint32 index, guint *count, MonoGenericContext *context)
2425 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_INTERFACEIMPL];
2428 guint32 cols [MONO_INTERFACEIMPL_SIZE];
2436 loc.idx = mono_metadata_token_index (index);
2437 loc.col_idx = MONO_INTERFACEIMPL_CLASS;
2440 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
2445 * We may end up in the middle of the rows...
2448 if (loc.idx == mono_metadata_decode_row_col (tdef, start - 1, MONO_INTERFACEIMPL_CLASS))
2455 while (start < tdef->rows) {
2456 mono_metadata_decode_row (tdef, start, cols, MONO_INTERFACEIMPL_SIZE);
2457 if (cols [MONO_INTERFACEIMPL_CLASS] != loc.idx)
2459 result = g_renew (MonoClass*, result, i + 1);
2460 result [i] = mono_class_get_full (
2461 meta, mono_metadata_token_from_dor (cols [MONO_INTERFACEIMPL_INTERFACE]), context);
2469 mono_metadata_interfaces_from_typedef (MonoImage *meta, guint32 index, guint *count)
2471 return mono_metadata_interfaces_from_typedef_full (meta, index, count, NULL);
2475 * mono_metadata_nested_in_typedef:
2476 * @meta: metadata context
2477 * @index: typedef token
2479 * Returns: the 1-based index into the TypeDef table of the type
2480 * where the type described by @index is nested.
2481 * Retruns 0 if @index describes a non-nested type.
2484 mono_metadata_nested_in_typedef (MonoImage *meta, guint32 index)
2486 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_NESTEDCLASS];
2492 loc.idx = mono_metadata_token_index (index);
2493 loc.col_idx = MONO_NESTED_CLASS_NESTED;
2496 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
2499 /* loc_result is 0..1, needs to be mapped to table index (that is +1) */
2500 return mono_metadata_decode_row_col (tdef, loc.result, MONO_NESTED_CLASS_ENCLOSING) | MONO_TOKEN_TYPE_DEF;
2504 * mono_metadata_nesting_typedef:
2505 * @meta: metadata context
2506 * @index: typedef token
2508 * Returns: the 1-based index into the TypeDef table of the first type
2509 * that is nested inside the type described by @index. The search starts at
2510 * @start_index. returns 0 if no such type is found.
2513 mono_metadata_nesting_typedef (MonoImage *meta, guint32 index, guint32 start_index)
2515 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_NESTEDCLASS];
2517 guint32 class_index = mono_metadata_token_index (index);
2522 start = start_index;
2524 while (start <= tdef->rows) {
2525 if (class_index == mono_metadata_decode_row_col (tdef, start - 1, MONO_NESTED_CLASS_ENCLOSING))
2531 if (start > tdef->rows)
2538 * mono_metadata_packing_from_typedef:
2539 * @meta: metadata context
2540 * @index: token representing a type
2542 * Returns: the info stored in the ClassLAyout table for the given typedef token
2543 * into the @packing and @size pointers.
2544 * Returns 0 if the info is not found.
2547 mono_metadata_packing_from_typedef (MonoImage *meta, guint32 index, guint32 *packing, guint32 *size)
2549 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_CLASSLAYOUT];
2551 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
2556 loc.idx = mono_metadata_token_index (index);
2557 loc.col_idx = MONO_CLASS_LAYOUT_PARENT;
2560 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
2563 mono_metadata_decode_row (tdef, loc.result, cols, MONO_CLASS_LAYOUT_SIZE);
2565 *packing = cols [MONO_CLASS_LAYOUT_PACKING_SIZE];
2567 *size = cols [MONO_CLASS_LAYOUT_CLASS_SIZE];
2569 /* loc_result is 0..1, needs to be mapped to table index (that is +1) */
2570 return loc.result + 1;
2574 * mono_metadata_custom_attrs_from_index:
2575 * @meta: metadata context
2576 * @index: token representing the parent
2578 * Returns: the 1-based index into the CustomAttribute table of the first
2579 * attribute which belongs to the metadata object described by @index.
2580 * Returns 0 if no such attribute is found.
2583 mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index)
2585 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_CUSTOMATTRIBUTE];
2592 loc.col_idx = MONO_CUSTOM_ATTR_PARENT;
2595 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
2598 /* Find the first entry by searching backwards */
2599 while ((loc.result > 0) && (mono_metadata_decode_row_col (tdef, loc.result - 1, MONO_CUSTOM_ATTR_PARENT) == index))
2602 /* loc_result is 0..1, needs to be mapped to table index (that is +1) */
2603 return loc.result + 1;
2607 * mono_metadata_declsec_from_index:
2608 * @meta: metadata context
2609 * @index: token representing the parent
2611 * Returns: the 0-based index into the DeclarativeSecurity table of the first
2612 * attribute which belongs to the metadata object described by @index.
2613 * Returns -1 if no such attribute is found.
2616 mono_metadata_declsec_from_index (MonoImage *meta, guint32 index)
2618 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_DECLSECURITY];
2625 loc.col_idx = MONO_DECL_SECURITY_PARENT;
2628 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, declsec_locator))
2631 /* Find the first entry by searching backwards */
2632 while ((loc.result > 0) && (mono_metadata_decode_row_col (tdef, loc.result - 1, MONO_DECL_SECURITY_PARENT) == index))
2640 mono_backtrace (int limit)
2645 backtrace (array, limit);
2646 names = backtrace_symbols (array, limit);
2647 for (i =0; i < limit; ++i) {
2648 g_print ("\t%s\n", names [i]);
2655 /*#define __alignof__(a) sizeof(a)*/
2656 #define __alignof__(type) G_STRUCT_OFFSET(struct { char c; type x; }, x)
2661 * @t: the type to return the size of
2663 * Returns: the number of bytes required to hold an instance of this
2667 mono_type_size (MonoType *t, gint *align)
2674 *align = __alignof__(gpointer);
2675 return sizeof (gpointer);
2679 case MONO_TYPE_VOID:
2682 case MONO_TYPE_BOOLEAN:
2683 *align = __alignof__(gint8);
2687 *align = __alignof__(gint8);
2689 case MONO_TYPE_CHAR:
2692 *align = __alignof__(gint16);
2696 *align = __alignof__(gint32);
2699 *align = __alignof__(float);
2703 *align = __alignof__(gint64);
2706 *align = __alignof__(double);
2710 *align = __alignof__(gpointer);
2711 return sizeof (gpointer);
2712 case MONO_TYPE_STRING:
2713 *align = __alignof__(gpointer);
2714 return sizeof (gpointer);
2715 case MONO_TYPE_OBJECT:
2716 *align = __alignof__(gpointer);
2717 return sizeof (gpointer);
2718 case MONO_TYPE_VALUETYPE: {
2719 if (t->data.klass->enumtype)
2720 return mono_type_size (t->data.klass->enum_basetype, align);
2722 return mono_class_value_size (t->data.klass, align);
2724 case MONO_TYPE_CLASS:
2725 case MONO_TYPE_SZARRAY:
2727 case MONO_TYPE_FNPTR:
2728 case MONO_TYPE_ARRAY:
2729 *align = __alignof__(gpointer);
2730 return sizeof (gpointer);
2731 case MONO_TYPE_TYPEDBYREF:
2732 return mono_class_value_size (mono_defaults.typed_reference_class, align);
2733 case MONO_TYPE_GENERICINST: {
2734 MonoGenericClass *gclass = t->data.generic_class;
2736 g_assert (!gclass->inst->is_open && !gclass->klass->generic_container);
2738 if (gclass->container_class->valuetype) {
2739 if (gclass->container_class->enumtype)
2740 return mono_type_size (gclass->container_class->enum_basetype, align);
2742 return mono_class_value_size (gclass->klass, align);
2744 *align = __alignof__(gpointer);
2745 return sizeof (gpointer);
2749 case MONO_TYPE_MVAR:
2750 *align = __alignof__(gpointer);
2751 return sizeof (gpointer);
2753 g_error ("mono_type_size: type 0x%02x unknown", t->type);
2759 * mono_type_stack_size:
2760 * @t: the type to return the size it uses on the stack
2762 * Returns: the number of bytes required to hold an instance of this
2763 * type on the runtime stack
2766 mono_type_stack_size (MonoType *t, gint *align)
2770 g_assert (t != NULL);
2776 *align = __alignof__(gpointer);
2777 return sizeof (gpointer);
2781 case MONO_TYPE_BOOLEAN:
2782 case MONO_TYPE_CHAR:
2791 case MONO_TYPE_STRING:
2792 case MONO_TYPE_OBJECT:
2793 case MONO_TYPE_CLASS:
2794 case MONO_TYPE_SZARRAY:
2796 case MONO_TYPE_FNPTR:
2797 case MONO_TYPE_ARRAY:
2798 *align = __alignof__(gpointer);
2799 return sizeof (gpointer);
2800 case MONO_TYPE_TYPEDBYREF:
2801 *align = __alignof__(gpointer);
2802 return sizeof (gpointer) * 3;
2804 *align = __alignof__(float);
2805 return sizeof (float);
2808 *align = __alignof__(gint64);
2809 return sizeof (gint64);
2811 *align = __alignof__(double);
2812 return sizeof (double);
2813 case MONO_TYPE_VALUETYPE: {
2816 if (t->data.klass->enumtype)
2817 return mono_type_stack_size (t->data.klass->enum_basetype, align);
2819 size = mono_class_value_size (t->data.klass, align);
2821 *align = *align + __alignof__(gpointer) - 1;
2822 *align &= ~(__alignof__(gpointer) - 1);
2824 size += sizeof (gpointer) - 1;
2825 size &= ~(sizeof (gpointer) - 1);
2830 case MONO_TYPE_GENERICINST: {
2831 MonoGenericClass *gclass = t->data.generic_class;
2833 g_assert (!gclass->inst->is_open && !gclass->klass->generic_container);
2835 if (gclass->container_class->valuetype) {
2836 if (gclass->container_class->enumtype)
2837 return mono_type_stack_size (gclass->container_class->enum_basetype, align);
2839 guint32 size = mono_class_value_size (gclass->klass, align);
2841 *align = *align + __alignof__(gpointer) - 1;
2842 *align &= ~(__alignof__(gpointer) - 1);
2844 size += sizeof (gpointer) - 1;
2845 size &= ~(sizeof (gpointer) - 1);
2850 *align = __alignof__(gpointer);
2851 return sizeof (gpointer);
2855 g_error ("type 0x%02x unknown", t->type);
2861 mono_metadata_generic_class_is_valuetype (MonoGenericClass *gclass)
2863 return gclass->container_class->valuetype;
2867 _mono_metadata_generic_class_equal (const MonoGenericClass *g1, const MonoGenericClass *g2, gboolean signature_only)
2871 if ((g1->inst->type_argc != g2->inst->type_argc) || (g1->is_dynamic != g2->is_dynamic) ||
2872 (g1->inst->is_reference != g2->inst->is_reference))
2874 if (!mono_metadata_class_equal (g1->container_class, g2->container_class, signature_only))
2876 for (i = 0; i < g1->inst->type_argc; ++i) {
2877 if (!do_mono_metadata_type_equal (g1->inst->type_argv [i], g2->inst->type_argv [i], signature_only))
2884 mono_metadata_generic_method_hash (MonoGenericMethod *gmethod)
2886 return gmethod->inst->id;
2890 mono_metadata_generic_method_equal (MonoGenericMethod *g1, MonoGenericMethod *g2)
2892 return (g1->container == g2->container) && (g1->generic_class == g2->generic_class) &&
2893 (g1->inst == g2->inst);
2898 * mono_metadata_type_hash:
2901 * Computes an hash value for @t1 to be used in GHashTable.
2904 mono_metadata_type_hash (MonoType *t1)
2906 guint hash = t1->type;
2908 hash |= t1->byref << 6; /* do not collide with t1->type values */
2910 case MONO_TYPE_VALUETYPE:
2911 case MONO_TYPE_CLASS:
2912 case MONO_TYPE_SZARRAY:
2913 /* check if the distribution is good enough */
2914 return ((hash << 5) - hash) ^ g_str_hash (t1->data.klass->name);
2916 return ((hash << 5) - hash) ^ mono_metadata_type_hash (t1->data.type);
2917 case MONO_TYPE_ARRAY:
2918 return ((hash << 5) - hash) ^ mono_metadata_type_hash (&t1->data.array->eklass->byval_arg);
2919 case MONO_TYPE_GENERICINST:
2920 return ((hash << 5) - hash) ^ mono_generic_class_hash (t1->data.generic_class);
2926 mono_metadata_generic_param_equal (MonoGenericParam *p1, MonoGenericParam *p2, gboolean signature_only)
2930 if (p1->num != p2->num)
2933 g_assert (p1->owner && p2->owner);
2934 if (p1->owner == p2->owner)
2938 * If `signature_only' is true, we're comparing two (method) signatures.
2939 * In this case, the owner of two type parameters doesn't need to match.
2942 return signature_only;
2946 mono_metadata_class_equal (MonoClass *c1, MonoClass *c2, gboolean signature_only)
2950 if (c1->generic_class && c2->generic_class)
2951 return _mono_metadata_generic_class_equal (c1->generic_class, c2->generic_class, signature_only);
2952 if ((c1->byval_arg.type == MONO_TYPE_VAR) && (c2->byval_arg.type == MONO_TYPE_VAR))
2953 return mono_metadata_generic_param_equal (
2954 c1->byval_arg.data.generic_param, c2->byval_arg.data.generic_param, FALSE);
2955 if ((c1->byval_arg.type == MONO_TYPE_MVAR) && (c2->byval_arg.type == MONO_TYPE_MVAR))
2956 return mono_metadata_generic_param_equal (
2957 c1->byval_arg.data.generic_param, c2->byval_arg.data.generic_param, signature_only);
2962 * mono_metadata_type_equal:
2966 * Determine if @t1 and @t2 represent the same type.
2967 * Returns: #TRUE if @t1 and @t2 are equal.
2970 do_mono_metadata_type_equal (MonoType *t1, MonoType *t2, gboolean signature_only)
2972 if (t1->type != t2->type ||
2973 t1->byref != t2->byref)
2977 case MONO_TYPE_VOID:
2978 case MONO_TYPE_BOOLEAN:
2979 case MONO_TYPE_CHAR:
2990 case MONO_TYPE_STRING:
2993 case MONO_TYPE_OBJECT:
2994 case MONO_TYPE_TYPEDBYREF:
2996 case MONO_TYPE_VALUETYPE:
2997 case MONO_TYPE_CLASS:
2998 case MONO_TYPE_SZARRAY:
2999 return mono_metadata_class_equal (t1->data.klass, t2->data.klass, signature_only);
3001 return do_mono_metadata_type_equal (t1->data.type, t2->data.type, signature_only);
3002 case MONO_TYPE_ARRAY:
3003 if (t1->data.array->rank != t2->data.array->rank)
3005 return mono_metadata_class_equal (t1->data.array->eklass, t2->data.array->eklass, signature_only);
3006 case MONO_TYPE_GENERICINST:
3007 return _mono_metadata_generic_class_equal (
3008 t1->data.generic_class, t2->data.generic_class, signature_only);
3010 return mono_metadata_generic_param_equal (
3011 t1->data.generic_param, t2->data.generic_param, FALSE);
3012 case MONO_TYPE_MVAR:
3013 return mono_metadata_generic_param_equal (
3014 t1->data.generic_param, t2->data.generic_param, signature_only);
3016 g_error ("implement type compare for %0x!", t1->type);
3024 mono_metadata_type_equal (MonoType *t1, MonoType *t2)
3026 return do_mono_metadata_type_equal (t1, t2, FALSE);
3030 * mono_metadata_signature_equal:
3031 * @sig1: a signature
3032 * @sig2: another signature
3034 * Determine if @sig1 and @sig2 represent the same signature, with the
3035 * same number of arguments and the same types.
3036 * Returns: #TRUE if @sig1 and @sig2 are equal.
3039 mono_metadata_signature_equal (MonoMethodSignature *sig1, MonoMethodSignature *sig2)
3043 if (sig1->hasthis != sig2->hasthis ||
3044 sig1->param_count != sig2->param_count)
3048 * We're just comparing the signatures of two methods here:
3050 * If we have two generic methods `void Foo<U> (U u)' and `void Bar<V> (V v)',
3051 * U and V are equal here.
3053 * That's what the `signature_only' argument of do_mono_metadata_type_equal() is for.
3056 for (i = 0; i < sig1->param_count; i++) {
3057 MonoType *p1 = sig1->params[i];
3058 MonoType *p2 = sig2->params[i];
3060 /* if (p1->attrs != p2->attrs)
3063 if (!do_mono_metadata_type_equal (p1, p2, TRUE))
3067 if (!do_mono_metadata_type_equal (sig1->ret, sig2->ret, TRUE))
3073 mono_signature_hash (MonoMethodSignature *sig)
3075 guint i, res = sig->ret->type;
3077 for (i = 0; i < sig->param_count; i++)
3078 res = (res << 5) - res + sig->params[i]->type;
3084 * mono_metadata_encode_value:
3085 * @value: value to encode
3086 * @buf: buffer where to write the compressed representation
3087 * @endbuf: pointer updated to point at the end of the encoded output
3089 * Encodes the value @value in the compressed representation used
3090 * in metadata and stores the result in @buf. @buf needs to be big
3091 * enough to hold the data (4 bytes).
3094 mono_metadata_encode_value (guint32 value, char *buf, char **endbuf)
3100 else if (value < 0x4000) {
3101 p [0] = 0x80 | (value >> 8);
3102 p [1] = value & 0xff;
3105 p [0] = (value >> 24) | 0xc0;
3106 p [1] = (value >> 16) & 0xff;
3107 p [2] = (value >> 8) & 0xff;
3108 p [3] = value & 0xff;
3116 * mono_metadata_field_info:
3117 * @meta: the Image the field is defined in
3118 * @index: the index in the field table representing the field
3119 * @offset: a pointer to an integer where to store the offset that
3120 * may have been specified for the field in a FieldLayout table
3121 * @rva: a pointer to the RVA of the field data in the image that
3122 * may have been defined in a FieldRVA table
3123 * @marshal_spec: a pointer to the marshal spec that may have been
3124 * defined for the field in a FieldMarshal table.
3126 * Gather info for field @index that may have been defined in the FieldLayout,
3127 * FieldRVA and FieldMarshal tables.
3128 * Either of offset, rva and marshal_spec can be NULL if you're not interested
3132 mono_metadata_field_info (MonoImage *meta, guint32 index, guint32 *offset, guint32 *rva,
3133 MonoMarshalSpec **marshal_spec)
3135 MonoTableInfo *tdef;
3138 loc.idx = index + 1;
3140 tdef = &meta->tables [MONO_TABLE_FIELDLAYOUT];
3142 loc.col_idx = MONO_FIELD_LAYOUT_FIELD;
3145 if (tdef->base && bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
3146 *offset = mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_LAYOUT_OFFSET);
3148 *offset = (guint32)-1;
3152 tdef = &meta->tables [MONO_TABLE_FIELDRVA];
3154 loc.col_idx = MONO_FIELD_RVA_FIELD;
3157 if (tdef->base && bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
3159 * LAMESPEC: There is no signature, no nothing, just the raw data.
3161 *rva = mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_RVA_RVA);
3169 if ((p = mono_metadata_get_marshal_info (meta, index, TRUE))) {
3170 *marshal_spec = mono_metadata_parse_marshal_spec (meta, p);
3177 * mono_metadata_get_constant_index:
3178 * @meta: the Image the field is defined in
3179 * @index: the token that may have a row defined in the constants table
3180 * @hint: possible position for the row
3182 * @token must be a FieldDef, ParamDef or PropertyDef token.
3184 * Returns: the index into the Constants table or 0 if not found.
3187 mono_metadata_get_constant_index (MonoImage *meta, guint32 token, guint32 hint)
3189 MonoTableInfo *tdef;
3191 guint32 index = mono_metadata_token_index (token);
3193 tdef = &meta->tables [MONO_TABLE_CONSTANT];
3194 index <<= MONO_HASCONSTANT_BITS;
3195 switch (mono_metadata_token_table (token)) {
3196 case MONO_TABLE_FIELD:
3197 index |= MONO_HASCONSTANT_FIEDDEF;
3199 case MONO_TABLE_PARAM:
3200 index |= MONO_HASCONSTANT_PARAM;
3202 case MONO_TABLE_PROPERTY:
3203 index |= MONO_HASCONSTANT_PROPERTY;
3206 g_warning ("Not a valid token for the constant table: 0x%08x", token);
3210 loc.col_idx = MONO_CONSTANT_PARENT;
3213 if ((hint > 0) && (hint < tdef->rows) && (mono_metadata_decode_row_col (tdef, hint - 1, MONO_CONSTANT_PARENT) == index))
3216 if (tdef->base && bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
3217 return loc.result + 1;
3223 * mono_metadata_events_from_typedef:
3224 * @meta: metadata context
3225 * @index: 0-based index (in the TypeDef table) describing a type
3227 * Returns: the 0-based index in the Event table for the events in the
3228 * type. The last event that belongs to the type (plus 1) is stored
3229 * in the @end_idx pointer.
3232 mono_metadata_events_from_typedef (MonoImage *meta, guint32 index, guint *end_idx)
3236 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_EVENTMAP];
3244 loc.col_idx = MONO_EVENT_MAP_PARENT;
3245 loc.idx = index + 1;
3247 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
3250 start = mono_metadata_decode_row_col (tdef, loc.result, MONO_EVENT_MAP_EVENTLIST);
3251 if (loc.result + 1 < tdef->rows) {
3252 end = mono_metadata_decode_row_col (tdef, loc.result + 1, MONO_EVENT_MAP_EVENTLIST) - 1;
3254 end = meta->tables [MONO_TABLE_EVENT].rows;
3262 * mono_metadata_methods_from_event:
3263 * @meta: metadata context
3264 * @index: 0-based index (in the Event table) describing a event
3266 * Returns: the 0-based index in the MethodDef table for the methods in the
3267 * event. The last method that belongs to the event (plus 1) is stored
3268 * in the @end_idx pointer.
3271 mono_metadata_methods_from_event (MonoImage *meta, guint32 index, guint *end_idx)
3275 guint32 cols [MONO_METHOD_SEMA_SIZE];
3276 MonoTableInfo *msemt = &meta->tables [MONO_TABLE_METHODSEMANTICS];
3283 loc.col_idx = MONO_METHOD_SEMA_ASSOCIATION;
3284 loc.idx = ((index + 1) << MONO_HAS_SEMANTICS_BITS) | MONO_HAS_SEMANTICS_EVENT; /* Method association coded index */
3286 if (!bsearch (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator))
3291 * We may end up in the middle of the rows...
3294 if (loc.idx == mono_metadata_decode_row_col (msemt, start - 1, MONO_METHOD_SEMA_ASSOCIATION))
3300 while (end < msemt->rows) {
3301 mono_metadata_decode_row (msemt, end, cols, MONO_METHOD_SEMA_SIZE);
3302 if (cols [MONO_METHOD_SEMA_ASSOCIATION] != loc.idx)
3311 * mono_metadata_properties_from_typedef:
3312 * @meta: metadata context
3313 * @index: 0-based index (in the TypeDef table) describing a type
3315 * Returns: the 0-based index in the Property table for the properties in the
3316 * type. The last property that belongs to the type (plus 1) is stored
3317 * in the @end_idx pointer.
3320 mono_metadata_properties_from_typedef (MonoImage *meta, guint32 index, guint *end_idx)
3324 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_PROPERTYMAP];
3332 loc.col_idx = MONO_PROPERTY_MAP_PARENT;
3333 loc.idx = index + 1;
3335 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
3338 start = mono_metadata_decode_row_col (tdef, loc.result, MONO_PROPERTY_MAP_PROPERTY_LIST);
3339 if (loc.result + 1 < tdef->rows) {
3340 end = mono_metadata_decode_row_col (tdef, loc.result + 1, MONO_PROPERTY_MAP_PROPERTY_LIST) - 1;
3342 end = meta->tables [MONO_TABLE_PROPERTY].rows;
3350 * mono_metadata_methods_from_property:
3351 * @meta: metadata context
3352 * @index: 0-based index (in the PropertyDef table) describing a property
3354 * Returns: the 0-based index in the MethodDef table for the methods in the
3355 * property. The last method that belongs to the property (plus 1) is stored
3356 * in the @end_idx pointer.
3359 mono_metadata_methods_from_property (MonoImage *meta, guint32 index, guint *end_idx)
3363 guint32 cols [MONO_METHOD_SEMA_SIZE];
3364 MonoTableInfo *msemt = &meta->tables [MONO_TABLE_METHODSEMANTICS];
3371 loc.col_idx = MONO_METHOD_SEMA_ASSOCIATION;
3372 loc.idx = ((index + 1) << MONO_HAS_SEMANTICS_BITS) | MONO_HAS_SEMANTICS_PROPERTY; /* Method association coded index */
3374 if (!bsearch (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator))
3379 * We may end up in the middle of the rows...
3382 if (loc.idx == mono_metadata_decode_row_col (msemt, start - 1, MONO_METHOD_SEMA_ASSOCIATION))
3388 while (end < msemt->rows) {
3389 mono_metadata_decode_row (msemt, end, cols, MONO_METHOD_SEMA_SIZE);
3390 if (cols [MONO_METHOD_SEMA_ASSOCIATION] != loc.idx)
3399 mono_metadata_implmap_from_method (MonoImage *meta, guint32 method_idx)
3402 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_IMPLMAP];
3408 loc.col_idx = MONO_IMPLMAP_MEMBER;
3409 loc.idx = ((method_idx + 1) << MONO_MEMBERFORWD_BITS) | MONO_MEMBERFORWD_METHODDEF;
3411 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
3414 return loc.result + 1;
3418 * @image: context where the image is created
3419 * @type_spec: typespec token
3421 * Creates a MonoType representing the TypeSpec indexed by the @type_spec
3425 mono_type_create_from_typespec_full (MonoImage *image, MonoGenericContext *generic_context, guint32 type_spec)
3427 guint32 idx = mono_metadata_token_index (type_spec);
3429 guint32 cols [MONO_TYPESPEC_SIZE];
3434 mono_loader_lock ();
3436 if ((type = g_hash_table_lookup (image->typespec_cache, GUINT_TO_POINTER (type_spec)))) {
3437 mono_loader_unlock ();
3441 t = &image->tables [MONO_TABLE_TYPESPEC];
3443 mono_metadata_decode_row (t, idx-1, cols, MONO_TYPESPEC_SIZE);
3444 ptr = mono_metadata_blob_heap (image, cols [MONO_TYPESPEC_SIGNATURE]);
3445 len = mono_metadata_decode_value (ptr, &ptr);
3447 type = g_new0 (MonoType, 1);
3449 g_hash_table_insert (image->typespec_cache, GUINT_TO_POINTER (type_spec), type);
3451 if (*ptr == MONO_TYPE_BYREF) {
3456 do_mono_metadata_parse_type (type, image, generic_context, ptr, &ptr);
3458 mono_loader_unlock ();
3464 mono_type_create_from_typespec (MonoImage *image, guint32 type_spec)
3466 return mono_type_create_from_typespec_full (image, NULL, type_spec);
3470 mono_metadata_parse_marshal_spec (MonoImage *image, const char *ptr)
3472 MonoMarshalSpec *res;
3474 const char *start = ptr;
3476 /* fixme: this is incomplete, but I cant find more infos in the specs */
3478 res = g_new0 (MonoMarshalSpec, 1);
3480 len = mono_metadata_decode_value (ptr, &ptr);
3481 res->native = *ptr++;
3483 if (res->native == MONO_NATIVE_LPARRAY) {
3484 res->data.array_data.param_num = -1;
3485 res->data.array_data.num_elem = -1;
3486 res->data.array_data.elem_mult = -1;
3488 if (ptr - start <= len)
3489 res->data.array_data.elem_type = *ptr++;
3490 if (ptr - start <= len)
3491 res->data.array_data.param_num = mono_metadata_decode_value (ptr, &ptr);
3492 if (ptr - start <= len)
3493 res->data.array_data.num_elem = mono_metadata_decode_value (ptr, &ptr);
3494 if (ptr - start <= len) {
3496 * LAMESPEC: Older spec versions say this parameter comes before
3497 * num_elem. Never spec versions don't talk about elem_mult at
3498 * all, but csc still emits it, and it is used to distinguish
3499 * between param_num being 0, and param_num being omitted.
3500 * So if (param_num == 0) && (num_elem > 0), then
3501 * elem_mult == 0 -> the array size is num_elem
3502 * elem_mult == 1 -> the array size is @param_num + num_elem
3504 res->data.array_data.elem_mult = mono_metadata_decode_value (ptr, &ptr);
3508 if (res->native == MONO_NATIVE_BYVALTSTR) {
3509 if (ptr - start <= len)
3510 res->data.array_data.num_elem = mono_metadata_decode_value (ptr, &ptr);
3513 if (res->native == MONO_NATIVE_BYVALARRAY) {
3514 if (ptr - start <= len)
3515 res->data.array_data.num_elem = mono_metadata_decode_value (ptr, &ptr);
3518 if (res->native == MONO_NATIVE_CUSTOM) {
3519 /* skip unused type guid */
3520 len = mono_metadata_decode_value (ptr, &ptr);
3522 /* skip unused native type name */
3523 len = mono_metadata_decode_value (ptr, &ptr);
3525 /* read custom marshaler type name */
3526 len = mono_metadata_decode_value (ptr, &ptr);
3527 res->data.custom_data.custom_name = g_strndup (ptr, len);
3529 /* read cookie string */
3530 len = mono_metadata_decode_value (ptr, &ptr);
3531 res->data.custom_data.cookie = g_strndup (ptr, len);
3538 mono_metadata_free_marshal_spec (MonoMarshalSpec *spec)
3540 if (spec->native == MONO_NATIVE_CUSTOM) {
3541 g_free (spec->data.custom_data.custom_name);
3542 g_free (spec->data.custom_data.cookie);
3548 mono_type_to_unmanaged (MonoType *type, MonoMarshalSpec *mspec, gboolean as_field,
3549 gboolean unicode, MonoMarshalConv *conv)
3551 MonoMarshalConv dummy_conv;
3557 *conv = MONO_MARSHAL_CONV_NONE;
3560 return MONO_NATIVE_UINT;
3564 case MONO_TYPE_BOOLEAN:
3566 switch (mspec->native) {
3567 case MONO_NATIVE_VARIANTBOOL:
3568 *conv = MONO_MARSHAL_CONV_BOOL_VARIANTBOOL;
3569 return MONO_NATIVE_VARIANTBOOL;
3570 case MONO_NATIVE_BOOLEAN:
3571 *conv = MONO_MARSHAL_CONV_BOOL_I4;
3572 return MONO_NATIVE_BOOLEAN;
3573 case MONO_NATIVE_I1:
3574 case MONO_NATIVE_U1:
3575 return mspec->native;
3577 g_error ("cant marshal bool to native type %02x", mspec->native);
3580 *conv = MONO_MARSHAL_CONV_BOOL_I4;
3581 return MONO_NATIVE_BOOLEAN;
3582 case MONO_TYPE_CHAR: return MONO_NATIVE_U2;
3583 case MONO_TYPE_I1: return MONO_NATIVE_I1;
3584 case MONO_TYPE_U1: return MONO_NATIVE_U1;
3585 case MONO_TYPE_I2: return MONO_NATIVE_I2;
3586 case MONO_TYPE_U2: return MONO_NATIVE_U2;
3587 case MONO_TYPE_I4: return MONO_NATIVE_I4;
3588 case MONO_TYPE_U4: return MONO_NATIVE_U4;
3589 case MONO_TYPE_I8: return MONO_NATIVE_I8;
3590 case MONO_TYPE_U8: return MONO_NATIVE_U8;
3591 case MONO_TYPE_R4: return MONO_NATIVE_R4;
3592 case MONO_TYPE_R8: return MONO_NATIVE_R8;
3593 case MONO_TYPE_STRING:
3595 switch (mspec->native) {
3596 case MONO_NATIVE_BSTR:
3597 *conv = MONO_MARSHAL_CONV_STR_BSTR;
3598 return MONO_NATIVE_BSTR;
3599 case MONO_NATIVE_LPSTR:
3600 *conv = MONO_MARSHAL_CONV_STR_LPSTR;
3601 return MONO_NATIVE_LPSTR;
3602 case MONO_NATIVE_LPWSTR:
3603 *conv = MONO_MARSHAL_CONV_STR_LPWSTR;
3604 return MONO_NATIVE_LPWSTR;
3605 case MONO_NATIVE_LPTSTR:
3606 *conv = MONO_MARSHAL_CONV_STR_LPTSTR;
3607 return MONO_NATIVE_LPTSTR;
3608 case MONO_NATIVE_ANSIBSTR:
3609 *conv = MONO_MARSHAL_CONV_STR_ANSIBSTR;
3610 return MONO_NATIVE_ANSIBSTR;
3611 case MONO_NATIVE_TBSTR:
3612 *conv = MONO_MARSHAL_CONV_STR_TBSTR;
3613 return MONO_NATIVE_TBSTR;
3614 case MONO_NATIVE_BYVALTSTR:
3616 *conv = MONO_MARSHAL_CONV_STR_BYVALWSTR;
3618 *conv = MONO_MARSHAL_CONV_STR_BYVALSTR;
3619 return MONO_NATIVE_BYVALTSTR;
3621 g_error ("Can not marshal string to native type '%02x': Invalid managed/unmanaged type combination (String fields must be paired with LPStr, LPWStr, BStr or ByValTStr).", mspec->native);
3624 *conv = MONO_MARSHAL_CONV_STR_LPTSTR;
3625 return MONO_NATIVE_LPTSTR;
3626 case MONO_TYPE_PTR: return MONO_NATIVE_UINT;
3627 case MONO_TYPE_VALUETYPE: /*FIXME*/
3628 if (type->data.klass->enumtype) {
3629 t = type->data.klass->enum_basetype->type;
3632 return MONO_NATIVE_STRUCT;
3633 case MONO_TYPE_SZARRAY:
3634 case MONO_TYPE_ARRAY:
3636 switch (mspec->native) {
3637 case MONO_NATIVE_BYVALARRAY:
3638 *conv = MONO_MARSHAL_CONV_ARRAY_BYVALARRAY;
3639 return MONO_NATIVE_BYVALARRAY;
3640 case MONO_NATIVE_SAFEARRAY:
3641 *conv = MONO_MARSHAL_CONV_ARRAY_SAVEARRAY;
3642 return MONO_NATIVE_SAFEARRAY;
3643 case MONO_NATIVE_LPARRAY:
3644 *conv = MONO_MARSHAL_CONV_ARRAY_LPARRAY;
3645 return MONO_NATIVE_LPARRAY;
3647 g_error ("cant marshal array as native type %02x", mspec->native);
3651 *conv = MONO_MARSHAL_CONV_ARRAY_LPARRAY;
3652 return MONO_NATIVE_LPARRAY;
3653 case MONO_TYPE_I: return MONO_NATIVE_INT;
3654 case MONO_TYPE_U: return MONO_NATIVE_UINT;
3655 case MONO_TYPE_CLASS:
3656 case MONO_TYPE_OBJECT: {
3657 /* FIXME : we need to handle ArrayList and StringBuilder here, probably */
3659 switch (mspec->native) {
3660 case MONO_NATIVE_STRUCT:
3661 return MONO_NATIVE_STRUCT;
3662 case MONO_NATIVE_INTERFACE:
3663 *conv = MONO_MARSHAL_CONV_OBJECT_INTERFACE;
3664 return MONO_NATIVE_INTERFACE;
3665 case MONO_NATIVE_IDISPATCH:
3666 *conv = MONO_MARSHAL_CONV_OBJECT_IDISPATCH;
3667 return MONO_NATIVE_IDISPATCH;
3668 case MONO_NATIVE_IUNKNOWN:
3669 *conv = MONO_MARSHAL_CONV_OBJECT_IUNKNOWN;
3670 return MONO_NATIVE_IUNKNOWN;
3671 case MONO_NATIVE_FUNC:
3672 if (t == MONO_TYPE_CLASS && (type->data.klass == mono_defaults.multicastdelegate_class ||
3673 type->data.klass == mono_defaults.delegate_class ||
3674 type->data.klass->parent == mono_defaults.multicastdelegate_class)) {
3675 *conv = MONO_MARSHAL_CONV_DEL_FTN;
3676 return MONO_NATIVE_FUNC;
3682 g_error ("cant marshal object as native type %02x", mspec->native);
3685 if (t == MONO_TYPE_CLASS && (type->data.klass == mono_defaults.multicastdelegate_class ||
3686 type->data.klass == mono_defaults.delegate_class ||
3687 type->data.klass->parent == mono_defaults.multicastdelegate_class)) {
3688 *conv = MONO_MARSHAL_CONV_DEL_FTN;
3689 return MONO_NATIVE_FUNC;
3691 *conv = MONO_MARSHAL_CONV_OBJECT_STRUCT;
3692 return MONO_NATIVE_STRUCT;
3694 case MONO_TYPE_FNPTR: return MONO_NATIVE_FUNC;
3695 case MONO_TYPE_GENERICINST:
3696 type = &type->data.generic_class->container_class->byval_arg;
3699 case MONO_TYPE_TYPEDBYREF:
3701 g_error ("type 0x%02x not handled in marshal", t);
3703 return MONO_NATIVE_MAX;
3707 mono_metadata_get_marshal_info (MonoImage *meta, guint32 idx, gboolean is_field)
3710 MonoTableInfo *tdef = &meta->tables [MONO_TABLE_FIELDMARSHAL];
3716 loc.col_idx = MONO_FIELD_MARSHAL_PARENT;
3717 loc.idx = ((idx + 1) << MONO_HAS_FIELD_MARSHAL_BITS) | (is_field? MONO_HAS_FIELD_MARSHAL_FIELDSREF: MONO_HAS_FIELD_MARSHAL_PARAMDEF);
3719 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
3722 return mono_metadata_blob_heap (meta, mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_MARSHAL_NATIVE_TYPE));
3726 method_from_method_def_or_ref (MonoImage *m, guint32 tok, MonoGenericContext *context)
3728 guint32 idx = tok >> MONO_METHODDEFORREF_BITS;
3729 switch (tok & MONO_METHODDEFORREF_MASK) {
3730 case MONO_METHODDEFORREF_METHODDEF:
3731 return mono_get_method_full (m, MONO_TOKEN_METHOD_DEF | idx, NULL, context);
3732 case MONO_METHODDEFORREF_METHODREF:
3733 return mono_get_method_full (m, MONO_TOKEN_MEMBER_REF | idx, NULL, context);
3735 g_assert_not_reached ();
3740 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, gint32 *num_overrides,
3741 MonoGenericContext *generic_context)
3744 MonoTableInfo *tdef = &image->tables [MONO_TABLE_METHODIMPL];
3747 guint32 cols [MONO_METHODIMPL_SIZE];
3748 MonoMethod **result;
3757 loc.col_idx = MONO_METHODIMPL_CLASS;
3758 loc.idx = mono_metadata_token_index (type_token);
3760 if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
3766 * We may end up in the middle of the rows...
3769 if (loc.idx == mono_metadata_decode_row_col (tdef, start - 1, MONO_METHODIMPL_CLASS))
3774 while (end < tdef->rows) {
3775 if (loc.idx == mono_metadata_decode_row_col (tdef, end, MONO_METHODIMPL_CLASS))
3781 result = g_new (MonoMethod*, num * 2);
3782 for (i = 0; i < num; ++i) {
3783 mono_metadata_decode_row (tdef, start + i, cols, MONO_METHODIMPL_SIZE);
3784 result [i * 2] = method_from_method_def_or_ref (
3785 image, cols [MONO_METHODIMPL_DECLARATION], generic_context);
3786 result [i * 2 + 1] = method_from_method_def_or_ref (
3787 image, cols [MONO_METHODIMPL_BODY], generic_context);
3791 *num_overrides = num;
3796 * mono_guid_to_string:
3798 * Converts a 16 byte Microsoft GUID to the standard string representation.
3801 mono_guid_to_string (const guint8 *guid)
3803 return g_strdup_printf ("%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
3804 guid[3], guid[2], guid[1], guid[0],
3808 guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
3812 get_constraints (MonoImage *image, int owner, MonoGenericContext *context)
3814 MonoTableInfo *tdef = &image->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
3815 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
3816 guint32 i, token, found;
3817 MonoClass *klass, **res;
3818 GList *cons = NULL, *tmp;
3822 for (i = 0; i < tdef->rows; ++i) {
3823 mono_metadata_decode_row (tdef, i, cols, MONO_GENPARCONSTRAINT_SIZE);
3824 if (cols [MONO_GENPARCONSTRAINT_GENERICPAR] == owner) {
3825 token = mono_metadata_token_from_dor (cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
3826 klass = mono_class_get_full (image, token, context);
3827 cons = g_list_append (cons, klass);
3830 /* contiguous list finished */
3837 res = g_new0 (MonoClass*, found + 1);
3838 for (i = 0, tmp = cons; i < found; ++i, tmp = tmp->next) {
3839 res [i] = tmp->data;
3846 mono_metadata_has_generic_params (MonoImage *image, guint32 token)
3848 MonoTableInfo *tdef = &image->tables [MONO_TABLE_GENERICPARAM];
3849 guint32 cols [MONO_GENERICPARAM_SIZE];
3850 guint32 i, owner = 0;
3852 if (mono_metadata_token_table (token) == MONO_TABLE_TYPEDEF)
3853 owner = MONO_TYPEORMETHOD_TYPE;
3854 else if (mono_metadata_token_table (token) == MONO_TABLE_METHOD)
3855 owner = MONO_TYPEORMETHOD_METHOD;
3857 g_error ("wrong token %x to load_generics_params", token);
3860 owner |= mono_metadata_token_index (token) << MONO_TYPEORMETHOD_BITS;
3864 for (i = 0; i < tdef->rows; ++i) {
3865 mono_metadata_decode_row (tdef, i, cols, MONO_GENERICPARAM_SIZE);
3866 if (cols [MONO_GENERICPARAM_OWNER] == owner)
3869 if (i >= tdef->rows)
3875 MonoGenericContainer *
3876 mono_metadata_load_generic_params (MonoImage *image, guint32 token, MonoGenericContainer *parent_container)
3878 MonoTableInfo *tdef = &image->tables [MONO_TABLE_GENERICPARAM];
3879 guint32 cols [MONO_GENERICPARAM_SIZE];
3880 guint32 i, owner = 0, last_num, n;
3881 MonoGenericContainer *container;
3882 MonoGenericParam *params;
3884 if (mono_metadata_token_table (token) == MONO_TABLE_TYPEDEF)
3885 owner = MONO_TYPEORMETHOD_TYPE;
3886 else if (mono_metadata_token_table (token) == MONO_TABLE_METHOD)
3887 owner = MONO_TYPEORMETHOD_METHOD;
3889 g_error ("wrong token %x to load_generics_params", token);
3892 owner |= mono_metadata_token_index (token) << MONO_TYPEORMETHOD_BITS;
3896 for (i = 0; i < tdef->rows; ++i) {
3897 mono_metadata_decode_row (tdef, i, cols, MONO_GENERICPARAM_SIZE);
3898 if (cols [MONO_GENERICPARAM_OWNER] == owner)
3902 if (i >= tdef->rows)
3906 container = g_new0 (MonoGenericContainer, 1);
3909 params = g_realloc (params, sizeof (MonoGenericParam) * n);
3910 params [n - 1].owner = container;
3911 params [n - 1].pklass = NULL;
3912 params [n - 1].method = NULL;
3913 params [n - 1].flags = cols [MONO_GENERICPARAM_FLAGS];
3914 params [n - 1].num = cols [MONO_GENERICPARAM_NUMBER];
3915 params [n - 1].name = mono_metadata_string_heap (image, cols [MONO_GENERICPARAM_NAME]);
3916 if (++i >= tdef->rows)
3918 mono_metadata_decode_row (tdef, i, cols, MONO_GENERICPARAM_SIZE);
3919 } while (cols [MONO_GENERICPARAM_OWNER] == owner);
3921 container->type_argc = n;
3922 container->type_params = params;
3923 container->parent = parent_container;
3925 if (mono_metadata_token_table (token) == MONO_TABLE_METHOD)
3926 container->is_method = 1;
3928 container->context.container = container;
3930 for (i = 0; i < n; i++)
3931 params [i].constraints = get_constraints (image, last_num + i + 1, &container->context);
3937 mono_type_is_byref (MonoType *type)
3943 mono_type_get_type (MonoType *type)
3948 /* For MONO_TYPE_FNPTR */
3949 MonoMethodSignature*
3950 mono_type_get_signature (MonoType *type)
3952 return type->data.method;
3955 /* For MONO_TYPE_CLASS, VALUETYPE */
3957 mono_type_get_class (MonoType *type)
3959 return type->data.klass;
3962 /* For MONO_TYPE_ARRAY */
3964 mono_type_get_array_type (MonoType *type)
3966 return type->data.array;
3970 mono_type_get_modifiers (MonoType *type, gboolean *is_required, gpointer *iter)
3972 /* FIXME: implement */
3977 mono_signature_get_return_type (MonoMethodSignature *sig)
3983 mono_signature_get_params (MonoMethodSignature *sig, gpointer *iter)
3989 /* start from the first */
3990 if (sig->param_count) {
3991 *iter = &sig->params [0];
3992 return sig->params [0];
4000 if (type < &sig->params [sig->param_count]) {
4008 mono_signature_get_param_count (MonoMethodSignature *sig)
4010 return sig->param_count;
4014 mono_signature_get_call_conv (MonoMethodSignature *sig)
4016 return sig->call_convention;
4020 mono_signature_vararg_start (MonoMethodSignature *sig)
4022 return sig->sentinelpos;
4026 mono_signature_is_instance (MonoMethodSignature *sig)
4028 return sig->hasthis;
4032 mono_signature_explicit_this (MonoMethodSignature *sig)
4034 return sig->explicit_this;
4037 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
4039 mono_aligned_addr_hash (gconstpointer ptr)
4041 return GPOINTER_TO_UINT (ptr) >> 3;