[NTOS] Configuration Manager fixes.
[reactos.git] / ntoskrnl / ex / init.c
index 9b8ec1e..66819c5 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
+/* This is the size that we can expect from the win 2003 loader */
+#define LOADER_PARAMETER_EXTENSION_MIN_SIZE \
+    RTL_SIZEOF_THROUGH_FIELD(LOADER_PARAMETER_EXTENSION, AcpiTableSize)
+
 /* Temporary hack */
 BOOLEAN
 NTAPI
@@ -37,9 +41,9 @@ typedef struct _INIT_BUFFER
 /* NT Version Info */
 ULONG NtMajorVersion = VER_PRODUCTMAJORVERSION;
 ULONG NtMinorVersion = VER_PRODUCTMINORVERSION;
-#if DBG
+#if DBG /* Checked Build */
 ULONG NtBuildNumber = VER_PRODUCTBUILD | 0xC0000000;
-#else
+#else   /* Free Build */
 ULONG NtBuildNumber = VER_PRODUCTBUILD;
 #endif
 
@@ -53,7 +57,9 @@ ULONG CmNtCSDVersion;
 ULONG CmNtCSDReleaseType;
 UNICODE_STRING CmVersionString;
 UNICODE_STRING CmCSDVersionString;
-CHAR NtBuildLab[] = KERNEL_VERSION_BUILD_STR;
+
+CHAR NtBuildLab[] = KERNEL_VERSION_BUILD_STR "."
+                    REACTOS_COMPILER_NAME "_" REACTOS_COMPILER_VERSION;
 
 /* Init flags and settings */
 ULONG ExpInitializationPhase;
@@ -522,7 +528,7 @@ ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer,
                               (USHORT)Size);
 
     /* Append the DLL path to it */
-    RtlAppendUnicodeToString(&Environment, L"Path=" );
+    RtlAppendUnicodeToString(&Environment, L"Path=");
     RtlAppendUnicodeStringToString(&Environment, &ProcessParams->DllPath);
     RtlAppendUnicodeStringToString(&Environment, &NullString);
 
