update for HEAD-2003050101
[reactos.git] / ntoskrnl / ke / main.c
index 894f925..0b2c079 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>
@@ -84,23 +85,24 @@ static BOOLEAN
 RtlpCheckFileNameExtension(PCHAR FileName,
                           PCHAR Extension)
 {
-   PCHAR Ext;
+  PCHAR Ext;
 
-   Ext = strrchr(FileName, '.');
-   if ((Extension == NULL) || (*Extension == 0))
-     {
-       if (Ext == NULL)
-         return TRUE;
-       else
-         return FALSE;
-     }
-   if (*Extension != '.')
-     Ext++;
-   
-   if (_stricmp(Ext, Extension) == 0)
-     return TRUE;
-   else
-     return FALSE;
+  Ext = strrchr(FileName, '.');
+  if (Ext == NULL)
+    {
+      if ((Extension == NULL) || (*Extension == 0))
+       return TRUE;
+      else
+       return FALSE;
+    }
+
+  if (*Extension != '.')
+    Ext++;
+
+  if (_stricmp(Ext, Extension) == 0)
+    return TRUE;
+  else
+    return FALSE;
 }
 
 
@@ -282,9 +284,13 @@ InitSystemSharedUserPage (PCSZ ParameterLine)
      }
 }
 
+
 VOID
 ExpInitializeExecutive(VOID)
 {
+  LARGE_INTEGER Timeout;
+  HANDLE ProcessHandle;
+  HANDLE ThreadHandle;
   ULONG BootDriverCount;
   ULONG i;
   ULONG start;
@@ -292,6 +298,7 @@ ExpInitializeExecutive(VOID)
   PCHAR name;
   CHAR str[50];
   NTSTATUS Status;
+  BOOLEAN SetupBoot;
 
   /*
    * Fail at runtime if someone has changed various structures without
@@ -420,6 +427,7 @@ ExpInitializeExecutive(VOID)
   MmInit3();
   CcInit();
   KdInit2();
+  FsRtlpInitFileLockingImplementation();
   
   /* Report all resources used by hal */
   HalReportResourceUsage();
@@ -472,22 +480,56 @@ ExpInitializeExecutive(VOID)
        }
     }
 
-  /*  Pass 2: load registry chunks passed in  */
+  /*  Pass 2: import system hive registry chunk  */
+  SetupBoot = TRUE;
+  for (i = 1; i < KeLoaderBlock.ModsCount; i++)
+    {
+      start = KeLoaderModules[i].ModStart;
+      length = KeLoaderModules[i].ModEnd - start;
+
+      DPRINT("Module: '%s'\n", (PCHAR)KeLoaderModules[i].String);
+      name = strrchr((PCHAR)KeLoaderModules[i].String, '\\');
+      if (name == NULL)
+       {
+         name = (PCHAR)KeLoaderModules[i].String;
+       }
+      else
+       {
+         name++;
+       }
+
+      if (!_stricmp (name, "system") ||
+         !_stricmp (name, "system.hiv"))
+       {
+         CPRINT("Process system hive registry chunk at %08lx\n", start);
+         SetupBoot = FALSE;
+         CmImportSystemHive((PCHAR)start, length);
+       }
+    }
+
+  /*  Pass 3: import hardware hive registry chunk  */
   for (i = 1; i < KeLoaderBlock.ModsCount; i++)
     {
       start = KeLoaderModules[i].ModStart;
       length = KeLoaderModules[i].ModEnd - start;
       name = (PCHAR)KeLoaderModules[i].String;
-      if (RtlpCheckFileNameExtension(name, "") ||
-         RtlpCheckFileNameExtension(name, ".hiv"))
+      if (!_stricmp (name, "hardware") ||
+         !_stricmp (name, "hardware.hiv"))
        {
-         CPRINT("Process registry chunk at %08lx\n", start);
-         CmImportHive((PCHAR)start, length);
+         CPRINT("Process hardware hive registry chunk at %08lx\n", start);
+         CmImportHardwareHive((PCHAR)start, length);
        }
     }
 
+  /* Create dummy keys if no hardware hive was found */
+  CmImportHardwareHive (NULL, 0);
+
+
   /* 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
@@ -498,7 +540,7 @@ ExpInitializeExecutive(VOID)
 
   IoCreateDriverList();
 
-  /*  Pass 3: process boot loaded drivers  */
+  /*  Pass 4: process boot loaded drivers  */
   BootDriverCount = 0;
   for (i=1; i < KeLoaderBlock.ModsCount; i++)
     {
@@ -537,6 +579,10 @@ ExpInitializeExecutive(VOID)
   DebugLogInit2();
 #endif /* DBGPRINT_FILE_LOG */
 
+#ifdef KDBG
+  KdbInitProfiling2();
+#endif /* KDBG */
+
 
   PiInitDefaultLocale();
 
@@ -575,7 +621,26 @@ 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 +734,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(%lu)partition(%lu)%s %s",
              DiskNumber, PartNumber + 1, Temp, options);
 
       p = KeLoaderCommandLine;