mscoree: Call Mono's System.Environment.Exit instead of duplicating it.

This commit is contained in:
Vincent Povirk 2013-10-24 16:01:11 -05:00 committed by Alexandre Julliard
parent 770918a91b
commit 5e81bad239
4 changed files with 73 additions and 45 deletions

View file

@ -214,6 +214,60 @@ static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *d
return hr;
}
void RuntimeHost_ExitProcess(RuntimeHost *This, INT exitcode)
{
HRESULT hr;
void *args[2];
MonoDomain *domain;
MonoAssembly *assembly;
MonoImage *image;
MonoClass *klass;
MonoMethod *method;
hr = RuntimeHost_GetDefaultDomain(This, &domain);
if (FAILED(hr))
{
ERR("Cannot get domain, hr=%x\n", hr);
return;
}
mono_thread_attach(domain);
assembly = mono_domain_assembly_open(domain, "mscorlib");
if (!assembly)
{
ERR("Cannot load mscorlib\n");
return;
}
image = mono_assembly_get_image(assembly);
if (!image)
{
ERR("Couldn't get assembly image\n");
return;
}
klass = mono_class_from_name(image, "System", "Environment");
if (!klass)
{
ERR("Couldn't get class from image\n");
return;
}
method = mono_class_get_method_from_name(klass, "Exit", 0);
if (!method)
{
ERR("Couldn't get method from class\n");
return;
}
args[0] = &exitcode;
args[1] = NULL;
mono_runtime_invoke(method, NULL, args, NULL);
ERR("Process should have exited\n");
}
static inline RuntimeHost *impl_from_ICLRRuntimeHost( ICLRRuntimeHost *iface )
{
return CONTAINING_RECORD(iface, RuntimeHost, ICLRRuntimeHost_iface);

View file

@ -100,17 +100,12 @@ 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);
static void (CDECL *mono_runtime_quit)(void);
static void (CDECL *mono_runtime_set_shutting_down)(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);
static char* (CDECL *mono_stringify_assembly_name)(MonoAssemblyName *aname);
MonoThread* (CDECL *mono_thread_attach)(MonoDomain *domain);
void (CDECL *mono_thread_manage)(void);
static void (CDECL *mono_thread_pool_cleanup)(void);
static void (CDECL *mono_thread_suspend_all_other_threads)(void);
static void (CDECL *mono_threads_set_shutting_down)(void);
void (CDECL *mono_trace_set_assembly)(MonoAssembly *assembly);
static BOOL find_mono_dll(LPCWSTR path, LPWSTR dll_path);
@ -134,10 +129,6 @@ static void set_environment(LPCWSTR bin_path)
SetEnvironmentVariableW(pathW, path_env);
}
static void CDECL do_nothing(void)
{
}
static MonoImage* CDECL image_open_module_handle_dummy(HMODULE module_handle,
char* fname, UINT has_entry_point, MonoImageOpenStatus* status)
{
@ -218,7 +209,6 @@ static HRESULT load_mono(CLRRuntimeInfo *This)
LOAD_MONO_FUNCTION(mono_reflection_type_from_name);
LOAD_MONO_FUNCTION(mono_runtime_invoke);
LOAD_MONO_FUNCTION(mono_runtime_object_init);
LOAD_MONO_FUNCTION(mono_runtime_quit);
LOAD_MONO_FUNCTION(mono_set_dirs);
LOAD_MONO_FUNCTION(mono_set_verbose_level);
LOAD_MONO_FUNCTION(mono_stringify_assembly_name);
@ -237,10 +227,6 @@ static HRESULT load_mono(CLRRuntimeInfo *This)
} while (0);
LOAD_OPT_MONO_FUNCTION(mono_image_open_from_module_handle, image_open_module_handle_dummy);
LOAD_OPT_MONO_FUNCTION(mono_runtime_set_shutting_down, do_nothing);
LOAD_OPT_MONO_FUNCTION(mono_thread_pool_cleanup, do_nothing);
LOAD_OPT_MONO_FUNCTION(mono_thread_suspend_all_other_threads, do_nothing);
LOAD_OPT_MONO_FUNCTION(mono_threads_set_shutting_down, do_nothing);
#undef LOAD_OPT_MONO_FUNCTION
@ -306,31 +292,6 @@ static HRESULT CLRRuntimeInfo_GetRuntimeHost(CLRRuntimeInfo *This, RuntimeHost *
return hr;
}
void unload_all_runtimes(void)
{
int i;
HMODULE handle;
/* If the only references to mscoree are through dll's that were loaded by
* Mono, shutting down the Mono runtime will free mscoree, so take a
* reference to prevent that from happening. */
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR *)unload_all_runtimes, &handle);
if (mono_handle && is_mono_started && !is_mono_shutdown)
{
/* Copied from Mono's ves_icall_System_Environment_Exit */
mono_threads_set_shutting_down();
mono_runtime_set_shutting_down();
mono_thread_pool_cleanup();
mono_thread_suspend_all_other_threads();
mono_runtime_quit();
}
for (i=0; i<NUM_RUNTIMES; i++)
if (runtimes[i].loaded_runtime)
RuntimeHost_Destroy(runtimes[i].loaded_runtime);
}
void expect_no_runtimes(void)
{
if (mono_handle && is_mono_started && !is_mono_shutdown)
@ -1147,9 +1108,21 @@ static HRESULT WINAPI CLRMetaHost_QueryLegacyV2RuntimeBinding(ICLRMetaHost* ifac
return E_NOTIMPL;
}
static HRESULT WINAPI CLRMetaHost_ExitProcess(ICLRMetaHost* iface, INT32 iExitCode)
HRESULT WINAPI CLRMetaHost_ExitProcess(ICLRMetaHost* iface, INT32 iExitCode)
{
FIXME("%i: stub\n", iExitCode);
TRACE("%i\n", iExitCode);
EnterCriticalSection(&runtime_list_cs);
if (is_mono_started && !is_mono_shutdown)
{
/* search for a runtime and call System.Environment.Exit() */
int i;
for (i=0; i<NUM_RUNTIMES; i++)
if (runtimes[i].loaded_runtime)
RuntimeHost_ExitProcess(runtimes[i].loaded_runtime, iExitCode);
}
ExitProcess(iExitCode);
}

View file

@ -249,8 +249,7 @@ __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName,
void WINAPI CorExitProcess(int exitCode)
{
TRACE("(%x)\n", exitCode);
unload_all_runtimes();
ExitProcess(exitCode);
CLRMetaHost_ExitProcess(0, exitCode);
}
VOID WINAPI _CorImageUnloading(PVOID imageBase)

View file

@ -162,12 +162,12 @@ extern void (CDECL *mono_thread_manage)(void);
extern void (CDECL *mono_trace_set_assembly)(MonoAssembly *assembly);
/* loaded runtime interfaces */
extern void unload_all_runtimes(void) DECLSPEC_HIDDEN;
extern void expect_no_runtimes(void) DECLSPEC_HIDDEN;
extern HRESULT RuntimeHost_Construct(const CLRRuntimeInfo *runtime_version, RuntimeHost** result) DECLSPEC_HIDDEN;
extern void RuntimeHost_ExitProcess(RuntimeHost *This, INT exitcode) DECLSPEC_HIDDEN;
extern HRESULT RuntimeHost_GetInterface(RuntimeHost *This, REFCLSID clsid, REFIID riid, void **ppv) DECLSPEC_HIDDEN;
extern HRESULT RuntimeHost_GetIUnknownForObject(RuntimeHost *This, MonoObject *obj, IUnknown **ppUnk) DECLSPEC_HIDDEN;
@ -177,6 +177,8 @@ extern HRESULT RuntimeHost_CreateManagedInstance(RuntimeHost *This, LPCWSTR name
extern HRESULT RuntimeHost_Destroy(RuntimeHost *This) DECLSPEC_HIDDEN;
HRESULT WINAPI CLRMetaHost_ExitProcess(ICLRMetaHost* iface, INT32 iExitCode) DECLSPEC_HIDDEN;
HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface, LPCWSTR pwzVersion, REFIID iid, LPVOID *ppRuntime) DECLSPEC_HIDDEN;
extern HRESULT CorDebug_Create(ICLRRuntimeHost *runtimehost, IUnknown** ppUnk) DECLSPEC_HIDDEN;