This patch mostly reverts 666d37829304e85f72969c44e92bc11ca167a272,
which put Mono's mixed-mode support in #ifdef ENABLE_COREE, disabling
it by default on Windows.

It was disabled because it broke the verifier, and it still does.

Since most of the new behavior is dependent on whether coree has been
hooked, or whether a particular image has been loaded using the OS
loader, skipping the hook step effectively disables coree at runtime.
So this patch moves that step out of mono_init_internal and into
mono_main, where it is dependent on a runtime switch.

Even if this didn't break the verifier, I think it's an intrusive,
hacky change to how Mono loads things that almost no one needs, and so
having it default off makes sense. Also, (my real motive) it's a step
towards my goal of getting Wine's builtin mscoree.dll to use Mono's
mixed-mode support without indirectly causing itself to be hooked.
From 1a6218abd8a3bec45d09cb2ff3b1404eb0ffa8f2 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vinc...@codeweavers.com>
Date: Mon, 7 Mar 2011 13:41:46 -0600
Subject: [PATCH] Replace ENABLE_COREE with a runtime switch.

---
 mono/metadata/assembly.c |    2 +-
 mono/metadata/coree.c    |    7 -------
 mono/metadata/domain.c   |    5 +----
 mono/metadata/image.c    |   26 +++++++++++++-------------
 mono/mini/driver.c       |   17 +++++++++++++++--
 5 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/mono/metadata/assembly.c b/mono/metadata/assembly.c
