Avoid leaking the vmmap allocated by the kernel for the thread_act_array_t
[mono.git] / mono / metadata / appdomain.c
index 13a3d5f54d9560fd569e7ff2ca63b74224d73837..ab1fc103a1a9e67fa4d47ec5fc20c2c001468485 100644 (file)
@@ -73,7 +73,7 @@
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  */
-#define MONO_CORLIB_VERSION 90
+#define MONO_CORLIB_VERSION 94
 
 typedef struct
 {
@@ -85,12 +85,7 @@ typedef struct
 
 CRITICAL_SECTION mono_delegate_section;
 
-#ifdef _EGLIB_MAJOR
-/* Need to lock here because EGLIB has locking defined as no-ops, we can not depend on mono_strtod do the right locking */
-/* Ideally this will be fixed in eglib */
 CRITICAL_SECTION mono_strtod_mutex;
-#endif
-
 
 static gunichar2 process_guid [36];
 static gboolean process_guid_set = FALSE;
@@ -165,7 +160,7 @@ mono_runtime_get_no_exec (void)
 }
 
 static void
-create_exceptions (MonoDomain *domain)
+create_domain_objects (MonoDomain *domain)
 {
        MonoDomain *old_domain = mono_domain_get ();
        MonoString *arg;
@@ -190,6 +185,9 @@ create_exceptions (MonoDomain *domain)
        arg = mono_string_new (domain, "The requested operation caused a stack overflow.");
        domain->stack_overflow_ex = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "StackOverflowException", arg, NULL);
 
+       /*The ephemeron tombstone i*/
+       domain->ephemeron_tombstone = mono_object_new (domain, mono_defaults.object_class);
+
        if (domain != old_domain) {
                mono_thread_pop_appdomain_ref ();
                mono_domain_set_internal_with_options (old_domain, FALSE);
@@ -251,10 +249,7 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
 
        InitializeCriticalSection (&mono_delegate_section);
 
-#ifdef _EGLIB_MAJOR
-       /* Needed until EGLIB is fixed #464316 */
        InitializeCriticalSection (&mono_strtod_mutex);
-#endif
        
        mono_thread_attach (domain);
        mono_context_init (domain);
@@ -263,7 +258,7 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
        mono_type_initialization_init ();
 
        if (!mono_runtime_get_no_exec ())
-               create_exceptions (domain);
+               create_domain_objects (domain);
 
        /* GC init has to happen after thread init */
        mono_gc_init ();
@@ -367,10 +362,6 @@ mono_runtime_cleanup (MonoDomain *domain)
        mono_type_initialization_cleanup ();
 
        mono_monitor_cleanup ();
-
-#ifndef HOST_WIN32
-       _wapi_cleanup ();
-#endif
 }
 
 static MonoDomainFunc quit_function = NULL;
@@ -516,7 +507,7 @@ mono_domain_create_appdomain_internal (char *friendly_name, MonoAppDomainSetup *
        g_free (shadow_location);
 #endif
 
-       create_exceptions (data);
+       create_domain_objects (data);
 
        return ad;
 }
@@ -539,6 +530,10 @@ mono_domain_has_type_resolve (MonoDomain *domain)
                g_assert (field);
        }
 
+       /*pedump doesn't create an appdomin, so the domain object doesn't exist.*/
+       if (!domain->domain)
+               return FALSE;
+
        mono_field_get_value ((MonoObject*)(domain->domain), field, &o);
        return o != NULL;
 }
@@ -995,7 +990,7 @@ add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass, GHashTable *ht)
                mono_assembly_addref (ass);
                g_hash_table_insert (ht, ass, ass);
                domain->domain_assemblies = g_slist_prepend (domain->domain_assemblies, ass);
-               mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Assembly %s %p added to domain %s, ref_count=%d\n", ass->aname.name, ass, domain->friendly_name, ass->ref_count);
+               mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Assembly %s[%p] added to domain %s, ref_count=%d", ass->aname.name, ass, domain->friendly_name, ass->ref_count);
        }
 
        if (ass->image->references) {
@@ -1259,8 +1254,18 @@ shadow_copy_sibling (gchar *src, gint srclen, const char *extension, gchar *targ
        gboolean copy_result;
        
        strcpy (src + srclen - tail_len, extension);
-       if (!g_file_test (src, G_FILE_TEST_IS_REGULAR))
+
+       if (IS_PORTABILITY_CASE) {
+               gchar *file = mono_portability_find_file (src, TRUE);
+
+               if (file == NULL)
+                       return TRUE;
+
+               g_free (file);
+       } else if (!g_file_test (src, G_FILE_TEST_IS_REGULAR)) {
                return TRUE;
+       }
+
        orig = g_utf8_to_utf16 (src, strlen (src), NULL, NULL, NULL);
 
        strcpy (target + targetlen - tail_len, extension);
@@ -2168,7 +2173,6 @@ typedef struct unload_data {
        char *failure_reason;
 } unload_data;
 
-#ifdef HAVE_SGEN_GC
 static void
 deregister_reflection_info_roots_nspace_table (gpointer key, gpointer value, gpointer image)
 {
@@ -2232,7 +2236,6 @@ deregister_reflection_info_roots (MonoDomain *domain)
        mono_domain_assemblies_unlock (domain);
        mono_loader_unlock ();
 }
-#endif
 
 static guint32 WINAPI
 unload_thread_main (void *arg)
@@ -2288,9 +2291,10 @@ unload_thread_main (void *arg)
 #endif
        for (i = 0; i < domain->class_vtable_array->len; ++i)
                clear_cached_vtable (g_ptr_array_index (domain->class_vtable_array, i));
-#ifdef HAVE_SGEN_GC
        deregister_reflection_info_roots (domain);
-#endif
+
+       mono_assembly_cleanup_domain_bindings (domain->domain_id);
+
        mono_domain_unlock (domain);
        mono_loader_unlock ();
 
@@ -2307,7 +2311,7 @@ unload_thread_main (void *arg)
 
        mono_gc_collect (mono_gc_max_generation ());
 
-       mono_thread_detach  (thread);
+       mono_thread_detach (thread);
 
        return 0;
 }