- Implement NtInitalizeRegistry with proper boot flags instead of TRUE/FALSE (our...
authorAleksey Bragin <aleksey@reactos.org>
Sun, 2 Dec 2007 18:40:33 +0000 (18:40 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Sun, 2 Dec 2007 18:40:33 +0000 (18:40 +0000)
- Always set last mode to kernel-mode when calling this function.

svn path=/trunk/; revision=30966

reactos/base/setup/usetup/interface/usetup.c
reactos/base/system/smss/initreg.c
reactos/include/ndk/cmtypes.h
reactos/ntoskrnl/cm/ntfunc.c
reactos/ntoskrnl/config/cm.h
reactos/ntoskrnl/config/ntapi.c

index 6832cad..f4a8b62 100644 (file)
@@ -3197,7 +3197,7 @@ RegistryPage(PINPUT_RECORD Ir)
 
   /* Create the default hives */
 #ifdef __REACTOS__
-  Status = NtInitializeRegistry(TRUE);
+  Status = NtInitializeRegistry(CM_BOOT_FLAG_SETUP);
   if (!NT_SUCCESS(Status))
     {
       DPRINT("NtInitializeRegistry() failed (Status %lx)\n", Status);
index 615381c..c62a27e 100644 (file)
@@ -35,7 +35,7 @@ SmInitializeRegistry(VOID)
   DPRINT("SM: %s: initializing registry\n", __FUNCTION__);
 
   /* Load remaining registry hives */
-  return NtInitializeRegistry(FALSE);
+  return NtInitializeRegistry(CM_BOOT_FLAG_SMSS);
 }
 
 /* EOF */
index 2faef37..199051d 100644 (file)
@@ -110,6 +110,14 @@ typedef enum _CM_SHARE_DISPOSITION
 #define CM_RESOURCE_DMA_TYPE_B            0x0020
 #define CM_RESOURCE_DMA_TYPE_F            0x0040
 
+//
+// NtInitializeRegistry Flags
+//
+#define CM_BOOT_FLAG_SMSS                 0x0000
+#define CM_BOOT_FLAG_SETUP                0x0001
+#define CM_BOOT_FLAG_ACCEPTED             0x0002
+#define CM_BOOT_FLAG_MAX                  0x03E9
+
 #ifdef NTOS_MODE_USER
 
 //
@@ -510,3 +518,4 @@ typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
 
 #endif // _CMTYPES_H
 
+
index ff02ccb..c29ba0c 100644 (file)
@@ -30,8 +30,6 @@ CmpCreateHandle(PVOID ObjectBody,
                 ULONG HandleAttributes,
                 PHANDLE HandleReturn);
 
-static BOOLEAN CmiRegistryInitialized = FALSE;
-
 /* FUNCTIONS ****************************************************************/
 
 NTSTATUS
@@ -284,22 +282,4 @@ openkey_cleanup:
     return Status;
 }
 
-NTSTATUS
-NTAPI
-NtInitializeRegistry (IN USHORT Flag)
-{
-    PAGED_CODE();
-    
-    if (CmiRegistryInitialized == TRUE)
-        return STATUS_ACCESS_DENIED;
-    
-    /* Save boot log file */
-    IopSaveBootLogToFile();
-        
-    CmpCmdInit(Flag);
-    CmiRegistryInitialized = TRUE;
-    
-    return STATUS_SUCCESS;
-}
-
 /* EOF */
index d5c1884..850837f 100644 (file)
@@ -1353,6 +1353,15 @@ CmQueryValueKey(
     IN PULONG ResultLength
 );
 
+NTSTATUS
+NTAPI
+CmLoadKey(
+    IN POBJECT_ATTRIBUTES TargetKey,
+    IN POBJECT_ATTRIBUTES SourceFile,
+    IN ULONG Flags,
+    IN PKEY_OBJECT KeyBody
+);
+
 //
 // Startup and Shutdown
 //
@@ -1406,6 +1415,7 @@ extern BOOLEAN CmpForceForceFlush;
 extern BOOLEAN CmpWasSetupBoot;
 extern PCMHIVE CmiVolatileHive;
 extern LIST_ENTRY CmiKeyObjectListHead;
+extern BOOLEAN CmpHoldLazyFlush;
 
 //
 // Inlined functions
index e8c455c..633a918 100644 (file)
@@ -13,6 +13,9 @@
 #define NDEBUG
 #include "debug.h"
 
+BOOLEAN CmBootAcceptFirstTime = TRUE;
+BOOLEAN CmFirstTime = TRUE;
+
 /* FUNCTIONS *****************************************************************/
 
 NTSTATUS
@@ -501,13 +504,6 @@ NtLoadKey2(IN POBJECT_ATTRIBUTES KeyObjectAttributes,
     return NtLoadKeyEx(KeyObjectAttributes, FileObjectAttributes, Flags, NULL);
 }
 
-NTSTATUS
-NTAPI
-CmLoadKey(IN POBJECT_ATTRIBUTES TargetKey,
-          IN POBJECT_ATTRIBUTES SourceFile,
-          IN ULONG Flags,
-          IN PKEY_OBJECT KeyBody);
-
 NTSTATUS
 NTAPI
 NtLoadKeyEx(IN POBJECT_ATTRIBUTES TargetKey,
@@ -559,6 +555,68 @@ NtLoadKeyEx(IN POBJECT_ATTRIBUTES TargetKey,
     return Status;
 }
 
+NTSTATUS
+NTAPI
+NtInitializeRegistry(IN USHORT Flag)
+{
+    BOOLEAN SetupBoot;
+    NTSTATUS Status = STATUS_SUCCESS;
+    PAGED_CODE();
+
+    /* Always do this as kernel mode */
+    if (KeGetPreviousMode() == UserMode) return ZwInitializeRegistry(Flag);
+    
+    /* Validate flag */
+    if (Flag > CM_BOOT_FLAG_MAX) return STATUS_INVALID_PARAMETER;
+
+    /* Check if boot was accepted */
+    if ((Flag >= CM_BOOT_FLAG_ACCEPTED) && (Flag <= CM_BOOT_FLAG_MAX))
+    {
+        /* Only allow once */
+        if (!CmBootAcceptFirstTime) return STATUS_ACCESS_DENIED;
+        CmBootAcceptFirstTime = FALSE;
+        
+        /* Get the control set accepted */
+        Flag -= CM_BOOT_FLAG_ACCEPTED;
+        if (Flag)
+        {
+            /* FIXME: Save the last known good boot */
+            //Status = CmpSaveBootControlSet(Flag);
+            
+            /* Notify HAL */
+            HalEndOfBoot();
+
+            /* Enable lazy flush */
+            CmpHoldLazyFlush = FALSE;
+            CmpLazyFlush();
+            return Status;
+        }
+
+        /* Otherwise, invalid boot */
+        return STATUS_INVALID_PARAMETER;
+    }
+    
+    /* Check if this was a setup boot */
+    SetupBoot = (Flag == CM_BOOT_FLAG_SETUP ? TRUE : FALSE);
+
+    /* Make sure we're only called once */
+    if (!CmFirstTime) return STATUS_ACCESS_DENIED;
+    CmFirstTime = FALSE;
+    
+    /* Acquire registry lock */
+    //CmpLockRegistryExclusive();
+
+    /* Initialize the hives and lazy flusher */
+    CmpCmdInit(SetupBoot);
+
+    /* FIXME: Save version data */
+    //CmpSetVersionData();
+
+    /* Release the registry lock */
+    //CmpUnlockRegistry();
+    return STATUS_SUCCESS;
+}
+
 NTSTATUS
 NTAPI
 NtLockProductActivationKeys(IN PULONG pPrivateVer,