2 * assembly.c: Routines for loading assemblies.
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc. http://www.ximian.com
19 #include "rawbuffer.h"
21 #include "mono-bundle.h"
23 #include <mono/metadata/loader.h>
24 #include <mono/metadata/tabledefs.h>
25 #include <mono/metadata/metadata-internals.h>
26 #include <mono/io-layer/io-layer.h>
27 #include <mono/utils/mono-uri.h>
28 #include <mono/metadata/mono-config.h>
29 #include <mono/utils/mono-digest.h>
30 #include <mono/utils/mono-logger.h>
32 #include <mono/os/util.h>
35 /* the default search path is just MONO_ASSEMBLIES */
42 static char **assemblies_path = NULL;
45 * keeps track of loaded assemblies
47 static GList *loaded_assemblies = NULL;
48 static MonoAssembly *corlib;
50 /* This protects loaded_assemblies and image->references */
51 static CRITICAL_SECTION assemblies_mutex;
53 /* A hastable of thread->assembly list mappings */
54 static GHashTable *assemblies_loading;
56 static char **extra_gac_paths = NULL;
59 encode_public_tok (const guchar *token, gint32 len)
61 const static gchar allowed [] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
65 res = g_malloc (len * 2 + 1);
66 for (i = 0; i < len; i++) {
67 res [i * 2] = allowed [token [i] >> 4];
68 res [i * 2 + 1] = allowed [token [i] & 0xF];
75 check_path_env (void) {
79 path = g_getenv ("MONO_PATH");
83 splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000);
85 g_strfreev (assemblies_path);
86 assemblies_path = splitted;
87 if (g_getenv ("MONO_DEBUG") == NULL)
91 if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR))
92 g_warning ("'%s' in MONO_PATH doesn't exist or has wrong permissions.", *splitted);
99 check_extra_gac_path_env (void) {
103 path = g_getenv ("MONO_GAC_PREFIX");
107 splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000);
109 g_strfreev (extra_gac_paths);
110 extra_gac_paths = splitted;
111 if (g_getenv ("MONO_DEBUG") == NULL)
115 if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR))
116 g_warning ("'%s' in MONO_GAC_PATH doesn't exist or has wrong permissions.", *splitted);
123 mono_assembly_names_equal (MonoAssemblyName *l, MonoAssemblyName *r)
125 if (!l->name || !r->name)
128 if (strcmp (l->name, r->name))
132 * simply compare names until some other issues are resolved
133 * (version info not getting set correctly for custom
137 if (l->major != r->major || l->minor != r->minor ||
138 l->build != r->build || l->revision != r->revision)
141 if (!l->public_tok_value && !r->public_tok_value)
144 if ((l->public_tok_value && !r->public_tok_value) || (!l->public_tok_value && r->public_tok_value))
147 if (strcmp (l->public_tok_value, r->public_tok_value))
153 /* assemblies_mutex must be held by the caller */
155 search_loaded (MonoAssemblyName* aname)
161 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
163 /* g_print ("compare %s %s\n", aname->name, ass->aname.name); */
164 if (!mono_assembly_names_equal (aname, &ass->aname))
166 /* g_print ("success\n"); */
172 * The assembly might be under load by this thread. In this case, it is
173 * safe to return an incomplete instance to prevent loops.
175 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
176 for (tmp = loading; tmp; tmp = tmp->next) {
178 if (!mono_assembly_names_equal (aname, &ass->aname))
187 static MonoAssembly *
188 load_in_path (const char *basename, const char** search_path, MonoImageOpenStatus *status)
192 MonoAssembly *result;
194 for (i = 0; search_path [i]; ++i) {
195 fullpath = g_build_filename (search_path [i], basename, NULL);
196 result = mono_assembly_open (fullpath, status);
205 * mono_assembly_setrootdir:
206 * @root_dir: The pathname of the root directory where we will locate assemblies
208 * This routine sets the internal default root directory for looking up
209 * assemblies. This is used by Windows installations to compute dynamically
210 * the place where the Mono assemblies are located.
214 mono_assembly_setrootdir (const char *root_dir)
217 * Override the MONO_ASSEMBLIES directory configured at compile time.
219 /* Leak if called more than once */
220 default_path [0] = g_strdup (root_dir);
223 G_CONST_RETURN gchar *
224 mono_assembly_getrootdir (void)
226 return default_path [0];
230 * mono_assemblies_init:
232 * Initialize global variables used by this module.
235 mono_assemblies_init (void)
237 #ifdef PLATFORM_WIN32
242 check_extra_gac_path_env ();
244 InitializeCriticalSection (&assemblies_mutex);
246 assemblies_loading = g_hash_table_new (NULL, NULL);
250 mono_assembly_fill_assembly_name (MonoImage *image, MonoAssemblyName *aname)
252 MonoTableInfo *t = &image->tables [MONO_TABLE_ASSEMBLY];
253 guint32 cols [MONO_ASSEMBLY_SIZE];
258 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
261 aname->hash_value = NULL;
262 aname->name = mono_metadata_string_heap (image, cols [MONO_ASSEMBLY_NAME]);
263 aname->culture = mono_metadata_string_heap (image, cols [MONO_ASSEMBLY_CULTURE]);
264 aname->flags = cols [MONO_ASSEMBLY_FLAGS];
265 aname->major = cols [MONO_ASSEMBLY_MAJOR_VERSION];
266 aname->minor = cols [MONO_ASSEMBLY_MINOR_VERSION];
267 aname->build = cols [MONO_ASSEMBLY_BUILD_NUMBER];
268 aname->revision = cols [MONO_ASSEMBLY_REV_NUMBER];
269 aname->hash_alg = cols [MONO_ASSEMBLY_HASH_ALG];
270 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
271 gchar* token = g_malloc (8);
275 aname->public_key = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
276 len = mono_metadata_decode_blob_size (aname->public_key, &aname->public_key);
278 mono_digest_get_public_token (token, aname->public_key, len);
279 encoded = encode_public_tok (token, 8);
280 g_strlcpy (aname->public_key_token, encoded, MONO_PUBLIC_KEY_TOKEN_LENGTH);
286 aname->public_key = NULL;
287 memset (aname->public_key_token, 0, MONO_PUBLIC_KEY_TOKEN_LENGTH);
290 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
291 aname->public_key = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
294 aname->public_key = 0;
300 assemblyref_public_tok (MonoImage *image, guint32 key_index, guint32 flags)
302 const gchar *public_tok;
305 public_tok = mono_metadata_blob_heap (image, key_index);
306 len = mono_metadata_decode_blob_size (public_tok, &public_tok);
308 if (flags & ASSEMBLYREF_FULL_PUBLIC_KEY_FLAG) {
310 mono_digest_get_public_token (token, public_tok, len);
311 return encode_public_tok (token, 8);
314 return encode_public_tok (public_tok, len);
318 mono_assembly_load_references (MonoImage *image, MonoImageOpenStatus *status)
321 guint32 cols [MONO_ASSEMBLYREF_SIZE];
324 MonoAssembly **references = NULL;
326 *status = MONO_IMAGE_OK;
329 * image->references is shared between threads, so we need to access
330 * it inside a critical section.
332 EnterCriticalSection (&assemblies_mutex);
333 references = image->references;
334 LeaveCriticalSection (&assemblies_mutex);
338 t = &image->tables [MONO_TABLE_ASSEMBLYREF];
340 references = g_new0 (MonoAssembly *, t->rows + 1);
343 * Load any assemblies this image references
345 for (i = 0; i < t->rows; i++) {
346 MonoAssemblyName aname;
348 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
350 hash = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLYREF_HASH_VALUE]);
351 aname.hash_len = mono_metadata_decode_blob_size (hash, &hash);
352 aname.hash_value = hash;
353 aname.name = mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME]);
354 aname.culture = mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_CULTURE]);
355 aname.flags = cols [MONO_ASSEMBLYREF_FLAGS];
356 aname.major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
357 aname.minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
358 aname.build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
359 aname.revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
361 if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]) {
362 gchar *token = assemblyref_public_tok (image, cols [MONO_ASSEMBLYREF_PUBLIC_KEY], aname.flags);
363 g_strlcpy (aname.public_key_token, token, MONO_PUBLIC_KEY_TOKEN_LENGTH);
366 memset (aname.public_key_token, 0, MONO_PUBLIC_KEY_TOKEN_LENGTH);
369 references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
371 if (references [i] == NULL){
375 ** Temporary work around: any System.* which are 3300 build, will get
376 ** remapped, this is to keep old applications running that might have
377 ** been linked against our 5000 API, before we were strongnamed, and
378 ** hence were labeled as 3300 builds by reflection.c
380 if (aname.build == 3300 && strncmp (aname.name, "System", 6) == 0){
383 references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
385 if (references [i] != NULL){
386 if (g_getenv ("MONO_SILENT_WARNING") == NULL)
387 g_printerr ("Compat mode: the request from %s to load %s was remapped (http://www.go-mono.com/remap.html)\n",
388 image->name, aname.name);
391 char *extra_msg = g_strdup ("");
393 if (*status == MONO_IMAGE_ERROR_ERRNO) {
394 extra_msg = g_strdup_printf ("System error: %s\n", strerror (errno));
395 } else if (*status == MONO_IMAGE_MISSING_ASSEMBLYREF) {
396 extra_msg = g_strdup ("Cannot find an assembly referenced from this one.\n");
397 } else if (*status == MONO_IMAGE_IMAGE_INVALID) {
398 extra_msg = g_strdup ("The file exists but is not a valid assembly.\n");
401 for (j = 0; j < i; j++)
402 mono_assembly_close (references [j]);
405 g_warning ("Could not find assembly %s, references from %s (assemblyref_index=%d)\n"
406 " Major/Minor: %d,%d\n"
409 aname.name, image->name, i,
410 aname.major, aname.minor, aname.build, aname.revision,
411 aname.public_key_token, extra_msg);
412 *status = MONO_IMAGE_MISSING_ASSEMBLYREF;
419 * This check is disabled since lots of people seem to have an older
420 * corlib which triggers this.
423 if (image->references [i]->image == image)
424 g_error ("Error: Assembly %s references itself", image->name);
427 references [i] = NULL;
429 /* resolve assembly references for modules */
430 t = &image->tables [MONO_TABLE_MODULEREF];
431 for (i = 0; i < t->rows; i++){
432 if (image->modules [i]) {
433 image->modules [i]->assembly = image->assembly;
434 mono_assembly_load_references (image->modules [i], status);
438 EnterCriticalSection (&assemblies_mutex);
439 if (!image->references)
440 image->references = references;
441 LeaveCriticalSection (&assemblies_mutex);
443 if (image->references != references) {
444 /* Somebody loaded it before us */
445 for (i = 0; i < t->rows; i++)
446 mono_assembly_close (references [i]);
451 typedef struct AssemblyLoadHook AssemblyLoadHook;
452 struct AssemblyLoadHook {
453 AssemblyLoadHook *next;
454 MonoAssemblyLoadFunc func;
458 AssemblyLoadHook *assembly_load_hook = NULL;
461 mono_assembly_invoke_load_hook (MonoAssembly *ass)
463 AssemblyLoadHook *hook;
465 for (hook = assembly_load_hook; hook; hook = hook->next) {
466 hook->func (ass, hook->user_data);
471 mono_install_assembly_load_hook (MonoAssemblyLoadFunc func, gpointer user_data)
473 AssemblyLoadHook *hook;
475 g_return_if_fail (func != NULL);
477 hook = g_new0 (AssemblyLoadHook, 1);
479 hook->user_data = user_data;
480 hook->next = assembly_load_hook;
481 assembly_load_hook = hook;
484 typedef struct AssemblyPreLoadHook AssemblyPreLoadHook;
485 struct AssemblyPreLoadHook {
486 AssemblyPreLoadHook *next;
487 MonoAssemblyPreLoadFunc func;
491 AssemblyPreLoadHook *assembly_preload_hook = NULL;
493 static MonoAssembly *
494 invoke_assembly_preload_hook (MonoAssemblyName *aname, gchar **assemblies_path)
496 AssemblyPreLoadHook *hook;
497 MonoAssembly *assembly;
499 for (hook = assembly_preload_hook; hook; hook = hook->next) {
500 assembly = hook->func (aname, assemblies_path, hook->user_data);
501 if (assembly != NULL)
509 mono_install_assembly_preload_hook (MonoAssemblyPreLoadFunc func, gpointer user_data)
511 AssemblyPreLoadHook *hook;
513 g_return_if_fail (func != NULL);
515 hook = g_new0 (AssemblyPreLoadHook, 1);
517 hook->user_data = user_data;
518 hook->next = assembly_preload_hook;
519 assembly_preload_hook = hook;
523 absolute_dir (const gchar *filename)
534 if (g_path_is_absolute (filename))
535 return g_path_get_dirname (filename);
537 cwd = g_get_current_dir ();
538 mixed = g_build_filename (cwd, filename, NULL);
539 parts = g_strsplit (mixed, G_DIR_SEPARATOR_S, 0);
544 for (i = 0; (part = parts [i]) != NULL; i++) {
545 if (!strcmp (part, "."))
548 if (!strcmp (part, "..")) {
549 if (list && list->next) /* Don't remove root */
550 list = g_list_delete_link (list, list);
552 list = g_list_prepend (list, part);
556 result = g_string_new ("");
557 list = g_list_reverse (list);
559 /* Ignores last data pointer, which should be the filename */
560 for (tmp = list; tmp && tmp->next != NULL; tmp = tmp->next)
562 g_string_append_printf (result, "%s%c", (char *) tmp->data,
566 g_string_free (result, FALSE);
571 return g_strdup (".");
578 do_mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
580 MonoImage *image = NULL;
583 char *name = g_path_get_basename (filename);
584 char *dot = strrchr (name, '.');
590 /* we do a very simple search for bundled assemblies: it's not a general
591 * purpose assembly loading mechanism.
593 EnterCriticalSection (&assemblies_mutex);
594 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
596 if (!ass->aname.name)
598 if (strcmp (name, ass->aname.name))
604 for (i = 0; !image && bundled_assemblies [i]; ++i) {
605 if (strcmp (bundled_assemblies [i]->name, name) == 0) {
606 image = mono_image_open_from_data ((char*)bundled_assemblies [i]->data, bundled_assemblies [i]->size, FALSE, status);
610 LeaveCriticalSection (&assemblies_mutex);
613 mono_image_addref (image);
617 EnterCriticalSection (&assemblies_mutex);
618 image = mono_image_open (filename, status);
619 LeaveCriticalSection (&assemblies_mutex);
625 * mono_assembly_open:
626 * @filename: Opens the assembly pointed out by this name
627 * @status: where a status code can be returned
629 * mono_assembly_open opens the PE-image pointed by @filename, and
630 * loads any external assemblies referenced by it.
632 * NOTE: we could do lazy loading of the assemblies. Or maybe not worth
636 mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
640 MonoImageOpenStatus def_status;
643 g_return_val_if_fail (filename != NULL, NULL);
646 status = &def_status;
647 *status = MONO_IMAGE_OK;
649 if (strncmp (filename, "file://", 7) == 0) {
650 GError *error = NULL;
651 gchar *uri = (gchar *) filename;
655 * MS allows file://c:/... and fails on file://localhost/c:/...
656 * They also throw an IndexOutOfRangeException if "file://"
659 uri = g_strdup_printf ("file:///%s", uri + 7);
662 uri = mono_escape_uri_string (tmpuri);
663 fname = g_filename_from_uri (uri, NULL, &error);
666 if (tmpuri != filename)
670 g_warning ("%s\n", error->message);
671 g_error_free (error);
672 fname = g_strdup (filename);
675 fname = g_strdup (filename);
678 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
679 "Assembly Loader probing location: '%s'.", filename);
680 image = do_mono_assembly_open (fname, status);
683 *status = MONO_IMAGE_ERROR_ERRNO;
688 ass = mono_assembly_load_from (image, fname, status);
691 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
692 "Assembly Loader loaded assembly from location: '%s'.", filename);
693 mono_config_for_assembly (ass->image);
702 mono_assembly_load_from (MonoImage *image, const char*fname,
703 MonoImageOpenStatus *status)
705 MonoAssembly *ass, *ass2;
709 #if defined (PLATFORM_WIN32)
714 tmp_fn = g_strdup (fname);
715 for (i = strlen (tmp_fn) - 1; i >= 0; i--) {
716 if (tmp_fn [i] == '/')
720 base_dir = absolute_dir (tmp_fn);
724 base_dir = absolute_dir (fname);
728 * To avoid deadlocks and scalability problems, we load assemblies outside
729 * the assembly lock. This means that multiple threads might try to load
730 * the same assembly at the same time. The first one to load it completely
731 * "wins", the other threads free their copy and use the one loaded by
732 * the winning thread.
736 * Create assembly struct, and enter it into the assembly cache
738 ass = g_new0 (MonoAssembly, 1);
739 ass->basedir = base_dir;
742 mono_assembly_fill_assembly_name (image, &ass->aname);
745 * Atomically search the loaded list and add ourselves to it if necessary.
747 EnterCriticalSection (&assemblies_mutex);
749 /* avoid loading the same assembly twice for now... */
750 if ((ass2 = search_loaded (&ass->aname))) {
753 mono_image_close (image);
754 *status = MONO_IMAGE_OK;
755 LeaveCriticalSection (&assemblies_mutex);
758 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
759 loading = g_list_prepend (loading, ass);
760 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
761 LeaveCriticalSection (&assemblies_mutex);
763 image->assembly = ass;
766 * We load referenced assemblies outside the lock to prevent deadlocks
767 * with regards to preload hooks.
769 mono_assembly_load_references (image, status);
771 EnterCriticalSection (&assemblies_mutex);
773 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
774 loading = g_list_remove (loading, ass);
776 /* Prevent memory leaks */
777 g_hash_table_remove (assemblies_loading, GetCurrentThread ());
779 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
780 if (*status != MONO_IMAGE_OK) {
781 LeaveCriticalSection (&assemblies_mutex);
782 mono_assembly_close (ass);
786 if (ass->aname.name) {
787 ass2 = search_loaded (&ass->aname);
789 /* Somebody else has loaded the assembly before us */
790 LeaveCriticalSection (&assemblies_mutex);
791 mono_assembly_close (ass);
796 loaded_assemblies = g_list_prepend (loaded_assemblies, ass);
797 LeaveCriticalSection (&assemblies_mutex);
799 mono_assembly_invoke_load_hook (ass);
805 probe_for_partial_name (const char *basepath, const char *fullname, MonoImageOpenStatus *status)
807 MonoAssembly *res = NULL;
810 const char* direntry;
812 dirhandle = g_dir_open (basepath, 0, NULL);
816 while ((direntry = g_dir_read_name (dirhandle))) {
817 fullpath = g_build_path (G_DIR_SEPARATOR_S, basepath, direntry, fullname, NULL);
818 res = mono_assembly_open (fullpath, status);
823 g_dir_close (dirhandle);
829 mono_assembly_load_with_partial_name (const char *name, MonoImageOpenStatus *status)
832 MonoAssemblyName aname;
833 gchar *fullname, *gacpath;
836 memset (&aname, 0, sizeof (MonoAssemblyName));
839 res = invoke_assembly_preload_hook (&aname, assemblies_path);
845 res = mono_assembly_loaded (&aname);
849 fullname = g_strdup_printf ("%s.dll", name);
851 if (extra_gac_paths) {
852 paths = extra_gac_paths;
853 while (!res && *paths) {
854 gacpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", name, NULL);
855 res = probe_for_partial_name (gacpath, fullname, status);
868 gacpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), "mono", "gac", name, NULL);
869 res = probe_for_partial_name (gacpath, fullname, status);
881 * mono_assembly_load_from_gac
883 * @aname: The assembly name object
886 mono_assembly_load_from_gac (MonoAssemblyName *aname, gchar *filename, MonoImageOpenStatus *status)
888 MonoAssembly *result = NULL;
889 gchar *name, *version, *culture, *fullpath, *subpath;
893 if (aname->public_key_token [0] == NULL) {
897 if (strstr (aname->name, ".dll")) {
898 len = strlen (filename) - 4;
899 name = g_malloc (len);
900 strncpy (name, aname->name, len);
902 name = g_strdup (aname->name);
905 if (aname->culture) {
906 culture = g_strdup (aname->culture);
909 culture = g_strdup ("");
912 version = g_strdup_printf ("%d.%d.%d.%d_%s_%s", aname->major,
913 aname->minor, aname->build, aname->revision,
914 culture, aname->public_key_token);
916 subpath = g_build_path (G_DIR_SEPARATOR_S, name, version, filename, NULL);
921 if (extra_gac_paths) {
922 paths = extra_gac_paths;
923 while (!result && *paths) {
924 fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", subpath, NULL);
925 result = mono_assembly_open (fullpath, status);
932 result->in_gac = TRUE;
937 fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (),
938 "mono", "gac", subpath, NULL);
939 result = mono_assembly_open (fullpath, status);
943 result->in_gac = TRUE;
952 mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status)
954 MonoAssembly *result;
955 char *fullpath, *filename;
957 result = invoke_assembly_preload_hook (aname, assemblies_path);
959 result->in_gac = FALSE;
963 result = mono_assembly_loaded (aname);
967 /* g_print ("loading %s\n", aname->name); */
968 /* special case corlib */
969 if (strcmp (aname->name, "mscorlib") == 0) {
971 /* g_print ("corlib already loaded\n"); */
974 /* g_print ("corlib load\n"); */
975 if (assemblies_path) {
976 corlib = load_in_path ("mscorlib.dll", (const char**)assemblies_path, status);
980 corlib = load_in_path ("mscorlib.dll", default_path, status);
984 if (strstr (aname->name, ".dll"))
985 filename = g_strdup (aname->name);
987 filename = g_strconcat (aname->name, ".dll", NULL);
989 result = mono_assembly_load_from_gac (aname, filename, status);
996 fullpath = g_build_filename (basedir, filename, NULL);
997 result = mono_assembly_open (fullpath, status);
1000 result->in_gac = FALSE;
1006 result = load_in_path (filename, default_path, status);
1008 result->in_gac = FALSE;
1014 mono_assembly_loaded (MonoAssemblyName *aname)
1018 EnterCriticalSection (&assemblies_mutex);
1019 res = search_loaded (aname);
1020 LeaveCriticalSection (&assemblies_mutex);
1026 mono_assembly_close (MonoAssembly *assembly)
1031 g_return_if_fail (assembly != NULL);
1033 EnterCriticalSection (&assemblies_mutex);
1034 if (--assembly->ref_count != 0) {
1035 LeaveCriticalSection (&assemblies_mutex);
1038 loaded_assemblies = g_list_remove (loaded_assemblies, assembly);
1039 LeaveCriticalSection (&assemblies_mutex);
1040 image = assembly->image;
1041 if (image->references) {
1042 for (i = 0; image->references [i] != NULL; i++)
1043 mono_image_close (image->references [i]->image);
1044 g_free (image->references);
1047 mono_image_close (assembly->image);
1049 g_free (assembly->basedir);
1054 mono_assembly_load_module (MonoAssembly *assembly, guint32 idx)
1056 MonoImageOpenStatus status;
1059 module = mono_image_load_file_for_image (assembly->image, idx);
1061 mono_assembly_load_references (module, &status);
1067 mono_assembly_foreach (GFunc func, gpointer user_data)
1072 * We make a copy of the list to avoid calling the callback inside the
1073 * lock, which could lead to deadlocks.
1075 EnterCriticalSection (&assemblies_mutex);
1076 copy = g_list_copy (loaded_assemblies);
1077 LeaveCriticalSection (&assemblies_mutex);
1079 g_list_foreach (loaded_assemblies, func, user_data);
1084 /* Holds the assembly of the application, for
1085 * System.Diagnostics.Process::MainModule
1087 static MonoAssembly *main_assembly=NULL;
1090 mono_assembly_set_main (MonoAssembly *assembly)
1092 main_assembly=assembly;
1096 mono_assembly_get_main (void)
1098 return(main_assembly);
1102 mono_assembly_get_image (MonoAssembly *assembly)
1104 return assembly->image;