From f15cc24b978a6650d51ccb3d62cef85ec2ad0306 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Mon, 10 Oct 2016 14:12:09 +0900 Subject: [PATCH 01/16] Coreclr & Mono Supported launcher and standalone Switch launcher engine with "/etc/.use_mono" file Now can run assembly standalone with "--standalone" option Change-Id: I120053756f4d86107dfe716cf5675389b7a9760d --- NativeLauncher/CMakeLists.txt | 15 +- NativeLauncher/inc/launcher.h | 27 ++- NativeLauncher/src/dotnet/base64.cc | 94 --------- NativeLauncher/src/dotnet/base64.h | 11 -- NativeLauncher/src/dotnet/dotnet_launcher.cc | 162 +++++----------- NativeLauncher/src/dotnet/dotnet_launcher.h | 18 +- NativeLauncher/src/launcher.cc | 201 +++++++++---------- NativeLauncher/src/main.cc | 108 +++++++++++ NativeLauncher/src/mono/mono_launcher.cc | 213 +++++++++++++++++++++ NativeLauncher/src/mono/mono_launcher.h | 78 ++++++++ ...Runtime.csproj => Tizen.Runtime.Coreclr.csproj} | 10 +- .../AssemblyLoader.cs | 2 +- .../AssemblyManager.cs | 138 +++---------- Tizen.Runtime/Tizen.Runtime.Mono.csproj | 75 ++++++++ .../Tizen.Runtime.Mono/AssemblyManager.cs | 153 +++++++++++++++ Tizen.Runtime/Tizen.Runtime/Ini.cs | 139 -------------- Tizen.Runtime/Tizen.Runtime/Interop.cs | 28 --- Tizen.Runtime/Tizen.Runtime/Log.cs | 53 ++++- Tizen.Runtime/Tizen.Runtime/test.cs | 21 -- packaging/dotnet-launcher.spec | 17 +- 20 files changed, 887 insertions(+), 676 deletions(-) delete mode 100644 NativeLauncher/src/dotnet/base64.cc delete mode 100644 NativeLauncher/src/dotnet/base64.h create mode 100644 NativeLauncher/src/main.cc create mode 100644 NativeLauncher/src/mono/mono_launcher.cc create mode 100644 NativeLauncher/src/mono/mono_launcher.h rename Tizen.Runtime/{Tizen.Runtime.csproj => Tizen.Runtime.Coreclr.csproj} (87%) rename Tizen.Runtime/{Tizen.Runtime => Tizen.Runtime.Coreclr}/AssemblyLoader.cs (98%) rename Tizen.Runtime/{Tizen.Runtime => Tizen.Runtime.Coreclr}/AssemblyManager.cs (55%) create mode 100644 Tizen.Runtime/Tizen.Runtime.Mono.csproj create mode 100644 Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs delete mode 100644 Tizen.Runtime/Tizen.Runtime/Ini.cs delete mode 100644 Tizen.Runtime/Tizen.Runtime/Interop.cs delete mode 100644 Tizen.Runtime/Tizen.Runtime/test.cs diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 203ffb7..00657be 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -18,9 +18,13 @@ IF(DEFINED LAUNCHER_CONFIG_PATH) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DLAUNCHER_CONFIG_PATH=${LAUNCHER_CONFIG_PATH}") ENDIF(DEFINED LAUNCHER_CONFIG_PATH) -IF(DEFINED LAUNCHER_ASSEMBLY_PATH) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DLAUNCHER_ASSEMBLY_PATH=${LAUNCHER_ASSEMBLY_PATH}") -ENDIF(DEFINED LAUNCHER_ASSEMBLY_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 MONO_LAUNCHER_ASSEMBLY_PATH) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DMONO_LAUNCHER_ASSEMBLY_PATH=${MONO_LAUNCHER_ASSEMBLY_PATH}") +ENDIF(DEFINED MONO_LAUNCHER_ASSEMBLY_PATH) IF(DEFINED DEVICE_API_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DDEVICE_API_DIR=${DEVICE_API_DIR}") @@ -30,7 +34,7 @@ IF(DEFINED RUNTIME_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DRUNTIME_DIR=${RUNTIME_DIR}") ENDIF(DEFINED RUNTIME_DIR) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread -std=c++11 -Wl,--no-as-needed") +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} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") @@ -49,10 +53,11 @@ SET(DOTNET_LAUNCHER "dotnet-launcher") SET(MONO_LAUNCHER "mono-launcher") SET(${DOTNET_LAUNCHER}_SOURCE_FILES + src/main.cc src/utils.cc src/launcher.cc src/dotnet/dotnet_launcher.cc - src/dotnet/base64.cc + src/mono/mono_launcher.cc ) ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${PROJECT_NAME}_SOURCE_FILES}) diff --git a/NativeLauncher/inc/launcher.h b/NativeLauncher/inc/launcher.h index f4309b4..399bef5 100644 --- a/NativeLauncher/inc/launcher.h +++ b/NativeLauncher/inc/launcher.h @@ -1,28 +1,37 @@ #ifndef __LAUNCHER_INTERFACE_H__ #define __LAUNCHER_INTERFACE_H__ +#include +#include + namespace tizen { namespace runtime { class LauncherInterface { public: - virtual int Initialize() = 0; + virtual int Initialize(bool standalone) = 0; virtual void Dispose() = 0; virtual int RunManagedLauncher() = 0; - virtual int Launch(const char* path, int argc, char* argv[]) = 0; + virtual int Launch(const char* root, const char* path, int argc, char* argv[]) = 0; +}; + +struct AppInfo +{ + std::string root; + std::string path; + std::string id; + std::string pkg; + std::string type; }; class LaunchpadAdapter { public: - virtual void LoaderMain(LauncherInterface* launcher, int argc, char* argv[]) = 0; - virtual void WaitUtilLaunched() = 0; - - protected: - virtual void OnCreate() = 0; - virtual void OnLaunch() = 0; - virtual void OnTerminate() = 0; + virtual void LoaderMain(int argc, char* argv[]) = 0; + std::function OnCreate = nullptr; + std::function OnLaunch = nullptr; + std::function OnTerminate = nullptr; }; extern LaunchpadAdapter& Launchpad; diff --git a/NativeLauncher/src/dotnet/base64.cc b/NativeLauncher/src/dotnet/base64.cc deleted file mode 100644 index 3330082..0000000 --- a/NativeLauncher/src/dotnet/base64.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "base64.h" -#include - -static const std::string base64_chars = -"ABCDEFGHIJKLMNOPQRSTUVWXYZ" -"abcdefghijklmnopqrstuvwxyz" -"0123456789+/"; - - -static inline bool is_base64(BYTE c) { - return (isalnum(c) || (c == '+') || (c == '/')); -} - -std::string base64_encode(BYTE const* buf, unsigned int bufLen) { - std::string ret; - int i = 0; - int j = 0; - BYTE char_array_3[3]; - BYTE char_array_4[4]; - - while (bufLen--) { - char_array_3[i++] = *(buf++); - if (i == 3) { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for(i = 0; (i <4) ; i++) - ret += base64_chars[char_array_4[i]]; - i = 0; - } - } - - if (i) - { - for(j = i; j < 3; j++) - char_array_3[j] = '\0'; - - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for (j = 0; (j < i + 1); j++) - ret += base64_chars[char_array_4[j]]; - - while((i++ < 3)) - ret += '='; - } - - return ret; -} - -std::vector base64_decode(std::string const& encoded_string) { - int in_len = encoded_string.size(); - int i = 0; - int j = 0; - int in_ = 0; - BYTE char_array_4[4], char_array_3[3]; - std::vector ret; - - while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { - char_array_4[i++] = encoded_string[in_]; in_++; - if (i ==4) { - for (i = 0; i <4; i++) - char_array_4[i] = base64_chars.find(char_array_4[i]); - - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - - for (i = 0; (i < 3); i++) - ret.push_back(char_array_3[i]); - i = 0; - } - } - - if (i) { - for (j = i; j <4; j++) - char_array_4[j] = 0; - - for (j = 0; j <4; j++) - char_array_4[j] = base64_chars.find(char_array_4[j]); - - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - - for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]); - } - - return ret; -} diff --git a/NativeLauncher/src/dotnet/base64.h b/NativeLauncher/src/dotnet/base64.h deleted file mode 100644 index 1a6b6ba..0000000 --- a/NativeLauncher/src/dotnet/base64.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _BASE64_H_ -#define _BASE64_H_ - -#include -#include -typedef unsigned char BYTE; - -std::string base64_encode(BYTE const* buf, unsigned int bufLen); -std::vector base64_decode(std::string const&); - -#endif diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.cc b/NativeLauncher/src/dotnet/dotnet_launcher.cc index 4942710..62738a3 100644 --- a/NativeLauncher/src/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/src/dotnet/dotnet_launcher.cc @@ -3,7 +3,6 @@ #include #include -#include #include #include "utils.h" @@ -15,43 +14,12 @@ namespace tizen { namespace runtime { namespace dotnetcore { - -void CoreRuntime::SetStandaloneExe(const char* exePath, int argc, char* argv[]) -{ - if (exePath == nullptr) - { - _ERR("executable path is null"); - return; - } - - if (FileNotExist(exePath)) - { - _ERR("File not exist : %s", exePath); - return; - } - - isLaunched = true; - LaunchParam.path = exePath; - LaunchParam.argc = argc; - LaunchParam.argv = argv; - - const char *_deviceapi_directory = getenv("DeviceAPIDirectory"); - const char *_runtime_directory = getenv("RuntimeDirectory"); - const char *_launcher_assembly = getenv("LauncherAssembly"); - if (_deviceapi_directory != nullptr) - DeviceAPIDirectory = _deviceapi_directory; - if (_runtime_directory != nullptr) - RuntimeDirectory = _runtime_directory; - if (_launcher_assembly != nullptr) - LauncherAssembly = _launcher_assembly; -} - CoreRuntime::CoreRuntime() : coreclrLib(nullptr), hostHandle(nullptr), domainId(-1), + PreparedFunction(nullptr), LaunchFunction(nullptr), - isLaunched(false), InitializeClr(nullptr), ExecuteAssembly(nullptr), Shutdown(nullptr), @@ -66,8 +34,8 @@ CoreRuntime::CoreRuntime() : #ifdef RUNTIME_DIR RuntimeDirectory = __STR(RUNTIME_DIR); #endif -#ifdef LAUNCHER_ASSEMBLY_PATH - LauncherAssembly = __STR(LAUNCHER_ASSEMBLY_PATH); +#ifdef CORECLR_LAUNCHER_ASSEMBLY_PATH + LauncherAssembly = __STR(CORECLR_LAUNCHER_ASSEMBLY_PATH); #endif #undef __STR @@ -81,9 +49,22 @@ CoreRuntime::~CoreRuntime() Dispose(); } -int CoreRuntime::Initialize() +int CoreRuntime::Initialize(bool standalone) { + if (standalone) + { + const char *_deviceapi_directory = getenv("DeviceAPIDirectory"); + const char *_runtime_directory = getenv("RuntimeDirectory"); + const char *_launcher_assembly = getenv("LauncherAssembly"); + if (_deviceapi_directory != nullptr) + DeviceAPIDirectory = _deviceapi_directory; + if (_runtime_directory != nullptr) + RuntimeDirectory = _runtime_directory; + if (_launcher_assembly != nullptr) + LauncherAssembly = _launcher_assembly; + } + if (DeviceAPIDirectory.empty()) { _ERR("Empty Device API Directory"); @@ -190,7 +171,7 @@ int CoreRuntime::RunManagedLauncher() "UseLatestBehaviorWhenTFMNotSpecified" }; -// _DBG("trusted platform assemblies : %s", propertyValues[0]); + _DBG("trusted platform assemblies : %s", propertyValues[0]); _DBG("app_path : %s", propertyValues[1]); _DBG("app_ni_path : %s", propertyValues[2]); _DBG("native dll search path : %s", propertyValues[3]); @@ -224,40 +205,34 @@ int CoreRuntime::RunManagedLauncher() _DBG("Initialize core clr success"); - void *launchFunctionDelegate; + void *preparedFunctionDelegate; st = CreateDelegate(hostHandle, domainId, - "Tizen.Runtime", - "Tizen.Runtime.AssemblyManager", - "Launch", &launchFunctionDelegate); + "Tizen.Runtime.Coreclr", + "Tizen.Runtime.Coreclr.AssemblyManager", + "Prepared", &preparedFunctionDelegate); if (st < 0) { - _ERR("Create delegate for Launch managed function is fail! (0x%08x)", st); + _ERR("Create delegate for Launch prepared function is fail (0x%08x)", st); return 1; } - LaunchFunction = reinterpret_cast(launchFunctionDelegate); + PreparedFunction = reinterpret_cast(preparedFunctionDelegate); - if (isLaunched) + if(PreparedFunction != nullptr) { - bool success = LaunchFunction(LaunchParam.path.c_str(), - LaunchParam.argc, LaunchParam.argv); - if (!success) - { - _ERR("Failed to Launching"); - } + PreparedFunction(); } - /* - unsigned int exitCode; - const char* argv[] = {LauncherAssembly.c_str()}; - st = ExecuteAssembly(hostHandle, domainId, - 1, argv, LauncherAssembly.c_str(), &exitCode); - _DBG("after execute coreclr"); + void *launchFunctionDelegate; + st = CreateDelegate(hostHandle, domainId, + "Tizen.Runtime.Coreclr", + "Tizen.Runtime.Coreclr.AssemblyManager", + "Launch", &launchFunctionDelegate); if (st < 0) { - _ERR("execute core clr fail! (0x%08x / %d)", st, exitCode); + _ERR("Create delegate for Launch managed function is fail! (0x%08x)", st); return 1; } - */ + LaunchFunction = reinterpret_cast(launchFunctionDelegate); return 0; } @@ -282,67 +257,32 @@ void CoreRuntime::Dispose() _DBG("Dotnet runtime disposed"); } -int CoreRuntime::Launch(const char* path, int argc, char* argv[]) +int CoreRuntime::Launch(const char* root, const char* path, int argc, char* argv[]) { - if (LaunchFunction != nullptr) + if (path == nullptr) { - LaunchFunction(path, argc, argv); + _ERR("executable path is null"); + return 1; } - else + + if (FileNotExist(path)) { - LaunchParam.path = path; - LaunchParam.argc = argc; - LaunchParam.argv = argv; + _ERR("File not exist : %s", path); + return 1; } - isLaunched = true; - return 0; -} - -} // namespace dotnetcore -} // namespace runtime -} // namespace tizen - -static std::string StandaloneOption("--standalone"); - -#include "base64.h" - -int main(int argc, char *argv[]) -{ - int i; - bool standalone = false; - const char* standalonePath = nullptr; - - for (i=1; i +#include -#include +#include #include #include #include -#include + +#include + namespace tizen { namespace runtime { struct FdHandler { - pollfd *info; - std::function receiver; + Ecore_Fd_Handler *handler; + loader_receiver_cb receiver; }; class LaunchpadAdapterImpl : public LaunchpadAdapter { public: LaunchpadAdapterImpl() : isLaunched(false) { } - void LoaderMain(LauncherInterface* launcher, int argc, char* argv[]) override; - void WaitUtilLaunched() override; + void LoaderMain(int argc, char* argv[]) override; - protected: - void OnCreate() override; - void OnLaunch() override; - void OnTerminate() override; + std::map Handlers; private: + AppInfo appinfo; loader_lifecycle_callback_s callbacks; loader_adapter_s adapter; LauncherInterface* launcher; bool isLaunched; std::string launchPath; - - bool Waiting; - std::vector FdList; - std::map Handlers; - - std::thread pollingThread; }; LaunchpadAdapterImpl LaunchpadImpl; LaunchpadAdapter& Launchpad = LaunchpadImpl; -void LaunchpadAdapterImpl::LoaderMain(LauncherInterface* launcher, int argc, char* argv[]) -{ - this->launcher = launcher; #define WITH_SELF(data) \ LaunchpadAdapterImpl* self = static_cast(data); \ if (self == nullptr) \ @@ -58,12 +49,75 @@ void LaunchpadAdapterImpl::LoaderMain(LauncherInterface* launcher, int argc, cha _ERR("No LaunchpadImplData"); \ } else +static Eina_Bool Fd_Handler(void *data, Ecore_Fd_Handler* handler) +{ + WITH_SELF(data) + { + int fd = ecore_main_fd_handler_fd_get(handler); + if (fd == -1) + { + _ERR("Failed to get the Ecore FD"); + exit(-1); + } + + if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) + { + if (self->Handlers.find(fd) != self->Handlers.end()) + { + self->Handlers[fd].receiver(fd); + } + } + else if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR)) + { + _ERR("Ecore FD Handler Have Error"); + close(fd); + exit(-1); + } + } + + return ECORE_CALLBACK_CANCEL; +} + +static void Fd_Add(void *data, int fd, loader_receiver_cb receiver) +{ + Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd, + static_cast(ECORE_FD_READ | ECORE_FD_ERROR), + Fd_Handler, data, nullptr, nullptr); + if (handler == nullptr) + { + _ERR("Failed to add a FD handler to ecore main loop"); + close(fd); + exit(-1); + } + WITH_SELF(data) + { + self->Handlers[fd] = {handler, receiver}; + } +} + +static void Fd_Remove(void *data, int fd) +{ + WITH_SELF(data) + { + if (self->Handlers.find(fd) != self->Handlers.end()) + { + Ecore_Fd_Handler* handler = self->Handlers[fd].handler; + ecore_main_fd_handler_del(handler); + self->Handlers.erase(fd); + } + } +} + +void LaunchpadAdapterImpl::LoaderMain(int argc, char* argv[]) +{ callbacks.create = [](bundle *extra, int type, void *user_data) { + ecore_init(); WITH_SELF(user_data) { - self->OnCreate(); + if (self->OnCreate != nullptr) + self->OnCreate(); } }; callbacks.launch = [](int argc, char** argv, const char* app_path, @@ -72,8 +126,13 @@ void LaunchpadAdapterImpl::LoaderMain(LauncherInterface* launcher, int argc, cha { WITH_SELF(user_data) { - self->OnLaunch(); - self->launchPath = std::string(app_path); + self->appinfo.root = std::string(aul_get_app_root_path()); + self->appinfo.path = app_path; + self->appinfo.id = appid; + self->appinfo.pkg = pkgid; + self->appinfo.type = pkg_type; + if (self->OnLaunch != nullptr) + self->OnLaunch(self->appinfo, argc, argv); } return 0; @@ -83,108 +142,30 @@ void LaunchpadAdapterImpl::LoaderMain(LauncherInterface* launcher, int argc, cha _DBG("Terminate!!"); WITH_SELF(user_data) { - self->OnTerminate(); - //self->launcher->Launch(self->launchPath.c_str(), argc, argv); + if (self->OnTerminate != nullptr) + self->OnTerminate(self->appinfo, argc, argv); } return 0; }; adapter.loop_begin = [](void *data) { - _DBG("start polling..."); - WITH_SELF(data) - { - self->Waiting = true; - while(self->Waiting) - { - if (poll(self->FdList.data(), self->FdList.size(), -1) < 0) - continue; - - _DBG("-----------------------------------------------------------4"); - for (auto &p : self->FdList) - { - if ( (p.revents | POLLIN) != 0) - self->Handlers[p.fd].receiver(p.fd); - } - _DBG("-----------------------------------------------------------5"); - } - } - _DBG("end polling..."); + ecore_main_loop_begin(); }; adapter.loop_quit = [](void *data) { - WITH_SELF(data) - { - self->Waiting = false; - } - }; - - adapter.add_fd = [](void *data, int fd, loader_receiver_cb receiver) - { - WITH_SELF(data) - { - pollfd info; - FdHandler handler; - - info.fd = fd; - info.events = POLLIN; - info.revents = 0; - - self->FdList.push_back(info); - handler.info = &((self->FdList).back()); - handler.receiver = receiver; - - self->Handlers[fd] = handler; - } - }; - - adapter.remove_fd = [](void *user_data, int fd) - { - WITH_SELF(user_data) - { - pollfd *info = self->Handlers[fd].info; - self->FdList.erase(self->FdList.begin() - (info - &(self->FdList.front()))); - self->Handlers.erase(fd); - } + ecore_main_loop_quit(); }; + adapter.add_fd = Fd_Add; + adapter.remove_fd = Fd_Remove; - pollingThread = std::thread([this, argc, argv]() - { - _DBG("launchpad_loader_main is start"); - int r = launchpad_loader_main(argc, argv, &(this->callbacks), &(this->adapter), this); - _DBG("launchpad_loader_main is finished with [%d]", r); - }); - //pollingThread.detach(); -} - -void LaunchpadAdapterImpl::WaitUtilLaunched() -{ - try - { - if (pollingThread.joinable()) - { - pollingThread.join(); - } - } - catch (const std::exception& ex) - { - _ERR("Exception : %s", ex.what()); - } -} - -void LaunchpadAdapterImpl::OnCreate() -{ -} - -void LaunchpadAdapterImpl::OnLaunch() -{ -} - -void LaunchpadAdapterImpl::OnTerminate() -{ + _DBG("launchpad_loader_main is start"); + int r = launchpad_loader_main(argc, argv, &(this->callbacks), &(this->adapter), this); + _DBG("launchpad_loader_main is finished with [%d]", r); } +#undef WITH_SELF } // namespace runtime } // namespace tizen diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc new file mode 100644 index 0000000..97ff67c --- /dev/null +++ b/NativeLauncher/src/main.cc @@ -0,0 +1,108 @@ +#include "dotnet/dotnet_launcher.h" +#include "mono/mono_launcher.h" +#include "utils.h" +#include "log.h" + +#include + +#include +#include + +static std::string StandaloneOption("--standalone"); + +int main(int argc, char *argv[]) +{ + int i; + bool standalone = false; + const char* standalonePath = nullptr; + + for (i=1; i runtime; + + bool useMono = !FileNotExist("/etc/.use_mono"); + + if (!useMono) + { + using tizen::runtime::dotnetcore::CoreRuntime; + std::unique_ptr coreRuntime(new CoreRuntime()); + runtime = std::move(coreRuntime); + } + else + { + using tizen::runtime::mono::MonoRuntime; + std::unique_ptr monoRuntime(new MonoRuntime()); + runtime = std::move(monoRuntime); + } + + if (standalone) + { + std::string base = Basename(standalonePath); + if (runtime->Initialize(true) != 0) + { + _ERR("Failed to initialize"); + return 1; + } + if (runtime->RunManagedLauncher() != 0) + { + _ERR("Failed to run managed launcher"); + return 1; + } + if (!runtime->Launch(base.c_str(), standalonePath, argc, argv)) + { + _ERR("Failed to launch"); + return 1; + } + } + else + { + Launchpad.OnCreate = [&runtime] + { + auto idle_task = [](void *data) -> Eina_Bool + { + LauncherInterface* runtime = static_cast(data); + if (runtime->RunManagedLauncher() != 0) + { + _ERR("Failed to run managed launcher"); + } + return ECORE_CALLBACK_CANCEL; + }; + if (runtime->Initialize(false) != 0) + { + _ERR("Failed to initialized"); + return 1; + } + ecore_idler_add(idle_task, runtime.get()); + }; + + Launchpad.OnTerminate = [&runtime](const AppInfo& info, int argc, char** argv) + { + _DBG("terminated with app path : %s", info.path.c_str()); + _DBG("appid : %s", info.id.c_str()); + _DBG("pkg : %s", info.pkg.c_str()); + _DBG("type : %s", info.type.c_str()); + + if (!runtime->Launch(info.root.c_str(), info.path.c_str(), argc, argv)) + { + _ERR("Failed to launch"); + } + }; + Launchpad.LoaderMain(argc, argv); + } + + return 0; +} diff --git a/NativeLauncher/src/mono/mono_launcher.cc b/NativeLauncher/src/mono/mono_launcher.cc new file mode 100644 index 0000000..fff1104 --- /dev/null +++ b/NativeLauncher/src/mono/mono_launcher.cc @@ -0,0 +1,213 @@ + +#include "mono_launcher.h" +#include "utils.h" +#include "log.h" + +#include +#include + +namespace tizen { +namespace runtime { +namespace mono { + +static const char* LIBMONO = "/usr/lib/libmono-2.0.so.1"; + +MonoRuntime::MonoRuntime() : + monolib(nullptr) +{ + +#define __XSTR(x) #x +#define __STR(x) __XSTR(x) + +#ifdef MONO_LAUNCHER_ASSEMBLY_PATH + launcherAssemblyPath = __STR(MONO_LAUNCHER_ASSEMBLY_PATH); +#endif + +#ifdef DEVICE_API_DIR + deviceAPIDirectory = __STR(DEVICE_API_DIR); +#endif +#ifdef RUNTIME_DIR + runtimeDirectory = __STR(RUNTIME_DIR); +#endif + +#undef __STR +#undef __XSTR +} + +MonoRuntime::~MonoRuntime() +{ + Dispose(); +} + +int MonoRuntime::Initialize(bool standalone) +{ + if (standalone) + { + const char *_deviceapi_directory = getenv("DeviceAPIDirectory"); + const char *_runtime_directory = getenv("RuntimeDirectory"); + const char *_launcher_assembly = getenv("LauncherAssembly"); + if (_deviceapi_directory != nullptr) + deviceAPIDirectory = _deviceapi_directory; + if (_runtime_directory != nullptr) + runtimeDirectory = _runtime_directory; + if (_launcher_assembly != nullptr) + launcherAssemblyPath = _launcher_assembly; + } + + if (FileNotExist(LIBMONO)) + { + _DBG("mono is not exist in %s", LIBMONO); + return 1; + } + + monolib = dlopen(LIBMONO, RTLD_LAZY); +#define MONOLIB_RETURN_IF_NOSYM(type, variable, name) \ + do { \ + variable = (type)dlsym(monolib, name); \ + if (variable == nullptr) { \ + _ERR(name " is not found in libmono"); \ + return 1; \ + }} while(0) + + MONOLIB_RETURN_IF_NOSYM(mono_set_dirs_ptr, SetDirs, "mono_set_dirs"); + MONOLIB_RETURN_IF_NOSYM(mono_set_assemblies_path_ptr, SetAssembliesPath, "mono_set_assemblies_path"); + MONOLIB_RETURN_IF_NOSYM(mono_jit_init_ptr, JitInit, "mono_jit_init"); + MONOLIB_RETURN_IF_NOSYM(mono_domain_assembly_open_ptr, DomainAssemblyOpen, "mono_domain_assembly_open"); + MONOLIB_RETURN_IF_NOSYM(mono_assembly_get_image_ptr, AssemblyGetImage, "mono_assembly_get_image"); + MONOLIB_RETURN_IF_NOSYM(mono_class_from_name_ptr, ClassFromName, "mono_class_from_name"); + MONOLIB_RETURN_IF_NOSYM(mono_runtime_invoke_ptr, RuntimeInvoke, "mono_runtime_invoke"); + MONOLIB_RETURN_IF_NOSYM(mono_class_get_method_from_name_ptr, ClassGetMethodFromName, "mono_class_get_method_from_name"); + MONOLIB_RETURN_IF_NOSYM(mono_object_to_string_ptr, ObjectToString, "mono_object_to_string"); + MONOLIB_RETURN_IF_NOSYM(mono_string_to_utf8_ptr, StringToUtf8, "mono_string_to_utf8"); + MONOLIB_RETURN_IF_NOSYM(mono_string_new_ptr, NewString, "mono_string_new"); + MONOLIB_RETURN_IF_NOSYM(mono_get_string_class_ptr, GetStringClass, "mono_get_string_class"); + MONOLIB_RETURN_IF_NOSYM(mono_array_new_ptr, ArrayNew, "mono_array_new"); + MONOLIB_RETURN_IF_NOSYM(mono_array_addr_with_size_ptr, ArrayAddrWithSize, "mono_array_addr_with_size"); + +#undef MONOLIB_RETURN_IF_NOSYM + + _DBG("libmono dlopen and dlsym success"); + + return 0; +} + +void MonoRuntime::Dispose() +{ + if (monolib != nullptr && dlclose(monolib) != 0) + { + _ERR("libmono close failed"); + } + monolib = nullptr; +} + +int MonoRuntime::RunManagedLauncher() +{ + if (FileNotExist(launcherAssemblyPath.c_str())) + { + _ERR("Launcher Assembly is not exist in %s", launcherAssemblyPath.c_str()); + return 1; + } + +// _DBG("mono_set_dirs(\"%s\", nullptr);", runtimeDirectory.c_str()); +// _DBG("mono_set_assemblies_path(\"%s\");", deviceAPIDirectory.c_str()); + +// SetDirs(runtimeDirectory.c_str(), nullptr); +/* + std::string assembliesPath = runtimeDirectory+":"+deviceAPIDirectory; + _DBG("assembliesPath : %s", assembliesPath.c_str()); + SetAssembliesPath(assembliesPath.c_str()); + */ + SetAssembliesPath(deviceAPIDirectory.c_str()); + + domain = JitInit("tizen_mono_domain"); + if (domain == nullptr) + { + _ERR("Failed to init mono jit"); + return 1; + } + + launcherAssembly = DomainAssemblyOpen(domain, launcherAssemblyPath.c_str()); + if (launcherAssembly == nullptr) + { + _ERR("Failed to Load Launcher Assembly"); + return 1; + } + + monoImage = AssemblyGetImage(launcherAssembly); + if (monoImage == nullptr) + { + _ERR("Failed to get image from launcher assembly"); + return 1; + } + + assemblyManagerClass = ClassFromName(monoImage, "Tizen.Runtime.Mono", "AssemblyManager"); + if (assemblyManagerClass == nullptr) + { + _ERR("Failed to get AssemblyManager class in namespace Tizen.Runtime.Mono from launcher image"); + return 1; + } + + prepareLaunch = ClassGetMethodFromName(assemblyManagerClass, "Prepared", 0); + if (prepareLaunch == nullptr) + { + _ERR("Failed to get Prepared() method from Tizen.Runtime.Mono.AssemblyManager"); + return 1; + } + MonoObject* exception = nullptr; + RuntimeInvoke(prepareLaunch, nullptr, nullptr, &exception); + if (exception != nullptr) + { + MonoString * exceptionMsg = ObjectToString(exception, nullptr); + char* cstringMsg = StringToUtf8(exceptionMsg); + _ERR("Failed to invoke method in runtime"); + _ERR("%s", cstringMsg); + free(cstringMsg); + return 1; + } + + launch = ClassGetMethodFromName(assemblyManagerClass, "Launch", 4); + + return 0; +} + +#define ArrayAddr(array,type,index) ((type*)(void*) ArrayAddrWithSize (array, sizeof (type), index)) +#define ArraySet(array,type,index,value) \ + do { \ + type *__p = (type *) ArrayAddr ((array), type, (index)); \ + *__p = (value); \ + } while (0) + +int MonoRuntime::Launch(const char* root, const char* path, int argc, char* argv[]) +{ + MonoString *rootMonoString = NewString(domain, root); + MonoString *pathMonoString = NewString(domain, path); + MonoArray *argvMonoArray = ArrayNew(domain, GetStringClass(), argc); + for (int i=0; i Debug AnyCPU - exe - Tizen.Runtime + library + Tizen.Runtime.Coreclr @@ -34,11 +34,9 @@ - - + + - - diff --git a/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs similarity index 98% rename from Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs rename to Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs index 4b4a30b..2e21c7b 100644 --- a/Tizen.Runtime/Tizen.Runtime/AssemblyLoader.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs @@ -4,7 +4,7 @@ using System.Reflection; using System.Runtime.Loader; using System.Collections.Generic; -namespace Tizen.Runtime +namespace Tizen.Runtime.Coreclr { public class AssemblyLoader : AssemblyLoadContext { diff --git a/Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs similarity index 55% rename from Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs rename to Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index 6a13648..ec342d5 100644 --- a/Tizen.Runtime/Tizen.Runtime/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -5,28 +5,43 @@ using System.Runtime.Loader; using System.Linq; using System.Runtime.InteropServices; -namespace Tizen.Runtime +namespace Tizen.Runtime.Coreclr { public static class AssemblyManager { public static bool Launch( + [In] string rootPath, [In] string path, [In] int argc, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)] [In] string[] argv) { - Console.WriteLine($"path : {path}"); - Console.WriteLine($"argc : {argc}"); - for (int i=0; i + + + + Debug + AnyCPU + library + Tizen.Runtime.Mono + v4.5 + + + + true + full + bin/ + DEBUG;TRACE + + + + pdbonly + true + bin/ + TRACE + + + + + + $(DefineConstants);CLOG + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_Parameter1>PreloadPath=$(PreloadPath) + + + + + + + + + diff --git a/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs new file mode 100644 index 0000000..ec65ca6 --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs @@ -0,0 +1,153 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Reflection; +using System.Runtime.InteropServices; +using Tizen.Runtime; + +namespace Tizen.Runtime.Mono +{ + public static class AssemblyManager + { + + private static SortedSet ResolveDirectories = new SortedSet(); + private static SortedSet ResolveFiles = new SortedSet(); + + 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)) + { + ResolveDirectories.Add(bindir.FullName); + } + if (Directory.Exists(libdir.FullName)) + { + ResolveDirectories.Add(libdir.FullName); + } + ResolveFiles.Add(path); + Execute(path, argv); + } + catch(Exception e) + { + ALog.Debug("Exception in Launch()"); + PrintException(e); + return false; + } + + return true; + } + + static readonly string[] assemblyExtensions = {".dll", ".exe"}; + + public static Assembly AssemblyResolverHandler(object sender, ResolveEventArgs args) + { + // find dll name + ext in paths for resolving + foreach (string path in ResolveDirectories) + { + foreach (string ext in assemblyExtensions) + { + string assemblyPath = Path.Combine(path, new AssemblyName(args.Name).Name + ext); + if (File.Exists(assemblyPath)) + { + Assembly assembly = Assembly.LoadFrom(assemblyPath); + return assembly; + } + } + } + + return null; + } + + public static void Prepared() + { + try + { + string preloadPath = ""; + ICustomAttributeProvider assembly = typeof(AssemblyManager).GetTypeInfo().Assembly; + var attributes = assembly.GetCustomAttributes(typeof(DefaultConfigAttribute), false); + foreach (DefaultConfigAttribute dca in attributes) + { + ALog.Debug($"{dca.Key} = {dca.Value}"); + if (dca.Key == "PreloadPath") + { + preloadPath = dca.Value; + } + } + + if (!Initialize(preloadPath)) + { + ALog.Debug($"Failed to Initialized with {preloadPath}"); + } + + AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolverHandler; + } + catch(Exception e) + { + ALog.Debug("Exception at Preparing"); + PrintException(e); + } + } + + private static void PrintException(Exception exception) + { + while (exception != null) + { + ALog.Debug(exception.ToString()); + exception = exception.InnerException; + } + } + + public static bool Initialize(string preloadDirectory) + { + try + { + if (!string.IsNullOrEmpty(preloadDirectory)) + { + Console.WriteLine($"[{preloadDirectory}]"); + DirectoryInfo d = new DirectoryInfo(preloadDirectory); + if (Directory.Exists(d.FullName)) + { + ResolveDirectories.Add(d.FullName); + } + } + } + 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 = Assembly.LoadFile(f.FullName); + if (asm.EntryPoint == null) throw new ArgumentException($"{f.FullName} did not have EntryPoint"); + asm.EntryPoint.Invoke(null, new object[]{argv}); + } + } + catch (Exception e) + { + ALog.Debug("Exception on Execute"); + PrintException(e); + } + } + + } +} diff --git a/Tizen.Runtime/Tizen.Runtime/Ini.cs b/Tizen.Runtime/Tizen.Runtime/Ini.cs deleted file mode 100644 index d5c2544..0000000 --- a/Tizen.Runtime/Tizen.Runtime/Ini.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; - -namespace Tizen.Runtime -{ - internal class Ini - { - public string GlobalName = "___GLOBAL"; - public Ini(Uri path) - { - if (path.Scheme != "file") - { - throw new NotSupportedException("Only File Uri is supported now"); - } - string absPath = path.AbsolutePath; - Initialize(); - Contents = File.ReadAllText(absPath); - } - - public Ini(string contents) - { - Initialize(); - Contents = contents; - } - - public string Contents - { - get { return contents; } - - set - { - contents = value; - ReadContents(contents); - } - } - - public Dictionary this[string name] - { - get - { - if (groups.ContainsKey(name)) - return groups[name]; - return null; - } - } - - public override string ToString() - { - string str = ""; - - if (groups.ContainsKey(GlobalName)) - { - foreach (var kv in groups[GlobalName]) - { - str += $"{kv.Key} = {kv.Value}" + Environment.NewLine; - } - } - - foreach (var gkv in groups) - { - if (gkv.Key == GlobalName) continue; - str += $"[{gkv.Key}]" + Environment.NewLine; - foreach (var kv in gkv.Value) - { - str += $"{kv.Key} = {kv.Value}" + Environment.NewLine; - } - } - - return str; - } - - public Dictionary Global - { - get - { - return groups[GlobalName]; - } - } - - private void Initialize() - { - groups = new Dictionary >(); - groups[GlobalName] = new Dictionary(); - } - - private string Uncommont(string str) - { - int comment_start = str.IndexOf('#'); - return str.Substring(0, comment_start); - } - - private bool GetHeader(string str, ref string groupName) - { - if (str.Length < 2 || str[0] != '[' || str[str.Length-1] != ']') return false; - string expected = str.Substring(1, str.Length-2); - groupName = expected.Trim(); - return true; - } - - private void GetKeyValueFromString(string str, out string key, out string value) - { - int eq_pos = str.IndexOf('='); - if (eq_pos == -1) - { - key = str.Trim(); - value = ""; - } - else - { - key = str.Substring(0, eq_pos).Trim(); - value = str.Substring(eq_pos+1).Trim(); - } - } - - private void ReadContents(string contents) - { - string key, value; - string groupName = GlobalName; - string[] lines = contents.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); - - foreach (string line in lines) - { - if (string.IsNullOrWhiteSpace(line)) continue; - if (GetHeader(line, ref groupName)) - { - groups[groupName] = new Dictionary(); - continue; - } - GetKeyValueFromString(line, out key, out value); - groups[groupName][key] = value; - } - } - - private Dictionary > groups; - private string contents; - } -} diff --git a/Tizen.Runtime/Tizen.Runtime/Interop.cs b/Tizen.Runtime/Tizen.Runtime/Interop.cs deleted file mode 100644 index 52ceeac..0000000 --- a/Tizen.Runtime/Tizen.Runtime/Interop.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -internal static class Interop -{ - public const string Launcher = "dotnet-launcher"; - - internal delegate int PreparedCallback(IntPtr userData); - internal delegate int RequestedCallback(IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate int ExecutedCallback( - [In] string path, - [In] string app_root, - [In] int argc, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)] - [In] string[] argv, - [In] IntPtr userData); - - [DllImport(Launcher)] - internal static extern void register_launching_callback( - [MarshalAs(UnmanagedType.FunctionPtr)] PreparedCallback prepared, - [MarshalAs(UnmanagedType.FunctionPtr)] RequestedCallback requested, - [MarshalAs(UnmanagedType.FunctionPtr)] ExecutedCallback executed, IntPtr userData); - - [DllImport(Launcher)] - internal static extern void wait_for_launching(int argc, string[] argv); -} diff --git a/Tizen.Runtime/Tizen.Runtime/Log.cs b/Tizen.Runtime/Tizen.Runtime/Log.cs index 064a5f3..b27a329 100644 --- a/Tizen.Runtime/Tizen.Runtime/Log.cs +++ b/Tizen.Runtime/Tizen.Runtime/Log.cs @@ -1,7 +1,7 @@ using System; -#if !CLOG -using Tizen; -#endif +using System.IO; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; namespace Tizen.Runtime { @@ -35,21 +35,54 @@ namespace Tizen.Runtime #endif internal static class ALog { - static string TAG = "Tizen.Runtime"; + const string Library = "libdlog.so.0"; + const string TAG = "Tizen.Runtime"; + + public static void Debug(string message, + [CallerFilePath] string file = "", + [CallerMemberName] string func = "", + [CallerLineNumber] int line = 0) + { + Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line); + } - public static void Debug(string message) + public static void Info(string message, + [CallerFilePath] string file = "", + [CallerMemberName] string func = "", + [CallerLineNumber] int line = 0) { - Log.Debug(TAG, message); + Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line); } - public static void Info(string message) + public static void Error(string message, + [CallerFilePath] string file = "", + [CallerMemberName] string func = "", + [CallerLineNumber] int line = 0) { - Log.Info(TAG, message); + Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line); } - public static void Error(string message) + internal enum LogPriority { - Log.Error(TAG, message); + DLOG_UNKNOWN = 0, + DLOG_DEFAULT, + DLOG_VERBOSE, + DLOG_DEBUG, + DLOG_INFO, + DLOG_WARN, + DLOG_ERROR, + DLOG_FATAL, + DLOG_SILENT, + DLOG_PRIO_MAX, } + + private static void Print(LogPriority priority, string tag, string message, string file, string func, int line) + { + FileInfo finfo = new FileInfo(file); + Print(priority, tag, "%s: %s(%d) > %s", finfo.Name, func, line, message); + } + + [DllImportAttribute(Library, EntryPoint = "dlog_print")] + internal static extern int Print(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg); } } diff --git a/Tizen.Runtime/Tizen.Runtime/test.cs b/Tizen.Runtime/Tizen.Runtime/test.cs deleted file mode 100644 index 1c65dbe..0000000 --- a/Tizen.Runtime/Tizen.Runtime/test.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Tizen.Runtime; - -public class Program -{ - public static void Main(string[] args) - { - if (args.Length < 2) - { - ALog.Debug("Cancel.."); - return; - } - string preload = Environment.GetEnvironmentVariable("PRELOAD_DLLS"); - string searchable = String.Join(":", args, 1, args.Length - 1); - - if (AssemblyManager.Initialize(searchable, preload)) - { - ALog.Debug("After Initialized..."); - AssemblyManager.Execute(args[0]); - } - } -} diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index c82b091..ee96df0 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -56,7 +56,8 @@ cmake \ -DCMAKE_BUILD_TYPE=%{_buildmode} \ -DDEVICE_API_DIR=%{_device_api_dir} \ -DRUNTIME_DIR=%{_runtime_dir} \ - -DLAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.exe \ + -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Coreclr.dll \ + -DMONO_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Mono.dll \ -DVERSION=%{version} \ NativeLauncher @@ -66,15 +67,23 @@ xbuild \ /p:Configuration=%{_buildmode} \ /p:PreloadPath=%{_preload_dir} \ /p:TizenDeviceAPIPath=%{_device_api_dir} \ - Tizen.Runtime/Tizen.Runtime.csproj + Tizen.Runtime/Tizen.Runtime.Coreclr.csproj + +xbuild \ + /p:Configuration=%{_buildmode} \ + /p:PreloadPath=%{_preload_dir} \ + /p:TizenDeviceAPIPath=%{_device_api_dir} \ + Tizen.Runtime/Tizen.Runtime.Mono.csproj %install rm -rf %{buildroot} %make_install -install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.exe %{buildroot}%{_bindir} +install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Coreclr.dll %{buildroot}%{_bindir} +install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir} %files %manifest dotnet-launcher.manifest %{_loaderdir}/dotnet.loader %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.exe +%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Coreclr.dll +%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Mono.dll -- 2.7.4 From a74953c665b4d5c177ebfaf014d2ba61f7e7906a Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Mon, 10 Oct 2016 19:03:12 +0900 Subject: [PATCH 02/16] Now options will be pass to managed launcher Commanline options will be pass to managed launcher except --standalone and assembly path. Change-Id: I2e853c23553152fb9291b4d586b50c133a5781ee --- NativeLauncher/src/main.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc index 97ff67c..41c0362 100644 --- a/NativeLauncher/src/main.cc +++ b/NativeLauncher/src/main.cc @@ -3,6 +3,8 @@ #include "utils.h" #include "log.h" +#include +#include #include #include @@ -16,16 +18,25 @@ int main(int argc, char *argv[]) bool standalone = false; const char* standalonePath = nullptr; + std::vector vargs; + for (i=1; i argc-1) + { + fprintf(stderr, "Assembly path must be after \"--standalone\" option\n"); + return 1; + } + i++; + standalonePath = argv[i]; } else { - if (standalonePath == nullptr) - standalonePath = argv[i]; + vargs.push_back(argv[i]); } } @@ -62,7 +73,10 @@ int main(int argc, char *argv[]) _ERR("Failed to run managed launcher"); return 1; } - if (!runtime->Launch(base.c_str(), standalonePath, argc, argv)) + + int args_len = vargs.size(); + char** args = &vargs[0]; + if (!runtime->Launch(base.c_str(), standalonePath, args_len, args)) { _ERR("Failed to launch"); return 1; -- 2.7.4 From c36bac706fa4427eaaed2182150f599471d44729 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Tue, 11 Oct 2016 16:27:34 +0900 Subject: [PATCH 03/16] Add "--version" option for dotnet-launcher Change-Id: I74e371732fd617e753711bcf9f1e9d9ba4c7e6a9 --- NativeLauncher/CMakeLists.txt | 4 ++++ NativeLauncher/src/dotnet/dotnet_launcher.cc | 2 +- NativeLauncher/src/main.cc | 17 ++++++++++++++++- packaging/dotnet-launcher.spec | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 00657be..37db3f2 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -34,6 +34,10 @@ IF(DEFINED RUNTIME_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DRUNTIME_DIR=${RUNTIME_DIR}") ENDIF(DEFINED RUNTIME_DIR) +IF(DEFINED VERSION) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DVERSION=${VERSION}") +ENDIF(DEFINED VERSION) + 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} -fvisibility=hidden") diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.cc b/NativeLauncher/src/dotnet/dotnet_launcher.cc index 62738a3..d9879ba 100644 --- a/NativeLauncher/src/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/src/dotnet/dotnet_launcher.cc @@ -171,7 +171,7 @@ int CoreRuntime::RunManagedLauncher() "UseLatestBehaviorWhenTFMNotSpecified" }; - _DBG("trusted platform assemblies : %s", propertyValues[0]); + //_DBG("trusted platform assemblies : %s", propertyValues[0]); _DBG("app_path : %s", propertyValues[1]); _DBG("app_ni_path : %s", propertyValues[2]); _DBG("native dll search path : %s", propertyValues[3]); diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc index 41c0362..c9790ce 100644 --- a/NativeLauncher/src/main.cc +++ b/NativeLauncher/src/main.cc @@ -10,6 +10,16 @@ #include #include +#define __XSTR(x) #x +#define __STR(x) __XSTR(x) + +#ifndef VERSION +#define LAUNCHER_VERSION_STR "-Unknown-" +#else +#define LAUNCHER_VERSION_STR __STR(VERSION) +#endif + +static std::string VersionOption("--version"); static std::string StandaloneOption("--standalone"); int main(int argc, char *argv[]) @@ -22,7 +32,12 @@ int main(int argc, char *argv[]) for (i=1; i Date: Mon, 17 Oct 2016 18:52:23 +0900 Subject: [PATCH 04/16] Fix App Root on standalone and support direct exec Set application root with aul_get_app_root_path() if AUL_APPID is exist. Add dotnet.launcher direct execute in launchpad. Change-Id: I4e45731c791449e3afa4e698b8bbb8ea3bede91f --- NativeLauncher/CMakeLists.txt | 1 + NativeLauncher/dotnet.launcher | 6 ++++++ NativeLauncher/src/main.cc | 24 ++++++++++++++++++++---- packaging/dotnet-launcher.spec | 3 ++- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 NativeLauncher/dotnet.launcher diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 37db3f2..9cd33a3 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -77,4 +77,5 @@ SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER} IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) + INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) ENDIF(NOT DEFINED NO_TIZEN) diff --git a/NativeLauncher/dotnet.launcher b/NativeLauncher/dotnet.launcher new file mode 100644 index 0000000..846e372 --- /dev/null +++ b/NativeLauncher/dotnet.launcher @@ -0,0 +1,6 @@ +[LAUNCHER] +NAME dotnet-launcher +EXE /usr/bin/dotnet-launcher +APP_TYPE dotnet +EXTRA_ARG --standalone + diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc index c9790ce..248de99 100644 --- a/NativeLauncher/src/main.cc +++ b/NativeLauncher/src/main.cc @@ -9,6 +9,7 @@ #include #include +#include #define __XSTR(x) #x #define __STR(x) __XSTR(x) @@ -67,17 +68,32 @@ int main(int argc, char *argv[]) using tizen::runtime::dotnetcore::CoreRuntime; std::unique_ptr coreRuntime(new CoreRuntime()); runtime = std::move(coreRuntime); + + _DBG("##### CoreCLR Launcher ######"); } else { using tizen::runtime::mono::MonoRuntime; std::unique_ptr monoRuntime(new MonoRuntime()); runtime = std::move(monoRuntime); + + _DBG("##### Mono Launcher ######"); } if (standalone) { - std::string base = Basename(standalonePath); + _DBG("##### Run it standalone #########"); + const char* appid = getenv("AUL_APPID"); + _DBG("AUL_APPID : %s", appid); + std::string approot; + if (appid != nullptr) + { + approot = std::string(aul_get_app_root_path()); + } + else + { + approot = Basename(standalonePath); + } if (runtime->Initialize(true) != 0) { _ERR("Failed to initialize"); @@ -91,10 +107,10 @@ int main(int argc, char *argv[]) int args_len = vargs.size(); char** args = &vargs[0]; - if (!runtime->Launch(base.c_str(), standalonePath, args_len, args)) + if (runtime->Launch(approot.c_str(), standalonePath, args_len, args)) { _ERR("Failed to launch"); - return 1; + return 0; } } else @@ -125,7 +141,7 @@ int main(int argc, char *argv[]) _DBG("pkg : %s", info.pkg.c_str()); _DBG("type : %s", info.type.c_str()); - if (!runtime->Launch(info.root.c_str(), info.path.c_str(), argc, argv)) + if (runtime->Launch(info.root.c_str(), info.path.c_str(), argc, argv)) { _ERR("Failed to launch"); } diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 9ff66ee..2891a2b 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -2,7 +2,7 @@ Name: dotnet-launcher Summary: Launchpad plugin for dotnet apps -Version: 1.0.0 +Version: 1.0.1 Release: 2 Group: Application Framework/Application State Management License: Apache License, Version 2.0 @@ -84,6 +84,7 @@ install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir %files %manifest dotnet-launcher.manifest %{_loaderdir}/dotnet.loader +%{_loaderdir}/dotnet.launcher %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Coreclr.dll %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Mono.dll -- 2.7.4 From 612bbc37fd9547ddd78e190ba2b0c51fb52ca1f3 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Mon, 17 Oct 2016 19:51:57 +0900 Subject: [PATCH 05/16] Fix missed 0 args on standalone Add argv[0] to args on standalone. Fix Console.WriteLine to Dlog debug print out. Change-Id: Iffc0eed1d0c7a9a538c12f9693b68e58011bea41 --- NativeLauncher/src/main.cc | 10 +++++++--- Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs | 2 +- Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc index 248de99..9f43bfc 100644 --- a/NativeLauncher/src/main.cc +++ b/NativeLauncher/src/main.cc @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) std::vector vargs; - for (i=1; i Date: Wed, 19 Oct 2016 09:13:37 +0900 Subject: [PATCH 06/16] Add README.md for simple explanation. Change-Id: Id90846de24756eb8ebc79117ee282431fb61a36a --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc2c991 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Launcher for .NET Application + +### Usage + +``` +dotnet-launcher [options...] [args...] +``` + +#### options + +* --version + print version and exit. + +* --standalone [assembly path] + Run assembly with the current user environment. + +---- + +### Anatomy + +``` ++----------------------------------------------------+ +| Tizen.Runtime.Mono.dll | Tizen.Runtime.Coreclr.dll | ++-----------+------------------------+---------------+ +| | libmono.so | | libcoreclr.so | +| +------------+ +---------------+ +| Mono Native Launcher | CoreClr Native Launcher | ++------------------------+---------------------------+ +| Dotnet launcher | ++----------------------------------------------------+ + +``` -- 2.7.4 From 0a0ecc4a37e4504cd8eb5c6b1681acb47086678e Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Thu, 20 Oct 2016 20:40:09 +0900 Subject: [PATCH 07/16] Now --standalone mode don't use managed launcher Launched assembly start on native directly on standalone mode. It does not use assembly launcher. Change-Id: I64536ed0bf48a7a9254f51189b53d219b8e4777b --- NativeLauncher/src/dotnet/dotnet_launcher.cc | 96 ++++++++++++++++------------ NativeLauncher/src/dotnet/dotnet_launcher.h | 1 + NativeLauncher/src/main.cc | 5 -- NativeLauncher/src/mono/mono_launcher.cc | 83 +++++++++++++++++------- NativeLauncher/src/mono/mono_launcher.h | 4 ++ 5 files changed, 118 insertions(+), 71 deletions(-) diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.cc b/NativeLauncher/src/dotnet/dotnet_launcher.cc index d9879ba..ce880a9 100644 --- a/NativeLauncher/src/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/src/dotnet/dotnet_launcher.cc @@ -127,31 +127,14 @@ int CoreRuntime::Initialize(bool standalone) return 0; } -int CoreRuntime::RunManagedLauncher() +bool CoreRuntime::InitializeCoreClr(const char* assembly_probe_paths, const char* pinvoke_probe_paths) { - void* hostHandle; - unsigned int domainId; - - if (FileNotExist(LauncherAssembly)) - { - _ERR("Launcher assembly is not exist in %s", LauncherAssembly.c_str()); - return 1; - } - - std::string launcherDir = Basename(LauncherAssembly); - std::vector searchDirectories = { - RuntimeDirectory, DeviceAPIDirectory, launcherDir + std::vector platformDirectories = { + RuntimeDirectory, DeviceAPIDirectory }; std::string trusted_assemblies; - AssembliesInDirectory(searchDirectories, trusted_assemblies); - std::string trusted_directories = JoinStrings(searchDirectories, ":"); - - _DBG("coreclr_dir : %s", RuntimeDirectory.c_str()); - _DBG("tpa_dirs : %s", trusted_directories.c_str()); - _DBG("native_so_search_dir : %s", trusted_directories.c_str()); - _DBG("launcher_assembly : %s", LauncherAssembly.c_str()); - _DBG("launcher_dir : %s", launcherDir.c_str()); + AssembliesInDirectory(platformDirectories, trusted_assemblies); const char *propertyKeys[] = { @@ -165,31 +148,16 @@ int CoreRuntime::RunManagedLauncher() const char *propertyValues[] = { trusted_assemblies.c_str(), - launcherDir.c_str(), - launcherDir.c_str(), - trusted_directories.c_str(), + assembly_probe_paths, + assembly_probe_paths, + pinvoke_probe_paths, "UseLatestBehaviorWhenTFMNotSpecified" }; - - //_DBG("trusted platform assemblies : %s", propertyValues[0]); - _DBG("app_path : %s", propertyValues[1]); - _DBG("app_ni_path : %s", propertyValues[2]); - _DBG("native dll search path : %s", propertyValues[3]); - _DBG("app domain compat switch : %s", propertyValues[4]); - - _DBG("before InitializeClr"); - _DBG("this addr : %x", this); - _DBG("coreclr_initialize : %x", InitializeClr); std::string selfPath = ReadSelfPath(); - _DBG("self path : %s", selfPath.c_str()); - - _DBG("libcoreclr addr : %x", coreclrLib); - int st = InitializeClr( selfPath.c_str(), - //LauncherAssembly.c_str(), "dotnet-launcher", sizeof(propertyKeys) / sizeof(propertyKeys[0]), propertyKeys, @@ -200,13 +168,41 @@ int CoreRuntime::RunManagedLauncher() if (st < 0) { _ERR("initialize core clr fail! (0x%08x)", st); - return 1; + return false; } _DBG("Initialize core clr success"); + return true; +} + +int CoreRuntime::RunManagedLauncher() +{ + if (FileNotExist(LauncherAssembly)) + { + _ERR("Launcher assembly is not exist in %s", LauncherAssembly.c_str()); + return 1; + } + + std::string launcherDir = Basename(LauncherAssembly); + std::vector searchDirectories = { + RuntimeDirectory, DeviceAPIDirectory + }; + + std::string trusted_directories = JoinStrings(searchDirectories, ":"); + + _DBG("coreclr_dir : %s", RuntimeDirectory.c_str()); + _DBG("native_so_search_dir : %s", trusted_directories.c_str()); + _DBG("launcher_assembly : %s", LauncherAssembly.c_str()); + _DBG("launcher_dir : %s", launcherDir.c_str()); + + if (!InitializeCoreClr(launcherDir.c_str(), launcherDir.c_str())) + { + _ERR("Failed to initialize coreclr"); + return 1; + } void *preparedFunctionDelegate; - st = CreateDelegate(hostHandle, domainId, + int st = CreateDelegate(hostHandle, domainId, "Tizen.Runtime.Coreclr", "Tizen.Runtime.Coreclr.AssemblyManager", "Prepared", &preparedFunctionDelegate); @@ -279,8 +275,24 @@ int CoreRuntime::Launch(const char* root, const char* path, int argc, char* argv { _ERR("Failed to launch Application %s", path); } + return success ? 0 : 1; + } + else + { + std::string appRoot = root; + std::string appBin = ConcatPath(appRoot, "bin"); + std::string appLib = ConcatPath(appRoot, "lib"); + std::string probePath = appBin + ":" + appLib; + + int st = InitializeCoreClr(probePath.c_str(), probePath.c_str()); + unsigned int ret = 0; + 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; } - return success ? 0 : 1; } } // namespace dotnetcore diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.h b/NativeLauncher/src/dotnet/dotnet_launcher.h index 92567f6..fa72e11 100644 --- a/NativeLauncher/src/dotnet/dotnet_launcher.h +++ b/NativeLauncher/src/dotnet/dotnet_launcher.h @@ -50,6 +50,7 @@ class CoreRuntime : public tizen::runtime::LauncherInterface int Launch(const char* root, const char* path, int argc, char* argv[]) override; private: + bool InitializeCoreClr(const char* assembly_probe_paths, const char* pinvoke_probe_paths); coreclr_initialize_ptr InitializeClr; coreclr_execute_assembly_ptr ExecuteAssembly; coreclr_shutdown_ptr Shutdown; diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc index 9f43bfc..18085b7 100644 --- a/NativeLauncher/src/main.cc +++ b/NativeLauncher/src/main.cc @@ -103,11 +103,6 @@ int main(int argc, char *argv[]) _ERR("Failed to initialize"); return 1; } - if (runtime->RunManagedLauncher() != 0) - { - _ERR("Failed to run managed launcher"); - return 1; - } int args_len = vargs.size(); char** args = &vargs[0]; diff --git a/NativeLauncher/src/mono/mono_launcher.cc b/NativeLauncher/src/mono/mono_launcher.cc index fff1104..8636447 100644 --- a/NativeLauncher/src/mono/mono_launcher.cc +++ b/NativeLauncher/src/mono/mono_launcher.cc @@ -10,10 +10,13 @@ namespace tizen { namespace runtime { namespace mono { +static const char* DOMAIN_NAME = "tizen_mono_domain"; static const char* LIBMONO = "/usr/lib/libmono-2.0.so.1"; MonoRuntime::MonoRuntime() : - monolib(nullptr) + monolib(nullptr), + domain(nullptr), + launch(nullptr) { #define __XSTR(x) #x @@ -83,6 +86,8 @@ int MonoRuntime::Initialize(bool standalone) MONOLIB_RETURN_IF_NOSYM(mono_get_string_class_ptr, GetStringClass, "mono_get_string_class"); MONOLIB_RETURN_IF_NOSYM(mono_array_new_ptr, ArrayNew, "mono_array_new"); MONOLIB_RETURN_IF_NOSYM(mono_array_addr_with_size_ptr, ArrayAddrWithSize, "mono_array_addr_with_size"); + MONOLIB_RETURN_IF_NOSYM(mono_jit_cleanup_ptr, DomainCleanup, "mono_jit_cleanup"); + MONOLIB_RETURN_IF_NOSYM(mono_jit_exec_ptr, AssemblyExec, "mono_jit_exec"); #undef MONOLIB_RETURN_IF_NOSYM @@ -93,6 +98,10 @@ int MonoRuntime::Initialize(bool standalone) void MonoRuntime::Dispose() { + if (domain != nullptr) + { + DomainCleanup(domain); + } if (monolib != nullptr && dlclose(monolib) != 0) { _ERR("libmono close failed"); @@ -119,7 +128,7 @@ int MonoRuntime::RunManagedLauncher() */ SetAssembliesPath(deviceAPIDirectory.c_str()); - domain = JitInit("tizen_mono_domain"); + domain = JitInit(DOMAIN_NAME); if (domain == nullptr) { _ERR("Failed to init mono jit"); @@ -179,31 +188,57 @@ int MonoRuntime::RunManagedLauncher() int MonoRuntime::Launch(const char* root, const char* path, int argc, char* argv[]) { - MonoString *rootMonoString = NewString(domain, root); - MonoString *pathMonoString = NewString(domain, path); - MonoArray *argvMonoArray = ArrayNew(domain, GetStringClass(), argc); - for (int i=0; i Date: Fri, 21 Oct 2016 17:22:09 +0900 Subject: [PATCH 08/16] Change managed build to use Nuget package. Change-Id: Ib93ee9123cb406ac3e50aea5eeb51ddbed683d29 --- Tizen.Runtime/Tizen.CoreFX.Ref.Targets | 51 ------------------------ Tizen.Runtime/Tizen.Runtime.Coreclr.csproj | 29 +++++++++++++- Tizen.Runtime/Tizen.Runtime.Coreclr.project.json | 10 +++++ Tizen.Runtime/Tizen.Runtime.Mono.project.json | 11 +++++ packaging/dotnet-launcher.spec | 10 +++-- 5 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 Tizen.Runtime/Tizen.CoreFX.Ref.Targets create mode 100644 Tizen.Runtime/Tizen.Runtime.Coreclr.project.json create mode 100644 Tizen.Runtime/Tizen.Runtime.Mono.project.json diff --git a/Tizen.Runtime/Tizen.CoreFX.Ref.Targets b/Tizen.Runtime/Tizen.CoreFX.Ref.Targets deleted file mode 100644 index 065f966..0000000 --- a/Tizen.Runtime/Tizen.CoreFX.Ref.Targets +++ /dev/null @@ -1,51 +0,0 @@ - - - - /opt/usr/share/tizen.net/ref - /opt/usr/share/dotnet.tizen/framework - - - - true - true - $(CoreFXRefPath);$(TizenDeviceAPIPath) - false - - 1701, 1702 - - - - $(ExternalCscDir) - $(ExternalCscExe) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj b/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj index 32864ed..6bf5754 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj @@ -1,5 +1,5 @@ - + Debug @@ -8,6 +8,15 @@ Tizen.Runtime.Coreclr + + .NETStandard + v1.5 + .NETStandard,Version=v1.5 + false + true + $(NoWarn);1701;1702 + + true full @@ -44,9 +53,25 @@ - + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr.project.json b/Tizen.Runtime/Tizen.Runtime.Coreclr.project.json new file mode 100644 index 0000000..01fa069 --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr.project.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "NETStandard.Library": "1.6.0", + "System.Runtime.Loader": "4.0.0" + }, + "frameworks": { + "netstandard1.5": {} + } +} + diff --git a/Tizen.Runtime/Tizen.Runtime.Mono.project.json b/Tizen.Runtime/Tizen.Runtime.Mono.project.json new file mode 100644 index 0000000..710ecfa --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime.Mono.project.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} + diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 2891a2b..2c228c0 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -16,10 +16,10 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(launchpad) BuildRequires: aul-devel -BuildRequires: corefx-managed-32b-ref BuildRequires: mono-compiler BuildRequires: mono-devel -BuildRequires: csapi-tizen +BuildRequires: csapi-tizen-nuget +BuildRequires: dotnet-build-tools Requires: aul Requires(post): /sbin/ldconfig @@ -63,16 +63,18 @@ cmake \ make %{?jobs:-j%jobs} VERBOSE=1 +nuget restore Tizen.Runtime/Tizen.Runtime.Coreclr.project.json + xbuild \ /p:Configuration=%{_buildmode} \ /p:PreloadPath=%{_preload_dir} \ - /p:TizenDeviceAPIPath=%{_device_api_dir} \ Tizen.Runtime/Tizen.Runtime.Coreclr.csproj +nuget restore Tizen.Runtime/Tizen.Runtime.Mono.project.json + xbuild \ /p:Configuration=%{_buildmode} \ /p:PreloadPath=%{_preload_dir} \ - /p:TizenDeviceAPIPath=%{_device_api_dir} \ Tizen.Runtime/Tizen.Runtime.Mono.csproj %install -- 2.7.4 From 419ec3b9aa7b2bf3ebc39d1c38ba27823acf357a Mon Sep 17 00:00:00 2001 From: chunseok lee Date: Thu, 27 Oct 2016 14:28:25 +0900 Subject: [PATCH 09/16] Add dotnet.debugger into /usr/share/aul This patch works after https://review.tizen.org/gerrit/#/c/90185/ has landed. Change-Id: I745699fd59be991dd842daffbefdeaaf557720fc Signed-off-by: chunseok lee --- NativeLauncher/CMakeLists.txt | 1 + NativeLauncher/dotnet.debugger | 6 ++++++ packaging/dotnet-launcher.spec | 1 + 3 files changed, 8 insertions(+) create mode 100644 NativeLauncher/dotnet.debugger diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 9cd33a3..0647e2a 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -78,4 +78,5 @@ IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) + INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) ENDIF(NOT DEFINED NO_TIZEN) diff --git a/NativeLauncher/dotnet.debugger b/NativeLauncher/dotnet.debugger new file mode 100644 index 0000000..bff2bf1 --- /dev/null +++ b/NativeLauncher/dotnet.debugger @@ -0,0 +1,6 @@ +[DEBUGGER] +NAME LLDB-SERVER +EXE /usr/local/bin/lldb-server +APP_TYPE dotnet +EXTRA_KEY __DLP_DEBUG_ARG__ +EXTRA_ENV CORECLR_GDBJIT \ No newline at end of file diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 2c228c0..fa0bb60 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -87,6 +87,7 @@ install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir %manifest dotnet-launcher.manifest %{_loaderdir}/dotnet.loader %{_loaderdir}/dotnet.launcher +%{_loaderdir}/dotnet.debugger %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Coreclr.dll %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Mono.dll -- 2.7.4 From 8cd6fb2c60ac74259fdce9615836949e9d0ef7fc Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Thu, 10 Nov 2016 20:26:43 +0900 Subject: [PATCH 10/16] Add installer plugin and tool for create a NI nitool : native image maker for system dlls and apps libui-application.so : native image creating plugin for app installer Fix bug on getting trusted platform dll. Change-Id: Ie0b18c9fcca2fa0b814d4056d87c2e5d67e4e0e4 --- NativeLauncher/CMakeLists.txt | 55 +++- NativeLauncher/inc/utils.h | 8 + NativeLauncher/installer-plugin/common.cc | 292 +++++++++++++++++++++ NativeLauncher/installer-plugin/common.h | 13 + NativeLauncher/installer-plugin/nitool.cc | 93 +++++++ .../pkgmgr_parser_plugin_interface.h | 21 ++ NativeLauncher/installer-plugin/ui-application.cc | 96 +++++++ .../{src => launcher}/dotnet/dotnet_launcher.cc | 10 +- .../{src => launcher}/dotnet/dotnet_launcher.h | 0 NativeLauncher/{src => launcher}/launcher.cc | 0 NativeLauncher/{inc => launcher}/launcher.h | 0 NativeLauncher/{src => launcher}/main.cc | 26 +- .../{src => launcher}/mono/mono_launcher.cc | 2 +- .../{src => launcher}/mono/mono_launcher.h | 0 NativeLauncher/{src => launcher}/waiter/waiter.cc | 0 NativeLauncher/{src => launcher}/waiter/waiter.h | 0 NativeLauncher/{src => util}/utils.cc | 172 ++++++++++-- packaging/dotnet-launcher.spec | 7 + 18 files changed, 736 insertions(+), 59 deletions(-) create mode 100644 NativeLauncher/installer-plugin/common.cc create mode 100644 NativeLauncher/installer-plugin/common.h create mode 100644 NativeLauncher/installer-plugin/nitool.cc create mode 100644 NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h create mode 100644 NativeLauncher/installer-plugin/ui-application.cc rename NativeLauncher/{src => launcher}/dotnet/dotnet_launcher.cc (99%) rename NativeLauncher/{src => launcher}/dotnet/dotnet_launcher.h (100%) rename NativeLauncher/{src => launcher}/launcher.cc (100%) rename NativeLauncher/{inc => launcher}/launcher.h (100%) rename NativeLauncher/{src => launcher}/main.cc (88%) rename NativeLauncher/{src => launcher}/mono/mono_launcher.cc (99%) rename NativeLauncher/{src => launcher}/mono/mono_launcher.h (100%) rename NativeLauncher/{src => launcher}/waiter/waiter.cc (100%) rename NativeLauncher/{src => launcher}/waiter/waiter.h (100%) rename NativeLauncher/{src => util}/utils.cc (51%) diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 0647e2a..cd273e1 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT("dotnet-launcher") +PROJECT("dotnet-tools") MESSAGE("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") @@ -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 dlog ecore bundle dlog launchpad) + PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad) ENDIF(DEFINED NO_TIZEN) FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) @@ -34,6 +34,10 @@ IF(DEFINED RUNTIME_DIR) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DRUNTIME_DIR=${RUNTIME_DIR}") ENDIF(DEFINED RUNTIME_DIR) +IF(DEFINED CROSSGEN_PATH) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DCROSSGEN_PATH=${CROSSGEN_PATH}") +ENDIF(DEFINED CROSSGEN_PATH) + IF(DEFINED VERSION) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DVERSION=${VERSION}") ENDIF(DEFINED VERSION) @@ -41,7 +45,7 @@ ENDIF(DEFINED VERSION) 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} -fvisibility=hidden") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") +#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -D_FILE_OFFSET_BITS=64") #SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DLAUNCHING_TIME_MEASURE") @@ -51,19 +55,20 @@ SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") -INCLUDE_DIRECTORIES(inc) +#SET(${PROJECT_NAME}_LDFLAGS ${${PROJECT_NAME}_LDFLAGS} "-pie") -SET(DOTNET_LAUNCHER "dotnet-launcher") -SET(MONO_LAUNCHER "mono-launcher") +INCLUDE_DIRECTORIES(inc launcher util) +SET(DOTNET_LAUNCHER "dotnet-launcher") SET(${DOTNET_LAUNCHER}_SOURCE_FILES - src/main.cc - src/utils.cc - src/launcher.cc - src/dotnet/dotnet_launcher.cc - src/mono/mono_launcher.cc + launcher/main.cc + util/utils.cc + launcher/launcher.cc + launcher/dotnet/dotnet_launcher.cc + launcher/mono/mono_launcher.cc ) -ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${PROJECT_NAME}_SOURCE_FILES}) +ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${DOTNET_LAUNCHER}_SOURCE_FILES}) +SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER} PROPERTIES COMPILE_FLAGS "-fPIE") IF(NOT DEFINED NO_TIZEN) TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER} aul) @@ -72,11 +77,33 @@ TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER} ${${PROJECT_NAME}_LDFLAGS} "-pie -ldl - SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER} PROPERTIES SKIP_BUILD_RPATH TRUE - ) # remove rpath option that is automatically generated by cmake. +) # remove rpath option that is automatically generated by cmake. + +SET(NITOOL "nitool") +SET(${NITOOL}_SOURCE_FILES + util/utils.cc + installer-plugin/common.cc + installer-plugin/nitool.cc +) +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}) IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) + INSTALL(TARGETS ${NITOOL} DESTINATION ${BINDIR}) + INSTALL(TARGETS ${INSTALLER_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) - INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) + INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) ENDIF(NOT DEFINED NO_TIZEN) diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 145a43d..ed993fa 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -3,11 +3,16 @@ #include #include +#include #ifndef PATH_SEPARATOR #define PATH_SEPARATOR '/' #endif +bool ICompare(const std::string& a, const std::string& b); +bool ICompare(const std::string& a, int a_offset, const std::string& b, int b_offset, int length); +bool IsManagedAssembly(const std::string& filename); +bool IsNativeImage(const std::string& filename); std::string ReadSelfPath (); std::string ConcatPath (const std::string& path1, const std::string& path2); void AppendPath (std::string& path1, const std::string& path2); @@ -18,4 +23,7 @@ void AssembliesInDirectory(const std::vector& directories, std::str bool FileNotExist(const std::string& path); std::string JoinStrings(const std::vector& strings, const char* const delimeter); +typedef std::function FileReader; +void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth); + #endif // __UTILS_H__ diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc new file mode 100644 index 0000000..70b963f --- /dev/null +++ b/NativeLauncher/installer-plugin/common.cc @@ -0,0 +1,292 @@ +#include +#include +#include + +#include "log.h" +#include "utils.h" +#include "pkgmgr_parser_plugin_interface.h" + +#include +#include +#include + +#include +#include + +#include "common.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "NETCORE_INSTALLER_PLUGIN" + +#ifndef DEVICE_API_DIR +#error "DEVICE_API_DIR is missed" +#endif + +#ifndef RUNTIME_DIR +#error "RUNTIME_DIR is missed" +#endif + +#ifndef CROSSGEN_PATH +#error "CROSSGEN_PATH is missed" +#endif + +#define __XSTR(x) #x +#define __STR(x) __XSTR(x) +static const char* DeviceAPIDir = __STR(DEVICE_API_DIR); +static const char* RuntimeDir = __STR(RUNTIME_DIR); +static const char* CrossgenPath = __STR(CROSSGEN_PATH); +static const char* JITPath = __STR(RUNTIME_DIR)"/libclrjit.so"; +#undef __STR +#undef __XSTR + +static void crossgen(const char* dll_path, const char* app_path); +static void smack_(const char* dll_path); + +void create_ni_platform() +{ + std::string corlib = ConcatPath(RuntimeDir, "System.Private.CoreLib.dll"); + std::string nicorlib = ConcatPath(RuntimeDir, "System.Private.CoreLib.ni.dll"); + + if (FileNotExist(nicorlib)) + { + crossgen(corlib.c_str(), nullptr); + smack_(nicorlib.c_str()); + } + + const char* platform_dirs[] = {RuntimeDir, DeviceAPIDir}; + const char* ignores[] = {corlib.c_str()}; + + create_ni_under_dirs(platform_dirs, 2, ignores, 1, [](const char* ni){ + smack_(ni); + }); +} + +static void smack_(const char* dll_path) +{ + static const char* CHKSMACK = "/usr/bin/chsmack"; + pid_t pid = fork(); + if (pid == -1) + { + return; + } + + if (pid > 0) + { + int status; + waitpid(pid, &status, 0); + if (WIFEXITED(status)) + { + return; + } + } + else + { + const char* args[] = { + CHKSMACK, + "-a", "_", + dll_path, + nullptr + }; + for (const char* arg : args) + { + printf("%s ", arg); + } + printf("\n"); + + execv(CHKSMACK, const_cast(args)); + + exit(0); + } +} + +static void crossgen(const char* dll_path, const char* app_path) +{ + //pid_t parent = getpid(); + pid_t pid = fork(); + if (pid == -1) + { + return; + } + + if (pid > 0) + { + int status; + waitpid(pid, &status, 0); + if (WIFEXITED(status)) + { + return; + } + } + else + { + std::vector tpaDir = { + RuntimeDir, DeviceAPIDir + }; + std::string tpa; + AssembliesInDirectory(tpaDir, tpa); + + std::vector argv = + { + CrossgenPath, + "/Trusted_Platform_Assemblies", tpa.c_str(), + "/JITPath", JITPath, + "/FragileNonVersionable" + }; + if (app_path != nullptr) + { + argv.push_back("/App_Paths"); + argv.push_back(app_path); + } + argv.push_back(dll_path); + argv.push_back(nullptr); + + /* + for (const char* arg : argv) + { + printf("%s ", arg); + } + printf("\n"); + */ + printf("+ %s\n", dll_path); + + execv(CrossgenPath, const_cast(argv.data())); + exit(0); + } +} + +static int get_root_path(const char *pkgid, std::string& root_path) +{ + int ret = 0; + char *path = 0; + + uid_t uid = 0; + + if (pkgmgr_installer_info_get_target_uid(&uid) < 0) + { + _ERR("Failed to get UID"); + return -1; + } + + _INFO("user id is %d", uid); + + pkgmgrinfo_pkginfo_h handle; + if (uid == 0) + { + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + if (ret != PMINFO_R_OK) + return -1; + } + else + { + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); + if (ret != PMINFO_R_OK) + return -1; + } + + ret = pkgmgrinfo_pkginfo_get_root_path(handle, &path); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return -1; + } + root_path = path; + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + + return 0; +} + +static bool NIExist(const std::string& path, std::string& ni) +{ + static const char* possible_exts[] = { + ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL" + }; + std::string fname = path.substr(0, path.size() - 4); + + struct stat sb; + + for (const char* ext : possible_exts) + { + std::string f = fname + ext; + if (stat(f.c_str(), &sb) == 0) + { + ni = f; + return true; + } + } + + return false; +} + +void create_ni_under_dirs(const char* root_paths[], int count, const char* ignores[], int igcount, after_create cb) +{ + std::string app_paths; + for (int i=0; i + +typedef std::function after_create; +void create_ni_under_dirs(const char* root_paths[], int count, const char* ignores[], int igcount, after_create cb); +void create_ni_under_dirs(const char* root_paths[], int count, after_create cb); +void create_ni_under_dirs(const char* root_paths[], int count); +int create_ni_under_pkg_root(const char* pkg_name); +void create_ni_platform(); + +#endif // __INSTALLER_PLUGIN_COMMON_H__ diff --git a/NativeLauncher/installer-plugin/nitool.cc b/NativeLauncher/installer-plugin/nitool.cc new file mode 100644 index 0000000..1fd4c8f --- /dev/null +++ b/NativeLauncher/installer-plugin/nitool.cc @@ -0,0 +1,93 @@ +#include "common.h" + +#include +#include + +#include + +std::vector get_cmd_args(char** begin, char** end) +{ + for (char** itr = end-1; itr != begin-1; --itr) + { + if (itr != end && strncmp(*itr, "--", 2) == 0) + { + itr++; + int len = end - itr; + return std::vector(len, *itr); + } + } + return std::vector(end-begin-1, *(begin+1)); +} + +bool cmd_option_exists(char** begin, char** end, const std::string& option) +{ + return std::find(begin, end, option) != end; +} + +static void help(const char *argv0) +{ + const char* helpdesc = + "Usage: %s [args] \n" + " --help - Display this screen\n" + " --system - Create NI under System DLLs\n" + " --pkg - Create NI for package\n" + "\n" + "Example:\n" + "Create native image for dlls and exes under platform directories\n" + "%s --system\n" + "Create native image under the package's bin and lib directory\n" + "%s --pkg org.tizen.FormsGallery\n\n"; + printf(helpdesc, argv0, argv0, argv0); +} + +int main(int argc, char* argv[]) +{ + bool pkg_mode = false; + + if (cmd_option_exists(argv, argv+argc, "--help")) + { + help(argv[0]); + return 0; + } + + if (cmd_option_exists(argv, argv+argc, "--system")) + { + create_ni_platform(); + return 0; + } + + if (cmd_option_exists(argv, argv+argc, "--pkg")) + { + pkg_mode = true; + } + + std::vector args = get_cmd_args(argv, argv+argc); + + if (args.size() < 1) + { + if (pkg_mode) + fprintf(stderr, "Package name is missed\n"); + else + fprintf(stderr, "DLL path is missed\n"); + help(argv[0]); + return 1; + } + + if (pkg_mode) + { + for (const char* pkg : args) + { + if (create_ni_under_pkg_root(pkg) != 0) + { + fprintf(stderr, "Failed to get root path from [%s]\n", pkg); + return 1; + } + } + } + else + { + create_ni_under_dirs(args.data(), args.size()); + } + + return 0; +} diff --git a/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h b/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h new file mode 100644 index 0000000..0f2d4a8 --- /dev/null +++ b/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h @@ -0,0 +1,21 @@ +#ifndef __PKGMGR_PARSER_PLUGIN_INTERFACE__ +#define __PKGMGR_PARSER_PLUGIN_INTERFACE__ + +extern "C" +{ + typedef struct _xmlDoc xmlDoc; + typedef xmlDoc* xmlDocPtr; + int PKGMGR_PARSER_PLUGIN_PRE_INSTALL (const char *pkgid); + int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE (const char *pkgid); + int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL (const char *pkgid); + + int PKGMGR_PARSER_PLUGIN_INSTALL (xmlDocPtr doc, const char* pkgid); + int PKGMGR_PARSER_PLUGIN_UPGRADE (xmlDocPtr doc, const char* pkgid); + int PKGMGR_PARSER_PLUGIN_UNINSTALL (xmlDocPtr doc, const char* pkgid); + + int PKGMGR_PARSER_PLUGIN_POST_INSTALL (const char *pkgid); + int PKGMGR_PARSER_PLUGIN_POST_UPGRADE (const char *pkgid); + int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL (const char *pkgid); +} + +#endif // __PKGMGR_PARSER_PLUGIN_INTERFACE__ diff --git a/NativeLauncher/installer-plugin/ui-application.cc b/NativeLauncher/installer-plugin/ui-application.cc new file mode 100644 index 0000000..c0196e3 --- /dev/null +++ b/NativeLauncher/installer-plugin/ui-application.cc @@ -0,0 +1,96 @@ +#include "common.h" +#include "log.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "NETCORE_INSTALLER_PLUGIN" + +#include +#include +#include + +/* + * forked crossgen from installer is not working. + * because crossgen's capability is not enough. + * following command is needed + * + * setcap cap_dac_override=eip /opt/usr/share/dotnet.tizen/framework/crossgen + * + */ + +extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL (const char *pkgid) +{ + _INFO("pkg : %s", pkgid); + + uid_t uid = 0; + + if (pkgmgr_installer_info_get_target_uid(&uid) < 0) + { + _ERR("Failed to get UID"); + return 0; + } + + pkgmgrinfo_pkginfo_h handle; + int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); + if (ret != PMINFO_R_OK) + { + _ERR("Failed to get pkg info"); + return 0; + } + + _INFO("success to get pkg info"); + + bool dotnet_exist = false; + + auto dotnet_app_counter = [] (pkgmgrinfo_appinfo_h handle, void *user_data) -> int + { + char* appid = nullptr; + char* type = nullptr; + bool* dotnet = static_cast(user_data); + + if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) + { + _ERR("Failed to get app id"); + return 0; + } + + _INFO("App id : %s", appid); + + if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) + { + _ERR("Failed to get app type : %s", appid); + return 0; + } + + _INFO("App type : %s", type); + + if (strcmp(type, "dotnet") == 0) + { + *dotnet = true; + } + + return 0; + }; + + if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, dotnet_app_counter, &dotnet_exist, uid) != PMINFO_R_OK) + { + _ERR("Failed to get list of app in pkg : %s", pkgid); + return -1; + } + + _INFO("Finish to get pkg list"); + + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + if (dotnet_exist) + { + _INFO("dotnet app is exist"); + return create_ni_under_pkg_root(pkgid) == 0 ? 0 : -1; + } + + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE (const char *pkgid) +{ + return PKGMGR_PARSER_PLUGIN_POST_INSTALL(pkgid); +} diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc similarity index 99% rename from NativeLauncher/src/dotnet/dotnet_launcher.cc rename to NativeLauncher/launcher/dotnet/dotnet_launcher.cc index ce880a9..1bfbdec 100644 --- a/NativeLauncher/src/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -15,15 +15,15 @@ namespace runtime { namespace dotnetcore { CoreRuntime::CoreRuntime() : + InitializeClr(nullptr), + ExecuteAssembly(nullptr), + Shutdown(nullptr), + CreateDelegate(nullptr), coreclrLib(nullptr), hostHandle(nullptr), domainId(-1), PreparedFunction(nullptr), - LaunchFunction(nullptr), - InitializeClr(nullptr), - ExecuteAssembly(nullptr), - Shutdown(nullptr), - CreateDelegate(nullptr) + LaunchFunction(nullptr) { #define __XSTR(x) #x #define __STR(x) __XSTR(x) diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h similarity index 100% rename from NativeLauncher/src/dotnet/dotnet_launcher.h rename to NativeLauncher/launcher/dotnet/dotnet_launcher.h diff --git a/NativeLauncher/src/launcher.cc b/NativeLauncher/launcher/launcher.cc similarity index 100% rename from NativeLauncher/src/launcher.cc rename to NativeLauncher/launcher/launcher.cc diff --git a/NativeLauncher/inc/launcher.h b/NativeLauncher/launcher/launcher.h similarity index 100% rename from NativeLauncher/inc/launcher.h rename to NativeLauncher/launcher/launcher.h diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/launcher/main.cc similarity index 88% rename from NativeLauncher/src/main.cc rename to NativeLauncher/launcher/main.cc index 18085b7..c43c299 100644 --- a/NativeLauncher/src/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -114,23 +114,25 @@ int main(int argc, char *argv[]) } else { - Launchpad.OnCreate = [&runtime] + Launchpad.OnCreate = [&runtime]() { - auto idle_task = [](void *data) -> Eina_Bool - { - LauncherInterface* runtime = static_cast(data); - if (runtime->RunManagedLauncher() != 0) - { - _ERR("Failed to run managed launcher"); - } - return ECORE_CALLBACK_CANCEL; - }; if (runtime->Initialize(false) != 0) { _ERR("Failed to initialized"); - return 1; } - ecore_idler_add(idle_task, runtime.get()); + else + { + auto idle_task = [](void *data) -> Eina_Bool + { + LauncherInterface* runtime = static_cast(data); + if (runtime->RunManagedLauncher() != 0) + { + _ERR("Failed to run managed launcher"); + } + return ECORE_CALLBACK_CANCEL; + }; + ecore_idler_add(idle_task, runtime.get()); + } }; Launchpad.OnTerminate = [&runtime](const AppInfo& info, int argc, char** argv) diff --git a/NativeLauncher/src/mono/mono_launcher.cc b/NativeLauncher/launcher/mono/mono_launcher.cc similarity index 99% rename from NativeLauncher/src/mono/mono_launcher.cc rename to NativeLauncher/launcher/mono/mono_launcher.cc index 8636447..e0d0156 100644 --- a/NativeLauncher/src/mono/mono_launcher.cc +++ b/NativeLauncher/launcher/mono/mono_launcher.cc @@ -238,7 +238,7 @@ int MonoRuntime::Launch(const char* root, const char* path, int argc, char* argv _ERR("Failed to open assembly : %s", path); return 1; } - int ret = AssemblyExec(domain, app, argc, argv); + AssemblyExec(domain, app, argc, argv); } return 0; } diff --git a/NativeLauncher/src/mono/mono_launcher.h b/NativeLauncher/launcher/mono/mono_launcher.h similarity index 100% rename from NativeLauncher/src/mono/mono_launcher.h rename to NativeLauncher/launcher/mono/mono_launcher.h diff --git a/NativeLauncher/src/waiter/waiter.cc b/NativeLauncher/launcher/waiter/waiter.cc similarity index 100% rename from NativeLauncher/src/waiter/waiter.cc rename to NativeLauncher/launcher/waiter/waiter.cc diff --git a/NativeLauncher/src/waiter/waiter.h b/NativeLauncher/launcher/waiter/waiter.h similarity index 100% rename from NativeLauncher/src/waiter/waiter.h rename to NativeLauncher/launcher/waiter/waiter.h diff --git a/NativeLauncher/src/utils.cc b/NativeLauncher/util/utils.cc similarity index 51% rename from NativeLauncher/src/utils.cc rename to NativeLauncher/util/utils.cc index 776fd9f..2cc1026 100644 --- a/NativeLauncher/src/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -8,13 +8,41 @@ #include #include #include -#include +#include #include #include #include #include "utils.h" +bool ICompare(const std::string& a, const std::string& b) +{ + return a.length() == b.length() && + std::equal(b.begin(), b.end(), a.begin(), + [](unsigned char a, unsigned char b) + { return std::tolower(a) == std::tolower(b); }); +} + +bool ICompare(const std::string& a, int a_offset, const std::string& b, int b_offset, int length) +{ + return static_cast(a.length()) - length >= a_offset && + static_cast(b.length()) - length >= b_offset && + std::equal(b.begin() + b_offset, b.begin() + b_offset + length, a.begin() + a_offset, + [](unsigned char a, unsigned char b) + { return std::tolower(a) == std::tolower(b); }); +} + +bool IsManagedAssembly(const std::string& filename) +{ + return ICompare(filename, filename.size()-4, ".dll", 0, 4) || + ICompare(filename, filename.size()-4, ".exe", 0, 4); +} + +bool IsNativeImage(const std::string& filename) +{ + return ICompare(filename, filename.size()-7, ".ni", 0, 3); +} + std::string ReadSelfPath() { char buff[PATH_MAX]; @@ -104,7 +132,7 @@ bool EndWithIgnoreCase(const std::string& str1, const std::string& str2, std::st bool FileNotExist(const std::string& path) { struct stat sb; - return (stat(path.c_str(), &sb) != 0) || !S_ISREG(sb.st_mode); + return stat(path.c_str(), &sb) != 0; } static bool ExtCheckAndGetFileNameIfExist(const std::string& dir, const std::string& ext, struct dirent* entry, std::string& filename) @@ -168,44 +196,134 @@ std::string JoinStrings(const std::vector& strings, const char* con } } -void AssembliesInDirectory(const std::vector& directories, std::string& tpaList) +struct AssemblyFile { - static const std::string tpaExtensions[] = - {".ni.dll", ".dll", ".ni.exe", ".exe"}; + std::string noext; + std::string ext; +}; - std::set addedAssemblies; - - DIR* dir = nullptr; - struct dirent* entry = nullptr; +bool operator == (const AssemblyFile& lhs, const AssemblyFile& rhs) +{ + return lhs.noext == rhs.noext && lhs.ext == rhs.ext; +} - for (auto directory : directories) +namespace std +{ + template<> + struct hash { - dir = opendir(directory.c_str()); - if (dir == nullptr) + std::size_t operator () (const AssemblyFile& f) const { - continue; + const std::size_t h1 = std::hash{}(f.noext); + const std::size_t h2 = std::hash{}(f.ext); + + return h1 ^ (h2 << 1); } + }; +} + +void AssembliesInDirectory(const std::vector& directories, std::string& tpaList) +{ + std::unordered_map addedAssemblies; + + auto reader = [&addedAssemblies] (const char* path) + { + std::string _path(path); - for (auto ext : tpaExtensions) + std::string::size_type dotp = _path.rfind('.'); + std::string ext = dotp != std::string::npos ? _path.substr(dotp) : ""; + std::string noext; + bool ni = false; + + if (IsManagedAssembly(_path)) { - while ((entry = readdir(dir)) != nullptr) + if (IsNativeImage(_path)) { - std::string fullname; - if (ExtCheckAndGetFileNameIfExist(directory.c_str(), ext, entry, fullname)) - { - std::string filename = StripNIDLL(fullname); - if (addedAssemblies.find(filename) == addedAssemblies.end()) - { - addedAssemblies.insert(filename); - tpaList += fullname + ':'; - } - } + noext = _path.substr(0, _path.size()-7); + ni = true; + } + else + { + noext = _path.substr(0, _path.size()-4); } - rewinddir(dir); + + AssemblyFile f = {noext, ext}; + addedAssemblies[f] = ni; } - closedir(dir); + }; + + for (auto directory : directories) + { + ScanFilesInDir(directory.c_str(), reader, 1); + } + + for (auto kv : addedAssemblies) + { + tpaList += kv.first.noext + (kv.second ? ".ni" : "") + kv.first.ext + ':'; } + if (tpaList.back() == ':') tpaList.pop_back(); +} + +void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth) +{ + DIR *dir; + struct dirent* entry; + bool isDir; + + dir = opendir(directory); + + if (dir == nullptr) + { + //_ERR("Can not open directory : %s", directory); + return; + } + + std::vector innerDirectories; + + while ((entry = readdir(dir)) != nullptr) + { + isDir = false; + std::string path = ConcatPath(directory, entry->d_name); + switch (entry->d_type) + { + case DT_REG: break; + case DT_DIR: + isDir = true; + break; + case DT_LNK: + case DT_UNKNOWN: + struct stat sb; + if (stat(path.c_str(), &sb) == -1) + { + continue; + } + + if (S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode)) + { + break; + } + default: + continue; + } + if (!isDir) + { + reader(path.c_str()); + } + else if (depth > 1 && strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) + { + innerDirectories.push_back(path); + } + } + + if (depth != 0) + { + for (auto& d : innerDirectories) + { + ScanFilesInDir(d.c_str(), reader, depth-1); + } + } + closedir(dir); } diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index fa0bb60..1050527 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -15,6 +15,8 @@ BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(launchpad) +BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: aul-devel BuildRequires: mono-compiler BuildRequires: mono-devel @@ -33,6 +35,7 @@ Requires(preun): /usr/bin/systemctl %define _device_api_dir %{dotnet_assembly_path} %define _runtime_dir /opt/usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0 %define _preload_dir /opt/usr/share/dotnet.tizen/preload +%define _install_plugin_dir /usr/etc/package-manager/parserlib %description Launchpad plugin for launching dotnet apps @@ -56,8 +59,10 @@ cmake \ -DCMAKE_BUILD_TYPE=%{_buildmode} \ -DDEVICE_API_DIR=%{_device_api_dir} \ -DRUNTIME_DIR=%{_runtime_dir} \ + -DCROSSGEN_PATH=%{_device_api_dir}/crossgen \ -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Coreclr.dll \ -DMONO_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Mono.dll \ + -DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \ -DVERSION=%{version} \ NativeLauncher @@ -89,5 +94,7 @@ install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir %{_loaderdir}/dotnet.launcher %{_loaderdir}/dotnet.debugger %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) %{_bindir}/Tizen.Runtime.Coreclr.dll %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Mono.dll -- 2.7.4 From d1996eaf33451d4c9ceb207247c8c2f33107ab09 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Tue, 15 Nov 2016 15:49:52 +0900 Subject: [PATCH 11/16] Add Unhandled Exception handler for Dlog output Add temporarily implmentation until become Appdomain on API Change-Id: I6c622d701d94cf3cc29262e066a490f102cfd46b --- .../Tizen.Runtime.Coreclr/AssemblyManager.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index 39ff2fa..acbb06e 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -78,10 +78,33 @@ namespace Tizen.Runtime.Coreclr } } + 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(string preloadDirectory) { 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}); + CurrentAssemblyLoaderContext = new AssemblyLoader(); if (!string.IsNullOrEmpty(preloadDirectory)) -- 2.7.4 From 6608f52ed733573561748e07922b20ea665c0562 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Thu, 24 Nov 2016 10:58:47 +0900 Subject: [PATCH 12/16] Fix missed ni.dll in tpa list Change-Id: I42a2bad8ebde5b6c056b2f12a5145ba31eda1d98 --- NativeLauncher/util/utils.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 2cc1026..df30ed0 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -248,7 +248,14 @@ void AssembliesInDirectory(const std::vector& directories, std::str } AssemblyFile f = {noext, ext}; - addedAssemblies[f] = ni; + if (addedAssemblies.find(f) == addedAssemblies.end()) + { + addedAssemblies[f] = ni; + } + else + { + addedAssemblies[f] |= ni; + } } }; -- 2.7.4 From 918b980449f4f85322821ced3e110eaa3a896bc9 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Tue, 29 Nov 2016 09:39:35 +0900 Subject: [PATCH 13/16] Change dotnet core directory Change-Id: I174dda342cc9d60f60a08c09d9ee78ba6d35c54d --- 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 1050527..0a95375 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -33,7 +33,7 @@ Requires(preun): /usr/bin/systemctl %define _loaderdir %{_prefix}/share/aul %define _configdir /etc %define _device_api_dir %{dotnet_assembly_path} -%define _runtime_dir /opt/usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0 +%define _runtime_dir /opt/usr/share/dotnet/shared/Microsoft.NETCore.App/1.1.0 %define _preload_dir /opt/usr/share/dotnet.tizen/preload %define _install_plugin_dir /usr/etc/package-manager/parserlib -- 2.7.4 From 966152751fa2830e7469c0598db3e7feb8edf952 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Tue, 29 Nov 2016 10:23:11 +0900 Subject: [PATCH 14/16] Add License file and comments to sources Change-Id: I2d4993dd798ebac2666018289f6359a579e328a0 --- LICENSE | 202 +++++++++++++++++++++ NativeLauncher/inc/log.h | 16 ++ NativeLauncher/inc/utils.h | 16 ++ NativeLauncher/installer-plugin/common.cc | 16 ++ NativeLauncher/installer-plugin/common.h | 16 ++ NativeLauncher/installer-plugin/nitool.cc | 16 ++ .../pkgmgr_parser_plugin_interface.h | 16 ++ NativeLauncher/installer-plugin/ui-application.cc | 16 ++ NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 16 ++ NativeLauncher/launcher/dotnet/dotnet_launcher.h | 16 ++ NativeLauncher/launcher/launcher.cc | 16 ++ NativeLauncher/launcher/launcher.h | 16 ++ NativeLauncher/launcher/main.cc | 16 ++ NativeLauncher/launcher/mono/mono_launcher.cc | 16 ++ NativeLauncher/launcher/mono/mono_launcher.h | 16 ++ NativeLauncher/launcher/waiter/waiter.cc | 16 ++ NativeLauncher/launcher/waiter/waiter.h | 16 ++ NativeLauncher/util/utils.cc | 16 ++ .../Tizen.Runtime.Coreclr/AssemblyLoader.cs | 16 ++ .../Tizen.Runtime.Coreclr/AssemblyManager.cs | 16 ++ .../Tizen.Runtime.Mono/AssemblyManager.cs | 16 ++ .../Tizen.Runtime/DefaultConfigAttribute.cs | 16 ++ Tizen.Runtime/Tizen.Runtime/Log.cs | 16 ++ 23 files changed, 554 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/NativeLauncher/inc/log.h b/NativeLauncher/inc/log.h index 59f2dc9..25b3f83 100644 --- a/NativeLauncher/inc/log.h +++ b/NativeLauncher/inc/log.h @@ -1,3 +1,19 @@ +/* + * 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 __LOG_H__ #define __LOG_H__ diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index ed993fa..3e56112 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -1,3 +1,19 @@ +/* + * 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 __UTILS_H__ #define __UTILS_H__ diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 70b963f..8701b2e 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -1,3 +1,19 @@ +/* + * 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 #include #include diff --git a/NativeLauncher/installer-plugin/common.h b/NativeLauncher/installer-plugin/common.h index 39f4381..50c33f3 100644 --- a/NativeLauncher/installer-plugin/common.h +++ b/NativeLauncher/installer-plugin/common.h @@ -1,3 +1,19 @@ +/* + * 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 __INSTALLER_PLUGIN_COMMON_H__ #define __INSTALLER_PLUGIN_COMMON_H__ diff --git a/NativeLauncher/installer-plugin/nitool.cc b/NativeLauncher/installer-plugin/nitool.cc index 1fd4c8f..fd090fb 100644 --- a/NativeLauncher/installer-plugin/nitool.cc +++ b/NativeLauncher/installer-plugin/nitool.cc @@ -1,3 +1,19 @@ +/* + * 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 "common.h" #include diff --git a/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h b/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h index 0f2d4a8..fc4354c 100644 --- a/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h +++ b/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h @@ -1,3 +1,19 @@ +/* + * 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 __PKGMGR_PARSER_PLUGIN_INTERFACE__ #define __PKGMGR_PARSER_PLUGIN_INTERFACE__ diff --git a/NativeLauncher/installer-plugin/ui-application.cc b/NativeLauncher/installer-plugin/ui-application.cc index c0196e3..f731888 100644 --- a/NativeLauncher/installer-plugin/ui-application.cc +++ b/NativeLauncher/installer-plugin/ui-application.cc @@ -1,3 +1,19 @@ +/* + * 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 "common.h" #include "log.h" diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 1bfbdec..509248d 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -1,3 +1,19 @@ +/* + * 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 diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index fa72e11..31a8c4a 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -1,3 +1,19 @@ +/* + * 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 "launcher.h" extern "C" diff --git a/NativeLauncher/launcher/launcher.cc b/NativeLauncher/launcher/launcher.cc index 9efd49e..ebbc58d 100644 --- a/NativeLauncher/launcher/launcher.cc +++ b/NativeLauncher/launcher/launcher.cc @@ -1,3 +1,19 @@ +/* + * 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 "launcher.h" #include "log.h" diff --git a/NativeLauncher/launcher/launcher.h b/NativeLauncher/launcher/launcher.h index 399bef5..4d87457 100644 --- a/NativeLauncher/launcher/launcher.h +++ b/NativeLauncher/launcher/launcher.h @@ -1,3 +1,19 @@ +/* + * 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 __LAUNCHER_INTERFACE_H__ #define __LAUNCHER_INTERFACE_H__ diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index c43c299..3d574ec 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -1,3 +1,19 @@ +/* + * 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/dotnet_launcher.h" #include "mono/mono_launcher.h" #include "utils.h" diff --git a/NativeLauncher/launcher/mono/mono_launcher.cc b/NativeLauncher/launcher/mono/mono_launcher.cc index e0d0156..97813b3 100644 --- a/NativeLauncher/launcher/mono/mono_launcher.cc +++ b/NativeLauncher/launcher/mono/mono_launcher.cc @@ -1,3 +1,19 @@ +/* + * 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 "mono_launcher.h" #include "utils.h" diff --git a/NativeLauncher/launcher/mono/mono_launcher.h b/NativeLauncher/launcher/mono/mono_launcher.h index d705d9e..4e73670 100644 --- a/NativeLauncher/launcher/mono/mono_launcher.h +++ b/NativeLauncher/launcher/mono/mono_launcher.h @@ -1,3 +1,19 @@ +/* + * 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 "launcher.h" extern "C" diff --git a/NativeLauncher/launcher/waiter/waiter.cc b/NativeLauncher/launcher/waiter/waiter.cc index 6447d4a..02fa3bf 100644 --- a/NativeLauncher/launcher/waiter/waiter.cc +++ b/NativeLauncher/launcher/waiter/waiter.cc @@ -1,3 +1,19 @@ +/* + * 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 diff --git a/NativeLauncher/launcher/waiter/waiter.h b/NativeLauncher/launcher/waiter/waiter.h index c4b98fb..bd3be5f 100644 --- a/NativeLauncher/launcher/waiter/waiter.h +++ b/NativeLauncher/launcher/waiter/waiter.h @@ -1,3 +1,19 @@ +/* + * 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 #include diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index df30ed0..48810d9 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -1,3 +1,19 @@ +/* + * 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 #include diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs index 2e21c7b..693877f 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs @@ -1,3 +1,19 @@ +/* + * 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; diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index acbb06e..28b0edf 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -1,3 +1,19 @@ +/* + * 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; diff --git a/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs index 9389c62..441317a 100644 --- a/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Mono/AssemblyManager.cs @@ -1,3 +1,19 @@ +/* + * 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.Collections.Generic; diff --git a/Tizen.Runtime/Tizen.Runtime/DefaultConfigAttribute.cs b/Tizen.Runtime/Tizen.Runtime/DefaultConfigAttribute.cs index b0a4cd6..097ef73 100644 --- a/Tizen.Runtime/Tizen.Runtime/DefaultConfigAttribute.cs +++ b/Tizen.Runtime/Tizen.Runtime/DefaultConfigAttribute.cs @@ -1,3 +1,19 @@ +/* + * 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.Collections.Generic; diff --git a/Tizen.Runtime/Tizen.Runtime/Log.cs b/Tizen.Runtime/Tizen.Runtime/Log.cs index b27a329..f0fd067 100644 --- a/Tizen.Runtime/Tizen.Runtime/Log.cs +++ b/Tizen.Runtime/Tizen.Runtime/Log.cs @@ -1,3 +1,19 @@ +/* + * 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; -- 2.7.4 From 0c867ba84c6495994b2ffb2c3149dae1ae6f5aa5 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Wed, 30 Nov 2016 16:29:20 +0900 Subject: [PATCH 15/16] Fix failed to launch on Exception. Fix Failed to launch on exception happend when unhandled exception handler failed to set. Make catch a exception on failed but it goes to launching normally. If unhandled exception handler is not set, unhandled exception is not print out to dlog but print into journal log. Change-Id: I3679470a2fa8d750cfbb1f47fc705dcf3a69e53b --- Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index 28b0edf..ea31f8f 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -121,6 +121,15 @@ namespace Tizen.Runtime.Coreclr 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(); if (!string.IsNullOrEmpty(preloadDirectory)) -- 2.7.4 From ac952532bac864e145498a0cc724d84a67339ac0 Mon Sep 17 00:00:00 2001 From: "pius.lee" Date: Wed, 30 Nov 2016 18:22:11 +0900 Subject: [PATCH 16/16] Fix unused native image in application. Now launcher use Native image in application's bin, lib directory. --native option is added to dotnet-launcher. It must be use with --standalone. --native launch dll without managed launcher. But it can't launch ni.dll. Change-Id: Icf0ab0e9330ec1e94db5440e517e76710f1d81e1 --- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 12 ++++++++++++ NativeLauncher/launcher/main.cc | 18 ++++++++++++++++++ Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs | 11 ++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 509248d..cb9fcd0 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -277,6 +277,18 @@ int CoreRuntime::Launch(const char* root, const char* path, int argc, char* argv return 1; } + 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(); + } + } + if (FileNotExist(path)) { _ERR("File not exist : %s", path); diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index 3d574ec..314e719 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -38,12 +38,14 @@ static std::string VersionOption("--version"); static std::string StandaloneOption("--standalone"); +static std::string NativeOption("--native"); int main(int argc, char *argv[]) { int i; bool standalone = false; const char* standalonePath = nullptr; + bool nativeOnly = false; std::vector vargs; @@ -66,12 +68,22 @@ int main(int argc, char *argv[]) i++; standalonePath = argv[i]; } + else if (NativeOption.compare(argv[i]) == 0) + { + nativeOnly = true; + } else { vargs.push_back(argv[i]); } } + if (!standalone && nativeOnly) + { + fprintf(stderr, "\"--native\" option must be use with \"--standalone\"\n"); + return 1; + } + using tizen::runtime::LauncherInterface; using tizen::runtime::Launchpad; using tizen::runtime::AppInfo; @@ -120,6 +132,12 @@ int main(int argc, char *argv[]) return 1; } + if (!nativeOnly && runtime->RunManagedLauncher() != 0) + { + _ERR("Failed to run managed launcher"); + return 1; + } + int args_len = vargs.size(); char** args = &vargs[0]; if (runtime->Launch(approot.c_str(), standalonePath, args_len, args)) diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs index ea31f8f..26b8868 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs @@ -165,7 +165,16 @@ namespace Tizen.Runtime.Coreclr FileInfo f = new FileInfo(dllPath); if (File.Exists(f.FullName)) { - Assembly asm = CurrentAssemblyLoaderContext.LoadFromAssemblyPath(f.FullName); + Assembly asm = null; + if (0 == string.Compare(f.FullName, f.FullName.Length - 7, ".ni", 0, 3, StringComparison.OrdinalIgnoreCase)) + { + asm = CurrentAssemblyLoaderContext.LoadFromNativeImagePath(f.FullName, null); + } + else + { + asm = CurrentAssemblyLoaderContext.LoadFromAssemblyPath(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}); -- 2.7.4