* 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.
			
			
This commit is contained in:
		
							parent
							
								
									b09e3cf8fd
								
							
						
					
					
						commit
						a6a0193b2f
					
				|  | @ -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. | ||||
|  |  | |||
|  | @ -65,222 +65,51 @@ gotit:\n\ | |||
|   jmp *%eax\n\ | ||||
| "); | ||||
| 
 | ||||
| int | ||||
| std_dll_init (HANDLE &dll_handle, const char *dll_name, LONG &here) | ||||
| { | ||||
|   HANDLE h; | ||||
| 
 | ||||
|   while (InterlockedIncrement (&here)) | ||||
|     { | ||||
|       InterlockedDecrement (&here); | ||||
|       Sleep (0); | ||||
|     } | ||||
| 
 | ||||
|   if (dll_handle) | ||||
|     /* nothing to do */; | ||||
|   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) | ||||
| { | ||||
|   HANDLE h; | ||||
|   static NO_COPY LONG here = -1L; | ||||
| 
 | ||||
|   while (InterlockedIncrement (&here)) | ||||
|     { | ||||
|       InterlockedDecrement (&here); | ||||
|       Sleep (0); | ||||
|     } | ||||
| 
 | ||||
|   if (advapi32_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"); | ||||
| 
 | ||||
|   InterlockedDecrement (&here); | ||||
|   return 0; | ||||
| } | ||||
| 
 | ||||
| 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) | ||||
| LoadDLLinitfunc (winmm) | ||||
| 
 | ||||
| extern void wsock_init (); | ||||
| 
 | ||||
| LoadDLLinitfuncdef (wsock32) | ||||
| { | ||||
|   HANDLE h; | ||||
| 
 | ||||
|   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? */ | ||||
| 
 | ||||
|   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; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 ();}) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1928,21 +1928,38 @@ endhostent (void) | |||
| extern "C" void | ||||
| wsock_init () | ||||
| { | ||||
|   int res = WSAStartup ((2<<8) | 2, &wsadata); | ||||
|   static LONG NO_COPY here = -1L; | ||||
|   static int NO_COPY was_in_progress = 0; | ||||
| 
 | ||||
|   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); | ||||
|   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 *); | ||||
| 
 | ||||
|   if (FIONBIO  != REAL_FIONBIO) | ||||
|     debug_printf ("****************  FIONBIO  != REAL_FIONBIO"); | ||||
|       wsastartup = (int (*)(int, WSADATA *)) | ||||
|       		   GetProcAddress ((HMODULE) (wsock32_handle ?: ws2_32_handle), | ||||
| 				   "WSAStartup"); | ||||
|       if (wsastartup) | ||||
|         { | ||||
| 	  int res = wsastartup ((2<<8) | 2, &wsadata); | ||||
| 
 | ||||
|   /* FIXME: will resulting random sequence be unpredictable enough? */ | ||||
|   srandom (GetTickCount ()); | ||||
| 	  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); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue