>Здравствуйте!
>Есть программка, она грузит плагин. (dlopen)
>Можно ли сделать так, чтобы плагин запускал функцию из основной программы? Например так:
$cat t.c
#include <dlfcn.h>
#include <link.h>
void bar(void)
{
printf(".so could call the main binary\n");
}
void
main(void)
{
void *handle;
void (*fptr)(void);
handle = dlopen("./library.so", RTLD_LAZY);
fptr = (void (*)(void))dlsym(handle, "foo");
(*fptr)();
}
$cat library.c
#include <dlfcn.h>
#include <link.h>
void
foo(void)
{
void *handle;
void (*fptr)(void);
handle = dlopen((char*)0, RTLD_LAZY);
fptr = (void (*)(void))dlsym(handle, "bar");
(*fptr)();
}
а вот абзац из описания dlopen()
If the value of pathname is 0, dlopen() provides a handle on
a global symbol object. This object provides access to the
symbols from an ordered set of objects consisting of the
original program image file, together with any dependencies
loaded at program startup, and any objects that were loaded
using dlopen() together with the RTLD_GLOBAL flag. As the
latter set of objects can change during process execution,
the set identified by handle can also change dynamically.