Implement injection logic with injectLibrary() stub
authorAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Thu, 13 Sep 2018 18:37:25 +0000 (21:37 +0300)
committerAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Tue, 25 Sep 2018 17:16:14 +0000 (20:16 +0300)
NativeLauncher/CMakeLists.txt
NativeLauncher/launcher/injection.cc [new file with mode: 0644]
NativeLauncher/launcher/injection.h [new file with mode: 0644]
NativeLauncher/launcher/main.cc
README.md

index 93cd551..e9ddfc7 100644 (file)
@@ -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 (file)
index 0000000..6aeaa61
--- /dev/null
@@ -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 <cstdlib>
+#include <cstring>
+
+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 (file)
index 0000000..3a08992
--- /dev/null
@@ -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__
index d1e3ce4..c11c423 100644 (file)
@@ -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");
 }
-
index e85863e..1ac01f9 100644 (file)
--- 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