2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 static int injectLibrary(const char path[])
26 typedef int inject_func();
30 inject_func *inject = nullptr;
31 const char *inject_sym = "dotnet_launcher_inject";
33 _INFO("Inject %s library", path);
35 // Current implementation of heaptrack CLR profiler requires RTLD_GLOBAL
36 lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
38 _ERR("%s", dlerror());
42 inject = reinterpret_cast<inject_func*>(dlsym(lib, inject_sym));
43 if (inject == nullptr) {
44 _ERR("%s is not found in the %s", inject_sym, path);
56 char* injectableLibs = nullptr;
57 const char *delim = ", ";
59 char *saveptr = nullptr;
61 env = getenv("DOTNET_LAUNCHER_INJECT");
67 _INFO("##### Perform injection #########");
69 injectableLibs = strdup(env);
70 if (injectableLibs == nullptr) {
71 _ERR("Fail to allocate memory for injectable library paths\n");
76 lib = strtok_r(injectableLibs, delim, &saveptr);
77 for(; lib != nullptr; lib = strtok_r(nullptr, delim, &saveptr)) {
78 if (injectLibrary(lib) != 0) {
85 _INFO("##### Injection finished #########");
87 _INFO("##### Injection failed #########");