[io-layer] Extract socket (#4241)
[mono.git] / mono / mini / driver.c
index 9181e53b25257183de08774b3a793327ebe33be2..40de446bc05907dfe1468965c7c7e47e9e3d8745 100644 (file)
@@ -33,7 +33,6 @@
 #include <mono/metadata/tabledefs.h>
 #include <mono/metadata/threads.h>
 #include <mono/metadata/marshal.h>
-#include <mono/metadata/socket-io.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
 #include <mono/io-layer/io-layer.h>
 #include <mono/metadata/gc-internals.h>
 #include <mono/metadata/coree.h>
 #include <mono/metadata/attach.h>
+#include <mono/metadata/w32process.h>
 #include "mono/utils/mono-counters.h"
 #include "mono/utils/mono-hwcap.h"
 #include "mono/utils/mono-logger-internals.h"
+#include "mono/metadata/w32handle.h"
 
 #include "mini.h"
 #include "jit.h"
 #include "aot-compiler.h"
+#include "interpreter/interp.h"
 
 #include <string.h>
 #include <ctype.h>
@@ -933,7 +935,7 @@ compile_all_methods_thread_main_inner (CompileAllThreadArgs *args)
                    (method->flags & METHOD_ATTRIBUTE_ABSTRACT))
                        continue;
 
-               if (method->klass->generic_container)
+               if (mono_class_is_gtd (method->klass))
                        continue;
                sig = mono_method_signature (method);
                if (!sig) {
@@ -953,7 +955,7 @@ compile_all_methods_thread_main_inner (CompileAllThreadArgs *args)
                        g_print ("Compiling %d %s\n", count, desc);
                        g_free (desc);
                }
-               cfg = mini_method_compile (method, mono_get_optimizations_for_method (method, args->opts), mono_get_root_domain (), (JitFlags)0, 0, -1);
+               cfg = mini_method_compile (method, mono_get_optimizations_for_method (method, args->opts), mono_get_root_domain (), (JitFlags)JIT_FLAG_DISCARD_RESULTS, 0, -1);
                if (cfg->exception_type != MONO_EXCEPTION_NONE) {
                        printf ("Compilation of %s failed with exception '%s':\n", mono_method_full_name (cfg->method, TRUE), cfg->exception_message);
                        fail_count ++;
@@ -1273,6 +1275,8 @@ mini_usage (void)
 #ifdef HOST_WIN32
                "    --mixed-mode           Enable mixed-mode image support.\n"
 #endif
+               "    --handlers             Install custom handlers, use --help-handlers for details.\n"
+               "    --aot-path=PATH        List of additional directories to search for AOT images.\n"
          );
 }
 
@@ -1367,30 +1371,6 @@ static const char info[] =
 #define error_if_aot_unsupported()
 #endif
 
