From: Aleksei Vereshchagin Date: Thu, 13 Sep 2018 18:37:25 +0000 (+0300) Subject: Implement injection logic with injectLibrary() stub X-Git-Tag: submit/tizen/20181001.123900~2^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b73905c1c5c1cc6746c5246433e95433754a8c3f;p=platform%2Fcore%2Fdotnet%2Flauncher.git Implement injection logic with injectLibrary() stub --- diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 93cd551..e9ddfc7 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -78,6 +78,7 @@ TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER_UTIL} ${${PROJECT_NAME}_LDFLAGS}) SET(DOTNET_LAUNCHER "dotnet-launcher") SET(${DOTNET_LAUNCHER}_SOURCE_FILES launcher/main.cc + launcher/injection.cc launcher/launcher.cc launcher/dotnet/dotnet_launcher.cc ) @@ -139,4 +140,3 @@ INSTALL(FILES inc/coreclr_host.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES inc/dotnet_launcher_plugin.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES installer-plugin/ni_common.h DESTINATION ${INCLUDEDIR}) INSTALL(FILES ../dotnet-launcher.pc DESTINATION ${LIBDIR}/pkgconfig) - diff --git a/NativeLauncher/launcher/injection.cc b/NativeLauncher/launcher/injection.cc new file mode 100644 index 0000000..6aeaa61 --- /dev/null +++ b/NativeLauncher/launcher/injection.cc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "log.h" + +#include +#include + +static int injectLibrary(const char path[]) +{ + return 0; +} + +int doInjection() +{ + int res = -1; + char *env = nullptr; + char* injectableLibs = nullptr; + const char *delim = ", "; + char *lib = nullptr; + + env = getenv("DOTNET_LAUNCHER_INJECT"); + if (env == nullptr) { + res = 0; + goto ret; + } + + _INFO("##### Perform injection #########"); + + injectableLibs = strdup(env); + if (injectableLibs == nullptr) { + _ERR("Fail to allocate memory for injectable library paths\n"); + goto ret; + } + + res = 0; + lib = strtok(injectableLibs, delim); + for(; lib != nullptr; lib = strtok(nullptr, delim)) { + if (injectLibrary(lib) != 0) { + res = -1; + break; + } + } + + if (res == 0) { + _INFO("##### Injection finished #########"); + } else { + _INFO("##### Injection failed #########"); + } + +ret: + free(injectableLibs); + + return res; +} diff --git a/NativeLauncher/launcher/injection.h b/NativeLauncher/launcher/injection.h new file mode 100644 index 0000000..3a08992 --- /dev/null +++ b/NativeLauncher/launcher/injection.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __INJETION_INTERFACE_H__ +#define __INJETION_INTERFACE_H__ + +int doInjection(); + +#endif // __INJETION_INTERFACE_H__ diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index d1e3ce4..c11c423 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "injection.h" #include "dotnet/dotnet_launcher.h" #include "utils.h" #include "log.h" @@ -151,6 +152,10 @@ extern "C" int realMain(int argc, char *argv[], const char* mode) int main(int argc, char *argv[]) { + int res = doInjection(); + if (res != 0) { + return 1; + } + return realMain(argc, argv, "default"); } - diff --git a/README.md b/README.md index e85863e..1ac01f9 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ 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