Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Stopping using DNX_DEFAULT_LIB to pass the path to the runtime folder
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzyk committed Sep 2, 2015
1 parent 5bbb84b commit 05767f4
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 33 deletions.
7 changes: 5 additions & 2 deletions src/Microsoft.Dnx.Host.Clr/DomainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void InitializeNewDomain(AppDomainSetup appDomainInfo)
Environment.SetEnvironmentVariable(EnvironmentNames.AppBase, _info.ApplicationBase);
}

appDomainInfo.ApplicationBase = Environment.GetEnvironmentVariable(EnvironmentNames.DefaultLib);
appDomainInfo.ApplicationBase = _info.RuntimeDirectory;
appDomainInfo.TargetFrameworkName = DetermineAppDomainTargetFramework();
appDomainInfo.ConfigurationFile = Path.Combine(_info.ApplicationBase, Constants.AppConfigurationFileName);
}
Expand Down Expand Up @@ -170,7 +170,10 @@ public struct ApplicationMainInfo
public MainDelegate Main;

[MarshalAs(UnmanagedType.BStr)]
public String ApplicationBase;
public string RuntimeDirectory;

[MarshalAs(UnmanagedType.BStr)]
public string ApplicationBase;
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
Expand Down
4 changes: 2 additions & 2 deletions src/dnx.clr/HostAssemblyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "stdafx.h"
#include "HostAssemblyManager.h"

HostAssemblyManager::HostAssemblyManager()
HostAssemblyManager::HostAssemblyManager(const wchar_t* runtimeDirectory)
{
m_pAssemblyStore = new HostAssemblyStore();
m_pAssemblyStore = new HostAssemblyStore(runtimeDirectory);
m_pAssemblyStore->AddRef();
}

Expand Down
2 changes: 1 addition & 1 deletion src/dnx.clr/HostAssemblyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HostAssemblyManager : public IHostAssemblyManager
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();

HostAssemblyManager();
HostAssemblyManager(const wchar_t* runtimeDirectory);
virtual ~HostAssemblyManager();

