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);
392 for (j = 0; j < i; j++)
393 mono_assembly_close (references [j]);
396 g_warning ("Could not find assembly %s, references from %s (assemblyref_index=%d)\n"
397 " Major/Minor: %d,%d\n"
400 aname.name, image->name, i,
401 aname.major, aname.minor, aname.build, aname.revision,
402 aname.public_key_token);
403 *status = MONO_IMAGE_MISSING_ASSEMBLYREF;
409 * This check is disabled since lots of people seem to have an older
410 * corlib which triggers this.
413 if (image->references [i]->image == image)
414 g_error ("Error: Assembly %s references itself", image->name);
417 references [i] = NULL;
419 /* resolve assembly references for modules */
420 t = &image->tables [MONO_TABLE_MODULEREF];
421 for (i = 0; i < t->rows; i++){
422 if (image->modules [i]) {
423 image->modules [i]->assembly = image->assembly;
424 mono_assembly_load_references (image->modules [i], status);
428 EnterCriticalSection (&assemblies_mutex);
429 if (!image->references)
430 image->references = references;
431 LeaveCriticalSection (&assemblies_mutex);
433 if (image->references != references) {
434 /* Somebody loaded it before us */
435 for (i = 0; i < t->rows; i++)
436 mono_assembly_close (references [i]);
441 typedef struct AssemblyLoadHook AssemblyLoadHook;
442 struct AssemblyLoadHook {
443 AssemblyLoadHook *next;
444 MonoAssemblyLoadFunc func;
448 AssemblyLoadHook *assembly_load_hook = NULL;
451 mono_assembly_invoke_load_hook (MonoAssembly *ass)
453 AssemblyLoadHook *hook;
455 for (hook = assembly_load_hook; hook; hook = hook->next) {
456 hook->func (ass, hook->user_data);
461 mono_install_assembly_load_hook (MonoAssemblyLoadFunc func, gpointer user_data)
463 AssemblyLoadHook *hook;
465 g_return_if_fail (func != NULL);
467 hook = g_new0 (AssemblyLoadHook, 1);
469 hook->user_data = user_data;
470 hook->next = assembly_load_hook;
471 assembly_load_hook = hook;
474 typedef struct AssemblyPreLoadHook AssemblyPreLoadHook;
475 struct AssemblyPreLoadHook {
476 AssemblyPreLoadHook *next;
477 MonoAssemblyPreLoadFunc func;
481 AssemblyPreLoadHook *assembly_preload_hook = NULL;
483 static MonoAssembly *
484 invoke_assembly_preload_hook (MonoAssemblyName *aname, gchar **assemblies_path)
486 AssemblyPreLoadHook *hook;
487 MonoAssembly *assembly;
489 for (hook = assembly_preload_hook; hook; hook = hook->next) {
490 assembly = hook->func (aname, assemblies_path, hook->user_data);
491 if (assembly != NULL)
499 mono_install_assembly_preload_hook (MonoAssemblyPreLoadFunc func, gpointer user_data)
501 AssemblyPreLoadHook *hook;
503 g_return_if_fail (func != NULL);
505 hook = g_new0 (AssemblyPreLoadHook, 1);
507 hook->user_data = user_data;
508 hook->next = assembly_preload_hook;
509 assembly_preload_hook = hook;
513 absolute_dir (const gchar *filename)
524 if (g_path_is_absolute (filename))
525 return g_path_get_dirname (filename);
527 cwd = g_get_current_dir ();
528 mixed = g_build_filename (cwd, filename, NULL);
529 parts = g_strsplit (mixed, G_DIR_SEPARATOR_S, 0);
534 for (i = 0; (part = parts [i]) != NULL; i++) {
535 if (!strcmp (part, "."))
538 if (!strcmp (part, "..")) {
539 if (list && list->next) /* Don't remove root */
540 list = g_list_delete_link (list, list);
542 list = g_list_prepend (list, part);
546 result = g_string_new ("");
547 list = g_list_reverse (list);
549 /* Ignores last data pointer, which should be the filename */
550 for (tmp = list; tmp && tmp->next != NULL; tmp = tmp->next)
552 g_string_append_printf (result, "%s%c", (char *) tmp->data,
556 g_string_free (result, FALSE);
561 return g_strdup (".");
568 do_mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
570 MonoImage *image = NULL;
573 char *name = g_path_get_basename (filename);
574 char *dot = strrchr (name, '.');
580 /* we do a very simple search for bundled assemblies: it's not a general
581 * purpose assembly loading mechanism.
583 EnterCriticalSection (&assemblies_mutex);
584 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
586 if (!ass->aname.name)
588 if (strcmp (name, ass->aname.name))
594 for (i = 0; !image && bundled_assemblies [i]; ++i) {
595 if (strcmp (bundled_assemblies [i]->name, name) == 0) {
596 image = mono_image_open_from_data ((char*)bundled_assemblies [i]->data, bundled_assemblies [i]->size, FALSE, status);
600 LeaveCriticalSection (&assemblies_mutex);
603 mono_image_addref (image);
607 EnterCriticalSection (&assemblies_mutex);
608 image = mono_image_open (filename, status);
609 LeaveCriticalSection (&assemblies_mutex);
615 * mono_assembly_open:
616 * @filename: Opens the assembly pointed out by this name
617 * @status: where a status code can be returned
619 * mono_assembly_open opens the PE-image pointed by @filename, and
620 * loads any external assemblies referenced by it.
622 * NOTE: we could do lazy loading of the assemblies. Or maybe not worth
626 mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
630 MonoImageOpenStatus def_status;
633 g_return_val_if_fail (filename != NULL, NULL);
636 status = &def_status;
637 *status = MONO_IMAGE_OK;
639 if (strncmp (filename, "file://", 7) == 0) {
640 GError *error = NULL;
641 gchar *uri = (gchar *) filename;
645 * MS allows file://c:/... and fails on file://localhost/c:/...
646 * They also throw an IndexOutOfRangeException if "file://"
649 uri = g_strdup_printf ("file:///%s", uri + 7);
652 uri = mono_escape_uri_string (tmpuri);
653 fname = g_filename_from_uri (uri, NULL, &error);
656 if (tmpuri != filename)
660 g_warning ("%s\n", error->message);
661 g_error_free (error);
662 fname = g_strdup (filename);
665 fname = g_strdup (filename);
668 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
669 "Assembly Loader probing location: '%s'.", filename);
670 image = do_mono_assembly_open (fname, status);
673 *status = MONO_IMAGE_ERROR_ERRNO;
678 ass = mono_assembly_load_from (image, fname, status);
681 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
682 "Assembly Loader loaded assembly from location: '%s'.", filename);
683 mono_config_for_assembly (ass->image);
692 mono_assembly_load_from (MonoImage *image, const char*fname,
693 MonoImageOpenStatus *status)
695 MonoAssembly *ass, *ass2;
699 #if defined (PLATFORM_WIN32)
704 tmp_fn = g_strdup (fname);
705 for (i = strlen (tmp_fn) - 1; i >= 0; i--) {
706 if (tmp_fn [i] == '/')
710 base_dir = absolute_dir (tmp_fn);
714 base_dir = absolute_dir (fname);
718 * To avoid deadlocks and scalability problems, we load assemblies outside
719 * the assembly lock. This means that multiple threads might try to load
720 * the same assembly at the same time. The first one to load it completely
721 * "wins", the other threads free their copy and use the one loaded by
722 * the winning thread.
726 * Create assembly struct, and enter it into the assembly cache
728 ass = g_new0 (MonoAssembly, 1);
729 ass->basedir = base_dir;
732 mono_assembly_fill_assembly_name (image, &ass->aname);
735 * Atomically search the loaded list and add ourselves to it if necessary.
737 EnterCriticalSection (&assemblies_mutex);
739 /* avoid loading the same assembly twice for now... */
740 if ((ass2 = search_loaded (&ass->aname))) {
743 mono_image_close (image);
744 *status = MONO_IMAGE_OK;
745 LeaveCriticalSection (&assemblies_mutex);
748 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
749 loading = g_list_prepend (loading, ass);
750 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
751 LeaveCriticalSection (&assemblies_mutex);
753 image->assembly = ass;
756 * We load referenced assemblies outside the lock to prevent deadlocks
757 * with regards to preload hooks.
759 mono_assembly_load_references (image, status);
761 EnterCriticalSection (&assemblies_mutex);
763 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
764 loading = g_list_remove (loading, ass);
766 /* Prevent memory leaks */
767 g_hash_table_remove (assemblies_loading, GetCurrentThread ());
769 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
770 if (*status != MONO_IMAGE_OK) {
771 LeaveCriticalSection (&assemblies_mutex);
772 mono_assembly_close (ass);
776 if (ass->aname.name) {
777 ass2 = search_loaded (&ass->aname);
779 /* Somebody else has loaded the assembly before us */
780 LeaveCriticalSection (&assemblies_mutex);
781 mono_assembly_close (ass);
786 loaded_assemblies = g_list_prepend (loaded_assemblies, ass);
787 LeaveCriticalSection (&assemblies_mutex);
789 mono_assembly_invoke_load_hook (ass);
795 probe_for_partial_name (const char *basepath, const char *fullname, MonoImageOpenStatus *status)
797 MonoAssembly *res = NULL;
800 const char* direntry;
802 dirhandle = g_dir_open (basepath, 0, NULL);
806 while ((direntry = g_dir_read_name (dirhandle))) {
807 fullpath = g_build_path (G_DIR_SEPARATOR_S, basepath, direntry, fullname, NULL);
808 res = mono_assembly_open (fullpath, status);
813 g_dir_close (dirhandle);
819 mono_assembly_load_with_partial_name (const char *name, MonoImageOpenStatus *status)
822 MonoAssemblyName aname;
823 gchar *fullname, *gacpath;
826 memset (&aname, 0, sizeof (MonoAssemblyName));
829 res = invoke_assembly_preload_hook (&aname, assemblies_path);
835 res = mono_assembly_loaded (&aname);
839 fullname = g_strdup_printf ("%s.dll", name);
841 if (extra_gac_paths) {
842 paths = extra_gac_paths;
843 while (!res && *paths) {
844 gacpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", name, NULL);
845 res = probe_for_partial_name (gacpath, fullname, status);
858 gacpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), "mono", "gac", name, NULL);
859 res = probe_for_partial_name (gacpath, fullname, status);
871 * mono_assembly_load_from_gac
873 * @aname: The assembly name object
876 mono_assembly_load_from_gac (MonoAssemblyName *aname, gchar *filename, MonoImageOpenStatus *status)
878 MonoAssembly *result = NULL;
879 gchar *name, *version, *culture, *fullpath, *subpath;
883 if (aname->public_key_token [0] == NULL) {
887 if (strstr (aname->name, ".dll")) {
888 len = strlen (filename) - 4;
889 name = g_malloc (len);
890 strncpy (name, aname->name, len);
892 name = g_strdup (aname->name);
895 if (aname->culture) {
896 culture = g_strdup (aname->culture);
899 culture = g_strdup ("");
902 version = g_strdup_printf ("%d.%d.%d.%d_%s_%s", aname->major,
903 aname->minor, aname->build, aname->revision,
904 culture, aname->public_key_token);
906 subpath = g_build_path (G_DIR_SEPARATOR_S, name, version, filename, NULL);
911 if (extra_gac_paths) {
912 paths = extra_gac_paths;
913 while (!result && *paths) {
914 fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", subpath, NULL);
915 result = mono_assembly_open (fullpath, status);
922 result->in_gac = TRUE;
927 fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (),
928 "mono", "gac", subpath, NULL);
929 result = mono_assembly_open (fullpath, status);
933 result->in_gac = TRUE;
942 mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status)
944 MonoAssembly *result;
945 char *fullpath, *filename;
947 result = invoke_assembly_preload_hook (aname, assemblies_path);
949 result->in_gac = FALSE;
953 result = mono_assembly_loaded (aname);
957 /* g_print ("loading %s\n", aname->name); */
958 /* special case corlib */
959 if (strcmp (aname->name, "mscorlib") == 0) {
962 /* g_print ("corlib already loaded\n"); */
965 /* g_print ("corlib load\n"); */
966 if (assemblies_path) {
967 corlib = load_in_path ("mscorlib.dll", (const char**)assemblies_path, status);
971 corlib = load_in_path ("mscorlib.dll", default_path, status);
976 /* Load corlib from mono/<version> */
978 corlib_file = g_build_filename ("mono", mono_get_framework_version (), "mscorlib.dll", NULL);
979 if (assemblies_path) {
980 corlib = load_in_path (corlib_file, (const char**)assemblies_path, status);
982 g_free (corlib_file);
986 corlib = load_in_path (corlib_file, default_path, status);
987 g_free (corlib_file);
992 if (strstr (aname->name, ".dll"))
993 filename = g_strdup (aname->name);
995 filename = g_strconcat (aname->name, ".dll", NULL);
997 result = mono_assembly_load_from_gac (aname, filename, status);
1004 fullpath = g_build_filename (basedir, filename, NULL);
1005 result = mono_assembly_open (fullpath, status);
1008 result->in_gac = FALSE;
1014 result = load_in_path (filename, default_path, status);
1016 result->in_gac = FALSE;
1022 mono_assembly_loaded (MonoAssemblyName *aname)
1026 EnterCriticalSection (&assemblies_mutex);
1027 res = search_loaded (aname);
1028 LeaveCriticalSection (&assemblies_mutex);
1034 mono_assembly_close (MonoAssembly *assembly)
1039 g_return_if_fail (assembly != NULL);
1041 EnterCriticalSection (&assemblies_mutex);
1042 if (--assembly->ref_count != 0) {
1043 LeaveCriticalSection (&assemblies_mutex);
1046 loaded_assemblies = g_list_remove (loaded_assemblies, assembly);
1047 LeaveCriticalSection (&assemblies_mutex);
1048 image = assembly->image;
1049 if (image->references) {
1050 for (i = 0; image->references [i] != NULL; i++)
1051 mono_image_close (image->references [i]->image);
1052 g_free (image->references);
1055 mono_image_close (assembly->image);
1057 g_free (assembly->basedir);
1062 mono_assembly_load_module (MonoAssembly *assembly, guint32 idx)
1064 MonoImageOpenStatus status;
1067 module = mono_image_load_file_for_image (assembly->image, idx);
1069 mono_assembly_load_references (module, &status);
1075 mono_assembly_foreach (GFunc func, gpointer user_data)
1080 * We make a copy of the list to avoid calling the callback inside the
1081 * lock, which could lead to deadlocks.
1083 EnterCriticalSection (&assemblies_mutex);
1084 copy = g_list_copy (loaded_assemblies);
1085 LeaveCriticalSection (&assemblies_mutex);
1087 g_list_foreach (loaded_assemblies, func, user_data);
1092 /* Holds the assembly of the application, for
1093 * System.Diagnostics.Process::MainModule
1095 static MonoAssembly *main_assembly=NULL;
1098 mono_assembly_set_main (MonoAssembly *assembly)
1100 main_assembly=assembly;
1104 mono_assembly_get_main (void)
1106 return(main_assembly);
1110 mono_assembly_get_image (MonoAssembly *assembly)
1112 return assembly->image;