[PATCH] mscoree: Add support for config stream in GetRequestedRuntime.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] mscoree: Add support for config stream in GetRequestedRuntime.

Vincent Povirk (they/them)
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=37751
Signed-off-by: Vincent Povirk <[hidden email]>
---
 dlls/mscoree/config.c          | 27 +++++++++++++++++++--------
 dlls/mscoree/corruntimehost.c  |  6 +++---
 dlls/mscoree/metahost.c        | 21 ++++++++++++---------
 dlls/mscoree/mscoree_main.c    | 14 +++++++-------
 dlls/mscoree/mscoree_private.h |  5 ++++-
 5 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/dlls/mscoree/config.c b/dlls/mscoree/config.c
index a5c0666904..777195d85c 100644
--- a/dlls/mscoree/config.c
+++ b/dlls/mscoree/config.c
@@ -650,33 +650,44 @@ static HRESULT parse_config(VARIANT input, parsed_config_file *result)
     return S_OK;
 }
 
-HRESULT parse_config_file(LPCWSTR filename, parsed_config_file *result)
+HRESULT parse_config_stream(IStream *stream, parsed_config_file *result)
 {
-    IStream *stream;
     VARIANT var;
     HRESULT hr;
     HRESULT initresult;
 
     init_config(result);
 
-
-    hr = CreateConfigStream(filename, &stream);
-    if (FAILED(hr))
-        return hr;
-
     initresult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
     V_VT(&var) = VT_UNKNOWN;
     V_UNKNOWN(&var) = (IUnknown*)stream;
 
     hr = parse_config(var, result);
 
-    IStream_Release(stream);
     if (SUCCEEDED(initresult))
         CoUninitialize();
 
     return hr;
 }
 