@@ -668,52 +674,52 @@ ExpInitSystemPhase1(VOID)
         DPRINT1("Executive: Event Pair initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize mutants */
     if (ExpInitializeMutantImplementation() == FALSE)
     {
         DPRINT1("Executive: Mutant initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize callbacks */
     if (ExpInitializeCallbacks() == FALSE)
     {
         DPRINT1("Executive: Callback initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize semaphores */
     if (ExpInitializeSemaphoreImplementation() == FALSE)
     {
         DPRINT1("Executive: Semaphore initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize timers */
     if (ExpInitializeTimerImplementation() == FALSE)
     {
         DPRINT1("Executive: Timer initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize profiling */
     if (ExpInitializeProfileImplementation() == FALSE)
     {
         DPRINT1("Executive: Profile initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize UUIDs */
     ExpInitUuids();
-    
+
     /* Initialize keyed events */
     if (ExpInitializeKeyedEventImplementation() == FALSE)
     {
         DPRINT1("Executive: Keyed event initialization failed\n");
         return FALSE;
     }
-    
+
     /* Initialize Win32K */
     if (ExpWin32kInit() == FALSE)
     {
@@ -759,8 +765,8 @@ ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     /* Get the loader extension */
     Extension = LoaderBlock->Extension;
 
-    /* Validate the size (larger structures are OK, we'll just ignore them) */
-    if (Extension->Size < sizeof(LOADER_PARAMETER_EXTENSION)) return FALSE;
+    /* Validate the size (Windows 2003 loader doesn't provide more) */
+    if (Extension->Size < LOADER_PARAMETER_EXTENSION_MIN_SIZE) return FALSE;
 
     /* Don't validate upper versions */
     if (Extension->MajorVersion > VER_PRODUCTMAJORVERSION) return TRUE;
@@ -846,7 +852,7 @@ ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
                 /* Load the symbols */
                 DbgLoadImageSymbols(&SymbolString,
                                     LdrEntry->DllBase,
-                                    (ULONG_PTR)ZwCurrentProcess());
+                                    (ULONG_PTR)PsGetCurrentProcessId());
             }
         }
 
@@ -866,7 +872,7 @@ ExBurnMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
     PLIST_ENTRY ListEntry;
     PMEMORY_ALLOCATION_DESCRIPTOR MemDescriptor;
 
-    DPRINT1("Burn RAM amount: %d pages\n", PagesToDestroy);
+    DPRINT1("Burn RAM amount: %lu pages\n", PagesToDestroy);
 
     /* Loop the memory descriptors, beginning at the end */
     for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Blink;
@@ -916,10 +922,10 @@ ExpInitializeExecutive(IN ULONG Cpu,
     ULONG PerfMemUsed;
     PLDR_DATA_TABLE_ENTRY NtosEntry;
     PMESSAGE_RESOURCE_ENTRY MsgEntry;
-    ANSI_STRING CsdString;
+    ANSI_STRING CSDString;
     size_t Remaining = 0;
     PCHAR RcEnd = NULL;
-    CHAR VersionBuffer [65];
+    CHAR VersionBuffer[65];
 
     /* Validate Loader */
     if (!ExpIsLoaderValid(LoaderBlock))
@@ -957,7 +963,8 @@ ExpInitializeExecutive(IN ULONG Cpu,
     if (LoaderBlock->SetupLdrBlock)
     {
         /* Check if this is text-mode setup */
-        if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_TEXT_MODE) ExpInTextModeSetup = TRUE;
+        if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_TEXT_MODE)
+            ExpInTextModeSetup = TRUE;
 
         /* Check if this is network boot */
         if (LoaderBlock->SetupLdrBlock->Flags & SETUPLDR_REMOTE_BOOT)
@@ -1072,17 +1079,11 @@ ExpInitializeExecutive(IN ULONG Cpu,
     /* Setup initial system settings */
     CmGetSystemControlValues(LoaderBlock->RegistryBase, CmControlVector);
 
-    /* Load static defaults for Service Pack 1 and add our SVN revision */
-    /* Format of CSD : SPMajor - SPMinor */
-    CmNtCSDVersion = 0x100 | (KERNEL_VERSION_BUILD_HEX << 16);
-    CmNtCSDReleaseType = 0;
-
-    /* Set Service Pack data for Service Pack 1 */
+    /* Set the Service Pack Number and add it to the CSD Version number if needed */
     CmNtSpBuildNumber = VER_PRODUCTBUILD_QFE;
-    if (!(CmNtCSDVersion & 0xFFFF0000))
+    if (((CmNtCSDVersion & 0xFFFF0000) == 0) && (CmNtCSDReleaseType == 1))
     {
-        /* Check the release type */
-        if (CmNtCSDReleaseType == 1) CmNtSpBuildNumber |= VER_PRODUCTBUILD_QFE << 16;
+        CmNtCSDVersion |= (VER_PRODUCTBUILD_QFE << 16);
     }
 
     /* Add loaded CmNtGlobalFlag value */
@@ -1136,22 +1137,22 @@ ExpInitializeExecutive(IN ULONG Cpu,
         if (NT_SUCCESS(Status))
         {
             /* Setup the string */
-            RtlInitAnsiString(&CsdString, (PCHAR)MsgEntry->Text);
+            RtlInitAnsiString(&CSDString, (PCHAR)MsgEntry->Text);
 
             /* Remove trailing newline */
-            while ((CsdString.Length > 0) &&
-                   ((CsdString.Buffer[CsdString.Length - 1] == '\r') ||
-                    (CsdString.Buffer[CsdString.Length - 1] == '\n')))
+            while ((CSDString.Length > 0) &&
+                   ((CSDString.Buffer[CSDString.Length - 1] == '\r') ||
+                    (CSDString.Buffer[CSDString.Length - 1] == '\n')))
             {
                 /* Skip the trailing character */
-                CsdString.Length--;
+                CSDString.Length--;
             }
 
             /* Fill the buffer with version information */
             Status = RtlStringCbPrintfA(Buffer,
                                         sizeof(Buffer),
                                         "%Z %u%c",
-                                        &CsdString,
+                                        &CSDString,
                                         (CmNtCSDVersion & 0xFF00) >> 8,
                                         (CmNtCSDVersion & 0xFF) ?
                                         'A' + (CmNtCSDVersion & 0xFF) - 1 :
@@ -1193,7 +1194,7 @@ ExpInitializeExecutive(IN ULONG Cpu,
     }
 
     /* Check if we have an RC number */
-    if (CmNtCSDVersion & 0xFFFF0000)
+    if ((CmNtCSDVersion & 0xFFFF0000) && (CmNtCSDReleaseType == 1))
     {
         /* Check if we have no version data yet */
         if (!(*Buffer))
@@ -1221,7 +1222,7 @@ ExpInitializeExecutive(IN ULONG Cpu,
         /* Add the version format string */
         Status = RtlStringCbPrintfA(RcEnd,
                                     Remaining,
-                                    "v. %u",
+                                    "v.%u",
                                     (CmNtCSDVersion & 0xFFFF0000) >> 16);
         if (!NT_SUCCESS(Status))
         {
@@ -1231,9 +1232,9 @@ ExpInitializeExecutive(IN ULONG Cpu,
     }
 
     /* Now setup the final string */
-    RtlInitAnsiString(&CsdString, Buffer);
+    RtlInitAnsiString(&CSDString, Buffer);
     Status = RtlAnsiStringToUnicodeString(&CmCSDVersionString,
-                                          &CsdString,
+                                          &CSDString,
                                           TRUE);
     if (!NT_SUCCESS(Status))
     {
@@ -1372,17 +1373,17 @@ Phase1InitializationDiscard(IN PVOID Context)
     if (!HalInitSystem(1, LoaderBlock)) KeBugCheck(HAL1_INITIALIZATION_FAILED);
 
     /* Get the command line and upcase it */
-    CommandLine = _strupr(LoaderBlock->LoadOptions);
+    CommandLine = (LoaderBlock->LoadOptions ? _strupr(LoaderBlock->LoadOptions) : NULL);
 
     /* Check if GUI Boot is enabled */
-    NoGuiBoot = (strstr(CommandLine, "NOGUIBOOT")) ? TRUE: FALSE;
+    NoGuiBoot = (CommandLine && strstr(CommandLine, "NOGUIBOOT") != NULL);
 
     /* Get the SOS setting */
-    SosEnabled = strstr(CommandLine, "SOS") ? TRUE: FALSE;
+    SosEnabled = (CommandLine && strstr(CommandLine, "SOS") != NULL);
 
     /* Setup the boot driver */
     InbvEnableBootDriver(!NoGuiBoot);
-    InbvDriverInitialize(LoaderBlock, 18);
+    InbvDriverInitialize(LoaderBlock, IDB_MAX_RESOURCE);
 
     /* Check if GUI boot is enabled */
     if (!NoGuiBoot)
@@ -1401,11 +1402,11 @@ Phase1InitializationDiscard(IN PVOID Context)
     }
 
     /* Check if this is LiveCD (WinPE) mode */
-    if (strstr(CommandLine, "MININT"))
+    if (CommandLine && strstr(CommandLine, "MININT") != NULL)
     {
         /* Setup WinPE Settings */
         InitIsWinPEMode = TRUE;
-        InitWinPEModeType |= (strstr(CommandLine, "INRAM")) ? 0x80000000 : 1;
+        InitWinPEModeType |= (strstr(CommandLine, "INRAM") != NULL) ? 0x80000000 : 0x00000001;
     }
 
     /* Get the kernel's load entry */
@@ -1468,9 +1469,12 @@ Phase1InitializationDiscard(IN PVOID Context)
     if (NT_SUCCESS(MsgStatus))
     {
         /* Create the banner message */
+        /* ReactOS specific: Report ReactOS version, NtBuildLab information and reported NT kernel version */
         Status = RtlStringCbPrintfA(EndBuffer,
                                     Remaining,
                                     (PCHAR)MsgEntry->Text,
+                                    KERNEL_VERSION_STR,
+                                    NtBuildLab,
                                     StringBuffer,
                                     NtBuildNumber & 0xFFFF,
                                     BeginBuffer);
@@ -1483,7 +1487,7 @@ Phase1InitializationDiscard(IN PVOID Context)
     else
     {
         /* Use hard-coded banner message */
-        Status = RtlStringCbCopyA(EndBuffer, Remaining, "REACTOS (R)\n");
+        Status = RtlStringCbCopyA(EndBuffer, Remaining, "REACTOS (R)\r\n");
         if (!NT_SUCCESS(Status))
         {
             /* Bugcheck */
@@ -1498,7 +1502,7 @@ Phase1InitializationDiscard(IN PVOID Context)
     if (!PoInitSystem(0)) KeBugCheck(INTERNAL_POWER_ERROR);
 
     /* Check for Y2K hack */
-    Y2KHackRequired = strstr(CommandLine, "YEAR");
+    Y2KHackRequired = CommandLine ? strstr(CommandLine, "YEAR") : NULL;
     if (Y2KHackRequired) Y2KHackRequired = strstr(Y2KHackRequired, "=");
     if (Y2KHackRequired) YearHack = atol(Y2KHackRequired + 1);
 
@@ -1577,8 +1581,9 @@ Phase1InitializationDiscard(IN PVOID Context)
                                WINDOWS_NT_INFO_STRING,
                                &MsgEntry);
 
-    /* Get total RAM size */
-    Size = MmNumberOfPhysicalPages * PAGE_SIZE / 1024 / 1024;
+    /* Get total RAM size, in MiB */
+    /* Round size up. Assumed to better match actual physical RAM size */
+    Size = ALIGN_UP_BY(MmNumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
 
     /* Create the string */
     StringBuffer = InitBuffer->VersionBuffer;
@@ -1586,7 +1591,7 @@ Phase1InitializationDiscard(IN PVOID Context)
                                 sizeof(InitBuffer->VersionBuffer),
                                 NT_SUCCESS(MsgStatus) ?
                                 (PCHAR)MsgEntry->Text :
-                                "%u System Processor [%u MB Memory] %Z\n",
+                                "%u System Processor [%Iu MB Memory] %Z\r\n",
                                 KeNumberProcessors,
                                 Size,
                                 &TempString);
@@ -1949,14 +1954,20 @@ Phase1InitializationDiscard(IN PVOID Context)
     MmFreeLoaderBlock(LoaderBlock);
     LoaderBlock = Context = NULL;
 
+    /* Initialize the SRM in phase 1 */
+    if (!SeRmInitPhase1()) KeBugCheck(PROCESS1_INITIALIZATION_FAILED);
+
     /* Update progress bar */
     InbvUpdateProgressBar(100);
 
+    /* Clear the screen */
+    if (InbvBootDriverInstalled) FinalizeBootLogo();
+
     /* Allow strings to be displayed */
     InbvEnableDisplayString(TRUE);
 
     /* Launch initial process */
-    DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
+    DPRINT("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
     ProcessInfo = &InitBuffer->ProcessInfo;
     ExpLoadInitialProcess(InitBuffer, &ProcessParameters, &Environment);
 
@@ -1990,15 +2001,12 @@ Phase1InitializationDiscard(IN PVOID Context)
                         &Size,
                         MEM_RELEASE);
 
-    /* Clean the screen */
-    if (InbvBootDriverInstalled) FinalizeBootLogo();
-
     /* Increase init phase */
     ExpInitializationPhase++;
 
     /* Free the boot buffer */
     ExFreePoolWithTag(InitBuffer, TAG_INIT);
-    DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
+    DPRINT("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
 }
 
 VOID