4#include <coreclr_delegates.h>
9# include <libloaderapi.h>
10# define c_dlopen LoadLibraryW
11# define c_dlclose FreeLibrary
12# define c_dlsym GetProcAddress
15# define c_dlopen(f) dlopen(f, RTLD_LAZY | RTLD_LOCAL)
16# define c_dlclose dlclose
20static get_function_pointer_fn s_get_function_pointer;
22static hostfxr_handle s_hostfxr;
24int mllif::init(
const char_t *runtimeConfigPath,
const char_t *assemblyPath) {
25 static char_t buffer[8192];
28 size_t size =
sizeof buffer;
29 if (r = get_hostfxr_path(buffer, &size,
nullptr)) {
35 auto initr =
reinterpret_cast<hostfxr_initialize_for_runtime_config_fn
>(
c_dlsym(s_dl,
"hostfxr_initialize_for_runtime_config"));
40 auto get_delegate =
reinterpret_cast<hostfxr_get_runtime_delegate_fn
>(
c_dlsym(s_dl,
"hostfxr_get_runtime_delegate"));
45 if (r = initr(runtimeConfigPath,
nullptr, &s_hostfxr)) {
49 load_assembly_fn load_assembly =
nullptr;
50 if (r = get_delegate(s_hostfxr, hdt_load_assembly, (
void **)&load_assembly)) {
53 if (r = load_assembly(assemblyPath,
nullptr,
nullptr)) {
56 if (r = get_delegate(s_hostfxr, hdt_get_function_pointer, (
void **)&s_get_function_pointer)) {
int init(const char *runtimeConfigPath, const char *assemblyPath)