@@ -70,6 +70,12 @@ namespace envvar
70
70
71
71
// Variable used to preload a mock hostpolicy for testing.
72
72
const char_t * mockHostPolicy = W(" MOCK_HOSTPOLICY" );
73
+
74
+ // Variable used to indicate how app assemblies should be provided to the runtime
75
+ // - PROPERTY: corerun will pass the paths vias the TRUSTED_PLATFORM_ASSEMBLIES property
76
+ // - EXTERNAL: corerun will pass an external assembly probe to the runtime for app assemblies
77
+ // - Not set: same as PROPERTY
78
+ const char_t * appAssemblies = W(" APP_ASSEMBLIES" );
73
79
}
74
80
75
81
static void wait_for_debugger ()
@@ -242,6 +248,37 @@ size_t HOST_CONTRACT_CALLTYPE get_runtime_property(
242
248
return -1 ;
243
249
}
244
250
251
+ // Paths for external assembly probe
252
+ static char * s_core_libs_path = nullptr ;
253
+ static char * s_core_root_path = nullptr ;
254
+
255
+ static bool HOST_CONTRACT_CALLTYPE external_assembly_probe (
256
+ const char * path,
257
+ void ** data_start,
258
+ int64_t * size)
259
+ {
260
+ // Get just the file name
261
+ const char * name = path;
262
+ const char * pos = strrchr (name, ' /' );
263
+ if (pos != NULL )
264
+ name = pos + 1 ;
265
+
266
+ // Try to map the file from our known app assembly paths
267
+ for (const char * dir : { s_core_libs_path, s_core_root_path })
268
+ {
269
+ if (dir == nullptr )
270
+ continue ;
271
+
272
+ std::string full_path = dir;
273
+ assert (full_path.back () == pal::dir_delim);
274
+ full_path.append (name);
275
+ if (pal::try_map_file_readonly (full_path.c_str (), data_start, size))
276
+ return true ;
277
+ }
278
+
279
+ return false ;
280
+ }
281
+
245
282
static int run (const configuration& config)
246
283
{
247
284
platform_specific_actions actions;
@@ -295,7 +332,37 @@ static int run(const configuration& config)
295
332
native_search_dirs << core_root << pal::env_path_delim;
296
333
}
297
334
298
- string_t tpa_list = build_tpa (core_root, core_libs);
335
+ string_t tpa_list;
336
+ string_t app_assemblies_env = pal::getenv (envvar::appAssemblies);
337
+ bool use_external_assembly_probe = false ;
338
+ if (app_assemblies_env.empty () || app_assemblies_env == W (" PROPERTY" ))
339
+ {
340
+ // Use the TRUSTED_PLATFORM_ASSEMBLIES property to pass the app assemblies to the runtime.
341
+ tpa_list = build_tpa (core_root, core_libs);
342
+ }
343
+ else if (app_assemblies_env == W (" EXTERNAL" ))
344
+ {
345
+ // Use the external assembly probe to load assemblies from the app assembly paths.
346
+ use_external_assembly_probe = true ;
347
+ if (!core_libs.empty ())
348
+ {
349
+ pal::string_utf8_t core_libs_utf8 = pal::convert_to_utf8 (core_libs.c_str ());
350
+ s_core_libs_path = (char *)::malloc (core_libs_utf8.length () + 1 );
351
+ ::strcpy (s_core_libs_path, core_libs_utf8.c_str());
352
+ }
353
+
354
+ if (!core_root.empty ())
355
+ {
356
+ pal::string_utf8_t core_root_utf8 = pal::convert_to_utf8 (core_root.c_str ());
357
+ s_core_root_path = (char *)::malloc (core_root_utf8.length () + 1 );
358
+ ::strcpy (s_core_root_path, core_root_utf8.c_str());
359
+ }
360
+ }
361
+ else
362
+ {
363
+ pal::fprintf (stderr, W (" Unknown value for APP_ASSEMBLIES environment variable: %s\n " ), app_assemblies_env.c_str ());
364
+ return -1 ;
365
+ }
299
366
300
367
{
301
368
// Load hostpolicy if requested.
@@ -376,7 +443,8 @@ static int run(const configuration& config)
376
443
(void *)&config,
377
444
&get_runtime_property,
378
445
nullptr ,
379
- nullptr };
446
+ nullptr ,
447
+ use_external_assembly_probe ? &external_assembly_probe : nullptr };
380
448
propertyKeys.push_back (HOST_PROPERTY_RUNTIME_CONTRACT);
381
449
std::stringstream ss;
382
450
ss << " 0x" << std::hex << (size_t )(&host_contract);
@@ -457,6 +525,8 @@ static int run(const configuration& config)
457
525
if (exit_code != -1 )
458
526
exit_code = latched_exit_code;
459
527
528
+ ::free ((void *)s_core_libs_path);
529
+ ::free ((void *)s_core_root_path);
460
530
return exit_code;
461
531
}
462
532
0 commit comments