Merge 25584, 25588.
[reactos.git] / reactos / ntoskrnl / ex / init.c
index ef8d6cb..6673931 100644 (file)
@@ -39,12 +39,6 @@ BOOLEAN NoGuiBoot = FALSE;
 /* NT Boot Path */
 UNICODE_STRING NtSystemRoot;
 
-/* NT Initial User Application */
-WCHAR NtInitialUserProcessBuffer[128] = L"\\SystemRoot\\System32\\smss.exe";
-ULONG NtInitialUserProcessBufferLength = sizeof(NtInitialUserProcessBuffer) -
-                                         sizeof(WCHAR);
-ULONG NtInitialUserProcessBufferType = REG_SZ;
-
 /* Boot NLS information */
 PVOID ExpNlsTableBase;
 ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset;
@@ -74,7 +68,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
                                &LinkName,
                                OBJ_CASE_INSENSITIVE | OBJ_PERMANENT,
                                NULL,
-                               SePublicDefaultUnrestrictedSd);
+                               SePublicDefaultSd);
 
     /* Create it */
     Status = NtCreateDirectoryObject(&LinkHandle,
@@ -94,7 +88,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
                                &LinkName,
                                OBJ_CASE_INSENSITIVE | OBJ_PERMANENT,
                                NULL,
-                               SePublicDefaultUnrestrictedSd);
+                               SePublicDefaultSd);
 
     /* Create it */
     Status = NtCreateDirectoryObject(&LinkHandle,
@@ -121,7 +115,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
                                &LinkName,
                                OBJ_CASE_INSENSITIVE | OBJ_PERMANENT,
                                NULL,
-                               SePublicDefaultUnrestrictedSd);
+                               SePublicDefaultSd);
 
     /* Build the ARC name */
     sprintf(Buffer,
@@ -359,11 +353,10 @@ ExpLoadInitialProcess(IN PHANDLE ProcessHandle,
     PWSTR p;
     UNICODE_STRING NullString = RTL_CONSTANT_STRING(L"");
     UNICODE_STRING SmssName, Environment, SystemDriveString;
-    PVOID EnvironmentPtr = NULL;
 
     /* Allocate memory for the process parameters */
     Size = sizeof(RTL_USER_PROCESS_PARAMETERS) +
-           ((MAX_PATH * 6) * sizeof(WCHAR));
+           ((MAX_PATH * 4) * sizeof(WCHAR));
     Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
                                      (PVOID)&ProcessParameters,
                                      0,
@@ -385,7 +378,7 @@ ExpLoadInitialProcess(IN PHANDLE ProcessHandle,
     /* Allocate a page for the environment */
     Size = PAGE_SIZE;
     Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
-                                     &EnvironmentPtr,
+                                     (PVOID)&ProcessParameters->Environment,
                                      0,
                                      &Size,
                                      MEM_COMMIT,
@@ -396,9 +389,6 @@ ExpLoadInitialProcess(IN PHANDLE ProcessHandle,
         KeBugCheckEx(SESSION2_INITIALIZATION_FAILED, Status, 0, 0, 0);
     }
 
-    /* Write the pointer */
-    ProcessParameters->Environment = EnvironmentPtr;
-
     /* Make a buffer for the DOS path */
     p = (PWSTR)(ProcessParameters + 1);
     ProcessParameters->CurrentDirectory.DosPath.Buffer = p;
@@ -426,48 +416,11 @@ ExpLoadInitialProcess(IN PHANDLE ProcessHandle,
     ProcessParameters->ImagePathName.Buffer = p;
     ProcessParameters->ImagePathName.MaximumLength = MAX_PATH * sizeof(WCHAR);
 
-    /* Make sure the buffer is a valid string which within the given length */
-    if ((NtInitialUserProcessBufferType != REG_SZ) ||
-        ((NtInitialUserProcessBufferLength != -1) &&
-         ((NtInitialUserProcessBufferLength < sizeof(WCHAR)) ||
-          (NtInitialUserProcessBufferLength >
-           sizeof(NtInitialUserProcessBuffer) - sizeof(WCHAR)))))
-    {
-        /* Invalid initial process string, bugcheck */
-        KeBugCheckEx(SESSION2_INITIALIZATION_FAILED,
-                     (ULONG_PTR)STATUS_INVALID_PARAMETER,
-                     NtInitialUserProcessBufferType,
-                     NtInitialUserProcessBufferLength,
-                     sizeof(NtInitialUserProcessBuffer));
-    }
-
-    /* Cut out anything after a space */
-    p = NtInitialUserProcessBuffer;
-    while (*p && *p != L' ') p++;
-
-    /* Set the image path length */
-    ProcessParameters->ImagePathName.Length =
-        (USHORT)((PCHAR)p - (PCHAR)NtInitialUserProcessBuffer);
-
-    /* Copy the actual buffer */
-    RtlCopyMemory(ProcessParameters->ImagePathName.Buffer,
-                  NtInitialUserProcessBuffer,
-                  ProcessParameters->ImagePathName.Length);
-
-    /* Null-terminate it */
-    ProcessParameters->
-        ImagePathName.Buffer[ProcessParameters->ImagePathName.Length /
-                             sizeof(WCHAR)] = UNICODE_NULL;
-
-    /* Make a buffer for the command line */
-    p = (PWSTR)((PCHAR)ProcessParameters->ImagePathName.Buffer +
-                ProcessParameters->ImagePathName.MaximumLength);
-    ProcessParameters->CommandLine.Buffer = p;
-    ProcessParameters->CommandLine.MaximumLength = MAX_PATH * sizeof(WCHAR);
-
-    /* Add the image name to the command line */
-    RtlAppendUnicodeToString(&ProcessParameters->CommandLine,
-                             NtInitialUserProcessBuffer);
+    /* Append the system path and session manager name */
+    RtlAppendUnicodeToString(&ProcessParameters->ImagePathName,
+                             L"\\SystemRoot\\System32");
+    RtlAppendUnicodeToString(&ProcessParameters->ImagePathName,
+                             L"\\smss.exe");
 
     /* Create the environment string */
     RtlInitEmptyUnicodeString(&Environment,
@@ -493,8 +446,11 @@ ExpLoadInitialProcess(IN PHANDLE ProcessHandle,
     RtlAppendUnicodeStringToString(&Environment, &NtSystemRoot);
     RtlAppendUnicodeStringToString(&Environment, &NullString);
 
-    /* Create SMSS process */
+    /* Get and set the command line equal to the image path */
+    ProcessParameters->CommandLine = ProcessParameters->ImagePathName;
     SmssName = ProcessParameters->ImagePathName;
+
+    /* Create SMSS process */
     Status = RtlCreateUserProcess(&SmssName,
                                   OBJ_CASE_INSENSITIVE,
                                   RtlDeNormalizeProcessParams(
@@ -775,9 +731,9 @@ ExpInitializeExecutive(IN ULONG Cpu,
     Buffer[--AnsiPath.Length] = ANSI_NULL;
 
     /* Get the string from KUSER_SHARED_DATA's buffer */
-    RtlInitEmptyUnicodeString(&NtSystemRoot,
-                              SharedUserData->NtSystemRoot,
-                              sizeof(SharedUserData->NtSystemRoot));
+    NtSystemRoot.Buffer = SharedUserData->NtSystemRoot;
+    NtSystemRoot.MaximumLength = sizeof(SharedUserData->NtSystemRoot) / sizeof(WCHAR);
+    NtSystemRoot.Length = 0;
 
     /* Now fill it in */
     Status = RtlAnsiStringToUnicodeString(&NtSystemRoot, &AnsiPath, FALSE);
@@ -1004,17 +960,19 @@ ExPhase2Init(PVOID Context)
         /* Bugcheck the system if SMSS couldn't initialize */
         KeBugCheck(SESSION5_INITIALIZATION_FAILED);
     }
+    else
+    {
+        /* Close process handles */
+        ZwClose(ThreadHandle);
+        ZwClose(ProcessHandle);
 
-    /* Close process handles */
-    ZwClose(ThreadHandle);
-    ZwClose(ProcessHandle);
-
-    /* FIXME: We should free the initial process' memory!*/
+        /* FIXME: We should free the initial process' memory!*/
 
-    /* Increase init phase */
-    ExpInitializationPhase += 1;
+        /* Increase init phase */
+        ExpInitializationPhase += 1;
 
-    /* Jump into zero page thread */
-    MmZeroPageThreadMain(NULL);
+        /* Jump into zero page thread */
+        MmZeroPageThreadMain(NULL);
+    }
 }
 /* EOF */