branch update for HEAD-2003021201
[reactos.git] / ntoskrnl / ke / main.c
index 894f925..5de88d2 100644 (file)
@@ -32,6 +32,7 @@
 #include <internal/ntoskrnl.h>
 #include <reactos/resource.h>
 #include <internal/mm.h>
+#include <internal/ifs.h>
 #include <internal/module.h>
 #include <internal/ldr.h>
 #include <internal/ex.h>
@@ -104,6 +105,26 @@ RtlpCheckFileNameExtension(PCHAR FileName,
 }
 
 
+static BOOLEAN
+RtlpIsSystemHive(PCHAR FileName)
+{
+  PCHAR Name;
+
+  Name = strrchr(FileName, '\\');
+  if (Name == NULL)
+  {
+    Name = FileName;
+  }
+  else
+  {
+    Name = Name + 1;
+  }
+
+  return((_stricmp(Name, "system.hiv") == 0) ||
+        (_stricmp(Name, "system") == 0));
+}
+
+
 static VOID
 InitSystemSharedUserPage (PCSZ ParameterLine)
 {
@@ -282,9 +303,13 @@ InitSystemSharedUserPage (PCSZ ParameterLine)
      }
 }
 
+
 VOID
 ExpInitializeExecutive(VOID)
 {
+  LARGE_INTEGER Timeout;
+  HANDLE ProcessHandle;
+  HANDLE ThreadHandle;
   ULONG BootDriverCount;
   ULONG i;
   ULONG start;
@@ -292,6 +317,7 @@ ExpInitializeExecutive(VOID)
   PCHAR name;
   CHAR str[50];
   NTSTATUS Status;
+  BOOLEAN SetupBoot;
 
   /*
    * Fail at runtime if someone has changed various structures without
@@ -394,14 +420,14 @@ ExpInitializeExecutive(VOID)
   if (KeNumberProcessors > 1)
     {
       sprintf(str,
-             "Found %d system processors. [%lu MB Memory]\n",
+             "Found %d system processors. [%u MB Memory]\n",
              KeNumberProcessors,
              (KeLoaderBlock.MemHigher + 1088)/ 1024);
     }
   else
     {
       sprintf(str,
-             "Found 1 system processor. [%lu MB Memory]\n",
+             "Found 1 system processor. [%u MB Memory]\n",
              (KeLoaderBlock.MemHigher + 1088)/ 1024);
     }
   HalDisplayString(str);
@@ -420,6 +446,7 @@ ExpInitializeExecutive(VOID)
   MmInit3();
   CcInit();
   KdInit2();
+  FsRtlpInitFileLockingImplementation();
   
   /* Report all resources used by hal */
   HalReportResourceUsage();
@@ -473,6 +500,7 @@ ExpInitializeExecutive(VOID)
     }
 
   /*  Pass 2: load registry chunks passed in  */
+  SetupBoot = TRUE;
   for (i = 1; i < KeLoaderBlock.ModsCount; i++)
     {
       start = KeLoaderModules[i].ModStart;
@@ -484,10 +512,17 @@ ExpInitializeExecutive(VOID)
          CPRINT("Process registry chunk at %08lx\n", start);
          CmImportHive((PCHAR)start, length);
        }
+      if (RtlpIsSystemHive(name))
+       {
+         SetupBoot = FALSE;
+       }
     }
 
   /* Initialize volatile registry settings */
-  CmInit2((PCHAR)KeLoaderBlock.CommandLine);
+  if (SetupBoot == FALSE)
+    {
+      CmInit2((PCHAR)KeLoaderBlock.CommandLine);
+    }
 
   /*
    * Enter the kernel debugger before starting up the boot drivers
@@ -537,6 +572,10 @@ ExpInitializeExecutive(VOID)
   DebugLogInit2();
 #endif /* DBGPRINT_FILE_LOG */
 
+#ifdef KDBG
+  KdbInitProfiling2();
+#endif /* KDBG */
+
 
   PiInitDefaultLocale();
 
@@ -575,7 +614,27 @@ ExpInitializeExecutive(VOID)
   /*
    *  Launch initial process
    */
-  LdrLoadInitialProcess();
+  Status = LdrLoadInitialProcess(&ProcessHandle,
+                                &ThreadHandle);
+  if (!NT_SUCCESS(Status))
+    {
+      KeBugCheckEx(SESSION4_INITIALIZATION_FAILED, Status, 0, 0, 0);
+    }
+
+  /*
+   * Crash the system if the initial process terminates within 5 seconds.
+   */
+  Timeout.QuadPart = -50000000LL;
+  Status = NtWaitForSingleObject(ProcessHandle,
+                                FALSE,
+                                &Timeout);
+  if (Status != STATUS_TIMEOUT)
+    {
+      KeBugCheckEx(SESSION5_INITIALIZATION_FAILED, Status, 0, 0, 0);
+    }
+
+  NtClose(ThreadHandle);
+  NtClose(ProcessHandle);
 
   PsTerminateSystemThread(STATUS_SUCCESS);
 }
@@ -669,7 +728,7 @@ _main (ULONG MultiBootMagic, PLOADER_PARAMETER_BLOCK _LoaderBlock)
            }
        }
       sprintf(KeLoaderCommandLine, 
-             "multi(0)disk(0)rdisk(%ld)partition(%ld)%s %s",
+             "multi(0)disk(0)rdisk(%d)partition(%d)%s %s",
              DiskNumber, PartNumber + 1, Temp, options);
 
       p = KeLoaderCommandLine;