Fix startup code for native NT processes.
smss, autocheck, csrss use new startup code.
Modified: trunk/reactos/subsys/csrss/csrss.c
Modified: trunk/reactos/subsys/csrss/csrss.xml
Modified: trunk/reactos/subsys/csrss/include/api.h
Modified: trunk/reactos/subsys/csrss/init.c
Modified: trunk/reactos/subsys/smss/smss.c
Modified: trunk/reactos/subsys/smss/smss.xml
_____
Modified: trunk/reactos/subsys/csrss/csrss.c
--- trunk/reactos/subsys/csrss/csrss.c 2005-10-08 22:40:04 UTC (rev
18364)
+++ trunk/reactos/subsys/csrss/csrss.c 2005-10-08 22:41:49 UTC (rev
18365)
@@ -22,14 +22,6 @@
* MA 02139, USA.
*
* --------------------------------------------------------------------
- *
- * 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).
*/
#include <csrss.h>
@@ -37,158 +29,35 @@
#define NDEBUG
#include <debug.h>
-#define CSRP_MAX_ARGUMENT_COUNT 512
-
-typedef struct _COMMAND_LINE_ARGUMENT
+int _cdecl _main(int argc,
+ char *argv[],
+ char *envp[],
+ int DebugFlag)
{
- ULONG Count;
- UNICODE_STRING Buffer;
- PWSTR * Vector;
-
-} COMMAND_LINE_ARGUMENT, *PCOMMAND_LINE_ARGUMENT;
-
-PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters = NULL;
-
-/**********************************************************************
- * 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;
-
-
- 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 (Argument->Buffer.Buffer[i] == L' ')
- {
- Argument->Count ++;
- Argument->Buffer.Buffer [i] = L'\0';
- Argument->Vector [Argument->Count - 1] = &
(Argument->Buffer.Buffer [afterlastspace]);
- i++;
- while (Argument->Buffer.Buffer [i] == L' ')
- {
- i++;
- }
- afterlastspace = i;
- }
- else
- {
- i++;
- }
- }
-
- if (Argument->Buffer.Buffer [afterlastspace] != L'\0')
- {
- Argument->Count ++;
- Argument->Buffer.Buffer [i] = L'\0';
- Argument->Vector [Argument->Count - 1] = &
(Argument->Buffer.Buffer [afterlastspace]);
- }
-
- 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);
-}
-
-
-/* Native process' entry point */
-
-VOID STDCALL NtProcessStartup(PPEB Peb)
-{
- COMMAND_LINE_ARGUMENT CmdLineArg = {0};
- NTSTATUS Status = STATUS_SUCCESS;
-
- PrintString("ReactOS Client/Server Run-Time %s (Build %s)\n",
- KERNEL_RELEASE_STR,
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ PrintString("ReactOS Client/Server Run-Time (Build %s)\n",
KERNEL_VERSION_BUILD_STR);
- RtlProcessParameters = RtlNormalizeProcessParams
(Peb->ProcessParameters);
-
/*==================================================================
- * Parse the command line: TODO actually parse the cl, because
- * it is required to load hosted server DLLs.
- *================================================================*/
- Status = CsrpParseCommandLine (Peb->ProcessHeap,
- RtlProcessParameters,
- & CmdLineArg);
- if(STATUS_SUCCESS != Status)
- {
- DPRINT1("CSR: %s: CsrpParseCommandLine failed
(Status=0x%08lx)\n",
- __FUNCTION__, Status);
- }
- /*==================================================================
* Initialize the Win32 environment subsystem server.
*================================================================*/
- if (CsrServerInitialization (CmdLineArg.Count, CmdLineArg.Vector) ==
TRUE)
+ if (CsrServerInitialization (argc, argv, envp) == TRUE)
{
- CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);
/*
* Terminate the current thread only.
*/
- NtTerminateThread (NtCurrentThread(), 0);
+ Status = NtTerminateThread (NtCurrentThread(), 0);
}
else
{
DisplayString (L"CSR: CsrServerInitialization failed.\n");
-
- CsrpFreeCommandLine (Peb->ProcessHeap, & CmdLineArg);
/*
* Tell the SM we failed.
*/
- NtTerminateProcess (NtCurrentProcess(), 0);
+ Status = NtTerminateProcess (NtCurrentProcess(), 0);
}
+ return (int) Status;
}
/* EOF */
_____
Modified: trunk/reactos/subsys/csrss/csrss.xml
--- trunk/reactos/subsys/csrss/csrss.xml 2005-10-08 22:40:04 UTC
(rev 18364)
+++ trunk/reactos/subsys/csrss/csrss.xml 2005-10-08 22:41:49 UTC
(rev 18365)
@@ -4,6 +4,7 @@
<define name="__USE_W32API" />
<define name="_WIN32_WINNT">0x0600</define>
<define name="WINVER">0x0501</define>
+ <library>nt</library>
<library>intrlck</library>
<library>ntdll</library>
<library>smdll</library>
@@ -13,7 +14,7 @@
<file>user.c</file>
<file>wapi.c</file>
</directory>
- <pch>csrss.h</pch>
+ <pch>csrss.h</pch>
<file>csrss.c</file>
<file>init.c</file>
<file>print.c</file>
_____
Modified: trunk/reactos/subsys/csrss/include/api.h
--- trunk/reactos/subsys/csrss/include/api.h 2005-10-08 22:40:04 UTC
(rev 18364)
+++ trunk/reactos/subsys/csrss/include/api.h 2005-10-08 22:41:49 UTC
(rev 18365)
@@ -120,7 +120,7 @@
NTSTATUS STDCALL CsrInsertObject( PCSRSS_PROCESS_DATA ProcessData,
PHANDLE Handle, Object_t *Object );
NTSTATUS STDCALL CsrDuplicateHandleTable(PCSRSS_PROCESS_DATA
SourceProcessData, PCSRSS_PROCESS_DATA TargetProcessData);
NTSTATUS STDCALL CsrGetObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE
Handle, Object_t **Object );
-BOOL STDCALL CsrServerInitialization (ULONG ArgumentCount, PWSTR
*ArgumentArray);
+BOOL STDCALL CsrServerInitialization (int,char**,char**);
NTSTATUS STDCALL CsrReleaseObjectByPointer(Object_t *Object);
NTSTATUS STDCALL CsrReleaseObject( PCSRSS_PROCESS_DATA ProcessData,
HANDLE Object );
NTSTATUS STDCALL CsrVerifyObject( PCSRSS_PROCESS_DATA ProcessData,
HANDLE Object );
_____
Modified: trunk/reactos/subsys/csrss/init.c
--- trunk/reactos/subsys/csrss/init.c 2005-10-08 22:40:04 UTC (rev
18364)
+++ trunk/reactos/subsys/csrss/init.c 2005-10-08 22:41:49 UTC (rev
18365)
@@ -24,7 +24,6 @@
UNICODE_STRING CsrDirectoryName;
extern HANDLE CsrssApiHeap;
-extern PRTL_USER_PROCESS_PARAMETERS RtlProcessParameters;
static unsigned InitCompleteProcCount;
static CSRPLUGIN_INIT_COMPLETE_PROC *InitCompleteProcs = NULL;
@@ -95,13 +94,10 @@
InitializeVideoAddressSpace(VOID);
/**********************************************************************
- * CsrpParseCommandLine/2
+ * CsrpCreateObjectDirectory/3
*/
static NTSTATUS
-CsrpParseCommandLine (
- ULONG ArgumentCount,
- PWSTR *ArgumentArray
- )
+CsrpCreateObjectDirectory (int argc, char ** argv, char ** envp)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES Attributes;
@@ -109,13 +105,6 @@
DPRINT("CSR: %s called\n", __FUNCTION__);
- /* DbgPrint ("Arguments: %ld\n", ArgumentCount);
- for (i = 0; i < ArgumentCount; i++)
- {
- DbgPrint ("Argument %ld: %S\n", i, ArgumentArray[i]);
- }*/
-
-
/* create object directory ('\Windows') */
RtlCreateUnicodeString (&CsrDirectoryName,
L"\\Windows");
@@ -133,13 +122,13 @@
}
/**********************************************************************
- * CsrpInitVideo/0
+ * CsrpInitVideo/3
*
* TODO: we need a virtual device for sessions other than
* TODO: the console one
*/
static NTSTATUS
-CsrpInitVideo (ULONG argc, PWSTR* argv)
+CsrpInitVideo (int argc, char ** argv, char ** envp)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\??\\DISPLAY1");
@@ -170,7 +159,7 @@
}
/**********************************************************************
- * CsrpInitWin32Csr/0
+ * CsrpInitWin32Csr/3
*
* TODO: this function should be turned more general to load an
* TODO: hosted server DLL as received from the command line;
@@ -182,7 +171,7 @@
* TODO: DWORD ServerId)
*/
static NTSTATUS
-CsrpInitWin32Csr (ULONG argc, PWSTR* argv)
+CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
{
NTSTATUS Status;
UNICODE_STRING DllName;
@@ -296,10 +285,10 @@
/* === INIT ROUTINES === */
/**********************************************************************
- * CsrpCreateHeap/2
+ * CsrpCreateHeap/3
*/
static NTSTATUS
-CsrpCreateHeap (ULONG argc, PWSTR* argv)
+CsrpCreateHeap (int argc, char ** argv, char ** envp)
{
DPRINT("CSR: %s called\n", __FUNCTION__);
@@ -317,10 +306,10 @@
}
/**********************************************************************
- * CsrpCreateCallbackPort/2
+ * CsrpCreateCallbackPort/3
*/
static NTSTATUS
-CsrpCreateCallbackPort (ULONG argc, PWSTR* argv)
+CsrpCreateCallbackPort (int argc, char ** argv, char ** envp)
{
DPRINT("CSR: %s called\n", __FUNCTION__);
@@ -330,10 +319,10 @@
}
/**********************************************************************
- * CsrpRegisterSubsystem/2
+ * CsrpRegisterSubsystem/3
*/
static NTSTATUS
-CsrpRegisterSubsystem (ULONG argc, PWSTR* argv)
+CsrpRegisterSubsystem (int argc, char ** argv, char ** envp)
{
NTSTATUS Status = STATUS_SUCCESS;
OBJECT_ATTRIBUTES BootstrapOkAttributes;
@@ -391,24 +380,65 @@
}
/**********************************************************************
- * CsrpLoadKernelModeDriver/2
+ * EnvpToUnicodeString/2
*/
+static ULONG FASTCALL
+EnvpToUnicodeString (char ** envp, PUNICODE_STRING UnicodeEnv)
+{
+ ULONG CharCount = 0;
+ ULONG Index = 0;
+ ANSI_STRING AnsiEnv;
+
+ UnicodeEnv->Buffer = NULL;
+
+ for (Index=0; NULL != envp[Index]; Index++)
+ {
+ CharCount += strlen (envp[Index]);
+ ++ CharCount;
+ }
+ ++ CharCount;
+
+ AnsiEnv.Buffer = RtlAllocateHeap (RtlGetProcessHeap(), 0,
CharCount);
+ if (NULL != AnsiEnv.Buffer)
+ {
+ PCHAR WritePos = AnsiEnv.Buffer;
+
+ for (Index=0; NULL != envp[Index]; Index++)
+ {
+ strcat (WritePos, envp[Index]);
+ WritePos += strlen (envp[Index]) + 1;
+ }
+ AnsiEnv.Buffer [CharCount] = '\0';
+ AnsiEnv.Length = CharCount;
+ AnsiEnv.MaximumLength = CharCount;
+ RtlAnsiStringToUnicodeString (UnicodeEnv, & AnsiEnv,
TRUE);
+ RtlFreeHeap (RtlGetProcessHeap(), 0, AnsiEnv.Buffer);
+ }
+ return CharCount;
+}
+/**********************************************************************
+ * CsrpLoadKernelModeDriver/3
+ */
static NTSTATUS
-CsrpLoadKernelModeDriver (ULONG argc, PWSTR* argv)
+CsrpLoadKernelModeDriver (int argc, char ** argv, char ** envp)
{
- NTSTATUS Status = STATUS_SUCCESS;
- WCHAR Data [MAX_PATH + 1];
- ULONG DataLength = sizeof Data;
- ULONG DataType = 0;
+ NTSTATUS Status = STATUS_SUCCESS;
+ WCHAR Data [MAX_PATH + 1];
+ ULONG DataLength = sizeof Data;
+ ULONG DataType = 0;
+ UNICODE_STRING Environment;
DPRINT("SM: %s called\n", __FUNCTION__);
+
+ EnvpToUnicodeString (envp, & Environment);
Status = SmLookupSubsystem (L"Kmode",
Data,
& DataLength,
& DataType,
- RtlProcessParameters->Environment);
+ Environment.Buffer);
+ RtlFreeUnicodeString (& Environment);
if((STATUS_SUCCESS == Status) && (DataLength > sizeof Data[0]))
{
WCHAR ImagePath [MAX_PATH + 1] =
{0};
@@ -434,7 +464,7 @@
* CsrpCreateApiPort/2
*/
static NTSTATUS
-CsrpCreateApiPort (ULONG argc, PWSTR* argv)
+CsrpCreateApiPort (int argc, char ** argv, char ** envp)
{
DPRINT("CSR: %s called\n", __FUNCTION__);
@@ -447,7 +477,7 @@
* CsrpApiRegisterDef/0
*/
static NTSTATUS
-CsrpApiRegisterDef (ULONG argc, PWSTR* argv)
+CsrpApiRegisterDef (int argc, char ** argv, char ** envp)
{
return CsrApiRegisterDefinitions(NativeDefinitions);
}
@@ -456,7 +486,7 @@
* CsrpCCTS/2
*/
static NTSTATUS
-CsrpCCTS (ULONG argc, PWSTR* argv)
+CsrpCCTS (int argc, char ** argv, char ** envp)
{
ULONG Dummy;
ULONG DummyLength = sizeof(Dummy);
@@ -473,7 +503,7 @@
* TODO: in its own desktop (one logon desktop per winstation).
*/
static NTSTATUS
-CsrpRunWinlogon (ULONG argc, PWSTR* argv)
+CsrpRunWinlogon (int argc, char ** argv, char ** envp)
{
NTSTATUS Status = STATUS_SUCCESS;
UNICODE_STRING ImagePath;
@@ -521,7 +551,7 @@
-typedef NTSTATUS (* CSR_INIT_ROUTINE)(ULONG, PWSTR*);
+typedef NTSTATUS (* CSR_INIT_ROUTINE)(int,char**,char**);
struct {
BOOL Required;
@@ -532,7 +562,7 @@
{TRUE, CsrpRegisterSubsystem, "register with SM"},
{TRUE, CsrpCreateHeap, "create the CSR heap"},
{TRUE, CsrpCreateApiPort, "create the api port
\\Windows\\ApiPort"},
- {TRUE, CsrpParseCommandLine, "parse the command line"},
+ {TRUE, CsrpCreateObjectDirectory,"create the object directory
\\Windows"},
{TRUE, CsrpLoadKernelModeDriver, "load Kmode driver"},
{TRUE, CsrpInitVideo, "initialize video"},
{TRUE, CsrpApiRegisterDef, "initialize api definitions"},
@@ -553,8 +583,9 @@
*/
BOOL STDCALL
CsrServerInitialization (
- ULONG ArgumentCount,
- PWSTR *ArgumentArray
+ int argc,
+ char ** argv,
+ char ** envp
)
{
UINT i = 0;
@@ -564,7 +595,7 @@
for (i=0; i < (sizeof InitRoutine / sizeof InitRoutine[0]); i++)
{
- Status =
InitRoutine[i].EntryPoint(ArgumentCount,ArgumentArray);
+ Status = InitRoutine[i].EntryPoint(argc,argv,envp);
if(!NT_SUCCESS(Status))
{
DPRINT1("CSR: %s: failed to %s
(Status=%08lx)\n",
_____
Modified: trunk/reactos/subsys/smss/smss.c
--- trunk/reactos/subsys/smss/smss.c 2005-10-08 22:40:04 UTC (rev
18364)
+++ trunk/reactos/subsys/smss/smss.c 2005-10-08 22:41:49 UTC (rev
18365)
@@ -33,16 +33,15 @@
/* Native image's entry point */
-VOID STDCALL
-NtProcessStartup(PPEB Peb)
+NTSTATUS __cdecl _main(int argc,
+ char *argv[],
+ char *envp[],
+ ULONG DebugFlag)
{
NTSTATUS Status = STATUS_SUCCESS;
PROCESS_BASIC_INFORMATION PBI = {0};
-PrintString("*** EXPERIMENTAL ***\n");
-
- PrintString("ReactOS Session Manager %s (Build %s)\n",
- KERNEL_RELEASE_STR,
+ PrintString("ReactOS Session Manager (Build %s)\n",
KERNEL_VERSION_BUILD_STR);
/* Lookup yourself */
@@ -94,7 +93,7 @@
// NtTerminateProcess(NtCurrentProcess(), 0);
#endif
- NtTerminateThread(NtCurrentThread(), Status);
+ return NtTerminateThread(NtCurrentThread(), Status);
}
/* EOF */
_____
Modified: trunk/reactos/subsys/smss/smss.xml
--- trunk/reactos/subsys/smss/smss.xml 2005-10-08 22:40:04 UTC (rev
18364)
+++ trunk/reactos/subsys/smss/smss.xml 2005-10-08 22:41:49 UTC (rev
18365)
@@ -2,10 +2,11 @@
<include base="smss">.</include>
<define name="__USE_W32API" />
<define name="_DISABLE_TIDENTS" />
+ <library>nt</library>
<library>smlib</library>
<library>ntdll</library>
<linkerflag>-lgcc</linkerflag>
- <pch>smss.h</pch>
+ <pch>smss.h</pch>
<file>client.c</file>
<file>debug.c</file>
<file>init.c</file>