2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
1999-12-22 14:48:30 +00:00
|
|
|
*
|
2000-02-29 23:57:47 +00:00
|
|
|
* reactos/subsys/csrss/api/wapi.c
|
1999-12-22 14:48:30 +00:00
|
|
|
*
|
|
|
|
* Initialize the CSRSS subsystem server process.
|
|
|
|
*
|
|
|
|
* ReactOS Operating System
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2004-04-09 20:03:21 +00:00
|
|
|
#include <csrss/csrss.h>
|
2002-09-08 10:23:54 +00:00
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
#include <ntdll/rtl.h>
|
2002-09-07 15:13:13 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
#include "api.h"
|
|
|
|
|
1999-12-30 01:51:42 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
HANDLE CsrssApiHeap;
|
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
static unsigned ApiDefinitionsCount = 0;
|
|
|
|
static PCSRSS_API_DEFINITION ApiDefinitions = NULL;
|
|
|
|
|
1999-12-22 14:48:30 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
NTSTATUS FASTCALL
|
|
|
|
CsrApiRegisterDefinitions(PCSRSS_API_DEFINITION NewDefinitions)
|
1999-12-22 14:48:30 +00:00
|
|
|
{
|
2003-12-02 11:38:47 +00:00
|
|
|
unsigned NewCount;
|
|
|
|
PCSRSS_API_DEFINITION Scan;
|
|
|
|
PCSRSS_API_DEFINITION New;
|
|
|
|
|
|
|
|
NewCount = 0;
|
|
|
|
for (Scan = NewDefinitions; 0 != Scan->Handler; Scan++)
|
|
|
|
{
|
|
|
|
NewCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
New = RtlAllocateHeap(CsrssApiHeap, 0,
|
|
|
|
(ApiDefinitionsCount + NewCount)
|
|
|
|
* sizeof(CSRSS_API_DEFINITION));
|
|
|
|
if (NULL == New)
|
|
|
|
{
|
|
|
|
DPRINT1("Unable to allocate memory\n");
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
if (0 != ApiDefinitionsCount)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(New, ApiDefinitions,
|
|
|
|
ApiDefinitionsCount * sizeof(CSRSS_API_DEFINITION));
|
|
|
|
RtlFreeHeap(CsrssApiHeap, 0, ApiDefinitions);
|
|
|
|
}
|
|
|
|
RtlCopyMemory(New + ApiDefinitionsCount, NewDefinitions,
|
|
|
|
NewCount * sizeof(CSRSS_API_DEFINITION));
|
|
|
|
ApiDefinitions = New;
|
|
|
|
ApiDefinitionsCount += NewCount;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID FASTCALL
|
|
|
|
CsrApiCallHandler(PCSRSS_PROCESS_DATA ProcessData,
|
|
|
|
PCSRSS_API_REQUEST Request,
|
|
|
|
PCSRSS_API_REPLY Reply)
|
|
|
|
{
|
|
|
|
BOOL Found;
|
|
|
|
unsigned DefIndex;
|
|
|
|
|
|
|
|
Found = FALSE;
|
|
|
|
for (DefIndex = 0; ! Found && DefIndex < ApiDefinitionsCount; DefIndex++)
|
|
|
|
{
|
|
|
|
if (ApiDefinitions[DefIndex].Type == Request->Type)
|
|
|
|
{
|
|
|
|
if (Request->Header.DataSize < ApiDefinitions[DefIndex].MinRequestSize)
|
|
|
|
{
|
|
|
|
DPRINT1("Request type %d min request size %d actual %d\n",
|
|
|
|
Request->Type, ApiDefinitions[DefIndex].MinRequestSize,
|
|
|
|
Request->Header.DataSize);
|
|
|
|
Reply->Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(ApiDefinitions[DefIndex].Handler)(ProcessData, Request, Reply);
|
|
|
|
Found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! Found)
|
|
|
|
{
|
2003-12-05 08:43:16 +00:00
|
|
|
DPRINT1("CSR: Unknown request type 0x%x\n", Request->Type);
|
|
|
|
Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
|
2004-04-09 20:03:21 +00:00
|
|
|
Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
|
2003-12-02 11:38:47 +00:00
|
|
|
Reply->Status = STATUS_INVALID_SYSTEM_SERVICE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-03 17:15:02 +00:00
|
|
|
static void STDCALL
|
|
|
|
ClientConnectionThread(HANDLE ServerPort)
|
2003-12-02 11:38:47 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
LPC_MAX_MESSAGE LpcReply;
|
|
|
|
LPC_MAX_MESSAGE LpcRequest;
|
|
|
|
PCSRSS_API_REQUEST Request;
|
|
|
|
PCSRSS_PROCESS_DATA ProcessData;
|
|
|
|
PCSRSS_API_REPLY Reply;
|
1999-12-22 14:48:30 +00:00
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
Reply = NULL;
|
1999-12-22 14:48:30 +00:00
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
Status = NtReplyWaitReceivePort(ServerPort,
|
|
|
|
0,
|
|
|
|
&Reply->Header,
|
|
|
|
&LpcRequest.Header);
|
|
|
|
if (! NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("CSR: NtReplyWaitReceivePort failed\n");
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
2003-12-02 11:38:47 +00:00
|
|
|
}
|
2000-04-03 21:54:42 +00:00
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
if (LpcRequest.Header.MessageType == LPC_PORT_CLOSED)
|
|
|
|
{
|
2005-01-26 00:03:05 +00:00
|
|
|
CsrFreeProcessData( LpcRequest.Header.ClientId.UniqueProcess );
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
2003-12-02 11:38:47 +00:00
|
|
|
}
|
2001-06-23 19:20:01 +00:00
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
Request = (PCSRSS_API_REQUEST)&LpcRequest;
|
|
|
|
Reply = (PCSRSS_API_REPLY)&LpcReply;
|
1999-12-22 14:48:30 +00:00
|
|
|
|
2005-01-26 00:03:05 +00:00
|
|
|
ProcessData = CsrGetProcessData(LpcRequest.Header.ClientId.UniqueProcess);
|
2004-07-03 17:15:02 +00:00
|
|
|
if (ProcessData == NULL)
|
|
|
|
{
|
2005-01-26 00:03:05 +00:00
|
|
|
DPRINT1("CSR: Message %d: Unable to find data for process 0x%x\n",
|
|
|
|
LpcRequest.Header.MessageType, LpcRequest.Header.ClientId.UniqueProcess);
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-27 12:21:32 +00:00
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
CsrApiCallHandler(ProcessData, Request, Reply);
|
|
|
|
}
|
2004-07-03 17:15:02 +00:00
|
|
|
NtClose(ServerPort);
|
|
|
|
RtlRosExitUserThread(STATUS_SUCCESS);
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* NAME
|
|
|
|
* Thread_Api
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* Handle connection requests from clients to the port
|
|
|
|
* "\Windows\ApiPort".
|
|
|
|
*/
|
2004-07-03 17:15:02 +00:00
|
|
|
void STDCALL
|
|
|
|
ServerApiPortThead(PVOID PortHandle)
|
1999-12-22 14:48:30 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2000-04-03 21:54:42 +00:00
|
|
|
LPC_MAX_MESSAGE Request;
|
1999-12-22 14:48:30 +00:00
|
|
|
HANDLE ServerPort;
|
2000-04-03 21:54:42 +00:00
|
|
|
HANDLE ServerThread;
|
2001-12-02 23:34:43 +00:00
|
|
|
PCSRSS_PROCESS_DATA ProcessData;
|
1999-12-22 14:48:30 +00:00
|
|
|
|
2000-02-27 02:12:07 +00:00
|
|
|
CsrInitProcessData();
|
2000-03-22 18:36:00 +00:00
|
|
|
|
1999-12-22 14:48:30 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2003-12-02 11:38:47 +00:00
|
|
|
LPC_SECTION_READ LpcRead;
|
2004-07-03 17:15:02 +00:00
|
|
|
ServerPort = NULL;
|
2001-12-02 23:34:43 +00:00
|
|
|
|
2000-04-03 21:54:42 +00:00
|
|
|
Status = NtListenPort(PortHandle, &Request.Header);
|
1999-12-22 14:48:30 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-12-02 11:38:47 +00:00
|
|
|
DPRINT1("CSR: NtListenPort() failed\n");
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
|
|
|
Status = NtAcceptConnectPort(&ServerPort,
|
|
|
|
PortHandle,
|
|
|
|
NULL,
|
|
|
|
1,
|
|
|
|
0,
|
2001-12-02 23:34:43 +00:00
|
|
|
&LpcRead);
|
1999-12-22 14:48:30 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-12-02 11:38:47 +00:00
|
|
|
DPRINT1("CSR: NtAcceptConnectPort() failed\n");
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-26 00:03:05 +00:00
|
|
|
ProcessData = CsrCreateProcessData(Request.Header.ClientId.UniqueProcess);
|
2004-07-03 17:15:02 +00:00
|
|
|
if (ProcessData == NULL)
|
|
|
|
{
|
2005-01-26 00:03:05 +00:00
|
|
|
DPRINT1("Unable to allocate or find data for process 0x%x\n",
|
|
|
|
Request.Header.ClientId.UniqueProcess);
|
2004-07-03 17:15:02 +00:00
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
break;
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
2004-07-03 17:15:02 +00:00
|
|
|
|
2001-12-02 23:34:43 +00:00
|
|
|
|
|
|
|
ProcessData->CsrSectionViewBase = LpcRead.ViewBase;
|
|
|
|
ProcessData->CsrSectionViewSize = LpcRead.ViewSize;
|
1999-12-22 14:48:30 +00:00
|
|
|
|
|
|
|
Status = NtCompleteConnectPort(ServerPort);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-12-02 11:38:47 +00:00
|
|
|
DPRINT1("CSR: NtCompleteConnectPort() failed\n");
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlCreateUserThread(NtCurrentProcess(),
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-07-03 17:15:02 +00:00
|
|
|
(PTHREAD_START_ROUTINE)ClientConnectionThread,
|
1999-12-22 14:48:30 +00:00
|
|
|
ServerPort,
|
2000-04-03 21:54:42 +00:00
|
|
|
&ServerThread,
|
1999-12-22 14:48:30 +00:00
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-12-02 11:38:47 +00:00
|
|
|
DPRINT1("CSR: Unable to create server thread\n");
|
2004-07-03 17:15:02 +00:00
|
|
|
break;
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
2000-04-03 21:54:42 +00:00
|
|
|
NtClose(ServerThread);
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
2004-07-03 17:15:02 +00:00
|
|
|
if (ServerPort)
|
|
|
|
{
|
|
|
|
NtClose(ServerPort);
|
|
|
|
}
|
|
|
|
NtClose(PortHandle);
|
|
|
|
NtTerminateThread(NtCurrentThread(), Status);
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2001-08-14 12:57:16 +00:00
|
|
|
/* EOF */
|