Add plugin API for setting extra dll path (#353)
author조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Wed, 5 Jan 2022 04:32:46 +0000 (13:32 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 5 Jan 2022 04:32:46 +0000 (13:32 +0900)
There is a requirement to add a searching path for a specific app.
For this requirement, a new plugin API is added to get the extra searching path.

NativeLauncher/dotnet-plugin/dotnet_plugin.cc
NativeLauncher/inc/dotnet_launcher_plugin.h
NativeLauncher/inc/path_manager.h
NativeLauncher/inc/plugin_manager.h
NativeLauncher/launcher/lib/core_runtime.cc
NativeLauncher/tool/ni_common.cc
NativeLauncher/util/path_manager.cc
NativeLauncher/util/plugin_manager.cc

index 539d5ae3b201e01d0bf7f67547832919a13f1d77..d101f2a73168e011edd0258adbc1c67ff24c4709 100644 (file)
@@ -51,6 +51,12 @@ char* plugin_get_dll_path()
        return "";\r
 }\r
 \r
+char* plugin_get_extra_dll_path()\r
+{\r
+       _SOUT("### plugin_get_extra_dll_path called");\r
+       return "/tmp";\r
+}\r
+\r
 char* plugin_get_native_dll_searching_path()\r
 {\r
        _SOUT("### plugin_get_native_dll_searching_path called");\r
index 517bbb1672b6007c383163ec7ef8bc279ef12672..9385485e01c443bf1ca0590682accaa895dcf6f5 100644 (file)
@@ -63,6 +63,12 @@ extern "C"
         */
        char* plugin_get_dll_path();
 
+       /**
+        * @brief return additional pathes to find app assembly.
+        * @return ":" seperated pathes
+        */
+       char* plugin_get_extra_dll_path();
+
        /**
         * @brief return additional searching pathes to find native libraries.
         * @return ":" seperated pathes
index fb2463739144c3d2ccc76443bce073c4897339fd..b3bc88e38f2f3a8d0da1de6a5c1dbee5aa90f3a2 100644 (file)
@@ -132,6 +132,12 @@ public:
         */
        const std::string& getAppNIPaths();
 
+       /**
+        * @brief Set addtional dll searching path for App.
+        * @param[in] paths path
+        */
+       void setExtraDllPaths(const char* paths);
+
        /**
         * @brief Get the list of directories where the native libraries of this application exist
         * @return the list(":" seperated) of paths the loader should probe when looking for native libraries
@@ -159,6 +165,7 @@ private:
        std::string appNIPaths;
        std::string nativeDllSearchingPaths;
        std::string appTacPath;
+       std::string extraDllPaths;
        int rootFD;
        int niRootFD;
 };
index 15c495ed29baf59aee3f6d611e03396845b21bd2..13d52816bfe9819b7ebf9d209c13d282d1c9353f 100644 (file)
@@ -30,6 +30,7 @@ typedef void (*plugin_set_coreclr_info_ptr)(
                        unsigned int domainId,
                        coreclr_create_delegate_ptr delegateFunc);
 typedef char* (*plugin_get_dll_path_ptr)();
+typedef char* (*plugin_get_extra_dll_path_ptr)();
 typedef char* (*plugin_get_native_dll_searching_path_ptr)();
 typedef char* (*plugin_get_tpa_ptr)();
 typedef void (*plugin_before_execute_ptr)();
@@ -42,6 +43,7 @@ typedef struct PluginFunc {
        plugin_set_app_info_ptr set_app_info;
        plugin_set_coreclr_info_ptr set_coreclr_info;
        plugin_get_dll_path_ptr get_dll_path;
+       plugin_get_extra_dll_path_ptr get_extra_dll_path;
        plugin_get_native_dll_searching_path_ptr get_native_dll_searching_path;
        plugin_get_tpa_ptr get_tpa;
        plugin_before_execute_ptr before_execute;
@@ -54,6 +56,7 @@ bool pluginHasLogControl();
 void pluginSetAppInfo(const char* appId, const char* managedAssemblyPath);
 void pluginSetCoreclrInfo(void* hostHandle, unsigned int domainId, coreclr_create_delegate_ptr delegateFunc);
 char* pluginGetDllPath();
+char* pluginGetExtraDllPath();
 char* pluginGetNativeDllSearchingPath();
 char* pluginGetTPA();
 void pluginBeforeExecute();
index eafb586e9d9b753c2634f82d653491b2063f70e5..c7e1577e799c0cb8f79a761d59ea2e61c7638d8c 100644 (file)
@@ -396,6 +396,11 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                __pm->addNativeDllSearchingPaths(pluginNativePaths, true);
        }
 
+       char* pluginExtraDllPaths = pluginGetExtraDllPath();
+       if (pluginExtraDllPaths && pluginExtraDllPaths[0] != '\0') {
+               __pm->setExtraDllPaths(pluginExtraDllPaths);
+       }
+
        pluginHasLogControl();
 
        std::string libCoreclr(concatPath(__pm->getRuntimePath(), "libcoreclr.so"));
index ed24af347ef292c79f0911b295ad923fd54718aa..7abedcd215f62c7eb2cf095a132675043b8e370b 100644 (file)
@@ -789,6 +789,11 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, NIOption* opt)
 
        __pm->setAppRootPath(rootPath);
 
+       char* extraDllPaths = pluginGetExtraDllPath();
+       if (extraDllPaths && extraDllPaths[0] != '\0') {
+               __pm->setExtraDllPaths(extraDllPaths);
+       }
+
        opt->flags |= NI_FLAGS_APPNI;
 
        if (isReadOnlyArea(rootPath)) {
index 6ecd556ec905c09bc9eab46637bd7bcd1bd7f332..664da52a635e69f5fabf231bbc6a25aef934e98c 100644 (file)
@@ -64,7 +64,12 @@ void PathManager::updateAppRelatedPath(const std::string& appRootPath, const std
 
        appTacPath = concatPath(appBinPath, TAC_SYMLINK_SUB_DIR);
        appPaths = appRootPath + ":" + appBinPath + ":" + appLibPath + ":" + appTacPath;
-       appNIPaths = appNIBinPath + ":" + appNILibPath + ":"+ appTacPath;
+       appNIPaths = appNIBinPath + ":" + appNILibPath + ":" + appTacPath;
+
+       if (!extraDllPaths.empty()) {
+               appPaths = appPaths + ":" + extraDllPaths;
+               appNIPaths = appNIPaths + ":" + extraDllPaths;
+       }
 }
 
 PathManager::PathManager() :
@@ -180,6 +185,16 @@ void PathManager::setAppRootPath(const std::string& rootPath)
        updateAppRelatedPath(appRootPath, appNIRootPath);
 }
 
+// paths: ":" separated muliple path.
+void PathManager::setExtraDllPaths(const char* paths)
+{
+       extraDllPaths = std::string(paths);
+       if (!extraDllPaths.empty()) {
+               appPaths = appPaths + ":" + extraDllPaths;
+               appNIPaths = appNIPaths + ":" + extraDllPaths;
+       }
+}
+
 const std::string& PathManager::getRuntimePath()
 {
        return runtimePath;
index 957d522ea6c9289863574dca94cd91a0afd31ec2..0e38f4e96d22e8d6abe614bcef60ae99a86d2e9f 100644 (file)
@@ -47,6 +47,7 @@ int initializePluginManager(const char* appType)
                        __pluginFunc->set_app_info = (plugin_set_app_info_ptr)dlsym(__pluginLib, "plugin_set_app_info");
                        __pluginFunc->set_coreclr_info = (plugin_set_coreclr_info_ptr)dlsym(__pluginLib, "plugin_set_coreclr_info");
                        __pluginFunc->get_dll_path = (plugin_get_dll_path_ptr)dlsym(__pluginLib, "plugin_get_dll_path");
+                       __pluginFunc->get_extra_dll_path = (plugin_get_extra_dll_path_ptr)dlsym(__pluginLib, "plugin_get_extra_dll_path");
                        __pluginFunc->get_native_dll_searching_path = (plugin_get_native_dll_searching_path_ptr)dlsym(__pluginLib, "plugin_get_native_dll_searching_path");
                        __pluginFunc->get_tpa = (plugin_get_tpa_ptr)dlsym(__pluginLib, "plugin_get_tpa");
                        __pluginFunc->before_execute = (plugin_before_execute_ptr)dlsym(__pluginLib, "plugin_before_execute");
@@ -122,6 +123,15 @@ char* pluginGetDllPath()
        }
 }
 
+char* pluginGetExtraDllPath()
+{
+       if (__pluginFunc && __pluginFunc->get_extra_dll_path) {
+               return __pluginFunc->get_extra_dll_path();
+       } else {
+               return NULL;
+       }
+}
+
 char* pluginGetNativeDllSearchingPath()
 {
        if (__pluginFunc && __pluginFunc->get_native_dll_searching_path) {