#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
+#ifdef HAVE_UTIME_H
+#include <utime.h>
+#else
+#ifdef HAVE_SYS_UTIME_H
+#include <sys/utime.h>
+#endif
+#endif
-#include <mono/os/gc_wrapper.h>
-
+#include <mono/metadata/gc-internal.h>
#include <mono/metadata/object.h>
#include <mono/metadata/domain-internals.h>
#include "mono/metadata/metadata-internals.h"
#include <direct.h>
#endif
-#define MONO_CORLIB_VERSION 59
+/*
+ * This is the version number of the corlib-runtime interface. When
+ * making changes to this interface (by changing the layout
+ * of classes the runtime knows about, changing icall signature or
+ * semantics etc), increment this variable. Also increment the
+ * pair of this variable in mscorlib in:
+ * mcs/class/mscorlib/System/Environment.cs
+ *
+ * Changes which are already detected at runtime, like the addition
+ * of icalls, do not require an increment.
+ */
+#define MONO_CORLIB_VERSION 68
typedef struct
{
static void
mono_domain_unload (MonoDomain *domain);
+static MonoLoadFunc load_function = NULL;
+
+void
+mono_install_runtime_load (MonoLoadFunc func)
+{
+ load_function = func;
+}
+
+MonoDomain*
+mono_runtime_load (const char *filename, const char *runtime_version)
+{
+ g_assert (load_function);
+ return load_function (filename, runtime_version);
+}
+
/**
* mono_runtime_init:
* @domain: domain returned by mono_init ()
mono_portability_helpers_init ();
- MONO_GC_PRE_INIT ();
+ mono_gc_base_init ();
mono_monitor_init ();
mono_thread_pool_init ();
mono_marshal_init ();
data->domain = ad;
data->setup = setup;
data->friendly_name = mono_string_to_utf8 (friendly_name);
+ // FIXME: The ctor runs in the current domain
+ // FIXME: Initialize null_reference_ex and stack_overflow_ex
data->out_of_memory_ex = mono_exception_from_name_domain (data, mono_defaults.corlib, "System", "OutOfMemoryException");
if (!setup->application_base) {
static MonoClass *System_Reflection_Assembly;
MonoArray *res;
GSList *tmp;
- int i, count;
-
+ int i;
+ GPtrArray *assemblies;
+
MONO_ARCH_SAVE_REGS;
if (!System_Reflection_Assembly)
System_Reflection_Assembly = mono_class_from_name (
mono_defaults.corlib, "System.Reflection", "Assembly");
- count = 0;
+ /*
+ * Make a copy of the list of assemblies because we can't hold the assemblies
+ * lock while creating objects etc.
+ */
+ assemblies = g_ptr_array_new ();
/* Need to skip internal assembly builders created by remoting */
mono_domain_assemblies_lock (domain);
- for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
- ass = tmp->data;
- if (refonly && !ass->ref_only)
- continue;
- 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 (refonly && !ass->ref_only)
continue;
if (ass->corlib_internal)
continue;
- mono_array_setref (res, i, mono_assembly_get_object (domain, ass));
- ++i;
+ g_ptr_array_add (assemblies, ass);
}
mono_domain_assemblies_unlock (domain);
+ res = mono_array_new (domain, System_Reflection_Assembly, assemblies->len);
+ for (i = 0; i < assemblies->len; ++i) {
+ ass = g_ptr_array_index (assemblies, i);
+ mono_array_setref (res, i, mono_assembly_get_object (domain, ass));
+ }
+
+ g_ptr_array_free (assemblies, TRUE);
+
return res;
}
mono_runtime_invoke (assembly_load_method, domain->domain, params, NULL);
}
+/*
+ * LOCKING: Acquires the domain assemblies lock.
+ */
static void
set_domain_search_path (MonoDomain *domain)
{
GError *error = NULL;
gint appbaselen = -1;
- if ((domain->search_path != NULL) && !domain->setup->path_changed)
+ /*
+ * We use the low-level domain assemblies lock, since this is called from
+ * assembly loads hooks, which means this thread might hold the loader lock.
+ */
+ mono_domain_assemblies_lock (domain);
+
+ if ((domain->search_path != NULL) && !domain->setup->path_changed) {
+ mono_domain_assemblies_unlock (domain);
return;
- if (!domain->setup)
+ }
+ if (!domain->setup) {
+ mono_domain_assemblies_unlock (domain);
return;
+ }
setup = domain->setup;
- if (!setup->application_base)
+ if (!setup->application_base) {
+ mono_domain_assemblies_unlock (domain);
return; /* Must set application base to get private path working */
+ }
npaths++;
* domain->search_path = g_malloc (sizeof (char *));
* domain->search_path [0] = NULL;
*/
+ mono_domain_assemblies_unlock (domain);
return;
}
domain->setup->path_changed = FALSE;
g_strfreev (pvt_split);
+
+ mono_domain_assemblies_unlock (domain);
}
static gboolean
char *p;
gchar *dir = g_path_get_dirname (filename);
int retval;
+ struct stat sbuf;
- if (!dir || !dir [0])
+ if (!dir || !dir [0]) {
+ g_free (dir);
return FALSE;
-
+ }
+
+ if (stat (dir, &sbuf) == 0 && S_ISDIR (sbuf.st_mode)) {
+ g_free (dir);
+ return TRUE;
+ }
+
p = dir;
while (*p == '/')
p++;
#endif
}
-static char *
-make_shadow_copy (const char *filename)
+static gboolean
+private_file_needs_copying (const char *src, struct stat *sbuf_src, char *dest)
+{
+ struct stat sbuf_dest;
+
+ if (stat (src, sbuf_src) == -1 || stat (dest, &sbuf_dest) == -1)
+ return TRUE;
+
+ if (sbuf_src->st_mode == sbuf_dest.st_mode &&
+ sbuf_src->st_size == sbuf_dest.st_size &&
+ sbuf_src->st_mtime == sbuf_dest.st_mtime)
+ return FALSE;
+
+ return TRUE;
+}
+
+char *
+mono_make_shadow_copy (const char *filename)
{
gchar *sibling_source, *sibling_target;
gint sibling_source_len, sibling_target_len;
guint16 *orig, *dest;
char *shadow;
gboolean copy_result;
+ gboolean is_private = FALSE;
+ gboolean do_copy = FALSE;
MonoException *exc;
+ gchar **path;
+ struct stat src_sbuf;
+ struct utimbuf utbuf;
+ char *dir_name = g_path_get_dirname (filename);
+ MonoDomain *domain = mono_domain_get ();
+ set_domain_search_path (domain);
+
+ if (!domain->search_path) {
+ g_free (dir_name);
+ return (char*) filename;
+ }
+
+ for (path = domain->search_path; *path; path++) {
+ if (**path == '\0') {
+ is_private = TRUE;
+ continue;
+ }
+
+ if (!is_private)
+ continue;
+
+ if (strstr (dir_name, *path) == dir_name) {
+ do_copy = TRUE;
+ break;
+ }
+ }
+ g_free (dir_name);
+
+ if (!do_copy)
+ return (char*) filename;
shadow = get_shadow_assembly_location (filename);
if (ensure_directory_exists (shadow) == FALSE) {
mono_raise_exception (exc);
}
+ if (!private_file_needs_copying (filename, &src_sbuf, shadow))
+ return (char*) shadow;
+
orig = g_utf8_to_utf16 (filename, strlen (filename), NULL, NULL, NULL);
dest = g_utf8_to_utf16 (shadow, strlen (shadow), NULL, NULL, NULL);
DeleteFile (dest);
exc = mono_get_exception_execution_engine ("Failed to create shadow copy of sibling data (CopyFile).");
mono_raise_exception (exc);
}
+
+ utbuf.actime = src_sbuf.st_atime;
+ utbuf.modtime = src_sbuf.st_mtime;
+ utime (shadow, &utbuf);
return shadow;
}
+
+MonoDomain *
+mono_domain_from_appdomain (MonoAppDomain *appdomain)
+{
+ if (appdomain == NULL)
+ return NULL;
+
+ return appdomain->data;
+}
+
static gboolean
try_load_from (MonoAssembly **assembly, const gchar *path1, const gchar *path2,
const gchar *path3, const gchar *path4,
gboolean refonly, gboolean is_private)
{
-
gchar *fullpath;
-
+ gboolean found = FALSE;
+
*assembly = NULL;
fullpath = g_build_filename (path1, path2, path3, path4, NULL);
- if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR)) {
- if (is_private) {
- char *new_path = make_shadow_copy (fullpath);
+
+ if (IS_PORTABILITY_SET) {
+ gchar *new_fullpath = mono_portability_find_file (fullpath, TRUE);
+ if (new_fullpath) {
g_free (fullpath);
- fullpath = new_path;
+ fullpath = new_fullpath;
+ found = TRUE;
}
-
+ } else
+ found = g_file_test (fullpath, G_FILE_TEST_IS_REGULAR);
+
+ if (found)
*assembly = mono_assembly_open_full (fullpath, NULL, refonly);
- }
g_free (fullpath);
return (*assembly != NULL);
/*
* Try loading the assembly from ApplicationBase and PrivateBinPath
* and then from assemblies_path if any.
+ * LOCKING: This is called from the assembly loading code, which means the caller
+ * might hold the loader lock. Thus, this function must not acquire the domain lock.
*/
static MonoAssembly *
mono_domain_assembly_preload (MonoAssemblyName *aname,
}
name = filename = mono_string_to_utf8 (fname);
-
+
ass = mono_assembly_open_full (filename, &status, refOnly);
if (!ass){
ass = mono_assembly_load_full_nosearch (&aname, NULL, &status, refOnly);
mono_assembly_name_free (&aname);
- if (!ass && (refass = mono_try_assembly_resolve (domain, assRef, refOnly)) == NULL){
- /* FIXME: it doesn't make much sense since we really don't have a filename ... */
- MonoException *exc = mono_get_exception_file_not_found2 (NULL, assRef);
- mono_raise_exception (exc);
+ if (!ass) {
+ /* MS.NET doesn't seem to call the assembly resolve handler for refonly assemblies */
+ if (!refOnly)
+ refass = mono_try_assembly_resolve (domain, assRef, refOnly);
+ else
+ refass = NULL;
+ if (!refass) {
+ /* FIXME: it doesn't make much sense since we really don't have a filename ... */
+ MonoException *exc = mono_get_exception_file_not_found2 (NULL, assRef);
+ mono_raise_exception (exc);
+ }
}
if (refass == NULL)
}
gint32
-ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad, MonoString *file,
- MonoObject *evidence, MonoArray *args)
+ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad,
+ MonoReflectionAssembly *refass, MonoArray *args)
{
- MonoAssembly *assembly;
MonoImage *image;
MonoMethod *method;
- char *filename;
- gint32 res;
- MonoReflectionAssembly *refass;
MONO_ARCH_SAVE_REGS;
- filename = mono_string_to_utf8 (file);
- assembly = mono_assembly_open (filename, NULL);
- g_free (filename);
-
- if (!assembly)
- mono_raise_exception (mono_get_exception_file_not_found2 (NULL, file));
-
- image = assembly->image;
+ g_assert (refass);
+ image = refass->assembly->image;
+ g_assert (image);
method = mono_get_method (image, mono_image_get_entry_point (image), NULL);
if (!args)
args = (MonoArray *) mono_array_new (ad->data, mono_defaults.string_class, 0);
- refass = mono_assembly_get_object (ad->data, assembly);
- MONO_OBJECT_SETREF (refass, evidence, evidence);
-
- res = mono_runtime_exec_main (method, (MonoArray *)args, NULL);
-
- return res;
+ return mono_runtime_exec_main (method, (MonoArray *)args, NULL);
}
gint32
* FIXME: Abort our parent thread last, so we can return a failure
* indication if aborting times out.
*/
- if (!mono_threads_abort_appdomain_threads (domain, 10000)) {
+ if (!mono_threads_abort_appdomain_threads (domain, -1)) {
data->failure_reason = g_strdup_printf ("Aborting of threads in domain %s timed out.", domain->friendly_name);
return 1;
}
/* Finalize all finalizable objects in the doomed appdomain */
- if (!mono_domain_finalize (domain, 10000)) {
+ if (!mono_domain_finalize (domain, -1)) {
data->failure_reason = g_strdup_printf ("Finalization of domain %s timed out.", domain->friendly_name);
return 1;
}