Merge pull request #3800 from madewokherd/mingwbuild
[mono.git] / mono / metadata / domain.c
index bb40725ac1f401e085deccb0dc901a0b083a6ecd..adb8909f460117ceebfa8be3facd485151765bd6 100644 (file)
@@ -66,7 +66,6 @@ MONO_FAST_TLS_DECLARE(tls_appdomain);
        MonoThreadInfo *info; \
        MONO_FAST_TLS_SET (tls_appdomain,x); \
        mono_native_tls_set_value (appdomain_thread_id, x); \
-       mono_gc_set_current_thread_appdomain (x); \
        info = mono_thread_info_current (); \
        if (info) \
                mono_thread_info_tls_set (info, TLS_KEY_DOMAIN, (x));   \
@@ -78,7 +77,6 @@ MONO_FAST_TLS_DECLARE(tls_appdomain);
 #define SET_APPDOMAIN(x) do {                                          \
                MonoThreadInfo *info;                                                           \
                mono_native_tls_set_value (appdomain_thread_id, x);     \
-               mono_gc_set_current_thread_appdomain (x);               \
                info = mono_thread_info_current ();                             \
                if (info)                                                                                                \
                        mono_thread_info_tls_set (info, TLS_KEY_DOMAIN, (x));   \
@@ -522,7 +520,7 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
        if (domain)
                g_assert_not_reached ();
 
-#ifdef HOST_WIN32
+#if defined(HOST_WIN32) && G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
        /* Avoid system error message boxes. */
        SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
 #endif
@@ -816,6 +814,16 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
 
        mono_profiler_appdomain_name (domain, domain->friendly_name);
 
+       /* Have to do this quite late so that we at least have System.Object */
+       MonoError custom_attr_error;
+       if (mono_assembly_has_reference_assembly_attribute (ass, &custom_attr_error)) {
+               char *corlib_file = g_build_filename (mono_assembly_getrootdir (), "mono", current_runtime->framework_version, "mscorlib.dll", NULL);
+               g_print ("Could not load file or assembly %s. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context.", corlib_file);
+               g_free (corlib_file);
+               exit (1);
+       }
+       mono_error_assert_ok (&custom_attr_error);
+
        return domain;
 }
 
@@ -1175,6 +1183,12 @@ mono_domain_free (MonoDomain *domain, gboolean force)
        g_slist_free (domain->domain_assemblies);
        domain->domain_assemblies = NULL;
 
+       /* 
+        * Send this after the assemblies have been unloaded and the domain is still in a 
+        * usable state.
+        */
+       mono_profiler_appdomain_event (domain, MONO_PROFILE_END_UNLOAD);
+
        if (free_domain_hook)
                free_domain_hook (domain);