Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass system path from host #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/coreclr/src/dlls/mscoree/mscoree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "shimload.h"
#include "metadataexports.h"
#include "ex.h"
#include "bundle.h"

#include <dbgenginemetrics.h>

Expand Down Expand Up @@ -336,8 +337,16 @@ STDAPI GetCORSystemDirectoryInternaL(SString& pBuffer)
}

#else

if (!PAL_GetPALDirectoryWrapper(pBuffer)) {
if (Bundle::AppIsBundle() && !Bundle::AppBundle->SystemPath().IsEmpty())
{
EX_TRY
{
pBuffer = Bundle::AppBundle->SystemPath();
}
EX_CATCH_HRESULT(hr);
}
else if (hr == S_OK && !PAL_GetPALDirectoryWrapper(pBuffer))
{
hr = HRESULT_FROM_GetLastError();
}
#endif
Expand Down
17 changes: 14 additions & 3 deletions src/coreclr/src/dlls/mscoree/unixinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ static void ConvertConfigPropertiesToUnicode(
LPCWSTR** propertyKeysWRef,
LPCWSTR** propertyValuesWRef,
BundleProbe** bundleProbe,
bool* hostPolicyEmbedded)
bool* hostPolicyEmbedded,
LPCWSTR* systemPath)
{
LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount];
ASSERTE_ALL_BUILDS(propertyKeysW != nullptr);
Expand All @@ -144,6 +145,14 @@ static void ConvertConfigPropertiesToUnicode(
// The HOSTPOLICY_EMBEDDED property indicates if the executable has hostpolicy statically linked in
*hostPolicyEmbedded = (wcscmp(propertyValuesW[propertyIndex], W("true")) == 0);
}
else if (strcmp(propertyKeys[propertyIndex], "SYSTEM_PATH") == 0)
{
// This is set by the host if the correct system path can't be determined by looking at the location
// of the runtime module itself. This is the case when the runtime is linked into the single file host
// so there's no coreclr library itself and the entire bundle is extracted onto disk - so for example
// System.Private.CoreLib doesn't exist "next" to the runtime.
*systemPath = propertyValuesW[propertyIndex];
}
}

*propertyKeysWRef = propertyKeysW;
Expand Down Expand Up @@ -187,6 +196,7 @@ int coreclr_initialize(
LPCWSTR* propertyValuesW;
BundleProbe* bundleProbe = nullptr;
bool hostPolicyEmbedded = false;
LPCWSTR systemPath = nullptr;

ConvertConfigPropertiesToUnicode(
propertyKeys,
Expand All @@ -195,7 +205,8 @@ int coreclr_initialize(
&propertyKeysW,
&propertyValuesW,
&bundleProbe,
&hostPolicyEmbedded);
&hostPolicyEmbedded,
&systemPath);

#ifdef TARGET_UNIX
DWORD error = PAL_InitializeCoreCLR(exePath, g_coreclr_embedded);
Expand All @@ -220,7 +231,7 @@ int coreclr_initialize(

if (bundleProbe != nullptr)
{
static Bundle bundle(StringToUnicode(exePath), bundleProbe);
static Bundle bundle(StringToUnicode(exePath), systemPath, bundleProbe);
Bundle::AppBundle = &bundle;
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/src/inc/bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ typedef bool(__stdcall BundleProbe)(LPCWSTR, INT64*, INT64*);
class Bundle
{
public:
Bundle(LPCWSTR bundlePath, BundleProbe *probe);
Bundle(LPCWSTR bundlePath, LPCWSTR systemPath, BundleProbe *probe);
BundleFileLocation Probe(LPCWSTR path, bool pathIsBundleRelative = false) const;

const SString &Path() const { LIMITED_METHOD_CONTRACT; return m_path; }
const SString &BasePath() const { LIMITED_METHOD_CONTRACT; return m_basePath; }
const SString &SystemPath() const { LIMITED_METHOD_CONTRACT; return m_systemPath; }

static Bundle* AppBundle; // The BundleInfo for the current app, initialized by coreclr_initialize.
static bool AppIsBundle() { LIMITED_METHOD_CONTRACT; return AppBundle != nullptr; }
Expand All @@ -52,6 +53,7 @@ class Bundle
private:

SString m_path; // The path to single-file executable
SString m_systemPath; // The system path if this needs to be different from the exe path above (otherwise empty)
BundleProbe *m_probe;

SString m_basePath; // The prefix to denote a path within the bundle
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/vm/bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ const SString &BundleFileLocation::Path() const
return Bundle::AppBundle->Path();
}

Bundle::Bundle(LPCWSTR bundlePath, BundleProbe *probe)
Bundle::Bundle(LPCWSTR bundlePath, LPCWSTR systemPath, BundleProbe *probe)
{
STANDARD_VM_CONTRACT;

_ASSERTE(probe != nullptr);

m_path.Set(bundlePath);
m_systemPath.Set(systemPath);
m_probe = probe;

// The bundle-base path is the directory containing the single-file bundle.
Expand Down
3 changes: 2 additions & 1 deletion src/installer/corehost/cli/hostpolicy/coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ namespace
_X("APP_NI_PATHS"),
_X("RUNTIME_IDENTIFIER"),
_X("BUNDLE_PROBE"),
_X("HOSTPOLICY_EMBEDDED")
_X("HOSTPOLICY_EMBEDDED"),
_X("SYSTEM_PATH")
};

static_assert((sizeof(PropertyNameMapping) / sizeof(*PropertyNameMapping)) == static_cast<size_t>(common_property::Last), "Invalid property count");
Expand Down
1 change: 1 addition & 0 deletions src/installer/corehost/cli/hostpolicy/coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum class common_property
RuntimeIdentifier,
BundleProbe,
HostPolicyEmbedded,
SystemPath,
// Sentinel value - new values should be defined above
Last
};
Expand Down
16 changes: 14 additions & 2 deletions src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,27 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a

if (!coreclr_properties.add(common_property::BundleProbe, ptr_stream.str().c_str()))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::BundleProbe));
return StatusCode::LibHostDuplicateProperty;
}

// In the case where everything is extracted onto disk, set the system path to the extraction directory
// This is important if the runtime is compiled into the host, in which case it would have no way to detect
// the extraction directory.
if (bundle::runner_t::app()->is_netcoreapp3_compat_mode())
{
if (!coreclr_properties.add(common_property::SystemPath, app_base.c_str()))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::SystemPath));
return StatusCode::LibHostDuplicateProperty;
}
}
}

#if defined(HOSTPOLICY_EMBEDDED)
if (!coreclr_properties.add(common_property::HostPolicyEmbedded, _X("true")))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::HostPolicyEmbedded));
return StatusCode::LibHostDuplicateProperty;
}
#endif
Expand Down