From 22e58b11a7c3b44c16a5537b9ebfd9f621fb7537 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Wed, 19 Feb 2020 10:11:05 -0600 Subject: [PATCH] mscoree: Remove appdomain tracking. This didn't work correctly with multiple runtime versions. We should rely on Mono to keep track of AppDomains. Signed-off-by: Vincent Povirk Signed-off-by: Alexandre Julliard --- dlls/mscoree/corruntimehost.c | 73 ++++------------------------------ dlls/mscoree/metahost.c | 22 ++++++++++ dlls/mscoree/mscoree_private.h | 4 +- 3 files changed, 31 insertions(+), 68 deletions(-) diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c index a900ed6a3e2..a8fc2674ace 100644 --- a/dlls/mscoree/corruntimehost.c +++ b/dlls/mscoree/corruntimehost.c @@ -127,54 +127,19 @@ static void domain_restore(MonoDomain *prev_domain) mono_domain_set(prev_domain, FALSE); } -static HRESULT RuntimeHost_AddDefaultDomain(RuntimeHost *This, MonoDomain **result) -{ - struct DomainEntry *entry; - HRESULT res=S_OK; - - EnterCriticalSection(&This->lock); - - entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry)); - if (!entry) - { - res = E_OUTOFMEMORY; - goto end; - } - - /* FIXME: Use exe filename to name the domain? */ - entry->domain = mono_jit_init_version("mscorlib.dll", "v4.0.30319"); - - if (!entry->domain) - { - HeapFree(GetProcessHeap(), 0, entry); - res = E_FAIL; - goto end; - } - - is_mono_started = TRUE; - - list_add_tail(&This->domains, &entry->entry); - - *result = entry->domain; - -end: - LeaveCriticalSection(&This->lock); - - return res; -} - static HRESULT RuntimeHost_GetDefaultDomain(RuntimeHost *This, const WCHAR *config_path, MonoDomain **result) { WCHAR config_dir[MAX_PATH]; WCHAR base_dir[MAX_PATH]; char *base_dirA, *config_pathA, *slash; HRESULT res=S_OK; + static BOOL configured_domain; + + *result = get_root_domain(); EnterCriticalSection(&This->lock); - if (This->default_domain) goto end; - - res = RuntimeHost_AddDefaultDomain(This, &This->default_domain); + if (configured_domain) goto end; if (!config_path) { @@ -213,40 +178,20 @@ static HRESULT RuntimeHost_GetDefaultDomain(RuntimeHost *This, const WCHAR *conf *(slash + 1) = 0; TRACE("setting base_dir: %s, config_path: %s\n", base_dirA, config_pathA); - mono_domain_set_config(This->default_domain, base_dirA, config_pathA); + mono_domain_set_config(*result, base_dirA, config_pathA); HeapFree(GetProcessHeap(), 0, config_pathA); HeapFree(GetProcessHeap(), 0, base_dirA); end: - *result = This->default_domain; + + configured_domain = TRUE; LeaveCriticalSection(&This->lock); return res; } -static void RuntimeHost_DeleteDomain(RuntimeHost *This, MonoDomain *domain) -{ - struct DomainEntry *entry; - - EnterCriticalSection(&This->lock); - - LIST_FOR_EACH_ENTRY(entry, &This->domains, struct DomainEntry, entry) - { - if (entry->domain == domain) - { - list_remove(&entry->entry); - if (This->default_domain == domain) - This->default_domain = NULL; - HeapFree(GetProcessHeap(), 0, entry); - break; - } - } - - LeaveCriticalSection(&This->lock); -} - static BOOL RuntimeHost_GetMethod(MonoDomain *domain, const char *assemblyname, const char *namespace, const char *typename, const char *methodname, int arg_count, MonoMethod **method) @@ -1529,8 +1474,6 @@ __int32 WINAPI _CorExeMain(void) ERR("couldn't load %s, status=%d\n", debugstr_w(filename), status); exit_code = -1; } - - RuntimeHost_DeleteDomain(host, domain); } else exit_code = -1; @@ -1616,8 +1559,6 @@ HRESULT RuntimeHost_Construct(CLRRuntimeInfo *runtime_version, RuntimeHost** res This->ref = 1; This->version = runtime_version; - list_init(&This->domains); - This->default_domain = NULL; InitializeCriticalSection(&This->lock); This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": RuntimeHost.lock"); diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c index 4c1e4e97c1e..3786f3afc5c 100644 --- a/dlls/mscoree/metahost.c +++ b/dlls/mscoree/metahost.c @@ -298,6 +298,28 @@ fail: return E_FAIL; } +MonoDomain* get_root_domain(void) +{ + static MonoDomain* root_domain; + + if (root_domain != NULL) + return root_domain; + + EnterCriticalSection(&runtime_list_cs); + + if (root_domain == NULL) + { + /* FIXME: Use exe filename to name the domain? */ + root_domain = mono_jit_init_version("mscorlib.dll", "v4.0.30319"); + + is_mono_started = TRUE; + } + + LeaveCriticalSection(&runtime_list_cs); + + return root_domain; +} + static void CDECL mono_shutdown_callback_fn(MonoProfiler *prof) { is_mono_shutdown = TRUE; diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h index d5f78b61f0b..5b6c3987615 100644 --- a/dlls/mscoree/mscoree_private.h +++ b/dlls/mscoree/mscoree_private.h @@ -76,8 +76,6 @@ struct RuntimeHost ICorRuntimeHost ICorRuntimeHost_iface; ICLRRuntimeHost ICLRRuntimeHost_iface; CLRRuntimeInfo *version; - struct list domains; - MonoDomain *default_domain; CRITICAL_SECTION lock; LONG ref; }; @@ -110,6 +108,8 @@ extern HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config extern BOOL get_mono_path(LPWSTR path, BOOL skip_local) DECLSPEC_HIDDEN; +extern MonoDomain* get_root_domain(void); + extern HRESULT ICLRRuntimeInfo_GetRuntimeHost(ICLRRuntimeInfo *iface, RuntimeHost **result) DECLSPEC_HIDDEN; extern HRESULT MetaDataDispenser_CreateInstance(IUnknown **ppUnk) DECLSPEC_HIDDEN;