2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
1999-06-08 22:50:59 +00:00
|
|
|
*
|
|
|
|
* csrss.c - Client/Server Runtime subsystem
|
2005-05-08 04:07:56 +00:00
|
|
|
*
|
1999-06-08 22:50:59 +00:00
|
|
|
* ReactOS Operating System
|
2005-05-08 04:07:56 +00:00
|
|
|
*
|
1999-06-08 22:50:59 +00:00
|
|
|
* --------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* This software is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this software; see the file COPYING.LIB. If not, write
|
|
|
|
* to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
|
2005-05-08 04:07:56 +00:00
|
|
|
* MA 02139, USA.
|
1999-06-08 22:50:59 +00:00
|
|
|
*
|
|
|
|
* --------------------------------------------------------------------
|
2005-05-08 04:07:56 +00:00
|
|
|
*
|
1999-06-08 22:50:59 +00:00
|
|
|
* 19990417 (Emanuele Aliberti)
|
|
|
|
* Do nothing native application skeleton
|
|
|
|
* 19990528 (Emanuele Aliberti)
|
|
|
|
* Compiled successfully with egcs 1.1.2
|
|
|
|
* 19990605 (Emanuele Aliberti)
|
|
|
|
* First standalone run under ReactOS (it
|
|
|
|
* actually does nothing but running).
|
|
|
|
*/
|
2005-06-20 11:56:10 +00:00
|
|
|
|
2005-07-26 08:55:25 +00:00
|
|
|
#include <csrss.h>
|
2000-03-22 18:36:00 +00:00
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
1999-06-08 22:50:59 +00:00
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
#define CSRP_MAX_ARGUMENT_COUNT 512
|
|
|
|
|
|
|
|
typedef struct _COMMAND_LINE_ARGUMENT
|
1999-06-08 22:50:59 +00:00
|
|
|
{
|
2005-02-26 15:06:19 +00:00
|
|
|
ULONG Count;
|
|
|
|
UNICODE_STRING Buffer;
|
|
|
|
PWSTR * Vector;
|
|
|
|
|
|
|
|
} COMMAND_LINE_ARGUMENT, *PCOMMAND_LINE_ARGUMENT;
|
|
|
|
|
2005-06-02 13:17:37 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters = NULL;
|
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* NAME PRIVATE
|
|
|
|
* CsrpParseCommandLine/3
|
|
|
|
*/
|
|
|
|
static NTSTATUS STDCALL
|
|
|
|
CsrpParseCommandLine (HANDLE ProcessHeap,
|
|
|
|
PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters,
|
|
|
|
PCOMMAND_LINE_ARGUMENT Argument)
|
|
|
|
{
|
|
|
|
INT i = 0;
|
|
|
|
INT afterlastspace = 0;
|
|
|
|
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
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])
|
1999-12-22 14:48:30 +00:00
|
|
|
{
|
2005-02-26 15:06:19 +00:00
|
|
|
if (Argument->Buffer.Buffer[i] == L' ')
|
1999-12-22 14:48:30 +00:00
|
|
|
{
|
2005-02-26 15:06:19 +00:00
|
|
|
Argument->Count ++;
|
|
|
|
Argument->Buffer.Buffer [i] = L'\0';
|
|
|
|
Argument->Vector [Argument->Count - 1] = & (Argument->Buffer.Buffer [afterlastspace]);
|
2000-02-27 02:12:07 +00:00
|
|
|
i++;
|
2005-02-26 15:06:19 +00:00
|
|
|
while (Argument->Buffer.Buffer [i] == L' ')
|
|
|
|
{
|
2000-02-27 02:12:07 +00:00
|
|
|
i++;
|
2005-02-26 15:06:19 +00:00
|
|
|
}
|
2000-02-27 02:12:07 +00:00
|
|
|
afterlastspace = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i++;
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
|
|
|
}
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
if (Argument->Buffer.Buffer [afterlastspace] != L'\0')
|
2000-02-27 02:12:07 +00:00
|
|
|
{
|
2005-02-26 15:06:19 +00:00
|
|
|
Argument->Count ++;
|
|
|
|
Argument->Buffer.Buffer [i] = L'\0';
|
|
|
|
Argument->Vector [Argument->Count - 1] = & (Argument->Buffer.Buffer [afterlastspace]);
|
2000-02-27 02:12:07 +00:00
|
|
|
}
|
2005-02-26 15:06:19 +00:00
|
|
|
|
2005-05-08 04:07:56 +00:00
|
|
|
return STATUS_SUCCESS;
|
2005-02-26 15:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* NAME PRIVATE
|
|
|
|
* CsrpFreeCommandLine/2
|
|
|
|
*/
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
static VOID STDCALL
|
|
|
|
CsrpFreeCommandLine (HANDLE ProcessHeap,
|
|
|
|
PCOMMAND_LINE_ARGUMENT Argument)
|
|
|
|
{
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2005-02-26 15:06:19 +00:00
|
|
|
RtlFreeHeap (ProcessHeap,
|
|
|
|
0,
|
|
|
|
Argument->Vector);
|
|
|
|
RtlFreeHeap (ProcessHeap,
|
|
|
|
0,
|
|
|
|
Argument->Buffer.Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Native process' entry point */
|
|
|
|
|
|
|
|
VOID STDCALL NtProcessStartup(PPEB Peb)
|
|
|
|
{
|
|
|
|
COMMAND_LINE_ARGUMENT CmdLineArg = {0};
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
PrintString("ReactOS Client/Server Run-Time %s (Build %s)\n",
|
|
|
|
KERNEL_RELEASE_STR,
|
|
|
|
KERNEL_VERSION_BUILD_STR);
|
2005-02-26 15:06:19 +00:00
|
|
|
|
|
|
|
RtlProcessParameters = RtlNormalizeProcessParams (Peb->ProcessParameters);
|
|
|
|
|
|
|
|
/*==================================================================
|
2005-03-20 22:55:05 +00:00
|
|
|
* Parse the command line: TODO actually parse the cl, because
|
|
|
|
* it is required to load hosted server DLLs.
|
2005-02-26 15:06:19 +00:00
|
|
|
*================================================================*/
|
|
|
|
Status = CsrpParseCommandLine (Peb->ProcessHeap,
|
|
|
|
RtlProcessParameters,
|
|
|
|
& CmdLineArg);
|
|
|
|
if(STATUS_SUCCESS != Status)
|
|
|
|
{
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT1("CSR: %s: CsrpParseCommandLine failed (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
2005-02-26 15:06:19 +00:00
|
|
|
}
|
|
|
|
/*==================================================================
|
|
|
|
* Initialize the Win32 environment subsystem server.
|
|
|
|
*================================================================*/
|
|
|
|
if (CsrServerInitialization (CmdLineArg.Count, CmdLineArg.Vector) == TRUE)
|
2000-02-27 02:12:07 +00:00
|
|
|
{
|
2005-05-08 04:07:56 +00:00
|
|
|
CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);
|
2005-02-26 15:06:19 +00:00
|
|
|
/*
|
|
|
|
* Terminate the current thread only.
|
|
|
|
*/
|
|
|
|
NtTerminateThread (NtCurrentThread(), 0);
|
2000-02-27 02:12:07 +00:00
|
|
|
}
|
1999-12-22 14:48:30 +00:00
|
|
|
else
|
|
|
|
{
|
2005-02-26 15:06:19 +00:00
|
|
|
DisplayString (L"CSR: CsrServerInitialization failed.\n");
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2005-05-08 04:07:56 +00:00
|
|
|
CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);
|
1999-12-22 14:48:30 +00:00
|
|
|
/*
|
2005-02-26 15:06:19 +00:00
|
|
|
* Tell the SM we failed.
|
1999-12-22 14:48:30 +00:00
|
|
|
*/
|
2005-02-26 15:06:19 +00:00
|
|
|
NtTerminateProcess (NtCurrentProcess(), 0);
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
1999-06-08 22:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|