#include <mono/os/gc_wrapper.h>
#include <mono/metadata/object.h>
-#include <mono/metadata/appdomain.h>
+#include <mono/metadata/domain-internals.h>
+#include "mono/metadata/metadata-internals.h"
#include <mono/metadata/assembly.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/gc-internal.h>
#include <mono/metadata/marshal.h>
+#include <mono/metadata/threadpool.h>
#include <mono/utils/mono-uri.h>
-#define MONO_CORLIB_VERSION 11
+#define MONO_CORLIB_VERSION 32
CRITICAL_SECTION mono_delegate_section;
gchar **assemblies_path,
gpointer user_data);
+static MonoAssembly *
+mono_domain_assembly_search (MonoAssemblyName *aname,
+ gpointer user_data);
+
static void
mono_domain_fire_assembly_load (MonoAssembly *assembly, gpointer user_data);
-static MonoMethod *
-look_for_method_by_name (MonoClass *klass, const gchar *name);
+static void
+add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass, GHashTable *hash);
static void
mono_domain_unload (MonoDomain *domain);
-/*
+/**
* mono_runtime_init:
* @domain: domain returned by mono_init ()
*
MonoAppDomainSetup *setup;
MonoAppDomain *ad;
MonoClass *class;
-
- mono_marshal_init ();
+ MonoString *arg;
+ MONO_GC_PRE_INIT ();
+ mono_thread_pool_init ();
+ mono_marshal_init ();
+
mono_install_assembly_preload_hook (mono_domain_assembly_preload, NULL);
+ mono_install_assembly_search_hook (mono_domain_assembly_search, NULL);
mono_install_assembly_load_hook (mono_domain_fire_assembly_load, NULL);
mono_install_lookup_dynamic_token (mono_reflection_lookup_dynamic_token);
+ mono_thread_init (start_cb, attach_cb);
+
class = mono_class_from_name (mono_defaults.corlib, "System", "AppDomainSetup");
setup = (MonoAppDomainSetup *) mono_object_new (domain, class);
mono_context_init (domain);
mono_context_set (domain->default_context);
- mono_thread_init (start_cb, attach_cb);
+ mono_type_initialization_init ();
+
/*
* Create an instance early since we can't do it when there is no memory.
*/
- domain->out_of_memory_ex = mono_exception_from_name (mono_defaults.corlib, "System", "OutOfMemoryException");
+ arg = mono_string_new (domain, "Out of memory");
+ domain->out_of_memory_ex = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "OutOfMemoryException", arg, NULL);
+
/*
* These two are needed because the signal handlers might be executing on
* an alternate stack, and Boehm GC can't handle that.
*/
- domain->null_reference_ex = mono_exception_from_name (mono_defaults.corlib, "System", "NullReferenceException");
- domain->stack_overflow_ex = mono_exception_from_name (mono_defaults.corlib, "System", "StackOverflowException");
+ arg = mono_string_new (domain, "A null value was found where an object instance was required");
+ domain->null_reference_ex = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "NullReferenceException", arg, NULL);
+ 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);
/* GC init has to happen after thread init */
mono_gc_init ();
mono_network_init ();
+ /* mscorlib is loaded before we install the load hook */
+ mono_domain_fire_assembly_load (mono_defaults.corlib->assembly, NULL);
+
return;
}
static MonoDomainFunc quit_function = NULL;
void
-mono_runtime_install_cleanup (MonoDomainFunc func)
+mono_install_runtime_cleanup (MonoDomainFunc func)
{
quit_function = func;
}
mono_runtime_quit ()
{
if (quit_function != NULL)
- quit_function (mono_root_domain, NULL);
+ quit_function (mono_get_root_domain (), NULL);
}
gboolean
klass = domain->domain->mbr.obj.vtable->klass;
g_assert (klass);
- method = look_for_method_by_name (klass, "DoTypeResolve");
+ method = mono_class_get_method_from_name (klass, "DoTypeResolve", -1);
if (method == NULL) {
g_warning ("Method AppDomain.DoTypeResolve not found.\n");
return NULL;
return (MonoReflectionAssembly *) mono_runtime_invoke (method, domain->domain, params, NULL);
}
-/*
+/**
+ * mono_domain_owns_vtable_slot:
+ *
+ * Returns whenever VTABLE_SLOT is inside a vtable which belongs to DOMAIN.
+ */
+gboolean
+mono_domain_owns_vtable_slot (MonoDomain *domain, gpointer vtable_slot)
+{
+ gboolean res;
+
+ mono_domain_lock (domain);
+ res = mono_mempool_contains_addr (domain->mp, vtable_slot);
+ mono_domain_unlock (domain);
+ return res;
+}
+
+/**
* mono_domain_set:
+ * @domain: domain
+ * @force: force setting.
*
* Set the current appdomain to @domain. If @force is set, set it even
* if it is being unloaded.
+ *
* Returns:
- * - TRUE on success
- * - FALSE if the domain is being unloaded
+ * TRUE on success;
+ * FALSE if the domain is unloaded
*/
gboolean
mono_domain_set (MonoDomain *domain, gboolean force)
{
- if (!force && (domain->state == MONO_APPDOMAIN_UNLOADING || domain->state == MONO_APPDOMAIN_UNLOADED))
+ if (!force && domain->state == MONO_APPDOMAIN_UNLOADED)
return FALSE;
mono_domain_set_internal (domain);
return TRUE;
}
-void
-ves_icall_System_AppDomainSetup_InitAppDomainSetup (MonoAppDomainSetup *setup)
-{
- MonoDomain* domain = mono_domain_get ();
- MonoAssembly *assembly;
- gchar *str;
- gchar *config_suffix;
-
- MONO_ARCH_SAVE_REGS;
-
- if (!domain->entry_assembly)
- assembly = mono_root_domain->entry_assembly;
- else
- assembly = domain->entry_assembly;
-
- g_assert (assembly);
-
- setup->application_base = mono_string_new (domain, assembly->basedir);
-
- config_suffix = g_strconcat (assembly->aname.name, ".exe.config", NULL);
- str = g_build_filename (assembly->basedir, config_suffix, NULL);
- g_free (config_suffix);
- setup->configuration_file = mono_string_new (domain, str);
- g_free (str);
-}
-
MonoObject *
ves_icall_System_AppDomain_GetData (MonoAppDomain *ad, MonoString *name)
{
MONO_ARCH_SAVE_REGS;
g_assert (ad != NULL);
- g_assert (name != NULL);
+
+ if (name == NULL)
+ mono_raise_exception (mono_get_exception_argument_null ("name"));
str = mono_string_to_utf8 (name);
MONO_ARCH_SAVE_REGS;
g_assert (ad != NULL);
- g_assert (name != NULL);
+
+ if (name == NULL)
+ mono_raise_exception (mono_get_exception_argument_null ("name"));
mono_domain_lock (add);
return add->domain;
}
+MonoAppDomain *
+ves_icall_System_AppDomain_getRootDomain ()
+{
+ MonoDomain *root = mono_get_root_domain ();
+
+ MONO_ARCH_SAVE_REGS;
+
+ return root->domain;
+}
+
MonoAppDomain *
ves_icall_System_AppDomain_createDomain (MonoString *friendly_name, MonoAppDomainSetup *setup)
{
- /*MonoDomain *domain = mono_domain_get (); */
+ MonoDomain *domain = mono_domain_get ();
MonoClass *adclass;
MonoAppDomain *ad;
MonoDomain *data;
+ GSList *tmp;
MONO_ARCH_SAVE_REGS;
data->friendly_name = mono_string_to_utf8 (friendly_name);
data->out_of_memory_ex = mono_exception_from_name_domain (data, mono_defaults.corlib, "System", "OutOfMemoryException");
+ if (!setup->application_base) {
+ /* Inherit from the root domain since MS.NET does this */
+ MonoDomain *root = mono_get_root_domain ();
+ setup->application_base = mono_string_new_utf16 (data, mono_string_chars (root->setup->application_base), mono_string_length (root->setup->application_base));
+ }
+
mono_context_init (data);
- /* FIXME: what to do next ? */
+ /* The new appdomain should have all assemblies loaded */
+ mono_domain_lock (domain);
+ /*g_print ("copy assemblies from domain %p (%s)\n", domain, domain->friendly_name);*/
+ for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next)
+ add_assemblies_to_domain (data, tmp->data, NULL);
+ mono_domain_unlock (domain);
return ad;
}
-typedef struct {
- MonoArray *res;
- MonoDomain *domain;
- int idx;
-} add_assembly_helper_t;
-
-static void
-add_assembly (gpointer key, gpointer value, gpointer user_data)
-{
- add_assembly_helper_t *ah = (add_assembly_helper_t *) user_data;
-
- mono_array_set (ah->res, gpointer, ah->idx++, mono_assembly_get_object (ah->domain, value));
-}
-
MonoArray *
ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad)
{
MonoDomain *domain = ad->data;
+ MonoAssembly* ass;
static MonoClass *System_Reflection_Assembly;
MonoArray *res;
- add_assembly_helper_t ah;
+ GSList *tmp;
+ int i, count;
MONO_ARCH_SAVE_REGS;
System_Reflection_Assembly = mono_class_from_name (
mono_defaults.corlib, "System.Reflection", "Assembly");
- res = mono_array_new (domain, System_Reflection_Assembly, g_hash_table_size (domain->assemblies));
-
- ah.domain = domain;
- ah.res = res;
- ah.idx = 0;
+ count = 0;
+ /* Need to skip internal assembly builders created by remoting */
mono_domain_lock (domain);
- g_hash_table_foreach (domain->assemblies, add_assembly, &ah);
+ for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
+ ass = tmp->data;
+ if (!ass->corlib_internal)
+ count++;
+ }
+ res = mono_array_new (domain, System_Reflection_Assembly, count);
+ i = 0;
+ for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
+ ass = tmp->data;
+ if (ass->corlib_internal)
+ continue;
+ mono_array_set (res, gpointer, i, mono_assembly_get_object (domain, ass));
+ ++i;
+ }
mono_domain_unlock (domain);
return res;
}
-/*
- * Used to find methods in AppDomain class.
- * It only works if there are no multiple signatures for any given method name
- */
-static MonoMethod *
-look_for_method_by_name (MonoClass *klass, const gchar *name)
-{
- gint i;
- MonoMethod *method;
-
- for (i = 0; i < klass->method.count; i++) {
- method = klass->methods [i];
- if (!strcmp (method->name, name))
- return method;
- }
-
- return NULL;
-}
-
static MonoReflectionAssembly *
try_assembly_resolve (MonoDomain *domain, MonoString *fname)
{
klass = domain->domain->mbr.obj.vtable->klass;
g_assert (klass);
- method = look_for_method_by_name (klass, "DoAssemblyResolve");
+ method = mono_class_get_method_from_name (klass, "DoAssemblyResolve", -1);
if (method == NULL) {
g_warning ("Method AppDomain.DoAssemblyResolve not found.\n");
return NULL;
return (MonoReflectionAssembly *) mono_runtime_invoke (method, domain->domain, params, NULL);
}
+/*
+ * LOCKING: assumes domain is already locked.
+ */
static void
-add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass)
+add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass, GHashTable *ht)
{
gint i;
+ GSList *tmp;
+ gboolean destroy_ht = FALSE;
if (!ass->aname.name)
return;
- mono_domain_lock (domain);
-
- if (g_hash_table_lookup (domain->assemblies, ass->aname.name)) {
- mono_domain_unlock (domain);
- return; /* This is ok while no lazy loading of assemblies */
+ if (!ht) {
+ ht = g_hash_table_new (mono_aligned_addr_hash, NULL);
+ destroy_ht = TRUE;
}
- g_hash_table_insert (domain->assemblies, (gpointer) ass->aname.name, ass);
- mono_domain_unlock (domain);
+ /* FIXME: handle lazy loaded assemblies */
+ for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
+ g_hash_table_insert (ht, tmp->data, tmp->data);
+ }
+ if (!g_hash_table_lookup (ht, ass)) {
+ mono_assembly_addref (ass);
+ g_hash_table_insert (ht, ass, ass);
+ domain->domain_assemblies = g_slist_prepend (domain->domain_assemblies, ass);
+ }
- if (ass->image->references)
- for (i = 0; ass->image->references [i] != NULL; i++)
- add_assemblies_to_domain (domain, ass->image->references [i]);
+ if (ass->image->references) {
+ for (i = 0; ass->image->references [i] != NULL; i++) {
+ if (!g_hash_table_lookup (ht, ass->image->references [i])) {
+ add_assemblies_to_domain (domain, ass->image->references [i], ht);
+ }
+ }
+ }
+ if (destroy_ht)
+ g_hash_table_destroy (ht);
}
static void
klass = domain->domain->mbr.obj.vtable->klass;
-
- method = look_for_method_by_name (klass, "DoAssemblyLoad");
+ method = mono_class_get_method_from_name (klass, "DoAssemblyLoad", -1);
if (method == NULL) {
g_warning ("Method AppDomain.DoAssemblyLoad not found.\n");
return;
}
- add_assemblies_to_domain (domain, assembly);
+ mono_domain_lock (domain);
+ add_assemblies_to_domain (domain, assembly, NULL);
+ mono_domain_unlock (domain);
ref_assembly = mono_assembly_get_object (domain, assembly);
g_assert (ref_assembly);
mono_runtime_invoke (method, domain->domain, params, NULL);
}
+static gchar *
+reduce_path (const gchar *dirname)
+{
+ gchar **parts;
+ gchar *part;
+ GList *list, *tmp;
+ GString *result;
+ gchar *res;
+ gint i;
+
+ parts = g_strsplit (dirname, G_DIR_SEPARATOR_S, 0);
+ list = NULL;
+ for (i = 0; (part = parts [i]) != NULL; i++) {
+ if (!strcmp (part, "."))
+ continue;
+
+ if (!strcmp (part, "..")) {
+ if (list && list->next) /* Don't remove root */
+ list = g_list_delete_link (list, list);
+ } else {
+ list = g_list_prepend (list, part);
+ }
+ }
+
+ result = g_string_new ("");
+ list = g_list_reverse (list);
+
+ for (tmp = list; tmp; tmp = tmp->next) {
+ gchar *data = (gchar *) tmp->data;
+
+ if (data && *data) {
+#ifdef PLATFORM_WIN32
+ if (result->len == 0)
+ g_string_append_printf (result, "%s\\", data);
+ else if (result->str [result->len - 1] == '\\')
+ g_string_append_printf (result, "%s", data);
+ else
+#endif
+ g_string_append_printf (result, "%c%s",
+ G_DIR_SEPARATOR, data);
+ }
+ }
+
+ res = result->str;
+ g_string_free (result, FALSE);
+ g_list_free (list);
+ g_strfreev (parts);
+ return res;
+}
+
static void
set_domain_search_path (MonoDomain *domain)
{
gint npaths = 0;
gchar **pvt_split = NULL;
GError *error = NULL;
+ gint appbaselen = -1;
if ((domain->search_path != NULL) && !domain->setup->path_changed)
return;
setup = domain->setup;
- if (setup->application_base)
- npaths++;
+ if (!setup->application_base)
+ return; /* Must set application base to get private path working */
+ npaths++;
if (setup->private_bin_path) {
utf8 = mono_string_to_utf8 (setup->private_bin_path);
pvt_split = g_strsplit (utf8, G_SEARCHPATH_SEPARATOR_S, 1000);
domain->search_path = tmp = g_malloc ((npaths + 1) * sizeof (gchar *));
tmp [npaths] = NULL;
- if (setup->application_base) {
- *tmp = mono_string_to_utf8 (setup->application_base);
-
- /* FIXME: is this needed? */
- if (strncmp (*tmp, "file://", 7) == 0) {
- gchar *file = *tmp;
- gchar *uri = *tmp;
- gchar *tmpuri;
-
- if (uri [7] != '/')
- uri = g_strdup_printf ("file:///%s", uri + 7);
-
- tmpuri = uri;
- uri = mono_escape_uri_string (tmpuri);
- *tmp = g_filename_from_uri (uri, NULL, &error);
- g_free (uri);
-
- if (tmpuri != file)
- g_free (tmpuri);
-
- if (error != NULL) {
- g_warning ("%s\n", error->message);
- g_error_free (error);
- *tmp = file;
- } else {
- g_free (file);
- }
+
+ *tmp = mono_string_to_utf8 (setup->application_base);
+
+ /* FIXME: is this needed? */
+ if (strncmp (*tmp, "file://", 7) == 0) {
+ gchar *file = *tmp;
+ gchar *uri = *tmp;
+ gchar *tmpuri;
+
+ if (uri [7] != '/')
+ uri = g_strdup_printf ("file:///%s", uri + 7);
+
+ tmpuri = uri;
+ uri = mono_escape_uri_string (tmpuri);
+ *tmp = g_filename_from_uri (uri, NULL, &error);
+ g_free (uri);
+
+ if (tmpuri != file)
+ g_free (tmpuri);
+
+ if (error != NULL) {
+ g_warning ("%s\n", error->message);
+ g_error_free (error);
+ *tmp = file;
+ } else {
+ g_free (file);
}
-
- } else {
- *tmp = g_strdup ("");
}
for (i = 1; pvt_split && i < npaths; i++) {
- if (*tmp [0] == '\0' || g_path_is_absolute (pvt_split [i - 1])) {
+ if (g_path_is_absolute (pvt_split [i - 1])) {
tmp [i] = g_strdup (pvt_split [i - 1]);
- continue;
+ } else {
+ tmp [i] = g_build_filename (tmp [0], pvt_split [i - 1], NULL);
}
- tmp [i] = g_build_filename (tmp [0], pvt_split [i - 1], NULL);
+ if (strchr (tmp [i], '.')) {
+ gchar *reduced;
+ gchar *freeme;
+
+ reduced = reduce_path (tmp [i]);
+ if (appbaselen == -1)
+ appbaselen = strlen (tmp [0]);
+
+ if (strncmp (tmp [0], reduced, appbaselen)) {
+ g_free (reduced);
+ g_free (tmp [i]);
+ tmp [i] = g_strdup ("");
+ continue;
+ }
+
+ freeme = tmp [i];
+ tmp [i] = reduced;
+ g_free (freeme);
+ }
}
- if (setup->private_bin_path_probe != NULL && setup->application_base) {
+ if (setup->private_bin_path_probe != NULL) {
g_free (tmp [0]);
tmp [0] = g_strdup ("");
}
g_strfreev (pvt_split);
}
+static gboolean
+try_load_from (MonoAssembly **assembly, const gchar *path1, const gchar *path2,
+ const gchar *path3, const gchar *path4)
+{
+ gchar *fullpath;
+
+ *assembly = NULL;
+ fullpath = g_build_filename (path1, path2, path3, path4, NULL);
+ if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
+ *assembly = mono_assembly_open (fullpath, NULL);
+
+ g_free (fullpath);
+ return (*assembly != NULL);
+}
+
static MonoAssembly *
-real_load (gchar **search_path, const gchar *culture, gchar *filename)
+real_load (gchar **search_path, const gchar *culture, const gchar *name)
{
- MonoAssembly *result;
+ MonoAssembly *result = NULL;
gchar **path;
- gchar *fullpath;
+ gchar *filename;
+ const gchar *local_culture;
+ gint len;
+
+ if (!culture || *culture == '\0') {
+ local_culture = "";
+ } else {
+ local_culture = culture;
+ }
+
+ filename = g_strconcat (name, ".dll", NULL);
+ len = strlen (filename);
for (path = search_path; *path; path++) {
if (**path == '\0')
continue; /* Ignore empty ApplicationBase */
- if (culture && (strlen (culture) > 0))
- fullpath = g_build_filename (*path, culture, filename, NULL);
- else
- fullpath = g_build_filename (*path, filename, NULL);
- result = mono_assembly_open (fullpath, NULL);
- g_free (fullpath);
- if (result)
- return result;
+
+ /* See test cases in bug #58992 and bug #57710 */
+ /* 1st try: [culture]/[name].dll (culture may be empty) */
+ strcpy (filename + len - 4, ".dll");
+ if (try_load_from (&result, *path, local_culture, "", filename))
+ break;
+
+ /* 2nd try: [culture]/[name].exe (culture may be empty) */
+ strcpy (filename + len - 4, ".exe");
+ if (try_load_from (&result, *path, local_culture, "", filename))
+ break;
+
+ /* 3rd try: [culture]/[name]/[name].dll (culture may be empty) */
+ strcpy (filename + len - 4, ".dll");
+ if (try_load_from (&result, *path, local_culture, name, filename))
+ break;
+
+ /* 4th try: [culture]/[name]/[name].exe (culture may be empty) */
+ strcpy (filename + len - 4, ".exe");
+ if (try_load_from (&result, *path, local_culture, name, filename))
+ break;
}
- return NULL;
+ g_free (filename);
+ return result;
}
/*
gpointer user_data)
{
MonoDomain *domain = mono_domain_get ();
- MonoAssembly *result;
- gchar *dll, *exe;
+ MonoAssembly *result = NULL;
set_domain_search_path (domain);
- dll = g_strconcat (aname->name, ".dll", NULL);
- exe = g_strdup (dll);
- strcpy (exe + strlen (exe) - 4, ".exe");
-
if (domain->search_path && domain->search_path [0] != NULL) {
- /* TODO: should also search in name/name.dll and name/name.exe from appbase */
- result = real_load (domain->search_path, aname->culture, dll);
- if (result) {
- g_free (dll);
- g_free (exe);
- return result;
- }
+ result = real_load (domain->search_path, aname->culture, aname->name);
+ }
- result = real_load (domain->search_path, aname->culture, exe);
- if (result) {
- g_free (dll);
- g_free (exe);
- return result;
- }
+ if (result == NULL && assemblies_path && assemblies_path [0] != NULL) {
+ result = real_load (assemblies_path, aname->culture, aname->name);
}
- if (assemblies_path && assemblies_path [0] != NULL) {
- result = real_load (assemblies_path, aname->culture, dll);
- if (result) {
- g_free (dll);
- g_free (exe);
- return result;
- }
+ return result;
+}
- result = real_load (assemblies_path, aname->culture, exe);
- if (result) {
- g_free (dll);
- g_free (exe);
- return result;
- }
+/*
+ * Check whenever a given assembly was already loaded in the current appdomain.
+ */
+static MonoAssembly *
+mono_domain_assembly_search (MonoAssemblyName *aname,
+ gpointer user_data)
+{
+ MonoDomain *domain = mono_domain_get ();
+ GSList *tmp;
+ MonoAssembly *ass;
+
+ mono_domain_lock (domain);
+ for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
+ ass = tmp->data;
+ /* Dynamic assemblies can't match here in MS.NET */
+ if (ass->dynamic || !mono_assembly_names_equal (aname, &ass->aname))
+ continue;
+
+ mono_domain_unlock (domain);
+ return ass;
}
-
- g_free (dll);
- g_free (exe);
+ mono_domain_unlock (domain);
+
return NULL;
}
while (*tmp) {
value = g_strstrip (*tmp);
- if (!strncmp (value, "Version=", 8)) {
+ if (!g_ascii_strncasecmp (value, "Version=", 8)) {
if (sscanf (value + 8, "%u.%u.%u.%u",
&major, &minor, &build, &revision) != 4) {
g_strfreev (parts);
continue;
}
- if (!strncmp (value, "Culture=", 8)) {
- /* g_print ("Culture: %s\n", aname->culture); */
- aname->culture = g_strstrip (g_strdup (value + 8));
+ if (!g_ascii_strncasecmp (value, "Culture=", 8)) {
+ gchar *t = g_strdup (value + 8);
+ g_strchug (t);
+ aname->culture = g_strdup (g_strchomp (t));
tmp++;
+ g_free (t);
+ if (g_strcasecmp (aname->culture, "neutral") == 0) {
+ g_free ((void *) aname->culture);
+ aname->culture = g_strdup ("");
+ }
continue;
}
- if (!strncmp (value, "PublicKeyToken=", 15)) {
+ if (!g_ascii_strncasecmp (value, "PublicKeyToken=", 15)) {
tmp++;
value += 15;
- if (*value && strcmp (value, "null")) {
- gint i, len;
- gchar h, l;
- gchar *result;
-
- value = g_strstrip (g_strdup (value));
- len = strlen (value);
- if (len % 2) {
- g_free (value);
- g_strfreev (parts);
- return FALSE;
- }
-
- aname->hash_len = len / 2;
- aname->hash_value = g_malloc0 (aname->hash_len);
- result = (gchar *) aname->hash_value;
-
- for (i = 0; i < len; i++) {
- if (i % 2) {
- l = g_ascii_xdigit_value (value [i]);
- if (l == -1) {
- g_free (value);
- g_strfreev (parts);
- return FALSE;
- }
- result [i / 2] = (h * 16) + l;
- } else {
- h = g_ascii_xdigit_value (value [i]);
- if (h == -1) {
- g_free (value);
- g_strfreev (parts);
- return FALSE;
- }
- }
- }
- g_free (value);
-
- /*
- g_print ("PublicKeyToken: ");
- for (i = 0; i < aname->hash_len; i++) {
- g_print ("%x", 0x00FF & aname->hash_value [i]);
- }
- g_print ("\n");
- */
+ if (*value && strncmp (value, "null", 4)) {
+ gchar *t = g_strdup (value);
+ g_strchug (t);
+ g_strlcpy (aname->public_key_token, g_strchomp (value), MONO_PUBLIC_KEY_TOKEN_LENGTH);
+ g_free (t);
}
+ continue;
}
+
+ g_strfreev (parts);
+ return FALSE;
}
g_strfreev (parts);
MonoArray *raw_symbol_store, MonoObject *evidence)
{
MonoAssembly *ass;
+ MonoReflectionAssembly *refass = NULL;
MonoDomain *domain = ad->data;
MonoImageOpenStatus status;
guint32 raw_assembly_len = mono_array_length (raw_assembly);
return NULL;
}
- return mono_assembly_get_object (domain, ass);
+ refass = mono_assembly_get_object (domain, ass);
+ refass->evidence = evidence;
+ return refass;
}
MonoReflectionAssembly *
MONO_ARCH_SAVE_REGS;
- memset (&aname, 0, sizeof (aname));
-
- /* FIXME : examine evidence? */
-
g_assert (assRef != NULL);
if (!get_info_from_assembly_name (assRef, &aname)) {
mono_raise_exception (exc);
}
- if (refass != NULL)
- return refass;
+ if (refass == NULL)
+ refass = mono_assembly_get_object (domain, ass);
- return mono_assembly_get_object (domain, ass);
+ refass->evidence = evidence;
+ return refass;
}
void
mono_raise_exception (exc);
}
- if (domain == mono_root_domain) {
+ if (domain == mono_get_root_domain ()) {
mono_raise_exception (mono_get_exception_cannot_unload_appdomain ("The default appdomain can not be unloaded."));
return;
}
+ /*
+ * Unloading seems to cause problems when running NUnit/NAnt, hence
+ * this workaround.
+ */
+ if (g_getenv ("MONO_NO_UNLOAD"))
+ return;
+
mono_domain_unload (domain);
}
MonoMethod *method;
char *filename;
gint32 res;
+ MonoReflectionAssembly *refass;
MONO_ARCH_SAVE_REGS;
assembly = mono_assembly_open (filename, NULL);
g_free (filename);
- if (!assembly) {
- mono_raise_exception ((MonoException *)mono_exception_from_name (
- mono_defaults.corlib, "System.IO", "FileNotFoundException"));
- }
+ if (!assembly)
+ mono_raise_exception (mono_get_exception_file_not_found (file));
image = assembly->image;
if (!args)
args = (MonoArray *) mono_array_new (ad->data, mono_defaults.string_class, 0);
+ refass = mono_assembly_get_object (ad->data, assembly);
+ refass->evidence = evidence;
+
res = mono_runtime_exec_main (method, (MonoArray *)args, NULL);
return res;
MONO_ARCH_SAVE_REGS;
mono_context_set (mc);
-
+
return old_context;
}
MonoString *
ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid)
{
+ MonoDomain* mono_root_domain = mono_get_root_domain ();
mono_domain_lock (mono_root_domain);
if (process_guid_set) {
mono_domain_unlock (mono_root_domain);
/* Clear references to our vtables in class->cached_vtable */
mono_domain_lock (domain);
- mono_g_hash_table_foreach (domain->class_vtable_hash, clear_cached_vtable,
- domain);
- mono_g_hash_table_foreach (domain->proxy_vtable_hash, clear_cached_vtable,
- domain);
+ g_hash_table_foreach (domain->class_vtable_hash, clear_cached_vtable,
+ domain);
mono_domain_unlock (domain);
+ mono_threads_clear_cached_culture (domain);
+
domain->state = MONO_APPDOMAIN_UNLOADED;
- //printf ("UNLOADED %s.\n", domain->friendly_name);
+ /* printf ("UNLOADED %s.\n", domain->friendly_name); */
mono_domain_free (domain, FALSE);
mono_domain_unload (MonoDomain *domain)
{
HANDLE thread_handle;
- guint32 tid;
- gboolean ret;
+ guint32 tid, res;
MonoAppDomainState prev_state;
MonoMethod *method;
MonoObject *exc;
unload_data thread_data;
+ MonoDomain *caller_domain = mono_domain_get ();
- //printf ("UNLOAD STARTING FOR %s.\n", domain->friendly_name);
+ /* printf ("UNLOAD STARTING FOR %s (%p) IN THREAD 0x%x.\n", domain->friendly_name, domain, GetCurrentThreadId ()); */
/* Atomically change our state to UNLOADING */
prev_state = InterlockedCompareExchange (&domain->state,
g_assert_not_reached ();
}
+ mono_domain_set (domain, FALSE);
/* Notify OnDomainUnload listeners */
- method = look_for_method_by_name (domain->domain->mbr.obj.vtable->klass, "DoDomainUnload");
+ method = mono_class_get_method_from_name (domain->domain->mbr.obj.vtable->klass, "DoDomainUnload", -1);
g_assert (method);
exc = NULL;
if (exc) {
/* Roll back the state change */
domain->state = MONO_APPDOMAIN_CREATED;
+ mono_domain_set (caller_domain, FALSE);
mono_raise_exception ((MonoException*)exc);
}
#if 0
thread_handle = CreateThread (NULL, 0, unload_thread_main, &thread_data, 0, &tid);
#else
- thread_handle = CreateThread (NULL, 0, unload_thread_main, &thread_data, CREATE_SUSPENDED, &tid);
+#if defined(PLATFORM_WIN32) && defined (HAVE_BOEHM_GC)
+ thread_handle = GC_CreateThread (NULL, 0, unload_thread_main, &thread_data, CREATE_SUSPENDED, &tid);
+#else
+ thread_handle = CreateThread (NULL, 0, unload_thread_main, &thread_data, CREATE_SUSPENDED, &tid);
+#endif
ResumeThread (thread_handle);
#endif
- ret = WaitForSingleObject (thread_handle, INFINITE);
+
+ /* Wait for the thread */
+ while ((res = WaitForSingleObjectEx (thread_handle, INFINITE, TRUE) == WAIT_IO_COMPLETION)) {
+ if (mono_thread_has_appdomain_ref (mono_thread_current (), domain) && (mono_thread_interruption_requested ()))
+ /* The unload thread tries to abort us */
+ /* The icall wrapper will execute the abort */
+ return;
+ }
+
+ mono_domain_set (caller_domain, FALSE);
if (thread_data.failure_reason) {
MonoException *ex;
- ex = mono_get_exception_cannot_unload_appdomain (thread_data.failure_reason);
/* Roll back the state change */
domain->state = MONO_APPDOMAIN_CREATED;
g_warning (thread_data.failure_reason);
g_free (thread_data.failure_reason);
+ thread_data.failure_reason = NULL;
+
+ ex = mono_get_exception_cannot_unload_appdomain (thread_data.failure_reason);
mono_raise_exception (ex);
}