#include <cstdlib>
#include <cstring>
+#include <dlfcn.h>
+
static int injectLibrary(const char path[])
{
- return 0;
+ typedef int inject_func();
+
+ int res = -1;
+ void *lib = nullptr;
+ inject_func *inject = nullptr;
+ const char *inject_sym = "dotnet_launcher_inject";
+
+ _INFO("Inject %s library", path);
+
+ // FIXME: remove RTLD_GLOBAL?
+ lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+ if (lib == nullptr) {
+ _ERR("%s", dlerror());
+ goto ret;
+ }
+
+ inject = reinterpret_cast<inject_func*>(dlsym(lib, inject_sym));
+ if (inject == nullptr) {
+ _ERR("%s is not found in the %s", inject_sym, path);
+ goto ret;
+ }
+
+ res = inject();
+
+ret:
+ return res;
}
int doInjection()