From ad01b0b89cbed87802b33c3320179eeb3d2a5f96 Mon Sep 17 00:00:00 2001 From: Mikhail Kurinnoi Date: Mon, 3 Jun 2019 15:18:47 +0300 Subject: [PATCH] Hardcode injection lib path. Fix https://github.sec.samsung.net/dotnet/dotnet-launcher/issues/59 --- NativeLauncher/dotnet.debugger | 1 - NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 3 +- NativeLauncher/launcher/injection.cc | 41 ++++++++--------------- README.md | 8 ----- 4 files changed, 15 insertions(+), 38 deletions(-) diff --git a/NativeLauncher/dotnet.debugger b/NativeLauncher/dotnet.debugger index fea3b4a..22338b2 100644 --- a/NativeLauncher/dotnet.debugger +++ b/NativeLauncher/dotnet.debugger @@ -32,7 +32,6 @@ DEFAULT_OPT /home/owner/share/tmp/sdk_tools/heaptrack/heaptrack_interpret DEFAULT_OPT -o DEFAULT_OPT /home/owner/share/tmp/sdk_tools/profctl/profctl_heaptrack.log DEFAULT_OPT -E -DEFAULT_OPT DOTNET_LAUNCHER_INJECT=/home/owner/share/tmp/sdk_tools/heaptrack/libheaptrack_inject.so DEFAULT_OPT DUMP_HEAPTRACK_OUTPUT=/home/owner/share/tmp/sdk_tools/heaptrack/heaptrack_fifo DEFAULT_OPT CORECLR_PROFILER={C7BAD323-25F0-4C0B-B354-566390B215CA} DEFAULT_OPT CORECLR_PROFILER_PATH=/home/owner/share/tmp/sdk_tools/heaptrack/libprofiler.so diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index b76f54a..48252e8 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -291,8 +291,7 @@ CoreRuntime::~CoreRuntime() int CoreRuntime::initialize(bool standalone) { - // checkInjection checks dotnet-launcher run mode, - // if it contains DOTNET_LAUNCHER_INJECT variable, it injects library. + // checkInjection checks dotnet-launcher run mode // At the moment, this mechanism is used only when the Memory Profiler is started. int res = checkInjection(); if (res != 0) { diff --git a/NativeLauncher/launcher/injection.cc b/NativeLauncher/launcher/injection.cc index 3efd3a9..819af59 100644 --- a/NativeLauncher/launcher/injection.cc +++ b/NativeLauncher/launcher/injection.cc @@ -21,6 +21,10 @@ #include +#define HT_PATH "/home/owner/share/tmp/sdk_tools/heaptrack/" +#define HT_LIB_PATH HT_PATH "libprofiler.so" +#define HT_INJECTION_LIB_PATH HT_PATH "libheaptrack_inject.so" + static int injectLibrary(const char path[]) { typedef int inject_func(); @@ -51,42 +55,25 @@ static int injectLibrary(const char path[]) int checkInjection() { - int res = -1; char *env = nullptr; - char* injectableLibs = nullptr; - const char *delim = ", "; - char *lib = nullptr; - char *saveptr = nullptr; - env = getenv("DOTNET_LAUNCHER_INJECT"); + env = getenv("CORECLR_PROFILER_PATH"); if (env == nullptr) { - res = 0; - return res; + return 0; } - _INFO("##### Perform injection #########"); - - injectableLibs = strdup(env); - if (injectableLibs == nullptr) { - _ERR("Fail to allocate memory for injectable library paths\n"); - return res; + // At the moment, this mechanism is used only when the Memory Profiler is started. + if (strcmp(env, HT_LIB_PATH) != 0) { + return 0; } - res = 0; - lib = strtok_r(injectableLibs, delim, &saveptr); - for(; lib != nullptr; lib = strtok_r(nullptr, delim, &saveptr)) { - if (injectLibrary(lib) != 0) { - res = -1; - break; - } - } + _INFO("##### Perform injection #########"); - if (res == 0) { - _INFO("##### Injection finished #########"); - } else { + if (injectLibrary(HT_INJECTION_LIB_PATH) != 0) { _INFO("##### Injection failed #########"); + return -1; } - free(injectableLibs); - return res; + _INFO("##### Injection finished #########"); + return 0; } diff --git a/README.md b/README.md index 1ac01f9..e85863e 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,6 @@ dotnet-launcher [options...] [args...] * --standalone [assembly path] Run assembly with the current user environment. -#### environment - -* DOTNET_LAUNCHER_INJECT - A list of additional libraries to be loaded with `dlopen()` and call to - `int dotnet_launcher_inject()` initialization hook. If hook returns non-zero - status initialization will be failed. The items of the list can be separated - by spaces or colons, and there is no support for escaping either separator. - ---- ### Anatomy -- 2.7.4