-#ifdef HOST_WIN32
-BOOL APIENTRY DllMain (HMODULE module_handle, DWORD reason, LPVOID reserved)
-{
-       if (!mono_gc_dllmain (module_handle, reason, reserved))
-               return FALSE;
-
-       switch (reason)
-       {
-       case DLL_PROCESS_ATTACH:
-               mono_install_runtime_load (mini_init);
-               break;
-       case DLL_PROCESS_DETACH:
-               if (coree_module_handle)
-                       FreeLibrary (coree_module_handle);
-               break;
-       case DLL_THREAD_DETACH:
-               mono_thread_info_detach ();
-               break;
-       
-       }
-       return TRUE;
-}
-#endif
-
 static gboolean enable_debugging;
 
 /*
@@ -1457,6 +1437,10 @@ mono_jit_parse_options (int argc, char * argv[])
                        
                        if (!mono_debugger_insert_breakpoint (argv [++i], FALSE))
                                fprintf (stderr, "Error: invalid method name '%s'\n", argv [i]);
+               } else if (strncmp (argv[i], "--gc-params=", 12) == 0) {
+                       mono_gc_params_set (argv[i] + 12);
+               } else if (strncmp (argv[i], "--gc-debug=", 11) == 0) {
+                       mono_gc_debug_set (argv[i] + 11);
                } else if (strcmp (argv [i], "--llvm") == 0) {
 #ifndef MONO_ARCH_LLVM_SUPPORTED
                        fprintf (stderr, "Mono Warning: --llvm not supported on this platform.\n");
@@ -1523,6 +1507,7 @@ switch_gc (char* argv[], const char* target_gc)
 
 #ifdef HAVE_EXECVP
        execvp (path->str, argv);
+       fprintf (stderr, "Error: Failed to switch to %s gc. mono-%s is not installed.\n", target_gc, target_gc);
 #else
        fprintf (stderr, "Error: --gc=<NAME> option not supported on this platform.\n");
 #endif
@@ -1574,6 +1559,10 @@ switch_arch (char* argv[], const char* target_arch)
 }
 
 #endif
+
+#define MONO_HANDLERS_ARGUMENT "--handlers="
+#define MONO_HANDLERS_ARGUMENT_LEN G_N_ELEMENTS(MONO_HANDLERS_ARGUMENT)-1
+
 /**
  * mono_main:
  * @argc: number of arguments in the argv array
@@ -1701,6 +1690,10 @@ mono_main (int argc, char* argv[])
                        switch_gc (argv, "sgen");
                } else if (strcmp (argv [i], "--gc=boehm") == 0) {
                        switch_gc (argv, "boehm");
+               } else if (strncmp (argv[i], "--gc-params=", 12) == 0) {
+                       mono_gc_params_set (argv[i] + 12);
+               } else if (strncmp (argv[i], "--gc-debug=", 11) == 0) {
+                       mono_gc_debug_set (argv[i] + 11);
                }
 #ifdef TARGET_OSX
                else if (strcmp (argv [i], "--arch=32") == 0) {
@@ -1767,10 +1760,11 @@ mono_main (int argc, char* argv[])
                } else if (strcmp (argv [i], "--verify-all") == 0) {
                        mono_verifier_enable_verify_all ();
                } else if (strcmp (argv [i], "--full-aot") == 0) {
-                       mono_aot_only = TRUE;
+                       mono_jit_set_aot_mode (MONO_AOT_MODE_FULL);
                } else if (strcmp (argv [i], "--llvmonly") == 0) {
-                       mono_aot_only = TRUE;
-                       mono_llvm_only = TRUE;
+                       mono_jit_set_aot_mode (MONO_AOT_MODE_LLVMONLY);
+               } else if (strcmp (argv [i], "--hybrid-aot") == 0) {
+                       mono_jit_set_aot_mode (MONO_AOT_MODE_HYBRID);
                } else if (strcmp (argv [i], "--print-vtable") == 0) {
                        mono_print_vtable = TRUE;
                } else if (strcmp (argv [i], "--stats") == 0) {
@@ -1786,6 +1780,16 @@ mono_main (int argc, char* argv[])
                        mono_compile_aot = TRUE;
                        aot_options = &argv [i][6];
 #endif
+               } else if (strncmp (argv [i], "--aot-path=", 11) == 0) {
+                       char **splitted;
+
+                       splitted = g_strsplit (argv [i] + 11, G_SEARCHPATH_SEPARATOR_S, 1000);
+                       while (*splitted) {
+                               char *tmp = *splitted;
+                               mono_aot_paths = g_list_append (mono_aot_paths, g_strdup (tmp));
+                               g_free (tmp);
+                               splitted++;
+                       }
                } else if (strncmp (argv [i], "--compile-all=", 14) == 0) {
                        action = DO_COMPILE;
                        recompilation_times = atoi (argv [i] + 14);
@@ -1915,12 +1919,26 @@ mono_main (int argc, char* argv[])
 #endif
                } else if (strcmp (argv [i], "--nollvm") == 0){
                        mono_use_llvm = FALSE;
+#ifdef ENABLE_INTERPRETER
+               } else if (strcmp (argv [i], "--interpreter") == 0) {
+                       mono_use_interpreter = TRUE;
+#endif
+
 #ifdef __native_client__
                } else if (strcmp (argv [i], "--nacl-mono-path") == 0){
                        nacl_mono_path = g_strdup(argv[++i]);
                } else if (strcmp (argv [i], "--nacl-null-checks-off") == 0){
                        nacl_null_checks_off = TRUE;
 #endif
+               } else if (strncmp (argv [i], MONO_HANDLERS_ARGUMENT, MONO_HANDLERS_ARGUMENT_LEN) == 0) {
+                       //Install specific custom handlers.
+                       if (!mono_runtime_install_custom_handlers (argv[i] + MONO_HANDLERS_ARGUMENT_LEN)) {
+                               fprintf (stderr, "error: " MONO_HANDLERS_ARGUMENT ", one or more unknown handlers: '%s'\n", argv [i]);
+                               return 1;
+                       }
+               } else if (strcmp (argv [i], "--help-handlers") == 0) {
+                       mono_runtime_install_custom_handlers_usage ();
+                       return 0;
                } else if (argv [i][0] == '-' && argv [i][1] == '-' && mini_parse_debug_option (argv [i] + 2)) {
                } else {
                        fprintf (stderr, "Unknown command line option: '%s'\n", argv [i]);
@@ -1955,9 +1973,9 @@ mono_main (int argc, char* argv[])
        {
                char *runtime_path;
 
-               runtime_path = wapi_process_get_path (getpid ());
+               runtime_path = mono_w32process_get_path (getpid ());
                if (runtime_path) {
-                       wapi_process_set_cli_launcher (runtime_path);
+                       mono_w32process_set_cli_launcher (runtime_path);
                        g_free (runtime_path);
                }
        }
@@ -1986,18 +2004,15 @@ mono_main (int argc, char* argv[])
 
        mono_counters_init ();
 
+#ifndef HOST_WIN32
+       mono_w32handle_init ();
+#endif
+
        /* Set rootdir before loading config */
        mono_set_rootdir ();
 
