ReactOS 0.4.15-dev-7842-g558ab78
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: dll/win32/ws2help/dllmain.c
5 * PURPOSE: WinSock 2 DLL header
6 */
7
8/* INCLUDES ******************************************************************/
9
10#include "precomp.h"
11
12/* DATA **********************************************************************/
13
18
19/* FUNCTIONS *****************************************************************/
20
21VOID
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
101DWORD
102WINAPI
104{
105 /* Enter the startup CS */
107
108 /* Check again for init */
110 {
111 /* Initialize us */
112 NewCtxInit();
114 }
115
116 /* Leave the CS and return */
118 return ERROR_SUCCESS;
119}
120
121BOOL
125 LPVOID lpReserved)
126{
127 switch (dwReason)
128 {
130
131 /* Save our handle */
133
134 /* Improve Performance */
136
137 /* Initialize startup CS */
139
140 /* Get Global Heap */
142 break;
143
146 break;
147
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}
DWORD dwReason
Definition: misc.cpp:154
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
Definition: dllmain.c:52
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition: version.c:96
#define APIENTRY
Definition: api.h:79
HMODULE hModule
Definition: animate.c:44
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define HeapFree(x, y, z)
Definition: compat.h:735
#define DLL_THREAD_ATTACH
Definition: compat.h:132
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
HANDLE GlobalHeap
Definition: dllmain.c:19
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
@ NtProductWinNt
Definition: shellpath.c:64
HANDLE ghWriterEvent
Definition: context.c:17
DWORD gdwSpinCount
Definition: context.c:18
DWORD gHandleToIndexMask
Definition: context.c:19
HINSTANCE LibraryHdl
Definition: dllmain.c:17
DWORD WINAPI Ws2helpInitialize(VOID)
Definition: dllmain.c:103
VOID WINAPI NewCtxInit(VOID)
Definition: dllmain.c:23
BOOL Ws2helpInitialized
Definition: dllmain.c:15
CRITICAL_SECTION StartupSynchronization
Definition: dllmain.c:16
PSECURITY_DESCRIPTOR pSDPipe
Definition: notify.c:16
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int Mask
Definition: fpcontrol.c:82
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
DWORD dwNumberOfProcessors
Definition: winbase.h:1177
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
unsigned char * LPBYTE
Definition: typedefs.h:53
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524