I have a working program that loads plugins with dlopen
.
New requirement: at some point in the code, I'm given a pointer, and I need to test whether this pointer points into the code or static data of a plugin.
bool is_pointer_into_plugin(void *p, void *handle);
Equivalently, I need to retrieve the plugin into which a pointer points, if any. I also need to know if the pointer points into the main program's 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 retrieve the extent (address and size) at which a plugin is mapped. 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 to dlopen
if necessary. The lookup should be reasonably fast as possible, the load-time code doesn't need to be fast. Running the plugins in separate processes and communicating through shared memory is not an option.
My program runs under Linux (and Windows, but that's another question). Future portability to other unix systems (at least to OSX) would be a plus.