I have a working program that loads plugins from dlopen.
New requirement: at some point in the code, a pointer is assigned to me, and I need to check whether this pointer points to the code or the static data of the plugin.
bool is_pointer_into_plugin(void *p, void *handle);
Equivalently, I need to get a plugin that points to a pointer, if any. I also need to know if the pointer points to the main program code or static data (and ideally distinguish between read-only and read-write areas).
void *handle plugin_containing_pointer(void *p);
Equivalently, I need to be able to get the size (address and size) on which the plugin is displayed. I also need this information for the main program.
How can I implement is_pointer_into_plugin, or plugin_containing_pointer, or something equivalent?
I can change the call dlopenif necessary. The search should be as fast as possible, the load time code should not be fast. Running plugins in separate processes and sharing data through shared memory is not an option.
My program runs on Linux (and Windows, but this is another question ). Future portability to other Unix systems (at least on OSX) would be a plus.
source
share