mirror of
https://github.com/reactos/reactos.git
synced 2025-04-20 20:36:35 +00:00
CSR pre-init cleanup
svn path=/trunk/; revision=13748
This commit is contained in:
parent
01e577bd0d
commit
825a47e3ad
4 changed files with 214 additions and 67 deletions
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* reactos/subsys/csrss/api/wapi.c
|
* reactos/subsys/csrss/api/wapi.c
|
||||||
*
|
*
|
||||||
* Initialize the CSRSS subsystem server process.
|
* CSRSS port message processing
|
||||||
*
|
*
|
||||||
* ReactOS Operating System
|
* ReactOS Operating System
|
||||||
*
|
*
|
||||||
|
@ -147,14 +147,14 @@ ClientConnectionThread(HANDLE ServerPort)
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* NAME
|
* NAME
|
||||||
* Thread_Api
|
* ServerApiPortThread/1
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* Handle connection requests from clients to the port
|
* Handle connection requests from clients to the port
|
||||||
* "\Windows\ApiPort".
|
* "\Windows\ApiPort".
|
||||||
*/
|
*/
|
||||||
void STDCALL
|
void STDCALL
|
||||||
ServerApiPortThead(PVOID PortHandle)
|
ServerApiPortThread (PVOID PortHandle)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
LPC_MAX_MESSAGE Request;
|
LPC_MAX_MESSAGE Request;
|
||||||
|
@ -232,4 +232,51 @@ ServerApiPortThead(PVOID PortHandle)
|
||||||
NtTerminateThread(NtCurrentThread(), Status);
|
NtTerminateThread(NtCurrentThread(), Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* NAME
|
||||||
|
* ServerSbApiPortThread/1
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* Handle connection requests from SM to the port
|
||||||
|
* "\Windows\SbApiPort".
|
||||||
|
*/
|
||||||
|
VOID STDCALL
|
||||||
|
ServerSbApiPortThread (PVOID PortHandle)
|
||||||
|
{
|
||||||
|
HANDLE hSbApiPortListen = (HANDLE) PortHandle;
|
||||||
|
HANDLE hConnectedPort = (HANDLE) 0;
|
||||||
|
LPC_MAX_MESSAGE Request = {{0}};
|
||||||
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
while (TRUE)
|
||||||
|
{
|
||||||
|
Status = NtListenPort (hSbApiPortListen, & Request.Header);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("CSR: %s: NtListenPort(SB) failed\n", __FUNCTION__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Status = NtAcceptConnectPort (& hConnectedPort,
|
||||||
|
hSbApiPortListen,
|
||||||
|
NULL,
|
||||||
|
TRUE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if(!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("CSR: %s: NtAcceptConnectPort() failed\n", __FUNCTION__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Status = NtCompleteConnectPort (hConnectedPort);
|
||||||
|
if(!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("CSR: %s: NtCompleteConnectPort() failed\n", __FUNCTION__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* TODO: create thread for the connected port */
|
||||||
|
}
|
||||||
|
NtClose (hSbApiPortListen);
|
||||||
|
NtTerminateThread (NtCurrentThread(), Status);
|
||||||
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -38,42 +38,75 @@
|
||||||
|
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
|
|
||||||
/* Native process' entry point */
|
#define NDEBUG
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
VOID STDCALL NtProcessStartup(PPEB Peb)
|
#define CSRP_MAX_ARGUMENT_COUNT 512
|
||||||
|
|
||||||
|
typedef struct _COMMAND_LINE_ARGUMENT
|
||||||
{
|
{
|
||||||
PRTL_USER_PROCESS_PARAMETERS ProcParams;
|
ULONG Count;
|
||||||
PWSTR ArgBuffer;
|
UNICODE_STRING Buffer;
|
||||||
PWSTR *argv;
|
PWSTR * Vector;
|
||||||
ULONG argc = 0;
|
|
||||||
int i = 0;
|
|
||||||
int afterlastspace = 0;
|
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
||||||
HANDLE CsrssInitEvent;
|
|
||||||
UNICODE_STRING UnicodeString;
|
|
||||||
NTSTATUS Status;
|
|
||||||
|
|
||||||
ProcParams = RtlNormalizeProcessParams (Peb->ProcessParameters);
|
} COMMAND_LINE_ARGUMENT, *PCOMMAND_LINE_ARGUMENT;
|
||||||
|
|
||||||
argv = (PWSTR *)RtlAllocateHeap (Peb->ProcessHeap,
|
/**********************************************************************
|
||||||
0, 512 * sizeof(PWSTR));
|
* NAME PRIVATE
|
||||||
ArgBuffer = (PWSTR)RtlAllocateHeap (Peb->ProcessHeap,
|
* CsrpParseCommandLine/3
|
||||||
0,
|
*/
|
||||||
ProcParams->CommandLine.Length + sizeof(WCHAR));
|
static NTSTATUS STDCALL
|
||||||
memcpy (ArgBuffer,
|
CsrpParseCommandLine (HANDLE ProcessHeap,
|
||||||
ProcParams->CommandLine.Buffer,
|
PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters,
|
||||||
ProcParams->CommandLine.Length + sizeof(WCHAR));
|
PCOMMAND_LINE_ARGUMENT Argument)
|
||||||
|
{
|
||||||
|
INT i = 0;
|
||||||
|
INT afterlastspace = 0;
|
||||||
|
|
||||||
while (ArgBuffer[i])
|
|
||||||
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||||
|
|
||||||
|
RtlZeroMemory (Argument, sizeof (COMMAND_LINE_ARGUMENT));
|
||||||
|
|
||||||
|
Argument->Vector = (PWSTR *) RtlAllocateHeap (ProcessHeap,
|
||||||
|
0,
|
||||||
|
(CSRP_MAX_ARGUMENT_COUNT * sizeof Argument->Vector[0]));
|
||||||
|
if(NULL == Argument->Vector)
|
||||||
|
{
|
||||||
|
DPRINT("CSR: %s: no memory for Argument->Vector\n", __FUNCTION__);
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
Argument->Buffer.Length =
|
||||||
|
Argument->Buffer.MaximumLength =
|
||||||
|
RtlProcessParameters->CommandLine.Length
|
||||||
|
+ sizeof Argument->Buffer.Buffer [0]; /* zero terminated */
|
||||||
|
Argument->Buffer.Buffer =
|
||||||
|
(PWSTR) RtlAllocateHeap (ProcessHeap,
|
||||||
|
0,
|
||||||
|
Argument->Buffer.MaximumLength);
|
||||||
|
if(NULL == Argument->Buffer.Buffer)
|
||||||
|
{
|
||||||
|
DPRINT("CSR: %s: no memory for Argument->Buffer.Buffer\n", __FUNCTION__);
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlCopyMemory (Argument->Buffer.Buffer,
|
||||||
|
RtlProcessParameters->CommandLine.Buffer,
|
||||||
|
RtlProcessParameters->CommandLine.Length);
|
||||||
|
|
||||||
|
while (Argument->Buffer.Buffer [i])
|
||||||
{
|
{
|
||||||
if (ArgBuffer[i] == L' ')
|
if (Argument->Buffer.Buffer[i] == L' ')
|
||||||
{
|
{
|
||||||
argc++;
|
Argument->Count ++;
|
||||||
ArgBuffer[i] = L'\0';
|
Argument->Buffer.Buffer [i] = L'\0';
|
||||||
argv[argc-1] = &(ArgBuffer[afterlastspace]);
|
Argument->Vector [Argument->Count - 1] = & (Argument->Buffer.Buffer [afterlastspace]);
|
||||||
i++;
|
i++;
|
||||||
while (ArgBuffer[i] == L' ')
|
while (Argument->Buffer.Buffer [i] == L' ')
|
||||||
|
{
|
||||||
i++;
|
i++;
|
||||||
|
}
|
||||||
afterlastspace = i;
|
afterlastspace = i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -82,56 +115,122 @@ VOID STDCALL NtProcessStartup(PPEB Peb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ArgBuffer[afterlastspace] != L'\0')
|
if (Argument->Buffer.Buffer [afterlastspace] != L'\0')
|
||||||
{
|
{
|
||||||
argc++;
|
Argument->Count ++;
|
||||||
ArgBuffer[i] = L'\0';
|
Argument->Buffer.Buffer [i] = L'\0';
|
||||||
argv[argc-1] = &(ArgBuffer[afterlastspace]);
|
Argument->Vector [Argument->Count - 1] = & (Argument->Buffer.Buffer [afterlastspace]);
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* NAME PRIVATE
|
||||||
|
* CsrpFreeCommandLine/2
|
||||||
|
*/
|
||||||
|
|
||||||
|
static VOID STDCALL
|
||||||
|
CsrpFreeCommandLine (HANDLE ProcessHeap,
|
||||||
|
PCOMMAND_LINE_ARGUMENT Argument)
|
||||||
|
{
|
||||||
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||||
|
|
||||||
|
RtlFreeHeap (ProcessHeap,
|
||||||
|
0,
|
||||||
|
Argument->Vector);
|
||||||
|
RtlFreeHeap (ProcessHeap,
|
||||||
|
0,
|
||||||
|
Argument->Buffer.Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* NAME PRIVATE
|
||||||
|
* CsrpOpenKeInitDoneEvent/0
|
||||||
|
*/
|
||||||
|
static NTSTATUS STDCALL
|
||||||
|
CsrpOpenKeInitDoneEvent (PHANDLE CsrssInitEvent)
|
||||||
|
{
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
UNICODE_STRING EventName;
|
||||||
|
|
||||||
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
||||||
|
|
||||||
|
RtlInitUnicodeString(& EventName,
|
||||||
L"\\CsrssInitDone");
|
L"\\CsrssInitDone");
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes (& ObjectAttributes,
|
||||||
&UnicodeString,
|
& EventName,
|
||||||
EVENT_ALL_ACCESS,
|
EVENT_ALL_ACCESS,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
Status = NtOpenEvent(&CsrssInitEvent,
|
return NtOpenEvent (CsrssInitEvent,
|
||||||
EVENT_ALL_ACCESS,
|
EVENT_ALL_ACCESS,
|
||||||
&ObjectAttributes);
|
& ObjectAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Native process' entry point */
|
||||||
|
|
||||||
|
VOID STDCALL NtProcessStartup(PPEB Peb)
|
||||||
|
{
|
||||||
|
PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters = NULL;
|
||||||
|
COMMAND_LINE_ARGUMENT CmdLineArg = {0};
|
||||||
|
HANDLE CsrssInitEvent = (HANDLE) 0;
|
||||||
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
DPRINT("CSR: %s\n", __FUNCTION__);
|
||||||
|
|
||||||
|
RtlProcessParameters = RtlNormalizeProcessParams (Peb->ProcessParameters);
|
||||||
|
|
||||||
|
/*==================================================================
|
||||||
|
* Parse the command line.
|
||||||
|
*================================================================*/
|
||||||
|
Status = CsrpParseCommandLine (Peb->ProcessHeap,
|
||||||
|
RtlProcessParameters,
|
||||||
|
& CmdLineArg);
|
||||||
|
if(STATUS_SUCCESS != Status)
|
||||||
|
{
|
||||||
|
DbgPrint("CSR: CsrpParseCommandLine failed (Status=0x%08lx)\n",
|
||||||
|
Status);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Open the Ke notification event to notify we are OK after
|
||||||
|
* subsystem server initialization.
|
||||||
|
*/
|
||||||
|
Status = CsrpOpenKeInitDoneEvent(& CsrssInitEvent);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DbgPrint("CSR: Failed to open csrss notification event\n");
|
DbgPrint("CSR: CsrpOpenKeInitDoneEvent failed (Status=0x%08lx)\n",
|
||||||
|
Status);
|
||||||
}
|
}
|
||||||
if (CsrServerInitialization (argc, argv) == TRUE)
|
/*==================================================================
|
||||||
|
* Initialize the Win32 environment subsystem server.
|
||||||
|
*================================================================*/
|
||||||
|
if (CsrServerInitialization (CmdLineArg.Count, CmdLineArg.Vector) == TRUE)
|
||||||
{
|
{
|
||||||
|
/*=============================================================
|
||||||
|
* Tell Ke we are up and safe. If we fail to notify Ke, it will
|
||||||
|
* bugcheck the system with SESSION5_INITIALIZATION_FAILED.
|
||||||
|
* TODO: choose a better way to check user mode initialization
|
||||||
|
* is OK.
|
||||||
|
*===========================================================*/
|
||||||
|
NtSetEvent (CsrssInitEvent, NULL);
|
||||||
|
|
||||||
NtSetEvent(CsrssInitEvent,
|
CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);
|
||||||
NULL);
|
/*
|
||||||
|
* Terminate the current thread only.
|
||||||
RtlFreeHeap (Peb->ProcessHeap,
|
*/
|
||||||
0, argv);
|
NtTerminateThread (NtCurrentThread(), 0);
|
||||||
RtlFreeHeap (Peb->ProcessHeap,
|
|
||||||
0,
|
|
||||||
ArgBuffer);
|
|
||||||
|
|
||||||
/* terminate the current thread only */
|
|
||||||
NtTerminateThread( NtCurrentThread(), 0 );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisplayString( L"CSR: Subsystem initialization failed.\n" );
|
DisplayString (L"CSR: CsrServerInitialization failed.\n");
|
||||||
|
|
||||||
RtlFreeHeap (Peb->ProcessHeap,
|
|
||||||
0, argv);
|
|
||||||
RtlFreeHeap (Peb->ProcessHeap,
|
|
||||||
0,
|
|
||||||
ArgBuffer);
|
|
||||||
|
|
||||||
|
CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);
|
||||||
/*
|
/*
|
||||||
* Tell SM we failed.
|
* Tell the SM we failed.
|
||||||
*/
|
*/
|
||||||
NtTerminateProcess( NtCurrentProcess(), 0 );
|
NtTerminateProcess (NtCurrentProcess(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,8 @@ NTSTATUS FASTCALL CsrApiRegisterDefinitions(PCSRSS_API_DEFINITION NewDefinitions
|
||||||
VOID FASTCALL CsrApiCallHandler(PCSRSS_PROCESS_DATA ProcessData,
|
VOID FASTCALL CsrApiCallHandler(PCSRSS_PROCESS_DATA ProcessData,
|
||||||
PCSRSS_API_REQUEST Request,
|
PCSRSS_API_REQUEST Request,
|
||||||
PCSRSS_API_REPLY Reply);
|
PCSRSS_API_REPLY Reply);
|
||||||
VOID STDCALL ServerApiPortThead(PVOID PortHandle);
|
VOID STDCALL ServerApiPortThread (PVOID PortHandle);
|
||||||
|
VOID STDCALL ServerSbApiPortThread (PVOID PortHandle);
|
||||||
VOID Console_Api( DWORD Ignored );
|
VOID Console_Api( DWORD Ignored );
|
||||||
|
|
||||||
extern HANDLE CsrssApiHeap;
|
extern HANDLE CsrssApiHeap;
|
||||||
|
|
|
@ -335,7 +335,7 @@ DisplayString(L"CSR: CsrServerInitialization\n");
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
(PTHREAD_START_ROUTINE)ServerApiPortThead,
|
(PTHREAD_START_ROUTINE)ServerApiPortThread,
|
||||||
ApiPortHandle,
|
ApiPortHandle,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
Loading…
Reference in a new issue