Author: dgorbachev
Date: Thu Jun 14 23:09:32 2007
New Revision: 27176
URL:
http://svn.reactos.org/svn/reactos?rev=27176&view=rev
Log:
- Do not leak ports.
- Use threads. This should allow shutdown.
- Fix indentation.
Modified:
trunk/reactos/subsystems/win32/csrss/api/process.c
trunk/reactos/subsystems/win32/csrss/api/wapi.c
trunk/reactos/subsystems/win32/csrss/csrss.rbuild
trunk/reactos/subsystems/win32/csrss/include/api.h
trunk/reactos/subsystems/win32/csrss/init.c
Modified: trunk/reactos/subsystems/win32/csrss/api/process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/api…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/api/process.c (original)
+++ trunk/reactos/subsystems/win32/csrss/api/process.c Thu Jun 14 23:09:32 2007
@@ -174,6 +174,10 @@
{
NtUnmapViewOfSection(NtCurrentProcess(), pProcessData->CsrSectionViewBase);
}
+ if (pProcessData->ServerCommunicationPort)
+ {
+ NtClose(pProcessData->ServerCommunicationPort);
+ }
if (pPrevProcessData)
{
pPrevProcessData->next = pProcessData->next;
Modified: trunk/reactos/subsystems/win32/csrss/api/wapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/api…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/api/wapi.c (original)
+++ trunk/reactos/subsystems/win32/csrss/api/wapi.c Thu Jun 14 23:09:32 2007
@@ -18,6 +18,8 @@
#include <debug.h>
/* GLOBALS *******************************************************************/
+
+extern HANDLE hApiPort;
HANDLE CsrssApiHeap = (HANDLE) 0;
@@ -132,13 +134,8 @@
DPRINT("CSR: %s: Handling: %p\n", __FUNCTION__, Request);
Status = NtAcceptConnectPort(&ServerPort,
-#ifdef NTLPC
NULL,
Request,
-#else
- hApiListenPort,
- NULL,
-#endif
TRUE,
0,
& LpcRead);
@@ -163,6 +160,7 @@
ProcessData->CsrSectionViewBase = LpcRead.ViewBase;
ProcessData->CsrSectionViewSize = LpcRead.ViewSize;
+ ProcessData->ServerCommunicationPort = ServerPort;
Status = NtCompleteConnectPort(ServerPort);
if (!NT_SUCCESS(Status))
@@ -171,7 +169,6 @@
return Status;
}
-#if !defined(NTLPC) /* ReactOS LPC */
HANDLE ServerThread = (HANDLE) 0;
Status = RtlCreateUserThread(NtCurrentProcess(),
NULL,
@@ -190,7 +187,6 @@
}
NtClose(ServerThread);
-#endif
Status = STATUS_SUCCESS;
DPRINT("CSR: %s done\n", __FUNCTION__);
@@ -216,7 +212,7 @@
for (;;)
{
/* Send the reply and wait for a new request */
- Status = NtReplyWaitReceivePort(ServerPort,
+ Status = NtReplyWaitReceivePort(hApiPort,
0,
&Reply->Header,
&Request->Header);
@@ -231,10 +227,7 @@
{
DPRINT("Port died, oh well\n");
CsrFreeProcessData( Request->Header.ClientId.UniqueProcess );
- //NtClose()
- Reply = NULL;
- continue;
- //break;
+ break;
}
if (Request->Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
@@ -296,7 +289,7 @@
}
/* Close the port and exit the thread */
- NtClose(ServerPort);
+ // NtClose(ServerPort);
DPRINT("CSR: %s done\n", __FUNCTION__);
RtlExitUserThread(STATUS_SUCCESS);
@@ -310,6 +303,7 @@
* Handle connection requests from clients to the port
* "\Windows\ApiPort".
*/
+#if 0
DWORD STDCALL
ServerApiPortThread (HANDLE hApiListenPort)
{
@@ -344,6 +338,7 @@
NtTerminateThread(NtCurrentThread(), Status);
return 0;
}
+#endif
/**********************************************************************
* NAME
@@ -357,88 +352,85 @@
DWORD STDCALL
ServerSbApiPortThread (HANDLE hSbApiPortListen)
{
- HANDLE hConnectedPort = (HANDLE) 0;
- PORT_MESSAGE Request;
- PVOID Context = NULL;
- NTSTATUS Status = STATUS_SUCCESS;
+ HANDLE hConnectedPort = (HANDLE) 0;
+ PORT_MESSAGE Request;
+ PVOID Context = NULL;
+ NTSTATUS Status = STATUS_SUCCESS;
PPORT_MESSAGE Reply = NULL;
- DPRINT("CSR: %s called\n", __FUNCTION__);
+ DPRINT("CSR: %s called\n", __FUNCTION__);
RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
- Status = NtListenPort (hSbApiPortListen, & Request);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("CSR: %s: NtListenPort(SB) failed (Status=0x%08lx)\n",
- __FUNCTION__, Status);
- } else {
-DPRINT("-- 1\n");
- Status = NtAcceptConnectPort (& hConnectedPort,
-#ifdef NTLPC
- NULL,
- &Request,
-#else
- hSbApiPortListen,
- NULL,
-#endif
- TRUE,
- NULL,
- NULL);
- if(!NT_SUCCESS(Status))
- {
- DPRINT1("CSR: %s: NtAcceptConnectPort() failed (Status=0x%08lx)\n",
- __FUNCTION__, Status);
- } else {
-DPRINT("-- 2\n");
- Status = NtCompleteConnectPort (hConnectedPort);
- if(!NT_SUCCESS(Status))
- {
- DPRINT1("CSR: %s: NtCompleteConnectPort() failed (Status=0x%08lx)\n",
- __FUNCTION__, Status);
- } else {
-DPRINT("-- 3\n");
-
- /*
- * Tell the init thread the SM gave the
- * green light for boostrapping.
- */
- Status = NtSetEvent (hBootstrapOk, NULL);
- if(!NT_SUCCESS(Status))
- {
- DPRINT1("CSR: %s: NtSetEvent failed (Status=0x%08lx)\n",
- __FUNCTION__, Status);
- }
- /* Wait for messages from the SM */
-DPRINT("-- 4\n");
- while (TRUE)
- {
- Status = NtReplyWaitReceivePort(hConnectedPort,
- Context,
- Reply,
- & Request);
- if(!NT_SUCCESS(Status))
- {
- DPRINT1("CSR: %s: NtReplyWaitReceivePort failed (Status=0x%08lx)\n",
- __FUNCTION__, Status);
- break;
- }
- switch (Request.u2.s2.Type)//fix .h PORT_MESSAGE_TYPE(Request))
- {
- /* TODO */
- default:
- DPRINT1("CSR: %s received message (type=%d)\n",
- __FUNCTION__, Request.u2.s2.Type);
- }
-DPRINT("-- 5\n");
- }
- }
- }
- }
- DPRINT("CSR: %s: terminating!\n", __FUNCTION__);
- if(hConnectedPort) NtClose (hConnectedPort);
- NtClose (hSbApiPortListen);
- NtTerminateThread (NtCurrentThread(), Status);
- return 0;
+ Status = NtListenPort (hSbApiPortListen, & Request);
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSR: %s: NtListenPort(SB) failed (Status=0x%08lx)\n",
+ __FUNCTION__, Status);
+ } else {
+ DPRINT("-- 1\n");
+ Status = NtAcceptConnectPort(&hConnectedPort,
+ NULL,
+ &Request,
+ TRUE,
+ NULL,
+ NULL);
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSR: %s: NtAcceptConnectPort() failed
(Status=0x%08lx)\n",
+ __FUNCTION__, Status);
+ } else {
+ DPRINT("-- 2\n");
+ Status = NtCompleteConnectPort (hConnectedPort);
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSR: %s: NtCompleteConnectPort() failed
(Status=0x%08lx)\n",
+ __FUNCTION__, Status);
+ } else {
+ DPRINT("-- 3\n");
+ /*
+ * Tell the init thread the SM gave the
+ * green light for boostrapping.
+ */
+ Status = NtSetEvent (hBootstrapOk, NULL);
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSR: %s: NtSetEvent failed (Status=0x%08lx)\n",
+ __FUNCTION__, Status);
+ }
+ /* Wait for messages from the SM */
+ DPRINT("-- 4\n");
+ while (TRUE)
+ {
+ Status = NtReplyWaitReceivePort(hConnectedPort,
+ Context,
+ Reply,
+ &Request);
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSR: %s: NtReplyWaitReceivePort failed
(Status=0x%08lx)\n",
+ __FUNCTION__, Status);
+ break;
+ }
+
+ switch (Request.u2.s2.Type) //fix .h PORT_MESSAGE_TYPE(Request))
+ {
+ /* TODO */
+ default:
+ DPRINT1("CSR: %s received message (type=%d)\n",
+ __FUNCTION__, Request.u2.s2.Type);
+ }
+ DPRINT("-- 5\n");
+ }
+ }
+ }
+ }
+
+ DPRINT("CSR: %s: terminating!\n", __FUNCTION__);
+ if(hConnectedPort) NtClose (hConnectedPort);
+ NtClose (hSbApiPortListen);
+ NtTerminateThread (NtCurrentThread(), Status);
+ return 0;
}
/* EOF */
Modified: trunk/reactos/subsystems/win32/csrss/csrss.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrss.rbuild (original)
+++ trunk/reactos/subsystems/win32/csrss/csrss.rbuild Thu Jun 14 23:09:32 2007
@@ -6,9 +6,6 @@
<define name="__USE_W32API" />
<define name="_WIN32_WINNT">0x0600</define>
<define name="WINVER">0x0501</define>
- <if property="NTLPC" value="1">
- <define name="NTLPC" />
- </if>
<library>nt</library>
<library>ntdll</library>
<library>smdll</library>
Modified: trunk/reactos/subsystems/win32/csrss/include/api.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/inc…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/include/api.h (original)
+++ trunk/reactos/subsystems/win32/csrss/include/api.h Thu Jun 14 23:09:32 2007
@@ -47,6 +47,7 @@
HANDLE ConsoleEvent;
PVOID CsrSectionViewBase;
ULONG CsrSectionViewSize;
+ HANDLE ServerCommunicationPort;
struct _CSRSS_PROCESS_DATA * next;
LIST_ENTRY ProcessEntry;
PCONTROLDISPATCHER CtrlDispatcher;
Modified: trunk/reactos/subsystems/win32/csrss/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/ini…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/init.c (original)
+++ trunk/reactos/subsystems/win32/csrss/init.c Thu Jun 14 23:09:32 2007
@@ -530,13 +530,8 @@
CsrInitProcessData();
- return CsrpCreateListenPort (L"\\Windows\\ApiPort",
- & hApiPort,
-#ifdef NTLPC
- (PTHREAD_START_ROUTINE)ClientConnectionThread);
-#else
- ServerApiPortThread);
-#endif
+ return CsrpCreateListenPort(L"\\Windows\\ApiPort", &hApiPort,
+ (PTHREAD_START_ROUTINE)ClientConnectionThread);
}
/**********************************************************************