extern "C" int CallApplicationMain(CALL_APPLICATION_MAIN_DATA* data) { if (LoadCoreClr(data->runtimeDirectory) != 0) { return 1; } int result = 0; MultiByteToWideChar = (MultiByteToWideChar_fn)dlsym(pLibCoreClr, "MultiByteToWideChar"); if (!MultiByteToWideChar) { fprintf(stderr, "Could not find MultiByteToWideChar entrypoint in coreclr\n"); result = 1; } else { result = CallMain(data); } FreeCoreClr(); return result; }
extern "C" HRESULT CallApplicationMain(PCALL_APPLICATION_MAIN_DATA data) { HRESULT hr = S_OK; size_t cchTrustedPlatformAssemblies = 0; std::string runtimeDirectory; if (data->runtimeDirectory) { runtimeDirectory = data->runtimeDirectory; } else { // TODO: This should get the directory that this library is in, not the CWD. char szCurrentDirectory[PATH_MAX]; if (!getcwd(szCurrentDirectory, PATH_MAX)) { return E_FAIL; } runtimeDirectory = std::string(szCurrentDirectory); } std::string coreClrDirectory; LoadCoreClr(coreClrDirectory); if (!pLibCoreClr) { char* error = dlerror(); fprintf(stderr, "failed to locate libcoreclr with error %s\n", error); FreeCoreClr(); return E_FAIL; } const char* property_keys[] = { "APPBASE", "TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", }; std::string trustedPlatformAssemblies; // Try native images first if (!GetTrustedPlatformAssembliesList(coreClrDirectory.c_str(), true, trustedPlatformAssemblies)) { if (!GetTrustedPlatformAssembliesList(coreClrDirectory.c_str(), false, trustedPlatformAssemblies)) { fprintf(stderr, "Failed to find files in the coreclr directory\n"); FreeCoreClr(); return E_FAIL; } } // Add the assembly containing the app domain manager to the trusted list trustedPlatformAssemblies.append(runtimeDirectory); trustedPlatformAssemblies.append("dnx.coreclr.managed.dll"); std::string appPaths(runtimeDirectory); appPaths.append(":"); appPaths.append(coreClrDirectory); appPaths.append(":"); const char* property_values[] = { // APPBASE data->applicationBase, // TRUESTED_PLATFORM_ASSEMBLIES trustedPlatformAssemblies.c_str(), // APP_PATHS appPaths.c_str(), }; ExecuteAssemblyFunction executeAssembly = (ExecuteAssemblyFunction)dlsym(pLibCoreClr, "ExecuteAssembly"); if (!executeAssembly) { fprintf(stderr, "Could not find ExecuteAssembly entrypoint in coreclr.\n"); FreeCoreClr(); return E_FAIL; } setenv("DNX_FRAMEWORK", "dnxcore50", 1); std::string coreClrDllPath(coreClrDirectory); coreClrDllPath.append("/"); coreClrDllPath.append(LIBCORECLR_NAME); std::string pathToBootstrapper = GetPathToBootstrapper(); hr = executeAssembly(pathToBootstrapper.c_str(), coreClrDllPath.c_str(), "dnx.coreclr.managed", sizeof(property_keys) / sizeof(property_keys[0]), property_keys, property_values, data->argc, (const char**)data->argv, nullptr, "dnx.coreclr.managed, Version=0.1.0.0", "DomainManager", "Execute", (DWORD*)&(data->exitcode)); FreeCoreClr(); return hr; }