[PATCH 2/2] mscoree: Implement ICorRuntimeHost::CreateDomain{, Ex}(). (try 4)

Charles Davis cdavis5x at gmail.com
Tue Feb 16 01:03:59 CST 2016


Try 4:
* Gut test. :\ (So it doesn't work on Wine64... dang.) It was broken anyhow. I forgot in try 3 to actually call it. ;)
* Fix a small typo ("get_ID" -> "get_Id") with big consequences. (Well, my test appeared to work at first, so I thought I was golden!)

Signed-off-by: Charles Davis <cdavis5x at gmail.com>
---
 dlls/mscoree/corruntimehost.c  | 130 +++++++++++++++++++++++++++++++++++++++--
 dlls/mscoree/metahost.c        |   2 +
 dlls/mscoree/mscoree_private.h |   1 +
 3 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index 820d786..ff1adb4 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -68,7 +68,7 @@ struct dll_fixup
     void *tokens; /* pointer into process heap */
 };
 
-static HRESULT RuntimeHost_AddDomain(RuntimeHost *This, MonoDomain **result)
+static HRESULT RuntimeHost_AddDefaultDomain(RuntimeHost *This, MonoDomain **result)
 {
     struct DomainEntry *entry;
     HRESULT res=S_OK;
@@ -115,7 +115,7 @@ static HRESULT RuntimeHost_GetDefaultDomain(RuntimeHost *This, const WCHAR *conf
 
     if (This->default_domain) goto end;
 
-    res = RuntimeHost_AddDomain(This, &This->default_domain);
+    res = RuntimeHost_AddDefaultDomain(This, &This->default_domain);
 
     if (!config_path)
     {
@@ -257,6 +257,104 @@ static HRESULT RuntimeHost_Invoke(RuntimeHost *This, MonoDomain *domain,
     return S_OK;
 }
 
+static HRESULT RuntimeHost_GetObjectForIUnknown(RuntimeHost *This, MonoDomain *domain,
+    IUnknown *unk, MonoObject **obj)
+{
+    HRESULT hr;
+    void *args[1];
+    MonoObject *result;
+
+    args[0] = &unk;
+    hr = RuntimeHost_Invoke(This, domain, "mscorlib", "System.Runtime.InteropServices", "Marshal", "GetObjectForIUnknown",
+        NULL, args, 1, &result);
+
+    if (SUCCEEDED(hr))
+    {
+        *obj = result;
+    }
+    return hr;
+}
+
+static HRESULT RuntimeHost_AddDomain(RuntimeHost *This, const WCHAR *name, IUnknown *setup,
+    IUnknown *evidence, MonoDomain **result)
+{
+    HRESULT res;
+    char *nameA;
+    MonoDomain *domain;
+    void *args[3];
+    MonoObject *new_domain, *id;
+
+    res = RuntimeHost_GetDefaultDomain(This, NULL, &domain);
+    if (FAILED(res))
+    {
+        return res;
+    }
+
+    nameA = WtoA(name);
+    if (!nameA)
+    {
+        return E_OUTOFMEMORY;
+    }
+
+    args[0] = mono_string_new(domain, nameA);
+    HeapFree(GetProcessHeap(), 0, nameA);
+
+    if (!args[0])
+    {
+        return E_OUTOFMEMORY;
+    }
+
+    if (evidence)
+    {
+        res = RuntimeHost_GetObjectForIUnknown(This, domain, evidence, (MonoObject **)&args[1]);
+        if (FAILED(res))
+        {
+            return res;
+        }
+    }
+    else
+    {
+        args[1] = NULL;
+    }
+
+    if (setup)
+    {
+        res = RuntimeHost_GetObjectForIUnknown(This, domain, setup, (MonoObject **)&args[2]);
+        if (FAILED(res))
+        {
+            return res;
+        }
+    }
+    else
+    {
+        args[2] = NULL;
+    }
+
+    res = RuntimeHost_Invoke(This, domain, "mscorlib", "System", "AppDomain", "CreateDomain",
+        NULL, args, 3, &new_domain);
+
+    if (FAILED(res))
+    {
+        return res;
+    }
+
+    /* new_domain is not the AppDomain itself, but a transparent proxy.
+     * So, we'll retrieve its ID, and use that to get the real domain object.
+     */
+
+    res = RuntimeHost_Invoke(This, domain, "mscorlib", "System", "AppDomain", "get_Id",
+        new_domain, NULL, 0, &id);
+
+    if (FAILED(res))
+    {
+        return res;
+    }
+
+    *result = mono_domain_get_by_id(*(int32_t *)mono_object_unbox(id));
+
+    return S_OK;
+}
+
 static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *domain, IUnknown **punk)
 {
     HRESULT hr;
@@ -432,8 +530,7 @@ static HRESULT WINAPI corruntimehost_CreateDomain(
     IUnknown *identityArray,
     IUnknown **appDomain)
 {
-    FIXME("stub %p\n", iface);
-    return E_NOTIMPL;
+    return ICorRuntimeHost_CreateDomainEx(iface, friendlyName, NULL, NULL, appDomain);
 }
 
 static HRESULT WINAPI corruntimehost_GetDefaultDomain(
@@ -488,8 +585,29 @@ static HRESULT WINAPI corruntimehost_CreateDomainEx(
     IUnknown *evidence,
     IUnknown **appDomain)
 {
-    FIXME("stub %p\n", iface);
-    return E_NOTIMPL;
+    RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
+    HRESULT hr;
+    MonoDomain *domain;
+
+    if (!friendlyName || !appDomain)
+    {
+        return E_POINTER;
+    }
+    if (!is_mono_started)
+    {
+        return E_FAIL;
+    }
+
+    TRACE("(%p)\n", iface);
+
+    hr = RuntimeHost_AddDomain(This, friendlyName, setup, evidence, &domain);
+
+    if (SUCCEEDED(hr))
+    {
+        hr = RuntimeHost_GetIUnknownForDomain(This, domain, appDomain);
+    }
+
+    return hr;
 }
 
 static HRESULT WINAPI corruntimehost_CreateDomainSetup(
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index 3d663f1..676b92c 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -79,6 +79,7 @@ MonoClass* (CDECL *mono_class_from_name)(MonoImage *image, const char* name_spac
 MonoMethod* (CDECL *mono_class_get_method_from_name)(MonoClass *klass, const char *name, int param_count);
 static void (CDECL *mono_config_parse)(const char *filename);
 MonoAssembly* (CDECL *mono_domain_assembly_open)(MonoDomain *domain, const char *name);
+MonoDomain* (CDECL *mono_domain_get_by_id)(int32_t id);
 void (CDECL *mono_domain_set_config)(MonoDomain *domain,const char *base_dir,const char *config_file_name);
 static void (CDECL *mono_free)(void *);
 static MonoImage* (CDECL *mono_image_open)(const char *fname, MonoImageOpenStatus *status);
@@ -175,6 +176,7 @@ static HRESULT load_mono(LPCWSTR mono_path)
         LOAD_MONO_FUNCTION(mono_class_from_name);
         LOAD_MONO_FUNCTION(mono_class_get_method_from_name);
         LOAD_MONO_FUNCTION(mono_domain_assembly_open);
+        LOAD_MONO_FUNCTION(mono_domain_get_by_id);
         LOAD_MONO_FUNCTION(mono_domain_set_config);
         LOAD_MONO_FUNCTION(mono_free);
         LOAD_MONO_FUNCTION(mono_image_open);
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index 8226463..f236141 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -146,6 +146,7 @@ extern MonoClass* (CDECL *mono_class_from_mono_type)(MonoType *type) DECLSPEC_HI
 extern MonoClass* (CDECL *mono_class_from_name)(MonoImage *image, const char* name_space, const char *name) DECLSPEC_HIDDEN;
 extern MonoMethod* (CDECL *mono_class_get_method_from_name)(MonoClass *klass, const char *name, int param_count) DECLSPEC_HIDDEN;
 extern MonoAssembly* (CDECL *mono_domain_assembly_open)(MonoDomain *domain, const char *name) DECLSPEC_HIDDEN;
+extern MonoDomain* (CDECL *mono_domain_get_by_id)(int32_t id);
 extern void (CDECL *mono_domain_set_config)(MonoDomain *domain,const char *base_dir,const char *config_file_name) DECLSPEC_HIDDEN;
 extern int (CDECL *mono_jit_exec)(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]) DECLSPEC_HIDDEN;
 extern MonoDomain* (CDECL *mono_jit_init_version)(const char *domain_name, const char *runtime_version) DECLSPEC_HIDDEN;
-- 
2.7.1




More information about the wine-patches mailing list