enumerating loaded modules on Cygwin
Jeremy Drake
cygwin@jdrake.com
Sun Apr 27 21:58:04 GMT 2025
I was asked an interesting question on a github issue about rust
backtraces: is there an API in Cygwin to get a list of loaded modules? I
know the info is there in the dlls list, but I don't see an API to get at
it.
The question was in regards to whether rust should be using toolhelp32 on
Cygwin as it does on Windows to get a list of modules, load addresses, and
sizes to then use to identify from which module addresses in a backtrace
are from. It appears the general non-Windows case uses dl_iterate_phdr to
do this, but it also appears that this function is pretty ELF-specific.
It feels like most of the data could be filled out from Windows APIs, but
I'm not sure it makes sense to.
I recommended to them to use cygwin_conv_path(CCP_WIN_W_TO_POSIX, ...) on
the szExePath rather than WideCharToMultiByte(CP_UTF8), or to pass the
hModule to dlinfo to get the name, or to inspect /proc/self/maps (which
the non-Windows path also uses in concert with dl_iterate_phdr).
More information about the Cygwin
mailing list