diff --git a/reactos/base/setup/usetup/interface/usetup.c b/reactos/base/setup/usetup/interface/usetup.c index 6832cad83b8..f4a8b629356 100644 --- a/reactos/base/setup/usetup/interface/usetup.c +++ b/reactos/base/setup/usetup/interface/usetup.c @@ -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); diff --git a/reactos/base/system/smss/initreg.c b/reactos/base/system/smss/initreg.c index 615381cd74c..c62a27e1f25 100644 --- a/reactos/base/system/smss/initreg.c +++ b/reactos/base/system/smss/initreg.c @@ -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 */ diff --git a/reactos/include/ndk/cmtypes.h b/reactos/include/ndk/cmtypes.h index 2faef370eea..199051d3ee1 100644 --- a/reactos/include/ndk/cmtypes.h +++ b/reactos/include/ndk/cmtypes.h @@ -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 + diff --git a/reactos/ntoskrnl/cm/ntfunc.c b/reactos/ntoskrnl/cm/ntfunc.c index ff02ccb084c..c29ba0c6bf0 100644 --- a/reactos/ntoskrnl/cm/ntfunc.c +++ b/reactos/ntoskrnl/cm/ntfunc.c @@ -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 */ diff --git a/reactos/ntoskrnl/config/cm.h b/reactos/ntoskrnl/config/cm.h index d5c18844767..850837f99ba 100644 --- a/reactos/ntoskrnl/config/cm.h +++ b/reactos/ntoskrnl/config/cm.h @@ -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 diff --git a/reactos/ntoskrnl/config/ntapi.c b/reactos/ntoskrnl/config/ntapi.c index e8c455ca23e..633a918b650 100644 --- a/reactos/ntoskrnl/config/ntapi.c +++ b/reactos/ntoskrnl/config/ntapi.c @@ -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,