Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: it seems there is no library enumeration mechanism in Boost.DLL #64

Open
fsmoke opened this issue Jan 16, 2023 · 0 comments

Comments

@fsmoke
Copy link

fsmoke commented Jan 16, 2023

My suggestion - add routins for enumeration shared libraries already loaded by current process

For example we have host app

  1. host.exe(or just bin on nix)
  2. host.exe dynamically loads some plugin.dll/so
  3. 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)
  4. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant