summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2001-05-03 09:35:08 +0000
committerCorinna Vinschen <corinna@vinschen.de>2001-05-03 09:35:08 +0000
commita6a0193b2fe6f83c7c0970afd5afecf28fba5595 (patch)
tree909bd43eb5c04aab1d3246d390ea4372bc01800b /winsup/cygwin
parentb09e3cf8fdb7927bc14af200b418841ebbae070d (diff)
downloadcygnal-a6a0193b2fe6f83c7c0970afd5afecf28fba5595.tar.gz
cygnal-a6a0193b2fe6f83c7c0970afd5afecf28fba5595.tar.bz2
cygnal-a6a0193b2fe6f83c7c0970afd5afecf28fba5595.zip
* autoload.cc: Use new definition of LoadDLLinitfunc throughout.
Redefine wrapper for wsock32.dll and ws2_32.dll. (std_dll_init): New function. * autoload.h: Rename LoadDLLinitfunc to LoadDLLinitfuncdef. Add new defines LoadDLLinitfunc and LoadDLLstdfunc. * net.cc (wsock_init): Add guard variable handling. Take care to call WSAStartup only once. Load WSAStartup without using autoload wrapper to eliminate recursion. Eliminate FIONBIO and srandom stuff.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog12
-rw-r--r--winsup/cygwin/autoload.cc205
-rw-r--r--winsup/cygwin/autoload.h10
-rw-r--r--winsup/cygwin/net.cc49
4 files changed, 72 insertions, 204 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 484c3cbe1..5a63b823d 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,15 @@
+Wed May 2 20:18:00 2001 Corinna Vinschen <corinna@vinschen.de>
+
+ * autoload.cc: Use new definition of LoadDLLinitfunc throughout.
+ Redefine wrapper for wsock32.dll and ws2_32.dll.
+ (std_dll_init): New function.
+ * autoload.h: Rename LoadDLLinitfunc to LoadDLLinitfuncdef.
+ Add new defines LoadDLLinitfunc and LoadDLLstdfunc.
+ * net.cc (wsock_init): Add guard variable handling. Take care
+ to call WSAStartup only once. Load WSAStartup without using
+ autoload wrapper to eliminate recursion. Eliminate FIONBIO
+ and srandom stuff.
+
Tue May 1 01:26:15 2001 Christopher Faylor <cgf@cygnus.com>
* path.cc (mount_info::conv_to_win32_path): More path tweaking.
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index 4555d786f..633d91a51 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -65,10 +65,10 @@ gotit:\n\
jmp *%eax\n\
");
-LoadDLLinitfunc (advapi32)
+int
+std_dll_init (HANDLE &dll_handle, const char *dll_name, LONG &here)
{
HANDLE h;
- static NO_COPY LONG here = -1L;
while (InterlockedIncrement (&here))
{
@@ -76,211 +76,40 @@ LoadDLLinitfunc (advapi32)
Sleep (0);
}
- if (advapi32_handle)
+ if (dll_handle)
/* nothing to do */;
- else if ((h = LoadLibrary ("advapi32.dll")) != NULL)
- advapi32_handle = h;
- else if (!advapi32_handle)
- api_fatal ("could not load advapi32.dll, %E");
+ else if ((h = LoadLibrary (dll_name)) != NULL)
+ dll_handle = h;
+ else
+ api_fatal ("could not load %s, %E", dll_name);
InterlockedDecrement (&here);
return 0;
}
+LoadDLLinitfunc (advapi32)
LoadDLLinitfunc (netapi32)
-{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if ((h = LoadLibrary ("netapi32.dll")) != NULL)
- netapi32_handle = h;
- else if (! netapi32_handle)
- api_fatal ("could not load netapi32.dll. %d", GetLastError ());
-
- InterlockedDecrement (&here);
- return 0;
-}
-
LoadDLLinitfunc (ntdll)
-{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if (ntdll_handle)
- /* nothing to do */;
- else if ((h = LoadLibrary ("ntdll.dll")) != NULL)
- ntdll_handle = h;
- else if (!ntdll_handle)
- api_fatal ("could not load ntdll.dll, %E");
-
- InterlockedDecrement (&here);
- return 0;
-}
-
LoadDLLinitfunc (secur32)
-{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if (secur32_handle)
- /* nothing to do */;
- else if ((h = LoadLibrary ("secur32.dll")) != NULL)
- secur32_handle = h;
- else if (!secur32_handle)
- api_fatal ("could not load secur32.dll, %E");
-
- InterlockedDecrement (&here);
- return 0; /* Already done by another thread? */
-}
-
LoadDLLinitfunc (user32)
-{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if (user32_handle)
- /* nothing to do */;
- else if ((h = LoadLibrary ("user32.dll")) != NULL)
- user32_handle = h;
- else if (!user32_handle)
- api_fatal ("could not load user32.dll, %E");
-
- InterlockedDecrement (&here);
- return 0; /* Already done by another thread? */
-}
-
-LoadDLLinitfunc (wsock32)
-{
- extern void wsock_init ();
- HANDLE h;
-
- if ((h = LoadLibrary ("wsock32.dll")) != NULL)
- wsock32_handle = h;
- else if (!wsock32_handle)
- api_fatal ("could not load wsock32.dll. Is TCP/IP installed?");
- else
- return 0; /* Already done by another thread? */
-
- if (!ws2_32_handle)
- wsock_init ();
-
- return 0;
-}
-
-LoadDLLinitfunc (ws2_32)
-{
- extern void wsock_init ();
- HANDLE h;
-
- if ((h = LoadLibrary ("ws2_32.dll")) == NULL)
- return 0; /* Already done or not available. */
- ws2_32_handle = h;
-
- if (!wsock32_handle)
- wsock_init ();
-
- return 0;
-}
-
LoadDLLinitfunc (iphlpapi)
-{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if (iphlpapi_handle)
- /* nothing to do */;
- else if ((h = LoadLibrary ("iphlpapi.dll")) != NULL)
- iphlpapi_handle = h;
- else if (!iphlpapi_handle)
- api_fatal ("could not load iphlpapi.dll, %E");
-
- InterlockedDecrement (&here);
- return 0;
-}
-
LoadDLLinitfunc (ole32)
-{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if (ole32_handle)
- /* nothing to do */;
- else if ((h = LoadLibrary ("ole32.dll")) != NULL)
- ole32_handle = h;
- else if (!ole32_handle)
- api_fatal ("could not load ole32.dll, %E");
-
- InterlockedDecrement (&here);
- return 0;
-}
-
LoadDLLinitfunc (kernel32)
-{
- HANDLE h;
+LoadDLLinitfunc (winmm)
- if ((h = LoadLibrary ("kernel32.dll")) != NULL)
- kernel32_handle = h;
- else if (!kernel32_handle)
- api_fatal ("could not load kernel32.dll, %E");
- else
- return 0; /* Already done by another thread? */
+extern void wsock_init ();
+LoadDLLinitfuncdef (wsock32)
+{
+ LoadDLLstdfunc (wsock32);
+ wsock_init ();
return 0;
}
-LoadDLLinitfunc (winmm)
+LoadDLLinitfuncdef (ws2_32)
{
- HANDLE h;
- static NO_COPY LONG here = -1L;
-
- while (InterlockedIncrement (&here))
- {
- InterlockedDecrement (&here);
- Sleep (0);
- }
-
- if ((h = LoadLibrary ("winmm.dll")) != NULL)
- winmm_handle = h;
- else if (! winmm_handle)
- api_fatal ("could not load winmm.dll. %d", GetLastError ());
-
- InterlockedDecrement (&here);
+ LoadDLLstdfunc (ws2_32);
+ wsock_init ();
return 0;
}
diff --git a/winsup/cygwin/autoload.h b/winsup/cygwin/autoload.h
index b51df4121..c7f8e32e1 100644
--- a/winsup/cygwin/autoload.h
+++ b/winsup/cygwin/autoload.h
@@ -11,10 +11,20 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#define LoadDLLinitfunc(dllname) \
+LoadDLLinitfuncdef(dllname) \
+{ \
+ return LoadDLLstdfunc(dllname); \
+}
+
+#define LoadDLLinitfuncdef(dllname) \
HANDLE NO_COPY dllname ## _handle = NULL; \
+LONG NO_COPY dllname ## _here = -1L; \
/*static*/ int dllname ## _init () __asm__ (#dllname "_init"); \
/*static*/ int dllname ## _init ()
+#define LoadDLLstdfunc(dllname) \
+ std_dll_init (dllname ## _handle, #dllname ".dll", dllname ## _here)
+
#define LoadDLLinitnow(dllname) \
({__asm__ ("movl $cygwin_dll_func_load, " #dllname "_init_holder"); dllname##_init ();})
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 30b090164..72c7010d8 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -1928,21 +1928,38 @@ endhostent (void)
extern "C" void
wsock_init ()
{
- int res = WSAStartup ((2<<8) | 2, &wsadata);
-
- debug_printf ("res %d", res);
- debug_printf ("wVersion %d", wsadata.wVersion);
- debug_printf ("wHighVersion %d", wsadata.wHighVersion);
- debug_printf ("szDescription %s", wsadata.szDescription);
- debug_printf ("szSystemStatus %s", wsadata.szSystemStatus);
- debug_printf ("iMaxSockets %d", wsadata.iMaxSockets);
- debug_printf ("iMaxUdpDg %d", wsadata.iMaxUdpDg);
- debug_printf ("lpVendorInfo %d", wsadata.lpVendorInfo);
-
- if (FIONBIO != REAL_FIONBIO)
- debug_printf ("**************** FIONBIO != REAL_FIONBIO");
-
- /* FIXME: will resulting random sequence be unpredictable enough? */
- srandom (GetTickCount ());
+ static LONG NO_COPY here = -1L;
+ static int NO_COPY was_in_progress = 0;
+
+ while (InterlockedIncrement (&here))
+ {
+ InterlockedDecrement (&here);
+ Sleep (0);
+ }
+ if (!was_in_progress && (wsock32_handle || ws2_32_handle))
+ {
+ /* Don't use autoload to load WSAStartup to eliminate recursion. */
+ int (*wsastartup) (int, WSADATA *);
+
+ wsastartup = (int (*)(int, WSADATA *))
+ GetProcAddress ((HMODULE) (wsock32_handle ?: ws2_32_handle),
+ "WSAStartup");
+ if (wsastartup)
+ {
+ int res = wsastartup ((2<<8) | 2, &wsadata);
+
+ debug_printf ("res %d", res);
+ debug_printf ("wVersion %d", wsadata.wVersion);
+ debug_printf ("wHighVersion %d", wsadata.wHighVersion);
+ debug_printf ("szDescription %s", wsadata.szDescription);
+ debug_printf ("szSystemStatus %s", wsadata.szSystemStatus);
+ debug_printf ("iMaxSockets %d", wsadata.iMaxSockets);
+ debug_printf ("iMaxUdpDg %d", wsadata.iMaxUdpDg);
+ debug_printf ("lpVendorInfo %d", wsadata.lpVendorInfo);
+
+ was_in_progress = 1;
+ }
+ }
+ InterlockedDecrement (&here);
}