From: Mikhail Kurinnoi Date: Fri, 29 Jul 2022 15:30:26 +0000 (+0300) Subject: Add NCDB startup hook support. X-Git-Tag: submit/tizen/20220825.083931~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=667e87b9e2fd3879ba6100b7fde9295408f9c337;p=platform%2Fcore%2Fdotnet%2Flauncher.git Add NCDB startup hook support. --- diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 1f49526..927b213 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -314,4 +314,16 @@ int pkgmgrMDFilterForeach(pkgmgrinfo_appinfo_metadata_filter_h handle, */ void printHWClockLog(const char* format, ...); +/** + * @brief Return NCDB startup hook + * @return NCDB startup hook + */ +const char* getNCDBStartupHook(); + +/** + * @brief Check is NCDB startup hook provided in DOTNET_STARTUP_HOOKS env + * @return `true` if provided, otherwise `false` + */ +bool isNCDBStartupHookProvided(); + #endif /* __UTILS_H__ */ diff --git a/NativeLauncher/launcher/exec/corerun.cc b/NativeLauncher/launcher/exec/corerun.cc index 802b9a0..939d543 100644 --- a/NativeLauncher/launcher/exec/corerun.cc +++ b/NativeLauncher/launcher/exec/corerun.cc @@ -191,12 +191,15 @@ int main(int argc, const char* argv[]) { return -1; } + bool ncdbStartupHook = isNCDBStartupHookProvided(); + const char* propertyKeys[] = { "TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", "APP_NI_PATHS", "NATIVE_DLL_SEARCH_DIRECTORIES", "System.Globalization.Invariant", + ncdbStartupHook ? "STARTUP_HOOKS" : "" // must be the last one }; const char* propertyValues[] = { tpaList.c_str(), @@ -204,6 +207,7 @@ int main(int argc, const char* argv[]) { appPath.c_str(), nativeDllSearchDirs.c_str(), globalizationInvariant ? "true" : "false", + ncdbStartupHook ? getNCDBStartupHook() : "" // must be the last one }; void* hostHandle; @@ -212,7 +216,7 @@ int main(int argc, const char* argv[]) { int st = initializeCoreCLR( currentExeAbsolutePath.c_str(), "dotnet", - sizeof(propertyKeys) / sizeof(propertyKeys[0]), + sizeof(propertyKeys) / sizeof(propertyKeys[0]) - (ncdbStartupHook ? 0 : 1), propertyKeys, propertyValues, &hostHandle, diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 2f1d7d6..4fb9562 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -277,12 +277,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[] = { @@ -290,14 +293,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, diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 64f4428..ff5c5bd 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -815,3 +815,41 @@ void printHWClockLog(const char* format, ...) prctl(PR_TASK_PERF_USER_TRACE, buf, strlen(buf)); } +const char* getNCDBStartupHook() +{ + return "/home/owner/share/tmp/sdk_tools/netcoredbg/ncdbhook.dll"; +} + +bool isNCDBStartupHookProvided() +{ + char *env = nullptr; + env = getenv("DOTNET_STARTUP_HOOKS"); + if (env == nullptr) + return false; + + // Note, `DOTNET_STARTUP_HOOKS` env could provide list of dlls with ':' delimiter, + // for example: "/path1/name1.dll:/path2/name2.dll" + while (*env != '\0') + { + const char *ncdbCur = getNCDBStartupHook(); + while (*ncdbCur != '\0' && *env != '\0' && *env != ':') + { + if (*ncdbCur != *env) + break; + + ncdbCur++; + env++; + + if (*ncdbCur == '\0' && (*env == '\0' || *env == ':')) + return true; + } + while (*env != '\0' && *env != ':') + { + env++; + } + if (*env == ':') + env++; + } + + return false; +}