summaryrefslogtreecommitdiff
path: root/src/coreclr/hosts
diff options
context:
space:
mode:
Diffstat (limited to 'src/coreclr/hosts')
-rw-r--r--src/coreclr/hosts/coreconsole/coreconsole.cpp24
-rw-r--r--src/coreclr/hosts/corerun/corerun.cpp38
-rw-r--r--src/coreclr/hosts/inc/coreclrhost.h5
-rw-r--r--src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp50
4 files changed, 84 insertions, 33 deletions
diff --git a/src/coreclr/hosts/coreconsole/coreconsole.cpp b/src/coreclr/hosts/coreconsole/coreconsole.cpp
index ea4e2e72c5..e3813d49b3 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 @@ public:
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 @@ public:
*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)) {
@@ -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;
//-------------------------------------------------------------
@@ -568,7 +570,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 dfbb79c0d2..a9e3b66f3b 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 @@ public:
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 @@ public:
*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)) {
@@ -470,6 +470,18 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo
return false;
}
+ StackSString tpaList;
+ if (!managedAssemblyFullName.IsEmpty())
+ {
+ // Target assembly should be added to the tpa list. Otherwise corerun.exe
+ // may find wrong assembly to execute.
+ // Details can be found at https://github.com/dotnet/coreclr/issues/5631
+ tpaList = managedAssemblyFullName;
+ tpaList.Append(W(';'));
+ }
+
+ tpaList.Append(hostEnvironment.GetTpaList());
+
//-------------------------------------------------------------
// Create an AppDomain
@@ -499,7 +511,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo
};
const wchar_t *property_values[] = {
// TRUSTED_PLATFORM_ASSEMBLIES
- hostEnvironment.GetTpaList(),
+ tpaList,
// APP_PATHS
appPath,
// APP_NI_PATHS
@@ -581,15 +593,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;
//-------------------------------------------------------------
@@ -608,7 +622,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/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..f97f262993 100644
--- a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
+++ b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
@@ -35,6 +35,10 @@
// disabled. Server GC is off by default.
static const char* serverGcVar = "CORECLR_SERVER_GC";
+// Name of environment variable to control "System.Globalization.Invariant"
+// Set to 1 for Globalization Invariant mode to be true. Default is false.
+static const char* globalizationInvariantVar = "CORECLR_GLOBAL_INVARIANT";
+
#if defined(__linux__)
#define symlinkEntrypointExecutable "/proc/self/exe"
#elif !defined(__APPLE__)
@@ -260,6 +264,17 @@ void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList)
closedir(dir);
}
+const char* GetEnvValueBoolean(const char* envVariable)
+{
+ const char* envValue = std::getenv(envVariable);
+ if (envValue == nullptr)
+ {
+ envValue = "0";
+ }
+ // CoreCLR expects strings "true" and "false" instead of "1" and "0".
+ return (std::strcmp(envValue, "1") == 0 || strcasecmp(envValue, "true") == 0) ? "true" : "false";
+}
+
int ExecuteManagedAssembly(
const char* currentExeAbsolutePath,
const char* clrFilesAbsolutePath,
@@ -299,6 +314,15 @@ int ExecuteManagedAssembly(
GetDirectory(managedAssemblyAbsolutePath, appPath);
std::string tpaList;
+ if (strlen(managedAssemblyAbsolutePath) > 0)
+ {
+ // Target assembly should be added to the tpa list. Otherwise corerun.exe
+ // may find wrong assembly to execute.
+ // Details can be found at https://github.com/dotnet/coreclr/issues/5631
+ tpaList = managedAssemblyAbsolutePath;
+ tpaList.append(":");
+ }
+
// Construct native search directory paths
std::string nativeDllSearchDirs(appPath);
char *coreLibraries = getenv("CORE_LIBRARIES");
@@ -311,6 +335,7 @@ int ExecuteManagedAssembly(
AddFilesFromDirectoryToTpaList(coreLibraries, tpaList);
}
}
+
nativeDllSearchDirs.append(":");
nativeDllSearchDirs.append(clrFilesAbsolutePath);
@@ -321,7 +346,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,19 +358,15 @@ 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
{
// Check whether we are enabling server GC (off by default)
- const char* useServerGc = std::getenv(serverGcVar);
- if (useServerGc == nullptr)
- {
- useServerGc = "0";
- }
+ const char* useServerGc = GetEnvValueBoolean(serverGcVar);
- // CoreCLR expects strings "true" and "false" instead of "1" and "0".
- useServerGc = std::strcmp(useServerGc, "1") == 0 ? "true" : "false";
+ // Check Globalization Invariant mode (false by default)
+ const char* globalizationInvariant = GetEnvValueBoolean(globalizationInvariantVar);
// Allowed property names:
// APPBASE
@@ -369,6 +390,7 @@ int ExecuteManagedAssembly(
"APP_NI_PATHS",
"NATIVE_DLL_SEARCH_DIRECTORIES",
"System.GC.Server",
+ "System.Globalization.Invariant",
};
const char *propertyValues[] = {
// TRUSTED_PLATFORM_ASSEMBLIES
@@ -381,6 +403,8 @@ int ExecuteManagedAssembly(
nativeDllSearchDirs.c_str(),
// System.GC.Server
useServerGc,
+ // System.Globalization.Invariant
+ globalizationInvariant,
};
void* hostHandle;
@@ -416,12 +440,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;
+ }
}
}