Add NCDB startup hook support.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Fri, 29 Jul 2022 15:30:26 +0000 (18:30 +0300)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Mon, 1 Aug 2022 13:54:50 +0000 (16:54 +0300)
NativeLauncher/inc/utils.h
NativeLauncher/launcher/exec/corerun.cc
NativeLauncher/launcher/lib/core_runtime.cc
NativeLauncher/util/utils.cc

index 1f49526..927b213 100644 (file)
@@ -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__ */
index 802b9a0..939d543 100644 (file)
@@ -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,
index 2f1d7d6..4fb9562 100644 (file)
@@ -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,
index 64f4428..ff5c5bd 100644 (file)
@@ -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;
+}