From 323150bea27f1ebada1399e51ceba0c01b0606ed Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Tue, 25 Apr 2017 17:26:05 +0900 Subject: [PATCH 01/16] Bug fixed for performance_test Change-Id: I7e3e42defbd9cf25da8d605c2d8dc8cc75267a18 --- tools/performance_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/performance_test.sh b/tools/performance_test.sh index 37b7950..43b7962 100755 --- a/tools/performance_test.sh +++ b/tools/performance_test.sh @@ -145,7 +145,7 @@ execute_time_stamp_auto_memory () echo "[>] Start performance test that applciation launching memory" echo "" sdb shell "dlogutil -c" - sdb shell "dlogutil -v time AUL APP_CORE|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|__show_cb.*[EVENT_TEST][EVENT]'" >> $STREAM_LOG_FILE & + sdb shell "dlogutil -v time AUL APP_CORE_UI_BASE|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|appcore_ui_base_window_on_show.*[EVENT_TEST][EVENT]'" >> $STREAM_LOG_FILE & DLOG_STREAMER_PID=$! #execute timestamp /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE & @@ -202,7 +202,7 @@ execute_time_stamp_manual_memory () rm $STREAM_LOG_FILE touch $STREAM_LOG_FILE sdb shell "dlogutil -c" - sdb shell "dlogutil -v time AUL APP_CORE|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|__show_cb.*[EVENT_TEST][EVENT]'" >> $STREAM_LOG_FILE & + sdb shell "dlogutil -v time AUL APP_CORE_UI_BASE|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|appcore_ui_base_window_on_show.*[EVENT_TEST][EVENT]'" >> $STREAM_LOG_FILE & DLOG_STREAMER_PID=$! #execute timestamp /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE & -- 2.7.4 From 7f481bb69fb6d1a11ed2d88461d74bfb0f5d22d6 Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Wed, 26 Apr 2017 08:36:35 +0900 Subject: [PATCH 02/16] crossgen bug fixed Change-Id: Ia8632e7b66cabbfd2d1c780d85db52462e1db38e --- NativeLauncher/installer-plugin/common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index e53cff3..9cd2109 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -175,7 +175,7 @@ static void crossgen(const char* dllPath, const char* appPath) std::vector argv = { __CROSSGEN_PATH, "/Trusted_Platform_Assemblies", tpa.c_str(), - "/__JIT_PATH", __JIT_PATH, + "/JITPath", __JIT_PATH, "/FragileNonVersionable" }; if (appPath != nullptr) { -- 2.7.4 From 9e24b5e89b5022a29abc318b67f31493acd21fcc Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Thu, 27 Apr 2017 13:32:28 +0900 Subject: [PATCH 03/16] Remove the cap_mac_admin for dotnet-launcher Change-Id: I96ac4601185314edeee80e39bb67a512f1816610 --- NativeLauncher/CMakeLists.txt | 20 ++++++++++---------- packaging/dotnet-launcher.spec | 13 ++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 4107d05..e453d9a 100755 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -113,15 +113,15 @@ ADD_EXECUTABLE(${NITOOL} ${${NITOOL}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${NITOOL} PROPERTIES COMPILE_FLAGS "-fPIE") TARGET_LINK_LIBRARIES(${NITOOL} ${${PROJECT_NAME}_LDFLAGS} "-pie") -SET(INSTALLER_PLUGIN "ui-application") -SET(${INSTALLER_PLUGIN}_SOURCE_FILES - util/utils.cc - installer-plugin/common.cc - installer-plugin/ui-application.cc -) -ADD_LIBRARY(${INSTALLER_PLUGIN} SHARED ${${INSTALLER_PLUGIN}_SOURCE_FILES}) -SET_TARGET_PROPERTIES(${INSTALLER_PLUGIN} PROPERTIES COMPILE_FLAGS "-fPIC") -TARGET_LINK_LIBRARIES(${INSTALLER_PLUGIN} ${${PROJECT_NAME}_LDFLAGS}) +#SET(INSTALLER_PLUGIN "ui-application") +#SET(${INSTALLER_PLUGIN}_SOURCE_FILES +# util/utils.cc +# installer-plugin/common.cc +# installer-plugin/ui-application.cc +#) +#ADD_LIBRARY(${INSTALLER_PLUGIN} SHARED ${${INSTALLER_PLUGIN}_SOURCE_FILES}) +#SET_TARGET_PROPERTIES(${INSTALLER_PLUGIN} PROPERTIES COMPILE_FLAGS "-fPIC") +#TARGET_LINK_LIBRARIES(${INSTALLER_PLUGIN} ${${PROJECT_NAME}_LDFLAGS}) SET(PREFER_DOTNET_AOT_PLUGIN "prefer_dotnet_aot_plugin") @@ -139,7 +139,7 @@ IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(TARGETS ${SCD_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(TARGETS ${NITOOL} DESTINATION ${BINDIR}) - INSTALL(TARGETS ${INSTALLER_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) +# INSTALL(TARGETS ${INSTALLER_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) INSTALL(TARGETS ${PREFER_DOTNET_AOT_PLUGIN} DESTINATION ${INSTALL_MDPLUGIN_DIR}) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index f82e994..847558a 100755 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -26,7 +26,6 @@ BuildRequires: pkgconfig(appcore-agent) BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-service-application) -BuildRequires: pkgconfig(capi-appfw-service-application) Requires: aul @@ -106,13 +105,13 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %{_loaderdir}/dotnet.launcher %{_loaderdir}/dotnet.debugger %{_native_lib_dir}/libsqlite3.so -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/nitool -%caps(cap_mac_admin,cap_setgid=ei) %{_install_plugin_dir}/libui-application.so -%caps(cap_mac_admin,cap_setgid=ei) %{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so +%{_bindir}/nitool +#%{_install_plugin_dir}/libui-application.so +%{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so %if %{use_managed_launcher} -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.dll +%{_bindir}/Tizen.Runtime.dll %endif +%caps(cap_setgid=ei) %{_bindir}/dotnet-launcher %files -n scd-launcher -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/scd-launcher +%caps(cap_setgid=ei) %{_bindir}/scd-launcher -- 2.7.4 From 9923c6c1a7c00678b59cc15f2047be7e98be553f Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Thu, 11 May 2017 14:03:17 +0900 Subject: [PATCH 04/16] Add signal handler Change-Id: I46bd2e0867261675c3f04352330df9022526cf20 --- NativeLauncher/CMakeLists.txt | 5 + NativeLauncher/launcher/dotnet_signal_handler.cc | 146 +++++++++++++++++++++++ NativeLauncher/launcher/dotnet_signal_handler.h | 23 ++++ NativeLauncher/launcher/main.cc | 3 + packaging/dotnet-launcher.spec | 6 + 5 files changed, 183 insertions(+) mode change 100755 => 100644 NativeLauncher/CMakeLists.txt create mode 100644 NativeLauncher/launcher/dotnet_signal_handler.cc create mode 100644 NativeLauncher/launcher/dotnet_signal_handler.h mode change 100755 => 100644 packaging/dotnet-launcher.spec diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt old mode 100755 new mode 100644 index e453d9a..abbf4c2 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -46,6 +46,10 @@ IF(USE_MANAGED_LAUNCHER STREQUAL "ENABLE") ADD_DEFINITIONS("-DUSE_MANAGED_LAUNCHER") ENDIF(USE_MANAGED_LAUNCHER) +IF(RAISE_DEFAULT_SIGNAL_HANDLER STREQUAL "ENABLE") + ADD_DEFINITIONS("-DRAISE_DEFAULT_SIGNAL_HANDLER") +ENDIF(RAISE_DEFAULT_SIGNAL_HANDLER) + OPTION(NOT_USE_FUNCTION "Remove build warning" OFF) IF(NOT_USE_FUNCTION) ADD_DEFINITIONS("-DNOT_USE_FUNCTION") @@ -74,6 +78,7 @@ SET(${DOTNET_LAUNCHER}_SOURCE_FILES launcher/main.cc util/utils.cc launcher/launcher.cc + launcher/dotnet_signal_handler.cc launcher/dotnet/dotnet_launcher.cc ) ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${DOTNET_LAUNCHER}_SOURCE_FILES}) diff --git a/NativeLauncher/launcher/dotnet_signal_handler.cc b/NativeLauncher/launcher/dotnet_signal_handler.cc new file mode 100644 index 0000000..783f6c7 --- /dev/null +++ b/NativeLauncher/launcher/dotnet_signal_handler.cc @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2016 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 "dotnet_signal_handler.h" + +#include "log.h" + +#include +#include + +#include +#include +#include +#include + +using namespace std; + +#define CALLSTACK_SIZE 30 + +std::vector backtraceStr; +char **backtraceStrings; +int backtracePtrs; + +static void printBacktrace() +{ + if (backtraceStr.size() > 0) { + _ERR("Backtrace returned %d addresses :", backtraceStr.size()); + + for (unsigned int i = 0; i < backtraceStr.size(); i++) { + _ERR("[Backtrace #%d] : %s", i, backtraceStr[i].c_str()); + } + } + + backtraceStr.clear(); +} + +static bool nativeCrashCheck() +{ + int i; + void *buf[CALLSTACK_SIZE + 1]; + + backtracePtrs = backtrace(buf, CALLSTACK_SIZE); + if (backtracePtrs == 0) { + _ERR("No backtrace captured"); + return false; + } + + backtraceStrings = backtrace_symbols(buf, backtracePtrs); + + if (backtraceStrings == NULL) { + _ERR("No backtrace captured"); + return false; + } + + backtraceStr.clear(); + + for (i = backtracePtrs - 1; i >= 0; i--) { + if (strstr(backtraceStrings[i], "__default_rt_sa_restorer") != NULL) + return backtraceStr.size() > 0; + + backtraceStr.push_back(std::string(backtraceStrings[i])); + } + + return true; +} + +static void onSigabrt(int signum) +{ + _ERR("<<< SIGABRT %d >>>", signum); + + backtracePtrs = 0; + backtraceStrings = NULL; + + if (nativeCrashCheck()) { + printBacktrace(); +#ifdef RAISE_DEFAULT_SIGNAL_HANDLER + SIG_DFL(signum); +#endif + } else { + _ERR("Crash from managed code"); + } + + if (backtraceStrings != NULL) { + free(backtraceStrings); + backtraceStrings = NULL; + } + + exit(0); +} + +static void onSigsegv(int signum) +{ + _ERR("<<< SIGSEGV %d >>>", signum); + + backtracePtrs = 0; + backtraceStrings = NULL; + + if (nativeCrashCheck()) { + printBacktrace(); +#ifdef RAISE_DEFAULT_SIGNAL_HANDLER + SIG_DFL(signum); +#endif + } else { + _ERR("Crash from managed code"); + } + + if (backtraceStrings != NULL) { + free(backtraceStrings); + backtraceStrings = NULL; + } + + exit(0); +} + +static void onSigtrap(int signum) +{ + _ERR("<<< SIGTRAP %d >>>", signum); + + exit(0); +} + +void registerSignalHandler() +{ + _DBG("Register signal handler"); + + if (SIG_ERR == signal(SIGABRT, &onSigabrt) || + SIG_ERR == signal(SIGSEGV, &onSigsegv) || + SIG_ERR == signal(SIGTRAP, &onSigtrap)) { + perror("[dotnet-launcher] signal register error\n"); + _ERR("Signal register error"); + } +} diff --git a/NativeLauncher/launcher/dotnet_signal_handler.h b/NativeLauncher/launcher/dotnet_signal_handler.h new file mode 100644 index 0000000..9cbb62e --- /dev/null +++ b/NativeLauncher/launcher/dotnet_signal_handler.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016 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. + */ + + +#ifndef __DOTNET_SIGNAL_HANDLER__ +#define __DOTNET_SIGNAL_HANDLER__ + +void registerSignalHandler(); + +#endif /* __DOTNET_SIGNAL_HANDLER__ */ diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 2bbda72..7063a2d 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -15,6 +15,7 @@ */ #include "dotnet/dotnet_launcher.h" +#include "dotnet_signal_handler.h" #include "utils.h" #include "log.h" @@ -40,6 +41,8 @@ static std::string StandaloneOption("--standalone"); int main(int argc, char *argv[]) { + registerSignalHandler(); + int i; bool standalone = false; const char* standalonePath = nullptr; diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec old mode 100755 new mode 100644 index 847558a..09e3e41 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -63,6 +63,11 @@ launching dotnet apps without dotent runtime installed %define USE_MANAGED_LAUNCHER ENABLE %endif +%define raise_default_signal_handler 0 +%if %{raise_default_signal_handler} + %define RAISE_DEFAULT_SIGNAL_HANDLER ENABLE +%endif + %build cmake \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ @@ -82,6 +87,7 @@ cmake \ -DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \ -DVERSION=%{version} \ -DUSE_MANAGED_LAUNCHER=%{?USE_MANAGED_LAUNCHER:%USE_MANAGED_LAUNCHER} \ + -DRAISE_DEFAULT_SIGNAL_HANDLER=%{?RAISE_DEFAULT_SIGNAL_HANDLER:%RAISE_DEFAULT_SIGNAL_HANDLER} \ -DNATIVE_LIB_DIR=%{_native_lib_dir} \ NativeLauncher -- 2.7.4 From 91e3a0520950bc15da708f5129a85415dae9397c Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Mon, 15 May 2017 20:12:58 +0900 Subject: [PATCH 05/16] Add cap_mac_admin for dotnet-launcher(Revert patch) Change-Id: If40f2f7afe7a8c59235fc8a969c74ac90ef9c3e7 --- packaging/dotnet-launcher.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 09e3e41..d41993a 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -117,7 +117,7 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %if %{use_managed_launcher} %{_bindir}/Tizen.Runtime.dll %endif -%caps(cap_setgid=ei) %{_bindir}/dotnet-launcher +%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher %files -n scd-launcher -%caps(cap_setgid=ei) %{_bindir}/scd-launcher +%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/scd-launcher -- 2.7.4 From cfef9f11cffb8b2a8e8963042b783776c38edac1 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 19 May 2017 13:53:50 +0900 Subject: [PATCH 06/16] support reference API directory to support PlatformNotSupport Exception Change-Id: Ib4e389fcffea849cc2235a42b844e643c2e4b92a --- NativeLauncher/installer-plugin/common.cc | 6 ++++++ NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 4 ++++ NativeLauncher/launcher/dotnet/dotnet_launcher.h | 1 + 3 files changed, 11 insertions(+) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 9cd2109..fe89609 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -169,6 +169,12 @@ static void crossgen(const char* dllPath, const char* appPath) tpaDir.push_back(__RUNTIME_DIR); tpaDir.push_back(__DEVICE_API_DIR); + // get reference API directory ([DEVICE_API_DIR]/ref) + int len = strlen(__DEVICE_API_DIR); + char* refAPIDir = (char*)calloc(len + 4, 1); + snprintf(refAPIDir, len + 4, "%s%s", __DEVICE_API_DIR, "/ref"); + tpaDir.push_back(refAPIDir); + std::string tpa; assembliesInDirectory(tpaDir, tpa); diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index c0b5300..d01c155 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -116,6 +116,9 @@ int CoreRuntime::initialize(bool standalone) __runtimeDirectory = absolutePath(__runtimeDirectory); } + // set Reference API directory + __refAPIDirectory = __deviceAPIDirectory + "/ref"; + #ifdef USE_MANAGED_LAUNCHER if (__launcherAssembly.empty()) { _ERR("Empty Launcher Assembly"); @@ -279,6 +282,7 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i searchDirectories.push_back(appLib); searchDirectories.push_back(__runtimeDirectory); searchDirectories.push_back(__deviceAPIDirectory); + searchDirectories.push_back(__refAPIDirectory); #ifdef USE_MANAGED_LAUNCHER searchDirectories.push_back(baseName(__launcherAssembly)); #endif diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index fb44a47..1e9bee7 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -78,6 +78,7 @@ class CoreRuntime : public tizen::runtime::LauncherInterface std::string __runtimeDirectory; std::string __launcherAssembly; std::string __nativeLibDirectory; + std::string __refAPIDirectory; void* __coreclrLib; void* __hostHandle; unsigned int __domainId; -- 2.7.4 From 05e74b0f439327ff661ebce1208deb8b5aa43889 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Thu, 15 Jun 2017 16:00:25 +0900 Subject: [PATCH 07/16] update nitool to support coreclr upgrade. Change-Id: I441626207f77e1de9e6e376668de7bedf064f978 --- NativeLauncher/installer-plugin/common.cc | 111 +++++++++++++++++++----------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index fe89609..8ba2a09 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include "common.h" @@ -62,10 +63,8 @@ static const char* __JIT_PATH = __STR(RUNTIME_DIR)"/libclrjit.so"; #undef __STR #undef __XSTR -static void crossgen(const char* dllPath, const char* appPath); -static void smack_(const char* dllPath, const char* label); -std::string replace(std::string &str, const std::string& from, const std::string& to) +static std::string replace(std::string &str, const std::string& from, const std::string& to) { size_t startPos = 0; while ((startPos = str.find(from, startPos)) != std::string::npos) { @@ -75,45 +74,6 @@ std::string replace(std::string &str, const std::string& from, const std::string return str; } -void createNiPlatform() -{ - std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); - std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); - - if (fileNotExist(niCoreLib)) { - crossgen(coreLib.c_str(), nullptr); - smack_(niCoreLib.c_str(), "_"); - } - - const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"}; - const char* ignores[] = {coreLib.c_str()}; - - createNiUnderDirs(platformDirs, 3, ignores, 1, [](const char* ni) { - smack_(ni, "_"); - }); -} - -void createNiSelect(const char* dllPath) -{ - std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); - std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); - - if (fileNotExist(niCoreLib)) { - crossgen(coreLib.c_str(), nullptr); - smack_(niCoreLib.c_str(), "_"); - } - - if (!fileNotExist(dllPath)) { - std::string strPath = dllPath; - std::string niPath = replace(strPath, std::string(".dll"), std::string(".ni.dll")); - if (fileNotExist(niPath)) - crossgen(dllPath, nullptr); - else - printf("Already [%s] file is exist\n", niPath.c_str()); - smack_(niPath.c_str(), "_"); - } -} - static void smack_(const char* dllPath, const char* label) { static const char* chsmack = "/usr/bin/chsmack"; @@ -236,6 +196,17 @@ static int getRootPath(const char *pkgId, std::string& rootPath) static bool niExist(const std::string& path, std::string& ni) { + // native image of System.Private.CoreLib.dll should have to overwrite + // original file to support new coreclr + if (path.find("System.Private.CoreLib.dll") != std::string::npos) { + std::string coreLibBackup = path + ".Backup"; + if (!fileNotExist(coreLibBackup)) { + ni = path; + return true; + } + return false; + } + static const char* possibleExts[] = { ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL", ".ni.exe", ".NI.exe", ".NI.EXE", ".ni.EXE" @@ -255,6 +226,62 @@ static bool niExist(const std::string& path, std::string& ni) return false; } +static void createCoreLibNI() +{ + std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); + std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); + std::string coreLibBackup = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll.Backup"); + + if (!niExist(coreLib, niCoreLib)) { + crossgen(coreLib.c_str(), nullptr); + if (!fileNotExist(niCoreLib)) { + // change owner and groups for generated ni file. + struct stat info; + if (!stat(coreLib.c_str(), &info)) { + if (chown(niCoreLib.c_str(), info.st_uid, info.st_gid) == -1) + _ERR("Failed to change owner and group name"); + } + smack_(niCoreLib.c_str(), "_"); + rename(coreLib.c_str(), coreLibBackup.c_str()); + rename(niCoreLib.c_str(), coreLib.c_str()); + } + } +} + +void createNiPlatform() +{ + createCoreLibNI(); + + const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"}; + + createNiUnderDirs(platformDirs, 3, [](const char* ni) { + smack_(ni, "_"); + }); +} + +void createNiSelect(const char* dllPath) +{ + createCoreLibNI(); + + std::string niPath; + if (!fileNotExist(dllPath)) { + if (!niExist(dllPath, niPath)) { + crossgen(dllPath, nullptr); + if (niExist(dllPath, niPath)) { + // change owner and groups for generated ni file. + struct stat info; + if (!stat(dllPath, &info)) { + if (chown(niPath.c_str(), info.st_uid, info.st_gid) == -1) + _ERR("Failed to change owner and group name"); + } + smack_(niPath.c_str(), "_"); + } + } + else + printf("Already [%s] file is exist\n", niPath.c_str()); + } +} + void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb) { std::string appPaths; -- 2.7.4 From 84ed68ad40c96b66f7d7c559855534c2b4f9f65a Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 23 Jun 2017 10:29:44 +0900 Subject: [PATCH 08/16] support launcher plugin Change-Id: Ie992819b4918e65fd733edec2e46136324c59e0e --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 59 ++++++++++++++++++++++- NativeLauncher/launcher/dotnet/dotnet_launcher.h | 22 +++++++++ NativeLauncher/launcher/main.cc | 1 + 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index d01c155..6724558 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -26,6 +26,8 @@ #include "launcher.h" #include "dotnet_launcher.h" +#define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so" + namespace tizen { namespace runtime { namespace dotnetcore { @@ -39,7 +41,14 @@ CoreRuntime::CoreRuntime() : __hostHandle(nullptr), __domainId(-1), preparedFunction(nullptr), - launchFunction(nullptr) + launchFunction(nullptr), + __pluginLib(nullptr), + pluginInitialize(nullptr), + pluginPreload(nullptr), + pluginSetAppInfo(nullptr), + pluginGetDllPath(nullptr), + pluginBeforeExecute(nullptr), + pluginFinalize(nullptr) { #define __XSTR(x) #x #define __STR(x) __XSTR(x) @@ -63,6 +72,22 @@ CoreRuntime::CoreRuntime() : #undef __STR #undef __XSTR + // support launcher plugin + if (!fileNotExist(PLUGIN_PATH)) { + __pluginLib = dlopen(PLUGIN_PATH, RTLD_NOW | RTLD_LOCAL); + if (__pluginLib) { + pluginInitialize = (plugin_initialize_ptr)dlsym(__pluginLib, "plugin_initialize"); + pluginPreload = (plugin_preload_ptr)dlsym(__pluginLib, "plugin_preload"); + pluginSetAppInfo = (plugin_set_app_info_ptr)dlsym(__pluginLib, "plugin_set_app_info"); + pluginGetDllPath = (plugin_get_dll_path_ptr)dlsym(__pluginLib, "plugin_get_dll_path"); + pluginBeforeExecute = (plugin_before_execute_ptr)dlsym(__pluginLib, "plugin_before_execute"); + pluginFinalize = (plugin_finalize_ptr)dlsym(__pluginLib, "plugin_finalize"); + } + } + + if (pluginInitialize) + pluginInitialize(); + _DBG("Constructor called!!"); } @@ -159,6 +184,9 @@ int CoreRuntime::initialize(bool standalone) _DBG("this addr : %x", this); _DBG("coreclr_initialize : %x", initializeClr); + if (!standalone && pluginPreload) + pluginPreload(); + return 0; } @@ -256,6 +284,22 @@ void CoreRuntime::dispose() __coreclrLib = nullptr; + if (pluginFinalize) + pluginFinalize(); + + if (__pluginLib != nullptr) { + if (dlclose(__pluginLib) != 0) + _ERR("libdotnet_plugin.so close failed"); + + __pluginLib = nullptr; + pluginInitialize = nullptr; + pluginPreload = nullptr; + pluginSetAppInfo = nullptr; + pluginGetDllPath = nullptr; + pluginBeforeExecute = nullptr; + pluginFinalize = nullptr; + } + _DBG("Dotnet runtime disposed"); } @@ -271,6 +315,9 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i return 1; } + if (pluginSetAppInfo) + pluginSetAppInfo(appId, path); + std::string tpa; std::string appRoot = root; std::string appBin = concatPath(appRoot, "bin"); @@ -280,6 +327,13 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i std::vector searchDirectories; searchDirectories.push_back(appBin); searchDirectories.push_back(appLib); + if (pluginGetDllPath) { + std::string pluginPath = pluginGetDllPath(); + if (!pluginPath.empty()) { + probePath = probePath + ":" + pluginPath; + searchDirectories.push_back(pluginPath); + } + } searchDirectories.push_back(__runtimeDirectory); searchDirectories.push_back(__deviceAPIDirectory); searchDirectories.push_back(__refAPIDirectory); @@ -289,6 +343,9 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i assembliesInDirectory(searchDirectories, tpa); + if (pluginBeforeExecute) + pluginBeforeExecute(); + #ifdef USE_MANAGED_LAUNCHER runManagedLauncher(appId, probePath.c_str(), tpa.c_str()); diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index 1e9bee7..931846c 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -49,6 +49,20 @@ extern "C" const char* entryPointTypeName, const char* entryPointMethodName, void** delegate); + + typedef void (*plugin_initialize_ptr)(); + + typedef void (*plugin_preload_ptr)(); + + typedef void (*plugin_set_app_info_ptr)( + const char* appId, + const char* hostHandle); + + typedef char* (*plugin_get_dll_path_ptr)(); + + typedef void (*plugin_before_execute_ptr)(); + + typedef void (*plugin_finalize_ptr)(); } namespace tizen { @@ -84,6 +98,14 @@ class CoreRuntime : public tizen::runtime::LauncherInterface unsigned int __domainId; PreparedFunctionPtr preparedFunction; LaunchFunctionPtr launchFunction; + // plugin function pointer + void* __pluginLib; + plugin_initialize_ptr pluginInitialize; + plugin_preload_ptr pluginPreload; + plugin_set_app_info_ptr pluginSetAppInfo; + plugin_get_dll_path_ptr pluginGetDllPath; + plugin_before_execute_ptr pluginBeforeExecute; + plugin_finalize_ptr pluginFinalize; }; } // dotnetcore diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 7063a2d..b5fdb17 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -126,5 +126,6 @@ int main(int argc, char *argv[]) Launchpad.loaderMain(argc, argv); } + runtime->dispose(); return 0; } -- 2.7.4 From ef1576a92d02831b3c2713fe8fed6bba63679ec4 Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Mon, 17 Jul 2017 15:43:31 +0900 Subject: [PATCH 09/16] Revert "Add signal handler" This reverts commit 9923c6c1a7c00678b59cc15f2047be7e98be553f. Change-Id: Ie04614e1ca81955149c42d42a98e25579bbeae0f --- NativeLauncher/CMakeLists.txt | 5 - NativeLauncher/launcher/dotnet_signal_handler.cc | 146 ----------------------- NativeLauncher/launcher/dotnet_signal_handler.h | 23 ---- NativeLauncher/launcher/main.cc | 3 - packaging/dotnet-launcher.spec | 6 - 5 files changed, 183 deletions(-) delete mode 100644 NativeLauncher/launcher/dotnet_signal_handler.cc delete mode 100644 NativeLauncher/launcher/dotnet_signal_handler.h diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index abbf4c2..e453d9a 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -46,10 +46,6 @@ IF(USE_MANAGED_LAUNCHER STREQUAL "ENABLE") ADD_DEFINITIONS("-DUSE_MANAGED_LAUNCHER") ENDIF(USE_MANAGED_LAUNCHER) -IF(RAISE_DEFAULT_SIGNAL_HANDLER STREQUAL "ENABLE") - ADD_DEFINITIONS("-DRAISE_DEFAULT_SIGNAL_HANDLER") -ENDIF(RAISE_DEFAULT_SIGNAL_HANDLER) - OPTION(NOT_USE_FUNCTION "Remove build warning" OFF) IF(NOT_USE_FUNCTION) ADD_DEFINITIONS("-DNOT_USE_FUNCTION") @@ -78,7 +74,6 @@ SET(${DOTNET_LAUNCHER}_SOURCE_FILES launcher/main.cc util/utils.cc launcher/launcher.cc - launcher/dotnet_signal_handler.cc launcher/dotnet/dotnet_launcher.cc ) ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${DOTNET_LAUNCHER}_SOURCE_FILES}) diff --git a/NativeLauncher/launcher/dotnet_signal_handler.cc b/NativeLauncher/launcher/dotnet_signal_handler.cc deleted file mode 100644 index 783f6c7..0000000 --- a/NativeLauncher/launcher/dotnet_signal_handler.cc +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2016 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 "dotnet_signal_handler.h" - -#include "log.h" - -#include -#include - -#include -#include -#include -#include - -using namespace std; - -#define CALLSTACK_SIZE 30 - -std::vector backtraceStr; -char **backtraceStrings; -int backtracePtrs; - -static void printBacktrace() -{ - if (backtraceStr.size() > 0) { - _ERR("Backtrace returned %d addresses :", backtraceStr.size()); - - for (unsigned int i = 0; i < backtraceStr.size(); i++) { - _ERR("[Backtrace #%d] : %s", i, backtraceStr[i].c_str()); - } - } - - backtraceStr.clear(); -} - -static bool nativeCrashCheck() -{ - int i; - void *buf[CALLSTACK_SIZE + 1]; - - backtracePtrs = backtrace(buf, CALLSTACK_SIZE); - if (backtracePtrs == 0) { - _ERR("No backtrace captured"); - return false; - } - - backtraceStrings = backtrace_symbols(buf, backtracePtrs); - - if (backtraceStrings == NULL) { - _ERR("No backtrace captured"); - return false; - } - - backtraceStr.clear(); - - for (i = backtracePtrs - 1; i >= 0; i--) { - if (strstr(backtraceStrings[i], "__default_rt_sa_restorer") != NULL) - return backtraceStr.size() > 0; - - backtraceStr.push_back(std::string(backtraceStrings[i])); - } - - return true; -} - -static void onSigabrt(int signum) -{ - _ERR("<<< SIGABRT %d >>>", signum); - - backtracePtrs = 0; - backtraceStrings = NULL; - - if (nativeCrashCheck()) { - printBacktrace(); -#ifdef RAISE_DEFAULT_SIGNAL_HANDLER - SIG_DFL(signum); -#endif - } else { - _ERR("Crash from managed code"); - } - - if (backtraceStrings != NULL) { - free(backtraceStrings); - backtraceStrings = NULL; - } - - exit(0); -} - -static void onSigsegv(int signum) -{ - _ERR("<<< SIGSEGV %d >>>", signum); - - backtracePtrs = 0; - backtraceStrings = NULL; - - if (nativeCrashCheck()) { - printBacktrace(); -#ifdef RAISE_DEFAULT_SIGNAL_HANDLER - SIG_DFL(signum); -#endif - } else { - _ERR("Crash from managed code"); - } - - if (backtraceStrings != NULL) { - free(backtraceStrings); - backtraceStrings = NULL; - } - - exit(0); -} - -static void onSigtrap(int signum) -{ - _ERR("<<< SIGTRAP %d >>>", signum); - - exit(0); -} - -void registerSignalHandler() -{ - _DBG("Register signal handler"); - - if (SIG_ERR == signal(SIGABRT, &onSigabrt) || - SIG_ERR == signal(SIGSEGV, &onSigsegv) || - SIG_ERR == signal(SIGTRAP, &onSigtrap)) { - perror("[dotnet-launcher] signal register error\n"); - _ERR("Signal register error"); - } -} diff --git a/NativeLauncher/launcher/dotnet_signal_handler.h b/NativeLauncher/launcher/dotnet_signal_handler.h deleted file mode 100644 index 9cbb62e..0000000 --- a/NativeLauncher/launcher/dotnet_signal_handler.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2016 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. - */ - - -#ifndef __DOTNET_SIGNAL_HANDLER__ -#define __DOTNET_SIGNAL_HANDLER__ - -void registerSignalHandler(); - -#endif /* __DOTNET_SIGNAL_HANDLER__ */ diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index b5fdb17..c23e16f 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -15,7 +15,6 @@ */ #include "dotnet/dotnet_launcher.h" -#include "dotnet_signal_handler.h" #include "utils.h" #include "log.h" @@ -41,8 +40,6 @@ static std::string StandaloneOption("--standalone"); int main(int argc, char *argv[]) { - registerSignalHandler(); - int i; bool standalone = false; const char* standalonePath = nullptr; diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index d41993a..6d4216e 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -63,11 +63,6 @@ launching dotnet apps without dotent runtime installed %define USE_MANAGED_LAUNCHER ENABLE %endif -%define raise_default_signal_handler 0 -%if %{raise_default_signal_handler} - %define RAISE_DEFAULT_SIGNAL_HANDLER ENABLE -%endif - %build cmake \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ @@ -87,7 +82,6 @@ cmake \ -DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \ -DVERSION=%{version} \ -DUSE_MANAGED_LAUNCHER=%{?USE_MANAGED_LAUNCHER:%USE_MANAGED_LAUNCHER} \ - -DRAISE_DEFAULT_SIGNAL_HANDLER=%{?RAISE_DEFAULT_SIGNAL_HANDLER:%RAISE_DEFAULT_SIGNAL_HANDLER} \ -DNATIVE_LIB_DIR=%{_native_lib_dir} \ NativeLauncher -- 2.7.4 From cc9146e37b31738fba3ef3ef88fae623568525e0 Mon Sep 17 00:00:00 2001 From: CHUNSEOK LEE Date: Thu, 20 Jul 2017 07:36:39 +0900 Subject: [PATCH 10/16] remove Self-Contained Deployment launcher Change-Id: I88bb4540725a62cbe331225654a55be0dd2702b3 Signed-off-by: CHUNSEOK LEE --- NativeLauncher/CMakeLists.txt | 17 +- NativeLauncher/launcher/dotnet/scd_launcher.cc | 580 ------------------------- packaging/dotnet-launcher.spec | 16 - 3 files changed, 1 insertion(+), 612 deletions(-) delete mode 100644 NativeLauncher/launcher/dotnet/scd_launcher.cc diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index e453d9a..6d78c6f 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -7,7 +7,7 @@ IF(DEFINED NO_TIZEN) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DNO_TIZEN") ELSE(DEFINED NO_TIZEN) INCLUDE(FindPkgConfig) - PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0 capi-appfw-app-control capi-appfw-service-application) + PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0) ENDIF(DEFINED NO_TIZEN) FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) @@ -80,20 +80,6 @@ ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${DOTNET_LAUNCHER}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER} PROPERTIES COMPILE_FLAGS "-fPIE") -SET(SCD_LAUNCHER "scd-launcher") -SET(${SCD_LAUNCHER}_SOURCE_FILES - launcher/dotnet/scd_launcher.cc -) -ADD_EXECUTABLE(${SCD_LAUNCHER} ${${SCD_LAUNCHER}_SOURCE_FILES}) -SET_TARGET_PROPERTIES(${SCD_LAUNCHER} PROPERTIES COMPILE_FLAGS "-fPIE") - - -IF(NOT DEFINED NO_TIZEN) - TARGET_LINK_LIBRARIES(${SCD_LAUNCHER} capi-appfw-app-control dlog appcore-agent) -ENDIF(NOT DEFINED NO_TIZEN) -TARGET_LINK_LIBRARIES(${SCD_LAUNCHER} ${${PROJECT_NAME}_LDFLAGS} "-pie -ldl -lpthread") - - IF(NOT DEFINED NO_TIZEN) TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER} aul) ENDIF(NOT DEFINED NO_TIZEN) @@ -137,7 +123,6 @@ TARGET_LINK_LIBRARIES(${PREFER_DOTNET_AOT_PLUGIN} ${${PROJECT_NAME}_LDFLAGS}) IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) - INSTALL(TARGETS ${SCD_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(TARGETS ${NITOOL} DESTINATION ${BINDIR}) # INSTALL(TARGETS ${INSTALLER_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) INSTALL(TARGETS ${PREFER_DOTNET_AOT_PLUGIN} DESTINATION ${INSTALL_MDPLUGIN_DIR}) diff --git a/NativeLauncher/launcher/dotnet/scd_launcher.cc b/NativeLauncher/launcher/dotnet/scd_launcher.cc deleted file mode 100644 index 7bbd883..0000000 --- a/NativeLauncher/launcher/dotnet/scd_launcher.cc +++ /dev/null @@ -1,580 +0,0 @@ -/* - * Copyright (c) 2016 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. - */ - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -// for serive_app -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "dotnet_launcher.h" - -using namespace std; - - -bool isDebugMode = false; -char *coreclrGdbjit[PATH_MAX]; -char *rootPath; - -bool service_app_create(void *data) -{ - // Todo: add your code here. - return true; -} - -void service_app_terminate(void *data) -{ - // Todo: add your code here. - - return; -} - -void service_app_control(app_control_h appControl, void *data) -{ - // Get _DEBUG_ value - char* buf[82]; - int ret = app_control_get_extra_data(appControl, "_SCD_DEBUG_", buf); - - if (ret == APP_CONTROL_ERROR_NONE) - if (strcmp(*buf, "1") == 0) - isDebugMode = true; - - if (isDebugMode) - ret = app_control_get_extra_data(appControl, "_SCD_CORECLR_GDBJIT_", coreclrGdbjit); - - service_app_exit(); - return; -} - - -// -// A simple CoreCLR host that runs a managed binary with the same name as this executable but with the *.dll extension -// The dll binary must contain a main entry point. -// - -#ifndef SUCCEEDED -#define SUCCEEDED(Status) ((Status) >= 0) -#endif // !SUCCEEDED - -static const char * const __CORECLR_DLL = "libcoreclr.so"; -// Name of the environment variable controlling server GC. -// If set to 1, server GC is enabled on startup. If 0, server GC is -// disabled. Server GC is off by default. -static const char* __SERVER_GC_VAR = "CORECLR_SERVER_GC"; -#define symlinkEntrypointExecutable "/proc/self/exe" - -bool getEntrypointExecutableabsolutePath(std::string& entrypointExecutable) -{ - bool result = false; - - entrypointExecutable.clear(); - - // Get path to the executable for the current process using - // platform specific means. - - // On Linux, fetch the entry point EXE absolute path, inclusive of filename. - char exe[PATH_MAX]; - ssize_t res = readlink(symlinkEntrypointExecutable, exe, PATH_MAX - 1); - if (res != -1) { - exe[res] = '\0'; - entrypointExecutable.assign(exe); - result = true; - } else { - result = false; - } - - return result; -} - -bool getabsolutePath(const char* path, std::string& absolutePath) -{ - bool result = false; - - char realPath[PATH_MAX]; - if (realpath(path, realPath) != nullptr && realPath[0] != '\0') { - absolutePath.assign(realPath); - // realpath should return canonicalized path without the trailing slash - assert(absolutePath.back() != '/'); - - result = true; - } - - return result; -} - -bool getDirectory(const char* absolutePath, std::string& directory) -{ - directory.assign(absolutePath); - size_t lastSlash = directory.rfind('/'); - if (lastSlash != std::string::npos) { - directory.erase(lastSlash); - return true; - } - - return false; -} - -bool getClrFilesabsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath) -{ - std::string clrFilesRelativePath; - const char* clrFilesPathLocal = clrFilesPath; - if (clrFilesPathLocal == nullptr) { - // There was no CLR files path specified, use the folder of the corerun/coreconsole - if (!getDirectory(currentExePath, clrFilesRelativePath)) { - perror("Failed to get directory from argv[0]"); - return false; - } - - clrFilesPathLocal = clrFilesRelativePath.c_str(); - - // TODO: consider using an env variable (if defined) as a fall-back. - // The windows version of the corerun uses core_root env variable - } - - if (!getabsolutePath(clrFilesPathLocal, clrFilesAbsolutePath)) { - perror("Failed to convert CLR files path to absolute path"); - return false; - } - - return true; -} - -void addFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList) -{ - const char * const tpaExtensions[] = { - ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir - ".dll", - ".ni.exe", - ".exe", - }; - - DIR* dir = opendir(directory); - if (dir == nullptr) - return; - - std::set addedAssemblies; - - // Walk the directory for each extension separately so that we first get files with .ni.dll extension, - // then files with .dll extension, etc. - for (unsigned int extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++) { - const char* ext = tpaExtensions[extIndex]; - int extLength = strlen(ext); - - struct dirent* entry; - - // For all entries in the directory - while ((entry = readdir(dir)) != nullptr) { - // We are interested in files only - switch (entry->d_type) { - case DT_REG: - break; - - // Handle symlinks and file systems that do not support d_type - case DT_LNK: - case DT_UNKNOWN: - { - std::string fullFileName; - - fullFileName.append(directory); - fullFileName.append("/"); - fullFileName.append(entry->d_name); - - struct stat sb; - if (stat(fullFileName.c_str(), &sb) == -1) - continue; - - if (!S_ISREG(sb.st_mode)) - continue; - } - break; - - default: - continue; - } - - std::string fileName(entry->d_name); - - // Check if the extension matches the one we are looking for - int extPos = fileName.length() - extLength; - if ((extPos <= 0) || (fileName.compare(extPos, extLength, ext) != 0)) - continue; - - std::string fileNameWithoutExt(fileName.substr(0, extPos)); - - // Make sure if we have an assembly with multiple extensions present, - // we insert only one version of it. - if (addedAssemblies.find(fileNameWithoutExt) == addedAssemblies.end()) { - addedAssemblies.insert(fileNameWithoutExt); - - tpaList.append(directory); - tpaList.append("/"); - tpaList.append(fileName); - tpaList.append(":"); - } - } - - // Rewind the directory stream to be able to iterate over it for the next extension - rewinddir(dir); - } - - closedir(dir); -} - -int executeManagedAssembly(const char* currentExeAbsolutePath, - const char* clrFilesAbsolutePath, - const char* managedAssemblyAbsolutePath, - int managedAssemblyArgc, - const char** managedAssemblyArgv) -{ - // Indicates failure - int exitCode = -1; - -#ifdef __arm__ - // libunwind library is used to unwind stack frame, but libunwind for ARM - // does not support ARM vfpv3/NEON registers in DWARF format correctly. - // Therefore let's disable stack unwinding using DWARF information - // See https://github.com/dotnet/coreclr/issues/6698 - // - // libunwind use following methods to unwind stack frame. - // UNW_ARM_METHOD_ALL 0xFF - // UNW_ARM_METHOD_DWARF 0x01 - // UNW_ARM_METHOD_FRAME 0x02 - // UNW_ARM_METHOD_EXIDX 0x04 - putenv(const_cast("UNW_ARM_UNWIND_METHOD=6")); -#endif // __arm__ - - std::string coreClrDllPath(clrFilesAbsolutePath); - coreClrDllPath.append("/"); - coreClrDllPath.append(__CORECLR_DLL); - - if (coreClrDllPath.length() >= PATH_MAX) { - fprintf(stderr, "Absolute path to libcoreclr.so too long\n"); - return -1; - } - - // Get just the path component of the managed assembly path - std::string appPath; - getDirectory(managedAssemblyAbsolutePath, appPath); - - std::string tpaList; - // Construct native search directory paths - std::string nativeDllSearchDirs(appPath); - char *coreLibraries = getenv("CORE_LIBRARIES"); - if (coreLibraries) { - nativeDllSearchDirs.append(":"); - nativeDllSearchDirs.append(coreLibraries); - if (std::strcmp(coreLibraries, clrFilesAbsolutePath) != 0) - addFilesFromDirectoryToTpaList(coreLibraries, tpaList); - } - nativeDllSearchDirs.append(":"); - nativeDllSearchDirs.append(clrFilesAbsolutePath); - - addFilesFromDirectoryToTpaList(clrFilesAbsolutePath, tpaList); - - void* __coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL); - if (__coreclrLib != nullptr) { - coreclr_initialize_ptr initializeCoreCLR = (coreclr_initialize_ptr)dlsym(__coreclrLib, "coreclr_initialize"); - coreclr_execute_assembly_ptr executeAssembly = (coreclr_execute_assembly_ptr)dlsym(__coreclrLib, "coreclr_execute_assembly"); - coreclr_shutdown_ptr shutdownCoreCLR = (coreclr_shutdown_ptr)dlsym(__coreclrLib, "coreclr_shutdown"); - - if (initializeCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n"); - } else if (executeAssembly == nullptr) { - fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n"); - } else if (shutdownCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n"); - } else { - // Check whether we are enabling server GC (off by default) - const char* useServerGc = std::getenv(__SERVER_GC_VAR); - if (useServerGc == nullptr) - useServerGc = "0"; - - // CoreCLR expects strings "true" and "false" instead of "1" and "0". - useServerGc = std::strcmp(useServerGc, "1") == 0 ? "true" : "false"; - - // Allowed property names: - // APPBASE - // - The base path of the application from which the exe and other assemblies will be loaded - // - // TRUSTED_PLATFORM_ASSEMBLIES - // - The list of complete paths to each of the fully trusted assemblies - // - // APP_PATHS - // - The list of paths which will be probed by the assembly loader - // - // APP_NI_PATHS - // - The list of additional paths that the assembly loader will probe for ngen images - // - // NATIVE_DLL_SEARCH_DIRECTORIES - // - The list of paths that will be probed for native DLLs called by PInvoke - // - const char *propertyKeys[] = { - "TRUSTED_PLATFORM_ASSEMBLIES", - "APP_PATHS", - "APP_NI_PATHS", - "NATIVE_DLL_SEARCH_DIRECTORIES", - "System.GC.Server", - }; - const char *propertyValues[] = { - // TRUSTED_PLATFORM_ASSEMBLIES - tpaList.c_str(), - // APP_PATHS - appPath.c_str(), - // APP_NI_PATHS - appPath.c_str(), - // NATIVE_DLL_SEARCH_DIRECTORIES - nativeDllSearchDirs.c_str(), - // System.GC.Server - useServerGc, - }; - - void* hostHandle; - unsigned int domainId; - - int st = initializeCoreCLR(currentExeAbsolutePath, - "unixcorerun", - sizeof(propertyKeys) / sizeof(propertyKeys[0]), - propertyKeys, - propertyValues, - &hostHandle, - &domainId); - - if (!SUCCEEDED(st)) { - fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st); - exitCode = -1; - } else { - st = executeAssembly(hostHandle, - domainId, - managedAssemblyArgc, - managedAssemblyArgv, - managedAssemblyAbsolutePath, - (unsigned int*)&exitCode); - - if (!SUCCEEDED(st)) { - fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st); - exitCode = -1; - } - - st = shutdownCoreCLR(hostHandle, domainId); - if (!SUCCEEDED(st)) { - fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st); - exitCode = -1; - } - } - } - - if (dlclose(__coreclrLib) != 0) { - fprintf(stderr, "Warning - dlclose failed\n"); - } - } else { - const char* error = dlerror(); - fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error); - } - - return exitCode; -} - - -// Display the help text -void displayUsage() -{ - fprintf(stderr, - "Runs executables on CoreCLR\n\n" - "Usage: [OPTIONS] [ARGUMENTS]\n" - "Runs .dll on CoreCLR.\n\n" - "Options:\n" - "-_c path to libcoreclr.so and the managed CLR assemblies.\n" - "-_h show this help message. \n"); -} - -// Parse the command line arguments -bool parseArguments(const int argc, - const char* argv[], - const char** clrFilesPath, - int* managedAssemblyArgc, - const char*** managedAssemblyArgv) -{ - bool success = true; - - *clrFilesPath = nullptr; - *managedAssemblyArgv = nullptr; - *managedAssemblyArgc = 0; - - for (int i = 1; i < argc; i++) { - // Check for options. Options to the Unix coreconsole are prefixed with '-_' to match the convention - // used in the Windows version of coreconsole. - if (strncmp(argv[i], "-_", 2) == 0) { - // Path to the libcoreclr.so and the managed CLR assemblies - if (strcmp(argv[i], "-_c") == 0) { - i++; - if (i < argc) { - *clrFilesPath = argv[i]; - } else { - fprintf(stderr, "Option %s: missing path\n", argv[i - 1]); - success = false; - break; - } - } else if (strcmp(argv[i], "-_h") == 0) { - displayUsage(); - success = false; - break; - } else { - fprintf(stderr, "Unknown option %s\n", argv[i]); - success = false; - break; - } - } else { - // We treat everything starting from the first non-option argument as arguments - // to the managed assembly. - *managedAssemblyArgc = argc - i; - if (*managedAssemblyArgc != 0) - *managedAssemblyArgv = &argv[i]; - - break; - } - } - - return success; -} - -int main(const int argc, const char* argv[]) -{ - /// service_app_begin - char *rootPath = getenv("AUL_ROOT_PATH"); - char *secondPass = getenv("SECONDPASS"); - - // This routine check whether _SCD_DEBUG_ flag is set(1) or not. - // In second pass, this routine is skipped. - if (secondPass == NULL) { - // run service_app routine to extract _SCD_DEBUG_ - char ad[50] = {0, }; - service_app_lifecycle_callback_s eventCallback; - eventCallback.create = service_app_create; - eventCallback.terminate = service_app_terminate; - eventCallback.app_control = service_app_control; - // FIXME: casting of argv is safe ? - service_app_main(argc, (char**)argv, &eventCallback, ad); - - char buf[PATH_MAX]; - vector vargs; - int status = 0; - - if (isDebugMode) { - dlog_print(DLOG_INFO, "dotnet", "debugmode on\n"); - setenv("CORECLR_GDBJIT", *coreclrGdbjit, 1); - - string curPath(getenv("PATH")); - string newPath("/home/owner/share/tmp/sdk_tools/lldb/bin:"); - newPath.append(curPath); - setenv("PATH", newPath.c_str(), 1); - - vargs.push_back("/home/owner/share/tmp/sdk_tools/lldb/bin/lldb-server"); - vargs.push_back("g"); - vargs.push_back("--platform=host"); - vargs.push_back("*:1234"); - vargs.push_back("--"); - } - snprintf(buf, sizeof(buf), "%s/bin/%s", rootPath, basename(rootPath)); - vargs.push_back(buf); - - // Pass app argument to lldb-server as it is - for (int i = 1; i < argc; i++) - vargs.push_back(argv[i]); - - const char** newArgs = &vargs[0]; - setenv("SECONDPASS", "1", 1); - status = execvp(newArgs[0], (char *const *)newArgs); - if (status == -1) - dlog_print(DLOG_ERROR, "dotnet", "execvp error"); - dlog_print(DLOG_INFO, "dotnet", "something wrong errno: %d\n", errno); - } - /// service_app_end - - // Make sure we have a full path for argv[0]. - std::string argv0AbsolutePath; - std::string entryPointExecutablePath; - - if (!getEntrypointExecutableabsolutePath(entryPointExecutablePath)) { - perror("Could not get full path to current executable"); - return -1; - } - - if (!getabsolutePath(entryPointExecutablePath.c_str(), argv0AbsolutePath)) { - perror("Could not normalize full path to current executable"); - return -1; - } - - // We will try to load the managed assembly with the same name as this executable - // but with the .dll extension. - std::string programPath(argv0AbsolutePath); - programPath.append(".dll"); - const char* managedAssemblyAbsolutePath = programPath.c_str(); - - // Check if the specified managed assembly file exists - struct stat sb; - if (stat(managedAssemblyAbsolutePath, &sb) == -1) { - perror("Managed assembly not found"); - return -1; - } - - // Verify that the managed assembly path points to a file - if (!S_ISREG(sb.st_mode)) { - fprintf(stderr, "The specified managed assembly is not a file\n"); - return -1; - } - - const char* clrFilesPath; - const char** managedAssemblyArgv; - int managedAssemblyArgc; - if (!parseArguments(argc, argv, &clrFilesPath, &managedAssemblyArgc, &managedAssemblyArgv)) - return -1; - - std::string clrFilesAbsolutePath; - if (!getClrFilesabsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath)) - return -1; - - int exitCode = executeManagedAssembly(argv0AbsolutePath.c_str(), - clrFilesAbsolutePath.c_str(), - managedAssemblyAbsolutePath, - managedAssemblyArgc, - managedAssemblyArgv); - - return exitCode; -} diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 6d4216e..7f4d46c 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -20,14 +20,6 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: aul-devel BuildRequires: dotnet-build-tools -# Required by scd-launcher -BuildRequires: appcore-agent -BuildRequires: pkgconfig(appcore-agent) -BuildRequires: pkgconfig(capi-appfw-app-control) -BuildRequires: pkgconfig(capi-appfw-application) -BuildRequires: pkgconfig(capi-appfw-service-application) - - Requires: aul Requires(post): /sbin/ldconfig @@ -49,11 +41,6 @@ ExcludeArch: aarch64 %description Launchpad plugin for launching dotnet apps -%package -n scd-launcher -Summary: self-contained dotnet launcher -%description -n scd-launcher -launching dotnet apps without dotent runtime installed - %prep %setup -q @@ -112,6 +99,3 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %{_bindir}/Tizen.Runtime.dll %endif %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher - -%files -n scd-launcher -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/scd-launcher -- 2.7.4 From 6d179f13ad595875a0843741036930b1bf683760 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Wed, 19 Jul 2017 19:47:31 +0900 Subject: [PATCH 11/16] remove getenv Change-Id: Ia1c1c021ba8d31060643d44bf94aa6928761e957 --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 15 --------------- NativeLauncher/launcher/main.cc | 15 +++++++++------ NativeLauncher/util/utils.cc | 1 + 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 6724558..6adff4b 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -112,21 +112,6 @@ int CoreRuntime::initialize(bool standalone) putenv(const_cast("UNW_ARM_UNWIND_METHOD=6")); #endif // __arm__ - if (standalone) { - const char *deviceApiDirectory = getenv("__deviceAPIDirectory"); - const char *runtimeDirectory = getenv("__runtimeDirectory"); - if (deviceApiDirectory != nullptr) - __deviceAPIDirectory = deviceApiDirectory; - if (runtimeDirectory != nullptr) - __runtimeDirectory = runtimeDirectory; - -#ifdef USE_MANAGED_LAUNCHER - const char *launcherAssembly = getenv("__launcherAssembly"); - if (launcherAssembly != nullptr) - __launcherAssembly = launcherAssembly; -#endif - } - if (__deviceAPIDirectory.empty()) { _ERR("Empty Device API Directory"); return 1; diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index c23e16f..b5e566c 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -25,6 +25,8 @@ #include #include #include +#include +#include #define __XSTR(x) #x #define __STR(x) __XSTR(x) @@ -76,19 +78,20 @@ int main(int argc, char *argv[]) if (standalone) { _DBG("##### Run it standalone #########"); - const char* appId = getenv("AUL_APPID"); - _DBG("AUL_APPID : %s", appId); + char appId[1024] = {0,}; std::string appRoot; - if (appId != nullptr) { + if (AUL_R_OK == aul_app_get_appid_bypid(getpid(), appId, sizeof(appId))) { const char* appRootPath = aul_get_app_root_path(); if (appRootPath != nullptr) appRoot = std::string(appRootPath); } else { - appId = "dotnet-launcher"; + // If appId is not set, it is executed directly by cmdline. + // In this case, appRoot is passed as an argument. + snprintf(appId, 16, "%s", "dotnet-launcher"); + appRoot = baseName(baseName(standalonePath)); } + _DBG("AUL_APPID : %s", appId); - if (appRoot.empty()) - appRoot = baseName(baseName(standalonePath)); if (runtime->initialize(true) != 0) { _ERR("Failed to initialize"); return 1; diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index d5cf5d3..92440f1 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -145,6 +145,7 @@ static bool extCheckAndGetFileNameIfExist(const std::string& dir, const std::str if (fName.length() < ext.length() || fHame.compare(fName.length() - ext.length(), ext.length(), ext) != 0) { return false; + } std::string fullName = concatPath(dir, entry->d_name); switch (entry->d_type) { -- 2.7.4 From c9e5d8e142aa02dfeffe1d31ff819fffd899ae5a Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Tue, 1 Aug 2017 18:28:14 +0900 Subject: [PATCH 12/16] temporal patch for setting LANG environment value Change-Id: I0999f2ef62119d9d1d6278d09be915399ba6b0a1 --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 6adff4b..b268357 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -21,6 +21,8 @@ #include #include +#include + #include "utils.h" #include "log.h" #include "launcher.h" @@ -288,8 +290,27 @@ void CoreRuntime::dispose() _DBG("Dotnet runtime disposed"); } +static void setLang() +{ + char *lang; + lang = vconf_get_str(VCONFKEY_LANGSET); + if (lang) { + _DBG("setenv for language setting : %s", lang); + setenv("LANG", lang, 1); + setenv("LC_MESSAGES", lang, 1); + } +} + int CoreRuntime::launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) { + // temporal patch to set LANG for coreclr. + // below code will be removed after applying appfw patch. + setLang(); + + vconf_notify_key_changed(VCONFKEY_LANGSET, [](keynode_t* node, void* user_data) { + setLang(); + }, NULL); + if (path == nullptr) { _ERR("executable path is null"); return 1; -- 2.7.4 From 03ce03422d3d65f8a5ead86e2bb14b364e6a5ce4 Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Thu, 24 Aug 2017 16:17:40 +0900 Subject: [PATCH 13/16] Add requires to launchpad Change-Id: I69d11c13bc633e296833160cb52cf946b57778bf --- packaging/dotnet-launcher.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 7f4d46c..c9b0b7c 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -21,6 +21,7 @@ BuildRequires: aul-devel BuildRequires: dotnet-build-tools Requires: aul +Requires: launchpad Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl -- 2.7.4 From ab0c34497889634785b9c2c7efbbc5067363c18f Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Mon, 28 Aug 2017 19:01:38 +0900 Subject: [PATCH 14/16] Add null check Change-Id: I94bb4d6f6a3b56e71bc25b7f2a9bf5ba6f233b2c --- NativeLauncher/installer-plugin/common.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 8ba2a09..74b6f18 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -132,6 +132,10 @@ static void crossgen(const char* dllPath, const char* appPath) // get reference API directory ([DEVICE_API_DIR]/ref) int len = strlen(__DEVICE_API_DIR); char* refAPIDir = (char*)calloc(len + 4, 1); + if (!refAPIDir) { + printf("fail to allocate memory for reference API directory\n"); + return; + } snprintf(refAPIDir, len + 4, "%s%s", __DEVICE_API_DIR, "/ref"); tpaDir.push_back(refAPIDir); -- 2.7.4 From 91c9d05a8aa766d359443f478f6b00fbf4359c93 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Wed, 30 Aug 2017 15:25:45 +0900 Subject: [PATCH 15/16] change cmdline to executable path for standalone mode. after adapting this change, crash dump will be generated with executable name not dotnet-launcher Change-Id: I1052f2d8740f6d51dff978871252e2cbe10a1d63 --- NativeLauncher/launcher/main.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index b5e566c..b532832 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -44,7 +44,8 @@ int main(int argc, char *argv[]) { int i; bool standalone = false; - const char* standalonePath = nullptr; + char* standalonePath = nullptr; + int cmdlineSize = 0; std::vector vargs; @@ -61,10 +62,11 @@ int main(int argc, char *argv[]) return 1; } i++; - standalonePath = argv[i]; + standalonePath = strdup(argv[i]); } else { vargs.push_back(argv[i]); } + cmdlineSize += (strlen(argv[i]) +1); } using tizen::runtime::LauncherInterface; @@ -97,6 +99,10 @@ int main(int argc, char *argv[]) return 1; } + // change cmdline from dotnet-launcher to executable path + memset(argv[0], '\0', cmdlineSize); + snprintf(argv[0], cmdlineSize, "%s", standalonePath); + int argsLen = vargs.size(); char** args = &vargs[0]; if (runtime->launch(appId, appRoot.c_str(), standalonePath, argsLen, args)) { @@ -126,6 +132,10 @@ int main(int argc, char *argv[]) Launchpad.loaderMain(argc, argv); } + if (standalonePath != nullptr) { + free(standalonePath); + } + runtime->dispose(); return 0; } -- 2.7.4 From 8564ec92b5775026190ed190e81b272324fda4de Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Tue, 5 Sep 2017 08:58:51 +0900 Subject: [PATCH 16/16] bug-fix: to pass argument, change exectuable name to appid Change-Id: I1873bec7879c97c449060b98c895d8437a3a45f4 --- NativeLauncher/launcher/main.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index b532832..a3ad62b 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -37,6 +37,8 @@ #define LAUNCHER_VERSION_STR __STR(VERSION) #endif +#define CMD_LINE_SIZE 24 // sizeof("/usr/bin/dotnet-launcher") + static std::string VersionOption("--version"); static std::string StandaloneOption("--standalone"); @@ -45,7 +47,6 @@ int main(int argc, char *argv[]) int i; bool standalone = false; char* standalonePath = nullptr; - int cmdlineSize = 0; std::vector vargs; @@ -62,11 +63,10 @@ int main(int argc, char *argv[]) return 1; } i++; - standalonePath = strdup(argv[i]); + standalonePath = argv[i]; } else { vargs.push_back(argv[i]); } - cmdlineSize += (strlen(argv[i]) +1); } using tizen::runtime::LauncherInterface; @@ -100,8 +100,8 @@ int main(int argc, char *argv[]) } // change cmdline from dotnet-launcher to executable path - memset(argv[0], '\0', cmdlineSize); - snprintf(argv[0], cmdlineSize, "%s", standalonePath); + memset(argv[0], '\0', CMD_LINE_SIZE); + snprintf(argv[0], CMD_LINE_SIZE - 1, "%s", appId); int argsLen = vargs.size(); char** args = &vargs[0]; @@ -132,10 +132,6 @@ int main(int argc, char *argv[]) Launchpad.loaderMain(argc, argv); } - if (standalonePath != nullptr) { - free(standalonePath); - } - runtime->dispose(); return 0; } -- 2.7.4