Skip to content

Commit da5bd2b

Browse files
authored
Stop setting separate properties for BUNDLE_PROBE, HOSTPOLICY_EMBEDDED, PINVOKE_OVERRIDE (#92448)
1 parent c6fcf2e commit da5bd2b

File tree

9 files changed

+29
-66
lines changed

9 files changed

+29
-66
lines changed

docs/design/features/host-runtime-information.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ List of directory paths corresponding to shared store paths and additional probi
8484

8585
Hex string representation of a function pointer. It is set when running a single-file application. The function is called by the runtime to look for assemblies bundled into the application. The expected signature is defined as `BundleProbeFn` in [`coreclrhost.h`](/src/coreclr/hosts/inc/coreclrhost.h)
8686

87+
**.NET 9 and above** This property is no longer set by the host. `host_runtime_contract.bundle_probe` is set when running a single-file application.
88+
8789
`HOSTPOLICY_EMBEDDED`
8890

8991
Indicates whether or not [`hostpolicy`](./host-components.md#host-policy) is embedded in the host executable. It is set to `true` when running a self-contained single-file application.
9092

93+
**.NET 9 and above** This property is no longer set by the host or read by the runtime. Self-contained single-file includes both host and runtime components in the executable, so the information is known at build-time.
94+
9195
`PINVOKE_OVERRIDE`
9296

9397
Hex string representation of a function pointer. It is set when running a self-contained single-file application. The function is called by the runtime to check for redirected p/invokes. The expected signature is defined as `PInvokeOverrideFn` in [`coreclrhost.h`](/src/coreclr/hosts/inc/coreclrhost.h) and [`mono-private-unstable-types.h`](/src/native/public/mono/metadata/details/mono-private-unstable-types.h).
98+
99+
**.NET 9 and above** This property is no longer set by the host. `host_runtime_contract.pinvoke_override` is set when running a self-contained single-file application.

src/coreclr/dlls/mscoree/exports.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ static void ConvertConfigPropertiesToUnicode(
138138
LPCWSTR** propertyValuesWRef,
139139
BundleProbeFn** bundleProbe,
140140
PInvokeOverrideFn** pinvokeOverride,
141-
bool* hostPolicyEmbedded,
142141
host_runtime_contract** hostContract)
143142
{
144143
LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount];
@@ -170,11 +169,6 @@ static void ConvertConfigPropertiesToUnicode(
170169
if (*pinvokeOverride == nullptr)
171170
*pinvokeOverride = (PInvokeOverrideFn*)u16_strtoui64(propertyValuesW[propertyIndex], nullptr, 0);
172171
}
173-
else if (strcmp(propertyKeys[propertyIndex], HOST_PROPERTY_HOSTPOLICY_EMBEDDED) == 0)
174-
{
175-
// The HOSTPOLICY_EMBEDDED property indicates if the executable has hostpolicy statically linked in
176-
*hostPolicyEmbedded = (u16_strcmp(propertyValuesW[propertyIndex], W("true")) == 0);
177-
}
178172
else if (strcmp(propertyKeys[propertyIndex], HOST_PROPERTY_RUNTIME_CONTRACT) == 0)
179173
{
180174
// Host contract is passed in as the value of HOST_RUNTIME_CONTRACT property (encoded as a string).
@@ -252,7 +246,6 @@ int coreclr_initialize(
252246
LPCWSTR* propertyKeysW;
253247
LPCWSTR* propertyValuesW;
254248
BundleProbeFn* bundleProbe = nullptr;
255-
bool hostPolicyEmbedded = false;
256249
PInvokeOverrideFn* pinvokeOverride = nullptr;
257250
host_runtime_contract* hostContract = nullptr;
258251

@@ -268,7 +261,6 @@ int coreclr_initialize(
268261
&propertyValuesW,
269262
&bundleProbe,
270263
&pinvokeOverride,
271-
&hostPolicyEmbedded,
272264
&hostContract);
273265

274266
#ifdef TARGET_UNIX
@@ -283,8 +275,6 @@ int coreclr_initialize(
283275
}
284276
#endif
285277

286-
g_hostpolicy_embedded = hostPolicyEmbedded;
287-
288278
if (hostContract != nullptr)
289279
{
290280
HostInformation::SetContract(hostContract);

src/coreclr/vm/ceemain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,12 @@ extern "C" HRESULT __cdecl CorDBGetInterface(DebugInterface** rcInterface);
224224

225225
// g_coreclr_embedded indicates that coreclr is linked directly into the program
226226
// g_hostpolicy_embedded indicates that the hostpolicy library is linked directly into the executable
227-
// Note: that it can happen that the hostpolicy is embedded but coreclr isn't (on Windows singlefilehost is built that way)
228227
#ifdef CORECLR_EMBEDDED
229228
bool g_coreclr_embedded = true;
230229
bool g_hostpolicy_embedded = true; // We always embed hostpolicy if coreclr is also embedded
231230
#else
232231
bool g_coreclr_embedded = false;
233-
bool g_hostpolicy_embedded = false; // In this case the value may come from a runtime property and may change
232+
bool g_hostpolicy_embedded = false;
234233
#endif
235234

236235
// Remember how the last startup of EE went.

src/mono/mono/mini/monovm.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <mono/metadata/components.h>
1717

18+
#include <corehost/host_runtime_contract.h>
19+
1820
static MonoCoreTrustedPlatformAssemblies *trusted_platform_assemblies;
1921
static MonoCoreLookupPaths *native_lib_paths;
2022
static MonoCoreLookupPaths *app_paths;
@@ -187,26 +189,39 @@ parse_properties (int propertyCount, const char **propertyKeys, const char **pro
187189
// A partial list of relevant properties is at:
188190
// https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting#step-3---prepare-runtime-properties
189191

192+
PInvokeOverrideFn override_fn = NULL;
190193
for (int i = 0; i < propertyCount; ++i) {
191194
size_t prop_len = strlen (propertyKeys [i]);
192-
if (prop_len == 27 && !strncmp (propertyKeys [i], "TRUSTED_PLATFORM_ASSEMBLIES", 27)) {
195+
if (prop_len == 27 && !strncmp (propertyKeys [i], HOST_PROPERTY_TRUSTED_PLATFORM_ASSEMBLIES, 27)) {
193196
parse_trusted_platform_assemblies (propertyValues[i]);
194-
} else if (prop_len == 9 && !strncmp (propertyKeys [i], "APP_PATHS", 9)) {
197+
} else if (prop_len == 9 && !strncmp (propertyKeys [i], HOST_PROPERTY_APP_PATHS, 9)) {
195198
app_paths = parse_lookup_paths (propertyValues [i]);
196-
} else if (prop_len == 23 && !strncmp (propertyKeys [i], "PLATFORM_RESOURCE_ROOTS", 23)) {
199+
} else if (prop_len == 23 && !strncmp (propertyKeys [i], HOST_PROPERTY_PLATFORM_RESOURCE_ROOTS, 23)) {
197200
platform_resource_roots = parse_lookup_paths (propertyValues [i]);
198-
} else if (prop_len == 29 && !strncmp (propertyKeys [i], "NATIVE_DLL_SEARCH_DIRECTORIES", 29)) {
201+
} else if (prop_len == 29 && !strncmp (propertyKeys [i], HOST_PROPERTY_NATIVE_DLL_SEARCH_DIRECTORIES, 29)) {
199202
native_lib_paths = parse_lookup_paths (propertyValues [i]);
200-
} else if (prop_len == 16 && !strncmp (propertyKeys [i], "PINVOKE_OVERRIDE", 16)) {
201-
PInvokeOverrideFn override_fn = (PInvokeOverrideFn)(uintptr_t)strtoull (propertyValues [i], NULL, 0);
202-
mono_loader_install_pinvoke_override (override_fn);
203+
} else if (prop_len == 16 && !strncmp (propertyKeys [i], HOST_PROPERTY_PINVOKE_OVERRIDE, 16)) {
204+
if (override_fn == NULL) {
205+
override_fn = (PInvokeOverrideFn)(uintptr_t)strtoull (propertyValues [i], NULL, 0);
206+
}
207+
} else if (prop_len == STRING_LENGTH(HOST_PROPERTY_RUNTIME_CONTRACT) && !strncmp (propertyKeys [i], HOST_PROPERTY_RUNTIME_CONTRACT, STRING_LENGTH(HOST_PROPERTY_RUNTIME_CONTRACT))) {
208+
// Functions in HOST_RUNTIME_CONTRACT have priority over the individual properties
209+
// for callbacks, so we set them as long as the contract has a non-null function.
210+
struct host_runtime_contract* contract = (struct host_runtime_contract*)(uintptr_t)strtoull (propertyValues [i], NULL, 0);
211+
if (contract->pinvoke_override != NULL) {
212+
override_fn = (PInvokeOverrideFn)contract->pinvoke_override;
213+
}
203214
} else {
204215
#if 0
205216
// can't use mono logger, it's not initialized yet.
206217
printf ("\t Unprocessed property %03d '%s': <%s>\n", i, propertyKeys[i], propertyValues[i]);
207218
#endif
208219
}
209220
}
221+
222+
if (override_fn != NULL)
223+
mono_loader_install_pinvoke_override (override_fn);
224+
210225
return TRUE;
211226
}
212227

src/native/corehost/apphost/static/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ set(HEADERS
3636
add_definitions(-D_NO_ASYNCRTIMP)
3737
add_definitions(-D_NO_PPLXIMP)
3838
remove_definitions(-DEXPORT_SHARED_API)
39-
add_definitions(-DHOSTPOLICY_EMBEDDED)
4039
add_definitions(-DNATIVE_LIBS_EMBEDDED)
4140

42-
4341
include(../../fxr/files.cmake)
4442
include(../../hostpolicy/files.cmake)
4543
include(../../hostcommon/files.cmake)

src/native/corehost/host_runtime_contract.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define HOST_PROPERTY_APP_PATHS "APP_PATHS"
1919
#define HOST_PROPERTY_BUNDLE_PROBE "BUNDLE_PROBE"
2020
#define HOST_PROPERTY_ENTRY_ASSEMBLY_NAME "ENTRY_ASSEMBLY_NAME"
21-
#define HOST_PROPERTY_HOSTPOLICY_EMBEDDED "HOSTPOLICY_EMBEDDED"
2221
#define HOST_PROPERTY_NATIVE_DLL_SEARCH_DIRECTORIES "NATIVE_DLL_SEARCH_DIRECTORIES"
2322
#define HOST_PROPERTY_PINVOKE_OVERRIDE "PINVOKE_OVERRIDE"
2423
#define HOST_PROPERTY_PLATFORM_RESOURCE_ROOTS "PLATFORM_RESOURCE_ROOTS"

src/native/corehost/hostpolicy/coreclr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ namespace
166166
_X("STARTUP_HOOKS"),
167167
_X("APP_PATHS"),
168168
_X("RUNTIME_IDENTIFIER"),
169-
_X("BUNDLE_PROBE"),
170-
_X("HOSTPOLICY_EMBEDDED"),
171-
_X("PINVOKE_OVERRIDE")
172169
};
173170

174171
static_assert((sizeof(PropertyNameMapping) / sizeof(*PropertyNameMapping)) == static_cast<size_t>(common_property::Last), "Invalid property count");

src/native/corehost/hostpolicy/coreclr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ enum class common_property
6464
StartUpHooks,
6565
AppPaths,
6666
RuntimeIdentifier,
67-
BundleProbe,
68-
HostPolicyEmbedded,
69-
PInvokeOverride,
7067
// Sentinel value - new values should be defined above
7168
Last
7269
};

src/native/corehost/hostpolicy/hostpolicy_context.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -329,44 +329,6 @@ int hostpolicy_context_t::initialize(const hostpolicy_init_t &hostpolicy_init, c
329329
coreclr_properties.add(common_property::StartUpHooks, startup_hooks.c_str());
330330
}
331331

332-
// Single-File Bundle Probe
333-
if (bundle::info_t::is_single_file_bundle())
334-
{
335-
// Encode the bundle_probe function pointer as a string, and pass it to the runtime.
336-
pal::stringstream_t ptr_stream;
337-
ptr_stream << "0x" << std::hex << (size_t)(&bundle_probe);
338-
339-
if (!coreclr_properties.add(common_property::BundleProbe, ptr_stream.str().c_str()))
340-
{
341-
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::BundleProbe));
342-
return StatusCode::LibHostDuplicateProperty;
343-
}
344-
}
345-
346-
#if defined(NATIVE_LIBS_EMBEDDED)
347-
// PInvoke Override
348-
if (bundle::info_t::is_single_file_bundle())
349-
{
350-
// Encode the pinvoke_override function pointer as a string, and pass it to the runtime.
351-
pal::stringstream_t ptr_stream;
352-
ptr_stream << "0x" << std::hex << (size_t)(&pinvoke_override);
353-
354-
if (!coreclr_properties.add(common_property::PInvokeOverride, ptr_stream.str().c_str()))
355-
{
356-
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::PInvokeOverride));
357-
return StatusCode::LibHostDuplicateProperty;
358-
}
359-
}
360-
#endif
361-
362-
#if defined(HOSTPOLICY_EMBEDDED)
363-
if (!coreclr_properties.add(common_property::HostPolicyEmbedded, _X("true")))
364-
{
365-
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::HostPolicyEmbedded));
366-
return StatusCode::LibHostDuplicateProperty;
367-
}
368-
#endif
369-
370332
{
371333
host_contract = { sizeof(host_runtime_contract), this };
372334
if (bundle::info_t::is_single_file_bundle())

0 commit comments

Comments
 (0)