From: Woongsuk Cho Date: Thu, 26 Mar 2020 04:53:26 +0000 (+0900) Subject: Use root path only for corerun mode. X-Git-Tag: accepted/tizen/unified/20200402.155646~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f03af56caaa54f41560746cfb7a85deb0b07c800;p=platform%2Fcore%2Fdotnet%2Flauncher.git Use root path only for corerun mode. In the current implementation, app's "/bin" and "/lib" path are set to app_path for coreclr_initialization(). So, when running corerun mode, there is a problem that the assembly in the same directory cannot be found, but rather, the assembly under "/bin" and "/lib" can be loaded. --- diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index e6d3bc7..890e5b7 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -279,7 +279,7 @@ CoreRuntime::CoreRuntime(const char* mode) : __coreclrLib(nullptr), __hostHandle(nullptr), __domainId(-1), - fd(0), + __fd(-1), __initialized(false), __isProfileMode(false) { @@ -317,7 +317,7 @@ CoreRuntime::~CoreRuntime() dispose(); } -int CoreRuntime::initialize(bool standalone, bool useDlog) +int CoreRuntime::initialize(bool standalone, bool useDlog, const char* corerunRoot) { // checkInjection checks dotnet-launcher run mode // At the moment, this mechanism is used only when the Memory Profiler is started. @@ -415,17 +415,31 @@ int CoreRuntime::initialize(bool standalone, bool useDlog) // To avoid gdbus blocking issue, below function should be called after fork() initEnvForSpecialFolder(); - fd = open("/proc/self", O_DIRECTORY); - std::string appRoot = std::string("/proc/self/fd/") + std::to_string(fd); - std::string appBin = concatPath(appRoot, "bin"); - std::string appLib = concatPath(appRoot, "lib"); - std::string appTac = concatPath(appBin, TAC_SYMLINK_SUB_DIR); - std::string probePath = appBin + ":" + appLib + ":" + appTac; - std::string NIprobePath = concatPath(appBin, APP_NI_SUB_DIR) + ":" + concatPath(appLib, APP_NI_SUB_DIR) + ":" + appTac; std::string tpa = getTPA(); std::string runtimeDir = getRuntimeDir(); - std::string nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appBin + ":" + appLib + ":" + __nativeLibDirectory + ":" + runtimeDir; std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid()); + std::string probePath; + std::string NIprobePath; + std::string nativeLibPath; + + if (corerunRoot) { + probePath = corerunRoot; + NIprobePath = corerunRoot; + nativeLibPath = corerunRoot; + } else { + __fd = open("/proc/self", O_DIRECTORY); + if (__fd < 0) { + _ERR("Failed to open /proc/self"); + return -1; + } + std::string appRoot = std::string("/proc/self/fd/") + std::to_string(__fd); + std::string appBin = concatPath(appRoot, "bin"); + std::string appLib = concatPath(appRoot, "lib"); + std::string appTac = concatPath(appBin, TAC_SYMLINK_SUB_DIR); + probePath = appRoot + ":" + appBin + ":" + appLib + ":" + appTac; + NIprobePath = concatPath(appBin, APP_NI_SUB_DIR) + ":" + concatPath(appLib, APP_NI_SUB_DIR) + ":" + appTac; + nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appBin + ":" + appLib + ":" + __nativeLibDirectory + ":" + runtimeDir; + } if (!initializeCoreClr(appName.c_str(), probePath.c_str(), NIprobePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) { _ERR("Failed to initialize coreclr"); @@ -556,10 +570,13 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i pluginSetAppInfo(appId, path); - int fd2 = open(root, O_DIRECTORY); - dup3(fd2, fd, O_CLOEXEC); - if (fd2 >= 0) - close(fd2); + // override root path for application launch mode (candidate / standalone mode) + if (__fd >= 0) { + int fd2 = open(root, O_DIRECTORY); + dup3(fd2, __fd, O_CLOEXEC); + if (fd2 >= 0) + close(fd2); + } // set application data path to coreclr environment. // application data path can be changed by owner. So, we have to set data path just before launching. diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index 3a06ab0..f5cedc9 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -30,7 +30,7 @@ class CoreRuntime public: CoreRuntime(const char* mode); ~CoreRuntime(); - int initialize(bool standalone, bool useDlog); + int initialize(bool standalone, bool useDlog, const char* corerunRoot); void dispose(); int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]); @@ -47,7 +47,7 @@ class CoreRuntime void* __coreclrLib; void* __hostHandle; unsigned int __domainId; - int fd; + int __fd; bool __initialized; bool __isProfileMode; diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 3645320..755a82b 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -80,7 +80,7 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) snprintf(appId, 16, "%s", "dotnet-launcher"); appRoot = baseName(argv[1]); - if (runtime->initialize(true, false) != 0) { + if (runtime->initialize(true, false, appRoot.c_str()) != 0) { _ERR("Failed to initialize"); return 1; } @@ -107,7 +107,7 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) } _INFO("AUL_APPID : %s", appId); - if (runtime->initialize(true, true) != 0) { + if (runtime->initialize(true, true, NULL) != 0) { _ERR("Failed to initialize"); return 1; } @@ -131,7 +131,7 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) } Launchpad.onCreate = [&runtime]() { - if (runtime->initialize(false, true) != 0) { + if (runtime->initialize(false, true, NULL) != 0) { _ERR("Failed to initialized"); } else { _INFO("Success to initialized");