First set of licensing changes
[mono.git] / mono / mini / driver.c
index 09da6d2875e48376d83823e8eec0857ad79e4300..a84cd2f6ab049bf3bde009f94c6c947ece646446 100644 (file)
@@ -7,6 +7,7 @@
  *
  * (C) 2002-2003 Ximian, Inc.
  * (C) 2003-2006 Novell, Inc.
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -50,6 +51,7 @@
 #include <mono/metadata/attach.h>
 #include "mono/utils/mono-counters.h"
 #include "mono/utils/mono-hwcap.h"
+#include "mono/utils/mono-logger-internals.h"
 
 #include "mini.h"
 #include "jit.h"
@@ -381,9 +383,12 @@ mini_regression_step (MonoImage *image, int verbose, int *total_run, int *total,
        if (mini_stats_fd)
                fprintf (mini_stats_fd, "[");
        for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
-               MonoMethod *method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL);
-               if (!method)
+               MonoError error;
+               MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
+               if (!method) {
+                       mono_error_cleanup (&error); /* FIXME don't swallow the error */
                        continue;
+               }
                if (strncmp (method->name, "test_", 5) == 0) {
                        MonoCompile *cfg;
 
@@ -474,9 +479,12 @@ mini_regression (MonoImage *image, int verbose, int *total_run)
 
        /* load the metadata */
        for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
-               method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL);
-               if (!method)
+               MonoError error;
+               method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
+               if (!method) {
+                       mono_error_cleanup (&error);
                        continue;
+               }
                mono_class_init (method->klass);
 
                if (!strncmp (method->name, "test_", 5) && mini_stats_fd) {
@@ -904,15 +912,18 @@ compile_all_methods_thread_main_inner (CompileAllThreadArgs *args)
        int i, count = 0, fail_count = 0;
 
        for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
+               MonoError error;
                guint32 token = MONO_TOKEN_METHOD_DEF | (i + 1);
                MonoMethodSignature *sig;
 
                if (mono_metadata_has_generic_params (image, token))
                        continue;
 
-               method = mono_get_method (image, token, NULL);
-               if (!method)
+               method = mono_get_method_checked (image, token, NULL, NULL, &error);
+               if (!method) {
+                       mono_error_cleanup (&error); /* FIXME don't swallow the error */
                        continue;
+               }
                if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
                    (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
                    (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
@@ -989,6 +1000,7 @@ compile_all_methods (MonoAssembly *ass, int verbose, guint32 opts, guint32 recom
 int 
 mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
 {
+       MonoError error;
        MonoImage *image = mono_assembly_get_image (assembly);
        MonoMethod *method;
        guint32 entry = mono_image_get_entry_point (image);
@@ -1000,14 +1012,28 @@ mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[
                return 1;
        }
 
-       method = mono_get_method (image, entry, NULL);
+       method = mono_get_method_checked (image, entry, NULL, NULL, &error);
        if (method == NULL){
-               g_print ("The entry point method could not be loaded\n");
+               g_print ("The entry point method could not be loaded due to %s\n", mono_error_get_message (&error));
+               mono_error_cleanup (&error);
                mono_environment_exitcode_set (1);
                return 1;
        }
        
-       return mono_runtime_run_main (method, argc, argv, NULL);
+       if (mono_llvm_only) {
+               MonoObject *exc;
+               int res;
+
+               res = mono_runtime_run_main (method, argc, argv, &exc);
+               if (exc) {
+                       mono_unhandled_exception (exc);
+                       mono_invoke_unhandled_exception_hook (exc);
+                       return 1;
+               }
+               return res;
+       } else {
+               return mono_runtime_run_main (method, argc, argv, NULL);
+       }
 }
 
 typedef struct 
@@ -1073,6 +1099,7 @@ static void main_thread_handler (gpointer user_data)
 static int
 load_agent (MonoDomain *domain, char *desc)
 {
+       MonoError error;
        char* col = strchr (desc, ':'); 
        char *agent, *args;
        MonoAssembly *agent_assembly;
@@ -1111,9 +1138,10 @@ load_agent (MonoDomain *domain, char *desc)
                return 1;
        }
 
-       method = mono_get_method (image, entry, NULL);
+       method = mono_get_method_checked (image, entry, NULL, NULL, &error);
        if (method == NULL){
-               g_print ("The entry point method of assembly '%s' could not be loaded\n", agent);
+               g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, &error);
+               mono_error_cleanup (&error);
                g_free (agent);
                return 1;
        }
@@ -1131,7 +1159,8 @@ load_agent (MonoDomain *domain, char *desc)
 
        pa [0] = main_args;
        /* Pass NULL as 'exc' so unhandled exceptions abort the runtime */
-       mono_runtime_invoke (method, NULL, pa, NULL);
+       mono_runtime_invoke_checked (method, NULL, pa, &error);
+       mono_error_raise_exception (&error); /* FIXME don't raise here */
 
        return 0;
 }
@@ -1574,7 +1603,7 @@ mono_main (int argc, char* argv[])
 #if TARGET_OSX
        darwin_change_default_file_handles ();
 #endif
-       
+
        if (g_getenv ("MONO_NO_SMP"))
                mono_set_use_smp (FALSE);
        
@@ -1900,6 +1929,14 @@ mono_main (int argc, char* argv[])
        }
 #endif
 
+#ifdef DISABLE_HW_TRAPS
+       // Signal handlers not available
+       {
+               MonoDebugOptions *opt = mini_get_debug_options ();
+               opt->explicit_null_checks = TRUE;
+       }
+#endif
+
        if (!argv [i]) {
                mini_usage ();
                return 1;
@@ -2240,8 +2277,9 @@ mono_jit_init (const char *file)
  * (since Mono does not support having more than one mscorlib runtime
  * loaded at once).
  *
- * The @runtime_version can be one of these strings: "v1.1.4322" for
- * the 1.1 runtime or "v2.0.50727"  for the 2.0 runtime. 
+ * The @runtime_version can be one of these strings: "v4.0.30319" for
+ * desktop, "mobile" for mobile or "moonlight" for Silverlight compat.
+ * If an unrecognized string is input, the vm will default to desktop.
  *
  * Returns: the MonoDomain representing the domain where the assembly
  * was loaded.
@@ -2270,8 +2308,10 @@ void
 mono_jit_set_aot_mode (MonoAotMode mode)
 {
        mono_aot_mode = mode;
-       if (mono_aot_mode == MONO_AOT_MODE_LLVMONLY)
+       if (mono_aot_mode == MONO_AOT_MODE_LLVMONLY) {
+               mono_aot_only = TRUE;
                mono_llvm_only = TRUE;
+       }
 }
 
 /**