|
15 | 15 |
|
16 | 16 | #include <mono/metadata/components.h> |
17 | 17 |
|
| 18 | +#include <corehost/host_runtime_contract.h> |
| 19 | + |
18 | 20 | static MonoCoreTrustedPlatformAssemblies *trusted_platform_assemblies; |
19 | 21 | static MonoCoreLookupPaths *native_lib_paths; |
20 | 22 | static MonoCoreLookupPaths *app_paths; |
@@ -187,26 +189,39 @@ parse_properties (int propertyCount, const char **propertyKeys, const char **pro |
187 | 189 | // A partial list of relevant properties is at: |
188 | 190 | // https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting#step-3---prepare-runtime-properties |
189 | 191 |
|
| 192 | + PInvokeOverrideFn override_fn = NULL; |
190 | 193 | for (int i = 0; i < propertyCount; ++i) { |
191 | 194 | 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)) { |
193 | 196 | 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)) { |
195 | 198 | 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)) { |
197 | 200 | 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)) { |
199 | 202 | 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 | + } |
203 | 214 | } else { |
204 | 215 | #if 0 |
205 | 216 | // can't use mono logger, it's not initialized yet. |
206 | 217 | printf ("\t Unprocessed property %03d '%s': <%s>\n", i, propertyKeys[i], propertyValues[i]); |
207 | 218 | #endif |
208 | 219 | } |
209 | 220 | } |
| 221 | + |
| 222 | + if (override_fn != NULL) |
| 223 | + mono_loader_install_pinvoke_override (override_fn); |
| 224 | + |
210 | 225 | return TRUE; |
211 | 226 | } |
212 | 227 |
|
|
0 commit comments