2008-08-28 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Thu, 28 Aug 2008 20:16:59 +0000 (20:16 -0000)
committerZoltan Varga <vargaz@gmail.com>
Thu, 28 Aug 2008 20:16:59 +0000 (20:16 -0000)
* appdomain.c (mono_runtime_set_no_exec): New internal function setting
the runtime into no-exec mode, useful when running the AOT compiler.

* appdomain.c gc.c object.c: Avoid executing managed code when running
in no-exec mode.

svn path=/trunk/mono/; revision=111865

mono/metadata/ChangeLog
mono/metadata/appdomain.c
mono/metadata/domain-internals.h
mono/metadata/gc.c
mono/metadata/object.c

index f5597e5ef6d7bfbeb4d6faf65897f5db83c75eb6..6fd2a23bcf9d9343cf59a3bb9fc546978df54400 100644 (file)
@@ -1,5 +1,11 @@
 2008-08-28  Zoltan Varga  <vargaz@gmail.com>
 
+       * appdomain.c (mono_runtime_set_no_exec): New internal function setting
+       the runtime into no-exec mode, useful when running the AOT compiler.
+
+       * appdomain.c gc.c object.c: Avoid executing managed code when running
+       in no-exec mode.
+       
        * rawbuffer.c (mono_raw_buffer_load_mmap): Disable this on the iphone.
 
        * reflection.c (_mono_reflection_get_type_from_info): Handle the 
index 94d0c2043775aa95f04dca4ba158a3b28f131138..17863eb9cb4568cb21b0308848c7e8fbb927f734 100644 (file)
@@ -77,6 +77,8 @@ static gboolean process_guid_set = FALSE;
 
 static gboolean shutting_down = FALSE;
 
+static gboolean no_exec = FALSE;
+
 static MonoAssembly *
 mono_domain_assembly_preload (MonoAssemblyName *aname,
                              gchar **assemblies_path,
@@ -114,6 +116,26 @@ mono_runtime_load (const char *filename, const char *runtime_version)
        return load_function (filename, runtime_version);
 }
 
+/*
+ * mono_runtime_set_no_exec:
+ *
+ *   Instructs the runtime to operate in static mode, i.e. avoid/do not allow managed
+ * code execution. This is useful for running the AOT compiler on platforms which
+ * allow full-aot execution only.
+ * This should be called before mono_runtime_init ().
+ */
+void
+mono_runtime_set_no_exec (gboolean val)
+{
+       no_exec = val;
+}
+
+gboolean
+mono_runtime_get_no_exec (void)
+{
+       return no_exec;
+}
+
 /**
  * mono_runtime_init:
  * @domain: domain returned by mono_init ()
@@ -170,22 +192,23 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
 
        mono_type_initialization_init ();
 
+       if (!mono_runtime_get_no_exec ()) {
+               /*
+                * Create an instance early since we can't do it when there is no memory.
+                */
+               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);
        
-       /*
-        * Create an instance early since we can't do it when there is no memory.
-        */
-       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.
-        */
-       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);
-       
+               /* 
+                * These two are needed because the signal handlers might be executing on
+                * an alternate stack, and Boehm GC can't handle that.
+                */
+               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 ();
 
index 3a54ab477c6182b98943276f4bb82f0771b69e65..072138e9b829f9dd0e23927bcb41e94c225dd11f 100644 (file)
@@ -396,6 +396,12 @@ mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *
 const MonoRuntimeInfo*
 mono_get_runtime_info (void) MONO_INTERNAL;
 
+void
+mono_runtime_set_no_exec (gboolean val) MONO_INTERNAL;
+
+gboolean
+mono_runtime_get_no_exec (void) MONO_INTERNAL;
+
 gboolean
 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
 
index 8dd89081e183d0ee704364f0a5977d6c0e8c5a50..f9383eb32d761b77d8ecc2939704ffa2b463ce52 100644 (file)
@@ -118,6 +118,9 @@ run_finalize (void *obj, void *data)
                }
        }
 
+       if (mono_runtime_get_no_exec ())
+               return;
+
        /* speedup later... and use a timeout */
        /* g_print ("Finalize run on %p %s.%s\n", o, mono_object_class (o)->name_space, mono_object_class (o)->name); */
 
index 2440545176a3e4b6910b41ff8594e38053294259..be2f902732f6302fbd7e80a2824874868a7c9e19 100644 (file)
@@ -1047,7 +1047,7 @@ add_imt_builder_entry (MonoImtBuilderEntry **imt_builder, MonoMethod *method, gu
                /* we build just a single imt slot and this is not it */
                return;
        }
-       
+
        entry = malloc (sizeof (MonoImtBuilderEntry));
        entry->method = method;
        entry->vtable_slot = vtable_slot;
@@ -2163,6 +2163,9 @@ static MonoInvokeFunc default_mono_runtime_invoke = dummy_mono_runtime_invoke;
 MonoObject*
 mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc)
 {
+       if (mono_runtime_get_no_exec ())
+               g_warning ("Invoking method '%s' when running in no-exec mode.\n", mono_method_full_name (method, TRUE));
+
        return default_mono_runtime_invoke (method, obj, params, exc);
 }