2009-03-27 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mono / metadata / appdomain.c
index 5f419e93f0995acf6fb803663a6f20898dbd3713..6310e03e5b2385a457c372d5b2ba411ff263f557 100644 (file)
@@ -47,6 +47,9 @@
 #include <mono/metadata/mono-debug.h>
 #include <mono/metadata/attach.h>
 #include <mono/metadata/file-io.h>
+#include <mono/metadata/lock-tracer.h>
+#include <mono/metadata/console-io.h>
+#include <mono/metadata/threads-types.h>
 #include <mono/utils/mono-uri.h>
 #include <mono/utils/mono-logger.h>
 #include <mono/utils/mono-path.h>
@@ -67,7 +70,7 @@
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  */
-#define MONO_CORLIB_VERSION 69
+#define MONO_CORLIB_VERSION 74
 
 typedef struct
 {
@@ -234,8 +237,11 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
        mono_network_init ();
 #endif
        
+       mono_console_init ();
        mono_attach_init ();
 
+       mono_locks_tracer_init ();
+
        /* mscorlib is loaded before we install the load hook */
        mono_domain_fire_assembly_load (mono_defaults.corlib->assembly, NULL);
        
@@ -711,7 +717,6 @@ mono_set_private_bin_path_from_config (MonoDomain *domain)
 {
        gchar *config_file, *text;
        gsize len;
-       struct stat sbuf;
        GMarkupParseContext *context;
        RuntimeConfig runtime_config;
        
@@ -719,10 +724,6 @@ mono_set_private_bin_path_from_config (MonoDomain *domain)
                return;
 
        config_file = mono_string_to_utf8 (domain->setup->configuration_file);
-       if (stat (config_file, &sbuf) != 0) {
-               g_free (config_file);
-               return;
-       }
 
        if (!g_file_get_contents (config_file, &text, &len, NULL)) {
                g_free (config_file);
@@ -1201,6 +1202,8 @@ get_shadow_assembly_location (const char *filename)
        tmploc = get_shadow_assembly_location_base (domain);
        location = g_build_filename (tmploc, name_hash, path_hash, bname, NULL);
        g_free (tmploc);
+       g_free (bname);
+       g_free (dirname);
        return location;
 }
 
@@ -1382,7 +1385,7 @@ mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name)
 
        /* Is dir_name a shadow_copy destination already? */
        base_dir = get_shadow_assembly_location_base (domain);
-       if (strstr (dir_name, base_dir) == dir_name) {
+       if (strstr (dir_name, base_dir)) {
                g_free (base_dir);
                return TRUE;
        }
@@ -1416,14 +1419,24 @@ mono_make_shadow_copy (const char *filename)
        struct utimbuf utbuf;
        char *dir_name = g_path_get_dirname (filename);
        MonoDomain *domain = mono_domain_get ();
+       char *shadow_dir;
+
        set_domain_search_path (domain);
 
        if (!mono_is_shadow_copy_enabled (domain, dir_name)) {
                g_free (dir_name);
                return (char *) filename;
        }
+       /* Is dir_name a shadow_copy destination already? */
+       shadow_dir = get_shadow_assembly_location_base (domain);
+       if (strstr (dir_name, shadow_dir)) {
+               g_free (shadow_dir);
+               g_free (dir_name);
+               return (char *) filename;
+       }
+       g_free (shadow_dir);
        g_free (dir_name);
-       
+
        shadow = get_shadow_assembly_location (filename);
        if (ensure_directory_exists (shadow) == FALSE) {
                g_free (shadow);
@@ -1972,11 +1985,12 @@ unload_thread_main (void *arg)
         * We also hold the loader lock because we're going to change
         * class->runtime_info.
         */
-       mono_domain_lock (domain);
+
        mono_loader_lock ();
+       mono_domain_lock (domain);
        g_hash_table_foreach (domain->class_vtable_hash, clear_cached_vtable, domain);
-       mono_loader_unlock ();
        mono_domain_unlock (domain);
+       mono_loader_unlock ();
 
        mono_threads_clear_cached_culture (domain);
 
@@ -2067,9 +2081,9 @@ mono_domain_unload (MonoDomain *domain)
         * http://bugzilla.ximian.com/show_bug.cgi?id=27663
         */ 
 #if 0
-       thread_handle = CreateThread (NULL, 0, unload_thread_main, &thread_data, 0, &tid);
+       thread_handle = mono_create_thread (NULL, 0, unload_thread_main, &thread_data, 0, &tid);
 #else
-       thread_handle = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)unload_thread_main, &thread_data, CREATE_SUSPENDED, &tid);
+       thread_handle = mono_create_thread (NULL, 0, (LPTHREAD_START_ROUTINE)unload_thread_main, &thread_data, CREATE_SUSPENDED, &tid);
        if (thread_handle == NULL) {
                return;
        }
@@ -2094,7 +2108,7 @@ mono_domain_unload (MonoDomain *domain)
                /* Roll back the state change */
                domain->state = MONO_APPDOMAIN_CREATED;
 
-               g_warning (thread_data.failure_reason);
+               g_warning ("%s", thread_data.failure_reason);
 
                ex = mono_get_exception_cannot_unload_appdomain (thread_data.failure_reason);