diff --git a/reactos/lib/ntrt0lib/args.c b/reactos/lib/ntrt0lib/args.c deleted file mode 100644 index 7c4fc010621..00000000000 --- a/reactos/lib/ntrt0lib/args.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $Id$ - * - * ReactOS Operating System - */ -#include "ntrt0.h" - -#define NDEBUG -#include - -/********************************************************************** - * NAME - * NtRtParseCommandLine/2 - */ -NTSTATUS STDCALL NtRtParseCommandLine (PPEB Peb, int * argc, char ** argv) -{ - *argc=0; - argv[0]=NULL; - //TODO - return STATUS_SUCCESS; -} -/* EOF */ diff --git a/reactos/lib/ntrt0lib/entry_point.c b/reactos/lib/ntrt0lib/entry_point.c index 1bdaa38c923..892f36fd70d 100644 --- a/reactos/lib/ntrt0lib/entry_point.c +++ b/reactos/lib/ntrt0lib/entry_point.c @@ -1,40 +1,144 @@ -/* $Id$ - * - * ReactOS Operating System +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS + * FILE: lib/nt/entry_point.c + * PURPOSE: Native NT Runtime Library + * PROGRAMMERS: Alex Ionescu (alex@relsoft.net) */ -#include "ntrt0.h" + +/* INCLUDES ******************************************************************/ + +/* PSDK/NDK Headers */ +#include +#include +#define NTOS_MODE_USER +#include + +NTSTATUS +__cdecl +_main( + int argc, + char *argv[], + char *envp[], + ULONG DebugFlag +); #define NDEBUG #include -#ifdef NDEBUG -#define NTRT_DEBUG_FLAG 0 -#else -#define NTRT_DEBUG_FLAG 1 -#endif +/* FUNCTIONSS ****************************************************************/ -int argc = 0; -char * argv [32] = {NULL}; -char * envp = NULL; - -/* Native process' entry point */ - -VOID STDCALL NtProcessStartup (PPEB Peb) +VOID +STDCALL +NtProcessStartup(PPEB Peb) { - NTSTATUS Status = STATUS_SUCCESS; + NTSTATUS Status; + PRTL_USER_PROCESS_PARAMETERS ProcessParameters; + PUNICODE_STRING CmdLineString; + ANSI_STRING AnsiCmdLine; + PCHAR NullPointer = NULL; + INT argc = 0; + PCHAR *argv; + PCHAR *envp; + PCHAR *ArgumentList; + PCHAR Source, Destination; + ULONG Length; + ASSERT(Peb); - /* - * Parse the command line. - */ - Status = NtRtParseCommandLine (Peb, & argc, argv); - if (STATUS_SUCCESS != Status) - { - DPRINT1("NT: %s: NtRtParseCommandLine failed (Status=0x%08lx)\n", - __FUNCTION__, Status); - } - /* - * Call the user main - */ - (void) _main (argc, argv, & envp, NTRT_DEBUG_FLAG); + /* Normalize and get the Process Parameters */ + ProcessParameters = RtlNormalizeProcessParams(Peb->ProcessParameters); + ASSERT(ProcessParameters); + + /* Allocate memory for the argument list, enough for 512 tokens */ + ArgumentList = RtlAllocateHeap(Peb->ProcessHeap, 0, 512 * sizeof(PCHAR)); + + /* Use a null pointer as default */ + argv = &NullPointer; + envp = &NullPointer; + + /* Set the first pointer to NULL, and set the argument array to the buffer */ + *ArgumentList = NULL; + argv = ArgumentList; + + /* Get the pointer to the Command Line */ + CmdLineString = &ProcessParameters->CommandLine; + + /* If we don't have a command line, use the image path instead */ + if (!CmdLineString->Buffer || !CmdLineString->Length) + { + CmdLineString = &ProcessParameters->ImagePathName; + } + + /* Convert it to an ANSI string */ + RtlUnicodeStringToAnsiString(&AnsiCmdLine, CmdLineString, TRUE); + + /* Save parameters for parsing */ + Source = AnsiCmdLine.Buffer; + Length = AnsiCmdLine.Length; + + /* Ensure it's valid */ + if (Source) + { + /* Allocate a buffer for the destination */ + Destination = RtlAllocateHeap(Peb->ProcessHeap, 0, Length + sizeof(WCHAR)); + + /* Start parsing */ + while (*Source) + { + /* Skip the white space. */ + while (*Source && *Source <= ' ') Source++; + + /* Copy until the next white space is reached */ + if (*Source) + { + /* Save one token pointer */ + *ArgumentList++ = Destination; + + /* Increase one token count */ + argc++; + + /* Copy token until white space */ + while (*Source > ' ') *Destination++ = *Source++; + + /* Null terminate it */ + *Destination++ = '\0'; + } + } + } + + /* Null terminate the token pointer list */ + *ArgumentList++ = NULL; + + /* Now handle the enviornment, point the envp at our current list location. */ + envp = ArgumentList; + + /* Change our source to the enviroment pointer */ + Source = (PCHAR)ProcessParameters->Environment; + + /* Simply do a direct copy */ + if (Source) + { + while (*Source) + { + /* Save a pointer to this token */ + *ArgumentList++ = Source; + + /* Keep looking for another variable */ + while (*Source++); + } + } + + /* Null terminate the list again */ + *ArgumentList++ = NULL; + + /* Breakpoint if we were requested to do so */ + if (ProcessParameters->DebugFlags) DbgBreakPoint(); + + /* Call the Main Function */ + Status = _main(argc, argv, envp, ProcessParameters->DebugFlags); + + /* We're done here */ + NtTerminateProcess(NtCurrentProcess(), Status); } + /* EOF */ diff --git a/reactos/lib/ntrt0lib/ntrt0.h b/reactos/lib/ntrt0lib/ntrt0.h deleted file mode 100644 index 9f5f2849919..00000000000 --- a/reactos/lib/ntrt0lib/ntrt0.h +++ /dev/null @@ -1,16 +0,0 @@ -#if !defined(_NTRT0_H) -#define _NTRT0_H - -/* PSDK/NDK Headers */ -#include -#include - -#define NTOS_MODE_USER -#include - -extern int _cdecl _main(int,char**,char**,int); - -NTSTATUS STDCALL NtRtParseCommandLine (PPEB,int*,char**); - -#endif /* !def _NTRT0_H */ - diff --git a/reactos/lib/ntrt0lib/ntrt0lib.xml b/reactos/lib/ntrt0lib/ntrt0lib.xml index b4b0892c3be..c605539b46b 100644 --- a/reactos/lib/ntrt0lib/ntrt0lib.xml +++ b/reactos/lib/ntrt0lib/ntrt0lib.xml @@ -1,5 +1,4 @@ - args.c entry_point.c