Add plugin api to add native dll searching path (#343) submit/tizen/20210722.053902
author조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Thu, 22 Jul 2021 05:35:58 +0000 (14:35 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 22 Jul 2021 05:35:58 +0000 (14:35 +0900)
There are some cases to add dll and native library searching path through plugin API.
The adding dll searching path was already supported, but the adding native library searching part is missing, so this part is added.

The added searching path by plugin has the highest priority. (VD requirement)

Additionally, an environment for building simple libdotnet_plugin.so for testing was also added.

NativeLauncher/CMakeLists.txt
NativeLauncher/dotnet-plugin/dotnet_plugin.cc [new file with mode: 0644]
NativeLauncher/inc/dotnet_launcher_plugin.h
NativeLauncher/inc/log.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
packaging/dotnet-launcher.spec

index ab4de99cd18bb0d83e90a7e9b02c813855454e99..6caa0ce5b8ee1ec42671229a0d27fff1b4104f9c 100644 (file)
@@ -242,6 +242,17 @@ ADD_LIBRARY(${DELETE_UNUSED_LIBRARY_PLUGIN} SHARED ${${DELETE_UNUSED_LIBRARY_PLU
 SET_TARGET_PROPERTIES(${DELETE_UNUSED_LIBRARY_PLUGIN} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB})
 TARGET_LINK_LIBRARIES(${DELETE_UNUSED_LIBRARY_PLUGIN} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${MULTI_TARGET_RESOLVER})
 
+# Build for test plugin library (libdotnet-plugin.so)
+IF(DEFINED BUILD_DOTNET_PLUGIN)
+    SET(DOTNET_PLUGIN "dotnet_plugin")
+    SET(${DOTNET_PLUGIN}_SOURCE_FILES
+        dotnet-plugin/dotnet_plugin.cc
+    )
+    ADD_LIBRARY(${DOTNET_PLUGIN} SHARED ${${DOTNET_PLUGIN}_SOURCE_FILES})
+    SET_TARGET_PROPERTIES(${DOTNET_PLUGIN} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB})
+    TARGET_LINK_LIBRARIES(${DOTNET_PLUGIN} ${${PROJECT_NAME}_LDFLAGS})
+ENDIF(DEFINED BUILD_DOTNET_PLUGIN)
+
 CONFIGURE_FILE(dotnet-launcher.pc.in dotnet-launcher.pc @ONLY)
 
 INSTALL(TARGETS ${DOTNET_LAUNCHER_UTIL} DESTINATION ${LIBDIR})
@@ -270,3 +281,7 @@ INSTALL(FILES inc/ni_common.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES inc/tac_common.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES ../dotnet-launcher.pc DESTINATION ${LIBDIR}/pkgconfig)
 INSTALL(FILES dotnet-launcher.info DESTINATION /usr/share/parser-plugins)
+IF(DEFINED BUILD_DOTNET_PLUGIN)
+    INSTALL(TARGETS ${DOTNET_PLUGIN} DESTINATION ${NATIVE_LIB_DIR})
+ENDIF(DEFINED BUILD_DOTNET_PLUGIN)
+
diff --git a/NativeLauncher/dotnet-plugin/dotnet_plugin.cc b/NativeLauncher/dotnet-plugin/dotnet_plugin.cc
new file mode 100644 (file)
index 0000000..539d5ae
--- /dev/null
@@ -0,0 +1,75 @@
+/*\r
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <unistd.h>\r
+\r
+#include "dotnet_launcher_plugin.h"\r
+#include "log.h"\r
+\r
+void plugin_initialize(const char* appType)\r
+{\r
+       _SOUT("### plugin_initialize called");\r
+}\r
+\r
+void plugin_preload()\r
+{\r
+       _SOUT("### plugin_preload called");\r
+}\r
+\r
+void plugin_set_app_info(const char* appId, const char* managedAssemblyPath)\r
+{\r
+       _SOUT("### plugin_set_app_info called");\r
+}\r
+\r
+bool plugin_has_log_control()\r
+{\r
+       _SOUT("### plugin_has_log_control called");\r
+       return false;\r
+}\r
+\r
+void plugin_set_coreclr_info(void* hostHandle, unsigned int domainId, coreclr_create_delegate_ptr delegateFunc)\r
+{\r
+       _SOUT("### plugin_set_coreclr_info called");\r
+}\r
+\r
+char* plugin_get_dll_path()\r
+{\r
+       _SOUT("### plugin_get_dll_path called");\r
+       return "";\r
+}\r
+\r
+char* plugin_get_native_dll_searching_path()\r
+{\r
+       _SOUT("### plugin_get_native_dll_searching_path called");\r
+       return "";\r
+}\r
+\r
+char* plugin_get_tpa()\r
+{\r
+       _SOUT("### plugin_get_tpa called");\r
+       return "";\r
+}\r
+\r
+void plugin_before_execute()\r
+{\r
+       _SOUT("### plugin_before_execute called");\r
+}\r
+\r
+void plugin_finalize()\r
+{\r
+       _SOUT("### plugin_finalize called");\r
+}\r
+\r
index 332c9f133b7f7e3e59b3715e1e98761283abd9f7..517bbb1672b6007c383163ec7ef8bc279ef12672 100644 (file)
@@ -63,6 +63,12 @@ extern "C"
         */
        char* plugin_get_dll_path();
 
+       /**
+        * @brief return additional searching pathes to find native libraries.
+        * @return ":" seperated pathes
+        */
+       char* plugin_get_native_dll_searching_path();
+
        /**
         * @brief function will be called before invoking managed code
         */
index bb0ca75420e6a4e0dfbbc160b4e0c0cdeca4039b..d15446a149b8ad5daf422963bf4d6a992d4400de 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef __LOG_H__
 #define __LOG_H__
 
+#include <stdio.h>
 #include <dlog.h>
 #define LOGX(fmt, arg...) \
        ({ do { \
index 38ca3270a6af6e6497272f435bab3ddde8ca9d76..fb2463739144c3d2ccc76443bce073c4897339fd 100644 (file)
@@ -74,6 +74,13 @@ public:
         */
        void addPlatformAssembliesPaths(const std::string& paths, bool isHighPriority = false);
 
+       /**
+        * @brief Add native dll searching paths.
+        * @param[in] paths the paths to be added
+        * @param[in] isHighPriority if true, paths are added in front of the current list, otherwise added at the end of the list
+        */
+       void addNativeDllSearchingPaths(const std::string& paths, bool isHighPriority = false);
+
        /**
         * @brief Set application root path.
         *        All application related paths ("bin", "lib", ".tac_symlink", ".native_image") are generated based on it.
index e00b628d9b4db59bcfef075c7db35c6b6d3545e0..15c495ed29baf59aee3f6d611e03396845b21bd2 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_native_dll_searching_path_ptr)();
 typedef char* (*plugin_get_tpa_ptr)();
 typedef void (*plugin_before_execute_ptr)();
 typedef void (*plugin_finalize_ptr)();
@@ -41,6 +42,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_native_dll_searching_path_ptr get_native_dll_searching_path;
        plugin_get_tpa_ptr get_tpa;
        plugin_before_execute_ptr before_execute;
        plugin_finalize_ptr finalize;
@@ -52,6 +54,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* pluginGetNativeDllSearchingPath();
 char* pluginGetTPA();
 void pluginBeforeExecute();
 void pluginFinalize();
index b0129d9e14d6e64a78e01300bf3b705e963b5ded..13efc05ae4a2279da712ad7a78b624e26ef08276 100644 (file)
@@ -379,9 +379,14 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                return -1;
        }
 
-       char* pluginPath = pluginGetDllPath();
-       if (pluginPath) {
-               __pm->addPlatformAssembliesPaths(pluginPath);
+       char* pluginDllPaths = pluginGetDllPath();
+       if (pluginDllPaths && pluginDllPaths[0] != '\0') {
+               __pm->addPlatformAssembliesPaths(pluginDllPaths, true);
+       }
+
+       char* pluginNativePaths = pluginGetNativeDllSearchingPath();
+       if (pluginNativePaths && pluginNativePaths[0] != '\0') {
+               __pm->addNativeDllSearchingPaths(pluginNativePaths, true);
        }
 
        pluginHasLogControl();
@@ -421,7 +426,7 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
 
        std::string tpa;
        char* pluginTPA = pluginGetTPA();
-       if (pluginTPA) {
+       if (pluginTPA && pluginTPA[0] != '\0') {
                tpa = std::string(pluginTPA);
        } else {
                addAssembliesFromDirectories(__pm->getPlatformAssembliesPaths(), tpa);
index 73cf7381b6f43561a461f3e9aad1fb8d78b05ddb..51a04b30e90b20400edebae88304865dbeac76ba 100644 (file)
@@ -523,8 +523,13 @@ ni_error_e initNICommon()
        }
 
        char* pluginDllPaths = pluginGetDllPath();
-       if (pluginDllPaths) {
-               __pm->addPlatformAssembliesPaths(pluginDllPaths);
+       if (pluginDllPaths && pluginDllPaths[0] != '\0') {
+               __pm->addPlatformAssembliesPaths(pluginDllPaths, true);
+       }
+
+       char* pluginNativePaths = pluginGetNativeDllSearchingPath();
+       if (pluginNativePaths && pluginNativePaths[0] != '\0') {
+               __pm->addNativeDllSearchingPaths(pluginNativePaths, true);
        }
 
        return NI_ERROR_NONE;
index ae89ca2aa8c76d9e6054b56a6e183e08f44bb128..97db862411da2a4c16a421a2a208fe6fd604642d 100644 (file)
@@ -65,7 +65,6 @@ 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;
-       nativeDllSearchingPaths = runtimePath + ":" + __NATIVE_LIB_DIR + ":" + appBinPath + ":" + appLibPath + ":" + getExtraNativeLibDirs(appRootPath);
 }
 
 PathManager::PathManager() :
@@ -106,6 +105,11 @@ PathManager::PathManager() :
        appNIRootPath = std::string("/proc/self/fd/") + std::to_string(niRootFD);
        updateAppRelatedPath(appRootPath, appNIRootPath);
 
+       // Set native library searching path
+       nativeDllSearchingPaths = runtimePath + ":" + __NATIVE_LIB_DIR + ":" +
+                                 concatPath(appRootPath, "bin") + ":" + concatPath(appRootPath, "lib") + ":" +
+                                 getExtraNativeLibDirs(appRootPath);
+
        _INFO("Path manager created successfully");
 }
 
@@ -134,6 +138,15 @@ void PathManager::addPlatformAssembliesPaths(const std::string& paths, bool isHi
        platformAssembliesPaths.insert(it, pathVec.begin(), pathVec.end());
 }
 
+void PathManager::addNativeDllSearchingPaths(const std::string& paths, bool isHighPriority)
+{
+       if (isHighPriority) {
+               nativeDllSearchingPaths = paths + ":" + nativeDllSearchingPaths;
+       } else {
+               nativeDllSearchingPaths = nativeDllSearchingPaths + ":" + paths;
+       }
+}
+
 void PathManager::setAppRootPath(const std::string& rootPath)
 {
        appRootPath = getAbsolutePath(rootPath);
index a797ced17c1c6a8d5b6697d325ed49af50231bc9..957d522ea6c9289863574dca94cd91a0afd31ec2 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_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");
                        __pluginFunc->finalize  = (plugin_finalize_ptr)dlsym(__pluginLib, "plugin_finalize");
@@ -121,6 +122,15 @@ char* pluginGetDllPath()
        }
 }
 
+char* pluginGetNativeDllSearchingPath()
+{
+       if (__pluginFunc && __pluginFunc->get_native_dll_searching_path) {
+               return __pluginFunc->get_native_dll_searching_path();
+       } else {
+               return NULL;
+       }
+}
+
 char* pluginGetTPA()
 {
        if (__pluginFunc && __pluginFunc->get_tpa) {
index dc82c9b924654b178dbf8f16a0be9250b8f2bde0..2445646144d5cbaf284e07470e7f5b853dce1ceb 100644 (file)
@@ -69,6 +69,8 @@ Requires(preun): /usr/bin/systemctl
 %define _rw_update_scripts_dir /usr/share/upgrade/scripts
 %define _rw_dotnet_update_script 715.dotnet_regen_app_ni.patch.sh
 
+%define _build_dotnet_plugin 0
+
 %description
 Launchpad plugin for launching dotnet apps
 
@@ -138,6 +140,9 @@ cmake \
        -DUNIQUE_DEFAULT_BASE_ADDR_SUPPORT="" \
        -DSYSTEM_BASE_FILE=%{_system_base_addr_file} \
        -DDEFAULT_BASE_ADDR_START=%{_default_base_addr_start} \
+%endif
+%if 0%{_build_dotnet_plugin}
+       -DBUILD_DOTNET_PLUGIN="" \
 %endif
        NativeLauncher
 
@@ -208,6 +213,9 @@ chsmack -a User /usr/bin/dotnet-nui-loader
 %{_ibc_data_dir}
 %{_tizen_preload_dir}
 %{_rw_update_scripts_dir}/%{_rw_dotnet_update_script}
+%if 0%{_build_dotnet_plugin}
+%{_native_lib_dir}/libdotnet_plugin.so
+%endif
 
 %files devel
 %manifest dotnet-launcher.manifest