index cc9e980..621e450 100644
--- a/mono/metadata/assembly.c
+++ b/mono/metadata/assembly.c
@@ -1634,7 +1634,7 @@ mono_assembly_load_from_full (MonoImage *image, const 
char*fname,
        loaded_assemblies = g_list_prepend (loaded_assemblies, ass);
        mono_assemblies_unlock ();
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        if (image->is_module_handle)
                mono_image_fixup_vtable (image);
 #endif
diff --git a/mono/metadata/coree.c b/mono/metadata/coree.c
index c31dfaf..9e48a3f 100644
--- a/mono/metadata/coree.c
+++ b/mono/metadata/coree.c
@@ -33,14 +33,10 @@
 #include "environment.h"
 #include "coree.h"
 
-#ifdef ENABLE_COREE
-
 HMODULE coree_module_handle = NULL;
 
 static gboolean init_from_coree = FALSE;
 
-#endif
-
 gchar*
 mono_get_module_file_name (HMODULE module_handle)
 {
@@ -73,7 +69,6 @@ mono_get_module_file_name (HMODULE module_handle)
        return file_name_utf8;
 }
 
-#ifdef ENABLE_COREE
 /* Entry point called by LdrLoadDll of ntdll.dll after _CorValidateImage. */
 BOOL STDMETHODCALLTYPE _CorDllMain(HINSTANCE hInst, DWORD dwReason, LPVOID 
lpReserved)
 {
@@ -928,6 +923,4 @@ mono_fixup_exe_image (MonoImage* image)
                MonoFixupExe ((HMODULE) image->raw_data);
 }
 
-#endif /* ENABLE_COREE */
-
 #endif /* HOST_WIN32 */
diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c
index 8e001df..cbeef36 100644
--- a/mono/metadata/domain.c
+++ b/mono/metadata/domain.c
@@ -1271,9 +1271,6 @@ mono_init_internal (const char *filename, const char 
*exe_filename, const char *
 #ifdef HOST_WIN32
        /* Avoid system error message boxes. */
        SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
-#ifdef ENABLE_COREE
-       mono_load_coree (exe_filename);
-#endif
 #endif
 
        mono_perfcounters_init ();
@@ -1312,7 +1309,7 @@ mono_init_internal (const char *filename, const char 
*exe_filename, const char *
                 * exe_image, and close it during shutdown.
                 */
                get_runtimes_from_exe (exe_filename, &exe_image, runtimes);
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
                if (!exe_image) {
                        exe_image = mono_assembly_open_from_bundle 
(exe_filename, NULL, FALSE);
                        if (!exe_image)
diff --git a/mono/metadata/image.c b/mono/metadata/image.c
index 5d098a0..ef904da 100644
--- a/mono/metadata/image.c
+++ b/mono/metadata/image.c
@@ -121,7 +121,7 @@ mono_cli_rva_image_map (MonoImage *image, guint32 addr)
        for (i = 0; i < top; i++){
                if ((addr >= tables->st_virtual_address) &&
                    (addr < tables->st_virtual_address + 
tables->st_raw_data_size)){
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
                        if (image->is_module_handle)
                                return addr;
 #endif
@@ -158,7 +158,7 @@ mono_image_rva_map (MonoImage *image, guint32 addr)
                                if (!mono_image_ensure_section_idx (image, i))
                                        return NULL;
                        }
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
                        if (image->is_module_handle)
                                return image->raw_data + addr;
 #endif
@@ -239,7 +239,7 @@ mono_image_ensure_section_idx (MonoImage *image, int 
section)
 
        if (sect->st_raw_data_ptr + sect->st_raw_data_size > 
image->raw_data_len)
                return FALSE;
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        if (image->is_module_handle)
                iinfo->cli_sections [section] = image->raw_data + 
sect->st_virtual_address;
        else
@@ -628,7 +628,7 @@ mono_image_load_module (MonoImage *image, int idx)
                        if (image->modules [idx - 1]) {
                                mono_image_addref (image->modules [idx - 1]);
                                image->modules [idx - 1]->assembly = 
image->assembly;
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
                                if (image->modules [idx - 1]->is_module_handle)
                                        mono_image_fixup_vtable (image->modules 
[idx - 1]);
 #endif
@@ -702,7 +702,7 @@ do_load_header (MonoImage *image, MonoDotNetHeader *header, 
int offset)
 {
        MonoDotNetHeader64 header64;
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        if (!image->is_module_handle)
 #endif
        if (offset + sizeof (MonoDotNetHeader32) > image->raw_data_len)
@@ -823,7 +823,7 @@ do_load_header (MonoImage *image, MonoDotNetHeader *header, 
int offset)
        SWAPPDE (header->datadir.pe_cli_header);
        SWAPPDE (header->datadir.pe_reserved);
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        if (image->is_module_handle)
                image->raw_data_len = header->nt.pe_image_size;
 #endif
@@ -842,7 +842,7 @@ mono_image_load_pe_data (MonoImage *image)
        iinfo = image->image_info;
        header = &iinfo->cli_header;
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        if (!image->is_module_handle)
 #endif
        if (offset + sizeof (msdos) > image->raw_data_len)
@@ -1178,7 +1178,7 @@ mono_image_open_from_data (char *data, guint32 data_len, 
gboolean need_copy, Mon
        return mono_image_open_from_data_full (data, data_len, need_copy, 
status, FALSE);
 }
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
 /* fname is not duplicated. */
 MonoImage*
 mono_image_open_from_module_handle (HMODULE module_handle, char* fname, 
gboolean has_entry_point, MonoImageOpenStatus* status)
@@ -1212,7 +1212,7 @@ mono_image_open_full (const char *fname, 
MonoImageOpenStatus *status, gboolean r
        
        g_return_val_if_fail (fname != NULL, NULL);
        
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        /* Load modules using LoadLibrary. */
        if (!refonly && coree_module_handle) {
                HMODULE module_handle;
@@ -1364,7 +1364,7 @@ mono_image_open_raw (const char *fname, 
MonoImageOpenStatus *status)
 void
 mono_image_fixup_vtable (MonoImage *image)
 {
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        MonoCLIImageInfo *iinfo;
        MonoPEDirEntry *de;
        MonoVTableFixup *vtfixup;
@@ -1502,7 +1502,7 @@ mono_image_close_except_pools (MonoImage *image)
 
        mono_images_unlock ();
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        if (image->is_module_handle && image->has_entry_point) {
                mono_images_lock ();
                if (image->ref_count == 0) {
@@ -1545,7 +1545,7 @@ mono_image_close_except_pools (MonoImage *image)
                }
        }
 
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
        mono_images_lock ();
        if (image->is_module_handle && !image->has_entry_point)
                FreeLibrary ((HMODULE) image->raw_data);
@@ -2000,7 +2000,7 @@ mono_image_load_file_for_image (MonoImage *image, int 
fileidx)
                }
 
                image->files [fileidx - 1] = res;
-#ifdef ENABLE_COREE
+#ifdef HOST_WIN32
                if (res->is_module_handle)
                        mono_image_fixup_vtable (res);
 #endif
diff --git a/mono/mini/driver.c b/mono/mini/driver.c
index 58b37a3..6da8ea0 100644
--- a/mono/mini/driver.c
+++ b/mono/mini/driver.c
@@ -1143,6 +1143,9 @@ mini_usage (void)
                "                           Currently the only supported option 
is 'disable'.\n"
                "    --llvm, --nollvm       Controls whenever the runtime uses 
LLVM to compile code.\n"
                "    --gc=[sgen,boehm]      Select SGen or Boehm GC (runs mono 
or mono-sgen)\n"
+#ifdef HOST_WIN32
+               "    --mixed-mode           Enable mixed-mode image support.\n"
+#endif
          );
 }
 
@@ -1248,10 +1251,8 @@ BOOL APIENTRY DllMain (HMODULE module_handle, DWORD 
reason, LPVOID reserved)
                mono_install_runtime_load (mini_init);
                break;
        case DLL_PROCESS_DETACH:
-#ifdef ENABLE_COREE
                if (coree_module_handle)
                        FreeLibrary (coree_module_handle);
-#endif
                break;
        }
        return TRUE;
@@ -1343,6 +1344,9 @@ mono_main (int argc, char* argv[])
 #ifdef MONO_JIT_INFO_TABLE_TEST
        int test_jit_info_table = FALSE;
 #endif
+#ifdef HOST_WIN32
+       int mixed_mode = FALSE;
+#endif
 
 #ifdef MOONLIGHT
 #ifndef HOST_WIN32
@@ -1471,6 +1475,10 @@ mono_main (int argc, char* argv[])
                                return 1;
                        }
                        config_file = argv [++i];
+#ifdef HOST_WIN32
+               } else if (strcmp (argv [i], "--mixed-mode") == 0) {
+                       mixed_mode = TRUE;
+#endif
                } else if (strcmp (argv [i], "--ncompile") == 0) {
                        if (i + 1 >= argc){
                                fprintf (stderr, "error: --ncompile requires an 
argument\n");
@@ -1735,6 +1743,11 @@ mono_main (int argc, char* argv[])
        }
 #endif
 
+#ifdef HOST_WIN32
+       if (mixed_mode)
+               mono_load_coree (argv [i]);
+#endif
+
        mono_set_defaults (mini_verbose, opt);
        domain = mini_init (argv [i], forced_version);
 
-- 
1.7.1

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to