2 * loader.c: Image Loader
5 * Paolo Molaro (lupus@ximian.com)
6 * Miguel de Icaza (miguel@ximian.com)
8 * (C) 2001 Ximian, Inc.
10 * This file is used by the interpreter and the JIT engine to locate
11 * assemblies. Used to load AssemblyRef and later to resolve various
15 * This should keep track of the assembly versions that we are loading.
21 #include <mono/metadata/metadata.h>
22 #include <mono/metadata/image.h>
23 #include <mono/metadata/cil-coff.h>
27 mono_get_method (MonoImage *image, guint32 token)
30 int table = mono_metadata_token_table (token);
31 int index = mono_metadata_token_index (token);
32 metadata_tableinfo_t *tables = image->metadata.tables;
34 const char *sig = NULL;
38 if ((result = g_hash_table_lookup (image->method_cache, GINT_TO_POINTER (token))))
41 result = g_new0 (MonoMethod, 1);
42 result->image = image;
44 * We need a context with cli_image_info_t for this module and the assemblies
45 * loaded later to support method refs...
47 if (table != META_TABLE_METHOD) {
48 g_assert (table == META_TABLE_MEMBERREF);
49 mono_metadata_decode_row (&tables [table], index-1, cols, 3);
50 g_print ("methodref: 0x%x 0x%x", cols [0] & 7, cols [0] >> 3);
51 index = cols [0] >> 3;
52 sig = mono_metadata_blob_heap (&image->metadata, cols [2]);
53 result->name_idx = cols [1];
54 /* Need to finish this code ... */
55 switch ((cols [0] & 0x07)) {
57 mono_metadata_decode_row (&tables [META_TABLE_TYPEREF], index, cols, 3);
61 g_assert_not_reached ();
63 table = META_TABLE_METHOD;
66 mono_metadata_decode_row (&tables [table], index - 1, cols, 6);
67 result->name_idx = cols [3];
68 /* if this is a methodref from another module/assembly, this fails */
69 loc = cli_rva_map ((cli_image_info_t *)image->image_info, cols [0]);
71 result->header = mono_metadata_parse_mh (&image->metadata, loc);
72 if (!sig) /* already taken from the methodref */
73 sig = mono_metadata_blob_heap (&image->metadata, cols [4]);
74 size = mono_metadata_decode_blob_size (sig, &sig);
75 result->signature = mono_metadata_parse_method_signature (&image->metadata, 0, sig, NULL);
77 g_hash_table_insert (image->method_cache, GINT_TO_POINTER (token), result);
83 mono_free_method (MonoMethod *method)
85 mono_metadata_free_method_signature (method->signature);
86 mono_metadata_free_mh (method->header);