-       /*
-        * We only set the native name of the thread since MS.NET leaves the
-        * managed thread name for the main thread as null.
-        */
-       mono_native_thread_set_name (mono_native_thread_id_get (), "Main");
-
        if (enable_profile) {
-               mono_profiler_load (profile_options);
-               mono_profiler_thread_name (MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ()), "Main");
+               mini_profiler_enable_with_options (profile_options);
        }
 
        mono_attach_parse_options (attach_options);
@@ -2037,6 +2052,11 @@ mono_main (int argc, char* argv[])
        }
 
        mono_set_defaults (mini_verbose, opt);
+#if ENABLE_INTERPRETER
+       if (mono_use_interpreter)
+               domain = mono_interp_init (argv [i]);
+       else
+#endif
        domain = mini_init (argv [i], forced_version);
 
        mono_gc_set_stack_end (&domain);
@@ -2060,6 +2080,17 @@ mono_main (int argc, char* argv[])
        case DO_SINGLE_METHOD_REGRESSION:
                mono_do_single_method_regression = TRUE;
        case DO_REGRESSION:
+#ifdef ENABLE_INTERPRETER
+               if (mono_use_interpreter) {
+                       if (interp_regression_list (2, argc -i, argv + i)) {
+                               g_print ("Regression ERRORS!\n");
+                               // mini_cleanup (domain);
+                               return 1;
+                       }
+                       // mini_cleanup (domain);
+                       return 0;
+               }
+#endif
                if (mini_regression_list (mini_verbose, argc -i, argv + i)) {
                        g_print ("Regression ERRORS!\n");
                        mini_cleanup (domain);
@@ -2092,6 +2123,10 @@ mono_main (int argc, char* argv[])
                aname = argv [i];
                break;
        default:
+#ifdef ENABLE_INTERPRETER
+               if (mono_use_interpreter)
+                       g_error ("not yet");
+#endif
                if (argc - i < 1) {
                        mini_usage ();
                        mini_cleanup (domain);
@@ -2130,7 +2165,7 @@ mono_main (int argc, char* argv[])
                        exit (1);
                }
 
-#ifdef HOST_WIN32
+#if defined(HOST_WIN32) && G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
                /* Detach console when executing IMAGE_SUBSYSTEM_WINDOWS_GUI on win32 */
                if (!enable_debugging && !mono_compile_aot && ((MonoCLIImageInfo*)(mono_assembly_get_image (assembly)->image_info))->cli_header.nt.pe_subsys_required == IMAGE_SUBSYSTEM_WINDOWS_GUI)
                        FreeConsole ();
@@ -2321,11 +2356,21 @@ mono_jit_set_aot_only (gboolean val)
 void
 mono_jit_set_aot_mode (MonoAotMode mode)
 {
+       /* we don't want to set mono_aot_mode twice */
+       g_assert (mono_aot_mode == MONO_AOT_MODE_NONE);
        mono_aot_mode = mode;
+
        if (mono_aot_mode == MONO_AOT_MODE_LLVMONLY) {
                mono_aot_only = TRUE;
                mono_llvm_only = TRUE;
        }
+       if (mono_aot_mode == MONO_AOT_MODE_FULL) {
+               mono_aot_only = TRUE;
+       }
+       if (mono_aot_mode == MONO_AOT_MODE_HYBRID) {
+               mono_set_generic_sharing_vt_supported (TRUE);
+               mono_set_partial_sharing_supported (TRUE);
+       }
 }
 
 /**