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))
131 if (l->culture && r->culture && strcmp (l->culture, r->culture))
135 * simply compare names until some other issues are resolved
136 * (version info not getting set correctly for custom
140 if (l->major != r->major || l->minor != r->minor ||
141 l->build != r->build || l->revision != r->revision)
144 if (!l->public_tok_value && !r->public_tok_value)
147 if ((l->public_tok_value && !r->public_tok_value) || (!l->public_tok_value && r->public_tok_value))
150 if (strcmp (l->public_tok_value, r->public_tok_value))
156 /* assemblies_mutex must be held by the caller */
158 search_loaded (MonoAssemblyName* aname)
164 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
166 /* g_print ("compare %s %s\n", aname->name, ass->aname.name); */
167 if (!mono_assembly_names_equal (aname, &ass->aname))
169 /* g_print ("success\n"); */
175 * The assembly might be under load by this thread. In this case, it is
176 * safe to return an incomplete instance to prevent loops.
178 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
179 for (tmp = loading; tmp; tmp = tmp->next) {
181 if (!mono_assembly_names_equal (aname, &ass->aname))
190 static MonoAssembly *
191 load_in_path (const char *basename, const char** search_path, MonoImageOpenStatus *status)
195 MonoAssembly *result;
197 for (i = 0; search_path [i]; ++i) {
198 fullpath = g_build_filename (search_path [i], basename, NULL);
199 result = mono_assembly_open (fullpath, status);
208 * mono_assembly_setrootdir:
209 * @root_dir: The pathname of the root directory where we will locate assemblies
211 * This routine sets the internal default root directory for looking up
212 * assemblies. This is used by Windows installations to compute dynamically
213 * the place where the Mono assemblies are located.
217 mono_assembly_setrootdir (const char *root_dir)
220 * Override the MONO_ASSEMBLIES directory configured at compile time.
222 /* Leak if called more than once */
223 default_path [0] = g_strdup (root_dir);
226 G_CONST_RETURN gchar *
227 mono_assembly_getrootdir (void)
229 return default_path [0];
233 * mono_assemblies_init:
235 * Initialize global variables used by this module.
238 mono_assemblies_init (void)
240 #ifdef PLATFORM_WIN32
245 check_extra_gac_path_env ();
247 InitializeCriticalSection (&assemblies_mutex);
249 assemblies_loading = g_hash_table_new (NULL, NULL);
253 mono_assembly_fill_assembly_name (MonoImage *image, MonoAssemblyName *aname)
255 MonoTableInfo *t = &image->tables [MONO_TABLE_ASSEMBLY];
256 guint32 cols [MONO_ASSEMBLY_SIZE];
261 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
264 aname->hash_value = NULL;
265 aname->name = mono_metadata_string_heap (image, cols [MONO_ASSEMBLY_NAME]);
266 aname->culture = mono_metadata_string_heap (image, cols [MONO_ASSEMBLY_CULTURE]);
267 aname->flags = cols [MONO_ASSEMBLY_FLAGS];
268 aname->major = cols [MONO_ASSEMBLY_MAJOR_VERSION];
269 aname->minor = cols [MONO_ASSEMBLY_MINOR_VERSION];
270 aname->build = cols [MONO_ASSEMBLY_BUILD_NUMBER];
271 aname->revision = cols [MONO_ASSEMBLY_REV_NUMBER];
272 aname->hash_alg = cols [MONO_ASSEMBLY_HASH_ALG];
273 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
274 gchar* token = g_malloc (8);
278 aname->public_key = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
279 len = mono_metadata_decode_blob_size (aname->public_key, &aname->public_key);
281 mono_digest_get_public_token (token, aname->public_key, len);
282 encoded = encode_public_tok (token, 8);
283 g_strlcpy (aname->public_key_token, encoded, MONO_PUBLIC_KEY_TOKEN_LENGTH);
289 aname->public_key = NULL;
290 memset (aname->public_key_token, 0, MONO_PUBLIC_KEY_TOKEN_LENGTH);
293 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
294 aname->public_key = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
297 aname->public_key = 0;
303 assemblyref_public_tok (MonoImage *image, guint32 key_index, guint32 flags)
305 const gchar *public_tok;
308 public_tok = mono_metadata_blob_heap (image, key_index);
309 len = mono_metadata_decode_blob_size (public_tok, &public_tok);
311 if (flags & ASSEMBLYREF_FULL_PUBLIC_KEY_FLAG) {
313 mono_digest_get_public_token (token, public_tok, len);
314 return encode_public_tok (token, 8);
317 return encode_public_tok (public_tok, len);
321 mono_assembly_load_references (MonoImage *image, MonoImageOpenStatus *status)
324 guint32 cols [MONO_ASSEMBLYREF_SIZE];
327 MonoAssembly **references = NULL;
329 *status = MONO_IMAGE_OK;
332 * image->references is shared between threads, so we need to access
333 * it inside a critical section.
335 EnterCriticalSection (&assemblies_mutex);
336 references = image->references;
337 LeaveCriticalSection (&assemblies_mutex);
341 t = &image->tables [MONO_TABLE_ASSEMBLYREF];
343 references = g_new0 (MonoAssembly *, t->rows + 1);
346 * Load any assemblies this image references
348 for (i = 0; i < t->rows; i++) {
349 MonoAssemblyName aname;
351 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
353 hash = mono_metadata_blob_heap (image, cols [MONO_ASSEMBLYREF_HASH_VALUE]);
354 aname.hash_len = mono_metadata_decode_blob_size (hash, &hash);
355 aname.hash_value = hash;
356 aname.name = mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_NAME]);
357 aname.culture = mono_metadata_string_heap (image, cols [MONO_ASSEMBLYREF_CULTURE]);
358 aname.flags = cols [MONO_ASSEMBLYREF_FLAGS];
359 aname.major = cols [MONO_ASSEMBLYREF_MAJOR_VERSION];
360 aname.minor = cols [MONO_ASSEMBLYREF_MINOR_VERSION];
361 aname.build = cols [MONO_ASSEMBLYREF_BUILD_NUMBER];
362 aname.revision = cols [MONO_ASSEMBLYREF_REV_NUMBER];
364 if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]) {
365 gchar *token = assemblyref_public_tok (image, cols [MONO_ASSEMBLYREF_PUBLIC_KEY], aname.flags);
366 g_strlcpy (aname.public_key_token, token, MONO_PUBLIC_KEY_TOKEN_LENGTH);
369 memset (aname.public_key_token, 0, MONO_PUBLIC_KEY_TOKEN_LENGTH);
372 references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
374 if (references [i] == NULL){
378 ** Temporary work around: any System.* which are 3300 build, will get
379 ** remapped, this is to keep old applications running that might have
380 ** been linked against our 5000 API, before we were strongnamed, and
381 ** hence were labeled as 3300 builds by reflection.c
383 if (aname.build == 3300 && strncmp (aname.name, "System", 6) == 0){
386 references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
388 if (references [i] != NULL){
389 if (g_getenv ("MONO_SILENT_WARNING") == NULL)
390 g_printerr ("Compat mode: the request from %s to load %s was remapped (http://www.go-mono.com/remap.html)\n",
391 image->name, aname.name);
394 char *extra_msg = g_strdup ("");
396 if (*status == MONO_IMAGE_ERROR_ERRNO) {
397 extra_msg = g_strdup_printf ("System error: %s\n", strerror (errno));
398 } else if (*status == MONO_IMAGE_MISSING_ASSEMBLYREF) {
399 extra_msg = g_strdup ("Cannot find an assembly referenced from this one.\n");
400 } else if (*status == MONO_IMAGE_IMAGE_INVALID) {
401 extra_msg = g_strdup ("The file exists but is not a valid assembly.\n");
404 for (j = 0; j < i; j++)
405 mono_assembly_close (references [j]);
408 g_warning ("Could not find assembly %s, references from %s (assemblyref_index=%d)\n"
409 " Major/Minor: %d,%d\n"
412 aname.name, image->name, i,
413 aname.major, aname.minor, aname.build, aname.revision,
414 aname.public_key_token, extra_msg);
415 *status = MONO_IMAGE_MISSING_ASSEMBLYREF;
422 * This check is disabled since lots of people seem to have an older
423 * corlib which triggers this.
426 if (image->references [i]->image == image)
427 g_error ("Error: Assembly %s references itself", image->name);
430 references [i] = NULL;
432 /* resolve assembly references for modules */
433 t = &image->tables [MONO_TABLE_MODULEREF];
434 for (i = 0; i < t->rows; i++){
435 if (image->modules [i]) {
436 image->modules [i]->assembly = image->assembly;
437 mono_assembly_load_references (image->modules [i], status);
441 EnterCriticalSection (&assemblies_mutex);
442 if (!image->references)
443 image->references = references;
444 LeaveCriticalSection (&assemblies_mutex);
446 if (image->references != references) {
447 /* Somebody loaded it before us */
448 for (i = 0; i < t->rows; i++)
449 mono_assembly_close (references [i]);
454 typedef struct AssemblyLoadHook AssemblyLoadHook;
455 struct AssemblyLoadHook {
456 AssemblyLoadHook *next;
457 MonoAssemblyLoadFunc func;
461 AssemblyLoadHook *assembly_load_hook = NULL;
464 mono_assembly_invoke_load_hook (MonoAssembly *ass)
466 AssemblyLoadHook *hook;
468 for (hook = assembly_load_hook; hook; hook = hook->next) {
469 hook->func (ass, hook->user_data);
474 mono_install_assembly_load_hook (MonoAssemblyLoadFunc func, gpointer user_data)
476 AssemblyLoadHook *hook;
478 g_return_if_fail (func != NULL);
480 hook = g_new0 (AssemblyLoadHook, 1);
482 hook->user_data = user_data;
483 hook->next = assembly_load_hook;
484 assembly_load_hook = hook;
487 typedef struct AssemblyPreLoadHook AssemblyPreLoadHook;
488 struct AssemblyPreLoadHook {
489 AssemblyPreLoadHook *next;
490 MonoAssemblyPreLoadFunc func;
494 AssemblyPreLoadHook *assembly_preload_hook = NULL;
496 static MonoAssembly *
497 invoke_assembly_preload_hook (MonoAssemblyName *aname, gchar **assemblies_path)
499 AssemblyPreLoadHook *hook;
500 MonoAssembly *assembly;
502 for (hook = assembly_preload_hook; hook; hook = hook->next) {
503 assembly = hook->func (aname, assemblies_path, hook->user_data);
504 if (assembly != NULL)
512 mono_install_assembly_preload_hook (MonoAssemblyPreLoadFunc func, gpointer user_data)
514 AssemblyPreLoadHook *hook;
516 g_return_if_fail (func != NULL);
518 hook = g_new0 (AssemblyPreLoadHook, 1);
520 hook->user_data = user_data;
521 hook->next = assembly_preload_hook;
522 assembly_preload_hook = hook;
526 absolute_dir (const gchar *filename)
537 if (g_path_is_absolute (filename))
538 return g_path_get_dirname (filename);
540 cwd = g_get_current_dir ();
541 mixed = g_build_filename (cwd, filename, NULL);
542 parts = g_strsplit (mixed, G_DIR_SEPARATOR_S, 0);
547 for (i = 0; (part = parts [i]) != NULL; i++) {
548 if (!strcmp (part, "."))
551 if (!strcmp (part, "..")) {
552 if (list && list->next) /* Don't remove root */
553 list = g_list_delete_link (list, list);
555 list = g_list_prepend (list, part);
559 result = g_string_new ("");
560 list = g_list_reverse (list);
562 /* Ignores last data pointer, which should be the filename */
563 for (tmp = list; tmp && tmp->next != NULL; tmp = tmp->next)
565 g_string_append_printf (result, "%s%c", (char *) tmp->data,
569 g_string_free (result, FALSE);
574 return g_strdup (".");
581 do_mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
583 MonoImage *image = NULL;
586 char *name = g_path_get_basename (filename);
587 char *dot = strrchr (name, '.');
593 /* we do a very simple search for bundled assemblies: it's not a general
594 * purpose assembly loading mechanism.
596 EnterCriticalSection (&assemblies_mutex);
597 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
599 if (!ass->aname.name)
601 if (strcmp (name, ass->aname.name))
607 for (i = 0; !image && bundled_assemblies [i]; ++i) {
608 if (strcmp (bundled_assemblies [i]->name, name) == 0) {
609 image = mono_image_open_from_data ((char*)bundled_assemblies [i]->data, bundled_assemblies [i]->size, FALSE, status);
613 LeaveCriticalSection (&assemblies_mutex);
616 mono_image_addref (image);
620 EnterCriticalSection (&assemblies_mutex);
621 image = mono_image_open (filename, status);
622 LeaveCriticalSection (&assemblies_mutex);
628 * mono_assembly_open:
629 * @filename: Opens the assembly pointed out by this name
630 * @status: where a status code can be returned
632 * mono_assembly_open opens the PE-image pointed by @filename, and
633 * loads any external assemblies referenced by it.
635 * NOTE: we could do lazy loading of the assemblies. Or maybe not worth
639 mono_assembly_open (const char *filename, MonoImageOpenStatus *status)
643 MonoImageOpenStatus def_status;
646 g_return_val_if_fail (filename != NULL, NULL);
649 status = &def_status;
650 *status = MONO_IMAGE_OK;
652 if (strncmp (filename, "file://", 7) == 0) {
653 GError *error = NULL;
654 gchar *uri = (gchar *) filename;
658 * MS allows file://c:/... and fails on file://localhost/c:/...
659 * They also throw an IndexOutOfRangeException if "file://"
662 uri = g_strdup_printf ("file:///%s", uri + 7);
665 uri = mono_escape_uri_string (tmpuri);
666 fname = g_filename_from_uri (uri, NULL, &error);
669 if (tmpuri != filename)
673 g_warning ("%s\n", error->message);
674 g_error_free (error);
675 fname = g_strdup (filename);
678 fname = g_strdup (filename);
681 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
682 "Assembly Loader probing location: '%s'.", filename);
683 image = do_mono_assembly_open (fname, status);
686 *status = MONO_IMAGE_ERROR_ERRNO;
691 ass = mono_assembly_load_from (image, fname, status);
694 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY,
695 "Assembly Loader loaded assembly from location: '%s'.", filename);
696 mono_config_for_assembly (ass->image);
705 mono_assembly_load_from (MonoImage *image, const char*fname,
706 MonoImageOpenStatus *status)
708 MonoAssembly *ass, *ass2;
712 #if defined (PLATFORM_WIN32)
717 tmp_fn = g_strdup (fname);
718 for (i = strlen (tmp_fn) - 1; i >= 0; i--) {
719 if (tmp_fn [i] == '/')
723 base_dir = absolute_dir (tmp_fn);
727 base_dir = absolute_dir (fname);
731 * To avoid deadlocks and scalability problems, we load assemblies outside
732 * the assembly lock. This means that multiple threads might try to load
733 * the same assembly at the same time. The first one to load it completely
734 * "wins", the other threads free their copy and use the one loaded by
735 * the winning thread.
739 * Create assembly struct, and enter it into the assembly cache
741 ass = g_new0 (MonoAssembly, 1);
742 ass->basedir = base_dir;
745 mono_assembly_fill_assembly_name (image, &ass->aname);
748 * Atomically search the loaded list and add ourselves to it if necessary.
750 EnterCriticalSection (&assemblies_mutex);
752 /* avoid loading the same assembly twice for now... */
753 if ((ass2 = search_loaded (&ass->aname))) {
756 mono_image_close (image);
757 *status = MONO_IMAGE_OK;
758 LeaveCriticalSection (&assemblies_mutex);
761 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
762 loading = g_list_prepend (loading, ass);
763 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
764 LeaveCriticalSection (&assemblies_mutex);
766 image->assembly = ass;
769 * We load referenced assemblies outside the lock to prevent deadlocks
770 * with regards to preload hooks.
772 mono_assembly_load_references (image, status);
774 EnterCriticalSection (&assemblies_mutex);
776 loading = g_hash_table_lookup (assemblies_loading, GetCurrentThread ());
777 loading = g_list_remove (loading, ass);
779 /* Prevent memory leaks */
780 g_hash_table_remove (assemblies_loading, GetCurrentThread ());
782 g_hash_table_insert (assemblies_loading, GetCurrentThread (), loading);
783 if (*status != MONO_IMAGE_OK) {
784 LeaveCriticalSection (&assemblies_mutex);
785 mono_assembly_close (ass);
789 if (ass->aname.name) {
790 ass2 = search_loaded (&ass->aname);
792 /* Somebody else has loaded the assembly before us */
793 LeaveCriticalSection (&assemblies_mutex);
794 mono_assembly_close (ass);
799 loaded_assemblies = g_list_prepend (loaded_assemblies, ass);
800 LeaveCriticalSection (&assemblies_mutex);
802 mono_assembly_invoke_load_hook (ass);
808 probe_for_partial_name (const char *basepath, const char *fullname, MonoImageOpenStatus *status)
810 MonoAssembly *res = NULL;
813 const char* direntry;
815 dirhandle = g_dir_open (basepath, 0, NULL);
819 while ((direntry = g_dir_read_name (dirhandle))) {
820 fullpath = g_build_path (G_DIR_SEPARATOR_S, basepath, direntry, fullname, NULL);
821 res = mono_assembly_open (fullpath, status);
826 g_dir_close (dirhandle);
832 mono_assembly_load_with_partial_name (const char *name, MonoImageOpenStatus *status)
835 MonoAssemblyName aname;
836 gchar *fullname, *gacpath;
839 memset (&aname, 0, sizeof (MonoAssemblyName));
842 res = invoke_assembly_preload_hook (&aname, assemblies_path);
848 res = mono_assembly_loaded (&aname);
852 fullname = g_strdup_printf ("%s.dll", name);
854 if (extra_gac_paths) {
855 paths = extra_gac_paths;
856 while (!res && *paths) {
857 gacpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", name, NULL);
858 res = probe_for_partial_name (gacpath, fullname, status);
871 gacpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), "mono", "gac", name, NULL);
872 res = probe_for_partial_name (gacpath, fullname, status);
884 * mono_assembly_load_from_gac
886 * @aname: The assembly name object
889 mono_assembly_load_from_gac (MonoAssemblyName *aname, gchar *filename, MonoImageOpenStatus *status)
891 MonoAssembly *result = NULL;
892 gchar *name, *version, *culture, *fullpath, *subpath;
896 if (aname->public_key_token [0] == NULL) {
900 if (strstr (aname->name, ".dll")) {
901 len = strlen (filename) - 4;
902 name = g_malloc (len);
903 strncpy (name, aname->name, len);
905 name = g_strdup (aname->name);
908 if (aname->culture) {
909 culture = g_strdup (aname->culture);
912 culture = g_strdup ("");
915 version = g_strdup_printf ("%d.%d.%d.%d_%s_%s", aname->major,
916 aname->minor, aname->build, aname->revision,
917 culture, aname->public_key_token);
919 subpath = g_build_path (G_DIR_SEPARATOR_S, name, version, filename, NULL);
924 if (extra_gac_paths) {
925 paths = extra_gac_paths;
926 while (!result && *paths) {
927 fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "lib", "mono", "gac", subpath, NULL);
928 result = mono_assembly_open (fullpath, status);
935 result->in_gac = TRUE;
940 fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (),
941 "mono", "gac", subpath, NULL);
942 result = mono_assembly_open (fullpath, status);
946 result->in_gac = TRUE;
955 mono_assembly_load (MonoAssemblyName *aname, const char *basedir, MonoImageOpenStatus *status)
957 MonoAssembly *result;
958 char *fullpath, *filename;
960 result = invoke_assembly_preload_hook (aname, assemblies_path);
962 result->in_gac = FALSE;
966 result = mono_assembly_loaded (aname);
970 /* g_print ("loading %s\n", aname->name); */
971 /* special case corlib */
972 if (strcmp (aname->name, "mscorlib") == 0) {
974 /* g_print ("corlib already loaded\n"); */
977 /* g_print ("corlib load\n"); */
978 if (assemblies_path) {
979 corlib = load_in_path ("mscorlib.dll", (const char**)assemblies_path, status);
983 corlib = load_in_path ("mscorlib.dll", default_path, status);
987 if (strstr (aname->name, ".dll"))
988 filename = g_strdup (aname->name);
990 filename = g_strconcat (aname->name, ".dll", NULL);
992 result = mono_assembly_load_from_gac (aname, filename, status);
999 fullpath = g_build_filename (basedir, filename, NULL);
1000 result = mono_assembly_open (fullpath, status);
1003 result->in_gac = FALSE;
1009 result = load_in_path (filename, default_path, status);
1011 result->in_gac = FALSE;
1017 mono_assembly_loaded (MonoAssemblyName *aname)
1021 EnterCriticalSection (&assemblies_mutex);
1022 res = search_loaded (aname);
1023 LeaveCriticalSection (&assemblies_mutex);
1029 mono_assembly_close (MonoAssembly *assembly)
1034 g_return_if_fail (assembly != NULL);
1036 EnterCriticalSection (&assemblies_mutex);
1037 if (--assembly->ref_count != 0) {
1038 LeaveCriticalSection (&assemblies_mutex);
1041 loaded_assemblies = g_list_remove (loaded_assemblies, assembly);
1042 LeaveCriticalSection (&assemblies_mutex);
1043 image = assembly->image;
1044 if (image->references) {
1045 for (i = 0; image->references [i] != NULL; i++)
1046 mono_image_close (image->references [i]->image);
1047 g_free (image->references);
1050 mono_image_close (assembly->image);
1052 g_free (assembly->basedir);
1057 mono_assembly_load_module (MonoAssembly *assembly, guint32 idx)
1059 MonoImageOpenStatus status;
1062 module = mono_image_load_file_for_image (assembly->image, idx);
1064 mono_assembly_load_references (module, &status);
1070 mono_assembly_foreach (GFunc func, gpointer user_data)
1075 * We make a copy of the list to avoid calling the callback inside the
1076 * lock, which could lead to deadlocks.
1078 EnterCriticalSection (&assemblies_mutex);
1079 copy = g_list_copy (loaded_assemblies);
1080 LeaveCriticalSection (&assemblies_mutex);
1082 g_list_foreach (loaded_assemblies, func, user_data);
1087 /* Holds the assembly of the application, for
1088 * System.Diagnostics.Process::MainModule
1090 static MonoAssembly *main_assembly=NULL;
1093 mono_assembly_set_main (MonoAssembly *assembly)
1095 main_assembly=assembly;
1099 mono_assembly_get_main (void)
1101 return(main_assembly);
1105 mono_assembly_get_image (MonoAssembly *assembly)
1107 return assembly->image;