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/metadata/domain-internals.h>
27 #include <mono/io-layer/io-layer.h>
28 #include <mono/utils/mono-uri.h>
29 #include <mono/metadata/mono-config.h>
30 #include <mono/utils/mono-digest.h>
31 #include <mono/utils/mono-logger.h>
33 #include <mono/os/util.h>
36 /* the default search path is just MONO_ASSEMBLIES */
43 static char **assemblies_path = NULL;
46 * keeps track of loaded assemblies
48 static GList *loaded_assemblies = NULL;
49 static MonoAssembly *corlib;
51 /* This protects loaded_assemblies and image->references */
52 static CRITICAL_SECTION assemblies_mutex;
54 /* A hastable of thread->assembly list mappings */
55 static GHashTable *assemblies_loading;
57 static char **extra_gac_paths = NULL;
60 encode_public_tok (const guchar *token, gint32 len)
62 const static gchar allowed [] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
66 res = g_malloc (len * 2 + 1);
67 for (i = 0; i < len; i++) {
68 res [i * 2] = allowed [token [i] >> 4];
69 res [i * 2 + 1] = allowed [token [i] & 0xF];
76 check_path_env (void) {
80 path = g_getenv ("MONO_PATH");
84 splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000);
86 g_strfreev (assemblies_path);
87 assemblies_path = splitted;
88 if (g_getenv ("MONO_DEBUG") == NULL)
92 if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR))
93 g_warning ("'%s' in MONO_PATH doesn't exist or has wrong permissions.", *splitted);
100 check_extra_gac_path_env (void) {
104 path = g_getenv ("MONO_GAC_PREFIX");
108 splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000);
110 g_strfreev (extra_gac_paths);
111 extra_gac_paths = splitted;
112 if (g_getenv ("MONO_DEBUG") == NULL)
116 if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR))
117 g_warning ("'%s' in MONO_GAC_PATH doesn't exist or has wrong permissions.", *splitted);
124 mono_assembly_names_equal (MonoAssemblyName *l, MonoAssemblyName *r)
126 if (!l->name || !r->name)
129 if (strcmp (l->name, r->name))
133 * simply compare names until some other issues are resolved
134 * (version info not getting set correctly for custom
138 if (l->major != r->major || l->minor != r->minor ||
139 l->build != r->build || l->revision != r->revision)
142 if (!l->public_tok_value && !r->public_tok_value)
145 if ((l->public_tok_value && !r->public_tok_value) || (!l->public_tok_value && r->public_tok_value))
148 if (strcmp (l->public_tok_value, r->public_tok_value))
154 /* assemblies_mutex must be held by the caller */
156 search_loaded (MonoAssemblyName* aname)
162 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
164 /* g_print ("compare %s %s\n", aname->name, ass->aname.name); */
165 if (!mono_assembly_names_equal (aname, &ass->aname))
167 /* g_print ("success\n"); */
173 * The assembly might be under load by this thread. In this case, it is
174 * safe to return an incomplete instance to prevent loops.
176 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
177 for (tmp = loading; tmp; tmp = tmp->next) {
179 if (!mono_assembly_names_equal (aname, &ass->aname))
188 static MonoAssembly *
189 load_in_path (const char *basename, const char** search_path, MonoImageOpenStatus *status)
193 MonoAssembly *result;
195 for (i = 0; search_path [i]; ++i) {
196 fullpath = g_build_filename (search_path [i], basename, NULL);
197 result = mono_assembly_open (fullpath, status);
206 * mono_assembly_setrootdir:
207 * @root_dir: The pathname of the root directory where we will locate assemblies
209 * This routine sets the internal default root directory for looking up
210 * assemblies. This is used by Windows installations to compute dynamically
211 * the place where the Mono assemblies are located.
215 mono_assembly_setrootdir (const char *root_dir)
218 * Override the MONO_ASSEMBLIES directory configured at compile time.
220 /* Leak if called more than once */
221 default_path [0] = g_strdup (root_dir);
224 G_CONST_RETURN gchar *
225 mono_assembly_getrootdir (void)
227 return default_path [0];
231 * mono_assemblies_init:
233 * Initialize global variables used by this module.
236 mono_assemblies_init (void)
238 #ifdef PLATFORM_WIN32
243 check_extra_gac_path_env ();
245 InitializeCriticalSection (&assemblies_mutex);
247 assemblies_loading = g_hash_table_new (NULL, NULL);
251 mono_assembly_fill_assembly_name (MonoImage *image, MonoAssemblyName *aname)
253 MonoTableInfo *t = &image->tables [MONO_TABLE_ASSEMBLY];
254 guint32 cols [MONO_ASSEMBLY_SIZE];
259 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
262 aname->hash_value = NULL;
263 aname->name = mono_metadata_string_heap (image, cols [MONO_ASSEMBLY_NAME]);
264 aname->culture = mono_metadata_string_heap (image, cols [MONO_ASSEMBLY_CULTURE]);
265 aname->flags = cols [MONO_ASSEMBLY_FLAGS];
266 aname->major = cols [MONO_ASSEMBLY_MAJOR_VERSION];
267 aname->minor = cols [MONO_ASSEMBLY_MINOR_VERSION];
268 aname->build = cols [MONO_ASSEMBLY_BUILD_NUMBER];
269 aname->revision = cols [MONO_ASSEMBLY_REV_NUMBER];
270 aname->hash_alg = cols [MONO_ASSEMBLY_HASH_ALG];
271 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
272 gchar* token = g_malloc (8);
276 aname->public_key = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
277 len = mono_metadata_decode_blob_size (aname->public_key, (const char**)&aname->public_key);
279 mono_digest_get_public_token (token, aname->public_key, len);
280 encoded = encode_public_tok (token, 8);
281 g_strlcpy (aname->public_key_token, encoded, MONO_PUBLIC_KEY_TOKEN_LENGTH);
287 aname->public_key = NULL;
288 memset (aname->public_key_token, 0, MONO_PUBLIC_KEY_TOKEN_LENGTH);
291 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
292 aname->public_key = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
295 aname->public_key = 0;
301 assemblyref_public_tok (MonoImage *image, guint32 key_index, guint32 flags)
303 const gchar *public_tok;
306 public_tok = mono_metadata_blob_heap (image, key_index);
307 len = mono_metadata_decode_blob_size (public_tok, &public_tok);
309 if (flags & ASSEMBLYREF_FULL_PUBLIC_KEY_FLAG) {
311 mono_digest_get_public_token (token, public_tok, len);
312 return encode_public_tok (token, 8);
315 return encode_public_tok (public_tok, len);
319 mono_assembly_load_references (MonoImage *image, MonoImageOpenStatus *status)
322 guint32 cols [MONO_ASSEMBLYREF_SIZE];
325 MonoAssembly **references = NULL;
327 *status = MONO_IMAGE_OK;
330 * image->references is shared between threads, so we need to access
331 * it inside a critical section.
333 EnterCriticalSection (&assemblies_mutex);
334 references = image->references;
335 LeaveCriticalSection (&assemblies_mutex);
339 t = &image->tables [MONO_TABLE_ASSEMBLYREF];
341 references = g_new0 (MonoAssembly *, t->rows + 1);
344 * Load any assemblies this image references
346 for (i = 0; i < t->rows; i++) {
347 MonoAssemblyName aname;
349 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
351 hash = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLYREF_HASH_VALUE]);
352 aname.hash_len = mono_metadata_decode_blob_size (hash, &hash);
353 aname.hash_value = hash;
354 aname.name = mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME]);
355 aname.culture = mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_CULTURE]);
356 aname.flags = cols [MONO_ASSEMBLYREF_FLAGS];
357 aname.major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
358 aname.minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
359 aname.build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
360 aname.revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
362 if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]) {
363 gchar *token = assemblyref_public_tok (image, cols [MONO_ASSEMBLYREF_PUBLIC_KEY], aname.flags);
364 g_strlcpy (aname.public_key_token, token, MONO_PUBLIC_KEY_TOKEN_LENGTH);
367 memset (aname.public_key_token, 0, MONO_PUBLIC_KEY_TOKEN_LENGTH);
370 references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
372 if (references [i] == NULL){
376 ** Temporary work around: any System.* which are 3300 build, will get
377 ** remapped, this is to keep old applications running that might have
378 ** been linked against our 5000 API, before we were strongnamed, and
379 ** hence were labeled as 3300 builds by reflection.c
381 if (aname.build == 3300 && strncmp (aname.name, "System", 6) == 0){
384 references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
386 if (references [i] != NULL){
387 if (g_getenv ("MONO_SILENT_WARNING") == NULL)
388 g_printerr ("Compat mode: the request from %s to load %s was remapped (http://www.go-mono.com/remap.html)\n",
389 image->name, aname.name);
392 char *extra_msg = g_strdup ("");
394 if (*status == MONO_IMAGE_ERROR_ERRNO) {
395 extra_msg = g_strdup_printf ("System error: %s\n", strerror (errno));
396 } else if (*status == MONO_IMAGE_MISSING_ASSEMBLYREF) {
397 extra_msg = g_strdup ("Cannot find an assembly referenced from this one.\n");
398 } else if (*status == MONO_IMAGE_IMAGE_INVALID) {
399 extra_msg = g_strdup ("The file exists but is not a valid assembly.\n");
402 for (j = 0; j < i; j++)
403 mono_assembly_close (references [j]);
406 g_warning ("Could not find assembly %s, references from %s (assemblyref_index=%d)\n"
407 " Major/Minor: %d,%d\n"
410 aname.name, image->name, i,
411 aname.major, aname.minor, aname.build, aname.revision,
412 aname.public_key_token, extra_msg);
413 *status = MONO_IMAGE_MISSING_ASSEMBLYREF;
420 * This check is disabled since lots of people seem to have an older
421 * corlib which triggers this.
424 if (image->references [i]->image == image)
425 g_error ("Error: Assembly %s references itself", image->name);
428 references [i] = NULL;
430 /* resolve assembly references for modules */
431 t = &image->tables [MONO_TABLE_MODULEREF];
432 for (i = 0; i < t->rows; i++){
433 if (image->modules [i]) {
434 image->modules [i]->assembly = image->assembly;
435 mono_assembly_load_references (image->modules [i], status);
439 EnterCriticalSection (&assemblies_mutex);
440 if (!image->references)
441 image->references = references;
442 LeaveCriticalSection (&assemblies_mutex);
444 if (image->references != references) {
445 /* Somebody loaded it before us */
446 for (i = 0; i < t->rows; i++)
447 mono_assembly_close (references [i]);
452 typedef struct AssemblyLoadHook AssemblyLoadHook;
453 struct AssemblyLoadHook {
454 AssemblyLoadHook *next;
455 MonoAssemblyLoadFunc func;
459 AssemblyLoadHook *assembly_load_hook = NULL;
462 mono_assembly_invoke_load_hook (MonoAssembly *ass)
464 AssemblyLoadHook *hook;
466 for (hook = assembly_load_hook; hook; hook = hook->next) {
467 hook->func (ass, hook->user_data);
472 mono_install_assembly_load_hook (MonoAssemblyLoadFunc func, gpointer user_data)
474 AssemblyLoadHook *hook;
476 g_return_if_fail (func != NULL);
478 hook = g_new0 (AssemblyLoadHook, 1);
480 hook->user_data = user_data;
481 hook->next = assembly_load_hook;
482 assembly_load_hook = hook;
485 typedef struct AssemblyPreLoadHook AssemblyPreLoadHook;
486 struct AssemblyPreLoadHook {
487 AssemblyPreLoadHook *next;
488 MonoAssemblyPreLoadFunc func;
492 AssemblyPreLoadHook *assembly_preload_hook = NULL;
494 static MonoAssembly *
495 invoke_assembly_preload_hook (MonoAssemblyName *aname, gchar **assemblies_path)
497 AssemblyPreLoadHook *hook;
498 MonoAssembly *assembly;
500 for (hook = assembly_preload_hook; hook; hook = hook->next) {
501 assembly = hook->func (aname, assemblies_path, hook->user_data);
502 if (assembly != NULL)
510 mono_install_assembly_preload_hook (MonoAssemblyPreLoadFunc func, gpointer user_data)
512 AssemblyPreLoadHook *hook;
514 g_return_if_fail (func != NULL);
516 hook = g_new0 (AssemblyPreLoadHook, 1);
518 hook->user_data = user_data;
519 hook->next = assembly_preload_hook;
520 assembly_preload_hook = hook;
524 absolute_dir (const gchar *filename)
535 if (g_path_is_absolute (filename))
536 return g_path_get_dirname (filename);
538 cwd = g_get_current_dir ();
539 mixed = g_build_filename (cwd, filename, NULL);
540 parts = g_strsplit (mixed, G_DIR_SEPARATOR_S, 0);
545 for (i = 0; (part = parts [i]) != NULL; i++) {
546 if (!strcmp (part, "."))
549 if (!strcmp (part, "..")) {
550 if (list && list->next) /* Don't remove root */
551 list = g_list_delete_link (list, list);
553 list = g_list_prepend (list, part);
557 result = g_string_new ("");
558 list = g_list_reverse (list);
560 /* Ignores last data pointer, which should be the filename */
561 for (tmp = list; tmp && tmp->next != NULL; tmp = tmp->next)
563 g_string_append_printf (result, "%s%c", (char *) tmp->data,
567 g_string_free (result, FALSE);
572 return g_strdup (".");
579 do_mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
581 MonoImage *image = NULL;
584 char *name = g_path_get_basename (filename);
585 char *dot = strrchr (name, '.');
591 /* we do a very simple search for bundled assemblies: it's not a general
592 * purpose assembly loading mechanism.
594 EnterCriticalSection (&assemblies_mutex);
595 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
597 if (!ass->aname.name)
599 if (strcmp (name, ass->aname.name))
605 for (i = 0; !image && bundled_assemblies [i]; ++i) {
606 if (strcmp (bundled_assemblies [i]->name, name) == 0) {
607 image = mono_image_open_from_data ((char*)bundled_assemblies [i]->data, bundled_assemblies [i]->size, FALSE, status);
611 LeaveCriticalSection (&assemblies_mutex);
614 mono_image_addref (image);
618 EnterCriticalSection (&assemblies_mutex);
619 image = mono_image_open (filename, status);
620 LeaveCriticalSection (&assemblies_mutex);
626 * mono_assembly_open:
627 * @filename: Opens the assembly pointed out by this name
628 * @status: where a status code can be returned
630 * mono_assembly_open opens the PE-image pointed by @filename, and
631 * loads any external assemblies referenced by it.
633 * NOTE: we could do lazy loading of the assemblies. Or maybe not worth
637 mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
641 MonoImageOpenStatus def_status;
644 g_return_val_if_fail (filename != NULL, NULL);
647 status = &def_status;
648 *status = MONO_IMAGE_OK;
650 if (strncmp (filename, "file://", 7) == 0) {
651 GError *error = NULL;
652 gchar *uri = (gchar *) filename;
656 * MS allows file://c:/... and fails on file://localhost/c:/...
657 * They also throw an IndexOutOfRangeException if "file://"
660 uri = g_strdup_printf ("file:///%s", uri + 7);
663 uri = mono_escape_uri_string (tmpuri);
664 fname = g_filename_from_uri (uri, NULL, &error);
667 if (tmpuri != filename)
671 g_warning ("%s\n", error->message);
672 g_error_free (error);
673 fname = g_strdup (filename);
676 fname = g_strdup (filename);
679 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
680 "Assembly Loader probing location: '%s'.", filename);
681 image = do_mono_assembly_open (fname, status);
684 *status = MONO_IMAGE_ERROR_ERRNO;
689 ass = mono_assembly_load_from (image, fname, status);
692 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
693 "Assembly Loader loaded assembly from location: '%s'.", filename);
694 mono_config_for_assembly (ass->image);
703 mono_assembly_load_from (MonoImage *image, const char*fname,
704 MonoImageOpenStatus *status)
706 MonoAssembly *ass, *ass2;
710 #if defined (PLATFORM_WIN32)
715 tmp_fn = g_strdup (fname);
716 for (i = strlen (tmp_fn) - 1; i >= 0; i--) {
717 if (tmp_fn [i] == '/')
721 base_dir = absolute_dir (tmp_fn);
725 base_dir = absolute_dir (fname);
729 * To avoid deadlocks and scalability problems, we load assemblies outside
730 * the assembly lock. This means that multiple threads might try to load
731 * the same assembly at the same time. The first one to load it completely
732 * "wins", the other threads free their copy and use the one loaded by
733 * the winning thread.
737 * Create assembly struct, and enter it into the assembly cache
739 ass = g_new0 (MonoAssembly, 1);
740 ass->basedir = base_dir;
743 mono_assembly_fill_assembly_name (image, &ass->aname);
746 * Atomically search the loaded list and add ourselves to it if necessary.
748 EnterCriticalSection (&assemblies_mutex);
750 /* avoid loading the same assembly twice for now... */
751 if ((ass2 = search_loaded (&ass->aname))) {
754 mono_image_close (image);
755 *status = MONO_IMAGE_OK;
756 LeaveCriticalSection (&assemblies_mutex);
759 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
760 loading = g_list_prepend (loading, ass);
761 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
762 LeaveCriticalSection (&assemblies_mutex);
764 image->assembly = ass;
767 * We load referenced assemblies outside the lock to prevent deadlocks
768 * with regards to preload hooks.
770 mono_assembly_load_references (image, status);
772 EnterCriticalSection (&assemblies_mutex);
774 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
775 loading = g_list_remove (loading, ass);
777 /* Prevent memory leaks */
778 g_hash_table_remove (assemblies_loading, GetCurrentThread ());
780 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
781 if (*status != MONO_IMAGE_OK) {
782 LeaveCriticalSection (&assemblies_mutex);
783 mono_assembly_close (ass);
787 if (ass->aname.name) {
788 ass2 = search_loaded (&ass->aname);
790 /* Somebody else has loaded the assembly before us */
791 LeaveCriticalSection (&assemblies_mutex);
792 mono_assembly_close (ass);
797 loaded_assemblies = g_list_prepend (loaded_assemblies, ass);
798 LeaveCriticalSection (&assemblies_mutex);
800 mono_assembly_invoke_load_hook (ass);
806 probe_for_partial_name (const char *basepath, const char *fullname, MonoImageOpenStatus *status)
808 MonoAssembly *res = NULL;
811 const char* direntry;
813 dirhandle = g_dir_open (basepath, 0, NULL);
817 while ((direntry = g_dir_read_name (dirhandle))) {
818 fullpath = g_build_path (G_DIR_SEPARATOR_S, basepath, direntry, fullname, NULL);
819 res = mono_assembly_open (fullpath, status);
824 g_dir_close (dirhandle);
830 mono_assembly_load_with_partial_name (const char *name, MonoImageOpenStatus *status)
833 MonoAssemblyName aname;
834 gchar *fullname, *gacpath;
837 memset (&aname, 0, sizeof (MonoAssemblyName));
840 res = invoke_assembly_preload_hook (&aname, assemblies_path);
846 res = mono_assembly_loaded (&aname);
850 fullname = g_strdup_printf ("%s.dll", name);
852 if (extra_gac_paths) {
853 paths = extra_gac_paths;
854 while (!res && *paths) {
855 gacpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", name, NULL);
856 res = probe_for_partial_name (gacpath, fullname, status);
869 gacpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), "mono", "gac", name, NULL);
870 res = probe_for_partial_name (gacpath, fullname, status);
882 * mono_assembly_load_from_gac
884 * @aname: The assembly name object
887 mono_assembly_load_from_gac (MonoAssemblyName *aname, gchar *filename, MonoImageOpenStatus *status)
889 MonoAssembly *result = NULL;
890 gchar *name, *version, *culture, *fullpath, *subpath;
894 if (aname->public_key_token [0] == 0) {
898 if (strstr (aname->name, ".dll")) {
899 len = strlen (filename) - 4;
900 name = g_malloc (len);
901 strncpy (name, aname->name, len);
903 name = g_strdup (aname->name);
906 if (aname->culture) {
907 culture = g_strdup (aname->culture);
910 culture = g_strdup ("");
913 version = g_strdup_printf ("%d.%d.%d.%d_%s_%s", aname->major,
914 aname->minor, aname->build, aname->revision,
915 culture, aname->public_key_token);
917 subpath = g_build_path (G_DIR_SEPARATOR_S, name, version, filename, NULL);
922 if (extra_gac_paths) {
923 paths = extra_gac_paths;
924 while (!result && *paths) {
925 fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", subpath, NULL);
926 result = mono_assembly_open (fullpath, status);
933 result->in_gac = TRUE;
938 fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (),
939 "mono", "gac", subpath, NULL);
940 result = mono_assembly_open (fullpath, status);
944 result->in_gac = TRUE;
953 mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status)
955 MonoAssembly *result;
956 char *fullpath, *filename;
958 result = invoke_assembly_preload_hook (aname, assemblies_path);
960 result->in_gac = FALSE;
964 result = mono_assembly_loaded (aname);
968 /* g_print ("loading %s\n", aname->name); */
969 /* special case corlib */
970 if (strcmp (aname->name, "mscorlib") == 0) {
973 /* g_print ("corlib already loaded\n"); */
976 /* g_print ("corlib load\n"); */
977 if (assemblies_path) {
978 corlib = load_in_path ("mscorlib.dll", (const char**)assemblies_path, status);
982 corlib = load_in_path ("mscorlib.dll", default_path, status);
987 /* Load corlib from mono/<version> */
989 corlib_file = g_build_filename ("mono", mono_get_framework_version (), "mscorlib.dll", NULL);
990 if (assemblies_path) {
991 corlib = load_in_path (corlib_file, (const char**)assemblies_path, status);
993 g_free (corlib_file);
997 corlib = load_in_path (corlib_file, default_path, status);
998 g_free (corlib_file);
1003 if (strstr (aname->name, ".dll"))
1004 filename = g_strdup (aname->name);
1006 filename = g_strconcat (aname->name, ".dll", NULL);
1008 result = mono_assembly_load_from_gac (aname, filename, status);
1015 fullpath = g_build_filename (basedir, filename, NULL);
1016 result = mono_assembly_open (fullpath, status);
1019 result->in_gac = FALSE;
1025 result = load_in_path (filename, default_path, status);
1027 result->in_gac = FALSE;
1033 mono_assembly_loaded (MonoAssemblyName *aname)
1037 EnterCriticalSection (&assemblies_mutex);
1038 res = search_loaded (aname);
1039 LeaveCriticalSection (&assemblies_mutex);
1045 mono_assembly_close (MonoAssembly *assembly)
1050 g_return_if_fail (assembly != NULL);
1052 EnterCriticalSection (&assemblies_mutex);
1053 if (--assembly->ref_count != 0) {
1054 LeaveCriticalSection (&assemblies_mutex);
1057 loaded_assemblies = g_list_remove (loaded_assemblies, assembly);
1058 LeaveCriticalSection (&assemblies_mutex);
1059 image = assembly->image;
1060 if (image->references) {
1061 for (i = 0; image->references [i] != NULL; i++)
1062 mono_image_close (image->references [i]->image);
1063 g_free (image->references);
1066 mono_image_close (assembly->image);
1068 g_free (assembly->basedir);
1073 mono_assembly_load_module (MonoAssembly *assembly, guint32 idx)
1075 MonoImageOpenStatus status;
1078 module = mono_image_load_file_for_image (assembly->image, idx);
1080 mono_assembly_load_references (module, &status);
1086 mono_assembly_foreach (GFunc func, gpointer user_data)
1091 * We make a copy of the list to avoid calling the callback inside the
1092 * lock, which could lead to deadlocks.
1094 EnterCriticalSection (&assemblies_mutex);
1095 copy = g_list_copy (loaded_assemblies);
1096 LeaveCriticalSection (&assemblies_mutex);
1098 g_list_foreach (loaded_assemblies, func, user_data);
1103 /* Holds the assembly of the application, for
1104 * System.Diagnostics.Process::MainModule
1106 static MonoAssembly *main_assembly=NULL;
1109 mono_assembly_set_main (MonoAssembly *assembly)
1111 main_assembly=assembly;
1115 mono_assembly_get_main (void)
1117 return(main_assembly);
1121 mono_assembly_get_image (MonoAssembly *assembly)
1123 return assembly->image;