ReactOS  0.4.13-dev-563-g0561610
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_new/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 
22 INT
23 WSAAPI
25 {
27  HKEY RootKey = NULL;
28 
29  /* Initialize the thread list lock */
30  InitializeCriticalSection(&Process->ThreadLock);
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 */
54  ErrorCode = WsNcInitializeFromRegistry(Process->NamespaceCatalog,
55  RootKey,
56  Process->NamespaceCatalogEvent);
57 
58  /* Close the root key */
60  return ErrorCode;
61 }
62 
64 WSAAPI
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 
81 INT
82 WSAAPI
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 
105 INT
106 WSAAPI
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 
124 INT
125 WSAAPI
127 {
129 
130  /* Create a new process */
132 
133  /* Initialize it */
134  if (CurrentWsProcess)
135  {
136  /* Initialize the process */
138  }
139  else
140  {
141  /* No memory for the process object */
143  }
144 
145  return ErrorCode;
146 }
147 
148 PTCATALOG
149 WSAAPI
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 
165 WSAAPI
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 
180 BOOL
181 WSAAPI
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 
206 BOOL
207 WSAAPI
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 
225 BOOL
226 WSAAPI
229 {
231  INT ErrorCode;
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 
245 VOID
246 WSAAPI
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 */
256  if (WsSockHandleTable)
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 
310 VOID
311 WSAAPI
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 CreateEvent
Definition: winbase.h:3562
HKEY WSAAPI WsOpenRegistryRoot(VOID)
Definition: wsautil.c:17
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
DWORD WSAAPI WsTcInitializeFromRegistry(IN PTCATALOG TCatalog, HKEY, PVOID)
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define WSAEFAULT
Definition: winerror.h:1945
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
Definition: ws2_32p.h:85
static PMEMKEY RootKey
Definition: registry.c:55
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LOBYTE(W)
Definition: jmemdos.c:487
#define MAKEWORD(a, b)
Definition: typedefs.h:247
HANDLE Handle
Definition: ws2_32p.h:197
#define HIBYTE(W)
Definition: jmemdos.c:486
VOID WSAAPI WsTcDelete(IN PTCATALOG Catalog)
Definition: dcatalog.c:862
Definition: ws2_32p.h:121
PWSPROCESS CurrentWsProcess
Definition: dprocess.c:15
int32_t INT
Definition: typedefs.h:56
DWORD WINAPI WahCloseApcHelper(IN HANDLE ApcHelperHandle)
Definition: apc.c:42
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
INT WSAAPI WsNcRefreshFromRegistry(IN PNSCATALOG Catalog, IN HANDLE CatalogEvent)
Definition: nscatalo.c:209
BOOL WSAAPI CleanupProtocolProviders(IN PVOID Callback, IN PTCATALOG_ENTRY Entry)
Definition: dprocess.c:227
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
DWORD WINAPI WahRemoveHandleContext(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
Definition: context.c:564
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI WahCloseSocketHandle(IN HANDLE HelperHandle, IN SOCKET Socket)
Definition: handle.c:113
DWORD WSAAPI WsTpWSPCleanup(IN PTPROVIDER Provider, int *)
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
BOOL WSAAPI WsSockDeleteSockets(IN LPVOID Context, IN PWAH_HANDLE Handle)
Definition: dsocket.c:180
BOOL WSAAPI WsProcDetachSocket(IN PWSPROCESS Process, IN PWAH_HANDLE Handle)
Definition: dprocess.c:182
DWORD WSAAPI WsTcRefreshFromRegistry(IN PTCATALOG TCatalog, PVOID)
PWSPROCESS WSAAPI WsProcAllocate(VOID)
Definition: dprocess.c:65
DWORD WINAPI WahCloseHandleHelper(IN HANDLE HelperHandle)
Definition: handle.c:86
_In_ HANDLE Handle
Definition: extypes.h:390
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
PTCATALOG WSAAPI WsProcGetTCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:150
PNSCATALOG WSAAPI WsProcGetNsCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:166
PTPROVIDER Provider
Definition: ws2_32p.h:199
INT WSAAPI WsProcOpenAsyncHelperDevice(IN PWSPROCESS Process, OUT PHANDLE Handle)
Definition: dprocess.c:83
unsigned short WORD
Definition: ntddk_ex.h:93
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
#define WsProcUnlock()
Definition: dprocess.c:18
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:593
BOOL WINAPI WahEnumerateHandleContexts(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: context.c:280
BOOL WSAAPI WsCheckCatalogState(IN HANDLE Event)
Definition: wsautil.c:75
DWORD WSAAPI WsNpNSPCleanup(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:140
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
VOID WSAAPI WsTcEnumerateCatalogItems(IN PTCATALOG Catalog, IN PTCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: dcatalog.c:729
VOID WSAAPI WsNcEnumerateCatalogItems(IN PNSCATALOG Catalog, IN PNSCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: nscatalo.c:350
VOID WSAAPI WsProcDelete(IN PWSPROCESS Process)
Definition: dprocess.c:247
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define WSAAPI
Definition: winsock2.h:584
INT WSAAPI WsProcStartup(VOID)
Definition: dprocess.c:126
INT WSAAPI WsProcGetAsyncHelper(IN PWSPROCESS Process, OUT PHANDLE Handle)
Definition: dprocess.c:107
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
INT WSAAPI WsProcInitialize(IN PWSPROCESS Process)
Definition: dprocess.c:24
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define OUT
Definition: typedefs.h:39
#define WsProcLock()
Definition: dprocess.c:17
VOID WSAAPI WsNcDelete(IN PNSCATALOG Catalog)
Definition: nscatalo.c:603
BOOL WSAAPI CleanupNamespaceProviders(IN PVOID Callback, IN PNSCATALOG_ENTRY Entry)
Definition: dprocess.c:208
UINT_PTR SOCKET
Definition: winsock.h:47
DWORD WINAPI WahCloseNotificationHandleHelper(IN HANDLE HelperHandle)
Definition: notify.c:22
PNSCATALOG WSAAPI WsNcAllocate(VOID)
Definition: nscatalo.c:25
DWORD WINAPI WahOpenApcHelper(OUT PHANDLE ApcHelperHandle)
Definition: apc.c:20
LPFNPSPCALLBACK Callback
Definition: desk.c:111
struct _WSSOCKET * PWSSOCKET
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:394
VOID WSAAPI WsProcSetVersion(IN PWSPROCESS Process, IN WORD VersionRequested)
Definition: dprocess.c:312
base of all file and directory entries
Definition: entries.h:82
INT WSAAPI WsNcInitializeFromRegistry(IN PNSCATALOG Catalog, IN HKEY ParentKey, IN HANDLE CatalogEvent)
Definition: nscatalo.c:190
PTCATALOG WSAAPI WsTcAllocate(VOID)
Definition: dcatalog.c:25