SHARED_API int hostfxr_main(const int argc, const pal::char_t* argv[]) { trace::setup(); pal::string_t own_dir; auto mode = detect_operating_mode(argc, argv, &own_dir); switch (mode) { case muxer: { trace::info(_X("Host operating in Muxer mode")); fx_muxer_t muxer; return muxer.execute(argc, argv); } case split_fx: { trace::info(_X("Host operating in split mode; own dir=[%s]"), own_dir.c_str()); corehost_init_t init(_X(""), _X(""), own_dir, host_mode_t::split_fx, nullptr); return execute_app(own_dir, &init, argc, argv); } case standalone: { trace::info(_X("Host operating from standalone app dir %s"), own_dir.c_str()); pal::string_t svc_dir; corehost_init_t init(_X(""), _X(""), _X(""), host_mode_t::standalone, nullptr); return execute_app( hostpolicy_exists_in_svc(&svc_dir) ? svc_dir : own_dir, &init, argc, argv); } default: trace::error(_X("Unknown mode detected or could not resolve the mode.")); return StatusCode::CoreHostResolveModeFailure; } }
/** * Given own location, FX location, app binary and specified --depsfile and probe paths * return location that is expected to contain hostpolicy */ bool fx_muxer_t::resolve_hostpolicy_dir(host_mode_t mode, const pal::string_t& own_dir, const pal::string_t& fx_dir, const pal::string_t& app_candidate, const pal::string_t& specified_deps_file, const pal::string_t& specified_fx_version, const std::vector<pal::string_t>& probe_realpaths, const runtime_config_t& config, pal::string_t* impl_dir) { // Obtain deps file for the given configuration. pal::string_t resolved_deps = get_deps_file(fx_dir, app_candidate, specified_deps_file, config); // Resolve hostpolicy version out of the deps file. pal::string_t version = resolve_hostpolicy_version_from_deps(resolved_deps); if (trace::is_enabled() && version.empty() && pal::file_exists(resolved_deps)) { trace::warning(_X("Dependency manifest %s does not contain an entry for %s"), resolved_deps.c_str(), _STRINGIFY(HOST_POLICY_PKG_NAME)); } // Check if the given version of the hostpolicy exists in servicing. if (hostpolicy_exists_in_svc(version, impl_dir)) { return true; } // Get the expected directory that would contain hostpolicy. pal::string_t expected; if (config.get_portable()) { if (!pal::directory_exists(fx_dir)) { pal::string_t fx_version = specified_fx_version.empty() ? config.get_fx_version() : specified_fx_version; handle_missing_framework_error(config.get_fx_name(), fx_version, fx_dir); return false; } expected = fx_dir; } else { // Standalone apps can be activated by muxer or by standalone host or "corehost" // 1. When activated with dotnet.exe or corehost.exe, check for hostpolicy in the deps dir or // app dir. // 2. When activated with app.exe, the standalone host, check own directory. assert(mode == host_mode_t::muxer || mode == host_mode_t::standalone || mode == host_mode_t::split_fx); expected = (mode == host_mode_t::standalone) ? own_dir : get_directory(specified_deps_file.empty() ? app_candidate : specified_deps_file); } // Check if hostpolicy exists in "expected" directory. trace::verbose(_X("The expected %s directory is [%s]"), LIBHOSTPOLICY_NAME, expected.c_str()); if (library_exists_in_dir(expected, LIBHOSTPOLICY_NAME, nullptr)) { impl_dir->assign(expected); return true; } trace::verbose(_X("The %s was not found in [%s]"), LIBHOSTPOLICY_NAME, expected.c_str()); // Start probing for hostpolicy in the specified probe paths. pal::string_t candidate; if (resolve_hostpolicy_dir_from_probe_paths(version, probe_realpaths, &candidate)) { impl_dir->assign(candidate); return true; } // If it still couldn't be found, somebody upstack messed up. Flag an error for the "expected" location. trace::error(_X("A fatal error was encountered. The library '%s' required to execute the application was not found in '%s'."), LIBHOSTPOLICY_NAME, expected.c_str()); return false; }