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
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) {
#include <dlfcn.h>
+#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();
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;
}
* --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