+HRESULT parse_config_file(LPCWSTR filename, parsed_config_file *result)
+{
+    HRESULT hr;
+    IStream *stream;
+
+    init_config(result);
+
+    hr = CreateConfigStream(filename, &stream);
+    if (FAILED(hr))
+        return hr;
+
+    hr = parse_config_stream(stream, result);
+
+    IStream_Release(stream);
+
+    return hr;
+}
+
 void free_parsed_config_file(parsed_config_file *file)
 {
     supported_runtime *cursor, *cursor2;
diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index f6c77be4aa..ca8ba0dc01 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -1296,7 +1296,7 @@ static void CDECL ReallyFixupVTable(struct dll_fixup *fixup)
         hr = E_OUTOFMEMORY;
 
     if (SUCCEEDED(hr))
-        hr = get_runtime_info(filename, NULL, NULL, 0, 0, FALSE, &info);
+        hr = get_runtime_info(filename, NULL, NULL, NULL, 0, 0, FALSE, &info);
 
     if (SUCCEEDED(hr))
         hr = ICLRRuntimeInfo_GetRuntimeHost(info, &host);
@@ -1469,7 +1469,7 @@ __int32 WINAPI _CorExeMain(void)
 
     FixupVTable(GetModuleHandleW(NULL));
 
-    hr = get_runtime_info(filename, NULL, NULL, 0, 0, FALSE, &info);
+    hr = get_runtime_info(filename, NULL, NULL, NULL, 0, 0, FALSE, &info);
 
     if (SUCCEEDED(hr))
     {
@@ -1831,7 +1831,7 @@ HRESULT create_monodata(REFIID riid, LPVOID *ppObj )
     *ppObj = NULL;
 
 
-    hr = get_runtime_info(filename, NULL, NULL, 0, 0, FALSE, &info);
+    hr = get_runtime_info(filename, NULL, NULL, NULL, 0, 0, FALSE, &info);
     if (SUCCEEDED(hr))
     {
         hr = ICLRRuntimeInfo_GetRuntimeHost(info, &host);
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index 422ca3112b..b9f7637f05 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -1126,11 +1126,10 @@ static HRESULT WINAPI metahostpolicy_GetRequestedRuntime(ICLRMetaHostPolicy *ifa
         pwzVersion, pcchVersion, pwzImageVersion, pcchImageVersion, pdwConfigFlags,
         debugstr_guid(riid), ppRuntime);
 
-    if (pCfgStream)
-        FIXME("ignoring config file stream\n");
-
-    if (pdwConfigFlags)
+    if (pdwConfigFlags) {
         FIXME("ignoring config flags\n");
+        *pdwConfigFlags = 0;
+    }
 
     if(dwPolicyFlags & METAHOST_POLICY_USE_PROCESS_IMAGE_PATH)
     {
@@ -1145,7 +1144,7 @@ static HRESULT WINAPI metahostpolicy_GetRequestedRuntime(ICLRMetaHostPolicy *ifa
     if(dwPolicyFlags & METAHOST_POLICY_APPLY_UPGRADE_POLICY)
         flags |= RUNTIME_INFO_UPGRADE_VERSION;
 
-    hr = get_runtime_info(path, pwzImageVersion, NULL, 0, flags, FALSE, &result);
+    hr = get_runtime_info(path, pwzImageVersion, NULL, pCfgStream, 0, flags, FALSE, &result);
     if (SUCCEEDED(hr))
     {
         if (pwzImageVersion)
@@ -1276,7 +1275,8 @@ static MonoAssembly* CDECL mono_assembly_preload_hook_fn(MonoAssemblyName *aname
 }
 
 HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
-    DWORD startup_flags, DWORD runtimeinfo_flags, BOOL legacy, ICLRRuntimeInfo **result)
+    IStream *config_stream, DWORD startup_flags, DWORD runtimeinfo_flags,
+    BOOL legacy, ICLRRuntimeInfo **result)
 {
     static const WCHAR dotconfig[] = {'.','c','o','n','f','i','g',0};
     static const DWORD supported_startup_flags = 0;
@@ -1297,7 +1297,7 @@ HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
     if (exefile && !exefile[0])
         exefile = NULL;
 
-    if (exefile && !config_file)
+    if (exefile && !config_file && !config_stream)
     {
         strcpyW(local_config_file, exefile);
         strcatW(local_config_file, dotconfig);
@@ -1305,10 +1305,13 @@ HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
         config_file = local_config_file;
     }
 
-    if (config_file)
+    if (config_file || config_stream)
     {
         BOOL found = FALSE;
-        hr = parse_config_file(config_file, &parsed_config);
+        if (config_file)
+            hr = parse_config_file(config_file, &parsed_config);
+        else
+            hr = parse_config_stream(config_stream, &parsed_config);
 
         if (SUCCEEDED(hr))
         {
diff --git a/dlls/mscoree/mscoree_main.c b/dlls/mscoree/mscoree_main.c
index 785ecd0404..db5f42616b 100644
--- a/dlls/mscoree/mscoree_main.c
+++ b/dlls/mscoree/mscoree_main.c
@@ -205,7 +205,7 @@ HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor
 
     *ppv = NULL;
 
-    ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, startupFlags, 0, TRUE, &info);
+    ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, NULL, startupFlags, 0, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
@@ -274,7 +274,7 @@ HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwL
     if (!dwLength || !pbuffer)
         return E_POINTER;
 
-    ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
+    ret = get_runtime_info(NULL, NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
@@ -297,7 +297,7 @@ HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
     if (!dwLength || !pbuffer)
         return E_POINTER;
 
-    ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
+    ret = get_runtime_info(NULL, NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
@@ -336,7 +336,7 @@ HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWST
 
     if (!dwlength) dwlength = &length_dummy;
 
-    ret = get_runtime_info(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, TRUE, &info);
+    ret = get_runtime_info(pExe, pwszVersion, pConfigurationFile, NULL, startupFlags, runtimeInfoFlags, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
@@ -482,7 +482,7 @@ HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD
 
     *ppv = NULL;
 
-    ret = get_runtime_info(NULL, szVersion, NULL, nflags, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
+    ret = get_runtime_info(NULL, szVersion, NULL, NULL, nflags, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
@@ -503,7 +503,7 @@ HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID
 
     *ppv = NULL;
 
-    ret = get_runtime_info(NULL, NULL, filename, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
+    ret = get_runtime_info(NULL, NULL, filename, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
@@ -526,7 +526,7 @@ STDAPI ClrCreateManagedInstance(LPCWSTR pTypeName, REFIID riid, void **ppObject)
     TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName), debugstr_guid(riid), ppObject);
 
     /* FIXME: How to determine which runtime version to use? */
-    ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
+    ret = get_runtime_info(NULL, NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
 
     if (SUCCEEDED(ret))
     {
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index 3f2aa709f5..8ffb1f99e6 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -103,7 +103,8 @@ typedef struct CorDebug
 } CorDebug;
 
 extern HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
-    DWORD startup_flags, DWORD runtimeinfo_flags, BOOL legacy, ICLRRuntimeInfo **result) DECLSPEC_HIDDEN;
+    IStream *config_stream, DWORD startup_flags, DWORD runtimeinfo_flags, BOOL legacy,
+    ICLRRuntimeInfo **result) DECLSPEC_HIDDEN;
 
 extern HRESULT ICLRRuntimeInfo_GetRuntimeHost(ICLRRuntimeInfo *iface, RuntimeHost **result) DECLSPEC_HIDDEN;
 
@@ -122,6 +123,8 @@ typedef struct supported_runtime
 
 extern HRESULT parse_config_file(LPCWSTR filename, parsed_config_file *result) DECLSPEC_HIDDEN;
 
+extern HRESULT parse_config_stream(IStream *stream, parsed_config_file *result) DECLSPEC_HIDDEN;
+
 extern void free_parsed_config_file(parsed_config_file *file) DECLSPEC_HIDDEN;
 
 typedef enum {
--
2.17.1