- 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
@ -367,6 +362,7 @@ ServerSbApiPortThread (HANDLE hSbApiPortListen)
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", DPRINT1("CSR: %s: NtListenPort(SB) failed (Status=0x%08lx)\n",
@ -374,13 +370,8 @@ ServerSbApiPortThread (HANDLE hSbApiPortListen)
} else { } else {
DPRINT("-- 1\n"); DPRINT("-- 1\n");
Status = NtAcceptConnectPort(&hConnectedPort, Status = NtAcceptConnectPort(&hConnectedPort,
#ifdef NTLPC
NULL, NULL,
&Request, &Request,
#else
hSbApiPortListen,
NULL,
#endif
TRUE, TRUE,
NULL, NULL,
NULL); NULL);
@ -397,7 +388,6 @@ DPRINT("-- 2\n");
__FUNCTION__, Status); __FUNCTION__, Status);
} else { } else {
DPRINT("-- 3\n"); DPRINT("-- 3\n");
/* /*
* Tell the init thread the SM gave the * Tell the init thread the SM gave the
* green light for boostrapping. * green light for boostrapping.
@ -422,6 +412,7 @@ DPRINT("-- 4\n");
__FUNCTION__, Status); __FUNCTION__, Status);
break; break;
} }
switch (Request.u2.s2.Type) //fix .h PORT_MESSAGE_TYPE(Request)) switch (Request.u2.s2.Type) //fix .h PORT_MESSAGE_TYPE(Request))
{ {
/* TODO */ /* TODO */
@ -434,6 +425,7 @@ DPRINT("-- 5\n");
} }
} }
} }
DPRINT("CSR: %s: terminating!\n", __FUNCTION__); DPRINT("CSR: %s: terminating!\n", __FUNCTION__);
if(hConnectedPort) NtClose (hConnectedPort); if(hConnectedPort) NtClose (hConnectedPort);
NtClose (hSbApiPortListen); NtClose (hSbApiPortListen);

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,
#ifdef NTLPC
(PTHREAD_START_ROUTINE)ClientConnectionThread); (PTHREAD_START_ROUTINE)ClientConnectionThread);
#else
ServerApiPortThread);
#endif
} }
/********************************************************************** /**********************************************************************