2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
5 * PURPOSE: Process Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
13 /* DATA **********************************************************************/
15 PWSPROCESS CurrentWsProcess
;
17 #define WsProcLock() EnterCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
18 #define WsProcUnlock() LeaveCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
20 /* FUNCTIONS *****************************************************************/
24 WsProcInitialize(IN PWSPROCESS Process
)
26 INT ErrorCode
= WSAEFAULT
;
29 /* Initialize the thread list lock */
30 InitializeCriticalSection((LPCRITICAL_SECTION
)&Process
->ThreadLock
);
31 Process
->LockReady
= TRUE
;
33 /* Open the Winsock Key */
34 RootKey
= WsOpenRegistryRoot();
36 /* Create the LP Catalog change event and catalog */
37 Process
->ProtocolCatalogEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
38 Process
->ProtocolCatalog
= WsTcAllocate();
41 WsTcInitializeFromRegistry(Process
->ProtocolCatalog
,
43 Process
->ProtocolCatalogEvent
);
45 /* Create the NS Catalog change event and catalog */
46 Process
->NamespaceCatalogEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
47 Process
->NamespaceCatalog
= WsNcAllocate();
50 ErrorCode
= WsNcInitializeFromRegistry(Process
->NamespaceCatalog
,
52 Process
->NamespaceCatalogEvent
);
54 /* Close the root key */
65 /* Allocate the structure */
66 Process
= HeapAlloc(WsSockHeap
, HEAP_ZERO_MEMORY
, sizeof(*Process
));
68 /* Set default non-zero values */
69 Process
->Version
= MAKEWORD(2,2);
77 WsProcOpenAsyncHelperDevice(IN PWSPROCESS Process
,
80 INT ErrorCode
= WSASYSCALLFAILURE
;
82 /* Lock the process */
85 /* Check if we have a handle, and if not, create one */
86 if ((Process
->ApcHelper
) ||
87 (WahOpenApcHelper(&Process
->ApcHelper
) == ERROR_SUCCESS
))
89 /* Return the handle */
90 *Handle
= Process
->ApcHelper
;
91 ErrorCode
= ERROR_SUCCESS
;
94 /* Unload the process and return */
101 WsProcGetAsyncHelper(IN PWSPROCESS Process
,
104 /* Check if we have it already set up */
105 if (Process
->ApcHelper
)
108 *Handle
= Process
->ApcHelper
;
109 return ERROR_SUCCESS
;
113 /* Open it for the first time */
114 return WsProcOpenAsyncHelperDevice(Process
, Handle
);
122 INT ErrorCode
= WSAEFAULT
;
124 /* Create a new process */
125 CurrentWsProcess
= WsProcAllocate();
128 if (CurrentWsProcess
)
130 /* Initialize the process */
131 ErrorCode
= WsProcInitialize(CurrentWsProcess
);
135 /* No memory for the process object */
136 ErrorCode
= WSA_NOT_ENOUGH_MEMORY
;
144 WsProcGetTCatalog(IN PWSPROCESS Process
)
146 /* Check if the catalogs have been modified */
147 if (WsCheckCatalogState(Process
->ProtocolCatalogEvent
))
149 /* Modification happened, reload them */
150 WsTcRefreshFromRegistry(Process
->ProtocolCatalog
,
151 Process
->ProtocolCatalogEvent
);
155 return Process
->ProtocolCatalog
;
160 WsProcGetNsCatalog(IN PWSPROCESS Process
)
162 /* Check if the catalogs have been modified */
163 if (WsCheckCatalogState(Process
->NamespaceCatalogEvent
))
165 /* Modification happened, reload them */
166 WsNcRefreshFromRegistry(Process
->NamespaceCatalog
,
167 Process
->NamespaceCatalogEvent
);
171 return Process
->NamespaceCatalog
;
176 WsProcDetachSocket(IN PWSPROCESS Process
,
177 IN PWAH_HANDLE Handle
)
179 PWSSOCKET Socket
= (PWSSOCKET
)Handle
;
181 /* Disassociate this socket from the table */
182 WahRemoveHandleContext(WsSockHandleTable
, Handle
);
184 /* If this is isn't an IFS socket */
185 if (!Socket
->Provider
)
187 /* Check if we have an active handle helper */
188 if (Process
->HandleHelper
)
191 WahCloseSocketHandle(Process
->HandleHelper
, (SOCKET
)Socket
->Handle
);
195 /* Remove a reference and return */
196 WsSockDereference(Socket
);
202 CleanupNamespaceProviders(IN PVOID Callback
,
203 IN PNSCATALOG_ENTRY Entry
)
205 PNS_PROVIDER Provider
;
207 /* Get the provider */
208 Provider
= Entry
->Provider
;
212 WsNpNSPCleanup(Provider
);
221 CleanupProtocolProviders(IN PVOID Callback
,
222 IN PTCATALOG_ENTRY Entry
)
227 /* Get the provider */
228 Provider
= Entry
->Provider
;
232 WsTpWSPCleanup(Provider
, &ErrorCode
);
241 WsProcDelete(IN PWSPROCESS Process
)
243 /* Check if we didn't even initialize yet */
244 if (!Process
->LockReady
) return;
246 /* No more current process */
247 CurrentWsProcess
= NULL
;
249 /* If we have a socket table */
250 if (WsSockHandleTable
)
252 /* Enumerate the sockets with a delete callback */
253 WahEnumerateHandleContexts(WsSockHandleTable
,
258 /* Close APC Helper */
259 if (Process
->ApcHelper
) WahCloseApcHelper(Process
->ApcHelper
);
261 /* Close handle helper */
262 if (Process
->HandleHelper
) WahCloseHandleHelper(Process
->HandleHelper
);
264 /* Check for notification helper */
265 if (Process
->NotificationHelper
)
267 /* Close notification helper */
268 WahCloseNotificationHandleHelper(Process
->NotificationHelper
);
271 /* Check if we have a protocol catalog*/
272 if (Process
->ProtocolCatalog
)
274 /* Enumerate it to clean it up */
275 WsTcEnumerateCatalogItems(Process
->ProtocolCatalog
,
276 CleanupProtocolProviders
,
280 WsTcDelete(Process
->ProtocolCatalog
);
281 Process
->ProtocolCatalog
= NULL
;
284 /* Check if we have a namespace catalog*/
285 if (Process
->NamespaceCatalog
)
287 /* Enumerate it to clean it up */
288 WsNcEnumerateCatalogItems(Process
->NamespaceCatalog
,
289 CleanupNamespaceProviders
,
293 WsNcDelete(Process
->NamespaceCatalog
);
294 Process
->NamespaceCatalog
= NULL
;
297 /* Delete the thread lock */
298 DeleteCriticalSection((LPCRITICAL_SECTION
)&Process
->ThreadLock
);
303 WsProcSetVersion(IN PWSPROCESS Process
,
304 IN WORD VersionRequested
)
307 WORD OldMajor
, OldMinor
;
309 /* Get the version data */
310 Major
= LOBYTE(VersionRequested
);
311 Minor
= HIBYTE(VersionRequested
);
312 OldMajor
= LOBYTE(Process
->Version
);
313 OldMinor
= HIBYTE(Process
->Version
);
315 /* Check if we're going lower */
316 if ((Major
< OldMajor
) || ((Major
== OldMajor
) && (Minor
< OldMinor
)))
318 /* Set the new version */
319 Process
->Version
= VersionRequested
;