From 92d8fe2e5a122d3d499fb7186176c5df60a52d10 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Thu, 2 Nov 2017 20:01:51 +0300 Subject: [PATCH] Support hydra mode --- NativeLauncher/dotnet.loader | 1 + NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 51 +++++++++++++++-------- NativeLauncher/launcher/dotnet/dotnet_launcher.h | 1 + NativeLauncher/launcher/launcher.cc | 32 ++++++++++++-- NativeLauncher/launcher/launcher.h | 1 + NativeLauncher/launcher/main.cc | 17 ++++++++ 6 files changed, 81 insertions(+), 22 deletions(-) diff --git a/NativeLauncher/dotnet.loader b/NativeLauncher/dotnet.loader index eb17893..e04b914 100644 --- a/NativeLauncher/dotnet.loader +++ b/NativeLauncher/dotnet.loader @@ -13,3 +13,4 @@ EXTRA_ARRAY_VAL /usr/lib/ecore_imf/modules/wayland/v-1.16/libwltextinputm EXTRA_ARRAY_VAL /usr/lib/libdali-toolkit.so EXTRA_ARRAY_VAL /usr/lib/libcairo.so.2 EXTRA_ARRAY_VAL /usr/lib/libefl-assist.so.0 +HYDRA ON diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index 713ff0c..c13c406 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -296,7 +296,7 @@ CoreRuntime::~CoreRuntime() dispose(); } -int CoreRuntime::initialize(bool standalone) +int CoreRuntime::preinitialize(bool standalone) { // checkInjection checks dotnet-launcher run mode // At the moment, this mechanism is used only when the Memory Profiler is started. @@ -351,23 +351,6 @@ int CoreRuntime::initialize(bool standalone) return -1; } - if (__enableLogManager) { - if (initializeLogManager() < 0) { - _ERR("Failed to initnialize LogManager"); - return -1; - } - - if (redirectFD() < 0) { - _ERR("Failed to redirect FD"); - return -1; - } - - if (runLoggingThread() < 0) { - _ERR("Failed to create and run logging thread to redicrect log"); - return -1; - } - } - std::string libCoreclr(concatPath(getRuntimeDir(), "libcoreclr.so")); __coreclrLib = dlopen(libCoreclr.c_str(), RTLD_NOW | RTLD_LOCAL); @@ -397,6 +380,38 @@ int CoreRuntime::initialize(bool standalone) _INFO("libcoreclr dlopen and dlsym success"); + return 0; +} + +int CoreRuntime::initialize(bool standalone) +{ +#define __XSTR(x) #x +#define __STR(x) __XSTR(x) + +#ifdef NATIVE_LIB_DIR + __nativeLibDirectory = __STR(NATIVE_LIB_DIR); +#endif + +#undef __STR +#undef __XSTR + + if (__enableLogManager) { + if (initializeLogManager() < 0) { + _ERR("Failed to initnialize LogManager"); + return -1; + } + + if (redirectFD() < 0) { + _ERR("Failed to redirect FD"); + return -1; + } + + if (runLoggingThread() < 0) { + _ERR("Failed to create and run logging thread to redicrect log"); + return -1; + } + } + if (!standalone) pluginPreload(); diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index 704070b..88fb931 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -30,6 +30,7 @@ class CoreRuntime public: CoreRuntime(const char* mode); ~CoreRuntime(); + int preinitialize(bool standalone); int initialize(bool standalone); void dispose(); int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]); diff --git a/NativeLauncher/launcher/launcher.cc b/NativeLauncher/launcher/launcher.cc index e5a1f14..14a7d18 100644 --- a/NativeLauncher/launcher/launcher.cc +++ b/NativeLauncher/launcher/launcher.cc @@ -57,6 +57,7 @@ class LaunchpadAdapterImpl : public LaunchpadAdapter private: AppInfo appInfo; loader_lifecycle_callback_s callbacks; + hydra_lifecycle_callback_s hydraCallbacks; loader_adapter_s adapter; bool __isLaunched; std::string __launchPath; @@ -90,7 +91,7 @@ static Eina_Bool fdHandler(void *data, Ecore_Fd_Handler* handler) } } - return ECORE_CALLBACK_CANCEL; + return ECORE_CALLBACK_RENEW; } static void fdAdd(void *data, int fd, loader_receiver_cb receiver) @@ -214,6 +215,28 @@ int LaunchpadAdapterImpl::loaderMain(int argc, char* argv[]) return 0; }; + // Called before initial fork + hydraCallbacks.precreate = [](void* userData) { + WITH_SELF(userData) { + if (self->onPreCreate != nullptr) + self->onPreCreate(); + } + }; + + hydraCallbacks.create = [](void* userData) { + ecore_init(); + }; + + // Called after fork in candidate + hydraCallbacks.fork = [](void *userData) { + ecore_fork_reset(); + }; + + hydraCallbacks.terminate = [](void* userData) { + ecore_shutdown(); + return 0; + }; + adapter.loop_begin = [](void *data) { ecore_main_loop_begin(); }; @@ -224,9 +247,10 @@ int LaunchpadAdapterImpl::loaderMain(int argc, char* argv[]) adapter.add_fd = fdAdd; adapter.remove_fd = fdRemove; - _INFO("launchpad_loader_main is start"); - int r = launchpad_loader_main(argc, argv, &(this->callbacks), &(this->adapter), this); - _INFO("launchpad_loader_main is finished with [%d]", r); + _INFO("launchpad_hydra_main is start"); + int r = launchpad_hydra_main(argc, argv, &(this->hydraCallbacks), + &(this->callbacks), &(this->adapter), this); + _INFO("launchpad_hydra_main is finished with [%d]", r); return r; } diff --git a/NativeLauncher/launcher/launcher.h b/NativeLauncher/launcher/launcher.h index e48f318..7e1125a 100644 --- a/NativeLauncher/launcher/launcher.h +++ b/NativeLauncher/launcher/launcher.h @@ -35,6 +35,7 @@ class LaunchpadAdapter { public: virtual int loaderMain(int argc, char* argv[]) = 0; + std::function onPreCreate = nullptr; std::function onCreate = nullptr; std::function onLaunch = nullptr; std::function onTerminate = nullptr; diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index d710225..cac7e39 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -80,6 +80,11 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) snprintf(appId, 16, "%s", "dotnet-launcher"); appRoot = baseName(argv[1]); + if (runtime->preinitialize(true) != 0) { + _ERR("Failed to preinitialized"); + return 1; + } + if (runtime->initialize(true) != 0) { _ERR("Failed to initialize"); return 1; @@ -107,6 +112,11 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) } _INFO("AUL_APPID : %s", appId); + if (runtime->preinitialize(true) != 0) { + _ERR("Failed to preinitialized"); + return 1; + } + if (runtime->initialize(true) != 0) { _ERR("Failed to initialize"); return 1; @@ -124,6 +134,13 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) return 1; } } else { + Launchpad.onPreCreate = [&runtime]() { + if (runtime->preinitialize(false) != 0) + _ERR("Failed to preinitialized"); + else + _INFO("Success to preinitialized"); + }; + Launchpad.onCreate = [&runtime]() { if (runtime->initialize(false) != 0) _ERR("Failed to initialized"); -- 2.7.4