#endif
// Used to initialize the runtime instance with values from the host when under dotnet-dump
-bool Runtime::s_isDesktop = false;
+IRuntime::RuntimeConfiguration Runtime::s_configuration = IRuntime::Core;
LPCSTR Runtime::s_dacFilePath = nullptr;
LPCSTR Runtime::s_dbiFilePath = nullptr;
/**********************************************************************\
* Creates a desktop or .NET Core instance of the runtime class
\**********************************************************************/
-HRESULT Runtime::CreateInstance(bool isDesktop, Runtime **ppRuntime)
+HRESULT Runtime::CreateInstance(RuntimeConfiguration configuration, Runtime **ppRuntime)
{
- PCSTR runtimeModuleName = isDesktop ? DESKTOP_RUNTIME_MODULE_NAME_A : NETCORE_RUNTIME_MODULE_NAME_A;
+ PCSTR runtimeModuleName = GetRuntimeModuleName(configuration);
ULONG moduleIndex = 0;
ULONG64 moduleAddress = 0;
ULONG64 moduleSize = 0;
if (*ppRuntime == nullptr)
{
hr = g_ExtSymbols->GetModuleByModuleName(runtimeModuleName, 0, &moduleIndex, &moduleAddress);
-#ifndef FEATURE_PAL
- // On Windows, support loading a Linux core dump by checking for NETCORE_RUNTIME_MODULE_NAME_UNIX_A too
- if (!SUCCEEDED(hr) && !isDesktop)
- {
- runtimeModuleName = NETCORE_RUNTIME_MODULE_NAME_UNIX_A;
-
- hr = g_ExtSymbols->GetModuleByModuleName(runtimeModuleName, 0, &moduleIndex, &moduleAddress);
- }
-#endif // !FEATURE_PAL
if (SUCCEEDED(hr))
{
#ifdef FEATURE_PAL
{
if (moduleSize > 0)
{
- *ppRuntime = new Runtime(isDesktop, moduleIndex, moduleAddress, moduleSize);
+ *ppRuntime = new Runtime(configuration, moduleIndex, moduleAddress, moduleSize);
OnUnloadTask::Register(CleanupRuntimes);
}
else
HRESULT hr = S_OK;
if (g_pRuntime == nullptr)
{
- hr = CreateInstance(false, &s_netcore);
+ hr = CreateInstance(IRuntime::Core, &s_netcore);
#ifdef FEATURE_PAL
g_pRuntime = s_netcore;
#else
if (FAILED(hr))
{
- hr = CreateInstance(true, &s_desktop);
+ hr = CreateInstance(IRuntime::UnixCore, &s_netcore);
+ }
+ if (FAILED(hr))
+ {
+ hr = CreateInstance(IRuntime::WindowsDesktop, &s_desktop);
}
g_pRuntime = s_netcore != nullptr ? s_netcore : s_desktop;
#endif
bool Runtime::SwitchRuntime(bool desktop)
{
if (desktop) {
- CreateInstance(true, &s_desktop);
+ CreateInstance(IRuntime::WindowsDesktop, &s_desktop);
}
IRuntime* runtime = desktop ? s_desktop : s_netcore;
if (runtime == nullptr) {
GUID skuId = CLR_ID_CORECLR;
#endif
#ifndef FEATURE_PAL
- if (IsDesktop())
+ if (GetRuntimeConfiguration() == IRuntime::WindowsDesktop)
{
skuId = CLR_ID_V4_DESKTOP;
}
\**********************************************************************/
void Runtime::DisplayStatus()
{
- ExtOut("%s runtime at %p (%08x)\n", m_isDesktop ? "Desktop" : ".NET Core", m_address, m_size);
+ ExtOut("%s runtime at %p (%08x)\n", GetRuntimeConfigurationName(GetRuntimeConfiguration()), m_address, m_size);
if (m_runtimeDirectory != nullptr) {
ExtOut("Runtime directory: %s\n", m_runtimeDirectory);
}
#ifdef FEATURE_PAL
-#define NETCORE_RUNTIME_MODULE_NAME_W MAKEDLLNAME_W(W("coreclr"))
-#define NETCORE_RUNTIME_MODULE_NAME_A MAKEDLLNAME_A("coreclr")
-#define NETCORE_RUNTIME_DLL_NAME_W NETCORE_RUNTIME_MODULE_NAME_W
-#define NETCORE_RUNTIME_DLL_NAME_A NETCORE_RUNTIME_MODULE_NAME_A
-
#define NETCORE_DAC_MODULE_NAME_W MAKEDLLNAME_W(W("mscordaccore"))
#define NETCORE_DAC_MODULE_NAME_A MAKEDLLNAME_A("mscordaccore")
#define NETCORE_DAC_DLL_NAME_W NETCORE_DAC_MODULE_NAME_W
#else
-#define NETCORE_RUNTIME_MODULE_NAME_UNIX_A "libcoreclr"
-
-#define NETCORE_RUNTIME_MODULE_NAME_W W("coreclr")
-#define NETCORE_RUNTIME_MODULE_NAME_A "coreclr"
-#define NETCORE_RUNTIME_DLL_NAME_W MAKEDLLNAME_W(NETCORE_RUNTIME_MODULE_NAME_W)
-#define NETCORE_RUNTIME_DLL_NAME_A MAKEDLLNAME_A(NETCORE_RUNTIME_MODULE_NAME_A)
-
#define NETCORE_DAC_MODULE_NAME_W W("mscordaccore")
#define NETCORE_DAC_MODULE_NAME_A "mscordaccore"
#define NETCORE_DAC_DLL_NAME_W MAKEDLLNAME_W(NETCORE_DAC_MODULE_NAME_W)
#endif // FEATURE_PAL
-#define DESKTOP_RUNTIME_MODULE_NAME_W W("clr")
-#define DESKTOP_RUNTIME_MODULE_NAME_A "clr"
-#define DESKTOP_RUNTIME_DLL_NAME_W MAKEDLLNAME_W(DESKTOP_RUNTIME_MODULE_NAME_W)
-#define DESKTOP_RUNTIME_DLL_NAME_A MAKEDLLNAME_A(DESKTOP_RUNTIME_MODULE_NAME_A)
-
#define DESKTOP_DAC_MODULE_NAME_W W("mscordacwks")
#define DESKTOP_DAC_MODULE_NAME_A "mscordacwks"
#define DESKTOP_DAC_DLL_NAME_W MAKEDLLNAME_W(W("mscordacwks"))
class IRuntime
{
public:
- // Returns true if desktop CLR; false if .NET Core
- virtual bool IsDesktop() const = 0;
+ enum RuntimeConfiguration
+ {
+ WindowsDesktop,
+ WindowsCore,
+ UnixCore,
+ OSXCore,
+ ConfigurationEnd,
+#ifdef FEATURE_PAL
+#ifdef __APPLE__
+ Core = OSXCore
+#else
+ Core = UnixCore
+#endif
+#else
+ Core = WindowsCore
+#endif
+ };
+
+ // Returns the runtime configuration
+ virtual RuntimeConfiguration GetRuntimeConfiguration() const = 0;
// Returns the runtime module index
virtual ULONG GetModuleIndex() const = 0;
virtual void DisplayStatus() = 0;
};
+// Returns the runtime configuration as a string
+inline static const char* GetRuntimeConfigurationName(IRuntime::RuntimeConfiguration config)
+{
+ static const char* name[IRuntime::ConfigurationEnd] = {
+ "Desktop",
+ ".NET Core (Windows)",
+ ".NET Core (Unix)",
+ ".NET Core (Mac)"
+ };
+ return (config < IRuntime::ConfigurationEnd) ? name[config] : nullptr;
+}
+
+// Returns the runtime module DLL name (clr.dll, coreclr.dll, libcoreclr.so, libcoreclr.dylib)
+inline static const char* GetRuntimeDllName(IRuntime::RuntimeConfiguration config)
+{
+ static const char* name[IRuntime::ConfigurationEnd] = {
+ "clr.dll",
+ "coreclr.dll",
+ "libcoreclr.so",
+ "libcoreclr.dylib"
+ };
+ return (config < IRuntime::ConfigurationEnd) ? name[config] : nullptr;
+}
+
+// Returns the runtime module name (clr, coreclr, libcoreclr.so, libcoreclr.dylib).
+inline static const char* GetRuntimeModuleName(IRuntime::RuntimeConfiguration config)
+{
+#ifdef FEATURE_PAL
+ return GetRuntimeDllName(config);
+#else
+ // On a windows host the module name does not include the extension.
+ static const char* name[IRuntime::ConfigurationEnd] = {
+ "clr",
+ "coreclr",
+ "libcoreclr",
+ "libcoreclr"
+ };
+ return (config < IRuntime::ConfigurationEnd) ? name[config] : nullptr;
+#endif
+}
+
extern LPCSTR g_runtimeModulePath;
extern IRuntime* g_pRuntime;
class Runtime : public IRuntime
{
private:
- bool m_isDesktop;
+ RuntimeConfiguration m_configuration;
ULONG m_index;
ULONG64 m_address;
ULONG64 m_size;
#ifndef FEATURE_PAL
static Runtime* s_desktop;
#endif
- static bool s_isDesktop;
+ static RuntimeConfiguration s_configuration;
static LPCSTR s_dacFilePath;
static LPCSTR s_dbiFilePath;
- Runtime(bool isDesktop, ULONG index, ULONG64 address, ULONG64 size) :
- m_isDesktop(isDesktop),
+ Runtime(RuntimeConfiguration configuration,ULONG index, ULONG64 address, ULONG64 size) :
+ m_configuration(configuration),
m_index(index),
m_address(address),
m_size(size),
_ASSERTE(index != -1);
_ASSERTE(address != 0);
_ASSERTE(size != 0);
- if (isDesktop == s_isDesktop) {
+ if (configuration == s_configuration) {
SetDacFilePath(s_dacFilePath);
SetDbiFilePath(s_dbiFilePath);
}
virtual Runtime::~Runtime();
- static HRESULT CreateInstance(bool isDesktop, Runtime** ppRuntime);
+ static HRESULT CreateInstance(RuntimeConfiguration configuration, Runtime** ppRuntime);
HRESULT GetRuntimeDirectory(std::string& runtimeDirectory);
static void SetDacDbiPath(bool isDesktop, LPCSTR dacFilePath, LPCSTR dbiFilePath)
{
- s_isDesktop = isDesktop;
+ s_configuration = isDesktop ? IRuntime::WindowsDesktop : IRuntime::Core;
if (dacFilePath != nullptr) {
s_dacFilePath = _strdup(dacFilePath);
}
static void Flush();
- virtual bool IsDesktop() const { return m_isDesktop; }
+ virtual RuntimeConfiguration GetRuntimeConfiguration() const { return m_configuration; }
virtual ULONG GetModuleIndex() const { return m_index; }
// Returns the runtime module DLL name (clr.dll, coreclr.dll, libcoreclr.so, libcoreclr.dylib)
inline const char* GetRuntimeDllName() const
{
- return IsDesktop() ? DESKTOP_RUNTIME_DLL_NAME_A : NETCORE_RUNTIME_DLL_NAME_A;
+ return ::GetRuntimeDllName(GetRuntimeConfiguration());
}
// Returns the DAC module name (mscordacwks.dll, mscordaccore.dll, libmscordaccore.so, libmscordaccore.dylib)
inline const char* GetDacDllName() const
{
- return IsDesktop() ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A;
+ return (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A;
}
// Returns the DAC module name (mscordacwks, mscordaccore, libmscordaccore.so, libmscordaccore.dylib)
inline const WCHAR* GetDacModuleNameW() const
{
- return IsDesktop() ? DESKTOP_DAC_MODULE_NAME_W : NETCORE_DAC_MODULE_NAME_W;
+ return (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_MODULE_NAME_W : NETCORE_DAC_MODULE_NAME_W;
}
// Returns the DAC module name (mscordacwks.dll, mscordaccore.dll, libmscordaccore.so, libmscordaccore.dylib)
inline const WCHAR* GetDacDllNameW() const
{
- return IsDesktop() ? DESKTOP_DAC_DLL_NAME_W : NETCORE_DAC_DLL_NAME_W;
+ return (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_DLL_NAME_W : NETCORE_DAC_DLL_NAME_W;
}
};
// Returns the runtime module name (clr, coreclr, libcoreclr.so, libcoreclr.dylib).
inline const char* GetRuntimeModuleName()
{
- return g_pRuntime->IsDesktop() ? DESKTOP_RUNTIME_MODULE_NAME_A : NETCORE_RUNTIME_MODULE_NAME_A;
+ return GetRuntimeModuleName(g_pRuntime->GetRuntimeConfiguration());
}
// Returns the runtime module DLL name (clr.dll, coreclr.dll, libcoreclr.so, libcoreclr.dylib)
inline const char* GetRuntimeDllName()
{
- return g_pRuntime->IsDesktop() ? DESKTOP_RUNTIME_DLL_NAME_A : NETCORE_RUNTIME_DLL_NAME_A;
+ return GetRuntimeDllName(g_pRuntime->GetRuntimeConfiguration());
}
// Returns the DAC module name (mscordacwks, mscordaccore, libmscordaccore.so, libmscordaccore.dylib)
inline const char* GetDacModuleName()
{
- return g_pRuntime->IsDesktop() ? DESKTOP_DAC_MODULE_NAME_A : NETCORE_DAC_MODULE_NAME_A;
+ return (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_MODULE_NAME_A : NETCORE_DAC_MODULE_NAME_A;
}
// Returns the DAC module name (mscordacwks.dll, mscordaccore.dll, libmscordaccore.so, libmscordaccore.dylib)
inline const char* GetDacDllName()
{
- return g_pRuntime->IsDesktop() ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A;
+ return (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A;
}
#endif // __runtime_h__