-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Labels
Description
My suggestion - add routins for enumeration shared libraries already loaded by current process
For example we have host app
- host.exe(or just bin on nix)
- host.exe dynamically loads some plugin.dll/so
- plugin.dll/so loads impl.dll/so automatically by lnker's import table(before run host(for example on linux) we set LD_LIBRARY_PATH to directory with impl.so to choose actual implementation)
- now from host.exe i want to set some global variable inside impl.so(for example some global interfaces used by impl) - but i dont know which of impl.so was loaded inside my process, i can not determine path of loaded dll/so - so i can't import symbol
i wrote some platform dependent code to demonstrate root of my suggestion
std::filesystem::path impl_dll_path;
#ifdef BOOST_OS_LINUX
auto self_handle = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL);
for (auto link_map = static_cast<const struct link_map*>(self_handle);
link_map; link_map = link_map->l_next)
{
std::string dll_name(link_map->l_name);
if (dll_name.ends_with("libimpl.so"))
{
impl_dll_path = dll_name;
break;
}
}
#endif
Overall i think enumeration of loaded libraries will be usefull in many other cases too
PS
For Windows OS this article will be useful obviosly https://learn.microsoft.com/en-us/windows/win32/psapi/enumerating-all-modules-for-a-process
Reactions are currently unavailable