Merge pull request #3442 from lateralusX/jlorenss/win-atexit-commands
authorJohan Lorensson <lateralusx.github@gmail.com>
Mon, 24 Oct 2016 09:53:15 +0000 (11:53 +0200)
committerGitHub <noreply@github.com>
Mon, 24 Oct 2016 09:53:15 +0000 (11:53 +0200)
Add support on Windows to install atexit handler(s) early in bootprocess.

1  2 
mono/mini/driver.c
mono/mini/mini-runtime.c
mono/mini/mini.h

diff --combined mono/mini/driver.c
index 514a7332a39c52785728a9a8e8a2fdc655d7083a,c1a0ae05a913727056f12a5a6049e4f68019fd96..14c97cbae30775317768cd2e19df55635904dc95
@@@ -1274,6 -1274,7 +1274,7 @@@ 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"
          );
  }
  
@@@ -1556,6 -1557,10 +1557,10 @@@ switch_arch (char* argv[], const char* 
  }
  
  #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
@@@ -1753,11 -1758,11 +1758,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) {
                } 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]);
        /* 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");
@@@ -2306,21 -2326,11 +2320,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);
 +      }
  }
  
  /**
diff --combined mono/mini/mini-runtime.c
index 617682fcec32c60f83dba9f5456da1e2241351d2,c0f0e04ec9c039b8d666d1cc7b202901c1bc7af0..92eb960a82278bc8c39c64cbb37d2cbeb5c5fb1f
@@@ -341,7 -341,7 +341,7 @@@ void *mono_global_codeman_reserve (int 
        void *ptr;
  
        if (mono_aot_only)
 -              g_error ("Attempting to allocate from the global code manager while running with --aot-only.\n");
 +              g_error ("Attempting to allocate from the global code manager while running in aot-only mode.\n");
  
        if (!global_codeman) {
                /* This can happen during startup */
@@@ -4256,3 -4256,23 +4256,23 @@@ mono_personality (void
        /* Not used */
        g_assert_not_reached ();
  }
+ // Custom handlers currently only implemented by Windows.
+ #ifndef HOST_WIN32
+ gboolean
+ mono_runtime_install_custom_handlers (const char *handlers)
+ {
+       return FALSE;
+ }
+ void
+ mono_runtime_install_custom_handlers_usage (void)
+ {
+       fprintf (stdout,
+                "Custom Handlers:\n"
+                "   --handlers=HANDLERS            Enable handler support, HANDLERS is a comma\n"
+                "                                  separated list of available handlers to install.\n"
+                "\n"
+                "No handlers supported on current platform.\n");
+ }
+ #endif /* HOST_WIN32 */
diff --combined mono/mini/mini.h
index bacb58402fff2fc1e96012081dc917ec0517c94f,d1236ef1b539160015486b6fe33566675c981a53..03ef9f89f199d3c3e606e3cf92af06d78fe8c600
@@@ -1743,7 -1743,7 +1743,7 @@@ typedef struct 
        guint8          *thunks;
        /* Offset between the start of code and the thunks area */
        int              thunks_offset;
 -      guint32          exception_type;        /* MONO_EXCEPTION_* */
 +      MonoExceptionType exception_type;       /* MONO_EXCEPTION_* */
        guint32          exception_data;
        char*            exception_message;
        gpointer         exception_ptr;
@@@ -3152,6 -3152,8 +3152,8 @@@ gboolean mono_jit_map_is_enabled (void)
   * Per-OS implementation functions.
   */
  void mono_runtime_install_handlers (void);
+ gboolean mono_runtime_install_custom_handlers (const char *handlers);
+ void mono_runtime_install_custom_handlers_usage (void);
  void mono_runtime_cleanup_handlers (void);
  void mono_runtime_setup_stat_profiler (void);
  void mono_runtime_shutdown_stat_profiler (void);