private:
Expand Down
9 changes: 1 addition & 8 deletions src/dnx.clr/HostAssemblyStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ HRESULT STDMETHODCALLTYPE HostAssemblyStore::ProvideAssembly(AssemblyBindInfo *p
{
if (_wcsicmp(AppDomainManagerAssemblyName, pBindInfo->lpReferencedIdentity) == 0)
{
wchar_t default_lib[MAX_PATH] = { 0 };
auto result = GetEnvironmentVariable(L"DNX_DEFAULT_LIB", default_lib, MAX_PATH);
if (result == 0 || result > MAX_PATH)
{
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
}

std::wstring path(default_lib);
std::wstring path(m_runtimeDirectory);
if (path.back() != L'\\')
{
path.append(L"\\");
Expand Down
10 changes: 6 additions & 4 deletions src/dnx.clr/HostAssemblyStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ class HostAssemblyStore : public IHostAssemblyStore
HRESULT STDMETHODCALLTYPE ProvideModule(ModuleBindInfo *pBindInfo, DWORD *pdwModuleId, IStream **ppStmModuleImage,
IStream **ppStmPDB);

virtual HRESULT STDMETHODCALLTYPE QueryInterface(const IID &iid, void **ppv);
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();
virtual HRESULT STDMETHODCALLTYPE QueryInterface(const IID &iid, void **ppv);
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();

HostAssemblyStore() : m_RefCount(0)
HostAssemblyStore(const wchar_t* runtimeDirectory)
: m_runtimeDirectory(runtimeDirectory), m_RefCount(0)
{};

virtual ~HostAssemblyStore() = default;

private:
long m_RefCount;
const wchar_t* m_runtimeDirectory;
};
20 changes: 15 additions & 5 deletions src/dnx.clr/KatanaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ struct ApplicationMainInfo

/* in */ ApplicationMainDelegate ApplicationMain;

/* out */ BSTR RuntimeDirectory;

/* out */ BSTR ApplicationBase;
};

class __declspec(uuid("7E9C5238-60DC-49D3-94AA-53C91FA79F7C")) IKatanaManager : public IUnknown
{
public:
virtual HRESULT InitializeRuntime(LPCWSTR applicationBase) = 0;
virtual HRESULT InitializeRuntime(LPCWSTR runtimeDirectory, LPCWSTR applicationBase) = 0;

virtual HRESULT BindApplicationMain(ApplicationMainInfo* pInfo) = 0;

Expand Down Expand Up @@ -52,22 +54,25 @@ class KatanaManager :
_bstr_t _rootWebConfigFileName;

_bstr_t _applicationBase;
_bstr_t _runtimeDirectory;

ApplicationMainInfo _applicationMainInfo;

public:

KatanaManager()
: m_pHostAssemblyManager{nullptr}
{
_calledInitializeRuntime = false;
_hrInitializeRuntime = E_PENDING;
m_pHostAssemblyManager = new HostAssemblyManager();
m_pHostAssemblyManager->AddRef();
}

~KatanaManager()
{
m_pHostAssemblyManager->Release();
if (m_pHostAssemblyManager)
{
m_pHostAssemblyManager->Release();
}
}

IUnknown* CastInterface(REFIID riid)
Expand All @@ -82,7 +87,7 @@ class KatanaManager :
return NULL;
}

HRESULT InitializeRuntime(LPCWSTR applicationBase)
HRESULT InitializeRuntime(LPCWSTR runtimeDirectory, LPCWSTR applicationBase)
{
Lock lock(&_crit);
if (_calledInitializeRuntime)
Expand All @@ -91,6 +96,10 @@ class KatanaManager :
HRESULT hr = S_OK;

_applicationBase = applicationBase;
_runtimeDirectory = runtimeDirectory;

m_pHostAssemblyManager = new HostAssemblyManager(runtimeDirectory);
m_pHostAssemblyManager->AddRef();

_HR(CLRCreateInstance(CLSID_CLRMetaHostPolicy, PPV(&_MetaHostPolicy)));

Expand Down Expand Up @@ -135,6 +144,7 @@ class KatanaManager :
HRESULT BindApplicationMain(ApplicationMainInfo* pInfo)
{
_applicationMainInfo = *pInfo;
pInfo->RuntimeDirectory = _runtimeDirectory.copy();
pInfo->ApplicationBase = _applicationBase.copy();
return S_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dnx.clr/dnx.clr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" __declspec(dllexport) HRESULT __stdcall CallApplicationMain(PCALL_APP

g_katanaManager = manager;

hr = manager->InitializeRuntime(data->applicationBase);
hr = manager->InitializeRuntime(data->runtimeDirectory, data->applicationBase);
if (SUCCEEDED(hr))
{
g_katanaManager = NULL;
Expand Down
14 changes: 6 additions & 8 deletions src/dnx.coreclr/dnx.coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ HRESULT StopClrHost(ICLRRuntimeHost2* pCLRRuntimeHost)
return pCLRRuntimeHost->Stop();
}

HRESULT ExecuteMain(ICLRRuntimeHost2* pCLRRuntimeHost, PCALL_APPLICATION_MAIN_DATA data, const std::wstring& runtime_directory,
HRESULT ExecuteMain(ICLRRuntimeHost2* pCLRRuntimeHost, PCALL_APPLICATION_MAIN_DATA data,
const std::wstring& core_clr_directory, dnx::trace_writer& trace_writer)
{
const wchar_t* property_keys[] =
Expand Down Expand Up @@ -255,10 +255,10 @@ HRESULT ExecuteMain(ICLRRuntimeHost2* pCLRRuntimeHost, PCALL_APPLICATION_MAIN_DA
}

// Add the assembly containing the app domain manager to the trusted list
trusted_platform_assemblies.append(dnx::utils::path_combine(runtime_directory, L"Microsoft.Dnx.Host.CoreClr.dll"));
trusted_platform_assemblies.append(dnx::utils::path_combine(data->runtimeDirectory, L"Microsoft.Dnx.Host.CoreClr.dll"));

std::wstring app_paths;
app_paths.append(runtime_directory).append(L";");
app_paths.append(data->runtimeDirectory).append(L";");
app_paths.append(core_clr_directory).append(L";");

const wchar_t* property_values[] = {
Expand Down Expand Up @@ -323,9 +323,7 @@ extern "C" HRESULT __stdcall CallApplicationMain(PCALL_APPLICATION_MAIN_DATA dat

Win32KDisable(trace_writer);

auto runtime_directory = data->runtimeDirectory ? data->runtimeDirectory : GetModuleDirectory(nullptr);

auto coreclr_module = LoadCoreClr(runtime_directory, trace_writer);
auto coreclr_module = LoadCoreClr(data->runtimeDirectory, trace_writer);
if (!coreclr_module)
{
trace_writer.write(L"Failed to locate or load coreclr.dll", false);
Expand All @@ -348,10 +346,10 @@ extern "C" HRESULT __stdcall CallApplicationMain(PCALL_APPLICATION_MAIN_DATA dat
return hr;
}

hr = ExecuteMain(pCLRRuntimeHost, data, runtime_directory, GetModuleDirectory(coreclr_module), trace_writer);
hr = ExecuteMain(pCLRRuntimeHost, data, GetModuleDirectory(coreclr_module), trace_writer);
if (FAILED(hr))
{
trace_writer.write(L"Failed to start CLR host", false);
trace_writer.write(L"Failed to execute Main", false);
return hr;
}

Expand Down
3 changes: 2 additions & 1 deletion src/dnx/dnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int CallApplicationProcessMain(size_t argc, dnx::char_t* argv[], dnx::trace_writ
// Set the DNX_CONOSLE_HOST flag which will print exceptions to stderr instead of throwing
SetConsoleHost();

auto currentDirectory = GetNativeBootstrapperDirectory();
const auto currentDirectory = GetNativeBootstrapperDirectory();

// Set the DEFAULT_LIB environment variable to be the same directory as the exe
SetEnvironmentVariable(_X("DNX_DEFAULT_LIB"), currentDirectory.c_str());
Expand All @@ -272,6 +272,7 @@ int CallApplicationProcessMain(size_t argc, dnx::char_t* argv[], dnx::trace_writ
CALL_APPLICATION_MAIN_DATA data = { 0 };
data.argc = static_cast<int>(argc);
data.argv = const_cast<const dnx::char_t**>(argv);
data.runtimeDirectory = currentDirectory.c_str();

dnx::char_t appBaseBuffer[MAX_PATH];

Expand Down
2 changes: 1 addition & 1 deletion src/dnx/pal.win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ int CallApplicationMain(const wchar_t* moduleName, const char* functionName, CAL
{
trace_writer.write(std::wstring(L"Redirecting runtime to: ").append(runtime_new_path), true);
SetEnvironmentVariable(_T("DNX_DEFAULT_LIB"), runtime_new_path.c_str());
data->runtimeDirectory = runtime_new_path.c_str();

#if defined(CORECLR_WIN)
SetEnvironmentVariable(_T("CORECLR_DIR"), runtime_new_path.c_str());
data->runtimeDirectory = runtime_new_path.c_str();
#endif
}

Expand Down

0 comments on commit 05767f4

Please sign in to comment.