ReactOS
0.4.16-dev-257-g6aa11ac
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
14
HANDLE
GlobalHeap
;
15
BOOL
Ws2helpInitialized
=
FALSE
;
16
CRITICAL_SECTION
StartupSynchronization
;
17
HINSTANCE
LibraryHdl
;
18
19
/* FUNCTIONS *****************************************************************/
20
21
VOID
22
WINAPI
23
NewCtxInit
(
VOID
)
24
{
25
NT_PRODUCT_TYPE
ProductType =
NtProductWinNt
;
26
SYSTEM_INFO
SystemInfo;
27
DWORD
NumHandleBuckets;
28
HKEY
KeyHandle
;
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 */
46
if
(
RegOpenKeyEx
(
HKEY_LOCAL_MACHINE
,
47
"System\\CurrentControlSet\\Services\\Winsock2\\Parameters"
,
48
0,
49
KEY_QUERY_VALUE
,
50
&
KeyHandle
) ==
ERROR_SUCCESS
)
51
{
52
/* Query the key */
53
RegQueryValueEx
(
KeyHandle
,
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 */
64
RegQueryValueEx
(
KeyHandle
,
65
"Ws2_32SpinCount"
,
66
0,
67
&RegType,
68
(
LPBYTE
)&
gdwSpinCount
,
69
&RegSize);
70
}
71
72
/* Close the key, we're done */
73
RegCloseKey
(
KeyHandle
);
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
103
Ws2helpInitialize
(
VOID
)
104
{
105
/* Enter the startup CS */
106
EnterCriticalSection
(&
StartupSynchronization
);
107
108
/* Check again for init */
109
if
(!
Ws2helpInitialized
)
110
{
111
/* Initialize us */
112
NewCtxInit
();
113
Ws2helpInitialized
=
TRUE
;
114
}
115
116
/* Leave the CS and return */
117
LeaveCriticalSection
(&
StartupSynchronization
);
118
return
ERROR_SUCCESS
;
119
}
120
121
BOOL
122
APIENTRY
123
DllMain
(
HANDLE
hModule
,
124
DWORD
dwReason
,
125
LPVOID
lpReserved)
126
{
127
switch
(
dwReason
)
128
{
129
case
DLL_PROCESS_ATTACH
:
130
131
/* Save our handle */
132
LibraryHdl
=
hModule
;
133
134
/* Improve Performance */
135
DisableThreadLibraryCalls
(
hModule
);
136
137
/* Initialize startup CS */
138
InitializeCriticalSection
(&
StartupSynchronization
);
139
140
/* Get Global Heap */
141
GlobalHeap
=
GetProcessHeap
();
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 */
157
if
(
pSDPipe
)
HeapFree
(
GlobalHeap
, 0,
pSDPipe
);
158
159
/* Close the event */
160
if
(
ghWriterEvent
)
CloseHandle
(
ghWriterEvent
);
161
162
/* Delete the startup CS */
163
DeleteCriticalSection
(&
StartupSynchronization
);
164
Ws2helpInitialized
=
FALSE
;
165
}
166
break
;
167
}
168
169
return
TRUE
;
170
}
dwReason
DWORD dwReason
Definition:
misc.cpp:141
RegCloseKey
#define RegCloseKey(hKey)
Definition:
registry.h:49
ERROR_SUCCESS
#define ERROR_SUCCESS
Definition:
deptool.c:10
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
DllMain
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
Definition:
dllmain.c:52
RtlGetNtProductType
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition:
version.c:96
APIENTRY
#define APIENTRY
Definition:
api.h:79
hModule
HMODULE hModule
Definition:
animate.c:44
CloseHandle
#define CloseHandle
Definition:
compat.h:739
GetProcessHeap
#define GetProcessHeap()
Definition:
compat.h:736
DLL_THREAD_DETACH
#define DLL_THREAD_DETACH
Definition:
compat.h:133
DLL_PROCESS_ATTACH
#define DLL_PROCESS_ATTACH
Definition:
compat.h:131
DLL_PROCESS_DETACH
#define DLL_PROCESS_DETACH
Definition:
compat.h:130
HeapFree
#define HeapFree(x, y, z)
Definition:
compat.h:735
DLL_THREAD_ATTACH
#define DLL_THREAD_ATTACH
Definition:
compat.h:132
DisableThreadLibraryCalls
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition:
loader.c:85
GetSystemInfo
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition:
sysinfo.c:143
GlobalHeap
HANDLE GlobalHeap
Definition:
dllmain.c:19
NT_PRODUCT_TYPE
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
NtProductWinNt
@ NtProductWinNt
Definition:
shellpath.c:64
ghWriterEvent
HANDLE ghWriterEvent
Definition:
context.c:17
gdwSpinCount
DWORD gdwSpinCount
Definition:
context.c:18
gHandleToIndexMask
DWORD gHandleToIndexMask
Definition:
context.c:19
LibraryHdl
HINSTANCE LibraryHdl
Definition:
dllmain.c:17
Ws2helpInitialize
DWORD WINAPI Ws2helpInitialize(VOID)
Definition:
dllmain.c:103
NewCtxInit
VOID WINAPI NewCtxInit(VOID)
Definition:
dllmain.c:23
Ws2helpInitialized
BOOL Ws2helpInitialized
Definition:
dllmain.c:15
StartupSynchronization
CRITICAL_SECTION StartupSynchronization
Definition:
dllmain.c:16
pSDPipe
PSECURITY_DESCRIPTOR pSDPipe
Definition:
notify.c:16
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
DWORD
unsigned long DWORD
Definition:
ntddk_ex.h:95
Mask
unsigned int Mask
Definition:
fpcontrol.c:82
void
Definition:
nsiface.idl:2307
KeyHandle
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition:
ndis.h:4715
KEY_QUERY_VALUE
#define KEY_QUERY_VALUE
Definition:
nt_native.h:1016
DWORD
#define DWORD
Definition:
nt_native.h:44
_CRITICAL_SECTION
Definition:
winbase.h:918
_SYSTEM_INFO
Definition:
winbase.h:1190
_SYSTEM_INFO::dwNumberOfProcessors
DWORD dwNumberOfProcessors
Definition:
winbase.h:1202
InitializeCriticalSection
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition:
synch.c:751
LPBYTE
unsigned char * LPBYTE
Definition:
typedefs.h:53
precomp.h
LeaveCriticalSection
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
EnterCriticalSection
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
DeleteCriticalSection
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
WINAPI
#define WINAPI
Definition:
msvc.h:6
HKEY_LOCAL_MACHINE
#define HKEY_LOCAL_MACHINE
Definition:
winreg.h:12
RegOpenKeyEx
#define RegOpenKeyEx
Definition:
winreg.h:520
RegQueryValueEx
#define RegQueryValueEx
Definition:
winreg.h:524
dll
win32
ws2help
dllmain.c
Generated on Mon Nov 11 2024 06:14:55 for ReactOS by
1.9.6