- Do not leak ports.

- Use threads. This should allow shutdown.
- Fix indentation.

svn path=/trunk/; revision=27176
This commit is contained in:
Dmitry Gorbachev 2007-06-14 19:09:32 +00:00
parent 076ca93553
commit e2299b4583
5 changed files with 90 additions and 101 deletions

View file

@ -174,6 +174,10 @@ NTSTATUS STDCALL CsrFreeProcessData(HANDLE Pid)
{ {
NtUnmapViewOfSection(NtCurrentProcess(), pProcessData->CsrSectionViewBase); NtUnmapViewOfSection(NtCurrentProcess(), pProcessData->CsrSectionViewBase);
} }
if (pProcessData->ServerCommunicationPort)
{
NtClose(pProcessData->ServerCommunicationPort);
}
if (pPrevProcessData) if (pPrevProcessData)
{ {
pPrevProcessData->next = pProcessData->next; pPrevProcessData->next = pProcessData->next;

View file

@ -19,6 +19,8 @@
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
extern HANDLE hApiPort;
HANDLE CsrssApiHeap = (HANDLE) 0; HANDLE CsrssApiHeap = (HANDLE) 0;
static unsigned ApiDefinitionsCount = 0; static unsigned ApiDefinitionsCount = 0;
@ -132,13 +134,8 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request,
DPRINT("CSR: %s: Handling: %p\n", __FUNCTION__, Request); DPRINT("CSR: %s: Handling: %p\n", __FUNCTION__, Request);
Status = NtAcceptConnectPort(&ServerPort, Status = NtAcceptConnectPort(&ServerPort,
#ifdef NTLPC
NULL, NULL,
Request, Request,
#else
hApiListenPort,
NULL,
#endif
TRUE, TRUE,
0, 0,
& LpcRead); & LpcRead);
@ -163,6 +160,7 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request,
ProcessData->CsrSectionViewBase = LpcRead.ViewBase; ProcessData->CsrSectionViewBase = LpcRead.ViewBase;
ProcessData->CsrSectionViewSize = LpcRead.ViewSize; ProcessData->CsrSectionViewSize = LpcRead.ViewSize;
ProcessData->ServerCommunicationPort = ServerPort;
Status = NtCompleteConnectPort(ServerPort); Status = NtCompleteConnectPort(ServerPort);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -171,7 +169,6 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request,
return Status; return Status;
} }
#if !defined(NTLPC) /* ReactOS LPC */
HANDLE ServerThread = (HANDLE) 0; HANDLE ServerThread = (HANDLE) 0;
Status = RtlCreateUserThread(NtCurrentProcess(), Status = RtlCreateUserThread(NtCurrentProcess(),
NULL, NULL,
@ -190,7 +187,6 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request,
} }
NtClose(ServerThread); NtClose(ServerThread);
#endif
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
DPRINT("CSR: %s done\n", __FUNCTION__); DPRINT("CSR: %s done\n", __FUNCTION__);
@ -216,7 +212,7 @@ ClientConnectionThread(HANDLE ServerPort)
for (;;) for (;;)
{ {
/* Send the reply and wait for a new request */ /* Send the reply and wait for a new request */
Status = NtReplyWaitReceivePort(ServerPort, Status = NtReplyWaitReceivePort(hApiPort,
0, 0,
&Reply->Header, &Reply->Header,
&Request->Header); &Request->Header);
@ -231,10 +227,7 @@ ClientConnectionThread(HANDLE ServerPort)
{ {
DPRINT("Port died, oh well\n"); DPRINT("Port died, oh well\n");
CsrFreeProcessData( Request->Header.ClientId.UniqueProcess ); CsrFreeProcessData( Request->Header.ClientId.UniqueProcess );
//NtClose() break;
Reply = NULL;
continue;
//break;
} }
if (Request->Header.u2.s2.Type == LPC_CONNECTION_REQUEST) if (Request->Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
@ -296,7 +289,7 @@ ClientConnectionThread(HANDLE ServerPort)
} }
/* Close the port and exit the thread */ /* Close the port and exit the thread */
NtClose(ServerPort); // NtClose(ServerPort);
DPRINT("CSR: %s done\n", __FUNCTION__); DPRINT("CSR: %s done\n", __FUNCTION__);
RtlExitUserThread(STATUS_SUCCESS); RtlExitUserThread(STATUS_SUCCESS);
@ -310,6 +303,7 @@ ClientConnectionThread(HANDLE ServerPort)
* Handle connection requests from clients to the port * Handle connection requests from clients to the port
* "\Windows\ApiPort". * "\Windows\ApiPort".
*/ */
#if 0
DWORD STDCALL DWORD STDCALL
ServerApiPortThread (HANDLE hApiListenPort) ServerApiPortThread (HANDLE hApiListenPort)
{ {
@ -344,6 +338,7 @@ ServerApiPortThread (HANDLE hApiListenPort)
NtTerminateThread(NtCurrentThread(), Status); NtTerminateThread(NtCurrentThread(), Status);
return 0; return 0;
} }
#endif
/********************************************************************** /**********************************************************************
* NAME * NAME
@ -357,88 +352,85 @@ ServerApiPortThread (HANDLE hApiListenPort)
DWORD STDCALL DWORD STDCALL
ServerSbApiPortThread (HANDLE hSbApiPortListen) ServerSbApiPortThread (HANDLE hSbApiPortListen)
{ {
HANDLE hConnectedPort = (HANDLE) 0; HANDLE hConnectedPort = (HANDLE) 0;
PORT_MESSAGE Request; PORT_MESSAGE Request;
PVOID Context = NULL; PVOID Context = NULL;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PPORT_MESSAGE Reply = NULL; PPORT_MESSAGE Reply = NULL;
DPRINT("CSR: %s called\n", __FUNCTION__); DPRINT("CSR: %s called\n", __FUNCTION__);
RtlZeroMemory(&Request, sizeof(PORT_MESSAGE)); RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
Status = NtListenPort (hSbApiPortListen, & Request); Status = NtListenPort (hSbApiPortListen, & Request);
if (!NT_SUCCESS(Status))
{ if (!NT_SUCCESS(Status))
DPRINT1("CSR: %s: NtListenPort(SB) failed (Status=0x%08lx)\n", {
__FUNCTION__, Status); DPRINT1("CSR: %s: NtListenPort(SB) failed (Status=0x%08lx)\n",
} else { __FUNCTION__, Status);
DPRINT("-- 1\n"); } else {
Status = NtAcceptConnectPort (& hConnectedPort, DPRINT("-- 1\n");
#ifdef NTLPC Status = NtAcceptConnectPort(&hConnectedPort,
NULL, NULL,
&Request, &Request,
#else TRUE,
hSbApiPortListen, NULL,
NULL, NULL);
#endif if(!NT_SUCCESS(Status))
TRUE, {
NULL, DPRINT1("CSR: %s: NtAcceptConnectPort() failed (Status=0x%08lx)\n",
NULL); __FUNCTION__, Status);
if(!NT_SUCCESS(Status)) } else {
{ DPRINT("-- 2\n");
DPRINT1("CSR: %s: NtAcceptConnectPort() failed (Status=0x%08lx)\n", Status = NtCompleteConnectPort (hConnectedPort);
__FUNCTION__, Status); if(!NT_SUCCESS(Status))
} else { {
DPRINT("-- 2\n"); DPRINT1("CSR: %s: NtCompleteConnectPort() failed (Status=0x%08lx)\n",
Status = NtCompleteConnectPort (hConnectedPort); __FUNCTION__, Status);
if(!NT_SUCCESS(Status)) } else {
{ DPRINT("-- 3\n");
DPRINT1("CSR: %s: NtCompleteConnectPort() failed (Status=0x%08lx)\n", /*
__FUNCTION__, Status); * Tell the init thread the SM gave the
} else { * green light for boostrapping.
DPRINT("-- 3\n"); */
Status = NtSetEvent (hBootstrapOk, NULL);
/* if(!NT_SUCCESS(Status))
* Tell the init thread the SM gave the {
* green light for boostrapping. DPRINT1("CSR: %s: NtSetEvent failed (Status=0x%08lx)\n",
*/ __FUNCTION__, Status);
Status = NtSetEvent (hBootstrapOk, NULL); }
if(!NT_SUCCESS(Status)) /* Wait for messages from the SM */
{ DPRINT("-- 4\n");
DPRINT1("CSR: %s: NtSetEvent failed (Status=0x%08lx)\n", while (TRUE)
__FUNCTION__, Status); {
} Status = NtReplyWaitReceivePort(hConnectedPort,
/* Wait for messages from the SM */ Context,
DPRINT("-- 4\n"); Reply,
while (TRUE) &Request);
{ if(!NT_SUCCESS(Status))
Status = NtReplyWaitReceivePort(hConnectedPort, {
Context, DPRINT1("CSR: %s: NtReplyWaitReceivePort failed (Status=0x%08lx)\n",
Reply, __FUNCTION__, Status);
& Request); break;
if(!NT_SUCCESS(Status)) }
{
DPRINT1("CSR: %s: NtReplyWaitReceivePort failed (Status=0x%08lx)\n", switch (Request.u2.s2.Type) //fix .h PORT_MESSAGE_TYPE(Request))
__FUNCTION__, Status); {
break; /* TODO */
} default:
switch (Request.u2.s2.Type)//fix .h PORT_MESSAGE_TYPE(Request)) DPRINT1("CSR: %s received message (type=%d)\n",
{ __FUNCTION__, Request.u2.s2.Type);
/* TODO */ }
default: DPRINT("-- 5\n");
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);
DPRINT("CSR: %s: terminating!\n", __FUNCTION__); NtTerminateThread (NtCurrentThread(), Status);
if(hConnectedPort) NtClose (hConnectedPort); return 0;
NtClose (hSbApiPortListen);
NtTerminateThread (NtCurrentThread(), Status);
return 0;
} }
/* EOF */ /* EOF */

