#include <mono/metadata/mono-config.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/runtime.h>
+#include <mono/metadata/w32mutex.h>
+#include <mono/metadata/w32semaphore.h>
+#include <mono/metadata/w32event.h>
+#include <mono/metadata/w32process.h>
+#include <mono/metadata/w32file.h>
#include <metadata/threads.h>
#include <metadata/profiler-private.h>
#include <mono/metadata/coree.h>
+#include <mono/io-layer/io-layer.h>
//#define DEBUG_DOMAIN_UNLOAD 1
-/* we need to use both the Tls* functions and __thread because
- * some archs may generate faster jit code with one meachanism
- * or the other (we used to do it because tls slots were GC-tracked,
- * but we can't depend on this).
- */
-static MonoNativeTlsKey appdomain_thread_id;
-
-#ifdef MONO_HAVE_FAST_TLS
-
-MONO_FAST_TLS_DECLARE(tls_appdomain);
-
-#define GET_APPDOMAIN() ((MonoDomain*)MONO_FAST_TLS_GET(tls_appdomain))
-
+#define GET_APPDOMAIN() ((MonoDomain*)mono_tls_get_domain ())
#define SET_APPDOMAIN(x) do { \
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); \
+ mono_tls_set_domain (x); \
info = mono_thread_info_current (); \
if (info) \
mono_thread_info_tls_set (info, TLS_KEY_DOMAIN, (x)); \
} while (FALSE)
-#else /* !MONO_HAVE_FAST_TLS */
-
-#define GET_APPDOMAIN() ((MonoDomain *)mono_native_tls_get_value (appdomain_thread_id))
-#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)); \
- } while (FALSE)
-
-#endif
-
#define GET_APPCONTEXT() (mono_thread_internal_current ()->current_appcontext)
#define SET_APPCONTEXT(x) MONO_OBJECT_SETREF (mono_thread_internal_current (), current_appcontext, (x))
static const MonoRuntimeInfo*
get_runtime_by_version (const char *version);
-MonoNativeTlsKey
-mono_domain_get_tls_key (void)
-{
- return appdomain_thread_id;
-}
-
-gint32
-mono_domain_get_tls_offset (void)
-{
- int offset = -1;
-
-#ifdef HOST_WIN32
- if (appdomain_thread_id)
- offset = appdomain_thread_id;
-#else
- MONO_THREAD_VAR_OFFSET (tls_appdomain, offset);
-#endif
- return offset;
-}
-
#define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
#define ALIGN_PTR_TO(ptr,align) (gpointer)((((gssize)(ptr)) + (align - 1)) & (~(align - 1)))
static MonoDomain *domain = NULL;
MonoAssembly *ass = NULL;
MonoImageOpenStatus status = MONO_IMAGE_OK;
- const MonoRuntimeInfo* runtimes [G_N_ELEMENTS (supported_runtimes) + 1];
+ const MonoRuntimeInfo* runtimes [G_N_ELEMENTS (supported_runtimes) + 1] = { NULL };
int n, dummy;
#ifdef DEBUG_DOMAIN_UNLOAD
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
#ifndef HOST_WIN32
mono_w32handle_init ();
- wapi_init ();
+ mono_w32handle_namespace_init ();
#endif
+ mono_w32mutex_init ();
+ mono_w32semaphore_init ();
+ mono_w32event_init ();
+ mono_w32process_init ();
+ mono_w32file_init ();
+
#ifndef DISABLE_PERFCOUNTERS
mono_perfcounters_init ();
#endif
mono_gc_base_init ();
mono_thread_info_attach (&dummy);
- MONO_FAST_TLS_INIT (tls_appdomain);
- mono_native_tls_alloc (&appdomain_thread_id, NULL);
-
mono_coop_mutex_init_recursive (&appdomains_mutex);
mono_metadata_init ();
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_get_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;
}
mono_images_cleanup ();
mono_metadata_cleanup ();
- mono_native_tls_free (appdomain_thread_id);
mono_coop_mutex_destroy (&appdomains_mutex);
-#ifndef HOST_WIN32
- wapi_cleanup ();
-#endif
+ mono_w32process_cleanup ();
+ mono_w32file_cleanup ();
}
void
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);
g_hash_table_destroy (domain->generic_virtual_cases);
domain->generic_virtual_cases = NULL;
}
- if (domain->generic_virtual_thunks) {
- g_hash_table_destroy (domain->generic_virtual_thunks);
- domain->generic_virtual_thunks = NULL;
- }
if (domain->ftnptrs_hash) {
g_hash_table_destroy (domain->ftnptrs_hash);
domain->ftnptrs_hash = NULL;
{
mono_locks_coop_release (&domain->lock, DomainLock);
}
+
+GPtrArray*
+mono_domain_get_assemblies (MonoDomain *domain, gboolean refonly)
+{
+ GSList *tmp;
+ GPtrArray *assemblies;
+ MonoAssembly *ass;
+
+ assemblies = g_ptr_array_new ();
+ mono_domain_assemblies_lock (domain);
+ for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
+ ass = (MonoAssembly *)tmp->data;
+ if (refonly != ass->ref_only)
+ continue;
+ if (ass->corlib_internal)
+ continue;
+ g_ptr_array_add (assemblies, ass);
+ }
+ mono_domain_assemblies_unlock (domain);
+ return assemblies;
+}