mscoree: Use mono_runtime_quit in shutdown process.

Vincent Povirk madewokherd at
Wed Oct 15 16:47:52 CDT 2014

mono_jit_cleanup was changed recently in Mono, it now calls
mono_thread_manage before shutting down the runtime. This was to fix
users of the embedded api that didn't know they needed to call
mono_thread_manage (probably because there's no mention of it on, but Wine was
doing this so the change broke Wine.

We can't remove the mono_thread_manage call because that would break
Wine with earlier versions of Mono.

The solution is to avoid mono_jit_cleanup and use mono_runtime_quit,
which until recently behaved identically, and now works the way
mono_jit_cleanup used to. This (or sometimes mini_cleanup which isn't
exported by the dll) is the function used internally for shutting down
the runtime, which in some cases needs to not call mono_thread_manage
at all, so *hopefully* they won't break this one. (mono_jit_cleanup
isn't called at all in the Mono source code.)
-------------- next part --------------
From d3d624d84e0b82901a0c46f3b689f483f9939b17 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at>
Date: Wed, 15 Oct 2014 16:26:09 -0500
Subject: [PATCH] mscoree: Use mono_runtime_quit in shutdown process.

 dlls/mscoree/corruntimehost.c  | 2 +-
 dlls/mscoree/metahost.c        | 4 ++--
 dlls/mscoree/mscoree_private.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index ce73134..6a037f8 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -1124,7 +1124,7 @@ __int32 WINAPI _CorExeMain(void)
     if (domain)
-        mono_jit_cleanup(domain);
+        mono_runtime_quit();
     return exit_code;
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index 2383068..f0ec778 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -88,7 +88,6 @@ static void (CDECL *mono_free)(void *);
 static MonoImage* (CDECL *mono_image_open)(const char *fname, MonoImageOpenStatus *status);
 MonoImage* (CDECL *mono_image_open_from_module_handle)(HMODULE module_handle, char* fname, UINT has_entry_point, MonoImageOpenStatus* status);
 static void (CDECL *mono_install_assembly_preload_hook)(MonoAssemblyPreLoadFunc func, void *user_data);
-void (CDECL *mono_jit_cleanup)(MonoDomain *domain);
 int (CDECL *mono_jit_exec)(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]);
 MonoDomain* (CDECL *mono_jit_init)(const char *file);
 static int (CDECL *mono_jit_set_trace_options)(const char* options);
@@ -100,6 +99,7 @@ static void (CDECL *mono_profiler_install)(MonoProfiler *prof, MonoProfileFunc s
 MonoType* (CDECL *mono_reflection_type_from_name)(char *name, MonoImage *image);
 MonoObject* (CDECL *mono_runtime_invoke)(MonoMethod *method, void *obj, void **params, MonoObject **exc);
 void (CDECL *mono_runtime_object_init)(MonoObject *this_obj);
+void (CDECL *mono_runtime_quit)(void);
 static void (CDECL *mono_set_dirs)(const char *assembly_dir, const char *config_dir);
 static void (CDECL *mono_set_verbose_level)(DWORD level);
 MonoString* (CDECL *mono_string_new)(MonoDomain *domain, const char *str);
@@ -197,7 +197,6 @@ static HRESULT load_mono(CLRRuntimeInfo *This)
-        LOAD_MONO_FUNCTION(mono_jit_cleanup);
@@ -209,6 +208,7 @@ static HRESULT load_mono(CLRRuntimeInfo *This)
+        LOAD_MONO_FUNCTION(mono_runtime_quit);
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index a451344..af329f8 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -145,7 +145,6 @@ extern MonoClass* (CDECL *mono_class_from_mono_type)(MonoType *type);
 extern MonoClass* (CDECL *mono_class_from_name)(MonoImage *image, const char* name_space, const char *name);
 extern MonoMethod* (CDECL *mono_class_get_method_from_name)(MonoClass *klass, const char *name, int param_count);
 extern MonoAssembly* (CDECL *mono_domain_assembly_open)(MonoDomain *domain, const char *name);
-extern void (CDECL *mono_jit_cleanup)(MonoDomain *domain);
 extern int (CDECL *mono_jit_exec)(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]);
 extern MonoDomain* (CDECL *mono_jit_init)(const char *file);
 extern MonoImage* (CDECL *mono_image_open_from_module_handle)(HMODULE module_handle, char* fname, UINT has_entry_point, MonoImageOpenStatus* status);
@@ -156,6 +155,7 @@ extern void* (CDECL *mono_object_unbox)(MonoObject *obj);
 extern MonoType* (CDECL *mono_reflection_type_from_name)(char *name, MonoImage *image);
 extern MonoObject* (CDECL *mono_runtime_invoke)(MonoMethod *method, void *obj, void **params, MonoObject **exc);
 extern void (CDECL *mono_runtime_object_init)(MonoObject *this_obj);
+extern void (CDECL *mono_runtime_quit)(void);
 extern MonoString* (CDECL *mono_string_new)(MonoDomain *domain, const char *str);
 extern MonoThread* (CDECL *mono_thread_attach)(MonoDomain *domain);
 extern void (CDECL *mono_thread_manage)(void);

More information about the wine-patches mailing list