View file

@ -6,9 +6,6 @@
<define name="__USE_W32API" /> <define name="__USE_W32API" />
<define name="_WIN32_WINNT">0x0600</define> <define name="_WIN32_WINNT">0x0600</define>
<define name="WINVER">0x0501</define> <define name="WINVER">0x0501</define>
<if property="NTLPC" value="1">
<define name="NTLPC" />
</if>
<library>nt</library> <library>nt</library>
<library>ntdll</library> <library>ntdll</library>
<library>smdll</library> <library>smdll</library>

View file

@ -47,6 +47,7 @@ typedef struct _CSRSS_PROCESS_DATA
HANDLE ConsoleEvent; HANDLE ConsoleEvent;
PVOID CsrSectionViewBase; PVOID CsrSectionViewBase;
ULONG CsrSectionViewSize; ULONG CsrSectionViewSize;
HANDLE ServerCommunicationPort;
struct _CSRSS_PROCESS_DATA * next; struct _CSRSS_PROCESS_DATA * next;
LIST_ENTRY ProcessEntry; LIST_ENTRY ProcessEntry;
PCONTROLDISPATCHER CtrlDispatcher; PCONTROLDISPATCHER CtrlDispatcher;

View file

@ -530,13 +530,8 @@ CsrpCreateApiPort (int argc, char ** argv, char ** envp)
CsrInitProcessData(); CsrInitProcessData();
return CsrpCreateListenPort (L"\\Windows\\ApiPort", return CsrpCreateListenPort(L"\\Windows\\ApiPort", &hApiPort,
& hApiPort, (PTHREAD_START_ROUTINE)ClientConnectionThread);
#ifdef NTLPC
(PTHREAD_START_ROUTINE)ClientConnectionThread);
#else
ServerApiPortThread);
#endif
} }
/********************************************************************** /**********************************************************************