summaryrefslogtreecommitdiff
path: root/src/dlls
diff options
context:
space:
mode:
authorJim Ma <mazong1123@gmail.com>2017-04-13 23:50:05 +0800
committerJan Kotas <jkotas@microsoft.com>2017-04-13 08:50:05 -0700
commit5e138a6d69215546e9bf4b38ec9bdd1c436fca5b (patch)
tree5f774a383b9ffeba11b93907d0b0c1e690919506 /src/dlls
parent7f1ebe17e63bf7670c8fc3393a82b2b1ed978762 (diff)
downloadcoreclr-5e138a6d69215546e9bf4b38ec9bdd1c436fca5b.tar.gz
coreclr-5e138a6d69215546e9bf4b38ec9bdd1c436fca5b.tar.bz2
coreclr-5e138a6d69215546e9bf4b38ec9bdd1c436fca5b.zip
Ensure Environment.ExitCode works correctly after app domain unloaded. (#10842)
* Ensure Environment.ExitCode works correctly after app domain unloaded. This PR addresses 2 problems of Environment.ExitCode: 1. Can't get correct exit code of main function. 2. Can't set %errorlevel%. Details can be found on #6206 Fix #6206
Diffstat (limited to 'src/dlls')
-rw-r--r--src/dlls/mscoree/mscorwks_ntdef.src1
-rw-r--r--src/dlls/mscoree/mscorwks_unixexports.src1
-rw-r--r--src/dlls/mscoree/unixinterface.cpp41
3 files changed, 38 insertions, 5 deletions
diff --git a/src/dlls/mscoree/mscorwks_ntdef.src b/src/dlls/mscoree/mscorwks_ntdef.src
index 8115475418..d7e6a2dcf4 100644
--- a/src/dlls/mscoree/mscorwks_ntdef.src
+++ b/src/dlls/mscoree/mscorwks_ntdef.src
@@ -21,6 +21,7 @@ EXPORTS
coreclr_execute_assembly
coreclr_initialize
coreclr_shutdown
+ coreclr_shutdown_2
; il{d}asm
MetaDataGetDispenser
diff --git a/src/dlls/mscoree/mscorwks_unixexports.src b/src/dlls/mscoree/mscorwks_unixexports.src
index f7862d3afe..28e9ac223f 100644
--- a/src/dlls/mscoree/mscorwks_unixexports.src
+++ b/src/dlls/mscoree/mscorwks_unixexports.src
@@ -3,6 +3,7 @@ coreclr_create_delegate
coreclr_execute_assembly
coreclr_initialize
coreclr_shutdown
+coreclr_shutdown_2
; il{d}asm
MetaDataGetDispenser
diff --git a/src/dlls/mscoree/unixinterface.cpp b/src/dlls/mscoree/unixinterface.cpp
index edd361c0c2..cf9bbc5c72 100644
--- a/src/dlls/mscoree/unixinterface.cpp
+++ b/src/dlls/mscoree/unixinterface.cpp
@@ -183,9 +183,9 @@ int coreclr_initialize(
}
#endif
- ReleaseHolder<ICLRRuntimeHost2> host;
+ ReleaseHolder<ICLRRuntimeHost4> host;
- hr = CorHost2::CreateObject(IID_ICLRRuntimeHost2, (void**)&host);
+ hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host);
IfFailRet(hr);
ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName);
@@ -284,7 +284,7 @@ int coreclr_shutdown(
void* hostHandle,
unsigned int domainId)
{
- ReleaseHolder<ICLRRuntimeHost2> host(reinterpret_cast<ICLRRuntimeHost2*>(hostHandle));
+ ReleaseHolder<ICLRRuntimeHost4> host(reinterpret_cast<ICLRRuntimeHost4*>(hostHandle));
HRESULT hr = host->UnloadAppDomain(domainId, true); // Wait until done
IfFailRet(hr);
@@ -299,6 +299,37 @@ int coreclr_shutdown(
}
//
+// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
+//
+// Parameters:
+// hostHandle - Handle of the host
+// domainId - Id of the domain
+// latchedExitCode - Latched exit code after domain unloaded
+//
+// Returns:
+// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
+//
+extern "C"
+int coreclr_shutdown_2(
+ void* hostHandle,
+ unsigned int domainId,
+ int* latchedExitCode)
+{
+ ReleaseHolder<ICLRRuntimeHost4> host(reinterpret_cast<ICLRRuntimeHost4*>(hostHandle));
+
+ HRESULT hr = host->UnloadAppDomain2(domainId, true, latchedExitCode); // Wait until done
+ IfFailRet(hr);
+
+ hr = host->Stop();
+
+#ifdef FEATURE_PAL
+ PAL_Shutdown();
+#endif
+
+ return hr;
+}
+
+//
// Create a native callable delegate for a managed method.
//
// Parameters:
@@ -321,7 +352,7 @@ int coreclr_create_delegate(
const char* entryPointMethodName,
void** delegate)
{
- ICLRRuntimeHost2* host = reinterpret_cast<ICLRRuntimeHost2*>(hostHandle);
+ ICLRRuntimeHost4* host = reinterpret_cast<ICLRRuntimeHost4*>(hostHandle);
ConstWStringHolder entryPointAssemblyNameW = StringToUnicode(entryPointAssemblyName);
ConstWStringHolder entryPointTypeNameW = StringToUnicode(entryPointTypeName);
@@ -366,7 +397,7 @@ int coreclr_execute_assembly(
}
*exitCode = -1;
- ICLRRuntimeHost2* host = reinterpret_cast<ICLRRuntimeHost2*>(hostHandle);
+ ICLRRuntimeHost4* host = reinterpret_cast<ICLRRuntimeHost4*>(hostHandle);
ConstWStringArrayHolder argvW;
argvW.Set(StringArrayToUnicode(argc, argv), argc);