ReactOS 0.4.15-dev-7907-g95bf896
dprocess.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: dll/win32/ws2_32/src/dprocess.c
5 * PURPOSE: Process Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ws2_32.h>
12
13/* DATA **********************************************************************/
14
16
17#define WsProcLock() EnterCriticalSection(&Process->ThreadLock)
18#define WsProcUnlock() LeaveCriticalSection(&Process->ThreadLock)
19
20/* FUNCTIONS *****************************************************************/
21
22INT
25{
28
29 /* Initialize the thread list lock */
31 Process->LockReady = TRUE;
32
33 /* Open the Winsock Key */
35
36 /* Create the LP Catalog change event and catalog */
37 Process->ProtocolCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
38 Process->ProtocolCatalog = WsTcAllocate();
39
40 // FIXME: Check for Process->ProtocolCatalog == NULL
41
42 /* Initialize it */
43 WsTcInitializeFromRegistry(Process->ProtocolCatalog,
44 RootKey,
45 Process->ProtocolCatalogEvent);
46
47 /* Create the NS Catalog change event and catalog */
48 Process->NamespaceCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
49 Process->NamespaceCatalog = WsNcAllocate();
50
51 // FIXME: Check for Process->NamespaceCatalog == NULL
52
53 /* Initialize it */
55 RootKey,
56 Process->NamespaceCatalogEvent);
57
58 /* Close the root key */
60 return ErrorCode;
61}
62
66{
68
69 /* Allocate the structure */
71 if (Process)
72 {
73 /* Set default non-zero values */
74 Process->Version = MAKEWORD(2,2);
75 }
76
77 /* Return it */
78 return Process;
79}
80
81INT
85{
87
88 /* Lock the process */
89 WsProcLock();
90
91 /* Check if we have a handle, and if not, create one */
92 if ((Process->ApcHelper) ||
93 (WahOpenApcHelper(&Process->ApcHelper) == ERROR_SUCCESS))
94 {
95 /* Return the handle */
96 *Handle = Process->ApcHelper;
98 }
99
100 /* Unload the process and return */
101 WsProcUnlock();
102 return ErrorCode;
103}
104
105INT
106WSAAPI
109{
110 /* Check if we have it already set up */
111 if (Process->ApcHelper)
112 {
113 /* Just return it */
114 *Handle = Process->ApcHelper;
115 return ERROR_SUCCESS;
116 }
117 else
118 {
119 /* Open it for the first time */
121 }
122}
123
124INT
125WSAAPI
127{
129
130 /* Create a new process */
132
133 /* Initialize it */
135 {
136 /* Initialize the process */
138 }
139 else
140 {
141 /* No memory for the process object */
143 }
144
145 return ErrorCode;
146}
147
149WSAAPI
151{
152 /* Check if the catalogs have been modified */
153 if (WsCheckCatalogState(Process->ProtocolCatalogEvent))
154 {
155 /* Modification happened, reload them */
156 WsTcRefreshFromRegistry(Process->ProtocolCatalog,
157 Process->ProtocolCatalogEvent);
158 }
159
160 /* Return it */
161 return Process->ProtocolCatalog;
162}
163
165WSAAPI
167{
168 /* Check if the catalogs have been modified */
169 if (WsCheckCatalogState(Process->NamespaceCatalogEvent))
170 {
171 /* Modification happened, reload them */
172 WsNcRefreshFromRegistry(Process->NamespaceCatalog,
173 Process->NamespaceCatalogEvent);
174 }
175
176 /* Return it */
177 return Process->NamespaceCatalog;
178}
179
180BOOL
181WSAAPI
184{
185 PWSSOCKET Socket = (PWSSOCKET)Handle;
186
187 /* Disassociate this socket from the table */
189
190 /* If this is isn't an IFS socket */
191 if (!Socket->Provider)
192 {
193 /* Check if we have an active handle helper */
194 if (Process->HandleHelper)
195 {
196 /* Close it */
197 WahCloseSocketHandle(Process->HandleHelper, (SOCKET)Socket->Handle);
198 }
199 }
200
201 /* Remove a reference and return */
202 WsSockDereference(Socket);
203 return TRUE;
204}
205
206BOOL
207WSAAPI
210{
212
213 /* Get the provider */
214 Provider = Entry->Provider;
215 if (Provider)
216 {
217 /* Do cleanup */
219 }
220
221 /* Return success */
222 return TRUE;
223}
224
225BOOL
226WSAAPI
229{
232
233 /* Get the provider */
234 Provider = Entry->Provider;
235 if (Provider)
236 {
237 /* Do cleanup */
239 }
240
241 /* Return success */
242 return TRUE;
243}
244
245VOID
246WSAAPI
248{
249 /* Check if we didn't even initialize yet */
250 if (!Process->LockReady) return;
251
252 /* No more current process */
254
255 /* If we have a socket table */
257 {
258 /* Enumerate the sockets with a delete callback */
261 Process);
262 }
263
264 /* Close APC Helper */
265 if (Process->ApcHelper) WahCloseApcHelper(Process->ApcHelper);
266
267 /* Close handle helper */
268 if (Process->HandleHelper) WahCloseHandleHelper(Process->HandleHelper);
269
270 /* Check for notification helper */
271 if (Process->NotificationHelper)
272 {
273 /* Close notification helper */
274 WahCloseNotificationHandleHelper(Process->NotificationHelper);
275 }
276
277 /* Check if we have a protocol catalog*/
278 if (Process->ProtocolCatalog)
279 {
280 /* Enumerate it to clean it up */
281 WsTcEnumerateCatalogItems(Process->ProtocolCatalog,
283 NULL);
284
285 /* Delete it */
286 WsTcDelete(Process->ProtocolCatalog);
287 Process->ProtocolCatalog = NULL;
288 }
289
290 /* Check if we have a namespace catalog*/
291 if (Process->NamespaceCatalog)
292 {
293 /* Enumerate it to clean it up */
294 WsNcEnumerateCatalogItems(Process->NamespaceCatalog,
296 NULL);
297
298 /* Delete it */
299 WsNcDelete(Process->NamespaceCatalog);
300 Process->NamespaceCatalog = NULL;
301 }
302
303 /* Delete the thread lock */
304 DeleteCriticalSection(&Process->ThreadLock);
305
306 /* Delete us */
308}
309
310VOID
311WSAAPI
313 IN WORD VersionRequested)
314{
315 WORD Major, Minor;
316 WORD OldMajor, OldMinor;
317
318 /* Get the version data */
319 Major = LOBYTE(VersionRequested);
320 Minor = HIBYTE(VersionRequested);
321 OldMajor = LOBYTE(Process->Version);
322 OldMinor = HIBYTE(Process->Version);
323
324 /* Check if we're going lower */
325 if ((Major < OldMajor) || ((Major == OldMajor) && (Minor < OldMinor)))
326 {
327 /* Set the new version */
328 Process->Version = VersionRequested;
329 }
330}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
DWORD WINAPI WahCloseApcHelper(IN HANDLE ApcHelperHandle)
Definition: apc.c:42
DWORD WINAPI WahOpenApcHelper(OUT PHANDLE ApcHelperHandle)
Definition: apc.c:20
BOOL WINAPI WahEnumerateHandleContexts(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: context.c:280
DWORD WINAPI WahRemoveHandleContext(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
Definition: context.c:564
DWORD WINAPI WahCloseHandleHelper(IN HANDLE HelperHandle)
Definition: handle.c:86
DWORD WINAPI WahCloseSocketHandle(IN HANDLE HelperHandle, IN SOCKET Socket)
Definition: handle.c:113
DWORD WINAPI WahCloseNotificationHandleHelper(IN HANDLE HelperHandle)
Definition: notify.c:22
BOOL WSAAPI CleanupNamespaceProviders(IN PVOID Callback, IN PNSCATALOG_ENTRY Entry)
Definition: dprocess.c:208
PWSPROCESS CurrentWsProcess
Definition: dprocess.c:15
INT WSAAPI WsProcInitialize(IN PWSPROCESS Process)
Definition: dprocess.c:24
BOOL WSAAPI WsProcDetachSocket(IN PWSPROCESS Process, IN PWAH_HANDLE Handle)
Definition: dprocess.c:182
#define WsProcLock()
Definition: dprocess.c:17
VOID WSAAPI WsProcDelete(IN PWSPROCESS Process)
Definition: dprocess.c:247
INT WSAAPI WsProcStartup(VOID)
Definition: dprocess.c:126
PNSCATALOG WSAAPI WsProcGetNsCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:166
#define WsProcUnlock()
Definition: dprocess.c:18
BOOL WSAAPI CleanupProtocolProviders(IN PVOID Callback, IN PTCATALOG_ENTRY Entry)
Definition: dprocess.c:227
PWSPROCESS WSAAPI WsProcAllocate(VOID)
Definition: dprocess.c:65
VOID WSAAPI WsProcSetVersion(IN PWSPROCESS Process, IN WORD VersionRequested)
Definition: dprocess.c:312
PTCATALOG WSAAPI WsProcGetTCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:150
INT WSAAPI WsProcGetAsyncHelper(IN PWSPROCESS Process, OUT PHANDLE Handle)
Definition: dprocess.c:107
INT WSAAPI WsProcOpenAsyncHelperDevice(IN PWSPROCESS Process, OUT PHANDLE Handle)
Definition: dprocess.c:83
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
ULONG Handle
Definition: gdb_input.c:15
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
static PMEMKEY RootKey
Definition: registry.c:55
base of all file and directory entries
Definition: entries.h:83
Definition: ws2_32p.h:122
Definition: ws2_32p.h:86
PTPROVIDER Provider
Definition: ws2_32p.h:199
HANDLE Handle
Definition: ws2_32p.h:197
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
#define CreateEvent
Definition: winbase.h:3748
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define WSAEFAULT
Definition: winerror.h:1945
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:620
#define WSAAPI
Definition: winsock2.h:605
UINT_PTR SOCKET
Definition: winsock.h:47
VOID WSAAPI WsNcDelete(IN PNSCATALOG Catalog)
Definition: nscatalo.c:624
PTCATALOG WSAAPI WsTcAllocate(VOID)
Definition: dcatalog.c:25
HKEY WSAAPI WsOpenRegistryRoot(VOID)
Definition: wsautil.c:17
struct _WSSOCKET * PWSSOCKET
INT WSAAPI WsNcInitializeFromRegistry(IN PNSCATALOG Catalog, IN HKEY ParentKey, IN HANDLE CatalogEvent)
Definition: nscatalo.c:211
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
VOID WSAAPI WsTcEnumerateCatalogItems(IN PTCATALOG Catalog, IN PTCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: dcatalog.c:750
BOOL WSAAPI WsCheckCatalogState(IN HANDLE Event)
Definition: wsautil.c:75
DWORD WSAAPI WsTcInitializeFromRegistry(IN PTCATALOG TCatalog, HKEY, PVOID)
DWORD WSAAPI WsNpNSPCleanup(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:140
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
VOID WSAAPI WsNcEnumerateCatalogItems(IN PNSCATALOG Catalog, IN PNSCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: nscatalo.c:371
HANDLE WsSockHeap
Definition: dllmain.c:21
PNSCATALOG WSAAPI WsNcAllocate(VOID)
Definition: nscatalo.c:25
INT WSAAPI WsNcRefreshFromRegistry(IN PNSCATALOG Catalog, IN HANDLE CatalogEvent)
Definition: nscatalo.c:230
BOOL WSAAPI WsSockDeleteSockets(IN LPVOID Context, IN PWAH_HANDLE Handle)
Definition: dsocket.c:180
VOID WSAAPI WsTcDelete(IN PTCATALOG Catalog)
Definition: dcatalog.c:883
DWORD WSAAPI WsTpWSPCleanup(IN PTPROVIDER Provider, int *)
DWORD WSAAPI WsTcRefreshFromRegistry(IN PTCATALOG TCatalog, PVOID)
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44