diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c22468e42..c7f69e242 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2004-09-14 Sam Steingold + + * autoload.cc (EnumProcessModules): Add. + * dlfcn.cc (dlsym): Handle RTLD_DEFAULT using EnumProcessModules(). + * include/dlfcn.h (RTLD_DEFAULT): Define to NULL. + 2004-09-13 Christopher Faylor * fork.cc (slow_pid_reuse): Temporarily double the number of pids held diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index e7de84225..a50fcb243 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -391,6 +391,7 @@ LoadDLLfuncEx (RtlInitUnicodeString, 8, ntdll, 1) LoadDLLfuncEx (RtlNtStatusToDosError, 4, ntdll, 1) LoadDLLfuncEx (RtlIsDosDeviceName_U, 4, ntdll, 1) +LoadDLLfuncEx (EnumProcessModules, 16, psapi, 1) LoadDLLfuncEx (GetProcessMemoryInfo, 12, psapi, 1) LoadDLLfuncEx (LsaDeregisterLogonProcess, 4, secur32, 1) 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 #include #include #include @@ -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); diff --git a/winsup/cygwin/include/dlfcn.h b/winsup/cygwin/include/dlfcn.h index 5eaa7061e..2cf88e2d3 100644 --- a/winsup/cygwin/include/dlfcn.h +++ b/winsup/cygwin/include/dlfcn.h @@ -28,6 +28,7 @@ extern char *dlerror (void); extern void dlfork (int); /* following doesn't exist in Win32 API .... */ +#define RTLD_DEFAULT NULL /* valid values for mode argument to dlopen */ #define RTLD_LAZY 1 /* lazy function call binding */