2 #include <mono/metadata/object-internals.h>
3 #include <mono/metadata/verify.h>
4 #include <mono/metadata/opcodes.h>
5 #include <mono/metadata/tabledefs.h>
6 #include <mono/metadata/reflection.h>
7 #include <mono/metadata/debug-helpers.h>
8 #include <mono/metadata/mono-endian.h>
9 #include <mono/metadata/metadata.h>
10 #include <mono/metadata/metadata-internals.h>
11 #include <mono/metadata/class-internals.h>
12 #include <mono/metadata/tokentype.h>
18 * Pull the list of opcodes
20 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
24 #include "mono/cil/opcode.def"
30 mono_free_verify_list (GSList
*list
)
35 for (tmp
= list
; tmp
; tmp
= tmp
->next
) {
37 g_free (info
->message
);
43 #define ADD_ERROR(list,msg) \
45 MonoVerifyInfo *vinfo = g_new (MonoVerifyInfo, 1); \
46 vinfo->status = MONO_VERIFY_ERROR; \
47 vinfo->message = (msg); \
48 (list) = g_slist_prepend ((list), vinfo); \
51 #define ADD_WARN(list,code,msg) \
53 MonoVerifyInfo *vinfo = g_new (MonoVerifyInfo, 1); \
54 vinfo->status = (code); \
55 vinfo->message = (msg); \
56 (list) = g_slist_prepend ((list), vinfo); \
60 valid_cultures
[][9] = {
61 "ar-SA", "ar-IQ", "ar-EG", "ar-LY",
62 "ar-DZ", "ar-MA", "ar-TN", "ar-OM",
63 "ar-YE", "ar-SY", "ar-JO", "ar-LB",
64 "ar-KW", "ar-AE", "ar-BH", "ar-QA",
65 "bg-BG", "ca-ES", "zh-TW", "zh-CN",
66 "zh-HK", "zh-SG", "zh-MO", "cs-CZ",
67 "da-DK", "de-DE", "de-CH", "de-AT",
68 "de-LU", "de-LI", "el-GR", "en-US",
69 "en-GB", "en-AU", "en-CA", "en-NZ",
70 "en-IE", "en-ZA", "en-JM", "en-CB",
71 "en-BZ", "en-TT", "en-ZW", "en-PH",
72 "es-ES-Ts", "es-MX", "es-ES-Is", "es-GT",
73 "es-CR", "es-PA", "es-DO", "es-VE",
74 "es-CO", "es-PE", "es-AR", "es-EC",
75 "es-CL", "es-UY", "es-PY", "es-BO",
76 "es-SV", "es-HN", "es-NI", "es-PR",
77 "Fi-FI", "fr-FR", "fr-BE", "fr-CA",
78 "Fr-CH", "fr-LU", "fr-MC", "he-IL",
79 "hu-HU", "is-IS", "it-IT", "it-CH",
80 "Ja-JP", "ko-KR", "nl-NL", "nl-BE",
81 "nb-NO", "nn-NO", "pl-PL", "pt-BR",
82 "pt-PT", "ro-RO", "ru-RU", "hr-HR",
83 "Lt-sr-SP", "Cy-sr-SP", "sk-SK", "sq-AL",
84 "sv-SE", "sv-FI", "th-TH", "tr-TR",
85 "ur-PK", "id-ID", "uk-UA", "be-BY",
86 "sl-SI", "et-EE", "lv-LV", "lt-LT",
87 "fa-IR", "vi-VN", "hy-AM", "Lt-az-AZ",
89 "eu-ES", "mk-MK", "af-ZA",
90 "ka-GE", "fo-FO", "hi-IN", "ms-MY",
91 "ms-BN", "kk-KZ", "ky-KZ", "sw-KE",
92 "Lt-uz-UZ", "Cy-uz-UZ", "tt-TA", "pa-IN",
93 "gu-IN", "ta-IN", "te-IN", "kn-IN",
94 "mr-IN", "sa-IN", "mn-MN", "gl-ES",
95 "kok-IN", "syr-SY", "div-MV"
99 is_valid_culture (const char *cname
)
105 for (i
= 0; i
< G_N_ELEMENTS (valid_cultures
); ++i
) {
106 if (g_strcasecmp (valid_cultures
[i
], cname
)) {
115 is_valid_assembly_flags (guint32 flags
) {
116 /* Metadata: 22.1.2 */
117 flags
&= ~(0x8000 | 0x4000); /* ignore reserved bits 0x0030? */
118 return ((flags
== 1) || (flags
== 0));
122 is_valid_blob (MonoImage
*image
, guint32 blob_index
, int notnull
)
125 const char *p
, *blob_end
;
127 if (blob_index
>= image
->heap_blob
.size
)
129 p
= mono_metadata_blob_heap (image
, blob_index
);
130 size
= mono_metadata_decode_blob_size (p
, &blob_end
);
131 if (blob_index
+ size
+ (blob_end
-p
) > image
->heap_blob
.size
)
133 if (notnull
&& !size
)
139 is_valid_string (MonoImage
*image
, guint32 str_index
, int notnull
)
141 const char *p
, *blob_end
, *res
;
143 if (str_index
>= image
->heap_strings
.size
)
145 res
= p
= mono_metadata_string_heap (image
, str_index
);
146 blob_end
= mono_metadata_string_heap (image
, image
->heap_strings
.size
- 1);
150 * FIXME: should check it's a valid utf8 string, too.
152 while (p
<= blob_end
) {
157 return *p
? NULL
: res
;
161 is_valid_cls_ident (const char *p
)
164 * FIXME: we need the full unicode glib support for this.
165 * Check: http://www.unicode.org/unicode/reports/tr15/Identifier.java
166 * We do the lame thing for now.
172 if (!isalnum (*p
) && *p
!= '_')
180 is_valid_filename (const char *p
)
184 return strpbrk (p
, "\\//:")? 0: 1;
188 verify_assembly_table (MonoImage
*image
, GSList
*list
, int level
)
190 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_ASSEMBLY
];
191 guint32 cols
[MONO_ASSEMBLY_SIZE
];
194 if (level
& MONO_VERIFY_ERROR
) {
196 ADD_ERROR (list
, g_strdup ("Assembly table may only have 0 or 1 rows"));
197 mono_metadata_decode_row (t
, 0, cols
, MONO_ASSEMBLY_SIZE
);
199 switch (cols
[MONO_ASSEMBLY_HASH_ALG
]) {
200 case ASSEMBLY_HASH_NONE
:
201 case ASSEMBLY_HASH_MD5
:
202 case ASSEMBLY_HASH_SHA1
:
205 ADD_ERROR (list
, g_strdup_printf ("Hash algorithm 0x%x unknown", cols
[MONO_ASSEMBLY_HASH_ALG
]));
208 if (!is_valid_assembly_flags (cols
[MONO_ASSEMBLY_FLAGS
]))
209 ADD_ERROR (list
, g_strdup_printf ("Invalid flags in assembly: 0x%x", cols
[MONO_ASSEMBLY_FLAGS
]));
211 if (!is_valid_blob (image
, cols
[MONO_ASSEMBLY_PUBLIC_KEY
], FALSE
))
212 ADD_ERROR (list
, g_strdup ("Assembly public key is an invalid index"));
214 if (!(p
= is_valid_string (image
, cols
[MONO_ASSEMBLY_NAME
], TRUE
))) {
215 ADD_ERROR (list
, g_strdup ("Assembly name is invalid"));
217 if (strpbrk (p
, ":\\/."))
218 ADD_ERROR (list
, g_strdup_printf ("Assembly name `%s' contains invalid chars", p
));
221 if (!(p
= is_valid_string (image
, cols
[MONO_ASSEMBLY_CULTURE
], FALSE
))) {
222 ADD_ERROR (list
, g_strdup ("Assembly culture is an invalid index"));
224 if (!is_valid_culture (p
))
225 ADD_ERROR (list
, g_strdup_printf ("Assembly culture `%s' is invalid", p
));
232 verify_assemblyref_table (MonoImage
*image
, GSList
*list
, int level
)
234 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_ASSEMBLYREF
];
235 guint32 cols
[MONO_ASSEMBLYREF_SIZE
];
239 if (level
& MONO_VERIFY_ERROR
) {
240 for (i
= 0; i
< t
->rows
; ++i
) {
241 mono_metadata_decode_row (t
, i
, cols
, MONO_ASSEMBLYREF_SIZE
);
242 if (!is_valid_assembly_flags (cols
[MONO_ASSEMBLYREF_FLAGS
]))
243 ADD_ERROR (list
, g_strdup_printf ("Invalid flags in assemblyref row %d: 0x%x", i
+ 1, cols
[MONO_ASSEMBLY_FLAGS
]));
245 if (!is_valid_blob (image
, cols
[MONO_ASSEMBLYREF_PUBLIC_KEY
], FALSE
))
246 ADD_ERROR (list
, g_strdup_printf ("AssemblyRef public key in row %d is an invalid index", i
+ 1));
248 if (!(p
= is_valid_string (image
, cols
[MONO_ASSEMBLYREF_CULTURE
], FALSE
))) {
249 ADD_ERROR (list
, g_strdup_printf ("AssemblyRef culture in row %d is invalid", i
+ 1));
251 if (!is_valid_culture (p
))
252 ADD_ERROR (list
, g_strdup_printf ("AssemblyRef culture `%s' in row %d is invalid", p
, i
+ 1));
255 if (cols
[MONO_ASSEMBLYREF_HASH_VALUE
] && !is_valid_blob (image
, cols
[MONO_ASSEMBLYREF_HASH_VALUE
], TRUE
))
256 ADD_ERROR (list
, g_strdup_printf ("AssemblyRef hash value in row %d is invalid or not null and empty", i
+ 1));
259 if (level
& MONO_VERIFY_WARNING
) {
260 /* check for duplicated rows */
261 for (i
= 0; i
< t
->rows
; ++i
) {
268 verify_class_layout_table (MonoImage
*image
, GSList
*list
, int level
)
270 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_CLASSLAYOUT
];
271 MonoTableInfo
*tdef
= &image
->tables
[MONO_TABLE_TYPEDEF
];
272 guint32 cols
[MONO_CLASS_LAYOUT_SIZE
];
275 if (level
& MONO_VERIFY_ERROR
) {
276 for (i
= 0; i
< t
->rows
; ++i
) {
277 mono_metadata_decode_row (t
, i
, cols
, MONO_CLASS_LAYOUT_SIZE
);
279 if (cols
[MONO_CLASS_LAYOUT_PARENT
] > tdef
->rows
|| !cols
[MONO_CLASS_LAYOUT_PARENT
]) {
280 ADD_ERROR (list
, g_strdup_printf ("Parent in class layout is invalid in row %d", i
+ 1));
282 value
= mono_metadata_decode_row_col (tdef
, cols
[MONO_CLASS_LAYOUT_PARENT
] - 1, MONO_TYPEDEF_FLAGS
);
283 if (value
& TYPE_ATTRIBUTE_INTERFACE
)
284 ADD_ERROR (list
, g_strdup_printf ("Parent in class layout row %d is an interface", i
+ 1));
285 if (value
& TYPE_ATTRIBUTE_AUTO_LAYOUT
)
286 ADD_ERROR (list
, g_strdup_printf ("Parent in class layout row %d is AutoLayout", i
+ 1));
287 if (value
& TYPE_ATTRIBUTE_SEQUENTIAL_LAYOUT
) {
288 switch (cols
[MONO_CLASS_LAYOUT_PACKING_SIZE
]) {
289 case 0: case 1: case 2: case 4: case 8: case 16:
290 case 32: case 64: case 128: break;
292 ADD_ERROR (list
, g_strdup_printf ("Packing size %d in class layout row %d is invalid", cols
[MONO_CLASS_LAYOUT_PACKING_SIZE
], i
+ 1));
294 } else if (value
& TYPE_ATTRIBUTE_EXPLICIT_LAYOUT
) {
296 * FIXME: LAMESPEC: it claims it must be 0 (it's 1, instead).
297 if (cols [MONO_CLASS_LAYOUT_PACKING_SIZE])
298 ADD_ERROR (list, g_strdup_printf ("Packing size %d in class layout row %d is invalid with explicit layout", cols [MONO_CLASS_LAYOUT_PACKING_SIZE], i + 1));
302 * FIXME: we need to check that if class size != 0,
303 * it needs to be greater than the class calculated size.
304 * If parent is a valuetype it also needs to be smaller than
305 * 1 MByte (0x100000 bytes).
306 * To do both these checks we need to load the referenced
307 * assemblies, though (the spec claims we didn't have to, bah).
310 * We need to check that the parent types have the samme layout
321 verify_constant_table (MonoImage
*image
, GSList
*list
, int level
)
323 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_CONSTANT
];
324 guint32 cols
[MONO_CONSTANT_SIZE
];
326 GHashTable
*dups
= g_hash_table_new (NULL
, NULL
);
328 for (i
= 0; i
< t
->rows
; ++i
) {
329 mono_metadata_decode_row (t
, i
, cols
, MONO_CONSTANT_SIZE
);
331 if (level
& MONO_VERIFY_ERROR
)
332 if (g_hash_table_lookup (dups
, GUINT_TO_POINTER (cols
[MONO_CONSTANT_PARENT
])))
333 ADD_ERROR (list
, g_strdup_printf ("Parent 0x%08x is duplicated in Constant row %d", cols
[MONO_CONSTANT_PARENT
], i
+ 1));
334 g_hash_table_insert (dups
, GUINT_TO_POINTER (cols
[MONO_CONSTANT_PARENT
]),
335 GUINT_TO_POINTER (cols
[MONO_CONSTANT_PARENT
]));
337 switch (cols
[MONO_CONSTANT_TYPE
]) {
338 case MONO_TYPE_U1
: /* LAMESPEC: it says I1...*/
342 if (level
& MONO_VERIFY_CLS
)
343 ADD_WARN (list
, MONO_VERIFY_CLS
, g_strdup_printf ("Type 0x%x not CLS compliant in Constant row %d", cols
[MONO_CONSTANT_TYPE
], i
+ 1));
344 case MONO_TYPE_BOOLEAN
:
352 case MONO_TYPE_STRING
:
353 case MONO_TYPE_CLASS
:
356 if (level
& MONO_VERIFY_ERROR
)
357 ADD_ERROR (list
, g_strdup_printf ("Type 0x%x is invalid in Constant row %d", cols
[MONO_CONSTANT_TYPE
], i
+ 1));
359 if (level
& MONO_VERIFY_ERROR
) {
360 value
= cols
[MONO_CONSTANT_PARENT
] >> MONO_HASCONSTANT_BITS
;
361 switch (cols
[MONO_CONSTANT_PARENT
] & MONO_HASCONSTANT_MASK
) {
362 case MONO_HASCONSTANT_FIEDDEF
:
363 if (value
> image
->tables
[MONO_TABLE_FIELD
].rows
)
364 ADD_ERROR (list
, g_strdup_printf ("Parent (field) is invalid in Constant row %d", i
+ 1));
366 case MONO_HASCONSTANT_PARAM
:
367 if (value
> image
->tables
[MONO_TABLE_PARAM
].rows
)
368 ADD_ERROR (list
, g_strdup_printf ("Parent (param) is invalid in Constant row %d", i
+ 1));
370 case MONO_HASCONSTANT_PROPERTY
:
371 if (value
> image
->tables
[MONO_TABLE_PROPERTY
].rows
)
372 ADD_ERROR (list
, g_strdup_printf ("Parent (property) is invalid in Constant row %d", i
+ 1));
375 ADD_ERROR (list
, g_strdup_printf ("Parent is invalid in Constant row %d", i
+ 1));
379 if (level
& MONO_VERIFY_CLS
) {
381 * FIXME: verify types is consistent with the enum type
382 * is parent is an enum.
386 g_hash_table_destroy (dups
);
391 verify_event_map_table (MonoImage
*image
, GSList
*list
, int level
)
393 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_EVENTMAP
];
394 guint32 cols
[MONO_EVENT_MAP_SIZE
];
395 guint32 i
, last_event
;
396 GHashTable
*dups
= g_hash_table_new (NULL
, NULL
);
400 for (i
= 0; i
< t
->rows
; ++i
) {
401 mono_metadata_decode_row (t
, i
, cols
, MONO_EVENT_MAP_SIZE
);
402 if (level
& MONO_VERIFY_ERROR
)
403 if (g_hash_table_lookup (dups
, GUINT_TO_POINTER (cols
[MONO_EVENT_MAP_PARENT
])))
404 ADD_ERROR (list
, g_strdup_printf ("Parent 0x%08x is duplicated in Event Map row %d", cols
[MONO_EVENT_MAP_PARENT
], i
+ 1));
405 g_hash_table_insert (dups
, GUINT_TO_POINTER (cols
[MONO_EVENT_MAP_PARENT
]),
406 GUINT_TO_POINTER (cols
[MONO_EVENT_MAP_PARENT
]));
407 if (level
& MONO_VERIFY_ERROR
) {
408 if (cols
[MONO_EVENT_MAP_PARENT
] > image
->tables
[MONO_TABLE_TYPEDEF
].rows
)
409 ADD_ERROR (list
, g_strdup_printf ("Parent 0x%08x is invalid in Event Map row %d", cols
[MONO_EVENT_MAP_PARENT
], i
+ 1));
410 if (cols
[MONO_EVENT_MAP_EVENTLIST
] > image
->tables
[MONO_TABLE_EVENT
].rows
)
411 ADD_ERROR (list
, g_strdup_printf ("EventList 0x%08x is invalid in Event Map row %d", cols
[MONO_EVENT_MAP_EVENTLIST
], i
+ 1));
413 if (cols
[MONO_EVENT_MAP_EVENTLIST
] <= last_event
)
414 ADD_ERROR (list
, g_strdup_printf ("EventList overlap in Event Map row %d", i
+ 1));
415 last_event
= cols
[MONO_EVENT_MAP_EVENTLIST
];
419 g_hash_table_destroy (dups
);
424 verify_event_table (MonoImage
*image
, GSList
*list
, int level
)
426 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_EVENT
];
427 guint32 cols
[MONO_EVENT_SIZE
];
431 for (i
= 0; i
< t
->rows
; ++i
) {
432 mono_metadata_decode_row (t
, i
, cols
, MONO_EVENT_SIZE
);
434 if (cols
[MONO_EVENT_FLAGS
] & ~(EVENT_SPECIALNAME
|EVENT_RTSPECIALNAME
)) {
435 if (level
& MONO_VERIFY_ERROR
)
436 ADD_ERROR (list
, g_strdup_printf ("Flags 0x%04x invalid in Event row %d", cols
[MONO_EVENT_FLAGS
], i
+ 1));
438 if (!(p
= is_valid_string (image
, cols
[MONO_EVENT_NAME
], TRUE
))) {
439 if (level
& MONO_VERIFY_ERROR
)
440 ADD_ERROR (list
, g_strdup_printf ("Invalid name in Event row %d", i
+ 1));
442 if (level
& MONO_VERIFY_CLS
) {
443 if (!is_valid_cls_ident (p
))
444 ADD_WARN (list
, MONO_VERIFY_CLS
, g_strdup_printf ("Invalid CLS name '%s` in Event row %d", p
, i
+ 1));
448 if (level
& MONO_VERIFY_ERROR
&& cols
[MONO_EVENT_TYPE
]) {
449 value
= cols
[MONO_EVENT_TYPE
] >> MONO_TYPEDEFORREF_BITS
;
450 switch (cols
[MONO_EVENT_TYPE
] & MONO_TYPEDEFORREF_MASK
) {
451 case MONO_TYPEDEFORREF_TYPEDEF
:
452 if (!value
|| value
> image
->tables
[MONO_TABLE_TYPEDEF
].rows
)
453 ADD_ERROR (list
, g_strdup_printf ("Type invalid in Event row %d", i
+ 1));
455 case MONO_TYPEDEFORREF_TYPEREF
:
456 if (!value
|| value
> image
->tables
[MONO_TABLE_TYPEREF
].rows
)
457 ADD_ERROR (list
, g_strdup_printf ("Type invalid in Event row %d", i
+ 1));
459 case MONO_TYPEDEFORREF_TYPESPEC
:
460 if (!value
|| value
> image
->tables
[MONO_TABLE_TYPESPEC
].rows
)
461 ADD_ERROR (list
, g_strdup_printf ("Type invalid in Event row %d", i
+ 1));
464 ADD_ERROR (list
, g_strdup_printf ("Type invalid in Event row %d", i
+ 1));
468 * FIXME: check that there is 1 add and remove row in methodsemantics
469 * and 0 or 1 raise and 0 or more other (maybe it's better to check for
470 * these while checking methodsemantics).
471 * check for duplicated names for the same type [ERROR]
472 * check for CLS duplicate names for the same type [CLS]
479 verify_field_table (MonoImage
*image
, GSList
*list
, int level
)
481 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_FIELD
];
482 guint32 cols
[MONO_FIELD_SIZE
];
486 for (i
= 0; i
< t
->rows
; ++i
) {
487 mono_metadata_decode_row (t
, i
, cols
, MONO_FIELD_SIZE
);
489 * Check this field has only one owner and that the owner is not
490 * an interface (done in verify_typedef_table() )
492 flags
= cols
[MONO_FIELD_FLAGS
];
493 switch (flags
& FIELD_ATTRIBUTE_FIELD_ACCESS_MASK
) {
494 case FIELD_ATTRIBUTE_COMPILER_CONTROLLED
:
495 case FIELD_ATTRIBUTE_PRIVATE
:
496 case FIELD_ATTRIBUTE_FAM_AND_ASSEM
:
497 case FIELD_ATTRIBUTE_ASSEMBLY
:
498 case FIELD_ATTRIBUTE_FAMILY
:
499 case FIELD_ATTRIBUTE_FAM_OR_ASSEM
:
500 case FIELD_ATTRIBUTE_PUBLIC
:
503 if (level
& MONO_VERIFY_ERROR
)
504 ADD_ERROR (list
, g_strdup_printf ("Invalid access mask in Field row %d", i
+ 1));
507 if (level
& MONO_VERIFY_ERROR
) {
508 if ((flags
& FIELD_ATTRIBUTE_LITERAL
) && (flags
& FIELD_ATTRIBUTE_INIT_ONLY
))
509 ADD_ERROR (list
, g_strdup_printf ("Literal and InitOnly cannot be both set in Field row %d", i
+ 1));
510 if ((flags
& FIELD_ATTRIBUTE_LITERAL
) && !(flags
& FIELD_ATTRIBUTE_STATIC
))
511 ADD_ERROR (list
, g_strdup_printf ("Literal needs also Static set in Field row %d", i
+ 1));
512 if ((flags
& FIELD_ATTRIBUTE_RT_SPECIAL_NAME
) && !(flags
& FIELD_ATTRIBUTE_SPECIAL_NAME
))
513 ADD_ERROR (list
, g_strdup_printf ("RTSpecialName needs also SpecialName set in Field row %d", i
+ 1));
515 * FIXME: check there is only ono owner in the respective table.
516 * if (flags & FIELD_ATTRIBUTE_HAS_FIELD_MARSHAL)
517 * if (flags & FIELD_ATTRIBUTE_HAS_DEFAULT)
518 * if (flags & FIELD_ATTRIBUTE_HAS_FIELD_RVA)
521 if (!(p
= is_valid_string (image
, cols
[MONO_FIELD_NAME
], TRUE
))) {
522 if (level
& MONO_VERIFY_ERROR
)
523 ADD_ERROR (list
, g_strdup_printf ("Invalid name in Field row %d", i
+ 1));
525 if (level
& MONO_VERIFY_CLS
) {
526 if (!is_valid_cls_ident (p
))
527 ADD_WARN (list
, MONO_VERIFY_CLS
, g_strdup_printf ("Invalid CLS name '%s` in Field row %d", p
, i
+ 1));
532 * if owner is module needs to be static, access mask needs to be compilercontrolled,
533 * public or private (not allowed in cls mode).
534 * if owner is an enum ...
543 verify_file_table (MonoImage
*image
, GSList
*list
, int level
)
545 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_FILE
];
546 guint32 cols
[MONO_FILE_SIZE
];
549 GHashTable
*dups
= g_hash_table_new (g_str_hash
, g_str_equal
);
551 for (i
= 0; i
< t
->rows
; ++i
) {
552 mono_metadata_decode_row (t
, i
, cols
, MONO_FILE_SIZE
);
553 if (level
& MONO_VERIFY_ERROR
) {
554 if (cols
[MONO_FILE_FLAGS
] != FILE_CONTAINS_METADATA
&& cols
[MONO_FILE_FLAGS
] != FILE_CONTAINS_NO_METADATA
)
555 ADD_ERROR (list
, g_strdup_printf ("Invalid flags in File row %d", i
+ 1));
556 if (!is_valid_blob (image
, cols
[MONO_FILE_HASH_VALUE
], TRUE
))
557 ADD_ERROR (list
, g_strdup_printf ("File hash value in row %d is invalid or not null and empty", i
+ 1));
559 if (!(p
= is_valid_string (image
, cols
[MONO_FILE_NAME
], TRUE
))) {
560 if (level
& MONO_VERIFY_ERROR
)
561 ADD_ERROR (list
, g_strdup_printf ("Invalid name in File row %d", i
+ 1));
563 if (level
& MONO_VERIFY_ERROR
) {
564 if (!is_valid_filename (p
))
565 ADD_ERROR (list
, g_strdup_printf ("Invalid name '%s` in File row %d", p
, i
+ 1));
566 else if (g_hash_table_lookup (dups
, p
)) {
567 ADD_ERROR (list
, g_strdup_printf ("Duplicate name '%s` in File row %d", p
, i
+ 1));
569 g_hash_table_insert (dups
, (gpointer
)p
, (gpointer
)p
);
573 * FIXME: I don't understand what this means:
574 * If this module contains a row in the Assembly table (that is, if this module "holds the manifest")
575 * then there shall not be any row in the File table for this module - i.e., no self-reference [ERROR]
579 if (level
& MONO_VERIFY_WARNING
) {
580 if (!t
->rows
&& image
->tables
[MONO_TABLE_EXPORTEDTYPE
].rows
)
581 ADD_WARN (list
, MONO_VERIFY_WARNING
, g_strdup ("ExportedType table should be empty if File table is empty"));
583 g_hash_table_destroy (dups
);
588 verify_moduleref_table (MonoImage
*image
, GSList
*list
, int level
)
590 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_MODULEREF
];
591 MonoTableInfo
*tfile
= &image
->tables
[MONO_TABLE_FILE
];
592 guint32 cols
[MONO_MODULEREF_SIZE
];
594 guint32 found
, i
, j
, value
;
595 GHashTable
*dups
= g_hash_table_new (g_str_hash
, g_str_equal
);
597 for (i
= 0; i
< t
->rows
; ++i
) {
598 mono_metadata_decode_row (t
, i
, cols
, MONO_MODULEREF_SIZE
);
599 if (!(p
= is_valid_string (image
, cols
[MONO_MODULEREF_NAME
], TRUE
))) {
600 if (level
& MONO_VERIFY_ERROR
)
601 ADD_ERROR (list
, g_strdup_printf ("Invalid name in ModuleRef row %d", i
+ 1));
603 if (level
& MONO_VERIFY_ERROR
) {
604 if (!is_valid_filename (p
))
605 ADD_ERROR (list
, g_strdup_printf ("Invalid name '%s` in ModuleRef row %d", p
, i
+ 1));
606 else if (g_hash_table_lookup (dups
, p
)) {
607 ADD_WARN (list
, MONO_VERIFY_WARNING
, g_strdup_printf ("Duplicate name '%s` in ModuleRef row %d", p
, i
+ 1));
608 g_hash_table_insert (dups
, (gpointer
)p
, (gpointer
)p
);
610 for (j
= 0; j
< tfile
->rows
; ++j
) {
611 value
= mono_metadata_decode_row_col (tfile
, j
, MONO_FILE_NAME
);
612 if ((pf
= is_valid_string (image
, value
, TRUE
)))
613 if (strcmp (p
, pf
) == 0) {
619 ADD_ERROR (list
, g_strdup_printf ("Name '%s` in ModuleRef row %d doesn't have a match in File table", p
, i
+ 1));
624 g_hash_table_destroy (dups
);
629 verify_standalonesig_table (MonoImage
*image
, GSList
*list
, int level
)
631 MonoTableInfo
*t
= &image
->tables
[MONO_TABLE_STANDALONESIG
];
632 guint32 cols
[MONO_STAND_ALONE_SIGNATURE_SIZE
];
636 for (i
= 0; i
< t
->rows
; ++i
) {
637 mono_metadata_decode_row (t
, i
, cols
, MONO_STAND_ALONE_SIGNATURE_SIZE
);
638 if (level
& MONO_VERIFY_ERROR
) {
639 if (!is_valid_blob (image
, cols
[MONO_STAND_ALONE_SIGNATURE
], TRUE
)) {
640 ADD_ERROR (list
, g_strdup_printf ("Signature is invalid in StandAloneSig row %d", i
+ 1));
642 p
= mono_metadata_blob_heap (image
, cols
[MONO_STAND_ALONE_SIGNATURE
]);
643 /* FIXME: check it's a valid locals or method sig.*/
651 mono_image_verify_tables (MonoImage
*image
, int level
)
653 GSList
*error_list
= NULL
;
655 error_list
= verify_assembly_table (image
, error_list
, level
);
657 * AssemblyOS, AssemblyProcessor, AssemblyRefOs and
658 * AssemblyRefProcessor should be ignored,
659 * though we may want to emit a warning, since it should not
660 * be present in a PE file.
662 error_list
= verify_assemblyref_table (image
, error_list
, level
);
663 error_list
= verify_class_layout_table (image
, error_list
, level
);
664 error_list
= verify_constant_table (image
, error_list
, level
);
666 * cutom attribute, declsecurity
668 error_list
= verify_event_map_table (image
, error_list
, level
);
669 error_list
= verify_event_table (image
, error_list
, level
);
670 error_list
= verify_field_table (image
, error_list
, level
);
671 error_list
= verify_file_table (image
, error_list
, level
);
672 error_list
= verify_moduleref_table (image
, error_list
, level
);
673 error_list
= verify_standalonesig_table (image
, error_list
, level
);
675 return g_slist_reverse (error_list
);
679 TYPE_INV
= 0, /* leave at 0. */
690 static const char* const
691 arg_name
[TYPE_MAX
] = {
703 bin_num_table
[TYPE_MAX
] [TYPE_MAX
] = {
704 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
705 {TYPE_INV
, TYPE_I4
, TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_MP
, TYPE_INV
, TYPE_INV
},
706 {TYPE_INV
, TYPE_INV
, TYPE_I8
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
707 {TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_MP
, TYPE_INV
, TYPE_INV
},
708 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_R8
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
709 {TYPE_INV
, TYPE_MP
, TYPE_INV
, TYPE_MP
, TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_INV
},
710 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
711 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
}
716 TYPE_INV
, TYPE_I4
, TYPE_I8
, TYPE_PTR
, TYPE_R8
, TYPE_INV
, TYPE_INV
, TYPE_INV
719 /* reduce the size of this table */
721 bin_int_table
[TYPE_MAX
] [TYPE_MAX
] = {
722 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
723 {TYPE_INV
, TYPE_I4
, TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
724 {TYPE_INV
, TYPE_INV
, TYPE_I8
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
725 {TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
726 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
727 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
728 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
729 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
}
733 bin_comp_table
[TYPE_MAX
] [TYPE_MAX
] = {
735 {0, 1, 0, 1, 0, 0, 0, 0},
736 {0, 0, 1, 0, 0, 0, 0, 0},
737 {0, 1, 0, 1, 0, 2, 0, 0},
738 {0, 0, 0, 0, 1, 0, 0, 0},
739 {0, 0, 0, 2, 0, 1, 0, 0},
740 {0, 0, 0, 0, 0, 0, 3, 0},
741 {0, 0, 0, 0, 0, 0, 0, 0},
744 /* reduce the size of this table */
746 shift_table
[TYPE_MAX
] [TYPE_MAX
] = {
747 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
748 {TYPE_INV
, TYPE_I4
, TYPE_INV
, TYPE_I4
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
749 {TYPE_INV
, TYPE_I8
, TYPE_INV
, TYPE_I8
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
750 {TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_PTR
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
751 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
752 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
753 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
},
754 {TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
, TYPE_INV
}
759 TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I8
, TYPE_PTR
, TYPE_R8
, TYPE_R8
, TYPE_OBJ
764 TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I4
, TYPE_I8
, TYPE_PTR
, TYPE_R8
, TYPE_R8
, TYPE_OBJ
767 #define ADD_INVALID(list,msg) \
769 MonoVerifyInfo *vinfo = g_new (MonoVerifyInfo, 1); \
770 vinfo->status = MONO_VERIFY_ERROR; \
771 vinfo->message = (msg); \
772 (list) = g_slist_prepend ((list), vinfo); \
773 /*G_BREAKPOINT ();*/ \
777 #define CHECK_STACK_UNDERFLOW(num) \
779 if (cur_stack < (num)) \
780 ADD_INVALID (list, g_strdup_printf ("Stack underflow at 0x%04x (%d items instead of %d)", ip_offset, cur_stack, (num))); \
783 #define CHECK_STACK_OVERFLOW() \
785 if (cur_stack >= max_stack) \
786 ADD_INVALID (list, g_strdup_printf ("Maxstack exceeded at 0x%04x", ip_offset)); \
790 PREFIX_UNALIGNED
= 1,
793 PREFIX_ADDR_MASK
= 3,
813 type_to_eval_stack_type (MonoType
*type
, ILStackDesc
*stack
, int take_addr
) {
817 if (type
->byref
|| take_addr
) { /* fix double addr issue */
818 stack
->stype
= TYPE_MP
;
826 case MONO_TYPE_BOOLEAN
:
832 stack
->stype
= TYPE_I4
;
837 stack
->stype
= TYPE_PTR
;
839 case MONO_TYPE_CLASS
:
840 case MONO_TYPE_STRING
:
841 case MONO_TYPE_OBJECT
:
842 case MONO_TYPE_SZARRAY
:
843 case MONO_TYPE_ARRAY
:
844 stack
->stype
= TYPE_OBJ
;
848 stack
->stype
= TYPE_I8
;
852 stack
->stype
= TYPE_R8
;
854 case MONO_TYPE_VALUETYPE
:
855 if (type
->data
.klass
->enumtype
) {
856 t
= type
->data
.klass
->enum_basetype
->type
;
859 stack
->stype
= TYPE_VT
;
863 g_error ("unknown type %02x in eval stack type", type
->type
);
869 type_from_op (int ins
, ILStackDesc
*arg
) {
877 /* FIXME: check unverifiable args for TYPE_MP */
878 return arg
->stype
= bin_num_table
[arg
->stype
] [arg
[1].stype
];
884 return arg
->stype
= bin_int_table
[arg
->stype
] [arg
[1].stype
];
888 return arg
->stype
= shift_table
[arg
->stype
] [arg
[1].stype
];
909 /* FIXME: handle some specifics with ins->next->type */
910 return bin_comp_table
[arg
->stype
] [arg
[1].stype
] ? TYPE_I4
: TYPE_INV
;
916 return arg
->stype
= bin_comp_table
[arg
->stype
] [arg
[1].stype
] ? TYPE_I4
: TYPE_INV
;
919 return arg
->stype
= neg_table
[arg
->stype
];
921 if (arg
->stype
>= TYPE_I4
&& arg
->stype
<= TYPE_PTR
)
924 return arg
->stype
= TYPE_INV
;
931 case CEE_CONV_OVF_I1
:
932 case CEE_CONV_OVF_U1
:
933 case CEE_CONV_OVF_I2
:
934 case CEE_CONV_OVF_U2
:
935 case CEE_CONV_OVF_I4
:
936 case CEE_CONV_OVF_U4
:
937 case CEE_CONV_OVF_I1_UN
:
938 case CEE_CONV_OVF_U1_UN
:
939 case CEE_CONV_OVF_I2_UN
:
940 case CEE_CONV_OVF_U2_UN
:
941 case CEE_CONV_OVF_I4_UN
:
942 case CEE_CONV_OVF_U4_UN
:
943 if (arg
->stype
== TYPE_INV
|| arg
->stype
>= TYPE_MP
)
944 return arg
->stype
= TYPE_INV
;
945 return arg
->stype
= TYPE_I4
;
950 case CEE_CONV_OVF_I_UN
:
951 case CEE_CONV_OVF_U_UN
:
952 if (arg
->stype
== TYPE_INV
|| arg
->stype
== TYPE_VT
)
953 return arg
->stype
= TYPE_INV
;
954 return arg
->stype
= TYPE_PTR
;
957 case CEE_CONV_OVF_I8
:
958 case CEE_CONV_OVF_U8
:
959 case CEE_CONV_OVF_I8_UN
:
960 case CEE_CONV_OVF_U8_UN
:
961 return arg
->stype
= TYPE_I8
;
964 return arg
->stype
= TYPE_R8
;
966 g_error ("opcode 0x%04x not handled in type from op", ins
);
973 in_any_block (MonoMethodHeader
*header
, guint offset
)
976 MonoExceptionClause
*clause
;
978 for (i
= 0; i
< header
->num_clauses
; ++i
) {
979 clause
= &header
->clauses
[i
];
980 if (MONO_OFFSET_IN_CLAUSE (clause
, offset
))
982 if (MONO_OFFSET_IN_HANDLER (clause
, offset
))
984 /* need to check filter ... */
990 in_same_block (MonoMethodHeader
*header
, guint offset
, guint target
)
993 MonoExceptionClause
*clause
;
995 for (i
= 0; i
< header
->num_clauses
; ++i
) {
996 clause
= &header
->clauses
[i
];
997 if (MONO_OFFSET_IN_CLAUSE (clause
, offset
) && !MONO_OFFSET_IN_CLAUSE (clause
, target
))
999 if (MONO_OFFSET_IN_HANDLER (clause
, offset
) && !MONO_OFFSET_IN_HANDLER (clause
, target
))
1001 /* need to check filter ... */
1007 * A leave can't escape a finally block
1010 is_correct_leave (MonoMethodHeader
*header
, guint offset
, guint target
)
1013 MonoExceptionClause
*clause
;
1015 for (i
= 0; i
< header
->num_clauses
; ++i
) {
1016 clause
= &header
->clauses
[i
];
1017 if (clause
->flags
== MONO_EXCEPTION_CLAUSE_FINALLY
&& MONO_OFFSET_IN_HANDLER (clause
, offset
) && !MONO_OFFSET_IN_HANDLER (clause
, target
))
1019 /* need to check filter ... */
1025 can_merge_stack (ILCodeDesc
*a
, ILCodeDesc
*b
)
1027 if (!b
->flags
& CODE_SEEN
) {
1028 b
->flags
|= CODE_SEEN
;
1029 b
->stack_count
= a
->stack_count
;
1033 if (a
->stack_count
!= b
->stack_count
)
1040 is_valid_bool_arg (ILStackDesc
*arg
)
1042 switch (arg
->stype
) {
1055 can_store_type (ILStackDesc
*arg
, MonoType
*type
)
1058 if (type
->byref
&& arg
->stype
!= TYPE_MP
)
1062 case MONO_TYPE_VOID
:
1066 case MONO_TYPE_BOOLEAN
:
1069 case MONO_TYPE_CHAR
:
1072 if (arg
->stype
== TYPE_I4
|| arg
->stype
== TYPE_PTR
)
1079 case MONO_TYPE_CLASS
:
1080 case MONO_TYPE_STRING
:
1081 case MONO_TYPE_OBJECT
:
1082 case MONO_TYPE_SZARRAY
:
1083 case MONO_TYPE_ARRAY
:
1084 return TRUE
; /* FIXME */
1087 if (arg
->stype
== TYPE_I8
)
1092 if (arg
->stype
== TYPE_R8
)
1095 case MONO_TYPE_VALUETYPE
:
1096 if (type
->data
.klass
->enumtype
) {
1097 t
= type
->data
.klass
->enum_basetype
->type
;
1100 if (arg
->type
->data
.klass
!= type
->data
.klass
)
1105 g_error ("unknown type %02x in store type", type
->type
);
1111 stind_type (int op
, int type
) {
1114 return type
== TYPE_OBJ
;
1118 return type
== TYPE_I4
;
1120 return type
== TYPE_I8
;
1123 return type
== TYPE_R8
;
1125 g_assert_not_reached ();
1131 * FIXME: need to distinguish between valid and verifiable.
1132 * Need to keep track of types on the stack.
1133 * Verify types for opcodes.
1136 mono_method_verify (MonoMethod
*method
, int level
)
1138 MonoMethodHeader
*header
;
1139 MonoMethodSignature
*signature
, *csig
;
1140 MonoGenericContext
*generic_context
= NULL
;
1141 MonoMethod
*cmethod
;
1142 MonoClassField
*field
;
1147 register const unsigned char *ip
;
1148 register const unsigned char *end
;
1149 const unsigned char *target
= NULL
; /* branch target */
1150 int max_args
, max_stack
, cur_stack
, i
, n
, need_merge
, start
;
1151 guint32 token
, ip_offset
= 0;
1152 char *local_state
= NULL
;
1153 GSList
*list
= NULL
;
1157 if (method
->iflags
& (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
| METHOD_IMPL_ATTRIBUTE_RUNTIME
) ||
1158 (method
->flags
& (METHOD_ATTRIBUTE_PINVOKE_IMPL
| METHOD_ATTRIBUTE_ABSTRACT
))) {
1161 signature
= mono_method_signature (method
);
1162 header
= mono_method_get_header (method
);
1164 end
= ip
+ header
->code_size
;
1165 max_args
= signature
->param_count
+ signature
->hasthis
;
1166 max_stack
= header
->max_stack
;
1167 need_merge
= cur_stack
= 0;
1169 image
= method
->klass
->image
;
1170 code
= g_new0 (ILCodeDesc
, header
->code_size
);
1171 stack
= g_new0 (ILStackDesc
, max_stack
);
1172 if (signature
->hasthis
) {
1173 params
= g_new0 (MonoType
*, max_args
);
1174 params
[0] = &method
->klass
->this_arg
;
1175 memcpy (params
+ 1, signature
->params
, sizeof (MonoType
*) * signature
->param_count
);
1177 params
= signature
->params
;
1180 if (signature
->is_inflated
)
1181 generic_context
= ((MonoMethodInflated
*) method
)->context
;
1183 if (header
->num_locals
) {
1184 local_state
= g_new (char, header
->num_locals
);
1185 memset (local_state
, header
->init_locals
, header
->num_locals
);
1187 /*g_print ("Method %s.%s::%s\n", method->klass->name_space, method->klass->name, method->name);*/
1189 for (i
= 0; i
< header
->num_clauses
; ++i
) {
1190 MonoExceptionClause
*clause
= &header
->clauses
[i
];
1191 /* catch blocks have the exception on the stack. */
1192 if (clause
->flags
== MONO_EXCEPTION_CLAUSE_NONE
) {
1193 code
[clause
->handler_offset
].stack_count
= 1;
1194 code
[clause
->handler_offset
].flags
|= CODE_SEEN
;
1199 ip_offset
= ip
- header
->code
;
1200 if (start
|| !(code
[ip_offset
].flags
& CODE_SEEN
)) {
1202 /* g_print ("setting stack of IL_%04x to %d\n", ip_offset, 0); */
1203 cur_stack
= code
[ip_offset
].stack_count
;
1205 code
[ip_offset
].stack_count
= cur_stack
;
1207 code
[ip_offset
].flags
|= CODE_SEEN
;
1210 if (code
[ip_offset
].stack_count
!= cur_stack
)
1211 ADD_INVALID (list
, g_strdup_printf ("Cannot merge stack states at 0x%04x", ip_offset
));
1215 if (!can_merge_stack (&code
[ip_offset
], &code
[target
- header
->code
]))
1216 ADD_INVALID (list
, g_strdup_printf ("Cannot merge stack states at 0x%04x", ip_offset
));
1222 discode
= mono_disasm_code_one (NULL
, method
, ip
, NULL
);
1223 discode
[strlen (discode
) - 1] = 0; /* no \n */
1224 g_print ("%-29s (%d)\n", discode
, cur_stack
);
1238 if (*ip
- CEE_LDARG_0
>= max_args
)
1239 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have argument %d at 0x%04x", *ip
- CEE_LDARG_0
, ip_offset
));
1240 CHECK_STACK_OVERFLOW ();
1241 type_to_eval_stack_type (params
[*ip
- CEE_LDARG_0
], stack
+ cur_stack
, FALSE
);
1249 if (*ip
- CEE_LDLOC_0
>= header
->num_locals
)
1250 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have local var %d at 0x%04x", *ip
- CEE_LDLOC_0
, ip_offset
));
1251 if (0 && !local_state
[*ip
- CEE_LDLOC_0
])
1252 ADD_INVALID (list
, g_strdup_printf ("Local var %d is initialized at 0x%04x", *ip
- CEE_LDLOC_0
, ip_offset
));
1253 CHECK_STACK_OVERFLOW ();
1254 type_to_eval_stack_type (header
->locals
[*ip
- CEE_LDLOC_0
], stack
+ cur_stack
, FALSE
);
1262 if (*ip
- CEE_STLOC_0
>= header
->num_locals
)
1263 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have local var %d at 0x%04x", *ip
- CEE_STLOC_0
, ip_offset
));
1264 local_state
[*ip
- CEE_STLOC_0
] = 1;
1265 CHECK_STACK_UNDERFLOW (1);
1267 if (!can_store_type (stack
+ cur_stack
, header
->locals
[*ip
- CEE_STLOC_0
]))
1268 ADD_INVALID (list
, g_strdup_printf ("Incompatible type %s in store at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
1273 if (ip
[1] >= max_args
)
1274 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have argument %d at 0x%04x", ip
[1], ip_offset
));
1275 CHECK_STACK_OVERFLOW ();
1276 type_to_eval_stack_type (params
[ip
[1]], stack
+ cur_stack
, *ip
== CEE_LDARGA_S
);
1281 if (ip
[1] >= max_args
)
1282 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have argument %d at 0x%04x", ip
[1], ip_offset
));
1283 CHECK_STACK_UNDERFLOW (1);
1289 if (ip
[1] >= header
->num_locals
)
1290 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have local var %d at 0x%04x", ip
[1], ip_offset
));
1291 /* no need to check if the var is initialized if the address is taken */
1292 if (0 && *ip
== CEE_LDLOC_S
&& !local_state
[ip
[1]])
1293 ADD_INVALID (list
, g_strdup_printf ("Local var %d is initialized at 0x%04x", ip
[1], ip_offset
));
1294 CHECK_STACK_OVERFLOW ();
1295 type_to_eval_stack_type (header
->locals
[ip
[1]], stack
+ cur_stack
, *ip
== CEE_LDLOCA_S
);
1300 if (ip
[1] >= header
->num_locals
)
1301 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have local var %d at 0x%04x", ip
[1], ip_offset
));
1302 local_state
[ip
[1]] = 1;
1303 CHECK_STACK_UNDERFLOW (1);
1305 if (!can_store_type (stack
+ cur_stack
, header
->locals
[ip
[1]]))
1306 ADD_INVALID (list
, g_strdup_printf ("Incompatible type %s in store at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
1310 CHECK_STACK_OVERFLOW ();
1311 stack
[cur_stack
].type
= &mono_defaults
.object_class
->byval_arg
;
1312 stack
[cur_stack
].stype
= TYPE_OBJ
;
1326 CHECK_STACK_OVERFLOW ();
1327 stack
[cur_stack
].type
= &mono_defaults
.int_class
->byval_arg
;
1328 stack
[cur_stack
].stype
= TYPE_I4
;
1333 CHECK_STACK_OVERFLOW ();
1334 stack
[cur_stack
].type
= &mono_defaults
.int_class
->byval_arg
;
1335 stack
[cur_stack
].stype
= TYPE_I4
;
1340 CHECK_STACK_OVERFLOW ();
1341 stack
[cur_stack
].type
= &mono_defaults
.int_class
->byval_arg
;
1342 stack
[cur_stack
].stype
= TYPE_I4
;
1347 CHECK_STACK_OVERFLOW ();
1348 stack
[cur_stack
].type
= &mono_defaults
.int64_class
->byval_arg
;
1349 stack
[cur_stack
].stype
= TYPE_I8
;
1354 CHECK_STACK_OVERFLOW ();
1355 stack
[cur_stack
].type
= &mono_defaults
.double_class
->byval_arg
;
1356 stack
[cur_stack
].stype
= TYPE_R8
;
1361 CHECK_STACK_OVERFLOW ();
1362 stack
[cur_stack
].type
= &mono_defaults
.double_class
->byval_arg
;
1363 stack
[cur_stack
].stype
= TYPE_R8
;
1367 case CEE_UNUSED99
: ++ip
; break; /* warn/error instead? */
1369 CHECK_STACK_UNDERFLOW (1);
1370 CHECK_STACK_OVERFLOW ();
1371 stack
[cur_stack
] = stack
[cur_stack
- 1];
1376 CHECK_STACK_UNDERFLOW (1);
1382 ADD_INVALID (list
, g_strdup_printf ("Eval stack must be empty in jmp at 0x%04x", ip_offset
));
1383 token
= read32 (ip
+ 1);
1384 if (in_any_block (header
, ip_offset
))
1385 ADD_INVALID (list
, g_strdup_printf ("jmp cannot escape exception blocks at 0x%04x", ip_offset
));
1387 * FIXME: check signature, retval, arguments etc.
1393 token
= read32 (ip
+ 1);
1395 * FIXME: we could just load the signature ...
1397 cmethod
= mono_get_method_full (image
, token
, NULL
, generic_context
);
1399 ADD_INVALID (list
, g_strdup_printf ("Method 0x%08x not found at 0x%04x", token
, ip_offset
));
1400 if (mono_method_signature (cmethod
)) {
1401 csig
= mono_method_signature (cmethod
);
1403 csig
= mono_method_get_signature (cmethod
, image
, token
);
1406 CHECK_STACK_UNDERFLOW (csig
->param_count
+ csig
->hasthis
);
1407 cur_stack
-= csig
->param_count
+ csig
->hasthis
;
1408 if (csig
->ret
->type
!= MONO_TYPE_VOID
) {
1409 CHECK_STACK_OVERFLOW ();
1410 type_to_eval_stack_type (csig
->ret
, stack
+ cur_stack
, FALSE
);
1416 token
= read32 (ip
+ 1);
1418 * FIXME: check signature, retval, arguments etc.
1423 if (signature
->ret
->type
!= MONO_TYPE_VOID
) {
1424 CHECK_STACK_UNDERFLOW (1);
1426 if (!can_store_type (stack
+ cur_stack
, signature
->ret
))
1427 ADD_INVALID (list
, g_strdup_printf ("Incompatible type %s in ret at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
1430 ADD_INVALID (list
, g_strdup_printf ("Stack not empty (%d) after ret at 0x%04x", cur_stack
, ip_offset
));
1432 if (in_any_block (header
, ip_offset
))
1433 ADD_INVALID (list
, g_strdup_printf ("ret cannot escape exception blocks at 0x%04x", ip_offset
));
1438 target
= ip
+ (signed char)ip
[1] + 2;
1439 if (target
>= end
|| target
< header
->code
)
1440 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1441 if (!in_same_block (header
, ip_offset
, target
- header
->code
))
1442 ADD_INVALID (list
, g_strdup_printf ("Branch target escapes out of exception block at 0x%04x", ip_offset
));
1448 target
= ip
+ (signed char)ip
[1] + 2;
1449 if (target
>= end
|| target
< header
->code
)
1450 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1451 if (!in_same_block (header
, ip_offset
, target
- header
->code
))
1452 ADD_INVALID (list
, g_strdup_printf ("Branch target escapes out of exception block at 0x%04x", ip_offset
));
1453 CHECK_STACK_UNDERFLOW (1);
1455 if (!is_valid_bool_arg (stack
+ cur_stack
))
1456 ADD_INVALID (list
, g_strdup_printf ("Argument type %s not valid for brtrue/brfalse at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
1470 target
= ip
+ (signed char)ip
[1] + 2;
1471 if (target
>= end
|| target
< header
->code
)
1472 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1473 if (!in_same_block (header
, ip_offset
, target
- header
->code
))
1474 ADD_INVALID (list
, g_strdup_printf ("Branch target escapes out of exception block at 0x%04x", ip_offset
));
1475 CHECK_STACK_UNDERFLOW (2);
1477 if (type_from_op (*ip
, stack
+ cur_stack
) == TYPE_INV
)
1478 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1483 target
= ip
+ (gint32
)read32 (ip
+ 1) + 5;
1484 if (target
>= end
|| target
< header
->code
)
1485 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1486 if (!in_same_block (header
, ip_offset
, target
- header
->code
))
1487 ADD_INVALID (list
, g_strdup_printf ("Branch target escapes out of exception block at 0x%04x", ip_offset
));
1493 target
= ip
+ (gint32
)read32 (ip
+ 1) + 5;
1494 if (target
>= end
|| target
< header
->code
)
1495 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1496 if (!in_same_block (header
, ip_offset
, target
- header
->code
))
1497 ADD_INVALID (list
, g_strdup_printf ("Branch target escapes out of exception block at 0x%04x", ip_offset
));
1498 CHECK_STACK_UNDERFLOW (1);
1500 if (!is_valid_bool_arg (stack
+ cur_stack
))
1501 ADD_INVALID (list
, g_strdup_printf ("Argument type %s not valid for brtrue/brfalse at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
1515 target
= ip
+ (gint32
)read32 (ip
+ 1) + 5;
1516 if (target
>= end
|| target
< header
->code
)
1517 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1518 if (!in_same_block (header
, ip_offset
, target
- header
->code
))
1519 ADD_INVALID (list
, g_strdup_printf ("Branch target escapes out of exception block at 0x%04x", ip_offset
));
1520 CHECK_STACK_UNDERFLOW (2);
1522 if (type_from_op (*ip
, stack
+ cur_stack
) == TYPE_INV
)
1523 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1528 n
= read32 (ip
+ 1);
1529 target
= ip
+ sizeof (guint32
) * n
;
1530 /* FIXME: check that ip is in range (and within the same exception block) */
1531 for (i
= 0; i
< n
; ++i
)
1532 if (target
+ (gint32
) read32 (ip
+ 5 + i
* sizeof (gint32
)) >= end
|| target
+ (gint32
) read32 (ip
+ 5 + i
* sizeof (gint32
)) < header
->code
)
1533 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1534 CHECK_STACK_UNDERFLOW (1);
1536 if (stack
[cur_stack
].stype
!= TYPE_I4
)
1537 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to switch at 0x%04x", ip_offset
));
1538 ip
+= 5 + sizeof (guint32
) * n
;
1551 CHECK_STACK_UNDERFLOW (1);
1552 if (stack
[cur_stack
- 1].stype
!= TYPE_PTR
&& stack
[cur_stack
- 1].stype
!= TYPE_MP
)
1553 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to ldind at 0x%04x", ip_offset
));
1554 stack
[cur_stack
- 1].stype
= ldind_type
[*ip
- CEE_LDIND_I1
];
1564 CHECK_STACK_UNDERFLOW (2);
1566 if (stack
[cur_stack
].stype
!= TYPE_PTR
&& stack
[cur_stack
].stype
!= TYPE_MP
)
1567 ADD_INVALID (list
, g_strdup_printf ("Invalid pointer argument to stind at 0x%04x", ip_offset
));
1568 if (!stind_type (*ip
, stack
[cur_stack
+ 1].stype
))
1569 ADD_INVALID (list
, g_strdup_printf ("Incompatible value argument to stind at 0x%04x", ip_offset
));
1585 CHECK_STACK_UNDERFLOW (2);
1587 if (type_from_op (*ip
, stack
+ cur_stack
- 1) == TYPE_INV
)
1588 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1601 CHECK_STACK_UNDERFLOW (1);
1602 if (type_from_op (*ip
, stack
+ cur_stack
- 1) == TYPE_INV
)
1603 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1607 token
= read32 (ip
+ 1);
1608 CHECK_STACK_UNDERFLOW (2);
1613 token
= read32 (ip
+ 1);
1614 CHECK_STACK_UNDERFLOW (1);
1615 if (stack
[cur_stack
- 1].stype
!= TYPE_MP
)
1616 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to ldobj at 0x%04x", ip_offset
));
1617 klass
= mono_class_get_full (image
, token
, generic_context
);
1619 ADD_INVALID (list
, g_strdup_printf ("Cannot load class from token 0x%08x at 0x%04x", token
, ip_offset
));
1620 if (!klass
->valuetype
)
1621 ADD_INVALID (list
, g_strdup_printf ("Class is not a valuetype at 0x%04x", ip_offset
));
1622 stack
[cur_stack
- 1].stype
= TYPE_VT
;
1623 stack
[cur_stack
- 1].type
= &klass
->byval_arg
;
1627 token
= read32 (ip
+ 1);
1628 CHECK_STACK_OVERFLOW ();
1629 stack
[cur_stack
].type
= &mono_defaults
.string_class
->byval_arg
;
1630 stack
[cur_stack
].stype
= TYPE_OBJ
;
1635 token
= read32 (ip
+ 1);
1637 * FIXME: we could just load the signature ...
1639 cmethod
= mono_get_method_full (image
, token
, NULL
, generic_context
);
1641 ADD_INVALID (list
, g_strdup_printf ("Constructor 0x%08x not found at 0x%04x", token
, ip_offset
));
1642 csig
= mono_method_signature (cmethod
);
1643 CHECK_STACK_UNDERFLOW (csig
->param_count
);
1644 cur_stack
-= csig
->param_count
;
1645 CHECK_STACK_OVERFLOW ();
1646 stack
[cur_stack
].type
= &cmethod
->klass
->byval_arg
;
1647 stack
[cur_stack
].stype
= cmethod
->klass
->valuetype
? TYPE_VT
: TYPE_OBJ
;
1653 token
= read32 (ip
+ 1);
1654 CHECK_STACK_UNDERFLOW (1);
1658 CHECK_STACK_UNDERFLOW (1);
1663 ++ip
; /* warn, error ? */
1666 token
= read32 (ip
+ 1);
1667 CHECK_STACK_UNDERFLOW (1);
1668 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
)
1669 ADD_INVALID (list
, g_strdup_printf ("Invalid argument %s to unbox at 0x%04x", arg_name
[stack
[cur_stack
- 1].stype
], ip_offset
));
1670 stack
[cur_stack
- 1].stype
= TYPE_MP
;
1671 stack
[cur_stack
- 1].type
= NULL
;
1675 CHECK_STACK_UNDERFLOW (1);
1681 CHECK_STACK_UNDERFLOW (1);
1682 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
&& stack
[cur_stack
- 1].stype
!= TYPE_MP
)
1683 ADD_INVALID (list
, g_strdup_printf ("Invalid argument %s to ldfld at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
1684 token
= read32 (ip
+ 1);
1685 field
= mono_field_from_token (image
, token
, &klass
, generic_context
);
1687 ADD_INVALID (list
, g_strdup_printf ("Cannot load field from token 0x%08x at 0x%04x", token
, ip_offset
));
1688 type_to_eval_stack_type (field
->type
, stack
+ cur_stack
- 1, FALSE
);
1692 CHECK_STACK_UNDERFLOW (1);
1693 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
&& stack
[cur_stack
- 1].stype
!= TYPE_MP
)
1694 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to ldflda at 0x%04x", ip_offset
));
1695 token
= read32 (ip
+ 1);
1696 field
= mono_field_from_token (image
, token
, &klass
, generic_context
);
1698 ADD_INVALID (list
, g_strdup_printf ("Cannot load field from token 0x%08x at 0x%04x", token
, ip_offset
));
1699 type_to_eval_stack_type (field
->type
, stack
+ cur_stack
- 1, TRUE
);
1703 CHECK_STACK_UNDERFLOW (2);
1705 if (stack
[cur_stack
].stype
!= TYPE_OBJ
&& stack
[cur_stack
].stype
!= TYPE_MP
)
1706 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to stfld at 0x%04x", ip_offset
));
1707 token
= read32 (ip
+ 1);
1708 field
= mono_field_from_token (image
, token
, &klass
, generic_context
);
1710 ADD_INVALID (list
, g_strdup_printf ("Cannot load field from token 0x%08x at 0x%04x", token
, ip_offset
));
1715 CHECK_STACK_OVERFLOW ();
1716 token
= read32 (ip
+ 1);
1717 field
= mono_field_from_token (image
, token
, &klass
, generic_context
);
1719 ADD_INVALID (list
, g_strdup_printf ("Cannot load field from token 0x%08x at 0x%04x", token
, ip_offset
));
1720 type_to_eval_stack_type (field
->type
, stack
+ cur_stack
, FALSE
);
1725 CHECK_STACK_OVERFLOW ();
1726 token
= read32 (ip
+ 1);
1727 field
= mono_field_from_token (image
, token
, &klass
, generic_context
);
1729 ADD_INVALID (list
, g_strdup_printf ("Cannot load field from token 0x%08x at 0x%04x", token
, ip_offset
));
1730 type_to_eval_stack_type (field
->type
, stack
+ cur_stack
, TRUE
);
1735 CHECK_STACK_UNDERFLOW (1);
1737 token
= read32 (ip
+ 1);
1738 field
= mono_field_from_token (image
, token
, &klass
, generic_context
);
1740 ADD_INVALID (list
, g_strdup_printf ("Cannot load field from token 0x%08x at 0x%04x", token
, ip_offset
));
1745 CHECK_STACK_UNDERFLOW (2);
1747 token
= read32 (ip
+ 1);
1750 case CEE_CONV_OVF_I1_UN
:
1751 case CEE_CONV_OVF_I2_UN
:
1752 case CEE_CONV_OVF_I4_UN
:
1753 case CEE_CONV_OVF_I8_UN
:
1754 case CEE_CONV_OVF_U1_UN
:
1755 case CEE_CONV_OVF_U2_UN
:
1756 case CEE_CONV_OVF_U4_UN
:
1757 case CEE_CONV_OVF_U8_UN
:
1758 case CEE_CONV_OVF_I_UN
:
1759 case CEE_CONV_OVF_U_UN
:
1760 CHECK_STACK_UNDERFLOW (1);
1761 if (type_from_op (*ip
, stack
+ cur_stack
- 1) == TYPE_INV
)
1762 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1766 CHECK_STACK_UNDERFLOW (1);
1767 token
= read32 (ip
+ 1);
1768 if (stack
[cur_stack
- 1].stype
== TYPE_OBJ
)
1769 ADD_INVALID (list
, g_strdup_printf ("Invalid argument %s to box at 0x%04x", arg_name
[stack
[cur_stack
- 1].stype
], ip_offset
));
1770 stack
[cur_stack
- 1].stype
= TYPE_OBJ
;
1774 CHECK_STACK_UNDERFLOW (1);
1775 token
= read32 (ip
+ 1);
1776 stack
[cur_stack
- 1].stype
= TYPE_OBJ
;
1780 CHECK_STACK_UNDERFLOW (1);
1781 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
)
1782 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to ldlen at 0x%04x", ip_offset
));
1783 stack
[cur_stack
- 1].type
= &mono_defaults
.int_class
->byval_arg
; /* FIXME: use a native int type */
1784 stack
[cur_stack
- 1].stype
= TYPE_PTR
;
1788 CHECK_STACK_UNDERFLOW (2);
1790 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
)
1791 ADD_INVALID (list
, g_strdup_printf ("Invalid array argument to ldelema at 0x%04x", ip_offset
));
1792 if (stack
[cur_stack
].stype
!= TYPE_I4
&& stack
[cur_stack
].stype
!= TYPE_PTR
)
1793 ADD_INVALID (list
, g_strdup_printf ("Array index needs to be Int32 or IntPtr at 0x%04x", ip_offset
));
1794 stack
[cur_stack
- 1].stype
= TYPE_MP
;
1795 token
= read32 (ip
+ 1);
1808 case CEE_LDELEM_REF
:
1809 CHECK_STACK_UNDERFLOW (2);
1811 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
)
1812 ADD_INVALID (list
, g_strdup_printf ("Invalid array argument to ldelem at 0x%04x", ip_offset
));
1813 if (stack
[cur_stack
].stype
!= TYPE_I4
&& stack
[cur_stack
].stype
!= TYPE_PTR
)
1814 ADD_INVALID (list
, g_strdup_printf ("Array index needs to be Int32 or IntPtr at 0x%04x", ip_offset
));
1815 stack
[cur_stack
- 1].stype
= ldelem_type
[*ip
- CEE_LDELEM_I1
];
1825 case CEE_STELEM_REF
:
1826 CHECK_STACK_UNDERFLOW (3);
1830 case CEE_LDELEM_ANY
:
1831 case CEE_STELEM_ANY
:
1846 ++ip
; /* warn, error ? */
1848 case CEE_CONV_OVF_I1
:
1849 case CEE_CONV_OVF_U1
:
1850 case CEE_CONV_OVF_I2
:
1851 case CEE_CONV_OVF_U2
:
1852 case CEE_CONV_OVF_I4
:
1853 case CEE_CONV_OVF_U4
:
1854 case CEE_CONV_OVF_I8
:
1855 case CEE_CONV_OVF_U8
:
1856 CHECK_STACK_UNDERFLOW (1);
1857 if (type_from_op (*ip
, stack
+ cur_stack
- 1) == TYPE_INV
)
1858 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1868 ++ip
; /* warn, error ? */
1871 CHECK_STACK_UNDERFLOW (1);
1875 CHECK_STACK_UNDERFLOW (1);
1880 ++ip
; /* warn, error ? */
1883 CHECK_STACK_UNDERFLOW (1);
1884 token
= read32 (ip
+ 1);
1896 ++ip
; /* warn, error ? */
1899 CHECK_STACK_OVERFLOW ();
1900 token
= read32 (ip
+ 1);
1907 case CEE_CONV_OVF_I
:
1908 case CEE_CONV_OVF_U
:
1909 CHECK_STACK_UNDERFLOW (1);
1910 if (type_from_op (*ip
, stack
+ cur_stack
- 1) == TYPE_INV
)
1911 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0x%02x at 0x%04x", *ip
, ip_offset
));
1915 case CEE_ADD_OVF_UN
:
1917 case CEE_MUL_OVF_UN
:
1919 case CEE_SUB_OVF_UN
:
1920 CHECK_STACK_UNDERFLOW (2);
1924 case CEE_ENDFINALLY
:
1929 target
= ip
+ (gint32
)read32(ip
+ 1) + 5;
1930 if (target
>= end
|| target
< header
->code
)
1931 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1932 if (!is_correct_leave (header
, ip_offset
, target
- header
->code
))
1933 ADD_INVALID (list
, g_strdup_printf ("Leave not allowed in finally block at 0x%04x", ip_offset
));
1938 target
= ip
+ (signed char)ip
[1] + 2;
1939 if (target
>= end
|| target
< header
->code
)
1940 ADD_INVALID (list
, g_strdup_printf ("Branch target out of code at 0x%04x", ip_offset
));
1941 if (!is_correct_leave (header
, ip_offset
, target
- header
->code
))
1942 ADD_INVALID (list
, g_strdup_printf ("Leave not allowed in finally block at 0x%04x", ip_offset
));
1947 CHECK_STACK_UNDERFLOW (2);
1952 CHECK_STACK_UNDERFLOW (1);
1993 CHECK_STACK_OVERFLOW ();
2001 CHECK_STACK_UNDERFLOW (2);
2003 if (type_from_op (256 + *ip
, stack
+ cur_stack
- 1) == TYPE_INV
)
2004 ADD_INVALID (list
, g_strdup_printf ("Invalid arguments to opcode 0xFE 0x%02x at 0x%04x", *ip
, ip_offset
));
2008 CHECK_STACK_OVERFLOW ();
2009 token
= read32 (ip
+ 1);
2011 stack
[cur_stack
].stype
= TYPE_PTR
;
2015 CHECK_STACK_UNDERFLOW (1);
2016 token
= read32 (ip
+ 1);
2018 if (stack
[cur_stack
- 1].stype
!= TYPE_OBJ
)
2019 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to ldvirtftn at 0x%04x", ip_offset
));
2020 stack
[cur_stack
- 1].stype
= TYPE_PTR
;
2027 if (read16 (ip
+ 1) >= max_args
)
2028 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have argument %d at 0x%04x", read16 (ip
+ 1), ip_offset
));
2029 CHECK_STACK_OVERFLOW ();
2034 if (read16 (ip
+ 1) >= max_args
)
2035 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have argument %d at 0x%04x", read16(ip
+ 1), ip_offset
));
2036 CHECK_STACK_UNDERFLOW (1);
2042 n
= read16 (ip
+ 1);
2043 if (n
>= header
->num_locals
)
2044 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have local var %d at 0x%04x", n
, ip_offset
));
2045 /* no need to check if the var is initialized if the address is taken */
2046 if (0 && *ip
== CEE_LDLOC
&& !local_state
[n
])
2047 ADD_INVALID (list
, g_strdup_printf ("Local var %d is initialized at 0x%04x", n
, ip_offset
));
2048 CHECK_STACK_OVERFLOW ();
2049 type_to_eval_stack_type (header
->locals
[n
], stack
+ cur_stack
, *ip
== CEE_LDLOCA
);
2054 n
= read16 (ip
+ 1);
2055 if (n
>= header
->num_locals
)
2056 ADD_INVALID (list
, g_strdup_printf ("Method doesn't have local var %d at 0x%04x", n
, ip_offset
));
2057 local_state
[n
] = 1;
2058 CHECK_STACK_UNDERFLOW (1);
2060 if (!can_store_type (stack
+ cur_stack
, header
->locals
[n
]))
2061 ADD_INVALID (list
, g_strdup_printf ("Incompatible type %s in store at 0x%04x", arg_name
[stack
[cur_stack
].stype
], ip_offset
));
2066 ADD_INVALID (list
, g_strdup_printf ("Stack must have only size item in localloc at 0x%04x", ip_offset
));
2067 if (stack
[cur_stack
-1].stype
!= TYPE_I4
&& stack
[cur_stack
-1].stype
!= TYPE_PTR
)
2068 ADD_INVALID (list
, g_strdup_printf ("Invalid argument to localloc at 0x%04x", ip_offset
));
2069 stack
[cur_stack
-1].stype
= TYPE_MP
;
2077 ADD_INVALID (list
, g_strdup_printf ("Stack must have only filter result in endfilter at 0x%04x", ip_offset
));
2080 case CEE_UNALIGNED_
:
2081 prefix
|= PREFIX_UNALIGNED
;
2085 prefix
|= PREFIX_VOLATILE
;
2089 prefix
|= PREFIX_TAIL
;
2091 if (ip
< end
&& (*ip
!= CEE_CALL
&& *ip
!= CEE_CALLI
&& *ip
!= CEE_CALLVIRT
))
2092 ADD_INVALID (list
, g_strdup_printf ("tail prefix must be used only with call opcodes at 0x%04x", ip_offset
));
2095 CHECK_STACK_UNDERFLOW (1);
2096 token
= read32 (ip
+ 1);
2100 case CEE_CONSTRAINED_
:
2101 token
= read32 (ip
+ 1);
2105 CHECK_STACK_UNDERFLOW (3);
2109 CHECK_STACK_UNDERFLOW (3);
2122 CHECK_STACK_OVERFLOW ();
2123 token
= read32 (ip
+ 1);
2125 stack
[cur_stack
].type
= &mono_defaults
.uint_class
->byval_arg
;
2126 stack
[cur_stack
].stype
= TYPE_I4
;
2129 case CEE_REFANYTYPE
:
2130 CHECK_STACK_UNDERFLOW (1);
2143 * if ip != end we overflowed: mark as error.
2145 if (ip
!= end
|| !start
) {
2146 ADD_INVALID (list
, g_strdup_printf ("Run ahead of method code at 0x%04x", ip_offset
));
2150 g_free (local_state
);
2153 if (signature
->hasthis
)
2165 const FieldDesc
*fields
;
2168 static const FieldDesc
2169 typebuilder_fields
[] = {
2170 {"tname", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, name
)},
2171 {"nspace", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, nspace
)},
2172 {"parent", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, parent
)},
2173 {"interfaces", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, interfaces
)},
2174 {"methods", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, methods
)},
2175 {"properties", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, properties
)},
2176 {"fields", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, fields
)},
2177 {"attrs", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, attrs
)},
2178 {"table_idx", G_STRUCT_OFFSET (MonoReflectionTypeBuilder
, table_idx
)},
2182 static const FieldDesc
2183 modulebuilder_fields
[] = {
2184 {"types", G_STRUCT_OFFSET (MonoReflectionModuleBuilder
, types
)},
2185 {"cattrs", G_STRUCT_OFFSET (MonoReflectionModuleBuilder
, cattrs
)},
2186 {"guid", G_STRUCT_OFFSET (MonoReflectionModuleBuilder
, guid
)},
2187 {"table_idx", G_STRUCT_OFFSET (MonoReflectionModuleBuilder
, table_idx
)},
2191 static const FieldDesc
2192 assemblybuilder_fields
[] = {
2193 {"entry_point", G_STRUCT_OFFSET (MonoReflectionAssemblyBuilder
, entry_point
)},
2194 {"modules", G_STRUCT_OFFSET (MonoReflectionAssemblyBuilder
, modules
)},
2195 {"name", G_STRUCT_OFFSET (MonoReflectionAssemblyBuilder
, name
)},
2196 {"resources", G_STRUCT_OFFSET (MonoReflectionAssemblyBuilder
, resources
)},
2197 {"version", G_STRUCT_OFFSET (MonoReflectionAssemblyBuilder
, version
)},
2198 {"culture", G_STRUCT_OFFSET (MonoReflectionAssemblyBuilder
, culture
)},
2202 static const FieldDesc
2203 ctorbuilder_fields
[] = {
2204 {"ilgen", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, ilgen
)},
2205 {"parameters", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, parameters
)},
2206 {"attrs", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, attrs
)},
2207 {"iattrs", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, iattrs
)},
2208 {"table_idx", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, table_idx
)},
2209 {"call_conv", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, call_conv
)},
2210 {"type", G_STRUCT_OFFSET (MonoReflectionCtorBuilder
, type
)},
2214 static const FieldDesc
2215 methodbuilder_fields
[] = {
2216 {"mhandle", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, mhandle
)},
2217 {"rtype", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, rtype
)},
2218 {"parameters", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, parameters
)},
2219 {"attrs", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, attrs
)},
2220 {"iattrs", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, iattrs
)},
2221 {"name", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, name
)},
2222 {"table_idx", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, table_idx
)},
2223 {"code", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, code
)},
2224 {"ilgen", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, ilgen
)},
2225 {"type", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, type
)},
2226 {"pinfo", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, pinfo
)},
2227 {"pi_dll", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, dll
)},
2228 {"pi_entry", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, dllentry
)},
2229 {"charset", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, charset
)},
2230 {"extra_flags", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, extra_flags
)},
2231 {"native_cc", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, native_cc
)},
2232 {"call_conv", G_STRUCT_OFFSET (MonoReflectionMethodBuilder
, call_conv
)},
2236 static const FieldDesc
2237 fieldbuilder_fields
[] = {
2238 {"attrs", G_STRUCT_OFFSET (MonoReflectionFieldBuilder
, attrs
)},
2239 {"type", G_STRUCT_OFFSET (MonoReflectionFieldBuilder
, type
)},
2240 {"name", G_STRUCT_OFFSET (MonoReflectionFieldBuilder
, name
)},
2241 {"def_value", G_STRUCT_OFFSET (MonoReflectionFieldBuilder
, def_value
)},
2242 {"offset", G_STRUCT_OFFSET (MonoReflectionFieldBuilder
, offset
)},
2243 {"table_idx", G_STRUCT_OFFSET (MonoReflectionFieldBuilder
, table_idx
)},
2247 static const FieldDesc
2248 propertybuilder_fields
[] = {
2249 {"attrs", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, attrs
)},
2250 {"name", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, name
)},
2251 {"type", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, type
)},
2252 {"parameters", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, parameters
)},
2253 {"def_value", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, def_value
)},
2254 {"set_method", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, set_method
)},
2255 {"get_method", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, get_method
)},
2256 {"table_idx", G_STRUCT_OFFSET (MonoReflectionPropertyBuilder
, table_idx
)},
2260 static const FieldDesc
2261 ilgenerator_fields
[] = {
2262 {"code", G_STRUCT_OFFSET (MonoReflectionILGen
, code
)},
2263 {"code_len", G_STRUCT_OFFSET (MonoReflectionILGen
, code_len
)},
2264 {"max_stack", G_STRUCT_OFFSET (MonoReflectionILGen
, max_stack
)},
2265 {"cur_stack", G_STRUCT_OFFSET (MonoReflectionILGen
, cur_stack
)},
2266 {"locals", G_STRUCT_OFFSET (MonoReflectionILGen
, locals
)},
2267 {"ex_handlers", G_STRUCT_OFFSET (MonoReflectionILGen
, ex_handlers
)},
2271 static const FieldDesc
2272 ilexinfo_fields
[] = {
2273 {"handlers", G_STRUCT_OFFSET (MonoILExceptionInfo
, handlers
)},
2274 {"start", G_STRUCT_OFFSET (MonoILExceptionInfo
, start
)},
2275 {"len", G_STRUCT_OFFSET (MonoILExceptionInfo
, len
)},
2276 {"end", G_STRUCT_OFFSET (MonoILExceptionInfo
, label
)},
2280 static const FieldDesc
2281 ilexblock_fields
[] = {
2282 {"extype", G_STRUCT_OFFSET (MonoILExceptionBlock
, extype
)},
2283 {"type", G_STRUCT_OFFSET (MonoILExceptionBlock
, type
)},
2284 {"start", G_STRUCT_OFFSET (MonoILExceptionBlock
, start
)},
2285 {"len", G_STRUCT_OFFSET (MonoILExceptionBlock
, len
)},
2286 {"filter_offset", G_STRUCT_OFFSET (MonoILExceptionBlock
, filter_offset
)},
2290 static const ClassDesc
2291 emit_classes_to_check
[] = {
2292 {"TypeBuilder", typebuilder_fields
},
2293 {"ModuleBuilder", modulebuilder_fields
},
2294 {"AssemblyBuilder", assemblybuilder_fields
},
2295 {"ConstructorBuilder", ctorbuilder_fields
},
2296 {"MethodBuilder", methodbuilder_fields
},
2297 {"FieldBuilder", fieldbuilder_fields
},
2298 {"PropertyBuilder", propertybuilder_fields
},
2299 {"ILGenerator", ilgenerator_fields
},
2300 {"ILExceptionBlock", ilexblock_fields
},
2301 {"ILExceptionInfo", ilexinfo_fields
},
2305 static const FieldDesc
2306 monoevent_fields
[] = {
2307 {"klass", G_STRUCT_OFFSET (MonoReflectionEvent
, klass
)},
2308 {"handle", G_STRUCT_OFFSET (MonoReflectionEvent
, event
)},
2312 static const FieldDesc
2313 monoproperty_fields
[] = {
2314 {"klass", G_STRUCT_OFFSET (MonoReflectionProperty
, klass
)},
2315 {"prop", G_STRUCT_OFFSET (MonoReflectionProperty
, property
)},
2319 static const FieldDesc
2320 monofield_fields
[] = {
2321 {"klass", G_STRUCT_OFFSET (MonoReflectionField
, klass
)},
2322 {"fhandle", G_STRUCT_OFFSET (MonoReflectionField
, field
)},
2326 static const FieldDesc
2327 monomethodinfo_fields
[] = {
2328 {"parent", G_STRUCT_OFFSET (MonoMethodInfo
, parent
)},
2329 {"ret", G_STRUCT_OFFSET (MonoMethodInfo
, ret
)},
2330 {"attrs", G_STRUCT_OFFSET (MonoMethodInfo
, attrs
)},
2331 {"iattrs", G_STRUCT_OFFSET (MonoMethodInfo
, implattrs
)},
2335 static const FieldDesc
2336 monopropertyinfo_fields
[] = {
2337 {"parent", G_STRUCT_OFFSET (MonoPropertyInfo
, parent
)},
2338 {"name", G_STRUCT_OFFSET (MonoPropertyInfo
, name
)},
2339 {"get_method", G_STRUCT_OFFSET (MonoPropertyInfo
, get
)},
2340 {"set_method", G_STRUCT_OFFSET (MonoPropertyInfo
, set
)},
2341 {"attrs", G_STRUCT_OFFSET (MonoPropertyInfo
, attrs
)},
2345 static const FieldDesc
2346 monomethod_fields
[] = {
2347 {"mhandle", G_STRUCT_OFFSET (MonoReflectionMethod
, method
)},
2351 static const FieldDesc
2352 monocmethod_fields
[] = {
2353 {"mhandle", G_STRUCT_OFFSET (MonoReflectionMethod
, method
)},
2357 static const FieldDesc
2359 {"ClassImpl", G_STRUCT_OFFSET (MonoReflectionParameter
, ClassImpl
)},
2360 {"DefaultValueImpl", G_STRUCT_OFFSET (MonoReflectionParameter
, DefaultValueImpl
)},
2361 {"MemberImpl", G_STRUCT_OFFSET (MonoReflectionParameter
, MemberImpl
)},
2362 {"NameImpl", G_STRUCT_OFFSET (MonoReflectionParameter
, NameImpl
)},
2363 {"PositionImpl", G_STRUCT_OFFSET (MonoReflectionParameter
, PositionImpl
)},
2364 {"AttrsImpl", G_STRUCT_OFFSET (MonoReflectionParameter
, AttrsImpl
)},
2368 static const ClassDesc
2369 reflection_classes_to_check
[] = {
2370 {"MonoEvent", monoevent_fields
},
2371 {"MonoProperty", monoproperty_fields
},
2372 {"MonoField", monofield_fields
},
2373 {"MonoMethodInfo", monomethodinfo_fields
},
2374 {"MonoPropertyInfo", monopropertyinfo_fields
},
2375 {"MonoMethod", monomethod_fields
},
2376 {"MonoCMethod", monocmethod_fields
},
2377 {"ParameterInfo", pinfo_fields
},
2382 enuminfo_fields
[] = {
2383 {"utype", G_STRUCT_OFFSET (MonoEnumInfo
, utype
)},
2384 {"values", G_STRUCT_OFFSET (MonoEnumInfo
, values
)},
2385 {"names", G_STRUCT_OFFSET (MonoEnumInfo
, names
)},
2390 delegate_fields
[] = {
2391 {"target_type", G_STRUCT_OFFSET (MonoDelegate
, target_type
)},
2392 {"m_target", G_STRUCT_OFFSET (MonoDelegate
, target
)},
2393 {"method_name", G_STRUCT_OFFSET (MonoDelegate
, method_name
)},
2394 {"method_ptr", G_STRUCT_OFFSET (MonoDelegate
, method_ptr
)},
2395 {"delegate_trampoline", G_STRUCT_OFFSET (MonoDelegate
, delegate_trampoline
)},
2396 {"method_info", G_STRUCT_OFFSET (MonoDelegate
, method_info
)},
2401 multicast_delegate_fields
[] = {
2402 {"prev", G_STRUCT_OFFSET (MonoMulticastDelegate
, prev
)},
2407 async_result_fields
[] = {
2408 {"async_state", G_STRUCT_OFFSET (MonoAsyncResult
, async_state
)},
2409 {"handle", G_STRUCT_OFFSET (MonoAsyncResult
, handle
)},
2410 {"async_delegate", G_STRUCT_OFFSET (MonoAsyncResult
, async_delegate
)},
2411 {"data", G_STRUCT_OFFSET (MonoAsyncResult
, data
)},
2412 {"sync_completed", G_STRUCT_OFFSET (MonoAsyncResult
, sync_completed
)},
2413 {"completed", G_STRUCT_OFFSET (MonoAsyncResult
, completed
)},
2414 {"endinvoke_called", G_STRUCT_OFFSET (MonoAsyncResult
, endinvoke_called
)},
2415 {"async_callback", G_STRUCT_OFFSET (MonoAsyncResult
, async_callback
)},
2420 exception_fields
[] = {
2421 {"trace_ips", G_STRUCT_OFFSET (MonoException
, trace_ips
)},
2422 {"inner_exception", G_STRUCT_OFFSET (MonoException
, inner_ex
)},
2423 {"message", G_STRUCT_OFFSET (MonoException
, message
)},
2424 {"help_link", G_STRUCT_OFFSET (MonoException
, help_link
)},
2425 {"class_name", G_STRUCT_OFFSET (MonoException
, class_name
)},
2426 {"stack_trace", G_STRUCT_OFFSET (MonoException
, stack_trace
)},
2427 {"remote_stack_trace", G_STRUCT_OFFSET (MonoException
, remote_stack_trace
)},
2428 {"remote_stack_index", G_STRUCT_OFFSET (MonoException
, remote_stack_index
)},
2429 {"hresult", G_STRUCT_OFFSET (MonoException
, hresult
)},
2430 {"source", G_STRUCT_OFFSET (MonoException
, source
)},
2434 static const ClassDesc
2435 system_classes_to_check
[] = {
2436 {"Exception", exception_fields
},
2437 {"MonoEnumInfo", enuminfo_fields
},
2438 {"Delegate", delegate_fields
},
2439 {"MulticastDelegate", multicast_delegate_fields
},
2444 stack_frame_fields
[] = {
2445 {"ilOffset", G_STRUCT_OFFSET (MonoStackFrame
, il_offset
)},
2446 {"nativeOffset", G_STRUCT_OFFSET (MonoStackFrame
, native_offset
)},
2447 {"methodBase", G_STRUCT_OFFSET (MonoStackFrame
, method
)},
2448 {"fileName", G_STRUCT_OFFSET (MonoStackFrame
, filename
)},
2449 {"lineNumber", G_STRUCT_OFFSET (MonoStackFrame
, line
)},
2450 {"columnNumber", G_STRUCT_OFFSET (MonoStackFrame
, column
)},
2454 static const ClassDesc
2455 system_diagnostics_classes_to_check
[] = {
2456 {"StackFrame", stack_frame_fields
},
2461 mono_method_message_fields
[] = {
2462 {"method", G_STRUCT_OFFSET (MonoMethodMessage
, method
)},
2463 {"args", G_STRUCT_OFFSET (MonoMethodMessage
, args
)},
2464 {"names", G_STRUCT_OFFSET (MonoMethodMessage
, names
)},
2465 {"arg_types", G_STRUCT_OFFSET (MonoMethodMessage
, arg_types
)},
2466 {"ctx", G_STRUCT_OFFSET (MonoMethodMessage
, ctx
)},
2467 {"rval", G_STRUCT_OFFSET (MonoMethodMessage
, rval
)},
2468 {"exc", G_STRUCT_OFFSET (MonoMethodMessage
, exc
)},
2472 static const ClassDesc
2473 messaging_classes_to_check
[] = {
2474 {"AsyncResult", async_result_fields
},
2475 {"MonoMethodMessage", mono_method_message_fields
},
2480 transparent_proxy_fields
[] = {
2481 {"_rp", G_STRUCT_OFFSET (MonoTransparentProxy
, rp
)},
2482 {"_class", G_STRUCT_OFFSET (MonoTransparentProxy
, remote_class
)},
2487 real_proxy_fields
[] = {
2488 {"class_to_proxy", G_STRUCT_OFFSET (MonoRealProxy
, class_to_proxy
)},
2492 static const ClassDesc
2493 proxy_classes_to_check
[] = {
2494 {"TransparentProxy", transparent_proxy_fields
},
2495 {"RealProxy", real_proxy_fields
},
2500 wait_handle_fields
[] = {
2501 {"os_handle", G_STRUCT_OFFSET (MonoWaitHandle
, handle
)},
2502 {"disposed", G_STRUCT_OFFSET (MonoWaitHandle
, disposed
)},
2508 {"system_thread_handle", G_STRUCT_OFFSET (MonoThread
, handle
)},
2509 {"threadpool_thread", G_STRUCT_OFFSET (MonoThread
, threadpool_thread
)},
2510 {"state", G_STRUCT_OFFSET (MonoThread
, state
)},
2511 {"abort_exc", G_STRUCT_OFFSET (MonoThread
, abort_exc
)},
2512 {"abort_state", G_STRUCT_OFFSET (MonoThread
, abort_state
)},
2513 {"thread_id", G_STRUCT_OFFSET (MonoThread
, tid
)},
2517 static const ClassDesc
2518 threading_classes_to_check
[] = {
2519 {"Thread", thread_fields
},
2520 {"WaitHandle", wait_handle_fields
},
2524 static const FieldDesc
2526 {"datetime_format", G_STRUCT_OFFSET (MonoCultureInfo
, datetime_format
)},
2527 {"number_format", G_STRUCT_OFFSET (MonoCultureInfo
, number_format
)},
2528 {"textinfo", G_STRUCT_OFFSET (MonoCultureInfo
, textinfo
)},
2529 {"name", G_STRUCT_OFFSET (MonoCultureInfo
, name
)},
2530 {"displayname", G_STRUCT_OFFSET (MonoCultureInfo
, displayname
)},
2531 {"englishname", G_STRUCT_OFFSET (MonoCultureInfo
, englishname
)},
2532 {"nativename", G_STRUCT_OFFSET (MonoCultureInfo
, nativename
)},
2533 {"iso3lang", G_STRUCT_OFFSET (MonoCultureInfo
, iso3lang
)},
2534 {"iso2lang", G_STRUCT_OFFSET (MonoCultureInfo
, iso2lang
)},
2535 {"icu_name", G_STRUCT_OFFSET (MonoCultureInfo
, icu_name
)},
2536 {"win3lang", G_STRUCT_OFFSET (MonoCultureInfo
, win3lang
)},
2537 {"compareinfo", G_STRUCT_OFFSET (MonoCultureInfo
, compareinfo
)},
2541 static const FieldDesc
2542 dtfinfo_fields
[] = {
2543 {"amDesignator", G_STRUCT_OFFSET (MonoDateTimeFormatInfo
, AMDesignator
)},
2544 {"pmDesignator", G_STRUCT_OFFSET (MonoDateTimeFormatInfo
, PMDesignator
)},
2545 {"dayNames", G_STRUCT_OFFSET (MonoDateTimeFormatInfo
, DayNames
)},
2546 {"monthNames", G_STRUCT_OFFSET (MonoDateTimeFormatInfo
, MonthNames
)},
2550 static const FieldDesc
2552 {"decimalFormats", G_STRUCT_OFFSET (MonoNumberFormatInfo
, decimalFormats
)},
2553 {"currencySymbol", G_STRUCT_OFFSET (MonoNumberFormatInfo
, currencySymbol
)},
2554 {"percentSymbol", G_STRUCT_OFFSET (MonoNumberFormatInfo
, percentSymbol
)},
2555 {"positiveSign", G_STRUCT_OFFSET (MonoNumberFormatInfo
, positiveSign
)},
2559 static const FieldDesc
2560 compinfo_fields
[] = {
2561 {"lcid", G_STRUCT_OFFSET (MonoCompareInfo
, lcid
)},
2562 {"ICU_collator", G_STRUCT_OFFSET (MonoCompareInfo
, ICU_collator
)},
2566 static const FieldDesc
2567 sortkey_fields
[] = {
2568 {"str", G_STRUCT_OFFSET (MonoSortKey
, str
)},
2569 {"options", G_STRUCT_OFFSET (MonoSortKey
, options
)},
2570 {"key", G_STRUCT_OFFSET (MonoSortKey
, key
)},
2571 {"lcid", G_STRUCT_OFFSET (MonoSortKey
, lcid
)},
2575 static const ClassDesc
2576 globalization_classes_to_check
[] = {
2577 {"CultureInfo", cinfo_fields
},
2578 {"DateTimeFormatInfo", dtfinfo_fields
},
2579 {"NumberFormatInfo", nfinfo_fields
},
2580 {"CompareInfo", compinfo_fields
},
2581 {"SortKey", sortkey_fields
},
2585 static const FieldDesc
2586 safe_handle_fields
[] ={
2587 {"handle", G_STRUCT_OFFSET (MonoSafeHandle
, handle
)},
2591 static const ClassDesc interop_classes_to_check
[] = {
2592 {"SafeHandle", safe_handle_fields
},
2598 const ClassDesc
*types
;
2601 static const NameSpaceDesc
2602 namespaces_to_check
[] = {
2603 {"System.Runtime.Remoting.Proxies", proxy_classes_to_check
},
2604 {"System.Runtime.Remoting.Messaging", messaging_classes_to_check
},
2605 {"System.Reflection.Emit", emit_classes_to_check
},
2606 {"System.Reflection", reflection_classes_to_check
},
2607 {"System.Threading", threading_classes_to_check
},
2608 {"System.Diagnostics", system_diagnostics_classes_to_check
},
2609 {"System", system_classes_to_check
},
2610 {"System.Globalization", globalization_classes_to_check
},
2611 {"System.Runtime.InteropServices", interop_classes_to_check
},
2616 check_corlib (MonoImage
*corlib
)
2619 MonoClassField
*field
;
2620 const FieldDesc
*fdesc
;
2621 const ClassDesc
*cdesc
;
2622 const NameSpaceDesc
*ndesc
;
2624 GString
*result
= NULL
;
2626 for (ndesc
= namespaces_to_check
; ndesc
->name
; ++ndesc
) {
2627 for (cdesc
= ndesc
->types
; cdesc
->name
; ++cdesc
) {
2628 klass
= mono_class_from_name (corlib
, ndesc
->name
, cdesc
->name
);
2631 result
= g_string_new ("");
2632 g_string_append_printf (result
, "Cannot find class %s\n", cdesc
->name
);
2635 mono_class_init (klass
);
2637 * FIXME: we should also check the size of valuetypes, or
2638 * we're going to have trouble when we access them in arrays.
2640 if (klass
->valuetype
)
2641 struct_offset
= sizeof (MonoObject
);
2644 for (fdesc
= cdesc
->fields
; fdesc
->name
; ++fdesc
) {
2645 field
= mono_class_get_field_from_name (klass
, fdesc
->name
);
2646 if (!field
|| (field
->offset
!= (fdesc
->offset
+ struct_offset
))) {
2648 result
= g_string_new ("");
2649 g_string_append_printf (result
, "field `%s' mismatch in class %s (%ld + %ld != %ld)\n", fdesc
->name
, cdesc
->name
, (long) fdesc
->offset
, (long)struct_offset
, (long) (field
?field
->offset
:-1));
2655 return g_string_free (result
, FALSE
);
2660 mono_verify_corlib () {
2661 return check_corlib (mono_defaults
.corlib
);