2 * loader.c: Image Loader
5 * Paolo Molaro (lupus@ximian.com)
6 * Miguel de Icaza (miguel@ximian.com)
7 * Patrik Torstensson (patrik.torstensson@labs2.com)
9 * (C) 2001 Ximian, Inc.
11 * This file is used by the interpreter and the JIT engine to locate
12 * assemblies. Used to load AssemblyRef and later to resolve various
16 * This should keep track of the assembly versions that we are loading.
25 #include <mono/metadata/metadata.h>
26 #include <mono/metadata/image.h>
27 #include <mono/metadata/assembly.h>
28 #include <mono/metadata/tokentype.h>
29 #include <mono/metadata/cil-coff.h>
30 #include <mono/metadata/tabledefs.h>
31 #include <mono/metadata/metadata-internals.h>
32 #include <mono/metadata/loader.h>
33 #include <mono/metadata/class-internals.h>
34 #include <mono/metadata/debug-helpers.h>
35 #include <mono/metadata/reflection.h>
36 #include <mono/utils/mono-logger.h>
38 MonoDefaults mono_defaults;
41 * This lock protects the hash tables inside MonoImage used by the metadata
42 * loading functions in class.c and loader.c.
44 static CRITICAL_SECTION loader_mutex;
48 * This TLS variable contains the last type load error encountered by the loader.
50 guint32 loader_error_thread_id;
55 InitializeCriticalSection (&loader_mutex);
57 loader_error_thread_id = TlsAlloc ();
61 * Handling of type load errors should be done as follows:
63 * If something could not be loaded, the loader should call one of the
64 * mono_loader_set_error_XXX functions ()
65 * with the appropriate arguments, then return NULL to report the failure. The error
66 * should be propagated until it reaches code which can throw managed exceptions. At that
67 * point, an exception should be thrown based on the information returned by
68 * mono_loader_get_error (). Then the error should be cleared by calling
69 * mono_loader_clear_error ().
73 set_loader_error (MonoLoaderError *error)
75 TlsSetValue (loader_error_thread_id, error);
79 * mono_loader_set_error_type_load:
81 * Set the loader error for this thread. CLASS_NAME and ASSEMBLY_NAME should be
82 * dynamically allocated strings whose ownership is passed to this function.
85 mono_loader_set_error_type_load (char *class_name, char *assembly_name)
87 MonoLoaderError *error;
89 if (mono_loader_get_last_error ()) {
91 g_free (assembly_name);
95 error = g_new0 (MonoLoaderError, 1);
96 error->kind = MONO_LOADER_ERROR_TYPE;
97 error->class_name = class_name;
98 error->assembly_name = assembly_name;
100 set_loader_error (error);
104 * mono_loader_set_error_method_load:
106 * Set the loader error for this thread. MEMBER_NAME should point to a string
110 mono_loader_set_error_method_load (MonoClass *klass, const char *member_name)
112 MonoLoaderError *error;
114 /* FIXME: Store the signature as well */
115 if (mono_loader_get_last_error ())
118 error = g_new0 (MonoLoaderError, 1);
119 error->kind = MONO_LOADER_ERROR_METHOD;
120 error->klass = klass;
121 error->member_name = member_name;
123 set_loader_error (error);
127 * mono_loader_set_error_field_load:
129 * Set the loader error for this thread. MEMBER_NAME should point to a string
133 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name)
135 MonoLoaderError *error;
137 /* FIXME: Store the signature as well */
138 if (mono_loader_get_last_error ())
141 error = g_new0 (MonoLoaderError, 1);
142 error->kind = MONO_LOADER_ERROR_FIELD;
143 error->klass = klass;
144 error->member_name = member_name;
146 set_loader_error (error);
150 * mono_loader_get_last_error:
152 * Returns information about the last type load exception encountered by the loader, or
153 * NULL. After use, the exception should be cleared by calling mono_loader_clear_error.
156 mono_loader_get_last_error (void)
158 return (MonoLoaderError*)TlsGetValue (loader_error_thread_id);
162 mono_loader_clear_error (void)
164 MonoLoaderError *ex = (MonoLoaderError*)TlsGetValue (loader_error_thread_id);
168 g_free (ex->class_name);
169 g_free (ex->assembly_name);
172 TlsSetValue (loader_error_thread_id, NULL);
175 static MonoClassField*
176 field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass,
177 MonoGenericContext *context)
180 MonoClassField *field;
181 MonoTableInfo *tables = image->tables;
183 guint32 nindex, class;
186 guint32 idx = mono_metadata_token_index (token);
188 if (image->dynamic) {
189 MonoClassField *result = mono_lookup_dynamic_token (image, token);
190 *retklass = result->parent;
194 mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], idx-1, cols, MONO_MEMBERREF_SIZE);
195 nindex = cols [MONO_MEMBERREF_CLASS] >> MONO_MEMBERREF_PARENT_BITS;
196 class = cols [MONO_MEMBERREF_CLASS] & MONO_MEMBERREF_PARENT_MASK;
198 fname = mono_metadata_string_heap (image, cols [MONO_MEMBERREF_NAME]);
200 ptr = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
201 mono_metadata_decode_blob_size (ptr, &ptr);
202 /* we may want to check the signature here... */
205 case MONO_MEMBERREF_PARENT_TYPEREF:
206 klass = mono_class_from_typeref (image, MONO_TOKEN_TYPE_REF | nindex);
208 char *name = mono_class_name_from_token (image, MONO_TOKEN_TYPE_REF | nindex);
209 g_warning ("Missing field %s in class %s (typeref index %d)", fname, name, nindex);
213 mono_class_init (klass);
216 field = mono_class_get_field_from_name (klass, fname);
218 case MONO_MEMBERREF_PARENT_TYPESPEC: {
219 /*guint32 bcols [MONO_TYPESPEC_SIZE];
223 mono_metadata_decode_row (&tables [MONO_TABLE_TYPESPEC], nindex - 1,
224 bcols, MONO_TYPESPEC_SIZE);
225 ptr = mono_metadata_blob_heap (image, bcols [MONO_TYPESPEC_SIGNATURE]);
226 len = mono_metadata_decode_value (ptr, &ptr);
227 type = mono_metadata_parse_type (image, MONO_PARSE_TYPE, 0, ptr, &ptr);
229 klass = mono_class_from_mono_type (type);
230 mono_class_init (klass);
231 g_print ("type in sig: %s\n", klass->name);*/
232 klass = mono_class_get_full (image, MONO_TOKEN_TYPE_SPEC | nindex, context);
233 mono_class_init (klass);
236 field = mono_class_get_field_from_name (klass, fname);
240 g_warning ("field load from %x", class);
245 mono_loader_set_error_field_load (klass, fname);
251 mono_field_from_token (MonoImage *image, guint32 token, MonoClass **retklass,
252 MonoGenericContext *context)
256 MonoClassField *field;
258 if (image->dynamic) {
259 MonoClassField *result = mono_lookup_dynamic_token (image, token);
260 *retklass = result->parent;
265 if ((field = g_hash_table_lookup (image->field_cache, GUINT_TO_POINTER (token)))) {
266 *retklass = field->parent;
267 mono_loader_unlock ();
270 mono_loader_unlock ();
272 if (mono_metadata_token_table (token) == MONO_TABLE_MEMBERREF)
273 field = field_from_memberref (image, token, retklass, context);
275 type = mono_metadata_typedef_from_field (image, mono_metadata_token_index (token));
278 k = mono_class_get (image, MONO_TOKEN_TYPE_DEF | type);
284 field = mono_class_get_field (k, token);
288 if (field && !field->parent->generic_class)
289 g_hash_table_insert (image->field_cache, GUINT_TO_POINTER (token), field);
290 mono_loader_unlock ();
295 mono_metadata_signature_vararg_match (MonoMethodSignature *sig1, MonoMethodSignature *sig2)
299 if (sig1->hasthis != sig2->hasthis ||
300 sig1->sentinelpos != sig2->sentinelpos)
303 for (i = 0; i < sig1->sentinelpos; i++) {
304 MonoType *p1 = sig1->params[i];
305 MonoType *p2 = sig2->params[i];
307 /*if (p1->attrs != p2->attrs)
310 if (!mono_metadata_type_equal (p1, p2))
314 if (!mono_metadata_type_equal (sig1->ret, sig2->ret))
320 find_method_in_class (MonoClass *klass, const char *name, const char *qname,
321 const char *fqname, MonoMethodSignature *sig, MonoGenericContainer *container)
325 mono_class_setup_methods (klass);
326 for (i = 0; i < klass->method.count; ++i) {
327 MonoMethod *m = klass->methods [i];
329 if (!((fqname && !strcmp (m->name, fqname)) ||
330 (qname && !strcmp (m->name, qname)) || !strcmp (m->name, name)))
333 if (sig->call_convention == MONO_CALL_VARARG) {
334 if (mono_metadata_signature_vararg_match (sig, mono_method_signature (m)))
337 MonoMethodSignature *msig = mono_method_signature_full (m, container);
338 if (mono_metadata_signature_equal (sig, msig))
347 find_method (MonoClass *klass, MonoClass *ic, const char* name, MonoMethodSignature *sig,
348 MonoGenericContainer *container)
351 char *qname, *fqname, *class_name;
352 gboolean is_interface;
353 MonoMethod *result = NULL;
355 is_interface = MONO_CLASS_IS_INTERFACE (klass);
358 class_name = mono_type_get_name_full (&ic->byval_arg, MONO_TYPE_NAME_FORMAT_IL);
360 qname = g_strconcat (class_name, ".", name, NULL);
361 if (ic->name_space && ic->name_space [0])
362 fqname = g_strconcat (ic->name_space, ".", class_name, ".", name, NULL);
366 class_name = qname = fqname = NULL;
369 result = find_method_in_class (klass, name, qname, fqname, sig, container);
373 if (name [0] == '.' && (!strcmp (name, ".ctor") || !strcmp (name, ".cctor")))
376 for (i = 0; i < klass->interface_count; i++) {
377 MonoClass *ic = klass->interfaces [i];
379 result = find_method_in_class (ic, name, qname, fqname, sig, container);
384 klass = klass->parent;
388 result = find_method_in_class (
389 mono_defaults.object_class, name, qname, fqname, sig, container);
399 * token is the method_ref or method_def token used in a call IL instruction.
402 mono_method_get_signature_full (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context)
404 int table = mono_metadata_token_table (token);
405 int idx = mono_metadata_token_index (token);
406 guint32 cols [MONO_MEMBERREF_SIZE];
407 MonoMethodSignature *sig, *prev_sig;
410 /* !table is for wrappers: we should really assign their own token to them */
411 if (!table || table == MONO_TABLE_METHOD)
412 return mono_method_signature (method);
414 if (table == MONO_TABLE_METHODSPEC) {
415 g_assert (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) &&
416 !(method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) &&
417 mono_method_signature (method));
418 g_assert (method->is_inflated);
420 return mono_method_signature (method);
423 if (method->klass->generic_class)
424 return mono_method_signature (method);
427 /* FIXME: This might be incorrect for vararg methods */
428 return mono_method_signature (method);
431 sig = g_hash_table_lookup (image->memberref_signatures, GUINT_TO_POINTER (token));
432 mono_loader_unlock ();
434 mono_metadata_decode_row (&image->tables [MONO_TABLE_MEMBERREF], idx-1, cols, MONO_MEMBERREF_SIZE);
436 ptr = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
437 mono_metadata_decode_blob_size (ptr, &ptr);
438 sig = mono_metadata_parse_method_signature_full (
439 image, context ? context->container : NULL, 0, ptr, NULL);
442 prev_sig = g_hash_table_lookup (image->memberref_signatures, GUINT_TO_POINTER (token));
444 /* Somebody got in before us */
445 /* FIXME: Free sig */
449 g_hash_table_insert (image->memberref_signatures, GUINT_TO_POINTER (token), sig);
450 mono_loader_unlock ();
453 sig = mono_class_inflate_generic_signature (image, sig, context);
459 mono_method_get_signature (MonoMethod *method, MonoImage *image, guint32 token)
461 return mono_method_get_signature_full (method, image, token, NULL);
465 method_from_memberref (MonoImage *image, guint32 idx, MonoGenericContext *context,
466 MonoGenericContext *class_context)
468 MonoClass *klass = NULL;
469 MonoMethod *method = NULL;
470 MonoTableInfo *tables = image->tables;
472 guint32 nindex, class;
474 MonoMethodSignature *sig;
475 MonoGenericContainer *container;
478 mono_metadata_decode_row (&tables [MONO_TABLE_MEMBERREF], idx-1, cols, 3);
479 nindex = cols [MONO_MEMBERREF_CLASS] >> MONO_MEMBERREF_PARENT_BITS;
480 class = cols [MONO_MEMBERREF_CLASS] & MONO_MEMBERREF_PARENT_MASK;
481 /*g_print ("methodref: 0x%x 0x%x %s\n", class, nindex,
482 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]));*/
484 mname = mono_metadata_string_heap (image, cols [MONO_MEMBERREF_NAME]);
487 case MONO_MEMBERREF_PARENT_TYPEREF:
488 klass = mono_class_from_typeref (image, MONO_TOKEN_TYPE_REF | nindex);
490 char *name = mono_class_name_from_token (image, MONO_TOKEN_TYPE_REF | nindex);
491 g_warning ("Missing method %s in assembly %s, type %s", mname, image->name, name);
496 case MONO_MEMBERREF_PARENT_TYPESPEC:
498 * Parse the TYPESPEC in the parent's context.
500 klass = mono_class_get_full (image, MONO_TOKEN_TYPE_SPEC | nindex, class_context);
502 char *name = mono_class_name_from_token (image, MONO_TOKEN_TYPE_SPEC | nindex);
503 g_warning ("Missing method %s in assembly %s, type %s", mname, image->name, name);
508 case MONO_MEMBERREF_PARENT_TYPEDEF:
509 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | nindex);
511 char *name = mono_class_name_from_token (image, MONO_TOKEN_TYPE_DEF | nindex);
512 g_warning ("Missing method %s in assembly %s, type %s", mname, image->name, name);
517 case MONO_MEMBERREF_PARENT_METHODDEF:
518 return mono_get_method (image, MONO_TOKEN_METHOD_DEF | nindex, NULL);
520 g_error ("Memberref parent unknown: class: %d, index %d", class, nindex);
521 g_assert_not_reached ();
524 mono_class_init (klass);
527 * Correctly set the context before parsing the method.
529 if (klass->generic_class)
530 context = klass->generic_class->context;
531 else if (klass->generic_container)
532 context = (MonoGenericContext *) klass->generic_container;
533 container = context ? context->container : NULL;
535 ptr = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
536 mono_metadata_decode_blob_size (ptr, &ptr);
537 sig = mono_metadata_parse_method_signature_full (image, container, 0, ptr, NULL);
538 sig = mono_class_inflate_generic_signature (image, sig, context);
541 case MONO_MEMBERREF_PARENT_TYPEREF:
542 method = find_method (klass, NULL, mname, sig, container);
544 mono_loader_set_error_method_load (klass, mname);
545 mono_metadata_free_method_signature (sig);
547 case MONO_MEMBERREF_PARENT_TYPESPEC: {
551 type = &klass->byval_arg;
553 if (type->type != MONO_TYPE_ARRAY && type->type != MONO_TYPE_SZARRAY) {
554 method = find_method (klass, NULL, mname, sig, container);
556 g_warning ("Missing method %s in assembly %s, type %s", mname, image->name, mono_class_get_name (klass));
557 else if (klass->generic_class && (klass != method->klass))
558 method = mono_class_inflate_generic_method (
559 method, klass->generic_class->context);
560 mono_metadata_free_method_signature (sig);
564 result = (MonoMethod *)g_new0 (MonoMethodPInvoke, 1);
565 result->klass = klass;
566 result->iflags = METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL;
567 result->signature = sig;
568 result->name = mname;
570 if (!strcmp (mname, ".ctor")) {
571 /* we special-case this in the runtime. */
575 if (!strcmp (mname, "Set")) {
576 g_assert (sig->hasthis);
577 g_assert (type->data.array->rank + 1 == sig->param_count);
578 result->iflags |= METHOD_IMPL_ATTRIBUTE_RUNTIME;
582 if (!strcmp (mname, "Get")) {
583 g_assert (sig->hasthis);
584 g_assert (type->data.array->rank == sig->param_count);
585 result->iflags |= METHOD_IMPL_ATTRIBUTE_RUNTIME;
589 if (!strcmp (mname, "Address")) {
590 g_assert (sig->hasthis);
591 g_assert (type->data.array->rank == sig->param_count);
592 result->iflags |= METHOD_IMPL_ATTRIBUTE_RUNTIME;
596 g_assert_not_reached ();
599 case MONO_MEMBERREF_PARENT_TYPEDEF:
600 method = find_method (klass, NULL, mname, sig, container);
602 g_warning ("Missing method %s in assembly %s, type %s", mname, image->name, mono_class_get_name (klass));
603 mono_metadata_free_method_signature (sig);
606 g_error ("Memberref parent unknown: class: %d, index %d", class, nindex);
607 g_assert_not_reached ();
614 method_from_methodspec (MonoImage *image, MonoGenericContext *context, guint32 idx)
616 MonoMethod *method, *inflated;
617 MonoTableInfo *tables = image->tables;
618 MonoGenericContext *new_context = NULL;
619 MonoGenericMethod *gmethod;
620 MonoGenericContainer *container = NULL;
622 guint32 cols [MONO_METHODSPEC_SIZE];
623 guint32 token, nindex, param_count;
626 mono_metadata_decode_row (&tables [MONO_TABLE_METHODSPEC], idx - 1, cols, MONO_METHODSPEC_SIZE);
627 token = cols [MONO_METHODSPEC_METHOD];
628 nindex = token >> MONO_METHODDEFORREF_BITS;
630 ptr = mono_metadata_blob_heap (image, cols [MONO_METHODSPEC_SIGNATURE]);
632 mono_metadata_decode_value (ptr, &ptr);
634 param_count = mono_metadata_decode_value (ptr, &ptr);
635 g_assert (param_count);
637 container = context ? context->container : NULL;
638 if (container && (container->is_method || container->is_signature))
639 container = container->parent;
641 if ((token & MONO_METHODDEFORREF_MASK) == MONO_METHODDEFORREF_METHODDEF)
642 method = mono_get_method_full (image, MONO_TOKEN_METHOD_DEF | nindex, NULL, context);
644 method = method_from_memberref (image, nindex, container, context);
646 method = mono_get_inflated_method (method);
648 container = ((MonoMethodNormal *) method)->generic_container;
649 g_assert (container);
651 gmethod = g_new0 (MonoGenericMethod, 1);
652 gmethod->generic_class = method->klass->generic_class;
653 gmethod->container = container;
655 new_context = g_new0 (MonoGenericContext, 1);
656 new_context->container = container;
657 new_context->gmethod = gmethod;
658 if (container->parent)
659 new_context->gclass = container->parent->context.gclass;
661 gmethod->inst = mono_metadata_parse_generic_inst (image, context, param_count, ptr, &ptr);
664 gmethod->inst = mono_metadata_inflate_generic_inst (gmethod->inst, context);
666 if (!container->method_hash)
667 container->method_hash = g_hash_table_new (
668 (GHashFunc)mono_metadata_generic_method_hash, (GEqualFunc)mono_metadata_generic_method_equal);
670 inflated = g_hash_table_lookup (container->method_hash, gmethod);
673 g_free (new_context);
677 context = new_context;
679 mono_stats.generics_metadata_size += sizeof (MonoGenericMethod) +
680 sizeof (MonoGenericContext) + param_count * sizeof (MonoType);
682 inflated = mono_class_inflate_generic_method (method, new_context);
683 g_hash_table_insert (container->method_hash, gmethod, inflated);
685 new_context->gclass = inflated->klass->generic_class;
689 typedef struct MonoDllMap MonoDllMap;
698 static GHashTable *global_dll_map;
701 mono_dllmap_lookup_hash (GHashTable *dll_map, const char *dll, const char* func, const char **rdll, const char **rfunc) {
702 MonoDllMap *map, *tmp;
711 map = g_hash_table_lookup (dll_map, dll);
713 mono_loader_unlock ();
716 *rdll = map->target? map->target: dll;
718 for (tmp = map->next; tmp; tmp = tmp->next) {
719 if (strcmp (func, tmp->name) == 0) {
723 mono_loader_unlock ();
728 mono_loader_unlock ();
733 mono_dllmap_lookup (MonoImage *assembly, const char *dll, const char* func, const char **rdll, const char **rfunc)
736 if (assembly && assembly->dll_map) {
737 res = mono_dllmap_lookup_hash (assembly->dll_map, dll, func, rdll, rfunc);
741 return mono_dllmap_lookup_hash (global_dll_map, dll, func, rdll, rfunc);
745 mono_dllmap_insert (MonoImage *assembly, const char *dll, const char *func, const char *tdll, const char *tfunc) {
746 MonoDllMap *map, *entry;
747 GHashTable *dll_map = NULL;
753 global_dll_map = g_hash_table_new (g_str_hash, g_str_equal);
754 dll_map = global_dll_map;
756 if (!assembly->dll_map)
757 assembly->dll_map = g_hash_table_new (g_str_hash, g_str_equal);
758 dll_map = assembly->dll_map;
761 map = g_hash_table_lookup (dll_map, dll);
763 map = g_new0 (MonoDllMap, 1);
764 map->dll = g_strdup (dll);
766 map->target = g_strdup (tdll);
767 g_hash_table_insert (dll_map, map->dll, map);
770 entry = g_new0 (MonoDllMap, 1);
771 entry->name = g_strdup (func);
773 entry->target = g_strdup (tfunc);
774 if (tdll && map->target && strcmp (map->target, tdll))
775 entry->dll = g_strdup (tdll);
776 entry->next = map->next;
780 mono_loader_unlock ();
784 mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char **exc_arg)
786 MonoImage *image = method->klass->image;
787 MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method;
788 MonoTableInfo *tables = image->tables;
789 MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
790 MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF];
791 guint32 im_cols [MONO_IMPLMAP_SIZE];
793 const char *import = NULL;
794 const char *orig_scope;
795 const char *new_scope;
796 char *full_name, *file_name;
798 GModule *gmodule = NULL;
800 g_assert (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL);
805 if (method->klass->image->dynamic) {
806 MonoReflectionMethodAux *method_aux =
807 g_hash_table_lookup (
808 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
812 import = method_aux->dllentry;
813 orig_scope = method_aux->dll;
816 if (!piinfo->implmap_idx)
819 mono_metadata_decode_row (im, piinfo->implmap_idx - 1, im_cols, MONO_IMPLMAP_SIZE);
821 piinfo->piflags = im_cols [MONO_IMPLMAP_FLAGS];
822 import = mono_metadata_string_heap (image, im_cols [MONO_IMPLMAP_NAME]);
823 scope_token = mono_metadata_decode_row_col (mr, im_cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME);
824 orig_scope = mono_metadata_string_heap (image, scope_token);
827 mono_dllmap_lookup (image, orig_scope, import, &new_scope, &import);
829 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
830 "DllImport attempting to load: '%s'.", new_scope);
837 /* we allow a special name to dlopen from the running process namespace */
838 if (strcmp (new_scope, "__Internal") == 0)
839 gmodule = g_module_open (NULL, G_MODULE_BIND_LAZY);
842 * Try loading the module using a variety of names
844 for (i = 0; i < 4; ++i) {
847 /* Try the original name */
848 file_name = g_strdup (new_scope);
851 /* Try trimming the .dll extension */
852 if (strstr (new_scope, ".dll") == (new_scope + strlen (new_scope) - 4)) {
853 file_name = g_strdup (new_scope);
854 file_name [strlen (new_scope) - 4] = '\0';
860 if (strstr (new_scope, "lib") != new_scope) {
861 file_name = g_strdup_printf ("lib%s", new_scope);
867 #ifndef PLATFORM_WIN32
868 if (!g_ascii_strcasecmp ("user32.dll", new_scope) ||
869 !g_ascii_strcasecmp ("kernel32.dll", new_scope) ||
870 !g_ascii_strcasecmp ("user32", new_scope) ||
871 !g_ascii_strcasecmp ("kernel", new_scope)) {
872 file_name = g_strdup ("libMonoSupportW.so");
876 #ifndef PLATFORM_WIN32
882 full_name = g_module_build_path (NULL, file_name);
883 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
884 "DllImport loading location: '%s'.", full_name);
885 gmodule = g_module_open (full_name, G_MODULE_BIND_LAZY);
887 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
888 "DllImport error loading library: '%s'.",
895 full_name = g_module_build_path (".", file_name);
896 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
897 "DllImport loading library: '%s'.", full_name);
898 gmodule = g_module_open (full_name, G_MODULE_BIND_LAZY);
900 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
901 "DllImport error loading library '%s'.",
908 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
909 "DllImport loading: '%s'.", file_name);
910 gmodule=g_module_open (file_name, G_MODULE_BIND_LAZY);
912 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
913 "DllImport error loading library '%s'.",
925 mono_trace (G_LOG_LEVEL_WARNING, MONO_TRACE_DLLIMPORT,
926 "DllImport unable to load library '%s'.",
930 *exc_class = "DllNotFoundException";
931 *exc_arg = new_scope;
936 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
937 "Searching for '%s'.", import);
939 if (piinfo->piflags & PINVOKE_ATTRIBUTE_NO_MANGLE) {
940 g_module_symbol (gmodule, import, &piinfo->addr);
942 char *mangled_name = NULL, *mangled_name2 = NULL;
945 int mangle_param_count;
946 #ifdef PLATFORM_WIN32
951 * Search using a variety of mangled names
953 for (mangle_charset = 0; mangle_charset <= 1; mangle_charset ++) {
954 for (mangle_stdcall = 0; mangle_stdcall <= 1; mangle_stdcall ++) {
955 gboolean need_param_count = FALSE;
956 #ifdef PLATFORM_WIN32
957 if (mangle_stdcall > 0)
958 need_param_count = TRUE;
960 for (mangle_param_count = 0; mangle_param_count <= (need_param_count ? 256 : 0); mangle_param_count += 4) {
965 mangled_name = (char*)import;
966 switch (piinfo->piflags & PINVOKE_ATTRIBUTE_CHAR_SET_MASK) {
967 case PINVOKE_ATTRIBUTE_CHAR_SET_UNICODE:
968 /* Try the mangled name first */
969 if (mangle_charset == 0)
970 mangled_name = g_strconcat (import, "W", NULL);
972 case PINVOKE_ATTRIBUTE_CHAR_SET_AUTO:
973 #ifdef PLATFORM_WIN32
974 if (mangle_charset == 0)
975 mangled_name = g_strconcat (import, "W", NULL);
978 case PINVOKE_ATTRIBUTE_CHAR_SET_ANSI:
980 /* Try the mangled name last */
981 if (mangle_charset == 1)
982 mangled_name = g_strconcat (import, "A", NULL);
986 #ifdef PLATFORM_WIN32
987 if (mangle_param_count == 0)
988 param_count = mono_method_signature (method)->param_count * sizeof (gpointer);
990 /* Try brute force, since it would be very hard to compute the stack usage correctly */
991 param_count = mangle_param_count;
993 /* Try the stdcall mangled name */
995 * gcc under windows creates mangled names without the underscore, but MS.NET
996 * doesn't support it, so we doesn't support it either.
998 if (mangle_stdcall == 1)
999 mangled_name2 = g_strdup_printf ("_%s@%d", mangled_name, param_count);
1001 mangled_name2 = mangled_name;
1003 mangled_name2 = mangled_name;
1006 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
1007 "Probing '%s'.", mangled_name2);
1009 g_module_symbol (gmodule, mangled_name2, &piinfo->addr);
1012 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT,
1013 "Found as '%s'.", mangled_name2);
1015 if (mangled_name != mangled_name2)
1016 g_free (mangled_name2);
1017 if (mangled_name != import)
1018 g_free (mangled_name);
1024 if (!piinfo->addr) {
1026 *exc_class = "EntryPointNotFoundException";
1031 return piinfo->addr;
1035 mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
1036 MonoGenericContext *context)
1039 int table = mono_metadata_token_table (token);
1040 int idx = mono_metadata_token_index (token);
1041 MonoTableInfo *tables = image->tables;
1042 MonoGenericContainer *generic_container = NULL, *container = NULL;
1043 const char *sig = NULL;
1045 guint32 cols [MONO_TYPEDEF_SIZE];
1048 return mono_lookup_dynamic_token (image, token);
1050 if (table != MONO_TABLE_METHOD) {
1051 if (table == MONO_TABLE_METHODSPEC)
1052 return method_from_methodspec (image, context, idx);
1053 if (table != MONO_TABLE_MEMBERREF)
1054 g_print("got wrong token: 0x%08x\n", token);
1055 g_assert (table == MONO_TABLE_MEMBERREF);
1056 result = method_from_memberref (image, idx, context, context);
1061 mono_metadata_decode_row (&tables [table], idx - 1, cols, 6);
1063 if ((cols [2] & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
1064 (cols [1] & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL))
1065 result = (MonoMethod *)g_new0 (MonoMethodPInvoke, 1);
1067 result = (MonoMethod *)g_new0 (MonoMethodNormal, 1);
1070 result->klass = klass;
1071 result->flags = cols [2];
1072 result->iflags = cols [1];
1073 result->token = token;
1074 result->name = mono_metadata_string_heap (image, cols [3]);
1077 container = klass->generic_container;
1079 if (!(cols [1] & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) &&
1080 (!(cols [2] & METHOD_ATTRIBUTE_PINVOKE_IMPL) || cols [1] & METHOD_IMPL_ATTRIBUTE_NATIVE)) {
1081 generic_container = mono_metadata_load_generic_params (image, token, container);
1082 if (generic_container) {
1083 mono_metadata_load_generic_param_constraints (image, token, generic_container);
1084 container = generic_container;
1088 if (!sig) /* already taken from the methodref */
1089 sig = mono_metadata_blob_heap (image, cols [4]);
1090 size = mono_metadata_decode_blob_size (sig, &sig);
1092 /* there are generic params, or a container. FIXME: be lazy here for generics*/
1093 if (* sig & 0x10 || container) {
1094 result->signature = mono_metadata_parse_method_signature_full (
1095 image, container, idx, sig, NULL);
1097 if (cols [1] & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
1098 result->signature->pinvoke = 1;
1101 if (!result->klass) {
1102 guint32 type = mono_metadata_typedef_from_method (image, token);
1103 result->klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | type);
1106 if (cols [1] & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
1107 if (result->klass == mono_defaults.string_class && !strcmp (result->name, ".ctor"))
1108 result->string_ctor = 1;
1109 } else if ((cols [2] & METHOD_ATTRIBUTE_PINVOKE_IMPL) && (!(cols [1] & METHOD_IMPL_ATTRIBUTE_NATIVE))) {
1110 MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)result;
1111 MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
1113 piinfo->implmap_idx = mono_metadata_implmap_from_method (image, idx - 1);
1114 piinfo->piflags = mono_metadata_decode_row_col (im, piinfo->implmap_idx - 1, MONO_IMPLMAP_FLAGS);
1116 if (result->signature && result->signature->generic_param_count) {
1117 MonoMethodSignature *sig = result->signature;
1119 for (i = 0; i < sig->generic_param_count; i++) {
1120 generic_container->type_params [i].method = result;
1122 mono_class_from_generic_parameter (
1123 &generic_container->type_params [i], image, TRUE);
1126 if (sig->ret->type == MONO_TYPE_MVAR) {
1127 int num = sig->ret->data.generic_param->num;
1128 sig->ret->data.generic_param = &generic_container->type_params [num];
1131 for (i = 0; i < sig->param_count; i++) {
1132 MonoType *t = sig->params [i];
1133 if (t->type == MONO_TYPE_MVAR) {
1134 int num = t->data.generic_param->num;
1135 sig->params [i]->data.generic_param = &generic_container->type_params [num];
1140 /* FIXME: lazyness for generics too, but how? */
1141 if (!result->klass->dummy && !(result->flags & METHOD_ATTRIBUTE_ABSTRACT) &&
1142 !(result->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) && container) {
1143 gpointer loc = mono_image_rva_map (image, cols [0]);
1145 ((MonoMethodNormal *) result)->header = mono_metadata_parse_mh_full (
1146 image, (MonoGenericContext *) container, loc);
1149 ((MonoMethodNormal *) result)->generic_container = generic_container;
1156 mono_get_method (MonoImage *image, guint32 token, MonoClass *klass)
1158 return mono_get_method_full (image, token, klass, NULL);
1162 mono_get_method_full (MonoImage *image, guint32 token, MonoClass *klass,
1163 MonoGenericContext *context)
1167 /* We do everything inside the lock to prevent creation races */
1169 mono_loader_lock ();
1171 if ((result = g_hash_table_lookup (image->method_cache, GINT_TO_POINTER (token)))) {
1172 mono_loader_unlock ();
1176 result = mono_get_method_from_token (image, token, klass, context);
1178 //printf ("GET: %s\n", mono_method_full_name (result, TRUE));
1180 if (!(result && result->is_inflated))
1181 g_hash_table_insert (image->method_cache, GINT_TO_POINTER (token), result);
1183 mono_loader_unlock ();
1189 mono_get_method_constrained (MonoImage *image, guint32 token, MonoClass *constrained_class,
1190 MonoGenericContext *context)
1192 MonoMethod *method, *result;
1193 MonoClass *ic = NULL;
1194 MonoGenericClass *gclass = NULL;
1196 mono_loader_lock ();
1198 method = mono_get_method_from_token (image, token, NULL, context);
1200 mono_loader_unlock ();
1204 mono_class_init (constrained_class);
1205 method = mono_get_inflated_method (method);
1207 if ((constrained_class != method->klass) && (method->klass->interface_id != 0))
1210 if (constrained_class->generic_class)
1211 gclass = constrained_class->generic_class;
1213 result = find_method (
1214 constrained_class, ic, method->name, mono_method_signature (method),
1215 context ? context->container : NULL);
1217 g_warning ("Missing method %s in assembly %s token %x", method->name,
1218 image->name, token);
1221 result = mono_class_inflate_generic_method (result, gclass->context);
1223 mono_loader_unlock ();
1228 mono_free_method (MonoMethod *method)
1230 if (method->signature) {
1232 * FIXME: This causes crashes because the types inside signatures and
1233 * locals are shared.
1235 /* mono_metadata_free_method_signature (method->signature); */
1236 g_free (method->signature);
1239 if (method->dynamic) {
1240 MonoMethodWrapper *mw = (MonoMethodWrapper*)method;
1242 g_free ((char*)method->name);
1243 if (mw->method.header)
1244 g_free ((char*)mw->method.header->code);
1245 g_free (mw->method_data);
1248 if (!(method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) && ((MonoMethodNormal *)method)->header) {
1250 /* mono_metadata_free_mh (((MonoMethodNormal *)method)->header); */
1251 g_free (((MonoMethodNormal*)method)->header);
1258 mono_method_get_param_names (MonoMethod *method, const char **names)
1261 MonoClass *klass = method->klass;
1262 MonoTableInfo *methodt;
1263 MonoTableInfo *paramt;
1266 if (!mono_method_signature (method)->param_count)
1268 for (i = 0; i < mono_method_signature (method)->param_count; ++i)
1271 if (klass->generic_class) /* copy the names later */
1274 mono_class_init (klass);
1276 if (klass->image->dynamic) {
1277 MonoReflectionMethodAux *method_aux =
1278 g_hash_table_lookup (
1279 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
1280 if (method_aux && method_aux->param_names) {
1281 for (i = 0; i < mono_method_signature (method)->param_count; ++i)
1282 if (method_aux->param_names [i + 1])
1283 names [i] = method_aux->param_names [i + 1];
1288 methodt = &klass->image->tables [MONO_TABLE_METHOD];
1289 paramt = &klass->image->tables [MONO_TABLE_PARAM];
1290 idx = mono_method_get_index (method);
1292 guint32 cols [MONO_PARAM_SIZE];
1293 guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);
1295 if (idx < methodt->rows)
1296 lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
1298 lastp = paramt->rows + 1;
1299 for (i = param_index; i < lastp; ++i) {
1300 mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
1301 if (cols [MONO_PARAM_SEQUENCE]) /* skip return param spec */
1302 names [cols [MONO_PARAM_SEQUENCE] - 1] = mono_metadata_string_heap (klass->image, cols [MONO_PARAM_NAME]);
1309 mono_method_get_param_token (MonoMethod *method, int index)
1311 MonoClass *klass = method->klass;
1312 MonoTableInfo *methodt;
1315 if (klass->generic_class)
1316 g_assert_not_reached ();
1318 mono_class_init (klass);
1320 if (klass->image->dynamic) {
1321 g_assert_not_reached ();
1324 methodt = &klass->image->tables [MONO_TABLE_METHOD];
1325 idx = mono_method_get_index (method);
1327 guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);
1329 return mono_metadata_make_token (MONO_TABLE_PARAM, param_index + index);
1336 mono_method_get_marshal_info (MonoMethod *method, MonoMarshalSpec **mspecs)
1339 MonoClass *klass = method->klass;
1340 MonoTableInfo *methodt;
1341 MonoTableInfo *paramt;
1344 for (i = 0; i < mono_method_signature (method)->param_count + 1; ++i)
1347 if (method->klass->image->dynamic) {
1348 MonoReflectionMethodAux *method_aux =
1349 g_hash_table_lookup (
1350 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
1351 if (method_aux && method_aux->param_marshall) {
1352 MonoMarshalSpec **dyn_specs = method_aux->param_marshall;
1353 for (i = 0; i < mono_method_signature (method)->param_count + 1; ++i)
1354 if (dyn_specs [i]) {
1355 mspecs [i] = g_new0 (MonoMarshalSpec, 1);
1356 memcpy (mspecs [i], dyn_specs [i], sizeof (MonoMarshalSpec));
1362 mono_class_init (klass);
1364 methodt = &klass->image->tables [MONO_TABLE_METHOD];
1365 paramt = &klass->image->tables [MONO_TABLE_PARAM];
1366 idx = mono_method_get_index (method);
1368 guint32 cols [MONO_PARAM_SIZE];
1369 guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);
1371 if (idx < methodt->rows)
1372 lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
1374 lastp = paramt->rows + 1;
1376 for (i = param_index; i < lastp; ++i) {
1377 mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
1379 if (cols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL) {
1381 tp = mono_metadata_get_marshal_info (klass->image, i - 1, FALSE);
1383 mspecs [cols [MONO_PARAM_SEQUENCE]]= mono_metadata_parse_marshal_spec (klass->image, tp);
1392 mono_method_has_marshal_info (MonoMethod *method)
1395 MonoClass *klass = method->klass;
1396 MonoTableInfo *methodt;
1397 MonoTableInfo *paramt;
1400 if (method->klass->image->dynamic) {
1401 MonoReflectionMethodAux *method_aux =
1402 g_hash_table_lookup (
1403 ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
1404 MonoMarshalSpec **dyn_specs = method_aux->param_marshall;
1406 for (i = 0; i < mono_method_signature (method)->param_count + 1; ++i)
1413 mono_class_init (klass);
1415 methodt = &klass->image->tables [MONO_TABLE_METHOD];
1416 paramt = &klass->image->tables [MONO_TABLE_PARAM];
1417 idx = mono_method_get_index (method);
1419 guint32 cols [MONO_PARAM_SIZE];
1420 guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);
1422 if (idx + 1 < methodt->rows)
1423 lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
1425 lastp = paramt->rows + 1;
1427 for (i = param_index; i < lastp; ++i) {
1428 mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
1430 if (cols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL)
1439 mono_method_get_wrapper_data (MonoMethod *method, guint32 id)
1442 g_assert (method != NULL);
1443 g_assert (method->wrapper_type != MONO_WRAPPER_NONE);
1445 data = ((MonoMethodWrapper *)method)->method_data;
1446 g_assert (data != NULL);
1447 g_assert (id <= GPOINTER_TO_UINT (*data));
1452 default_stack_walk (MonoStackWalk func, gboolean do_il_offset, gpointer user_data) {
1453 g_error ("stack walk not installed");
1456 static MonoStackWalkImpl stack_walk = default_stack_walk;
1459 mono_stack_walk (MonoStackWalk func, gpointer user_data)
1461 stack_walk (func, TRUE, user_data);
1465 mono_stack_walk_no_il (MonoStackWalk func, gpointer user_data)
1467 stack_walk (func, FALSE, user_data);
1471 mono_install_stack_walk (MonoStackWalkImpl func)
1477 last_managed (MonoMethod *m, gint no, gint ilo, gboolean managed, gpointer data)
1479 MonoMethod **dest = data;
1481 /*g_print ("In %s::%s [%d] [%d]\n", m->klass->name, m->name, no, ilo);*/
1487 mono_method_get_last_managed (void)
1489 MonoMethod *m = NULL;
1490 stack_walk (last_managed, FALSE, &m);
1495 mono_loader_lock (void)
1497 EnterCriticalSection (&loader_mutex);
1501 mono_loader_unlock (void)
1503 LeaveCriticalSection (&loader_mutex);
1506 MonoMethodSignature*
1507 mono_method_signature (MonoMethod *m)
1509 m = mono_get_inflated_method (m);
1510 return mono_method_signature_full (m, NULL);
1513 MonoMethodSignature*
1514 mono_method_signature_full (MonoMethod *m, MonoGenericContainer *container)
1522 return m->signature;
1524 mono_loader_lock ();
1527 mono_loader_unlock ();
1528 return m->signature;
1531 g_assert (mono_metadata_token_table (m->token) == MONO_TABLE_METHOD);
1532 idx = mono_metadata_token_index (m->token);
1533 img = m->klass->image;
1535 sig = mono_metadata_blob_heap (img, mono_metadata_decode_row_col (&img->tables [MONO_TABLE_METHOD], idx - 1, MONO_METHOD_SIGNATURE));
1536 size = mono_metadata_decode_blob_size (sig, &sig);
1538 m->signature = mono_metadata_parse_method_signature_full (img, container, idx, sig, NULL);
1540 if (m->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)
1541 m->signature->pinvoke = 1;
1542 else if ((m->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) && (!(m->iflags & METHOD_IMPL_ATTRIBUTE_NATIVE))) {
1543 MonoCallConvention conv = 0;
1544 MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)m;
1545 m->signature->pinvoke = 1;
1547 switch (piinfo->piflags & PINVOKE_ATTRIBUTE_CALL_CONV_MASK) {
1548 case 0: /* no call conv, so using default */
1549 case PINVOKE_ATTRIBUTE_CALL_CONV_WINAPI:
1550 conv = MONO_CALL_DEFAULT;
1552 case PINVOKE_ATTRIBUTE_CALL_CONV_CDECL:
1555 case PINVOKE_ATTRIBUTE_CALL_CONV_STDCALL:
1556 conv = MONO_CALL_STDCALL;
1558 case PINVOKE_ATTRIBUTE_CALL_CONV_THISCALL:
1559 conv = MONO_CALL_THISCALL;
1561 case PINVOKE_ATTRIBUTE_CALL_CONV_FASTCALL:
1562 conv = MONO_CALL_FASTCALL;
1564 case PINVOKE_ATTRIBUTE_CALL_CONV_GENERIC:
1565 case PINVOKE_ATTRIBUTE_CALL_CONV_GENERICINST:
1567 g_warning ("unsupported calling convention : 0x%04x", piinfo->piflags);
1568 g_assert_not_reached ();
1570 m->signature->call_convention = conv;
1573 mono_loader_unlock ();
1574 return m->signature;
1578 mono_method_get_name (MonoMethod *method)
1580 return method->name;
1584 mono_method_get_class (MonoMethod *method)
1586 return method->klass;
1590 mono_method_get_token (MonoMethod *method)
1592 return method->token;
1596 mono_method_get_header (MonoMethod *method)
1602 MonoMethodNormal* mn = (MonoMethodNormal*) method;
1605 if (G_LIKELY (mn->header))
1611 if (method->klass->dummy || (method->flags & METHOD_ATTRIBUTE_ABSTRACT) || (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) || (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
1614 mono_loader_lock ();
1617 mono_loader_unlock ();
1621 g_assert (mono_metadata_token_table (method->token) == MONO_TABLE_METHOD);
1622 idx = mono_metadata_token_index (method->token);
1623 img = method->klass->image;
1624 rva = mono_metadata_decode_row_col (&img->tables [MONO_TABLE_METHOD], idx - 1, MONO_METHOD_RVA);
1625 loc = mono_image_rva_map (img, rva);
1629 mn->header = mono_metadata_parse_mh_full (img, (MonoGenericContext *) mn->generic_container, loc);
1631 mono_loader_unlock ();
1636 mono_method_get_flags (MonoMethod *method, guint32 *iflags)
1639 *iflags = method->iflags;
1640 return method->flags;
1644 * Find the method index in the metadata methodDef table.
1647 mono_method_get_index (MonoMethod *method) {
1648 MonoClass *klass = method->klass;
1652 return mono_metadata_token_index (method->token);
1654 mono_class_setup_methods (klass);
1655 for (i = 0; i < klass->method.count; ++i) {
1656 if (method == klass->methods [i])
1657 return klass->method.first + 1 + i;