2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/config/cmsysini.c
5 * PURPOSE: Configuration Manager - System Initialization Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 * Alex Ionescu (alex.ionescu@reactos.org)
10 /* INCLUDES *******************************************************************/
16 POBJECT_TYPE CmpKeyObjectType
;
17 PCMHIVE CmiVolatileHive
;
18 LIST_ENTRY CmpHiveListHead
;
19 ERESOURCE CmpRegistryLock
;
20 KGUARDED_MUTEX CmpSelfHealQueueLock
;
21 LIST_ENTRY CmpSelfHealQueueListHead
;
22 KEVENT CmpLoadWorkerEvent
;
23 LONG CmpLoadWorkerIncrement
;
24 PEPROCESS CmpSystemProcess
;
25 BOOLEAN HvShutdownComplete
;
26 PVOID CmpRegistryLockCallerCaller
, CmpRegistryLockCaller
;
27 BOOLEAN CmpFlushOnLockRelease
;
28 BOOLEAN CmpSpecialBootCondition
;
30 BOOLEAN CmpWasSetupBoot
;
31 BOOLEAN CmpProfileLoaded
;
32 BOOLEAN CmpNoVolatileCreates
;
33 ULONG CmpTraceLevel
= 0;
35 extern LONG CmpFlushStarveWriters
;
36 extern BOOLEAN CmFirstTime
;
38 /* FUNCTIONS ******************************************************************/
43 _In_z_ PCWSTR LinkKeyName
,
44 _In_z_ PCWSTR TargetKeyName
)
47 OBJECT_ATTRIBUTES ObjectAttributes
;
48 UNICODE_STRING KeyName
;
54 /* Initialize the object attributes */
55 RtlInitUnicodeString(&KeyName
, LinkKeyName
);
56 InitializeObjectAttributes(&ObjectAttributes
,
58 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
62 /* Create the link key */
63 Status
= ZwCreateKey(&LinkKeyHandle
,
68 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
70 if (!NT_SUCCESS(Status
))
72 DPRINT1("CM: CmpLinkKeyToHive: couldn't create %S, Status = 0x%lx\n",
77 /* Check if the new key was actually created */
78 if (Disposition
!= REG_CREATED_NEW_KEY
)
80 DPRINT1("CM: CmpLinkKeyToHive: %S already exists!\n", LinkKeyName
);
81 ZwClose(LinkKeyHandle
);
85 /* Set the target key name as link target */
86 RtlInitUnicodeString(&KeyName
, TargetKeyName
);
87 Status
= ZwSetValueKey(LinkKeyHandle
,
88 &CmSymbolicLinkValueName
,
94 /* Close the link key handle */
95 ObCloseHandle(LinkKeyHandle
, KernelMode
);
97 if (!NT_SUCCESS(Status
))
99 DPRINT1("CM: CmpLinkKeyToHive: couldn't create symbolic link for %S, Status = 0x%lx\n",
100 TargetKeyName
, Status
);
109 CmpDeleteKeyObject(PVOID DeletedObject
)
111 PCM_KEY_BODY KeyBody
= (PCM_KEY_BODY
)DeletedObject
;
112 PCM_KEY_CONTROL_BLOCK Kcb
;
113 REG_KEY_HANDLE_CLOSE_INFORMATION KeyHandleCloseInfo
;
114 REG_POST_OPERATION_INFORMATION PostOperationInfo
;
118 /* First off, prepare the handle close information callback */
119 PostOperationInfo
.Object
= KeyBody
;
120 KeyHandleCloseInfo
.Object
= KeyBody
;
121 Status
= CmiCallRegisteredCallbacks(RegNtPreKeyHandleClose
,
122 &KeyHandleCloseInfo
);
123 if (!NT_SUCCESS(Status
))
125 /* If we failed, notify the post routine */
126 PostOperationInfo
.Status
= Status
;
127 CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose
, &PostOperationInfo
);
131 /* Acquire hive lock */
134 /* Make sure this is a valid key body */
135 if (KeyBody
->Type
== CM_KEY_BODY_TYPE
)
138 Kcb
= KeyBody
->KeyControlBlock
;
142 DelistKeyBodyFromKCB(KeyBody
, FALSE
);
144 /* Dereference the KCB */
145 CmpDelayDerefKeyControlBlock(Kcb
);
149 /* Release the registry lock */
152 /* Do the post callback */
153 PostOperationInfo
.Status
= STATUS_SUCCESS
;
154 CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose
, &PostOperationInfo
);
159 CmpCloseKeyObject(IN PEPROCESS Process OPTIONAL
,
161 IN ACCESS_MASK GrantedAccess
,
162 IN ULONG ProcessHandleCount
,
163 IN ULONG SystemHandleCount
)
165 PCM_KEY_BODY KeyBody
= (PCM_KEY_BODY
)Object
;
168 /* Don't do anything if we're not the last handle */
169 if (SystemHandleCount
> 1) return;
171 /* Make sure we're a valid key body */
172 if (KeyBody
->Type
== CM_KEY_BODY_TYPE
)
174 /* Don't do anything if we don't have a notify block */
175 if (!KeyBody
->NotifyBlock
) return;
177 /* This shouldn't happen yet */
184 CmpQueryKeyName(IN PVOID ObjectBody
,
186 IN OUT POBJECT_NAME_INFORMATION ObjectNameInfo
,
188 OUT PULONG ReturnLength
,
189 IN KPROCESSOR_MODE PreviousMode
)
191 PUNICODE_STRING KeyName
;
193 NTSTATUS Status
= STATUS_SUCCESS
;
194 PCM_KEY_BODY KeyBody
= (PCM_KEY_BODY
)ObjectBody
;
195 PCM_KEY_CONTROL_BLOCK Kcb
= KeyBody
->KeyControlBlock
;
197 /* Acquire hive lock */
200 /* Lock KCB shared */
201 CmpAcquireKcbLockShared(Kcb
);
203 /* Check if it's a deleted block */
206 /* Release the locks */
207 CmpReleaseKcbLock(Kcb
);
210 /* Let the caller know it's deleted */
211 return STATUS_KEY_DELETED
;
215 KeyName
= CmpConstructName(Kcb
);
217 /* Release the locks */
218 CmpReleaseKcbLock(Kcb
);
221 /* Check if we got the name */
222 if (!KeyName
) return STATUS_INSUFFICIENT_RESOURCES
;
224 /* Set the returned length */
225 *ReturnLength
= KeyName
->Length
+ sizeof(OBJECT_NAME_INFORMATION
) + sizeof(WCHAR
);
227 /* Calculate amount of bytes to copy into the buffer */
228 BytesToCopy
= KeyName
->Length
+ sizeof(WCHAR
);
230 /* Check if the provided buffer is too small to fit even anything */
231 if ((Length
<= sizeof(OBJECT_NAME_INFORMATION
)) ||
232 ((Length
< (*ReturnLength
)) && (BytesToCopy
< sizeof(WCHAR
))))
234 /* Free the buffer allocated by CmpConstructName */
235 ExFreePoolWithTag(KeyName
, TAG_CM
);
237 /* Return buffer length failure without writing anything there because nothing fits */
238 return STATUS_INFO_LENGTH_MISMATCH
;
241 /* Check if the provided buffer can be partially written */
242 if (Length
< (*ReturnLength
))
244 /* Yes, indicate so in the return status */
245 Status
= STATUS_INFO_LENGTH_MISMATCH
;
247 /* Calculate amount of bytes which the provided buffer could handle */
248 BytesToCopy
= Length
- sizeof(OBJECT_NAME_INFORMATION
);
251 /* Remove the null termination character from the size */
252 BytesToCopy
-= sizeof(WCHAR
);
254 /* Fill in the result */
257 /* Return data to user */
258 ObjectNameInfo
->Name
.Buffer
= (PWCHAR
)(ObjectNameInfo
+ 1);
259 ObjectNameInfo
->Name
.MaximumLength
= KeyName
->Length
;
260 ObjectNameInfo
->Name
.Length
= KeyName
->Length
;
262 /* Copy string content*/
263 RtlCopyMemory(ObjectNameInfo
->Name
.Buffer
,
267 /* Null terminate it */
268 ObjectNameInfo
->Name
.Buffer
[BytesToCopy
/ sizeof(WCHAR
)] = UNICODE_NULL
;
270 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
273 Status
= _SEH2_GetExceptionCode();
277 /* Free the buffer allocated by CmpConstructName */
278 ExFreePoolWithTag(KeyName
, TAG_CM
);
286 CmpInitHiveFromFile(IN PCUNICODE_STRING HiveName
,
292 ULONG HiveDisposition
, LogDisposition
;
293 HANDLE FileHandle
= NULL
, LogHandle
= NULL
;
295 ULONG Operation
, FileType
;
302 /* Open or create the hive files */
303 Status
= CmpOpenHiveFiles(HiveName
,
313 if (!NT_SUCCESS(Status
)) return Status
;
315 /* Check if we have a log handle */
316 FileType
= (LogHandle
) ? HFILE_TYPE_LOG
: HFILE_TYPE_PRIMARY
;
318 /* Check if we created or opened the hive */
319 if (HiveDisposition
== FILE_CREATED
)
321 /* Do a create operation */
322 Operation
= HINIT_CREATE
;
327 /* Open it as a file */
328 Operation
= HINIT_FILE
;
332 /* Check if we're sharing hives */
333 if (CmpShareSystemHives
)
335 /* Then force using the primary hive */
336 FileType
= HFILE_TYPE_PRIMARY
;
339 /* Get rid of the log handle */
345 /* Check if we're too late */
346 if (HvShutdownComplete
)
350 if (LogHandle
) ZwClose(LogHandle
);
351 return STATUS_TOO_LATE
;
354 /* Initialize the hive */
355 Status
= CmpInitializeHive(&NewHive
,
365 if (!NT_SUCCESS(Status
))
369 if (LogHandle
) ZwClose(LogHandle
);
373 /* Success, return hive */
376 /* Duplicate the hive name */
377 NewHive
->FileFullPath
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
380 if (NewHive
->FileFullPath
.Buffer
)
382 /* Copy the string */
383 RtlCopyMemory(NewHive
->FileFullPath
.Buffer
,
386 NewHive
->FileFullPath
.Length
= HiveName
->Length
;
387 NewHive
->FileFullPath
.MaximumLength
= HiveName
->Length
;
391 return STATUS_SUCCESS
;
397 CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
399 OBJECT_ATTRIBUTES ObjectAttributes
;
400 UNICODE_STRING KeyName
, ValueName
= { 0, 0, NULL
};
401 HANDLE KeyHandle
= NULL
;
403 ASSERT(LoaderBlock
!= NULL
);
405 /* Setup attributes for loader options */
406 RtlInitUnicodeString(&KeyName
,
407 L
"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\"
409 InitializeObjectAttributes(&ObjectAttributes
,
411 OBJ_CASE_INSENSITIVE
,
414 Status
= NtOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
415 if (!NT_SUCCESS(Status
)) goto Quickie
;
417 /* Key opened, now write to the key */
418 RtlInitUnicodeString(&KeyName
, L
"SystemStartOptions");
419 Status
= NtSetValueKey(KeyHandle
,
423 CmpLoadOptions
.Buffer
,
424 CmpLoadOptions
.Length
);
425 if (!NT_SUCCESS(Status
)) goto Quickie
;
427 /* Setup value name for system boot device in ARC format */
428 RtlInitUnicodeString(&KeyName
, L
"SystemBootDevice");
429 RtlCreateUnicodeStringFromAsciiz(&ValueName
, LoaderBlock
->ArcBootDeviceName
);
430 Status
= NtSetValueKey(KeyHandle
,
438 /* Free the buffers */
439 RtlFreeUnicodeString(&ValueName
);
441 /* Close the key and return */
442 if (KeyHandle
) NtClose(KeyHandle
);
444 /* Return the status */
445 return (ExpInTextModeSetup
? STATUS_SUCCESS
: Status
);
451 CmpCreateHardwareProfile(HANDLE ControlSetHandle
)
453 OBJECT_ATTRIBUTES ObjectAttributes
;
454 UNICODE_STRING KeyName
;
455 HANDLE ProfilesHandle
= NULL
;
456 HANDLE ProfileHandle
= NULL
;
460 DPRINT("CmpCreateHardwareProfile()\n");
462 /* Create the Hardware Profiles key */
463 RtlInitUnicodeString(&KeyName
, L
"Hardware Profiles");
464 InitializeObjectAttributes(&ObjectAttributes
,
466 OBJ_CASE_INSENSITIVE
,
469 Status
= NtCreateKey(&ProfilesHandle
,
476 if (!NT_SUCCESS(Status
))
478 DPRINT1("Creating the Hardware Profile key failed\n");
483 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
485 /* Create the 0000 key */
486 RtlInitUnicodeString(&KeyName
, L
"0000");
487 InitializeObjectAttributes(&ObjectAttributes
,
489 OBJ_CASE_INSENSITIVE
,
492 Status
= NtCreateKey(&ProfileHandle
,
499 if (!NT_SUCCESS(Status
))
501 DPRINT1("Creating the Hardware Profile\\0000 key failed\n");
506 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
510 NtClose(ProfilesHandle
);
513 NtClose(ProfileHandle
);
515 DPRINT("CmpCreateHardwareProfile() done\n");
523 CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
525 UNICODE_STRING ConfigName
= RTL_CONSTANT_STRING(L
"Control\\IDConfigDB");
526 UNICODE_STRING SelectName
=
527 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\System\\Select");
528 UNICODE_STRING KeyName
;
529 OBJECT_ATTRIBUTES ObjectAttributes
;
530 CHAR ValueInfoBuffer
[128];
531 PKEY_VALUE_FULL_INFORMATION ValueInfo
;
532 WCHAR UnicodeBuffer
[128];
533 HANDLE SelectHandle
= NULL
;
534 HANDLE KeyHandle
= NULL
;
535 HANDLE ConfigHandle
= NULL
;
536 HANDLE ProfileHandle
= NULL
;
537 HANDLE ParentHandle
= NULL
;
538 ULONG ControlSet
, HwProfile
;
540 ULONG ResultLength
, Disposition
;
541 PLOADER_PARAMETER_EXTENSION LoaderExtension
;
544 /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
545 if (LoaderBlock
->RegistryBase
== NULL
)
547 /* Build the ControlSet001 key */
548 RtlInitUnicodeString(&KeyName
,
549 L
"\\Registry\\Machine\\System\\ControlSet001");
550 InitializeObjectAttributes(&ObjectAttributes
,
552 OBJ_CASE_INSENSITIVE
,
555 Status
= NtCreateKey(&KeyHandle
,
562 if (!NT_SUCCESS(Status
))
564 DPRINT1("Failed to create ControlSet001 key: 0x%lx\n", Status
);
568 /* Create the Hardware Profile keys */
569 Status
= CmpCreateHardwareProfile(KeyHandle
);
570 if (!NT_SUCCESS(Status
))
572 DPRINT1("Failed to create Hardware profile keys: 0x%lx\n", Status
);
576 /* Use hard-coded setting */
581 /* Open the select key */
582 InitializeObjectAttributes(&ObjectAttributes
,
584 OBJ_CASE_INSENSITIVE
,
587 Status
= NtOpenKey(&SelectHandle
, KEY_READ
, &ObjectAttributes
);
588 if (!NT_SUCCESS(Status
))
590 DPRINT1("Failed to open select key: 0x%lx\n", Status
);
594 /* Open the current value */
595 RtlInitUnicodeString(&KeyName
, L
"Current");
596 Status
= NtQueryValueKey(SelectHandle
,
598 KeyValueFullInformation
,
600 sizeof(ValueInfoBuffer
),
602 if (!NT_SUCCESS(Status
))
604 DPRINT1("Failed to open the Current value: 0x%lx\n", Status
);
608 /* Get the actual value pointer, and get the control set ID */
609 ValueInfo
= (PKEY_VALUE_FULL_INFORMATION
)ValueInfoBuffer
;
610 ControlSet
= *(PULONG
)((PUCHAR
)ValueInfo
+ ValueInfo
->DataOffset
);
613 /* Create the current control set key */
614 RtlInitUnicodeString(&KeyName
,
615 L
"\\Registry\\Machine\\System\\CurrentControlSet");
616 InitializeObjectAttributes(&ObjectAttributes
,
618 OBJ_CASE_INSENSITIVE
,
621 Status
= NtCreateKey(&KeyHandle
,
626 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
628 if (!NT_SUCCESS(Status
))
632 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
634 /* Initialize the target link name */
635 Status
= RtlStringCbPrintfW(UnicodeBuffer
, sizeof(UnicodeBuffer
),
636 L
"\\Registry\\Machine\\System\\ControlSet%03ld",
638 if (!NT_SUCCESS(Status
))
641 RtlInitUnicodeString(&KeyName
, UnicodeBuffer
);
644 Status
= NtSetValueKey(KeyHandle
,
645 &CmSymbolicLinkValueName
,
650 if (!NT_SUCCESS(Status
))
653 /* Get the configuration database key */
654 InitializeObjectAttributes(&ObjectAttributes
,
656 OBJ_CASE_INSENSITIVE
,
659 Status
= NtOpenKey(&ConfigHandle
, KEY_READ
, &ObjectAttributes
);
661 /* Check if we don't have one */
662 if (!NT_SUCCESS(Status
))
664 /* Cleanup and exit */
665 Status
= STATUS_SUCCESS
;
669 /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
670 if (LoaderBlock
->RegistryBase
== NULL
)
676 /* Now get the current config */
677 RtlInitUnicodeString(&KeyName
, L
"CurrentConfig");
678 Status
= NtQueryValueKey(ConfigHandle
,
680 KeyValueFullInformation
,
682 sizeof(ValueInfoBuffer
),
685 /* Set pointer to buffer */
686 ValueInfo
= (PKEY_VALUE_FULL_INFORMATION
)ValueInfoBuffer
;
688 /* Check if we failed or got a non DWORD-value */
689 if (!(NT_SUCCESS(Status
)) || (ValueInfo
->Type
!= REG_DWORD
))
691 Status
= STATUS_SUCCESS
;
695 /* Get the hadware profile */
696 HwProfile
= *(PULONG
)((PUCHAR
)ValueInfo
+ ValueInfo
->DataOffset
);
699 /* Open the hardware profile key */
700 RtlInitUnicodeString(&KeyName
,
701 L
"\\Registry\\Machine\\System\\CurrentControlSet"
702 L
"\\Hardware Profiles");
703 InitializeObjectAttributes(&ObjectAttributes
,
705 OBJ_CASE_INSENSITIVE
,
708 Status
= NtOpenKey(&ParentHandle
, KEY_READ
, &ObjectAttributes
);
709 if (!NT_SUCCESS(Status
))
711 /* Exit and clean up */
712 Status
= STATUS_SUCCESS
;
716 /* Build the profile name */
717 RtlStringCbPrintfW(UnicodeBuffer
, sizeof(UnicodeBuffer
),
718 L
"%04ld", HwProfile
);
719 RtlInitUnicodeString(&KeyName
, UnicodeBuffer
);
721 /* Open the associated key */
722 InitializeObjectAttributes(&ObjectAttributes
,
724 OBJ_CASE_INSENSITIVE
,
727 Status
= NtOpenKey(&ProfileHandle
,
728 KEY_READ
| KEY_WRITE
,
730 if (!NT_SUCCESS (Status
))
732 /* Cleanup and exit */
733 Status
= STATUS_SUCCESS
;
737 /* Check if we have a loader block extension */
738 LoaderExtension
= LoaderBlock
->Extension
;
741 DPRINT("ReactOS doesn't support NTLDR Profiles yet!\n");
744 /* Create the current hardware profile key */
745 RtlInitUnicodeString(&KeyName
,
746 L
"\\Registry\\Machine\\System\\CurrentControlSet\\"
747 L
"Hardware Profiles\\Current");
748 InitializeObjectAttributes(&ObjectAttributes
,
750 OBJ_CASE_INSENSITIVE
,
753 Status
= NtCreateKey(&KeyHandle
,
758 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
760 if (NT_SUCCESS(Status
))
763 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
765 /* Create the profile name */
766 RtlStringCbPrintfW(UnicodeBuffer
, sizeof(UnicodeBuffer
),
767 L
"\\Registry\\Machine\\System\\CurrentControlSet\\"
768 L
"Hardware Profiles\\%04ld",
770 RtlInitUnicodeString(&KeyName
, UnicodeBuffer
);
773 Status
= NtSetValueKey(KeyHandle
,
774 &CmSymbolicLinkValueName
,
781 Status
= STATUS_SUCCESS
;
784 /* Close every opened handle */
785 if (SelectHandle
) NtClose(SelectHandle
);
786 if (KeyHandle
) NtClose(KeyHandle
);
787 if (ConfigHandle
) NtClose(ConfigHandle
);
788 if (ProfileHandle
) NtClose(ProfileHandle
);
789 if (ParentHandle
) NtClose(ParentHandle
);
791 DPRINT("CmpCreateControlSet() done\n");
797 CmpLinkHiveToMaster(IN PUNICODE_STRING LinkName
,
798 IN HANDLE RootDirectory
,
799 IN PCMHIVE RegistryHive
,
801 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
803 OBJECT_ATTRIBUTES ObjectAttributes
;
805 CM_PARSE_CONTEXT ParseContext
= {0};
807 PCM_KEY_BODY KeyBody
;
810 /* Setup the object attributes */
811 InitializeObjectAttributes(&ObjectAttributes
,
813 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
817 /* Setup the parse context */
818 ParseContext
.CreateLink
= TRUE
;
819 ParseContext
.CreateOperation
= TRUE
;
820 ParseContext
.ChildHive
.KeyHive
= &RegistryHive
->Hive
;
822 /* Check if we have a root keycell or if we need to create it */
826 ParseContext
.ChildHive
.KeyCell
= HCELL_NIL
;
831 ParseContext
.ChildHive
.KeyCell
= RegistryHive
->Hive
.BaseBlock
->RootCell
;
834 /* Create the link node */
835 Status
= ObOpenObjectByName(&ObjectAttributes
,
839 KEY_READ
| KEY_WRITE
,
840 (PVOID
)&ParseContext
,
842 if (!NT_SUCCESS(Status
)) return Status
;
844 /* Mark the hive as clean */
845 RegistryHive
->Hive
.DirtyFlag
= FALSE
;
847 /* ReactOS Hack: Keep alive */
848 Status
= ObReferenceObjectByHandle(KeyHandle
,
854 ASSERT(NT_SUCCESS(Status
));
856 /* Close the extra handle */
858 return STATUS_SUCCESS
;
864 CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
866 static const UNICODE_STRING HiveName
= RTL_CONSTANT_STRING(L
"SYSTEM");
868 ANSI_STRING LoadString
;
872 UNICODE_STRING KeyName
;
873 PCMHIVE SystemHive
= NULL
;
874 PSECURITY_DESCRIPTOR SecurityDescriptor
;
879 /* Setup the ansi string */
880 RtlInitAnsiString(&LoadString
, LoaderBlock
->LoadOptions
);
882 /* Allocate the unicode buffer */
883 Length
= LoadString
.Length
* sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
884 Buffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_CM
);
888 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
, 3, 1, (ULONG_PTR
)LoaderBlock
, 0);
891 /* Setup the unicode string */
892 RtlInitEmptyUnicodeString(&CmpLoadOptions
, Buffer
, (USHORT
)Length
);
894 /* Add the load options and null-terminate */
895 Status
= RtlAnsiStringToUnicodeString(&CmpLoadOptions
, &LoadString
, FALSE
);
896 if (!NT_SUCCESS(Status
))
901 CmpLoadOptions
.Buffer
[LoadString
.Length
] = UNICODE_NULL
;
902 CmpLoadOptions
.Length
+= sizeof(WCHAR
);
904 /* Get the System Hive base address */
905 HiveBase
= LoaderBlock
->RegistryBase
;
907 Status
= CmpInitializeHive(&SystemHive
,
908 HiveBase
? HINIT_MEMORY
: HINIT_CREATE
,
917 if (!NT_SUCCESS(Status
))
922 /* Set the hive filename */
923 Success
= RtlCreateUnicodeString(&SystemHive
->FileFullPath
,
924 L
"\\SystemRoot\\System32\\Config\\SYSTEM");
930 /* Manually set the hive as volatile, if in Live CD mode */
931 if (HiveBase
&& CmpShareSystemHives
)
933 SystemHive
->Hive
.HiveFlags
= HIVE_VOLATILE
;
936 /* Save the boot type */
937 CmpBootType
= SystemHive
->Hive
.BaseBlock
->BootType
;
939 /* Are we in self-healing mode? */
942 /* Disable self-healing internally and check if boot type wanted it */
946 /* We're disabled, so bugcheck */
947 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
,
950 (ULONG_PTR
)SystemHive
,
955 /* Create the default security descriptor */
956 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
958 /* Attach it to the system key */
959 /* Let CmpLinkHiveToMaster allocate a new hive if we got none from the LoaderBlock. */
960 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\SYSTEM");
961 Status
= CmpLinkHiveToMaster(&KeyName
,
967 /* Free the security descriptor */
968 ExFreePoolWithTag(SecurityDescriptor
, TAG_CMSD
);
969 if (!NT_SUCCESS(Status
)) return FALSE
;
971 /* Add the hive to the hive list */
972 CmpMachineHiveList
[3].CmHive
= SystemHive
;
981 CmpCreateObjectTypes(VOID
)
983 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer
;
985 GENERIC_MAPPING CmpKeyMapping
= {KEY_READ
,
991 /* Initialize the Key object type */
992 RtlZeroMemory(&ObjectTypeInitializer
, sizeof(ObjectTypeInitializer
));
993 RtlInitUnicodeString(&Name
, L
"Key");
994 ObjectTypeInitializer
.Length
= sizeof(ObjectTypeInitializer
);
995 ObjectTypeInitializer
.DefaultPagedPoolCharge
= sizeof(CM_KEY_BODY
);
996 ObjectTypeInitializer
.GenericMapping
= CmpKeyMapping
;
997 ObjectTypeInitializer
.PoolType
= PagedPool
;
998 ObjectTypeInitializer
.ValidAccessMask
= KEY_ALL_ACCESS
;
999 ObjectTypeInitializer
.UseDefaultObject
= TRUE
;
1000 ObjectTypeInitializer
.DeleteProcedure
= CmpDeleteKeyObject
;
1001 ObjectTypeInitializer
.ParseProcedure
= CmpParseKey
;
1002 ObjectTypeInitializer
.SecurityProcedure
= CmpSecurityMethod
;
1003 ObjectTypeInitializer
.QueryNameProcedure
= CmpQueryKeyName
;
1004 ObjectTypeInitializer
.CloseProcedure
= CmpCloseKeyObject
;
1005 ObjectTypeInitializer
.SecurityRequired
= TRUE
;
1006 ObjectTypeInitializer
.InvalidAttributes
= OBJ_EXCLUSIVE
| OBJ_PERMANENT
;
1009 return ObCreateObjectType(&Name
, &ObjectTypeInitializer
, NULL
, &CmpKeyObjectType
);
1015 CmpCreateRootNode(IN PHHIVE Hive
,
1017 OUT PHCELL_INDEX Index
)
1019 UNICODE_STRING KeyName
;
1020 PCM_KEY_NODE KeyCell
;
1023 /* Initialize the node name and allocate it */
1024 RtlInitUnicodeString(&KeyName
, Name
);
1025 *Index
= HvAllocateCell(Hive
,
1026 FIELD_OFFSET(CM_KEY_NODE
, Name
) +
1027 CmpNameSize(Hive
, &KeyName
),
1030 if (*Index
== HCELL_NIL
) return FALSE
;
1032 /* Set the cell index and get the data */
1033 Hive
->BaseBlock
->RootCell
= *Index
;
1034 KeyCell
= (PCM_KEY_NODE
)HvGetCell(Hive
, *Index
);
1035 if (!KeyCell
) return FALSE
;
1037 /* Setup the cell */
1038 KeyCell
->Signature
= CM_KEY_NODE_SIGNATURE
;
1039 KeyCell
->Flags
= KEY_HIVE_ENTRY
| KEY_NO_DELETE
;
1040 KeQuerySystemTime(&KeyCell
->LastWriteTime
);
1041 KeyCell
->Parent
= HCELL_NIL
;
1042 KeyCell
->SubKeyCounts
[Stable
] = 0;
1043 KeyCell
->SubKeyCounts
[Volatile
] = 0;
1044 KeyCell
->SubKeyLists
[Stable
] = HCELL_NIL
;
1045 KeyCell
->SubKeyLists
[Volatile
] = HCELL_NIL
;
1046 KeyCell
->ValueList
.Count
= 0;
1047 KeyCell
->ValueList
.List
= HCELL_NIL
;
1048 KeyCell
->Security
= HCELL_NIL
;
1049 KeyCell
->Class
= HCELL_NIL
;
1050 KeyCell
->ClassLength
= 0;
1051 KeyCell
->MaxNameLen
= 0;
1052 KeyCell
->MaxClassLen
= 0;
1053 KeyCell
->MaxValueNameLen
= 0;
1054 KeyCell
->MaxValueDataLen
= 0;
1056 /* Copy the name (this will also set the length) */
1057 KeyCell
->NameLength
= CmpCopyName(Hive
, KeyCell
->Name
, &KeyName
);
1059 /* Check if the name was compressed and set the flag if so */
1060 if (KeyCell
->NameLength
< KeyName
.Length
)
1061 KeyCell
->Flags
|= KEY_COMP_NAME
;
1063 /* Return success */
1064 HvReleaseCell(Hive
, *Index
);
1071 CmpCreateRegistryRoot(VOID
)
1073 UNICODE_STRING KeyName
;
1074 OBJECT_ATTRIBUTES ObjectAttributes
;
1075 PCM_KEY_BODY RootKey
;
1076 HCELL_INDEX RootIndex
;
1078 PCM_KEY_NODE KeyCell
;
1079 PSECURITY_DESCRIPTOR SecurityDescriptor
;
1080 PCM_KEY_CONTROL_BLOCK Kcb
;
1083 /* Setup the root node */
1084 if (!CmpCreateRootNode(&CmiVolatileHive
->Hive
, L
"REGISTRY", &RootIndex
))
1090 /* Create '\Registry' key. */
1091 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY");
1092 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
1093 InitializeObjectAttributes(&ObjectAttributes
,
1095 OBJ_CASE_INSENSITIVE
,
1097 SecurityDescriptor
);
1098 Status
= ObCreateObject(KernelMode
,
1103 sizeof(CM_KEY_BODY
),
1107 ExFreePoolWithTag(SecurityDescriptor
, TAG_CMSD
);
1108 if (!NT_SUCCESS(Status
)) return FALSE
;
1110 /* Sanity check, and get the key cell */
1111 ASSERT((&CmiVolatileHive
->Hive
)->ReleaseCellRoutine
== NULL
);
1112 KeyCell
= (PCM_KEY_NODE
)HvGetCell(&CmiVolatileHive
->Hive
, RootIndex
);
1113 if (!KeyCell
) return FALSE
;
1115 /* Create the KCB */
1116 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY");
1117 Kcb
= CmpCreateKeyControlBlock(&CmiVolatileHive
->Hive
,
1125 ObDereferenceObject(RootKey
);
1129 /* Initialize the object */
1130 RootKey
->KeyControlBlock
= Kcb
;
1131 RootKey
->Type
= CM_KEY_BODY_TYPE
;
1132 RootKey
->NotifyBlock
= NULL
;
1133 RootKey
->ProcessID
= PsGetCurrentProcessId();
1136 EnlistKeyBodyWithKCB(RootKey
, 0);
1138 /* Insert the key into the namespace */
1139 Status
= ObInsertObject(RootKey
,
1144 &CmpRegistryRootHandle
);
1145 if (!NT_SUCCESS(Status
))
1147 ObDereferenceObject(RootKey
);
1151 /* Reference the key again so that we never lose it */
1152 Status
= ObReferenceObjectByHandle(CmpRegistryRootHandle
,
1158 if (!NT_SUCCESS(Status
))
1160 ObDereferenceObject(RootKey
);
1164 /* Completely sucessful */
1170 CmpGetRegistryPath(OUT PWCHAR ConfigPath
)
1172 OBJECT_ATTRIBUTES ObjectAttributes
;
1175 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo
;
1176 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\HARDWARE");
1177 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"InstallPath");
1178 ULONG BufferSize
, ResultSize
;
1180 /* Check if we are booted in setup */
1181 if (ExpInTextModeSetup
)
1183 DPRINT1("CmpGetRegistryPath TextMode setup HACK!!\n");
1185 /* Setup the object attributes */
1186 InitializeObjectAttributes(&ObjectAttributes
,
1188 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
1192 Status
= ZwOpenKey(&KeyHandle
,
1195 if (!NT_SUCCESS(Status
)) return Status
;
1197 /* Allocate the buffer */
1198 BufferSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 4096;
1199 ValueInfo
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_CM
);
1204 return STATUS_INSUFFICIENT_RESOURCES
;
1207 /* Query the value */
1208 Status
= ZwQueryValueKey(KeyHandle
,
1210 KeyValuePartialInformation
,
1215 if (!NT_SUCCESS(Status
))
1218 ExFreePoolWithTag(ValueInfo
, TAG_CM
);
1222 /* Copy the config path and null-terminate it */
1223 RtlCopyMemory(ConfigPath
,
1225 ValueInfo
->DataLength
);
1226 ConfigPath
[ValueInfo
->DataLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1227 ExFreePoolWithTag(ValueInfo
, TAG_CM
);
1231 /* Just use default path */
1232 wcscpy(ConfigPath
, L
"\\SystemRoot");
1235 /* Add registry path */
1236 wcscat(ConfigPath
, L
"\\System32\\Config\\");
1238 DPRINT1("CmpGetRegistryPath: ConfigPath = '%S'\n", ConfigPath
);
1241 return STATUS_SUCCESS
;
1244 _Function_class_(KSTART_ROUTINE
)
1247 CmpLoadHiveThread(IN PVOID StartContext
)
1249 WCHAR FileBuffer
[MAX_PATH
], RegBuffer
[MAX_PATH
], ConfigPath
[MAX_PATH
];
1250 UNICODE_STRING TempName
, FileName
, RegName
;
1251 ULONG i
, ErrorResponse
, WorkerCount
, Length
;
1253 ULONG PrimaryDisposition
, SecondaryDisposition
, ClusterSize
;
1255 HANDLE PrimaryHandle
= NULL
, LogHandle
= NULL
;
1256 NTSTATUS Status
= STATUS_SUCCESS
;
1257 PVOID ErrorParameters
;
1260 /* Get the hive index, make sure it makes sense */
1261 i
= PtrToUlong(StartContext
);
1262 ASSERT(CmpMachineHiveList
[i
].Name
!= NULL
);
1264 /* We were started */
1265 CmpMachineHiveList
[i
].ThreadStarted
= TRUE
;
1267 /* Build the file name and registry name strings */
1268 RtlInitEmptyUnicodeString(&FileName
, FileBuffer
, sizeof(FileBuffer
));
1269 RtlInitEmptyUnicodeString(&RegName
, RegBuffer
, sizeof(RegBuffer
));
1271 /* Now build the system root path */
1272 CmpGetRegistryPath(ConfigPath
);
1273 RtlInitUnicodeString(&TempName
, ConfigPath
);
1274 RtlAppendUnicodeStringToString(&FileName
, &TempName
);
1275 FileStart
= FileName
.Length
;
1277 /* And build the registry root path */
1278 RtlInitUnicodeString(&TempName
, L
"\\REGISTRY\\");
1279 RtlAppendUnicodeStringToString(&RegName
, &TempName
);
1281 /* Build the base name */
1282 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].BaseName
);
1283 RtlAppendUnicodeStringToString(&RegName
, &TempName
);
1285 /* Check if this is a child of the root */
1286 if (RegName
.Buffer
[RegName
.Length
/ sizeof(WCHAR
) - 1] == OBJ_NAME_PATH_SEPARATOR
)
1288 /* Then setup the whole name */
1289 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].Name
);
1290 RtlAppendUnicodeStringToString(&RegName
, &TempName
);
1293 /* Now add the rest of the file name */
1294 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].Name
);
1295 FileName
.Length
= FileStart
;
1296 RtlAppendUnicodeStringToString(&FileName
, &TempName
);
1297 if (!CmpMachineHiveList
[i
].CmHive
)
1299 /* We need to allocate a new hive structure */
1300 CmpMachineHiveList
[i
].Allocate
= TRUE
;
1302 /* Load the hive file */
1303 Status
= CmpInitHiveFromFile(&FileName
,
1304 CmpMachineHiveList
[i
].HHiveFlags
,
1306 &CmpMachineHiveList
[i
].Allocate
,
1308 if (!(NT_SUCCESS(Status
)) ||
1309 (!(CmpShareSystemHives
) && !(CmHive
->FileHandles
[HFILE_TYPE_LOG
])))
1312 * We failed, or could not get a log file (unless
1313 * the hive is shared), raise a hard error.
1315 ErrorParameters
= &FileName
;
1316 NtRaiseHardError(STATUS_CANNOT_LOAD_REGISTRY_FILE
,
1319 (PULONG_PTR
)&ErrorParameters
,
1324 /* Set the hive flags and newly allocated hive pointer */
1325 CmHive
->Flags
= CmpMachineHiveList
[i
].CmHiveFlags
;
1326 CmpMachineHiveList
[i
].CmHive2
= CmHive
;
1330 /* We already have a hive, is it volatile? */
1331 CmHive
= CmpMachineHiveList
[i
].CmHive
;
1332 if (!(CmHive
->Hive
.HiveFlags
& HIVE_VOLATILE
))
1334 /* It's now, open the hive file and log */
1335 Status
= CmpOpenHiveFiles(&FileName
,
1339 &PrimaryDisposition
,
1340 &SecondaryDisposition
,
1345 if (!(NT_SUCCESS(Status
)) || !(LogHandle
))
1347 /* Couldn't open the hive or its log file, raise a hard error */
1348 ErrorParameters
= &FileName
;
1349 NtRaiseHardError(STATUS_CANNOT_LOAD_REGISTRY_FILE
,
1352 (PULONG_PTR
)&ErrorParameters
,
1356 /* And bugcheck for posterity's sake */
1357 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
, 9, 0, i
, Status
);
1360 /* Save the file handles. This should remove our sync hacks */
1361 CmHive
->FileHandles
[HFILE_TYPE_LOG
] = LogHandle
;
1362 CmHive
->FileHandles
[HFILE_TYPE_PRIMARY
] = PrimaryHandle
;
1364 /* Allow lazy flushing since the handles are there -- remove sync hacks */
1365 //ASSERT(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH);
1366 CmHive
->Hive
.HiveFlags
&= ~HIVE_NOLAZYFLUSH
;
1368 /* Get the real size of the hive */
1369 Length
= CmHive
->Hive
.Storage
[Stable
].Length
+ HBLOCK_SIZE
;
1371 /* Check if the cluster size doesn't match */
1372 if (CmHive
->Hive
.Cluster
!= ClusterSize
) ASSERT(FALSE
);
1374 /* Set the file size */
1375 DPRINT("FIXME: Should set file size: %lx\n", Length
);
1376 //if (!CmpFileSetSize((PHHIVE)CmHive, HFILE_TYPE_PRIMARY, Length, Length))
1378 /* This shouldn't fail */
1382 /* Another thing we don't support is NTLDR-recovery */
1383 if (CmHive
->Hive
.BaseBlock
->BootRecover
) ASSERT(FALSE
);
1385 /* Finally, set our allocated hive to the same hive we've had */
1386 CmpMachineHiveList
[i
].CmHive2
= CmHive
;
1387 ASSERT(CmpMachineHiveList
[i
].CmHive
== CmpMachineHiveList
[i
].CmHive2
);
1392 CmpMachineHiveList
[i
].ThreadFinished
= TRUE
;
1394 /* Check if we're the last worker */
1395 WorkerCount
= InterlockedIncrement(&CmpLoadWorkerIncrement
);
1396 if (WorkerCount
== CM_NUMBER_OF_MACHINE_HIVES
)
1398 /* Signal the event */
1399 KeSetEvent(&CmpLoadWorkerEvent
, 0, FALSE
);
1402 /* Kill the thread */
1403 PsTerminateSystemThread(Status
);
1408 CmpInitializeHiveList(IN USHORT Flag
)
1410 WCHAR FileBuffer
[MAX_PATH
], RegBuffer
[MAX_PATH
], ConfigPath
[MAX_PATH
];
1411 UNICODE_STRING TempName
, FileName
, RegName
;
1416 PSECURITY_DESCRIPTOR SecurityDescriptor
;
1419 /* Allow writing for now */
1422 /* Build the file name and registry name strings */
1423 RtlInitEmptyUnicodeString(&FileName
, FileBuffer
, sizeof(FileBuffer
));
1424 RtlInitEmptyUnicodeString(&RegName
, RegBuffer
, sizeof(RegBuffer
));
1426 /* Now build the system root path */
1427 CmpGetRegistryPath(ConfigPath
);
1428 RtlInitUnicodeString(&TempName
, ConfigPath
);
1429 RtlAppendUnicodeStringToString(&FileName
, &TempName
);
1431 /* And build the registry root path */
1432 RtlInitUnicodeString(&TempName
, L
"\\REGISTRY\\");
1433 RtlAppendUnicodeStringToString(&RegName
, &TempName
);
1434 RegStart
= RegName
.Length
;
1436 /* Setup the event to synchronize workers */
1437 KeInitializeEvent(&CmpLoadWorkerEvent
, SynchronizationEvent
, FALSE
);
1439 /* Enter special boot condition */
1440 CmpSpecialBootCondition
= TRUE
;
1442 /* Create the SD for the root hives */
1443 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
1445 /* Loop every hive we care about */
1446 for (i
= 0; i
< CM_NUMBER_OF_MACHINE_HIVES
; i
++)
1448 /* Make sure the list is set up */
1449 ASSERT(CmpMachineHiveList
[i
].Name
!= NULL
);
1451 /* Load the hive as volatile, if in LiveCD mode */
1452 if (CmpShareSystemHives
)
1453 CmpMachineHiveList
[i
].HHiveFlags
|= HIVE_VOLATILE
;
1455 /* Create a thread to handle this hive */
1456 Status
= PsCreateSystemThread(&Thread
,
1463 if (NT_SUCCESS(Status
))
1465 /* We don't care about the handle -- the thread self-terminates */
1470 /* Can't imagine this happening */
1471 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
, 9, 3, i
, Status
);
1475 /* Make sure we've reached the end of the list */
1476 ASSERT(CmpMachineHiveList
[i
].Name
== NULL
);
1478 /* Wait for hive loading to finish */
1479 KeWaitForSingleObject(&CmpLoadWorkerEvent
,
1485 /* Exit the special boot condition and make sure all workers completed */
1486 CmpSpecialBootCondition
= FALSE
;
1487 ASSERT(CmpLoadWorkerIncrement
== CM_NUMBER_OF_MACHINE_HIVES
);
1489 /* Loop hives again */
1490 for (i
= 0; i
< CM_NUMBER_OF_MACHINE_HIVES
; i
++)
1492 /* Make sure the thread ran and finished */
1493 ASSERT(CmpMachineHiveList
[i
].ThreadFinished
== TRUE
);
1494 ASSERT(CmpMachineHiveList
[i
].ThreadStarted
== TRUE
);
1496 /* Check if this was a new hive */
1497 if (!CmpMachineHiveList
[i
].CmHive
)
1499 /* Make sure we allocated something */
1500 ASSERT(CmpMachineHiveList
[i
].CmHive2
!= NULL
);
1502 /* Build the base name */
1503 RegName
.Length
= RegStart
;
1504 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].BaseName
);
1505 RtlAppendUnicodeStringToString(&RegName
, &TempName
);
1507 /* Check if this is a child of the root */
1508 if (RegName
.Buffer
[RegName
.Length
/ sizeof(WCHAR
) - 1] == OBJ_NAME_PATH_SEPARATOR
)
1510 /* Then setup the whole name */
1511 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].Name
);
1512 RtlAppendUnicodeStringToString(&RegName
, &TempName
);
1515 /* Now link the hive to its master */
1516 Status
= CmpLinkHiveToMaster(&RegName
,
1518 CmpMachineHiveList
[i
].CmHive2
,
1519 CmpMachineHiveList
[i
].Allocate
,
1520 SecurityDescriptor
);
1521 if (Status
!= STATUS_SUCCESS
)
1523 /* Linking needs to work */
1524 KeBugCheckEx(CONFIG_LIST_FAILED
, 11, Status
, i
, (ULONG_PTR
)&RegName
);
1527 /* Check if we had to allocate a new hive */
1528 if (CmpMachineHiveList
[i
].Allocate
)
1530 /* Sync the new hive */
1531 //HvSyncHive((PHHIVE)(CmpMachineHiveList[i].CmHive2));
1535 /* Check if we created a new hive */
1536 if (CmpMachineHiveList
[i
].CmHive2
)
1538 /* Add to HiveList key */
1539 CmpAddToHiveFileList(CmpMachineHiveList
[i
].CmHive2
);
1543 /* Get rid of the SD */
1544 ExFreePoolWithTag(SecurityDescriptor
, TAG_CMSD
);
1546 /* Link SECURITY to SAM */
1547 CmpLinkKeyToHive(L
"\\Registry\\Machine\\Security\\SAM",
1548 L
"\\Registry\\Machine\\SAM\\SAM");
1550 /* Link S-1-5-18 to .Default */
1551 CmpNoVolatileCreates
= FALSE
;
1552 CmpLinkKeyToHive(L
"\\Registry\\User\\S-1-5-18",
1553 L
"\\Registry\\User\\.Default");
1554 CmpNoVolatileCreates
= TRUE
;
1562 OBJECT_ATTRIBUTES ObjectAttributes
;
1563 UNICODE_STRING KeyName
;
1566 PCMHIVE HardwareHive
;
1567 PSECURITY_DESCRIPTOR SecurityDescriptor
;
1570 /* Check if this is PE-boot */
1571 if (InitIsWinPEMode
)
1573 /* Set registry to PE mode */
1574 CmpMiniNTBoot
= TRUE
;
1575 CmpShareSystemHives
= TRUE
;
1578 /* Initialize the hive list and lock */
1579 InitializeListHead(&CmpHiveListHead
);
1580 ExInitializePushLock(&CmpHiveListHeadLock
);
1581 ExInitializePushLock(&CmpLoadHiveLock
);
1583 /* Initialize registry lock */
1584 ExInitializeResourceLite(&CmpRegistryLock
);
1586 /* Initialize the cache */
1587 CmpInitializeCache();
1589 /* Initialize allocation and delayed dereferencing */
1590 CmpInitCmPrivateAlloc();
1591 CmpInitCmPrivateDelayAlloc();
1592 CmpInitDelayDerefKCBEngine();
1594 /* Initialize callbacks */
1597 /* Initialize self healing */
1598 KeInitializeGuardedMutex(&CmpSelfHealQueueLock
);
1599 InitializeListHead(&CmpSelfHealQueueListHead
);
1601 /* Save the current process and lock the registry */
1602 CmpSystemProcess
= PsGetCurrentProcess();
1604 /* Create the key object types */
1605 Status
= CmpCreateObjectTypes();
1606 if (!NT_SUCCESS(Status
))
1609 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 1, Status
, 0);
1612 /* Build the master hive */
1613 Status
= CmpInitializeHive(&CmiVolatileHive
,
1623 if (!NT_SUCCESS(Status
))
1626 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 2, Status
, 0);
1629 /* Create the \REGISTRY key node */
1630 if (!CmpCreateRegistryRoot())
1633 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 3, 0, 0);
1636 /* Create the default security descriptor */
1637 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
1639 /* Create '\Registry\Machine' key */
1640 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY\\MACHINE");
1641 InitializeObjectAttributes(&ObjectAttributes
,
1643 OBJ_CASE_INSENSITIVE
,
1645 SecurityDescriptor
);
1646 Status
= NtCreateKey(&KeyHandle
,
1647 KEY_READ
| KEY_WRITE
,
1653 if (!NT_SUCCESS(Status
))
1656 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 5, Status
, 0);
1659 /* Close the handle */
1662 /* Create '\Registry\User' key */
1663 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY\\USER");
1664 InitializeObjectAttributes(&ObjectAttributes
,
1666 OBJ_CASE_INSENSITIVE
,
1668 SecurityDescriptor
);
1669 Status
= NtCreateKey(&KeyHandle
,
1670 KEY_READ
| KEY_WRITE
,
1676 if (!NT_SUCCESS(Status
))
1679 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 6, Status
, 0);
1682 /* Close the handle */
1685 /* After this point, do not allow creating keys in the master hive */
1686 CmpNoVolatileCreates
= TRUE
;
1688 /* Initialize the system hive */
1689 if (!CmpInitializeSystemHive(KeLoaderBlock
))
1692 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 7, 0, 0);
1695 /* Create the 'CurrentControlSet' link */
1696 Status
= CmpCreateControlSet(KeLoaderBlock
);
1697 if (!NT_SUCCESS(Status
))
1700 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 8, Status
, 0);
1703 /* Create the hardware hive */
1704 Status
= CmpInitializeHive(&HardwareHive
,
1714 if (!NT_SUCCESS(Status
))
1717 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 11, Status
, 0);
1720 /* Add the hive to the hive list */
1721 CmpMachineHiveList
[0].CmHive
= HardwareHive
;
1723 /* Attach it to the machine key */
1724 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\HARDWARE");
1725 Status
= CmpLinkHiveToMaster(&KeyName
,
1729 SecurityDescriptor
);
1730 if (!NT_SUCCESS(Status
))
1733 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 12, Status
, 0);
1736 /* Add to HiveList key */
1737 CmpAddToHiveFileList(HardwareHive
);
1739 /* Free the security descriptor */
1740 ExFreePoolWithTag(SecurityDescriptor
, TAG_CMSD
);
1742 /* Fill out the Hardware key with the ARC Data from the Loader */
1743 Status
= CmpInitializeHardwareConfiguration(KeLoaderBlock
);
1744 if (!NT_SUCCESS(Status
))
1747 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 13, Status
, 0);
1750 /* Initialize machine-dependent information into the registry */
1751 Status
= CmpInitializeMachineDependentConfiguration(KeLoaderBlock
);
1752 if (!NT_SUCCESS(Status
))
1755 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 14, Status
, 0);
1758 /* Initialize volatile registry settings */
1759 Status
= CmpSetSystemValues(KeLoaderBlock
);
1760 if (!NT_SUCCESS(Status
))
1763 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 15, Status
, 0);
1766 /* Free the load options */
1767 ExFreePoolWithTag(CmpLoadOptions
.Buffer
, TAG_CM
);
1769 /* If we got here, all went well */
1776 CmpFreeDriverList(IN PHHIVE Hive
,
1777 IN PLIST_ENTRY DriverList
)
1779 PLIST_ENTRY NextEntry
, OldEntry
;
1780 PBOOT_DRIVER_NODE DriverNode
;
1783 /* Parse the current list */
1784 NextEntry
= DriverList
->Flink
;
1785 while (NextEntry
!= DriverList
)
1787 /* Get the driver node */
1788 DriverNode
= CONTAINING_RECORD(NextEntry
, BOOT_DRIVER_NODE
, ListEntry
.Link
);
1790 /* Get the next entry now, since we're going to free it later */
1791 OldEntry
= NextEntry
;
1792 NextEntry
= NextEntry
->Flink
;
1794 /* Was there a name? */
1795 if (DriverNode
->Name
.Buffer
)
1798 CmpFree(DriverNode
->Name
.Buffer
, DriverNode
->Name
.Length
);
1801 /* Was there a registry path? */
1802 if (DriverNode
->ListEntry
.RegistryPath
.Buffer
)
1805 CmpFree(DriverNode
->ListEntry
.RegistryPath
.Buffer
,
1806 DriverNode
->ListEntry
.RegistryPath
.MaximumLength
);
1809 /* Was there a file path? */
1810 if (DriverNode
->ListEntry
.FilePath
.Buffer
)
1813 CmpFree(DriverNode
->ListEntry
.FilePath
.Buffer
,
1814 DriverNode
->ListEntry
.FilePath
.MaximumLength
);
1817 /* Now free the node, and move on */
1818 CmpFree(OldEntry
, sizeof(BOOT_DRIVER_NODE
));
1825 CmGetSystemDriverList(VOID
)
1827 LIST_ENTRY DriverList
;
1828 OBJECT_ATTRIBUTES ObjectAttributes
;
1830 PCM_KEY_BODY KeyBody
;
1832 HCELL_INDEX RootCell
, ControlCell
;
1834 UNICODE_STRING KeyName
;
1835 PLIST_ENTRY NextEntry
;
1837 PUNICODE_STRING
* ServicePath
= NULL
;
1838 BOOLEAN Success
, AutoSelect
;
1839 PBOOT_DRIVER_LIST_ENTRY DriverEntry
;
1842 /* Initialize the driver list */
1843 InitializeListHead(&DriverList
);
1845 /* Open the system hive key */
1846 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\System");
1847 InitializeObjectAttributes(&ObjectAttributes
,
1849 OBJ_CASE_INSENSITIVE
,
1852 Status
= NtOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
1853 if (!NT_SUCCESS(Status
)) return NULL
;
1855 /* Reference the key object to get the root hive/cell to access directly */
1856 Status
= ObReferenceObjectByHandle(KeyHandle
,
1862 if (!NT_SUCCESS(Status
))
1869 /* Do all this under the registry lock */
1870 CmpLockRegistryExclusive();
1872 /* Get the hive and key cell */
1873 Hive
= KeyBody
->KeyControlBlock
->KeyHive
;
1874 RootCell
= KeyBody
->KeyControlBlock
->KeyCell
;
1876 /* Open the current control set key */
1877 RtlInitUnicodeString(&KeyName
, L
"Current");
1878 ControlCell
= CmpFindControlSet(Hive
, RootCell
, &KeyName
, &AutoSelect
);
1879 if (ControlCell
== HCELL_NIL
) goto EndPath
;
1881 /* Find all system drivers */
1882 Success
= CmpFindDrivers(Hive
, ControlCell
, SystemLoad
, NULL
, &DriverList
);
1883 if (!Success
) goto EndPath
;
1885 /* Sort by group/tag */
1886 if (!CmpSortDriverList(Hive
, ControlCell
, &DriverList
)) goto EndPath
;
1888 /* Remove circular dependencies (cycles) and sort */
1889 if (!CmpResolveDriverDependencies(&DriverList
)) goto EndPath
;
1891 /* Loop the list to count drivers */
1892 for (i
= 0, NextEntry
= DriverList
.Flink
;
1893 NextEntry
!= &DriverList
;
1894 i
++, NextEntry
= NextEntry
->Flink
);
1896 /* Allocate the array */
1897 ServicePath
= ExAllocatePool(NonPagedPool
, (i
+ 1) * sizeof(PUNICODE_STRING
));
1898 if (!ServicePath
) KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 2, 1, 0, 0);
1900 /* Loop the driver list */
1901 for (i
= 0, NextEntry
= DriverList
.Flink
;
1902 NextEntry
!= &DriverList
;
1903 i
++, NextEntry
= NextEntry
->Flink
)
1906 DriverEntry
= CONTAINING_RECORD(NextEntry
, BOOT_DRIVER_LIST_ENTRY
, Link
);
1908 /* Allocate the path for the caller */
1909 ServicePath
[i
] = ExAllocatePool(NonPagedPool
, sizeof(UNICODE_STRING
));
1910 if (!ServicePath
[i
])
1912 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 2, 1, 0, 0);
1915 /* Duplicate the registry path */
1916 Status
= RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
,
1917 &DriverEntry
->RegistryPath
,
1919 if (!NT_SUCCESS(Status
))
1921 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 2, 1, 0, 0);
1925 /* Terminate the list */
1926 ServicePath
[i
] = NULL
;
1929 /* Free the driver list if we had one */
1930 if (!IsListEmpty(&DriverList
)) CmpFreeDriverList(Hive
, &DriverList
);
1932 /* Unlock the registry */
1933 CmpUnlockRegistry();
1935 /* Close the key handle and dereference the object, then return the path */
1936 ObDereferenceObject(KeyBody
);
1943 CmpLockRegistryExclusive(VOID
)
1945 /* Enter a critical region and lock the registry */
1946 KeEnterCriticalRegion();
1947 ExAcquireResourceExclusiveLite(&CmpRegistryLock
, TRUE
);
1950 ASSERT(CmpFlushStarveWriters
== 0);
1951 RtlGetCallersAddress(&CmpRegistryLockCaller
, &CmpRegistryLockCallerCaller
);
1956 CmpLockRegistry(VOID
)
1958 /* Enter a critical region */
1959 KeEnterCriticalRegion();
1961 /* Check if we have to starve writers */
1962 if (CmpFlushStarveWriters
)
1964 /* Starve exlusive waiters */
1965 ExAcquireSharedStarveExclusive(&CmpRegistryLock
, TRUE
);
1969 /* Just grab the lock */
1970 ExAcquireResourceSharedLite(&CmpRegistryLock
, TRUE
);
1976 CmpTestRegistryLock(VOID
)
1979 return !ExIsResourceAcquiredSharedLite(&CmpRegistryLock
) ? FALSE
: TRUE
;
1984 CmpTestRegistryLockExclusive(VOID
)
1987 return !ExIsResourceAcquiredExclusiveLite(&CmpRegistryLock
) ? FALSE
: TRUE
;
1992 CmpLockHiveFlusherExclusive(IN PCMHIVE Hive
)
1994 /* Lock the flusher. We should already be in a critical section */
1995 CMP_ASSERT_REGISTRY_LOCK_OR_LOADING(Hive
);
1996 ASSERT((ExIsResourceAcquiredShared(Hive
->FlusherLock
) == 0) &&
1997 (ExIsResourceAcquiredExclusiveLite(Hive
->FlusherLock
) == 0));
1998 ExAcquireResourceExclusiveLite(Hive
->FlusherLock
, TRUE
);
2003 CmpLockHiveFlusherShared(IN PCMHIVE Hive
)
2005 /* Lock the flusher. We should already be in a critical section */
2006 CMP_ASSERT_REGISTRY_LOCK_OR_LOADING(Hive
);
2007 ASSERT((ExIsResourceAcquiredShared(Hive
->FlusherLock
) == 0) &&
2008 (ExIsResourceAcquiredExclusiveLite(Hive
->FlusherLock
) == 0));
2009 ExAcquireResourceSharedLite(Hive
->FlusherLock
, TRUE
);
2014 CmpUnlockHiveFlusher(IN PCMHIVE Hive
)
2017 CMP_ASSERT_REGISTRY_LOCK_OR_LOADING(Hive
);
2018 CMP_ASSERT_FLUSH_LOCK(Hive
);
2020 /* Release the lock */
2021 ExReleaseResourceLite(Hive
->FlusherLock
);
2026 CmpTestHiveFlusherLockShared(IN PCMHIVE Hive
)
2029 return !ExIsResourceAcquiredSharedLite(Hive
->FlusherLock
) ? FALSE
: TRUE
;
2034 CmpTestHiveFlusherLockExclusive(IN PCMHIVE Hive
)
2037 return !ExIsResourceAcquiredExclusiveLite(Hive
->FlusherLock
) ? FALSE
: TRUE
;
2042 CmpUnlockRegistry(VOID
)
2045 CMP_ASSERT_REGISTRY_LOCK();
2047 /* Check if we should flush the registry */
2048 if (CmpFlushOnLockRelease
)
2050 /* The registry should be exclusively locked for this */
2051 CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK();
2053 /* Flush the registry */
2054 CmpDoFlushAll(TRUE
);
2055 CmpFlushOnLockRelease
= FALSE
;
2059 /* Lazy flush the registry */
2063 /* Release the lock and leave the critical region */
2064 ExReleaseResourceLite(&CmpRegistryLock
);
2065 KeLeaveCriticalRegion();
2070 CmpAcquireTwoKcbLocksExclusiveByKey(IN ULONG ConvKey1
,
2073 ULONG Index1
, Index2
;
2076 CMP_ASSERT_REGISTRY_LOCK();
2078 /* Get hash indexes */
2079 Index1
= GET_HASH_INDEX(ConvKey1
);
2080 Index2
= GET_HASH_INDEX(ConvKey2
);
2082 /* See which one is highest */
2083 if (Index1
< Index2
)
2085 /* Grab them in the proper order */
2086 CmpAcquireKcbLockExclusiveByKey(ConvKey1
);
2087 CmpAcquireKcbLockExclusiveByKey(ConvKey2
);
2091 /* Grab the second one first, then the first */
2092 CmpAcquireKcbLockExclusiveByKey(ConvKey2
);
2093 if (Index1
!= Index2
) CmpAcquireKcbLockExclusiveByKey(ConvKey1
);
2099 CmpReleaseTwoKcbLockByKey(IN ULONG ConvKey1
,
2102 ULONG Index1
, Index2
;
2105 CMP_ASSERT_REGISTRY_LOCK();
2107 /* Get hash indexes */
2108 Index1
= GET_HASH_INDEX(ConvKey1
);
2109 Index2
= GET_HASH_INDEX(ConvKey2
);
2110 ASSERT((GET_HASH_ENTRY(CmpCacheTable
, ConvKey2
)->Owner
== KeGetCurrentThread()) ||
2111 (CmpTestRegistryLockExclusive()));
2113 /* See which one is highest */
2114 if (Index1
< Index2
)
2116 /* Grab them in the proper order */
2117 ASSERT((GET_HASH_ENTRY(CmpCacheTable
, ConvKey1
)->Owner
== KeGetCurrentThread()) ||
2118 (CmpTestRegistryLockExclusive()));
2119 CmpReleaseKcbLockByKey(ConvKey2
);
2120 CmpReleaseKcbLockByKey(ConvKey1
);
2124 /* Release the first one first, then the second */
2125 if (Index1
!= Index2
)
2127 ASSERT((GET_HASH_ENTRY(CmpCacheTable
, ConvKey1
)->Owner
== KeGetCurrentThread()) ||
2128 (CmpTestRegistryLockExclusive()));
2129 CmpReleaseKcbLockByKey(ConvKey1
);
2131 CmpReleaseKcbLockByKey(ConvKey2
);
2137 CmShutdownSystem(VOID
)
2139 PLIST_ENTRY ListEntry
;
2142 /* Kill the workers */
2143 if (!CmFirstTime
) CmpShutdownWorkers();
2145 /* Flush all hives */
2146 CmpLockRegistryExclusive();
2147 CmpDoFlushAll(TRUE
);
2149 /* Close all hive files */
2150 ListEntry
= CmpHiveListHead
.Flink
;
2151 while (ListEntry
!= &CmpHiveListHead
)
2153 Hive
= CONTAINING_RECORD(ListEntry
, CMHIVE
, HiveList
);
2155 CmpCloseHiveFiles(Hive
);
2157 ListEntry
= ListEntry
->Flink
;
2160 CmpUnlockRegistry();
2165 CmpSetVersionData(VOID
)
2168 OBJECT_ATTRIBUTES ObjectAttributes
;
2169 UNICODE_STRING KeyName
;
2170 UNICODE_STRING ValueName
;
2171 UNICODE_STRING ValueData
;
2172 ANSI_STRING TempString
;
2173 HANDLE SoftwareKeyHandle
= NULL
;
2174 HANDLE MicrosoftKeyHandle
= NULL
;
2175 HANDLE WindowsNtKeyHandle
= NULL
;
2176 HANDLE CurrentVersionKeyHandle
= NULL
;
2177 WCHAR Buffer
[128]; // Buffer large enough to contain a full ULONG in decimal
2178 // representation, and the full 'CurrentType' string.
2181 * Open the 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' key
2182 * (create the intermediate subkeys if needed).
2185 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY\\MACHINE\\SOFTWARE");
2186 InitializeObjectAttributes(&ObjectAttributes
,
2188 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2191 Status
= NtCreateKey(&SoftwareKeyHandle
,
2198 if (!NT_SUCCESS(Status
))
2200 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName
, Status
);
2204 RtlInitUnicodeString(&KeyName
, L
"Microsoft");
2205 InitializeObjectAttributes(&ObjectAttributes
,
2207 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2210 Status
= NtCreateKey(&MicrosoftKeyHandle
,
2217 if (!NT_SUCCESS(Status
))
2219 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName
, Status
);
2223 RtlInitUnicodeString(&KeyName
, L
"Windows NT");
2224 InitializeObjectAttributes(&ObjectAttributes
,
2226 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2229 Status
= NtCreateKey(&WindowsNtKeyHandle
,
2236 if (!NT_SUCCESS(Status
))
2238 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName
, Status
);
2242 RtlInitUnicodeString(&KeyName
, L
"CurrentVersion");
2243 InitializeObjectAttributes(&ObjectAttributes
,
2245 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
2248 Status
= NtCreateKey(&CurrentVersionKeyHandle
,
2249 KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
,
2255 if (!NT_SUCCESS(Status
))
2257 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName
, Status
);
2261 /* Set the 'CurrentVersion' value */
2262 RtlInitUnicodeString(&ValueName
, L
"CurrentVersion");
2263 NtSetValueKey(CurrentVersionKeyHandle
,
2267 CmVersionString
.Buffer
,
2268 CmVersionString
.Length
+ sizeof(WCHAR
));
2270 /* Set the 'CurrentBuildNumber' value */
2271 RtlInitUnicodeString(&ValueName
, L
"CurrentBuildNumber");
2272 RtlInitEmptyUnicodeString(&ValueData
, Buffer
, sizeof(Buffer
));
2273 RtlIntegerToUnicodeString(NtBuildNumber
& 0xFFFF, 10, &ValueData
);
2274 NtSetValueKey(CurrentVersionKeyHandle
,
2279 ValueData
.Length
+ sizeof(WCHAR
));
2281 /* Set the 'BuildLab' value */
2282 RtlInitUnicodeString(&ValueName
, L
"BuildLab");
2283 RtlInitAnsiString(&TempString
, NtBuildLab
);
2284 Status
= RtlAnsiStringToUnicodeString(&ValueData
, &TempString
, FALSE
);
2285 if (NT_SUCCESS(Status
))
2287 NtSetValueKey(CurrentVersionKeyHandle
,
2292 ValueData
.Length
+ sizeof(WCHAR
));
2295 /* Set the 'CurrentType' value */
2296 RtlInitUnicodeString(&ValueName
, L
"CurrentType");
2297 RtlStringCbPrintfW(Buffer
, sizeof(Buffer
),
2311 RtlInitUnicodeString(&ValueData
, Buffer
);
2312 NtSetValueKey(CurrentVersionKeyHandle
,
2317 ValueData
.Length
+ sizeof(WCHAR
));
2319 /* Set the 'CSDVersion' value */
2320 RtlInitUnicodeString(&ValueName
, L
"CSDVersion");
2321 if (CmCSDVersionString
.Length
!= 0)
2323 NtSetValueKey(CurrentVersionKeyHandle
,
2327 CmCSDVersionString
.Buffer
,
2328 CmCSDVersionString
.Length
+ sizeof(WCHAR
));
2332 NtDeleteValueKey(CurrentVersionKeyHandle
, &ValueName
);
2335 /* Set the 'CSDBuildNumber' value */
2336 RtlInitUnicodeString(&ValueName
, L
"CSDBuildNumber");
2337 if (CmNtSpBuildNumber
!= 0)
2339 RtlInitEmptyUnicodeString(&ValueData
, Buffer
, sizeof(Buffer
));
2340 RtlIntegerToUnicodeString(CmNtSpBuildNumber
, 10, &ValueData
);
2341 NtSetValueKey(CurrentVersionKeyHandle
,
2346 ValueData
.Length
+ sizeof(WCHAR
));
2350 NtDeleteValueKey(CurrentVersionKeyHandle
, &ValueName
);
2353 /* Set the 'SystemRoot' value */
2354 RtlInitUnicodeString(&ValueName
, L
"SystemRoot");
2355 NtSetValueKey(CurrentVersionKeyHandle
,
2359 NtSystemRoot
.Buffer
,
2360 NtSystemRoot
.Length
+ sizeof(WCHAR
));
2363 /* Close the keys */
2364 if (CurrentVersionKeyHandle
!= NULL
)
2365 NtClose(CurrentVersionKeyHandle
);
2367 if (WindowsNtKeyHandle
!= NULL
)
2368 NtClose(WindowsNtKeyHandle
);
2370 if (MicrosoftKeyHandle
!= NULL
)
2371 NtClose(MicrosoftKeyHandle
);
2373 if (SoftwareKeyHandle
!= NULL
)
2374 NtClose(SoftwareKeyHandle
);