X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=NativeLauncher%2Flauncher%2Flib%2Fcore_runtime.cc;h=ba874aabfe212c89614996224e01cf8acc0477be;hb=546f3a3947b7e7c205a4799156bcd41bc5ae3c2e;hp=64cc96253ea7f03507fece82f50c6c532888ed37;hpb=c097e29a79d9340f6c8c33ef4ba8bc700b5684a9;p=platform%2Fcore%2Fdotnet%2Flauncher.git diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 64cc962..ba874aa 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -33,10 +33,11 @@ #include #include #include +#include -#include #include #include +#include #include @@ -57,6 +58,7 @@ static coreclr_shutdown_ptr shutdown = nullptr; static coreclr_create_delegate_ptr createDelegate = nullptr; static set_environment_variable_ptr setEnvironmentVariable = nullptr; static stop_profile_after_delay_ptr stopProfileAfterDelay = nullptr; +static set_switch_ptr setSwitch = nullptr; static void* __coreclrLib = nullptr; static void* __hostHandle = nullptr; static unsigned int __domainId = -1; @@ -141,61 +143,36 @@ static void registerSigHandler() } } -static bool storage_cb(int id, storage_type_e type, storage_state_e state, const char *path, void *user_data) -{ - int* tmp = (int*)user_data; - if (type == STORAGE_TYPE_INTERNAL) - { - *tmp = id; - return false; - } - - return true; -} - static void initEnvForSpecialFolder() { - int storageId; - int error; - char *path = NULL; - - error = storage_foreach_device_supported(storage_cb, &storageId); - if (error != STORAGE_ERROR_NONE) { - return; - } - - error = storage_get_directory(storageId, STORAGE_DIRECTORY_IMAGES, &path); - if (error == STORAGE_ERROR_NONE && path != NULL) { - setenv("XDG_PICTURES_DIR", const_cast(path), 1); - free(path); - path = NULL; + const char* path = NULL; + if (getenv("XDG_PICTURES_DIR") == NULL) { + path = tzplatform_getenv(TZ_USER_IMAGES); + if (path) { + setenv("XDG_PICTURES_DIR", path, 1); + } } - error = storage_get_directory(storageId, STORAGE_DIRECTORY_MUSIC, &path); - if (error == STORAGE_ERROR_NONE && path != NULL) { - setenv("XDG_MUSIC_DIR", const_cast(path), 1); - free(path); - path = NULL; + if (getenv("XDG_MUSIC_DIR") == NULL) { + path = tzplatform_getenv(TZ_USER_MUSIC); + if (path) { + setenv("XDG_MUSIC_DIR", path, 1); + } } - error = storage_get_directory(storageId, STORAGE_DIRECTORY_VIDEOS, &path); - if (error == STORAGE_ERROR_NONE && path != NULL) { - setenv("XDG_VIDEOS_DIR", const_cast(path), 1); - free(path); - path = NULL; + if (getenv("XDG_VIDEOS_DIR") == NULL) { + path = tzplatform_getenv(TZ_USER_VIDEOS); + if (path) { + setenv("XDG_VIDEOS_DIR", path, 1); + } } } -// terminate candidate process when language changed -// icu related data (CultureInfo, etc) should be recreated. -static void langChangedCB(keynode_t *key, void* data) -{ - _INFO("terminiate candidate process to update language."); - exit(0); -} - static void setLang() { + //To reduce search overhead of libicuuc.so.xx + setenv("CLR_ICU_VERSION_OVERRIDE", "build", 1); + char* lang = vconf_get_str(VCONFKEY_LANGSET); if (!lang) { _ERR("Fail to get language from vconf"); @@ -274,12 +251,15 @@ void preload() bool initializeCoreClr(PathManager* pm, const std::string& tpa) { + bool ncdbStartupHook = isNCDBStartupHookProvided(); + const char *propertyKeys[] = { "TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", "APP_NI_PATHS", "NATIVE_DLL_SEARCH_DIRECTORIES", - "AppDomainCompatSwitch" + "AppDomainCompatSwitch", + ncdbStartupHook ? "STARTUP_HOOKS" : "" // must be the last one }; const char *propertyValues[] = { @@ -287,14 +267,15 @@ bool initializeCoreClr(PathManager* pm, const std::string& tpa) pm->getAppPaths().c_str(), pm->getAppNIPaths().c_str(), pm->getNativeDllSearchingPaths().c_str(), - "UseLatestBehaviorWhenTFMNotSpecified" + "UseLatestBehaviorWhenTFMNotSpecified", + ncdbStartupHook ? getNCDBStartupHook() : "" // must be the last one }; std::string selfPath = readSelfPath(); int st = initializeClr(selfPath.c_str(), "TizenDotnetApp", - sizeof(propertyKeys) / sizeof(propertyKeys[0]), + sizeof(propertyKeys) / sizeof(propertyKeys[0]) - (ncdbStartupHook ? 0 : 1), propertyKeys, propertyValues, &__hostHandle, @@ -318,9 +299,6 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) return -1; } - // Intiailize ecore first (signal handlers, etc.) before runtime init. - ecore_init(); - // set language environment to support ICU setLang(); @@ -337,6 +315,7 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) // So, plugin initialize should be called before creating threads. if (initializePluginManager(appType) < 0) { _ERR("Failed to initialize PluginManager"); + return -1; } // checkInjection checks dotnet-launcher run mode @@ -354,10 +333,10 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) // See https://github.com/dotnet/coreclr/issues/6698 // // libunwind use following methods to unwind stack frame. - // UNW_ARM_METHOD_ALL 0xFF - // UNW_ARM_METHOD_DWARF 0x01 - // UNW_ARM_METHOD_FRAME 0x02 - // UNW_ARM_METHOD_EXIDX 0x04 + // UNW_ARM_METHOD_ALL 0xFF + // UNW_ARM_METHOD_DWARF 0x01 + // UNW_ARM_METHOD_FRAME 0x02 + // UNW_ARM_METHOD_EXIDX 0x04 putenv(const_cast("UNW_ARM_UNWIND_METHOD=6")); #endif // __arm__ @@ -372,6 +351,12 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) putenv(const_cast("COMPlus_UseDefaultBaseAddr=1")); #endif // USE_DEFAULT_BASE_ADDR + // Disable config cache to set environment after coreclr_initialize() + putenv(const_cast("COMPlus_DisableConfigCache=1")); + + // Set environment variable for System.Environment.SpecialFolder + initEnvForSpecialFolder(); + // read string from external file and set them to environment value. setEnvFromFile(); @@ -392,7 +377,10 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) __pm->addNativeDllSearchingPaths(pluginNativePaths, true); } - pluginHasLogControl(); + char* pluginExtraDllPaths = pluginGetExtraDllPath(); + if (pluginExtraDllPaths && pluginExtraDllPaths[0] != '\0') { + __pm->setExtraDllPaths(pluginExtraDllPaths); + } std::string libCoreclr(concatPath(__pm->getRuntimePath(), "libcoreclr.so")); @@ -421,12 +409,6 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) _INFO("libcoreclr dlopen and dlsym success"); - // Set environment for System.Environment.SpecialFolder - // Below function creates dbus connection by callging storage API. - // If dbus connection is created bofere fork(), forked process cannot use dbus. - // To avoid gdbus blocking issue, below function should be called after fork() - initEnvForSpecialFolder(); - std::string tpa; char* pluginTPA = pluginGetTPA(); if (pluginTPA && pluginTPA[0] != '\0') { @@ -440,6 +422,11 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) return -1; } + // VD has their own signal handler. + if (!pluginHasLogControl()) { + registerSigHandler(); + } + int st = createDelegate(__hostHandle, __domainId, "Tizen.Runtime", "Tizen.Runtime.Environment", "SetEnvironmentVariable", (void**)&setEnvironmentVariable); if (st < 0 || setEnvironmentVariable == nullptr) { _ERR("Create delegate for Tizen.Runtime.dll -> Tizen.Runtime.Environment -> SetEnvironmentVariable failed (0x%08x)", st); @@ -452,11 +439,13 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode) return -1; } - if (launchMode == LaunchMode::loader) { - // terminate candidate process if language is changed. - // CurrentCulture created for preloaded dlls should be updated. - vconf_notify_key_changed(VCONFKEY_LANGSET, langChangedCB, NULL); + st = createDelegate(__hostHandle, __domainId, "Tizen.Runtime", "Tizen.Runtime.AppSetting", "SetSwitch", (void**)&setSwitch); + if (st < 0 || setSwitch == nullptr) { + _ERR("Create delegate for Tizen.Runtime.dll -> Tizen.Runtime.AppSetting -> SetSwitch failed (0x%08x)", st); + return -1; + } + if (launchMode == LaunchMode::loader) { // preload libraries and manage dlls for optimizing startup time preload(); @@ -485,7 +474,7 @@ void CoreRuntime::finalize() checkOnTerminate = true; // workaround : to prevent crash while process terminate on profiling mode, - // kill process immediately. + // kill process immediately. // see https://github.com/dotnet/coreclr/issues/26687 if (__isProfileMode) { _INFO("shutdown process immediately."); @@ -534,11 +523,6 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i return -1; } - // VD has their own signal handler. - if (!pluginHasLogControl()) { - registerSigHandler(); - } - pluginSetAppInfo(appId, path); // temporal root path is overrided to real application root path @@ -559,25 +543,32 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i setEnvironmentVariable("COMPlus_MultiCoreJitProfile", multiCoreJitProfile); setEnvironmentVariable("COMPlus_MultiCoreJitMinNumCpus", "1"); - // stop profiling and write collected data after delay if env value is set. - char *env = getenv("CLR_MCJ_PROFILE_WRITE_DELAY"); - if (env != nullptr) { - int delay = std::atoi(env); - // To avoid undefined behavior by out-of-range input(atoi), set max delay value to 100. - if (delay > 0) { - if (delay > MAX_DELAY_SEC) delay = MAX_DELAY_SEC; - stopProfileAfterDelay(delay); - } - } - if (exist(multiCoreJitProfile)) { setEnvironmentVariable("COMPlus_MultiCoreJitNoProfileGather", "1"); + _INFO("MCJ playing start for %s", appId); + } else { + setEnvironmentVariable("COMPlus_MultiCoreJitNoProfileGather", "0"); + // stop profiling and write collected data after delay if env value is set. + char *env = getenv("CLR_MCJ_PROFILE_WRITE_DELAY"); + if (env != nullptr) { + int delay = std::atoi(env); + // To avoid undefined behavior by out-of-range input(atoi), set max delay value to 100. + if (delay > 0) { + if (delay > MAX_DELAY_SEC) delay = MAX_DELAY_SEC; + stopProfileAfterDelay(delay); + } + } + _INFO("MCJ recording start for %s", appId); } } free(localDataPath); } - vconf_ignore_key_changed(VCONFKEY_LANGSET, langChangedCB); + if (exist(__pm->getAppRootPath() + "/bin/" + DISABLE_IPV6_FILE)) { + setSwitch("System.Net.DisableIPv6", true); + } + + setSwitch("Switch.System.Diagnostics.StackTrace.ShowILOffsets", true); pluginBeforeExecute();