diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2004-09-14 08:29:12 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2004-09-14 08:29:12 +0000 |
commit | 599b41c4ec64b2ee352db2c81ce77185ffd49923 (patch) | |
tree | cff55bb44300f8a58a44e6cc408b8f4e06a4e5c3 /winsup/cygwin/dlfcn.cc | |
parent | fc3a42749f79e8e4576d1ac915a3a9eb8452b4c1 (diff) | |
download | cygnal-599b41c4ec64b2ee352db2c81ce77185ffd49923.tar.gz cygnal-599b41c4ec64b2ee352db2c81ce77185ffd49923.tar.bz2 cygnal-599b41c4ec64b2ee352db2c81ce77185ffd49923.zip |
* autoload.cc (EnumProcessModules): Add.
* dlfcn.cc (dlsym): Handle RTLD_DEFAULT using EnumProcessModules().
* include/dlfcn.h (RTLD_DEFAULT): Define to NULL.
Diffstat (limited to 'winsup/cygwin/dlfcn.cc')
-rw-r--r-- | winsup/cygwin/dlfcn.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc index e57bb6328..3934428ca 100644 --- a/winsup/cygwin/dlfcn.cc +++ b/winsup/cygwin/dlfcn.cc @@ -9,6 +9,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ #include "winsup.h" +#include <psapi.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -112,7 +113,27 @@ dlopen (const char *name, int) void * dlsym (void *handle, const char *name) { - void *ret = (void *) GetProcAddress ((HMODULE) handle, name); + void *ret = NULL; + if (handle == RTLD_DEFAULT) + { /* search all modules */ + HANDLE cur_proc = GetCurrentProcess (); + HMODULE *modules; + DWORD needed, i; + if (!EnumProcessModules (cur_proc, NULL, 0, &needed)) + { + dlsym_fail: + set_dl_error ("dlsym"); + return NULL; + } + modules = (HMODULE*) alloca (needed); + if (!EnumProcessModules (cur_proc, modules, needed, &needed)) + goto dlsym_fail; + for (i = 0; i < needed / sizeof (HMODULE); i++) + if ((ret = (void *) GetProcAddress (modules[i], name))) + break; + } + else + ret = (void *) GetProcAddress ((HMODULE)handle, name); if (!ret) set_dl_error ("dlsym"); debug_printf ("ret %p", ret); |