2009-07-21 09:16:26 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS WinSock 2 DLL
|
2021-02-07 21:17:01 +00:00
|
|
|
* FILE: dll/win32/ws2help/dllmain.c
|
2009-07-21 09:16:26 +00:00
|
|
|
* PURPOSE: WinSock 2 DLL header
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/* DATA **********************************************************************/
|
|
|
|
|
|
|
|
HANDLE GlobalHeap;
|
|
|
|
BOOL Ws2helpInitialized = FALSE;
|
2016-11-12 21:53:33 +00:00
|
|
|
CRITICAL_SECTION StartupSynchronization;
|
2009-07-21 09:16:26 +00:00
|
|
|
HINSTANCE LibraryHdl;
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
NewCtxInit(VOID)
|
|
|
|
{
|
|
|
|
NT_PRODUCT_TYPE ProductType = NtProductWinNt;
|
|
|
|
SYSTEM_INFO SystemInfo;
|
|
|
|
DWORD NumHandleBuckets;
|
|
|
|
HKEY KeyHandle;
|
|
|
|
DWORD RegSize = sizeof(DWORD);
|
|
|
|
DWORD RegType;
|
|
|
|
DWORD Mask;
|
|
|
|
|
|
|
|
/* Try to figure out if this is a workstation or server install */
|
|
|
|
RtlGetNtProductType(&ProductType);
|
|
|
|
|
|
|
|
/* Get the system info */
|
|
|
|
GetSystemInfo(&SystemInfo);
|
|
|
|
|
|
|
|
/* If this is an MP machine, set the default spinlock */
|
|
|
|
if (SystemInfo.dwNumberOfProcessors > 1) gdwSpinCount = 2000;
|
|
|
|
|
|
|
|
/* Figure how many "Handle Buckets" we'll use. Start with the default */
|
|
|
|
NumHandleBuckets = ProductType == NtProductWinNt ? 8 : 32;
|
|
|
|
|
|
|
|
/* Open the registry settings */
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
|
|
"System\\CurrentControlSet\\Services\\Winsock2\\Parameters",
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&KeyHandle) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Query the key */
|
|
|
|
RegQueryValueEx(KeyHandle,
|
|
|
|
"Ws2_32NumHandleBuckets",
|
|
|
|
0,
|
|
|
|
&RegType,
|
|
|
|
(LPBYTE)&NumHandleBuckets,
|
|
|
|
&RegSize);
|
|
|
|
|
|
|
|
/* Are we on MP? */
|
|
|
|
if (SystemInfo.dwNumberOfProcessors > 1)
|
|
|
|
{
|
|
|
|
/* Also check for a custom spinlock setting */
|
|
|
|
RegQueryValueEx(KeyHandle,
|
|
|
|
"Ws2_32SpinCount",
|
|
|
|
0,
|
|
|
|
&RegType,
|
|
|
|
(LPBYTE)&gdwSpinCount,
|
|
|
|
&RegSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the key, we're done */
|
|
|
|
RegCloseKey(KeyHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now get the bucket count and normalize it to be log2 and within 256 */
|
|
|
|
for (Mask = 256; !(Mask & NumHandleBuckets); Mask >>= 1);
|
|
|
|
NumHandleBuckets = Mask;
|
|
|
|
|
|
|
|
/* Normalize it again, to be within OS parameters */
|
|
|
|
if (ProductType == NtProductWinNt)
|
|
|
|
{
|
|
|
|
/* Is it within norms for non-server editions? */
|
|
|
|
if (NumHandleBuckets > 32) NumHandleBuckets = 32;
|
|
|
|
else if (NumHandleBuckets < 8) NumHandleBuckets = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Is it within norms for server editions? */
|
|
|
|
if (NumHandleBuckets > 256) NumHandleBuckets = 256;
|
|
|
|
else if (NumHandleBuckets < 32) NumHandleBuckets = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normalize the spincount */
|
|
|
|
if (gdwSpinCount > 8000) gdwSpinCount = 8000;
|
|
|
|
|
|
|
|
/* Set the final mask */
|
|
|
|
gHandleToIndexMask = NumHandleBuckets -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
Ws2helpInitialize(VOID)
|
|
|
|
{
|
|
|
|
/* Enter the startup CS */
|
2016-11-12 21:53:33 +00:00
|
|
|
EnterCriticalSection(&StartupSynchronization);
|
2009-07-21 09:16:26 +00:00
|
|
|
|
|
|
|
/* Check again for init */
|
|
|
|
if (!Ws2helpInitialized)
|
|
|
|
{
|
|
|
|
/* Initialize us */
|
|
|
|
NewCtxInit();
|
|
|
|
Ws2helpInitialized = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Leave the CS and return */
|
2016-11-12 21:53:33 +00:00
|
|
|
LeaveCriticalSection(&StartupSynchronization);
|
2009-07-21 09:16:26 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
DllMain(HANDLE hModule,
|
|
|
|
DWORD dwReason,
|
2009-07-21 09:16:26 +00:00
|
|
|
LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2009-07-21 09:16:26 +00:00
|
|
|
/* Save our handle */
|
|
|
|
LibraryHdl = hModule;
|
|
|
|
|
|
|
|
/* Improve Performance */
|
|
|
|
DisableThreadLibraryCalls(hModule);
|
|
|
|
|
|
|
|
/* Initialize startup CS */
|
2016-11-12 21:53:33 +00:00
|
|
|
InitializeCriticalSection(&StartupSynchronization);
|
2009-07-21 09:16:26 +00:00
|
|
|
|
|
|
|
/* Get Global Heap */
|
|
|
|
GlobalHeap = GetProcessHeap();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
|
|
|
|
/* Make sure we loaded */
|
|
|
|
if (!LibraryHdl) break;
|
|
|
|
|
|
|
|
/* Check if we are cleaning up */
|
|
|
|
if (lpReserved)
|
|
|
|
{
|
|
|
|
/* Free the security descriptor */
|
|
|
|
if (pSDPipe) HeapFree(GlobalHeap, 0, pSDPipe);
|
|
|
|
|
|
|
|
/* Close the event */
|
|
|
|
if (ghWriterEvent) CloseHandle(ghWriterEvent);
|
|
|
|
|
|
|
|
/* Delete the startup CS */
|
2016-11-12 21:53:33 +00:00
|
|
|
DeleteCriticalSection(&StartupSynchronization);
|
2009-07-21 09:16:26 +00:00
|
|
|
Ws2helpInitialized = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|