OSDN Git Service

* autoload.cc (EnumProcessModules): Add.
authorcorinna <corinna>
Tue, 14 Sep 2004 08:29:07 +0000 (08:29 +0000)
committercorinna <corinna>
Tue, 14 Sep 2004 08:29:07 +0000 (08:29 +0000)
* dlfcn.cc (dlsym): Handle RTLD_DEFAULT using EnumProcessModules().
* include/dlfcn.h (RTLD_DEFAULT): Define to NULL.

winsup/cygwin/ChangeLog
winsup/cygwin/autoload.cc
winsup/cygwin/dlfcn.cc
winsup/cygwin/include/dlfcn.h

index c22468e..c7f69e2 100644 (file)
@@ -1,3 +1,9 @@
+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
index e7de842..a50fcb2 100644 (file)
@@ -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)
index e57bb63..3934428 100644 (file)
@@ -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);
index 5eaa706..2cf88e2 100644 (file)
@@ -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 */