* dlfcn.cc (dlsym): Handle RTLD_DEFAULT using EnumProcessModules().
* include/dlfcn.h (RTLD_DEFAULT): Define to NULL.
+2004-09-14 Sam Steingold <sds@gnu.org>
+
+ * 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 <cgf@timesys.com>
* fork.cc (slow_pid_reuse): Temporarily double the number of pids held
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)
details. */
#include "winsup.h"
+#include <psapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
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);
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 */