diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2017-03-06 18:30:45 +0000 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2017-03-08 17:49:08 +0000 |
commit | c8432a01c8401c121940c806a9d868c4adc4cefd (patch) | |
tree | 1bdee377ee8aa55d3267e2c749b6ac0a732fa3a2 /winsup/cygwin/dlfcn.cc | |
parent | 51a993c266581ba41f1622abd274d9848a37cf1d (diff) | |
download | cygnal-c8432a01c8401c121940c806a9d868c4adc4cefd.tar.gz cygnal-c8432a01c8401c121940c806a9d868c4adc4cefd.tar.bz2 cygnal-c8432a01c8401c121940c806a9d868c4adc4cefd.zip |
Implement dladdr() (partially)
Note that this always returns with dli_sname and dli_saddr set to NULL,
indicating no symbol matching addr could be found.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Diffstat (limited to 'winsup/cygwin/dlfcn.cc')
-rw-r--r-- | winsup/cygwin/dlfcn.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc index 159d4fe88..9959ff752 100644 --- a/winsup/cygwin/dlfcn.cc +++ b/winsup/cygwin/dlfcn.cc @@ -386,3 +386,37 @@ dlerror () } return res; } + +extern "C" int +dladdr (const void *addr, Dl_info *info) +{ + HMODULE hModule; + BOOL ret = GetModuleHandleEx (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + (LPCSTR) addr, + &hModule); + if (!ret) + return 0; + + /* Module handle happens to be equal to it's base load address. */ + info->dli_fbase = hModule; + + /* Get the module filename. This pathname may be in short-, long- or //?/ + format, depending on how it was specified when loaded, but we assume this + is always an absolute pathname. */ + WCHAR fname[MAX_PATH]; + DWORD length = GetModuleFileNameW (hModule, fname, MAX_PATH); + if ((length == 0) || (length == MAX_PATH)) + return 0; + + /* Convert to a cygwin pathname */ + ssize_t conv = cygwin_conv_path (CCP_WIN_W_TO_POSIX | CCP_ABSOLUTE, fname, + info->dli_fname, MAX_PATH); + if (conv) + return 0; + + /* Always indicate no symbol matching addr could be found. */ + info->dli_sname = NULL; + info->dli_saddr = NULL; + + return 1; +} |