From: 조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 Date: Thu, 22 Jul 2021 05:35:58 +0000 (+0900) Subject: Add plugin api to add native dll searching path (#343) X-Git-Tag: submit/tizen/20210722.053902^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d89a6fb543b0098bb5d6f39eea4d376d18414a24;p=platform%2Fcore%2Fdotnet%2Flauncher.git Add plugin api to add native dll searching path (#343) 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. --- diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index ab4de99..6caa0ce 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -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 index 0000000..539d5ae --- /dev/null +++ b/NativeLauncher/dotnet-plugin/dotnet_plugin.cc @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "dotnet_launcher_plugin.h" +#include "log.h" + +void plugin_initialize(const char* appType) +{ + _SOUT("### plugin_initialize called"); +} + +void plugin_preload() +{ + _SOUT("### plugin_preload called"); +} + +void plugin_set_app_info(const char* appId, const char* managedAssemblyPath) +{ + _SOUT("### plugin_set_app_info called"); +} + +bool plugin_has_log_control() +{ + _SOUT("### plugin_has_log_control called"); + return false; +} + +void plugin_set_coreclr_info(void* hostHandle, unsigned int domainId, coreclr_create_delegate_ptr delegateFunc) +{ + _SOUT("### plugin_set_coreclr_info called"); +} + +char* plugin_get_dll_path() +{ + _SOUT("### plugin_get_dll_path called"); + return ""; +} + +char* plugin_get_native_dll_searching_path() +{ + _SOUT("### plugin_get_native_dll_searching_path called"); + return ""; +} + +char* plugin_get_tpa() +{ + _SOUT("### plugin_get_tpa called"); + return ""; +} + +void plugin_before_execute() +{ + _SOUT("### plugin_before_execute called"); +} + +void plugin_finalize() +{ + _SOUT("### plugin_finalize called"); +} + diff --git a/NativeLauncher/inc/dotnet_launcher_plugin.h b/NativeLauncher/inc/dotnet_launcher_plugin.h index 332c9f1..517bbb1 100644 --- a/NativeLauncher/inc/dotnet_launcher_plugin.h +++ b/NativeLauncher/inc/dotnet_launcher_plugin.h @@ -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 */ diff --git a/NativeLauncher/inc/log.h b/NativeLauncher/inc/log.h index bb0ca75..d15446a 100644 --- a/NativeLauncher/inc/log.h +++ b/NativeLauncher/inc/log.h @@ -17,6 +17,7 @@ #ifndef __LOG_H__ #define __LOG_H__ +#include #include #define LOGX(fmt, arg...) \ ({ do { \ diff --git a/NativeLauncher/inc/path_manager.h b/NativeLauncher/inc/path_manager.h index 38ca327..fb24637 100644 --- a/NativeLauncher/inc/path_manager.h +++ b/NativeLauncher/inc/path_manager.h @@ -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. diff --git a/NativeLauncher/inc/plugin_manager.h b/NativeLauncher/inc/plugin_manager.h index e00b628..15c495e 100644 --- a/NativeLauncher/inc/plugin_manager.h +++ b/NativeLauncher/inc/plugin_manager.h @@ -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(); diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index b0129d9..13efc05 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -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); diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 73cf738..51a04b3 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -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; diff --git a/NativeLauncher/util/path_manager.cc b/NativeLauncher/util/path_manager.cc index ae89ca2..97db862 100644 --- a/NativeLauncher/util/path_manager.cc +++ b/NativeLauncher/util/path_manager.cc @@ -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); diff --git a/NativeLauncher/util/plugin_manager.cc b/NativeLauncher/util/plugin_manager.cc index a797ced..957d522 100644 --- a/NativeLauncher/util/plugin_manager.cc +++ b/NativeLauncher/util/plugin_manager.cc @@ -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) { diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index dc82c9b..2445646 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -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