ReactOS  0.4.14-dev-358-gbef841c
dllmain.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WinSock 2 DLL
4  * FILE: include/ws2_32.h
5  * PURPOSE: WinSock 2 DLL header
6  */
7 
8 /* INCLUDES ******************************************************************/
9 
10 #include "precomp.h"
11 
12 /* DATA **********************************************************************/
13 
18 
19 /* FUNCTIONS *****************************************************************/
20 
21 VOID
22 WINAPI
24 {
25  NT_PRODUCT_TYPE ProductType = NtProductWinNt;
26  SYSTEM_INFO SystemInfo;
27  DWORD NumHandleBuckets;
29  DWORD RegSize = sizeof(DWORD);
30  DWORD RegType;
31  DWORD Mask;
32 
33  /* Try to figure out if this is a workstation or server install */
34  RtlGetNtProductType(&ProductType);
35 
36  /* Get the system info */
37  GetSystemInfo(&SystemInfo);
38 
39  /* If this is an MP machine, set the default spinlock */
40  if (SystemInfo.dwNumberOfProcessors > 1) gdwSpinCount = 2000;
41 
42  /* Figure how many "Handle Buckets" we'll use. Start with the default */
43  NumHandleBuckets = ProductType == NtProductWinNt ? 8 : 32;
44 
45  /* Open the registry settings */
47  "System\\CurrentControlSet\\Services\\Winsock2\\Parameters",
48  0,
51  {
52  /* Query the key */
54  "Ws2_32NumHandleBuckets",
55  0,
56  &RegType,
57  (LPBYTE)&NumHandleBuckets,
58  &RegSize);
59 
60  /* Are we on MP? */
61  if (SystemInfo.dwNumberOfProcessors > 1)
62  {
63  /* Also check for a custom spinlock setting */
65  "Ws2_32SpinCount",
66  0,
67  &RegType,
69  &RegSize);
70  }
71 
72  /* Close the key, we're done */
74  }
75 
76  /* Now get the bucket count and normalize it to be log2 and within 256 */
77  for (Mask = 256; !(Mask & NumHandleBuckets); Mask >>= 1);
78  NumHandleBuckets = Mask;
79 
80  /* Normalize it again, to be within OS parameters */
81  if (ProductType == NtProductWinNt)
82  {
83  /* Is it within norms for non-server editions? */
84  if (NumHandleBuckets > 32) NumHandleBuckets = 32;
85  else if (NumHandleBuckets < 8) NumHandleBuckets = 8;
86  }
87  else
88  {
89  /* Is it within norms for server editions? */
90  if (NumHandleBuckets > 256) NumHandleBuckets = 256;
91  else if (NumHandleBuckets < 32) NumHandleBuckets = 32;
92  }
93 
94  /* Normalize the spincount */
95  if (gdwSpinCount > 8000) gdwSpinCount = 8000;
96 
97  /* Set the final mask */
98  gHandleToIndexMask = NumHandleBuckets -1;
99 }
100 
101 DWORD
102 WINAPI
104 {
105  /* Enter the startup CS */
107 
108  /* Check again for init */
109  if (!Ws2helpInitialized)
110  {
111  /* Initialize us */
112  NewCtxInit();
114  }
115 
116  /* Leave the CS and return */
118  return ERROR_SUCCESS;
119 }
120 
121 BOOL
122 APIENTRY
124  DWORD dwReason,
125  LPVOID lpReserved)
126 {
127  switch (dwReason)
128  {
129  case DLL_PROCESS_ATTACH:
130 
131  /* Save our handle */
133 
134  /* Improve Performance */
136 
137  /* Initialize startup CS */
139 
140  /* Get Global Heap */
142  break;
143 
144  case DLL_THREAD_ATTACH:
145  case DLL_THREAD_DETACH:
146  break;
147 
148  case DLL_PROCESS_DETACH:
149 
150  /* Make sure we loaded */
151  if (!LibraryHdl) break;
152 
153  /* Check if we are cleaning up */
154  if (lpReserved)
155  {
156  /* Free the security descriptor */
158 
159  /* Close the event */
161 
162  /* Delete the startup CS */
165  }
166  break;
167  }
168 
169  return TRUE;
170 }
#define RegQueryValueEx
Definition: winreg.h:524
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define ERROR_SUCCESS
Definition: deptool.c:10
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
CRITICAL_SECTION StartupSynchronization
Definition: dllmain.c:16
#define DLL_THREAD_ATTACH
Definition: compat.h:121
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
Definition: dllmain.c:52
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define DWORD
Definition: nt_native.h:44
#define DLL_THREAD_DETACH
Definition: compat.h:122
BOOL Ws2helpInitialized
Definition: dllmain.c:15
DWORD dwReason
Definition: misc.cpp:154
BOOLEAN NTAPI RtlGetNtProductType(PNT_PRODUCT_TYPE ProductType)
Definition: version.c:96
DWORD WINAPI Ws2helpInitialize(VOID)
Definition: dllmain.c:103
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define GetProcessHeap()
Definition: compat.h:403
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
HINSTANCE LibraryHdl
Definition: dllmain.c:17
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD gHandleToIndexMask
Definition: context.c:19
HANDLE GlobalHeap
Definition: dllmain.c:19
DWORD gdwSpinCount
Definition: context.c:18
#define RegOpenKeyEx
Definition: winreg.h:520
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
PSECURITY_DESCRIPTOR pSDPipe
Definition: notify.c:16
VOID WINAPI NewCtxInit(VOID)
Definition: dllmain.c:23
DWORD dwNumberOfProcessors
Definition: winbase.h:1137
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define HeapFree(x, y, z)
Definition: compat.h:402
HANDLE ghWriterEvent
Definition: context.c:17
#define APIENTRY
Definition: api.h:79
HMODULE hModule
Definition: animate.c:44
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12