- Implement Native Entrypoint for our NT.LIB
Deleted: trunk/reactos/lib/ntrt0lib/args.c
Modified: trunk/reactos/lib/ntrt0lib/entry_point.c
Deleted: trunk/reactos/lib/ntrt0lib/ntrt0.h
Modified: trunk/reactos/lib/ntrt0lib/ntrt0lib.xml
_____
Deleted: trunk/reactos/lib/ntrt0lib/args.c
--- trunk/reactos/lib/ntrt0lib/args.c 2005-10-02 16:23:26 UTC (rev
18220)
+++ trunk/reactos/lib/ntrt0lib/args.c 2005-10-02 16:58:35 UTC (rev
18221)
@@ -1,21 +0,0 @@
-/* $Id$
- *
- * ReactOS Operating System
- */
-#include "ntrt0.h"
-
-#define NDEBUG
-#include <debug.h>
-
-/**********************************************************************
- * NAME
- * NtRtParseCommandLine/2
- */
-NTSTATUS STDCALL NtRtParseCommandLine (PPEB Peb, int * argc, char **
argv)
-{
- *argc=0;
- argv[0]=NULL;
- //TODO
- return STATUS_SUCCESS;
-}
-/* EOF */
_____
Modified: trunk/reactos/lib/ntrt0lib/entry_point.c
--- trunk/reactos/lib/ntrt0lib/entry_point.c 2005-10-02 16:23:26 UTC
(rev 18220)
+++ trunk/reactos/lib/ntrt0lib/entry_point.c 2005-10-02 16:58:35 UTC
(rev 18221)
@@ -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(a)relsoft.net)
*/
-#include "ntrt0.h"
+/* INCLUDES
******************************************************************/
+
+/* PSDK/NDK Headers */
+#include <stdio.h>
+#include <windows.h>
+#define NTOS_MODE_USER
+#include <ndk/ntndk.h>
+
+NTSTATUS
+__cdecl
+_main(
+ int argc,
+ char *argv[],
+ char *envp[],
+ ULONG DebugFlag
+);
+
#define NDEBUG
#include <debug.h>
-#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;
+VOID
+STDCALL
+NtProcessStartup(PPEB Peb)
+{
+ 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);
-/* Native process' entry point */
+ /* Normalize and get the Process Parameters */
+ ProcessParameters =
RtlNormalizeProcessParams(Peb->ProcessParameters);
+ ASSERT(ProcessParameters);
-VOID STDCALL NtProcessStartup (PPEB Peb)
-{
- NTSTATUS Status = STATUS_SUCCESS;
+ /* Allocate memory for the argument list, enough for 512 tokens */
+ ArgumentList = RtlAllocateHeap(Peb->ProcessHeap, 0, 512 *
sizeof(PCHAR));
- /*
- * 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);
+ /* 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 */
_____
Deleted: trunk/reactos/lib/ntrt0lib/ntrt0.h
--- trunk/reactos/lib/ntrt0lib/ntrt0.h 2005-10-02 16:23:26 UTC (rev
18220)
+++ trunk/reactos/lib/ntrt0lib/ntrt0.h 2005-10-02 16:58:35 UTC (rev
18221)
@@ -1,16 +0,0 @@
-#if !defined(_NTRT0_H)
-#define _NTRT0_H
-
-/* PSDK/NDK Headers */
-#include <stdio.h>
-#include <windows.h>
-
-#define NTOS_MODE_USER
-#include <ndk/ntndk.h>
-
-extern int _cdecl _main(int,char**,char**,int);
-
-NTSTATUS STDCALL NtRtParseCommandLine (PPEB,int*,char**);
-
-#endif /* !def _NTRT0_H */
-
_____
Modified: trunk/reactos/lib/ntrt0lib/ntrt0lib.xml
--- trunk/reactos/lib/ntrt0lib/ntrt0lib.xml 2005-10-02 16:23:26 UTC
(rev 18220)
+++ trunk/reactos/lib/ntrt0lib/ntrt0lib.xml 2005-10-02 16:58:35 UTC
(rev 18221)
@@ -1,5 +1,4 @@
<module name="ntrt0lib" type="staticlibrary">
<define name="_DISABLE_TIDENTS" />
- <file>args.c</file>
<file>entry_point.c</file>
</module>