diff options
author | Jim Ma <mazong1123@gmail.com> | 2017-04-13 23:50:05 +0800 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-04-13 08:50:05 -0700 |
commit | 5e138a6d69215546e9bf4b38ec9bdd1c436fca5b (patch) | |
tree | 5f774a383b9ffeba11b93907d0b0c1e690919506 /src/coreclr | |
parent | 7f1ebe17e63bf7670c8fc3393a82b2b1ed978762 (diff) | |
download | coreclr-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/coreclr')
-rw-r--r-- | src/coreclr/hosts/inc/coreclrhost.h | 5 | ||||
-rw-r--r-- | src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp | 12 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/hosts/inc/coreclrhost.h index f0d7952aa6..dd11cb6a51 100644 --- a/src/coreclr/hosts/inc/coreclrhost.h +++ b/src/coreclr/hosts/inc/coreclrhost.h @@ -29,6 +29,11 @@ CORECLR_HOSTING_API(coreclr_shutdown, void* hostHandle, unsigned int domainId); +CORECLR_HOSTING_API(coreclr_shutdown_2, + void* hostHandle, + unsigned int domainId, + int* latchedExitCode); + CORECLR_HOSTING_API(coreclr_create_delegate, void* hostHandle, unsigned int domainId, diff --git a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp index d40fb424e6..52ffda8bb5 100644 --- a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp +++ b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp @@ -321,7 +321,7 @@ int ExecuteManagedAssembly( { coreclr_initialize_ptr initializeCoreCLR = (coreclr_initialize_ptr)dlsym(coreclrLib, "coreclr_initialize"); coreclr_execute_assembly_ptr executeAssembly = (coreclr_execute_assembly_ptr)dlsym(coreclrLib, "coreclr_execute_assembly"); - coreclr_shutdown_ptr shutdownCoreCLR = (coreclr_shutdown_ptr)dlsym(coreclrLib, "coreclr_shutdown"); + coreclr_shutdown_2_ptr shutdownCoreCLR = (coreclr_shutdown_2_ptr)dlsym(coreclrLib, "coreclr_shutdown_2"); if (initializeCoreCLR == nullptr) { @@ -333,7 +333,7 @@ int ExecuteManagedAssembly( } else if (shutdownCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n"); + fprintf(stderr, "Function coreclr_shutdown_2 not found in the libcoreclr.so\n"); } else { @@ -416,12 +416,18 @@ int ExecuteManagedAssembly( exitCode = -1; } - st = shutdownCoreCLR(hostHandle, domainId); + int latchedExitCode = 0; + st = shutdownCoreCLR(hostHandle, domainId, &latchedExitCode); if (!SUCCEEDED(st)) { fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st); exitCode = -1; } + + if (exitCode != -1) + { + exitCode = latchedExitCode; + } } } |