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)
29 MonoMethod *result = g_new0 (MonoMethod, 1);
30 int table = mono_metadata_token_table (token);
31 int index = mono_metadata_token_index (token);
32 cli_image_info_t *iinfo = image->image_info;
33 metadata_tableinfo_t *tables = iinfo->cli_metadata.tables;
35 const char *sig = NULL;
40 * We need a context with cli_image_info_t for this module and the assemblies
41 * loaded later to support method refs...
43 if (table != META_TABLE_METHOD) {
44 g_assert (table == META_TABLE_MEMBERREF);
45 mono_metadata_decode_row (&tables [table], index, cols, 3);
46 g_assert ((cols [0] & 0x07) != 3);
47 table = META_TABLE_METHOD;
48 index = cols [0] >> 3;
49 sig = mono_metadata_blob_heap (&iinfo->cli_metadata, cols [2]);
50 result->name_idx = cols [1];
53 mono_metadata_decode_row (&tables [table], index - 1, cols, 6);
54 result->name_idx = cols [3];
55 /* if this is a methodref from another module/assembly, this fails */
56 loc = cli_rva_map (iinfo, cols [0]);
58 result->header = mono_metadata_parse_mh (&iinfo->cli_metadata, loc);
59 if (!sig) /* already taken from the methodref */
60 sig = mono_metadata_blob_heap (&iinfo->cli_metadata, cols [4]);
61 sig = mono_metadata_decode_blob_size (sig, &size);
62 result->signature = mono_metadata_parse_method_signature (&iinfo->cli_metadata, 0, sig, NULL);
68 mono_free_method (MonoMethod *method)
70 mono_metadata_free_method_signature (method->signature);
71 mono_metadata_free_mh (method->header);