Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
To: cygwin@cygwin.com
Cc: cygwin-patches@cygwin.com
Subject: Re: RTLD_DEFAULT & RTLD_NEXT
Mail-Copies-To: never
Reply-To: sds@gnu.org
X-Attribution: Sam
X-Disclaimer: You should not expect anyone to agree with me.
From: Sam Steingold <sds@gnu.org>
In-Reply-To: <20040901094429.GY17670@cygbert.vinschen.de> (Corinna Vinschen's message of "Wed, 1 Sep 2004 11:44:29 +0200")
References: <u65704sup.fsf@gnu.org> <20040830143832.GE17670@cygbert.vinschen.de> <uisb018x4.fsf@gnu.org> <20040831083258.GA7517@cygbert.vinschen.de> <u1xhn1gaz.fsf@gnu.org> <20040831190826.GV17670@cygbert.vinschen.de> <uoekrxfqx.fsf@gnu.org> <20040901094429.GY17670@cygbert.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com, cygwin-patches@cygwin.com
Date: Tue, 07 Sep 2004 16:52:46 -0400
Message-ID: <uoekhx0m9.fsf@gnu.org>
User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (windows-nt)
MIME-Version: 1.0
Content-Type: text/plain

the (C) assignment is in the mail.

2004-08-31  Sam Steingold  <sds@gnu.org>

	* dlfcn.cc (dlsym): Handle RTLD_DEFAULT using EnumProcessModules().
	* include/dlfcn.h (RTLD_DEFAULT): Define to NULL.


-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Don't use force -- get a bigger hammer.


Index: src/winsup/cygwin/include/dlfcn.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/dlfcn.h,v
retrieving revision 1.2
diff -u -w -r1.2 dlfcn.h
--- src/winsup/cygwin/include/dlfcn.h	11 Sep 2001 20:01:01 -0000	1.2
+++ src/winsup/cygwin/include/dlfcn.h	7 Sep 2004 20:47:33 -0000
@@ -28,6 +28,7 @@
 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 */
Index: src/winsup/cygwin/dlfcn.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dlfcn.cc,v
retrieving revision 1.24
diff -u -w -r1.24 dlfcn.cc
--- src/winsup/cygwin/dlfcn.cc	3 Sep 2004 01:53:11 -0000	1.24
+++ src/winsup/cygwin/dlfcn.cc	7 Sep 2004 20:47:33 -0000
@@ -112,7 +112,27 @@
 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: src/winsup/cygwin/autoload.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/autoload.cc,v
retrieving revision 1.87
diff -u -w -r1.87 autoload.cc
--- src/winsup/cygwin/autoload.cc	3 Sep 2004 01:32:02 -0000	1.87
+++ src/winsup/cygwin/autoload.cc	7 Sep 2004 20:47:33 -0000
@@ -309,6 +309,7 @@
 LoadDLLfunc (DeregisterEventSource, 4, advapi32)
 LoadDLLfunc (DuplicateToken, 12, advapi32)
 LoadDLLfuncEx (DuplicateTokenEx, 24, advapi32, 1)
+LoadDLLfuncEx (EnumProcessModules, 16, psapi, 1)
 LoadDLLfunc (EqualSid, 8, advapi32)
 LoadDLLfunc (FindFirstFreeAce, 8, advapi32)
 LoadDLLfunc (GetAce, 12, advapi32)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

