Esempio n. 1
0
int execute_app(
    const pal::string_t& impl_dll_dir,
    corehost_init_t* init,
    const int argc,
    const pal::char_t* argv[])
{
    pal::dll_t corehost;
    corehost_main_fn host_main = nullptr;
    corehost_load_fn host_load = nullptr;
    corehost_unload_fn host_unload = nullptr;

    int code = load_host_library(impl_dll_dir, &corehost, &host_load, &host_main, &host_unload);
    if (code != StatusCode::Success)
    {
        trace::error(_X("An error occurred while loading required library %s from [%s]"), LIBHOSTPOLICY_NAME, impl_dll_dir.c_str());
        return code;
    }

    // Previous hostfxr trace messages must be printed before calling trace::setup in hostpolicy
    trace::flush();

    const host_interface_t& intf = init->get_host_init_data();
    if ((code = host_load(&intf)) == 0)
    {
        code = host_main(argc, argv);
        (void)host_unload();
    }

    pal::unload_library(corehost);

    return code;
}
Esempio n. 2
0
int execute_app(
    const pal::string_t& impl_dll_dir,
    const corehost_init_t* init,
    const int argc,
    const pal::char_t* argv[])
{
    pal::dll_t corehost;
    corehost_main_fn host_main = nullptr;
    corehost_load_fn host_load = nullptr;
    corehost_unload_fn host_unload = nullptr;

    int code = load_host_library(impl_dll_dir, &corehost, &host_load, &host_main, &host_unload);

    if (code != StatusCode::Success)
    {
        trace::error(_X("Could not load host policy library [%s]"), impl_dll_dir.c_str());
        return code;
    }

    if ((code = host_load(init)) == 0)
    {
        code = host_main(argc, argv);
        (void)host_unload();
    }

    pal::unload_library(corehost);

    return code;
}
Esempio n. 3
0
int main(const int argc, const pal::char_t* argv[])
#endif
{
    setup_tracing();

    pal::dll_t corehost;

#ifdef COREHOST_PACKAGE_SERVICING
    // No custom host asked, so load the corehost if serviced first.
    pal::string_t svc_dir;
    if (pal::getenv(_X("DOTNET_SERVICING"), &svc_dir))
    {
        pal::string_t path = svc_dir;
        append_path(&path, COREHOST_PACKAGE_NAME);
        append_path(&path, COREHOST_PACKAGE_VERSION);
        append_path(&path, COREHOST_PACKAGE_COREHOST_RELATIVE_DIR);

        corehost_main_fn host_main;
        StatusCode code = load_host_lib(path, &corehost, &host_main);
        if (code != StatusCode::Success)
        {
            trace::info(_X("Failed to load host library from servicing dir: %s; Status=%08X"), path.c_str(), code);
            // Ignore all errors for the servicing case, and proceed to the next step.
        }
        else
        {
            trace::info(_X("Calling host entrypoint from library at servicing dir %s"), path.c_str());
            return host_main(argc, argv);
        }
    }
#endif

    // Get current path to look for the library app locally.
    pal::string_t own_path;
    if (!pal::get_own_executable_path(&own_path) || !pal::realpath(&own_path))
    {
        trace::error(_X("Failed to locate current executable"));
        return StatusCode::CoreHostCurExeFindFailure;
    }

    // Local load of the corehost library.
    auto own_dir = get_directory(own_path);

    corehost_main_fn host_main;
    StatusCode code = load_host_lib(own_dir, &corehost, &host_main);
    switch (code)
    {
    // Success, call the entrypoint.
    case StatusCode::Success:
        trace::info(_X("Calling host entrypoint from library at own dir %s"), own_dir.c_str());
        return host_main(argc, argv);

    // DLL missing is not fatal.
    case StatusCode::CoreHostLibMissingFailure:
        trace::info(_X("Calling statically linked entrypoint from own exe"));
        return corehost_main(argc, argv);

    // Some other fatal error.
    default:
        trace::error(_X("Error loading the host library from own dir: %s; Status=%08X"), own_dir.c_str(), code);
        return code;
    }
}