From f978b5df98d7c78f79ccd11324c950a2d5592684 Mon Sep 17 00:00:00 2001 From: mazong1123 Date: Fri, 14 Apr 2017 15:15:08 +0800 Subject: [PATCH 1/5] Change ICLRRuntimeHost2 to ICLRRuntimeHost4 for Windows corerun. Since we've introduced ICLRRuntimeHost4 in PR #10842 for Unix, we apply it for Windows corerun as well. Fix #10960 --- src/coreclr/hosts/coreconsole/coreconsole.cpp | 18 +++++++++--------- src/coreclr/hosts/corerun/corerun.cpp | 18 +++++++++--------- src/inc/MSCOREE.IDL | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/coreclr/hosts/coreconsole/coreconsole.cpp b/src/coreclr/hosts/coreconsole/coreconsole.cpp index ea4e2e72c553..d6e8459cec45 100644 --- a/src/coreclr/hosts/coreconsole/coreconsole.cpp +++ b/src/coreclr/hosts/coreconsole/coreconsole.cpp @@ -71,7 +71,7 @@ class HostEnvironment // The list of paths to the assemblies that will be trusted by CoreCLR StringBuffer m_tpaList; - ICLRRuntimeHost2* m_CLRRuntimeHost; + ICLRRuntimeHost4* m_CLRRuntimeHost; HMODULE m_coreCLRModule; @@ -326,8 +326,8 @@ class HostEnvironment return m_hostExeName; } - // Returns the ICLRRuntimeHost2 instance, loading it from CoreCLR.dll if necessary, or nullptr on failure. - ICLRRuntimeHost2* GetCLRRuntimeHost() { + // Returns the ICLRRuntimeHost4 instance, loading it from CoreCLR.dll if necessary, or nullptr on failure. + ICLRRuntimeHost4* GetCLRRuntimeHost() { if (!m_CLRRuntimeHost) { if (!m_coreCLRModule) { @@ -347,9 +347,9 @@ class HostEnvironment *m_log << W("Calling GetCLRRuntimeHost(...)") << Logger::endl; - HRESULT hr = pfnGetCLRRuntimeHost(IID_ICLRRuntimeHost2, (IUnknown**)&m_CLRRuntimeHost); + HRESULT hr = pfnGetCLRRuntimeHost(IID_ICLRRuntimeHost4, (IUnknown**)&m_CLRRuntimeHost); if (FAILED(hr)) { - *m_log << W("Failed to get ICLRRuntimeHost2 interface. ERRORCODE: ") << hr << Logger::endl; + *m_log << W("Failed to get ICLRRuntimeHost4 interface. ERRORCODE: ") << hr << Logger::endl; return nullptr; } } @@ -405,14 +405,14 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo // Start the CoreCLR - ICLRRuntimeHost2 *host = hostEnvironment.GetCLRRuntimeHost(); + ICLRRuntimeHost4 *host = hostEnvironment.GetCLRRuntimeHost(); if (!host) { return false; } HRESULT hr; - log << W("Setting ICLRRuntimeHost2 startup flags") << Logger::endl; + log << W("Setting ICLRRuntimeHost4 startup flags") << Logger::endl; // Default startup flags hr = host->SetStartupFlags((STARTUP_FLAGS) @@ -424,7 +424,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo return false; } - log << W("Starting ICLRRuntimeHost2") << Logger::endl; + log << W("Starting ICLRRuntimeHost4") << Logger::endl; hr = host->Start(); if (FAILED(hr)) { @@ -568,7 +568,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo // Release the reference to the host - log << W("Releasing ICLRRuntimeHost2") << Logger::endl; + log << W("Releasing ICLRRuntimeHost4") << Logger::endl; host->Release(); diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index dfbb79c0d209..973211cd2d28 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -47,7 +47,7 @@ class HostEnvironment // The list of paths to the assemblies that will be trusted by CoreCLR SString m_tpaList; - ICLRRuntimeHost2* m_CLRRuntimeHost; + ICLRRuntimeHost4* m_CLRRuntimeHost; HMODULE m_coreCLRModule; @@ -298,8 +298,8 @@ class HostEnvironment return m_hostExeName; } - // Returns the ICLRRuntimeHost2 instance, loading it from CoreCLR.dll if necessary, or nullptr on failure. - ICLRRuntimeHost2* GetCLRRuntimeHost() { + // Returns the ICLRRuntimeHost4 instance, loading it from CoreCLR.dll if necessary, or nullptr on failure. + ICLRRuntimeHost4* GetCLRRuntimeHost() { if (!m_CLRRuntimeHost) { if (!m_coreCLRModule) { @@ -319,9 +319,9 @@ class HostEnvironment *m_log << W("Calling GetCLRRuntimeHost(...)") << Logger::endl; - HRESULT hr = pfnGetCLRRuntimeHost(IID_ICLRRuntimeHost2, (IUnknown**)&m_CLRRuntimeHost); + HRESULT hr = pfnGetCLRRuntimeHost(IID_ICLRRuntimeHost4, (IUnknown**)&m_CLRRuntimeHost); if (FAILED(hr)) { - *m_log << W("Failed to get ICLRRuntimeHost2 interface. ERRORCODE: ") << Logger::hresult << hr << Logger::endl; + *m_log << W("Failed to get ICLRRuntimeHost4 interface. ERRORCODE: ") << Logger::hresult << hr << Logger::endl; return nullptr; } } @@ -442,7 +442,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo // Start the CoreCLR - ICLRRuntimeHost2 *host = hostEnvironment.GetCLRRuntimeHost(); + ICLRRuntimeHost4 *host = hostEnvironment.GetCLRRuntimeHost(); if (!host) { return false; } @@ -451,7 +451,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo STARTUP_FLAGS flags = CreateStartupFlags(); - log << W("Setting ICLRRuntimeHost2 startup flags") << Logger::endl; + log << W("Setting ICLRRuntimeHost4 startup flags") << Logger::endl; log << W("Server GC enabled: ") << HAS_FLAG(flags, STARTUP_FLAGS::STARTUP_SERVER_GC) << Logger::endl; log << W("Concurrent GC enabled: ") << HAS_FLAG(flags, STARTUP_FLAGS::STARTUP_CONCURRENT_GC) << Logger::endl; @@ -462,7 +462,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo return false; } - log << W("Starting ICLRRuntimeHost2") << Logger::endl; + log << W("Starting ICLRRuntimeHost4") << Logger::endl; hr = host->Start(); if (FAILED(hr)) { @@ -608,7 +608,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo // Release the reference to the host - log << W("Releasing ICLRRuntimeHost2") << Logger::endl; + log << W("Releasing ICLRRuntimeHost4") << Logger::endl; host->Release(); diff --git a/src/inc/MSCOREE.IDL b/src/inc/MSCOREE.IDL index 97e2f2aca666..9cd7e20faa58 100644 --- a/src/inc/MSCOREE.IDL +++ b/src/inc/MSCOREE.IDL @@ -86,6 +86,9 @@ cpp_quote("EXTERN_GUID(IID_ICLRRuntimeHost, 0x90F1A06C, 0x7712, 0x4762, 0x86, 0x // IID ICLRRuntimeHost2: uuid(712AB73F-2C22-4807-AD7E-F501D7B72C2D) cpp_quote("EXTERN_GUID(IID_ICLRRuntimeHost2, 0x712AB73F, 0x2C22, 0x4807, 0xAD, 0x7E, 0xF5, 0x01, 0xD7, 0xb7, 0x2C, 0x2D);") +// IID ICLRRuntimeHost4: uuid(64F6D366-D7C2-4F1F-B4B2-E8160CAC43AF) +cpp_quote("EXTERN_GUID(IID_ICLRRuntimeHost4, 0x64F6D366, 0xD7C2, 0x4F1F, 0xB4, 0xB2, 0xE8, 0x16, 0x0C, 0xAC, 0x43, 0xAF);") + // IID IID_ICLRExecutionManager: uuid(1000A3E7-B420-4620-AE30-FB19B587AD1D) cpp_quote("EXTERN_GUID(IID_ICLRExecutionManager, 0x1000A3E7, 0xB420, 0x4620, 0xAE, 0x30, 0xFB, 0x19, 0xB5, 0x87, 0xAD, 0x1D);") @@ -847,6 +850,22 @@ interface ICLRRuntimeHost2 : ICLRRuntimeHost }; +[ + object, + uuid(64F6D366-D7C2-4F1F-B4B2-E8160CAC43AF), + version(4.0), + helpstring("Common Language Runtime Hosting Interface"), + pointer_default(unique), + local +] +ICLRRuntimeHost4 : public ICLRRuntimeHost2 +{ + virtual HRESULT STDMETHODCALLTYPE UnloadAppDomain2( + /* [in] */ DWORD dwAppDomainId, + /* [in] */ BOOL fWaitUntilDone, + /* [out] */ int *pLatchedExitCode); +}; + [ uuid(1000A3E7-B420-4620-AE30-FB19B587AD1D), version(1.0), From d70f2b1a54f2c72bc375c2c0b990dd63954a4fea Mon Sep 17 00:00:00 2001 From: mazong1123 Date: Sat, 15 Apr 2017 18:07:33 +1200 Subject: [PATCH 2/5] Added the missing interface keyword. Fix #10960 --- src/inc/MSCOREE.IDL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/MSCOREE.IDL b/src/inc/MSCOREE.IDL index 9cd7e20faa58..f745c5a90a0d 100644 --- a/src/inc/MSCOREE.IDL +++ b/src/inc/MSCOREE.IDL @@ -858,7 +858,7 @@ interface ICLRRuntimeHost2 : ICLRRuntimeHost pointer_default(unique), local ] -ICLRRuntimeHost4 : public ICLRRuntimeHost2 +interface ICLRRuntimeHost4 : public ICLRRuntimeHost2 { virtual HRESULT STDMETHODCALLTYPE UnloadAppDomain2( /* [in] */ DWORD dwAppDomainId, From af12b157d007679b165310cb86b0190066461c28 Mon Sep 17 00:00:00 2001 From: mazong1123 Date: Sat, 15 Apr 2017 19:51:36 +1200 Subject: [PATCH 3/5] Removed unnecessary public keyword. Fix #10960 --- src/inc/MSCOREE.IDL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/MSCOREE.IDL b/src/inc/MSCOREE.IDL index f745c5a90a0d..674d5be6b1c6 100644 --- a/src/inc/MSCOREE.IDL +++ b/src/inc/MSCOREE.IDL @@ -858,7 +858,7 @@ interface ICLRRuntimeHost2 : ICLRRuntimeHost pointer_default(unique), local ] -interface ICLRRuntimeHost4 : public ICLRRuntimeHost2 +interface ICLRRuntimeHost4 : ICLRRuntimeHost2 { virtual HRESULT STDMETHODCALLTYPE UnloadAppDomain2( /* [in] */ DWORD dwAppDomainId, From b3291e176c1013f25a0f8eab23198c65b27374e2 Mon Sep 17 00:00:00 2001 From: mazong1123 Date: Sat, 15 Apr 2017 20:19:58 +1200 Subject: [PATCH 4/5] Adjusted function signature for .idl file. Fix #10960 --- src/inc/MSCOREE.IDL | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/inc/MSCOREE.IDL b/src/inc/MSCOREE.IDL index 674d5be6b1c6..53d4ce3bb004 100644 --- a/src/inc/MSCOREE.IDL +++ b/src/inc/MSCOREE.IDL @@ -860,10 +860,9 @@ interface ICLRRuntimeHost2 : ICLRRuntimeHost ] interface ICLRRuntimeHost4 : ICLRRuntimeHost2 { - virtual HRESULT STDMETHODCALLTYPE UnloadAppDomain2( - /* [in] */ DWORD dwAppDomainId, - /* [in] */ BOOL fWaitUntilDone, - /* [out] */ int *pLatchedExitCode); + HRESULT UnloadAppDomain2([in] DWORD dwAppDomainId, + [in] BOOL fWaitUntilDone, + [out] int *pLatchedExitCode); }; [ From 29e3fe30a0517701ea628eae3b6b3cc97274029a Mon Sep 17 00:00:00 2001 From: mazong1123 Date: Wed, 19 Apr 2017 14:39:48 +0800 Subject: [PATCH 5/5] Use UnloadAppDomain2 instead of UnloadAppDomain. Fix #10960 --- src/coreclr/hosts/coreconsole/coreconsole.cpp | 6 ++++-- src/coreclr/hosts/corerun/corerun.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/coreclr/hosts/coreconsole/coreconsole.cpp b/src/coreclr/hosts/coreconsole/coreconsole.cpp index d6e8459cec45..e3813d49b3bd 100644 --- a/src/coreclr/hosts/coreconsole/coreconsole.cpp +++ b/src/coreclr/hosts/coreconsole/coreconsole.cpp @@ -541,15 +541,17 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo log << W("Unloading the AppDomain") << Logger::endl; - hr = host->UnloadAppDomain( + hr = host->UnloadAppDomain2( domainId, - true); // Wait until done + true, + (int *)&exitCode); // Wait until done if (FAILED(hr)) { log << W("Failed to unload the AppDomain. ERRORCODE: ") << hr << Logger::endl; return false; } + log << W("App domain unloaded exit value = ") << exitCode << Logger::endl; //------------------------------------------------------------- diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index 973211cd2d28..c65c626615b4 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -581,15 +581,17 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo log << W("Unloading the AppDomain") << Logger::endl; - hr = host->UnloadAppDomain( + hr = host->UnloadAppDomain2( domainId, - true); // Wait until done + true, + (int *)&exitCode); // Wait until done if (FAILED(hr)) { log << W("Failed to unload the AppDomain. ERRORCODE: ") << Logger::hresult << hr << Logger::endl; return false; } + log << W("App domain unloaded exit value = ") << exitCode << Logger::endl; //-------------------------------------------------------------