From 2169c2f2e0c92929f20ba81c4eb0dcd43819a71c Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 8 Sep 2017 11:24:07 +0900 Subject: [PATCH 01/16] bug-patch:support -am option Change-Id: I3e71bef55eea848e52bf4b417ddcab582b3421f0 --- tools/performance_test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/performance_test.sh b/tools/performance_test.sh index ed289fb..3519cc4 100755 --- a/tools/performance_test.sh +++ b/tools/performance_test.sh @@ -132,7 +132,7 @@ execute_time_stamp_auto () echo "" #execute dlogstreamer sdb shell "dlogutil -c" - sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done]'" >> $STREAM_LOG_FILE & + sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE & DLOG_STREAMER_PID=$! #execute timestamp /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE & @@ -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 LAUNCH|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|Launching:done'" >> $STREAM_LOG_FILE & + sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE & DLOG_STREAMER_PID=$! #execute timestamp /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE & @@ -181,7 +181,7 @@ execute_time_stamp_manual_trace () rm $STREAM_LOG_FILE touch $STREAM_LOG_FILE sdb shell "dlogutil -c" - sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|Launching:done'" >> $STREAM_LOG_FILE & + sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $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 LAUNCH|grep -E 'app_request_to_launchpad_for_uid.*[SECURE_LOG].*launch.*request|Launching:done'" >> $STREAM_LOG_FILE & + sdb shell "dlogutil -v time AUL LAUNCH|grep -E 'launch.*app_request_to_launchpad_for_uid.*request.*appid|Launching:done'" >> $STREAM_LOG_FILE & DLOG_STREAMER_PID=$! #execute timestamp /bin/bash ./timestamp.sh $STREAM_LOG_FILE $RESULT_LOG_FILE & -- 2.7.4 From b8364639ea341f44381271cc186c4299c317f5a3 Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Wed, 19 Jul 2017 14:49:39 +0900 Subject: [PATCH 02/16] Remove caps due to security issue. Apply caps directly in security-config Change-Id: I476d6928065762427d360e22518bf8330266808f --- packaging/dotnet-launcher.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index c9b0b7c..d4045f2 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -99,4 +99,3 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %if %{use_managed_launcher} %{_bindir}/Tizen.Runtime.dll %endif -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher -- 2.7.4 From 1f4fe78e4b16ccff778af75592a77f85cca11d5b Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 3 Nov 2017 13:30:12 +0900 Subject: [PATCH 03/16] add dotnet-launcher to files list to remove build error Change-Id: I88b3dab1dff4a7e30bfe1e6dfaee06b2d8edaf6b --- packaging/dotnet-launcher.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index d4045f2..1bebcca 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -99,3 +99,4 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %if %{use_managed_launcher} %{_bindir}/Tizen.Runtime.dll %endif +%{_bindir}/dotnet-launcher \ No newline at end of file -- 2.7.4 From 74702a30ffb1af33dc4c50ccf8c2c7e9ef19db60 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 3 Nov 2017 13:48:30 +0900 Subject: [PATCH 04/16] add cap_sys_admin and cap_setgid to dotnet-launcher to use candidate process Change-Id: I5034c7cca0d967708b69f3495d6665a4f49cf847 --- packaging/dotnet-launcher.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 1bebcca..369d243 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -99,4 +99,4 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %if %{use_managed_launcher} %{_bindir}/Tizen.Runtime.dll %endif -%{_bindir}/dotnet-launcher \ No newline at end of file +%caps(cap_sys_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher -- 2.7.4 From 3e3d508f3fa04835c34edc480f1cb9be4d3f8867 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Tue, 14 Nov 2017 15:32:31 +0900 Subject: [PATCH 05/16] add exception handling code for null return Change-Id: I41834f55e6d8d9e33a8d76bead8b281aec2c1a65 --- NativeLauncher/launcher/launcher.cc | 5 ++++- NativeLauncher/launcher/main.cc | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/NativeLauncher/launcher/launcher.cc b/NativeLauncher/launcher/launcher.cc index 91c24a1..e0b5ed0 100644 --- a/NativeLauncher/launcher/launcher.cc +++ b/NativeLauncher/launcher/launcher.cc @@ -177,7 +177,10 @@ int LaunchpadAdapterImpl::loaderMain(int argc, char* argv[]) const char* appId, const char* pkgId, const char* pkgType, void* userData) -> int { WITH_SELF(userData) { - self->appInfo.root = std::string(aul_get_app_root_path()); + const char* appRootPath = aul_get_app_root_path(); + if (appRootPath != nullptr) { + self->appInfo.root = std::string(appRootPath); + } self->appInfo.path = appPath; self->appInfo.id = appId; self->appInfo.pkg = pkgId; diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 6fcfb9b..6c1ac12 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -123,11 +123,15 @@ int main(int argc, char *argv[]) _DBG("pkg : %s", appInfo.pkg.c_str()); _DBG("type : %s", appInfo.type.c_str()); - // The launchpad pass the name of exe file to the first argument. - // For the C# spec, we have to skip this first argument. - - if (runtime->launch(appInfo.id.c_str(), appInfo.root.c_str(), appInfo.path.c_str(), argc-1, argv+1)) - _ERR("Failed to launch"); + // aul_get_app_root_path() can return NULL for error case. + if (appInfo.root.empty()) { + _ERR("Failed to launch. root path is set to NULL"); + } else { + // The launchpad pass the name of exe file to the first argument. + // For the C# spec, we have to skip this first argument. + if (runtime->launch(appInfo.id.c_str(), appInfo.root.c_str(), appInfo.path.c_str(), argc-1, argv+1)) + _ERR("Failed to launch"); + } }; int ret = Launchpad.loaderMain(argc, argv); if (ret < 0) { -- 2.7.4 From b9e2f8612cc34f8b34290ebb7e3c628664b8026f Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Tue, 28 Nov 2017 14:04:34 +0900 Subject: [PATCH 06/16] redirect stdout and stderr to dlog Change-Id: I4c5fe9f676e5fa3f5f8009eac910976e933acffd --- NativeLauncher/inc/utils.h | 2 + NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 4 ++ NativeLauncher/util/utils.cc | 69 ++++++++++++++++++++++- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 034b7f3..ac3816e 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -43,4 +43,6 @@ std::string joinStrings(const std::vector& strings, const char* con typedef std::function FileReader; void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth); + +int runLoggingThread(); #endif /* __UTILS_H__ */ diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index db93b4f..f19e5af 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -335,6 +335,10 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i if (pluginBeforeExecute) pluginBeforeExecute(); + if (runLoggingThread() < 0) { + _ERR("Failed to create logging thread"); + } + #ifdef USE_MANAGED_LAUNCHER runManagedLauncher(appId, probePath.c_str(), tpa.c_str()); diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 92440f1..d4142eb 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -14,12 +14,13 @@ * limitations under the License. */ - +#include #include #include #include #include #include +#include #include #include @@ -30,6 +31,10 @@ #include #include "utils.h" +#include "log.h" + +static int pfd[2]; +static pthread_t loggingThread; bool iCompare(const std::string& a, const std::string& b) { @@ -292,4 +297,64 @@ void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth scanFilesInDir(d.c_str(), reader, depth-1); closedir(dir); -} \ No newline at end of file +} + +static void *stdlog(void*) +{ + ssize_t readSize; + char buf[1024]; + + while ((readSize = read(pfd[0], buf, sizeof buf - 1)) > 0) { + if (buf[readSize - 1] == '\n') { + --readSize; + } + + buf[readSize] = 0; + + _INFO("%s", buf); + } + + return 0; +} + +int runLoggingThread() { // run this function to redirect your output to android log + if (setvbuf(stdout, NULL, _IOLBF, 0) < 0) { + _DBG("fail to make stdout line-buffered"); + return -1; + } + + if (setvbuf(stderr, NULL, _IONBF, 0) < 0) { + _DBG("make stderr unbuffered"); + return -1; + } + + /* create the pipe and redirect stdout and stderr */ + if (pipe(pfd) < 0) { + _DBG("fail to create pipe for logging"); + return -1; + } + + if (dup2(pfd[1], fileno(stdout)) == -1) { + _DBG("fail to duplicate fd to stdout"); + return -1; + } + + if (dup2(pfd[1], fileno(stderr)) == -1) { + _DBG("fail to duplicate fd to stderr"); + return -1; + } + + /* spawn the logging thread */ + if (pthread_create(&loggingThread, 0, stdlog, 0) != 0) { + _DBG("fail to create pthread"); + return -1; + } + + if (pthread_detach(loggingThread) != 0) { + _DBG("fail to detach pthread"); + return -1; + } + + return 0; +} + -- 2.7.4 From 47b44f39311e68172008c9ec9ee4a3cb9a53599d Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Tue, 5 Dec 2017 14:24:53 +0900 Subject: [PATCH 07/16] Coreclr needs original executable dll path not ni file path for dll loading. ni file searching is automatically done in the inside of coreclr Change-Id: I14fc7629431a3b082da06189dd2031a61b571afa --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index f19e5af..36df3ca 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -344,15 +344,6 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i bool success = false; if (launchFunction != nullptr) { - std::string cppPath(path); - - if (isManagedAssembly(cppPath) && !isNativeImage(cppPath)) { - size_t extindex = cppPath.size() - 4; - cppPath = cppPath.substr(0, extindex) + ".ni" + cppPath.substr(extindex, 4); - if (!fileNotExist(cppPath)) - path = cppPath.c_str(); - } - success = launchFunction(root, path, argc, argv); if (!success) _ERR("Failed to launch Application %s", path); -- 2.7.4 From 15df655ca41ee7e06d9e0ab7e35d0ca708a07c93 Mon Sep 17 00:00:00 2001 From: Konstantin Baladurin Date: Wed, 6 Dec 2017 09:18:22 +0300 Subject: [PATCH 08/16] Add option to enable clang Asan build. Now we can add '--define "asan_enabled 1"' option for gbs to enable Asan build. Change-Id: Iac347386c26e3a72aa1275c312550df809aff003 --- NativeLauncher/CMakeLists.txt | 15 +++++++++++---- packaging/dotnet-launcher.spec | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 6d78c6f..166e542 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -52,14 +52,21 @@ IF(NOT_USE_FUNCTION) ENDIF(NOT_USE_FUNCTION) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread -std=c++11 -Wl,--no-as-needed -ggdb") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread -std=c++11 -ggdb") #SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") #SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fdata-sections -ffunction-sections") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -D_FILE_OFFSET_BITS=64") #SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DLAUNCHING_TIME_MEASURE") +IF(ASAN_ENABLED) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fno-omit-frame-pointer -fsanitize=address") +ELSE(ASAN_ENABLED) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs") + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,--no-as-needed") + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,--gc-sections") +ENDIF(ASAN_ENABLED) + SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_CXX_FLAGS_DEBUG "-O2 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") @@ -129,4 +136,4 @@ IF(NOT DEFINED NO_TIZEN) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) -ENDIF(NOT DEFINED NO_TIZEN) +ENDIF(NOT DEFINED NO_TIZEN) \ No newline at end of file diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 369d243..66bb45d 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -20,6 +20,11 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: aul-devel BuildRequires: dotnet-build-tools +%if 0%{?asan_enabled} +BuildRequires: clang >= 3.8 +BuildRequires: compiler-rt +%endif + Requires: aul Requires: launchpad @@ -52,8 +57,24 @@ Launchpad plugin for launching dotnet apps %endif %build + +%if 0%{?asan_enabled} +%define _dotnet_build_conf Debug +export CFLAGS=" --target=%{_host} " +export CXXFLAGS=" --target=%{_host} " +%ifarch %{ix86} +export CFLAGS=$(echo $CFLAGS | sed -e 's/--target=i686/--target=i586/') +export CXXFLAGS=$(echo $CXXFLAGS | sed -e 's/--target=i686/--target=i586/') +%endif +%endif + cmake \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ +%if 0%{?asan_enabled} + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DASAN_ENABLED=TRUE \ +%endif -DPACKAGE_NAME=%{name} \ -DLIBDIR=%{_libdir} \ -DBINDIR=%{_bindir} \ -- 2.7.4 From 2d6890e13b6edb6c503b7e90e2a075bb0b553ff4 Mon Sep 17 00:00:00 2001 From: chunseok lee Date: Thu, 14 Dec 2017 16:03:37 +0900 Subject: [PATCH 09/16] Add COMPlus_ZapDisable env variable This patch is required to enable gdbjit with NI files Change-Id: Ic470761589480722fcae79720cd0bf6fe1004bbf Signed-off-by: chunseok lee (cherry picked from commit 4f26ced1190958c415fadc1356e54ae19920b4ae) --- NativeLauncher/dotnet.debugger | 1 + 1 file changed, 1 insertion(+) diff --git a/NativeLauncher/dotnet.debugger b/NativeLauncher/dotnet.debugger index 6f57cde..7a89927 100644 --- a/NativeLauncher/dotnet.debugger +++ b/NativeLauncher/dotnet.debugger @@ -4,3 +4,4 @@ EXE /home/owner/share/tmp/sdk_tools/lldb/bin/lldb-server APP_TYPE dotnet EXTRA_KEY __DLP_DEBUG_ARG__ EXTRA_ENV CORECLR_GDBJIT +EXTRA_ENV COMPlus_ZapDisable -- 2.7.4 From b93c8563bbbbae4b2152561053a8bb83fdf4efae Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Wed, 13 Dec 2017 16:30:12 +0900 Subject: [PATCH 10/16] remove module/function name from stderr log Change-Id: I48980d8579ed68a54460a795b550e853a80e67c5 --- NativeLauncher/inc/log.h | 10 ++++++++++ NativeLauncher/util/utils.cc | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/inc/log.h b/NativeLauncher/inc/log.h index 5769204..3315f8e 100644 --- a/NativeLauncher/inc/log.h +++ b/NativeLauncher/inc/log.h @@ -19,11 +19,17 @@ #ifndef NO_TIZEN #include +#define LOGX(fmt, arg...) \ + ({ do { \ + dlog_print(DLOG_ERROR, LOG_TAG, fmt, ##arg); \ + } while (0); }) + #else #include #define LOGE(fmt, args...) printf(fmt, ##args) #define LOGD(fmt, args...) printf(fmt, ##args) #define LOGI(fmt, args...) printf(fmt, ##args) +#define LOGX(fmt, args...) printf(fmt, ##args) #endif #ifdef LOG_TAG @@ -43,4 +49,8 @@ #define _INFO(fmt, args...) LOGI(fmt "\n", ##args) #endif +#ifndef _ERRX +#define _ERRX(fmt, args...) LOGX(fmt "\n", ##args) +#endif + #endif /* __LOG_H__ */ diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index d4142eb..f5b9406 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -311,7 +311,7 @@ static void *stdlog(void*) buf[readSize] = 0; - _INFO("%s", buf); + _ERRX("%s", buf); } return 0; -- 2.7.4 From 15bdbf0a11617b306fd5690fe585776c60c26056 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 15 Dec 2017 08:04:23 +0900 Subject: [PATCH 11/16] Remove code related to %caps. caps is handled by security team. Change-Id: I8998e71d86dc6436bcd262cde74da1a6a3cfdd76 --- packaging/dotnet-launcher.spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 369d243..ae0c072 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -99,4 +99,5 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %if %{use_managed_launcher} %{_bindir}/Tizen.Runtime.dll %endif -%caps(cap_sys_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher +%{_bindir}/dotnet-launcher + -- 2.7.4 From 3e0666401c881951d4bf2312d657d4ba491cd685 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Wed, 24 Jan 2018 11:13:20 +0900 Subject: [PATCH 12/16] add interval between each crossgen Change-Id: I9688331704322452cebe0a454ca03cf6bcf6d9e9 (cherry picked from commit 1b1fd307e364a6a6088f0aff31158035b8d6fb85) --- NativeLauncher/installer-plugin/common.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index f7fc71b..f1d212e 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -35,6 +35,8 @@ #include #include +#include + #include "common.h" #ifdef LOG_TAG @@ -338,6 +340,17 @@ int createNiUnderPkgRoot(const char* pkgName) if (getRootPath(pkgName, pkgRoot) < 0) return 1; + // get interval value + const char* intervalFile = "/usr/share/dotnet.tizen/lib/crossgen_interval.txt"; + int interval = 0; + std::ifstream inFile(intervalFile); + if (inFile) { + _INFO("crossgen_interval.txt is found"); + inFile >> interval; + } else { + _INFO("fail to read crossgen_interval.txt file"); + } + std::string binDir = concatPath(pkgRoot, "bin"); std::string libDir = concatPath(pkgRoot, "lib"); _INFO("bindir : %s", binDir.c_str()); @@ -350,8 +363,12 @@ int createNiUnderPkgRoot(const char* pkgName) // change smack label for generated ni file. std::string label = "User::Pkg::" + std::string(pkgName) + "::RO"; - createNiUnderDirs(paths, 2, [label](const char* ni) { + createNiUnderDirs(paths, 2, [label, interval](const char* ni) { smack_(ni, label.c_str()); + if (interval != 0) { + _INFO("sleep %d usec", interval); + usleep(interval); + } }); return 0; -- 2.7.4 From 8f7d31aa63f3747b821c21aa616570048135da0f Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Thu, 25 Jan 2018 11:37:48 +0900 Subject: [PATCH 13/16] Initialize coreclr in the candidate process and change ON_BOOT value to OFF Change-Id: Ia1984c310a59dc7d8d011f73c2dbd64164d8c7d1 (cherry picked from commit 43a03fd7fb4fb983f493fc42599a55950ced466c) --- NativeLauncher/CMakeLists.txt | 10 +- NativeLauncher/dotnet.loader | 1 + NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 142 ++++++------------ NativeLauncher/launcher/dotnet/dotnet_launcher.h | 3 +- NativeLauncher/launcher/launcher.h | 1 - Tizen.Runtime/CoreClr/AssemblyLoader.cs | 135 ----------------- Tizen.Runtime/CoreClr/AssemblyManager.cs | 174 ---------------------- Tizen.Runtime/Log.cs | 77 ---------- Tizen.Runtime/Tizen.Runtime.csproj | 11 -- packaging/dotnet-launcher.spec | 17 --- 10 files changed, 47 insertions(+), 524 deletions(-) delete mode 100644 Tizen.Runtime/CoreClr/AssemblyLoader.cs delete mode 100644 Tizen.Runtime/CoreClr/AssemblyManager.cs delete mode 100644 Tizen.Runtime/Log.cs delete mode 100644 Tizen.Runtime/Tizen.Runtime.csproj diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 166e542..98d60c8 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -18,10 +18,6 @@ IF(DEFINED LAUNCHER_CONFIG_PATH) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DLAUNCHER_CONFIG_PATH=${LAUNCHER_CONFIG_PATH}") ENDIF(DEFINED LAUNCHER_CONFIG_PATH) -IF(DEFINED CORECLR_LAUNCHER_ASSEMBLY_PATH) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DCORECLR_LAUNCHER_ASSEMBLY_PATH=${CORECLR_LAUNCHER_ASSEMBLY_PATH}") -ENDIF(DEFINED CORECLR_LAUNCHER_ASSEMBLY_PATH) - IF(DEFINED DEVICE_API_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DDEVICE_API_DIR=${DEVICE_API_DIR}") ENDIF(DEFINED DEVICE_API_DIR) @@ -42,10 +38,6 @@ IF(DEFINED NATIVE_LIB_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DNATIVE_LIB_DIR=${NATIVE_LIB_DIR}") ENDIF(DEFINED NATIVE_LIB_DIR) -IF(USE_MANAGED_LAUNCHER STREQUAL "ENABLE") - ADD_DEFINITIONS("-DUSE_MANAGED_LAUNCHER") -ENDIF(USE_MANAGED_LAUNCHER) - OPTION(NOT_USE_FUNCTION "Remove build warning" OFF) IF(NOT_USE_FUNCTION) ADD_DEFINITIONS("-DNOT_USE_FUNCTION") @@ -136,4 +128,4 @@ IF(NOT DEFINED NO_TIZEN) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) -ENDIF(NOT DEFINED NO_TIZEN) \ No newline at end of file +ENDIF(NOT DEFINED NO_TIZEN) diff --git a/NativeLauncher/dotnet.loader b/NativeLauncher/dotnet.loader index 78bb74f..9fac64c 100644 --- a/NativeLauncher/dotnet.loader +++ b/NativeLauncher/dotnet.loader @@ -4,6 +4,7 @@ EXE /usr/bin/dotnet-launcher APP_TYPE dotnet DETECTION_METHOD TIMEOUT|DEMAND TIMEOUT 5000 +ON_BOOT OFF EXTRA_ARRAY preload EXTRA_ARRAY_VAL /usr/lib/libappcore-efl.so.1 EXTRA_ARRAY_VAL /usr/lib/libappcore-common.so.1 diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 36df3ca..265c925 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -21,6 +21,12 @@ #include #include +#include +#include +#include +#include +#include + #include "utils.h" #include "log.h" #include "launcher.h" @@ -49,7 +55,8 @@ CoreRuntime::CoreRuntime() : pluginSetCoreclrInfo(nullptr), pluginGetDllPath(nullptr), pluginBeforeExecute(nullptr), - pluginFinalize(nullptr) + pluginFinalize(nullptr), + fd(0) { #define __XSTR(x) #x #define __STR(x) __XSTR(x) @@ -64,12 +71,6 @@ CoreRuntime::CoreRuntime() : __nativeLibDirectory = __STR(NATIVE_LIB_DIR); #endif -#ifdef USE_MANAGED_LAUNCHER -#ifdef CORECLR_LAUNCHER_ASSEMBLY_PATH - __launcherAssembly = __STR(CORECLR_LAUNCHER_ASSEMBLY_PATH); -#endif -#endif - #undef __STR #undef __XSTR @@ -131,15 +132,6 @@ int CoreRuntime::initialize(bool standalone) // set Reference API directory __refAPIDirectory = __deviceAPIDirectory + "/ref"; -#ifdef USE_MANAGED_LAUNCHER - if (__launcherAssembly.empty()) { - _ERR("Empty Launcher Assembly"); - return 1; - } else { - __launcherAssembly = absolutePath(__launcherAssembly); - } -#endif - std::string libCoreclr(concatPath(__runtimeDirectory, "libcoreclr.so")); _DBG("libcoreclr : %s", libCoreclr.c_str()); @@ -172,6 +164,38 @@ int CoreRuntime::initialize(bool standalone) if (!standalone && pluginPreload) pluginPreload(); + fd = open("/proc/self", O_DIRECTORY); + std::string path_tmp = std::string("/proc/self/fd/") + std::to_string(fd); + + std::string appRoot = path_tmp; + std::string appBin = concatPath(appRoot, "bin"); + std::string appLib = concatPath(appRoot, "lib"); + std::string probePath = appBin + ":" + appLib; + + std::string tpa; + std::vector searchDirectories; + searchDirectories.push_back(__runtimeDirectory); + searchDirectories.push_back(__deviceAPIDirectory); + searchDirectories.push_back(__refAPIDirectory); + + if (pluginGetDllPath) { + std::string pluginPath = pluginGetDllPath(); + if (!pluginPath.empty()) { + searchDirectories.push_back(pluginPath); + } + } + + assembliesInDirectory(searchDirectories, tpa); + + std::string nativeLibPath; + nativeLibPath = appLib + ":" + appBin + ":" + __nativeLibDirectory; + + std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid()); + if (!initializeCoreClr(appName.c_str(), probePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) { + _ERR("Failed to initialize coreclr"); + return 1; + } + return 0; } @@ -218,47 +242,6 @@ bool CoreRuntime::initializeCoreClr(const char* appId, return true; } -int CoreRuntime::runManagedLauncher(const char* appId, const char* appBase, const char* tpaList) -{ - if (fileNotExist(__launcherAssembly)) { - _ERR("Launcher assembly is not exist in %s", __launcherAssembly.c_str()); - return 1; - } - - if (!initializeCoreClr(appId, appBase, appBase, tpaList)) { - _ERR("Failed to initialize coreclr"); - return 1; - } - -#ifdef USE_MANAGED_LAUNCHER - void *preparedFunctionDelegate; - int st = createDelegate(__hostHandle, __domainId, - "Tizen.Runtime", - "Tizen.Runtime.Coreclr.AssemblyManager", - "Prepared", &preparedFunctionDelegate); - if (st < 0) { - _ERR("Create delegate for Launch prepared function is fail (0x%08x)", st); - return 1; - } - preparedFunction = reinterpret_cast(preparedFunctionDelegate); - - if (preparedFunction != nullptr) - preparedFunction(); - - void *launchFunctionDelegate; - st = createDelegate(__hostHandle, __domainId, - "Tizen.Runtime", - "Tizen.Runtime.Coreclr.AssemblyManager", - "Launch", &launchFunctionDelegate); - if (st < 0) { - _ERR("Create delegate for Launch managed function is fail! (0x%08x)", st); - return 1; - } - launchFunction = reinterpret_cast(launchFunctionDelegate); -#endif - return 0; -} - void CoreRuntime::dispose() { if (__hostHandle != nullptr) { @@ -307,30 +290,9 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i if (pluginSetAppInfo) pluginSetAppInfo(appId, path); - std::string tpa; - std::string appRoot = root; - std::string appBin = concatPath(appRoot, "bin"); - std::string appLib = concatPath(appRoot, "lib"); - std::string probePath = appBin + ":" + appLib + ":" + __nativeLibDirectory; - - 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); -#ifdef USE_MANAGED_LAUNCHER - searchDirectories.push_back(baseName(__launcherAssembly)); -#endif - - assembliesInDirectory(searchDirectories, tpa); + int fd2 = open(root, O_DIRECTORY); + dup3(fd2, fd, O_CLOEXEC); + close(fd2); if (pluginBeforeExecute) pluginBeforeExecute(); @@ -339,27 +301,11 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i _ERR("Failed to create logging thread"); } -#ifdef USE_MANAGED_LAUNCHER - runManagedLauncher(appId, probePath.c_str(), tpa.c_str()); - - bool success = false; - if (launchFunction != nullptr) { - success = launchFunction(root, path, argc, argv); - if (!success) - _ERR("Failed to launch Application %s", path); - return success ? 0 : 1; - } else { - _ERR("Failed to find launch function"); - return 1; - } -#else - int st = initializeCoreClr(appId, probePath.c_str(), probePath.c_str(), tpa.c_str()); unsigned int ret = 0; - st = executeAssembly(__hostHandle, __domainId, argc, (const char**)argv, path, &ret); + int st = executeAssembly(__hostHandle, __domainId, argc, (const char**)argv, path, &ret); if (st < 0) _ERR("Failed to Execute Assembly %s (0x%08x)", path, st); return ret; -#endif } } // namespace dotnetcore diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index aaaa9d8..998b0f8 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -83,7 +83,6 @@ class CoreRuntime : public tizen::runtime::LauncherInterface ~CoreRuntime(); int initialize(bool standalone) override; void dispose() override; - int runManagedLauncher(const char* appId, const char* appBase, const char* tpaList) override; int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) override; private: @@ -94,7 +93,6 @@ class CoreRuntime : public tizen::runtime::LauncherInterface coreclr_create_delegate_ptr createDelegate; std::string __deviceAPIDirectory; std::string __runtimeDirectory; - std::string __launcherAssembly; std::string __nativeLibDirectory; std::string __refAPIDirectory; void* __coreclrLib; @@ -111,6 +109,7 @@ class CoreRuntime : public tizen::runtime::LauncherInterface plugin_get_dll_path_ptr pluginGetDllPath; plugin_before_execute_ptr pluginBeforeExecute; plugin_finalize_ptr pluginFinalize; + int fd; }; } // dotnetcore diff --git a/NativeLauncher/launcher/launcher.h b/NativeLauncher/launcher/launcher.h index ce91241..38934b4 100644 --- a/NativeLauncher/launcher/launcher.h +++ b/NativeLauncher/launcher/launcher.h @@ -28,7 +28,6 @@ class LauncherInterface public: virtual int initialize(bool standalone) = 0; virtual void dispose() = 0; - virtual int runManagedLauncher(const char* appId, const char* appBase, const char* tpaList) = 0; virtual int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) = 0; }; diff --git a/Tizen.Runtime/CoreClr/AssemblyLoader.cs b/Tizen.Runtime/CoreClr/AssemblyLoader.cs deleted file mode 100644 index c6de690..0000000 --- a/Tizen.Runtime/CoreClr/AssemblyLoader.cs +++ /dev/null @@ -1,135 +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. - */ - -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.Loader; -using System.Collections.Generic; - -namespace Tizen.Runtime.Coreclr -{ - public class AssemblyLoader : AssemblyLoadContext - { - private const string NativeAssemblyInfix = ".ni"; - private const string DllAssemblySuffix = ".dll"; - private const string ExeAssemblySuffix = ".exe"; - private const string NativeDllAssemblySuffix = NativeAssemblyInfix + DllAssemblySuffix; - private static readonly string[] Suffixes = new string[] { NativeDllAssemblySuffix, DllAssemblySuffix, ExeAssemblySuffix }; - private SortedSet DllDirectoriesSet = new SortedSet(); - private SortedSet NativeDirectoriesSet = new SortedSet(); - private HashSet AssemblyCacheSet = new HashSet(); - - public AssemblyLoader() - { - AssemblyLoadContext.Default.Resolving += OnResolving; - } - - public IEnumerable DllDirectories - { - get { return DllDirectoriesSet; } - } - - public IEnumerable NativeDirectories - { - get { return NativeDirectoriesSet; } - } - - public void AddSearchableDirectory(string directory) - { - if (Directory.Exists(directory)) - { - DllDirectoriesSet.Add(directory); - NativeDirectoriesSet.Add(directory); - - foreach (var file in Directory.GetFiles(directory)) - { - var info = new FileInfo(file); - - if (Suffixes.Contains(info.Extension)) - { - AssemblyCacheSet.Add(info); - } - } - } - } - - public void RemoveSearchableDirectory(string directory) - { - DllDirectoriesSet.Remove(directory); - NativeDirectoriesSet.Remove(directory); - - AssemblyCacheSet.RemoveWhere(x => x.DirectoryName == directory); - } - - public Assembly LoadFromPath(string path) - { - if (string.Compare(path, path.Length - NativeDllAssemblySuffix.Length, NativeAssemblyInfix, 0, NativeAssemblyInfix.Length, StringComparison.OrdinalIgnoreCase) == 0) - { - return LoadFromNativeImagePath(path, null); - } - else - { - return LoadFromAssemblyPath(path); - } - } - - protected override Assembly Load(AssemblyName assemblyName) - { - return Resolve(assemblyName); - } - - protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) - { - IntPtr native = base.LoadUnmanagedDll(unmanagedDllName); - if (native == IntPtr.Zero) - { - foreach (string dir in NativeDirectories) - { - FileInfo f = new FileInfo(Path.Combine(dir, unmanagedDllName)); - if (File.Exists(f.FullName)) - { - native = LoadUnmanagedDllFromPath(f.FullName); - break; - } - } - } - - return native; - } - - private Assembly Resolve(AssemblyName assemblyName) - { - foreach (string suffix in Suffixes) - { - var info = AssemblyCacheSet.FirstOrDefault(x => x.Name == assemblyName.Name + suffix); - - if (info != null) - { - return LoadFromPath(info.FullName); - } - } - - return null; - } - - private Assembly OnResolving(AssemblyLoadContext context, AssemblyName assemblyName) - { - return Resolve(assemblyName); - } - } -} diff --git a/Tizen.Runtime/CoreClr/AssemblyManager.cs b/Tizen.Runtime/CoreClr/AssemblyManager.cs deleted file mode 100644 index 60b3e54..0000000 --- a/Tizen.Runtime/CoreClr/AssemblyManager.cs +++ /dev/null @@ -1,174 +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. - */ - -using System; -using System.IO; -using System.Reflection; -using System.Runtime.Loader; -using System.Linq; -using System.Runtime.InteropServices; - -namespace Tizen.Runtime.Coreclr -{ - public static class AssemblyManager - { - public static AssemblyLoader CurrentAssemblyLoaderContext - { - get; - private set; - } - - public static bool Launch( - [In] string rootPath, - [In] string path, - [In] int argc, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] - [In] string[] argv) - { - ALog.Debug($"Application Launch path : {path}"); - try - { - DirectoryInfo binDir = new DirectoryInfo(Path.Combine(rootPath, "bin")); - DirectoryInfo libDir = new DirectoryInfo(Path.Combine(rootPath, "lib")); - if (Directory.Exists(binDir.FullName)) - { - CurrentAssemblyLoaderContext.AddSearchableDirectory(binDir.FullName); - } - - if (Directory.Exists(libDir.FullName)) - { - CurrentAssemblyLoaderContext.AddSearchableDirectory(libDir.FullName); - } - - Execute(path, argv); - } - catch (Exception e) - { - ALog.Debug("Exception in Launch()"); - PrintException(e); - return false; - } - - return true; - } - - public static void Prepared() - { - try - { - if (!Initialize()) - { - ALog.Debug($"Failed to Initialized"); - } - } - catch (Exception e) - { - ALog.Debug("Exception at Preparing"); - PrintException(e); - } - } - - public static void UnhandledExceptionHandler(object sender, object args) - { - TypeInfo unhandledExceptionEventArgsType = - Type.GetType("UnhandledExceptionEventArgs").GetTypeInfo(); - - PropertyInfo exception = unhandledExceptionEventArgsType.GetProperty("ExceptionObject"); - Exception e = (Exception)exception.GetValue(args); - - PrintException(e); - } - - public static bool Initialize() - { - try - { - // Set UnhandledException handler with reflection - // we must replace this to no reflection method after AppDomain is comming in used net standard - TypeInfo appdomainType = Type.GetType("System.AppDomain").GetTypeInfo(); - PropertyInfo currentDomain = appdomainType.GetProperty("CurrentDomain", - BindingFlags.Public | BindingFlags.Static); - EventInfo unhandledException = appdomainType.GetDeclaredEvent("UnhandledException"); - object appDomain = currentDomain.GetValue(null, null); - MethodInfo handlerInfo = typeof(AssemblyManager).GetTypeInfo().GetDeclaredMethod("UnhandledExceptionHandler"); - Delegate handler = handlerInfo.CreateDelegate(unhandledException.EventHandlerType); - var addMethod = unhandledException.GetAddMethod(true); - addMethod.Invoke(appDomain, new[] {handler}); - } - catch (Exception e) - { - ALog.Debug("Exception on set handler for unhandled exception"); - PrintException(e); - } - - try - { - CurrentAssemblyLoaderContext = new AssemblyLoader(); - } - catch (Exception e) - { - ALog.Debug("Exception on Initialized"); - PrintException(e); - return false; - } - - return true; - } - - public static void Execute(string dllPath, string[] argv) - { - try - { - FileInfo f = new FileInfo(dllPath); - if (File.Exists(f.FullName)) - { - Assembly asm = CurrentAssemblyLoaderContext.LoadFromPath(f.FullName); - - if (asm == null) - { - throw new FileNotFoundException($"{f.FullName} is not found"); - } - - if (asm.EntryPoint == null) - { - throw new ArgumentException($"{f.FullName} did not have EntryPoint"); - } - - asm.EntryPoint.Invoke(null, new object[] {argv}); - } - else - { - ALog.Debug($"Requested file does not exist: {dllPath}"); - } - } - catch (Exception e) - { - ALog.Debug("Exception on Execute"); - PrintException(e); - } - } - - private static void PrintException(Exception exception) - { - while (exception != null) - { - ALog.Debug(exception.ToString()); - exception = exception.InnerException; - } - } - - } -} diff --git a/Tizen.Runtime/Log.cs b/Tizen.Runtime/Log.cs deleted file mode 100644 index 86b7e6f..0000000 --- a/Tizen.Runtime/Log.cs +++ /dev/null @@ -1,77 +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. - */ - -using System; -using System.IO; -using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; - -namespace Tizen.Runtime -{ - internal static class ALog - { - const string Library = "libdlog.so.0"; - const string Tag = "DOTNET_LAUNCHER"; - - internal enum LogPriority - { - DLOG_UNKNOWN = 0, - DLOG_DEFAULT, - DLOG_VERBOSE, - DLOG_DEBUG, - DLOG_INFO, - DLOG_WARN, - DLOG_ERROR, - DLOG_FATAL, - DLOG_SILENT, - DLOG_PRIO_MAX, - } - - public static void Debug(string message, - [CallerFilePath] string file = "", - [CallerMemberName] string function = "", - [CallerLineNumber] int line = 0) - { - Print(LogPriority.DLOG_DEBUG, Tag, message, file, function, line); - } - - public static void Info(string message, - [CallerFilePath] string file = "", - [CallerMemberName] string function = "", - [CallerLineNumber] int line = 0) - { - Print(LogPriority.DLOG_INFO, Tag, message, file, function, line); - } - - public static void Error(string message, - [CallerFilePath] string file = "", - [CallerMemberName] string function = "", - [CallerLineNumber] int line = 0) - { - Print(LogPriority.DLOG_ERROR, Tag, message, file, function, line); - } - - [DllImportAttribute(Library, EntryPoint = "dlog_print")] - internal static extern int Print(LogPriority priority, string tag, string format, string file, string function, int line, string msg); - - private static void Print(LogPriority priority, string tag, string message, string file, string function, int line) - { - FileInfo fileInfo = new FileInfo(file); - Print(priority, tag, "%s: %s(%d) > %s", fileInfo.Name, function, line, message); - } - - } -} diff --git a/Tizen.Runtime/Tizen.Runtime.csproj b/Tizen.Runtime/Tizen.Runtime.csproj deleted file mode 100644 index a232a3a..0000000 --- a/Tizen.Runtime/Tizen.Runtime.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - netstandard1.6 - - - - - - - \ No newline at end of file diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 5f233e8..19c42ff 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -51,11 +51,6 @@ Launchpad plugin for launching dotnet apps %prep %setup -q -%define use_managed_launcher 0 -%if %{use_managed_launcher} - %define USE_MANAGED_LAUNCHER ENABLE -%endif - %build %if 0%{?asan_enabled} @@ -84,26 +79,17 @@ cmake \ -DDEVICE_API_DIR=%{_device_api_dir} \ -DRUNTIME_DIR=%{_runtime_dir} \ -DCROSSGEN_PATH=%{_device_api_dir}/crossgen \ -%if %{use_managed_launcher} - -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.dll \ -%endif -DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \ -DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \ -DVERSION=%{version} \ - -DUSE_MANAGED_LAUNCHER=%{?USE_MANAGED_LAUNCHER:%USE_MANAGED_LAUNCHER} \ -DNATIVE_LIB_DIR=%{_native_lib_dir} \ NativeLauncher make %{?jobs:-j%jobs} VERBOSE=1 -%dotnet_build Tizen.Runtime - %install rm -rf %{buildroot} %make_install -%if %{use_managed_launcher} -install -p -m 644 Tizen.Runtime/bin/*/*/Tizen.Runtime.dll %{buildroot}%{_bindir} -%endif mkdir -p %{buildroot}%{_native_lib_dir} ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so @@ -117,8 +103,5 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %{_bindir}/nitool #%{_install_plugin_dir}/libui-application.so %{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so -%if %{use_managed_launcher} -%{_bindir}/Tizen.Runtime.dll -%endif %{_bindir}/dotnet-launcher -- 2.7.4 From 49f6c9a5c2bd5b2ad296c84c4217d49c5c6f11c7 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 2 Feb 2018 11:57:16 +0900 Subject: [PATCH 14/16] support multi-architecture library for lib dir Change-Id: Id603602bf46d477f3aa57813ad2f7c19e07aad9c (cherry picked from commit 39ed7656c266b754e71eb430c02ad60a980d869d) --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 265c925..af29793 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -38,6 +38,29 @@ namespace tizen { namespace runtime { namespace dotnetcore { +#if defined (__aarch64__) +#define ARCHITECTURE_IDENTIFIER "arm64" +#elif defined (__arm__) +#define ARCHITECTURE_IDENTIFIER "arm" +#elif defined (__x86_64__) +#define ARCHITECTURE_IDENTIFIER "x64" +#elif defined (__i386__) +#define ARCHITECTURE_IDENTIFIER "x86" +#else +#define ARCHITECTURE_IDENTIFIER "unknown" +#endif + +static std::string getExtraNativeLibDirs(const std::string& appRoot) +{ + // auto generated directory by nuget will be considered later + std::string candidate = concatPath(appRoot, "lib/" ARCHITECTURE_IDENTIFIER); + if (!strncmp(ARCHITECTURE_IDENTIFIER, "arm64", 5)) { + candidate = candidate + ":" + concatPath(appRoot, "lib/aarch64"); + } + + return candidate; +} + CoreRuntime::CoreRuntime() : initializeClr(nullptr), executeAssembly(nullptr), @@ -188,7 +211,7 @@ int CoreRuntime::initialize(bool standalone) assembliesInDirectory(searchDirectories, tpa); std::string nativeLibPath; - nativeLibPath = appLib + ":" + appBin + ":" + __nativeLibDirectory; + nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appLib + ":" + appBin + ":" + __nativeLibDirectory; std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid()); if (!initializeCoreClr(appName.c_str(), probePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) { -- 2.7.4 From 2df3ee43dbc1e1814113833e83cca249fd522355 Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Thu, 22 Feb 2018 16:45:11 +0900 Subject: [PATCH 15/16] multi-architecture support Change-Id: Id7e7fc24b6fa35ca547e441a297d5d6325fef41b (cherry picked from commit db615b8826eed0fad8ecccd687b0b77d620c8ebf) --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index af29793..fb0d6be 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -40,20 +40,39 @@ namespace dotnetcore { #if defined (__aarch64__) #define ARCHITECTURE_IDENTIFIER "arm64" +const static std::vector RID_FALLBACK_GRAPH = + {"linux-arm64", "linux", "unix-arm64", "unix", "any", "base"}; + #elif defined (__arm__) #define ARCHITECTURE_IDENTIFIER "arm" +const static std::vector RID_FALLBACK_GRAPH = + {"tizen.4.0.0-armel", "tizen.4.0.0", "tizen-armel", "tizen", "linux-armel", "linux", "unix-armel", "unix", "any", "base"}; + #elif defined (__x86_64__) #define ARCHITECTURE_IDENTIFIER "x64" +const static std::vector RID_FALLBACK_GRAPH = + {"linux-x64", "linux", "unix-x64", "unix", "any", "base"}; + #elif defined (__i386__) #define ARCHITECTURE_IDENTIFIER "x86" +const static std::vector RID_FALLBACK_GRAPH = + {"linux-x86", "linux", "unix-x86", "unix", "any", "base"}; + #else -#define ARCHITECTURE_IDENTIFIER "unknown" +#error "Unknown target" #endif static std::string getExtraNativeLibDirs(const std::string& appRoot) { - // auto generated directory by nuget will be considered later - std::string candidate = concatPath(appRoot, "lib/" ARCHITECTURE_IDENTIFIER); + std::string candidate; + for (int i = 0; i < RID_FALLBACK_GRAPH.size(); i++) { + if(!candidate.empty()) { + candidate += ":"; + } + candidate += concatPath(appRoot, "bin/runtimes/" + RID_FALLBACK_GRAPH[i] + "/native"); + } + + candidate = candidate + ":" + concatPath(appRoot, "lib/" ARCHITECTURE_IDENTIFIER); if (!strncmp(ARCHITECTURE_IDENTIFIER, "arm64", 5)) { candidate = candidate + ":" + concatPath(appRoot, "lib/aarch64"); } @@ -211,7 +230,7 @@ int CoreRuntime::initialize(bool standalone) assembliesInDirectory(searchDirectories, tpa); std::string nativeLibPath; - nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appLib + ":" + appBin + ":" + __nativeLibDirectory; + nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appBin + ":" + appLib + ":" + __nativeLibDirectory; std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid()); if (!initializeCoreClr(appName.c_str(), probePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) { -- 2.7.4 From c1b4ac62588a8aced5baf44f39fac353821a0e1a Mon Sep 17 00:00:00 2001 From: Cho Woong Suk Date: Fri, 23 Feb 2018 11:45:10 +0900 Subject: [PATCH 16/16] to send stdout to dlog, move logging thread creation point Change-Id: I929a29ce4f92b547eaa74f5bdf95c5c83c202946 (cherry picked from commit 65ee437b4cf72d4e4720f5d9c7c2e1d0a0d28676) --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 4 +++ NativeLauncher/util/utils.cc | 44 ++++++++++++----------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index fb0d6be..cc511ab 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -319,6 +319,10 @@ void CoreRuntime::dispose() int CoreRuntime::launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) { + if (runLoggingThread() < 0) { + _ERR("Failed to create logging thread"); + } + if (path == nullptr) { _ERR("executable path is null"); return 1; diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index f5b9406..ce01795 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -33,7 +33,6 @@ #include "utils.h" #include "log.h" -static int pfd[2]; static pthread_t loggingThread; bool iCompare(const std::string& a, const std::string& b) @@ -301,49 +300,54 @@ void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth static void *stdlog(void*) { + int pfd[2]; ssize_t readSize; char buf[1024]; - while ((readSize = read(pfd[0], buf, sizeof buf - 1)) > 0) { - if (buf[readSize - 1] == '\n') { - --readSize; - } - - buf[readSize] = 0; - - _ERRX("%s", buf); - } - - return 0; -} - -int runLoggingThread() { // run this function to redirect your output to android log if (setvbuf(stdout, NULL, _IOLBF, 0) < 0) { _DBG("fail to make stdout line-buffered"); - return -1; + return 0; } if (setvbuf(stderr, NULL, _IONBF, 0) < 0) { _DBG("make stderr unbuffered"); - return -1; + return 0; } /* create the pipe and redirect stdout and stderr */ if (pipe(pfd) < 0) { _DBG("fail to create pipe for logging"); - return -1; + return 0; } if (dup2(pfd[1], fileno(stdout)) == -1) { _DBG("fail to duplicate fd to stdout"); - return -1; + return 0; } if (dup2(pfd[1], fileno(stderr)) == -1) { _DBG("fail to duplicate fd to stderr"); - return -1; + return 0; } + close(pfd[1]); + + while ((readSize = read(pfd[0], buf, sizeof buf - 1)) > 0) { + if (buf[readSize - 1] == '\n') { + --readSize; + } + + buf[readSize] = 0; + + _ERRX("%s", buf); + } + + close(pfd[0]); + + return 0; +} + +int runLoggingThread() { /* spawn the logging thread */ if (pthread_create(&loggingThread, 0, stdlog, 0) != 0) { _DBG("fail to create pthread"); -- 2.7.4