#include <mono/metadata/tabledefs.h>
#include <mono/metadata/gc-internal.h>
#include <mono/metadata/marshal.h>
+#include <mono/utils/mono-uri.h>
+
+#define MONO_CORLIB_VERSION 9
CRITICAL_SECTION mono_delegate_section;
static gunichar2 process_guid [36];
static gboolean process_guid_set = FALSE;
+static gboolean shutting_down = FALSE;
+
static MonoAssembly *
mono_domain_assembly_preload (MonoAssemblyName *aname,
gchar **assemblies_path,
mono_context_set (domain->default_context);
mono_thread_init (start_cb, attach_cb);
+
+ /*
+ * 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");
/* GC init has to happen after thread init */
mono_gc_init ();
return;
}
+static int
+mono_get_corlib_version (void)
+{
+ MonoClass *klass;
+ MonoClassField *field;
+ MonoObject *value;
+
+ klass = mono_class_from_name (mono_defaults.corlib, "System", "Environment");
+ mono_class_init (klass);
+ field = mono_class_get_field_from_name (klass, "mono_corlib_version");
+ if (!field)
+ return -1;
+ if (! (field->type->attrs & FIELD_ATTRIBUTE_STATIC))
+ return -1;
+ value = mono_field_get_value_object (mono_domain_get (), field, NULL);
+ return *(gint32*)((gchar*)value + sizeof (MonoObject));
+}
+
+const char*
+mono_check_corlib_version (void)
+{
+ int version = mono_get_corlib_version ();
+ if (version != MONO_CORLIB_VERSION)
+ return g_strdup_printf ("expected corlib version %d, found %d.", MONO_CORLIB_VERSION, version);
+ else
+ return NULL;
+}
+
void
mono_context_init (MonoDomain *domain)
{
void
mono_runtime_cleanup (MonoDomain *domain)
{
+ shutting_down = TRUE;
+
/* This ends up calling any pending pending (for at most 2 seconds) */
mono_gc_cleanup ();
quit_function (mono_root_domain, NULL);
}
+gboolean
+mono_runtime_is_shutting_down (void)
+{
+ return shutting_down;
+}
+
gboolean
mono_domain_has_type_resolve (MonoDomain *domain)
{
data->domain = ad;
data->setup = setup;
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");
mono_context_init (data);
{
gint i;
+ if (!ass->aname.name)
+ return;
+
mono_domain_lock (domain);
if (g_hash_table_lookup (domain->assemblies, ass->aname.name)) {
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);
- if (uri != file)
- g_free (uri);
+ g_free (uri);
+
+ if (tmpuri != file)
+ g_free (tmpuri);
if (error != NULL) {
g_warning ("%s\n", error->message);
}
static MonoAssembly *
-real_load (gchar **search_path, gchar *filename)
+real_load (gchar **search_path, const gchar *culture, gchar *filename)
{
MonoAssembly *result;
gchar **path;
for (path = search_path; *path; path++) {
if (**path == '\0')
continue; /* Ignore empty ApplicationBase */
- fullpath = g_build_filename (*path, filename, NULL);
+ 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)
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, dll);
+ 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, exe);
+ result = real_load (domain->search_path, aname->culture, exe);
if (result) {
g_free (dll);
g_free (exe);
}
if (assemblies_path && assemblies_path [0] != NULL) {
- result = real_load (assemblies_path, dll);
+ result = real_load (assemblies_path, aname->culture, dll);
if (result) {
g_free (dll);
g_free (exe);
return result;
}
- result = real_load (assemblies_path, exe);
+ result = real_load (assemblies_path, aname->culture, exe);
if (result) {
g_free (dll);
g_free (exe);
}
static gboolean
-get_info_from_assembly_name (MonoReflectionAssemblyName *assRef, MonoAssemblyName *aname)
+get_info_from_assembly_name (MonoString *assRef, MonoAssemblyName *aname)
{
gchar *name;
gchar *value;
memset (aname, 0, sizeof (MonoAssemblyName));
- name = mono_string_to_utf8 (assRef->name);
+ name = mono_string_to_utf8 (assRef);
parts = tmp = g_strsplit (name, ",", 4);
g_free (name);
if (!tmp || !*tmp) {
return TRUE;
}
- value = g_strstrip (*tmp);
- if (strncmp (value, "Version=", 8)) {
- g_strfreev (parts);
- return FALSE;
- }
-
- if (sscanf (value + 8, "%u.%u.%u.%u", &major, &minor, &build, &revision) != 4) {
- g_strfreev (parts);
- return FALSE;
- }
-
- /* g_print ("Version: %u.%u.%u.%u\n", major, minor, build, revision); */
- aname->major = major;
- aname->minor = minor;
- aname->build = build;
- aname->revision = revision;
- tmp++;
-
- if (!*tmp) {
- g_strfreev (parts);
- return FALSE;
- }
-
- value = g_strstrip (*tmp);
- if (strncmp (value, "Culture=", 8)) {
- g_strfreev (parts);
- return FALSE;
- }
-
- /* g_print ("Culture: %s\n", aname->culture); */
- aname->culture = g_strstrip (g_strdup (value + 8));
- tmp++;
-
- if (!*tmp) {
- g_strfreev (parts);
- return FALSE;
- }
-
- value = g_strstrip (*tmp);
- if (strncmp (value, "PublicKeyToken=", 15)) {
- g_strfreev (parts);
- return FALSE;
- }
+ while (*tmp) {
+ value = g_strstrip (*tmp);
+ if (!strncmp (value, "Version=", 8)) {
+ if (sscanf (value + 8, "%u.%u.%u.%u",
+ &major, &minor, &build, &revision) != 4) {
+ g_strfreev (parts);
+ return FALSE;
+ }
+ /* g_print ("Version: %u.%u.%u.%u\n", major, minor, build, revision); */
+ aname->major = major;
+ aname->minor = minor;
+ aname->build = build;
+ aname->revision = revision;
+ tmp++;
+ continue;
+ }
- 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;
+ if (!strncmp (value, "Culture=", 8)) {
+ /* g_print ("Culture: %s\n", aname->culture); */
+ aname->culture = g_strstrip (g_strdup (value + 8));
+ tmp++;
+ continue;
}
-
- 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) {
+
+ if (!strncmp (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;
}
- 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;
+
+ 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_free (value);
- /*
- g_print ("PublicKeyToken: ");
- for (i = 0; i < aname->hash_len; i++) {
- g_print ("%x", 0x00FF & aname->hash_value [i]);
+ /*
+ g_print ("PublicKeyToken: ");
+ for (i = 0; i < aname->hash_len; i++) {
+ g_print ("%x", 0x00FF & aname->hash_value [i]);
+ }
+ g_print ("\n");
+ */
+ }
}
- g_print ("\n");
- */
}
g_strfreev (parts);
}
MonoReflectionAssembly *
-ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad, MonoReflectionAssemblyName *assRef, MonoObject *evidence)
+ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
+ MonoArray *raw_assembly,
+ MonoArray *raw_symbol_store, MonoObject *evidence)
+{
+ MonoAssembly *ass;
+ MonoDomain *domain = ad->data;
+ MonoImageOpenStatus status;
+ guint32 raw_assembly_len = mono_array_length (raw_assembly);
+ MonoImage *image = mono_image_open_from_data (mono_array_addr (raw_assembly, gchar, 0), raw_assembly_len, TRUE, NULL);
+
+ if (raw_symbol_store)
+ mono_raise_exception (mono_get_exception_not_implemented ("LoadAssemblyRaw: Raw Symbol Store not Implemented"));
+
+ if (!image) {
+ mono_raise_exception (mono_get_exception_bad_image_format (""));
+ return NULL;
+ }
+
+ ass = mono_assembly_load_from (image, "", &status);
+
+ if (!ass) {
+ mono_image_close (image);
+ mono_raise_exception (mono_get_exception_bad_image_format (""));
+ return NULL;
+ }
+
+ return mono_assembly_get_object (domain, ass);
+}
+
+MonoReflectionAssembly *
+ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad, MonoString *assRef, MonoObject *evidence)
{
MonoDomain *domain = ad->data;
MonoImageOpenStatus status = MONO_IMAGE_OK;
/* FIXME : examine evidence? */
g_assert (assRef != NULL);
- g_assert (assRef->name != NULL);
if (!get_info_from_assembly_name (assRef, &aname)) {
MonoException *exc;
free_assembly_name (&aname);
/* This is a parse error... */
- exc = mono_get_exception_file_not_found (assRef->name);
+ exc = mono_get_exception_file_not_found (assRef);
mono_raise_exception (exc);
}
ass = mono_assembly_load (&aname, NULL, &status);
free_assembly_name (&aname);
- if (!ass && (refass = try_assembly_resolve (domain, assRef->name)) == NULL){
+ if (!ass && (refass = try_assembly_resolve (domain, assRef)) == NULL){
/* FIXME: it doesn't make much sense since we really don't have a filename ... */
- MonoException *exc = mono_get_exception_file_not_found (assRef->name);
+ MonoException *exc = mono_get_exception_file_not_found (assRef);
mono_raise_exception (exc);
}
MONO_ARCH_SAVE_REGS;
- if (!mono_domain_set (domain, FALSE))
+ if (!domain || !mono_domain_set (domain, FALSE))
mono_raise_exception (mono_get_exception_appdomain_unloaded ());
return current_domain->domain;
}
-MonoObject *
-ves_icall_System_AppDomain_InternalInvokeInDomain (MonoAppDomain *ad, MonoReflectionMethod *method, MonoObject *obj, MonoArray *args)
+void
+ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad)
{
- MonoDomain *old_domain = mono_domain_get ();
- MonoMethod *m = method->method;
- MonoObject *res;
-
MONO_ARCH_SAVE_REGS;
- if (!mono_domain_set (ad->data, FALSE))
- mono_raise_exception (mono_get_exception_appdomain_unloaded ());
-
mono_thread_push_appdomain_ref (ad->data);
+}
- res = mono_runtime_invoke_array (m, obj, args, NULL);
-
- mono_thread_pop_appdomain_ref ();
+void
+ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id)
+{
+ MonoDomain *domain = mono_domain_get_by_id (domain_id);
- mono_domain_set (old_domain, TRUE);
+ MONO_ARCH_SAVE_REGS;
- return res;
+ if (domain)
+ mono_thread_push_appdomain_ref (domain);
}
-MonoObject *
-ves_icall_System_AppDomain_InternalInvokeInDomainByID (gint32 domain_id, MonoReflectionMethod *method, MonoObject *obj, MonoArray *args)
+void
+ves_icall_System_AppDomain_InternalPopDomainRef (void)
{
- MonoDomain *domain = mono_domain_get_by_id (domain_id);
-
- if (!domain)
- mono_raise_exception (mono_get_exception_appdomain_unloaded ());
+ MONO_ARCH_SAVE_REGS;
- return ves_icall_System_AppDomain_InternalInvokeInDomain (domain->domain, method, obj, args);
+ mono_thread_pop_appdomain_ref ();
}
MonoAppContext *
domain->state = MONO_APPDOMAIN_UNLOADED;
+ //printf ("UNLOADED %s.\n", domain->friendly_name);
+
mono_domain_free (domain, FALSE);
#ifdef HAVE_BOEHM_GC
* First we create a separate thread for unloading, since
* we might have to abort some threads, including the current one.
*/
+ /*
+ * If we create a non-suspended thread, the runtime will hang.
+ * See:
+ * http://bugzilla.ximian.com/show_bug.cgi?id=27663
+ */
+#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);
+ ResumeThread (thread_handle);
+#endif
ret = WaitForSingleObject (thread_handle, INFINITE);
if (thread_data.failure_reason) {