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_ PWSTR LinkKeyName
,
44 _In_z_ PWSTR TargetKeyName
)
46 OBJECT_ATTRIBUTES ObjectAttributes
;
47 UNICODE_STRING LinkKeyName_U
;
48 HANDLE TargetKeyHandle
;
53 /* Initialize the object attributes */
54 RtlInitUnicodeString(&LinkKeyName_U
, LinkKeyName
);
55 InitializeObjectAttributes(&ObjectAttributes
,
57 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
61 /* Create the link key */
62 Status
= ZwCreateKey(&TargetKeyHandle
,
67 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
69 if (!NT_SUCCESS(Status
))
71 DPRINT1("CM: CmpLinkKeyToHive: couldn't create %S Status = 0x%lx\n",
76 /* Check if the new key was actually created */
77 if (Disposition
!= REG_CREATED_NEW_KEY
)
79 DPRINT1("CM: CmpLinkKeyToHive: %S already exists!\n", LinkKeyName
);
80 ZwClose(TargetKeyHandle
);
84 /* Set the target key name as link target */
85 Status
= ZwSetValueKey(TargetKeyHandle
,
86 &CmSymbolicLinkValueName
,
90 (ULONG
)wcslen(TargetKeyName
) * sizeof(WCHAR
));
92 /* Close the link key handle */
93 ObCloseHandle(TargetKeyHandle
, KernelMode
);
95 if (!NT_SUCCESS(Status
))
97 DPRINT1("CM: CmpLinkKeyToHive: couldn't create symbolic link for %S\n",
107 CmpDeleteKeyObject(PVOID DeletedObject
)
109 PCM_KEY_BODY KeyBody
= (PCM_KEY_BODY
)DeletedObject
;
110 PCM_KEY_CONTROL_BLOCK Kcb
;
111 REG_KEY_HANDLE_CLOSE_INFORMATION KeyHandleCloseInfo
;
112 REG_POST_OPERATION_INFORMATION PostOperationInfo
;
116 /* First off, prepare the handle close information callback */
117 PostOperationInfo
.Object
= KeyBody
;
118 KeyHandleCloseInfo
.Object
= KeyBody
;
119 Status
= CmiCallRegisteredCallbacks(RegNtPreKeyHandleClose
,
120 &KeyHandleCloseInfo
);
121 if (!NT_SUCCESS(Status
))
123 /* If we failed, notify the post routine */
124 PostOperationInfo
.Status
= Status
;
125 CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose
, &PostOperationInfo
);
129 /* Acquire hive lock */
132 /* Make sure this is a valid key body */
133 if (KeyBody
->Type
== CM_KEY_BODY_TYPE
)
136 Kcb
= KeyBody
->KeyControlBlock
;
140 DelistKeyBodyFromKCB(KeyBody
, FALSE
);
142 /* Dereference the KCB */
143 CmpDelayDerefKeyControlBlock(Kcb
);
147 /* Release the registry lock */
150 /* Do the post callback */
151 PostOperationInfo
.Status
= STATUS_SUCCESS
;
152 CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose
, &PostOperationInfo
);
157 CmpCloseKeyObject(IN PEPROCESS Process OPTIONAL
,
159 IN ACCESS_MASK GrantedAccess
,
160 IN ULONG ProcessHandleCount
,
161 IN ULONG SystemHandleCount
)
163 PCM_KEY_BODY KeyBody
= (PCM_KEY_BODY
)Object
;
166 /* Don't do anything if we're not the last handle */
167 if (SystemHandleCount
> 1) return;
169 /* Make sure we're a valid key body */
170 if (KeyBody
->Type
== CM_KEY_BODY_TYPE
)
172 /* Don't do anything if we don't have a notify block */
173 if (!KeyBody
->NotifyBlock
) return;
175 /* This shouldn't happen yet */
182 CmpQueryKeyName(IN PVOID ObjectBody
,
184 IN OUT POBJECT_NAME_INFORMATION ObjectNameInfo
,
186 OUT PULONG ReturnLength
,
187 IN KPROCESSOR_MODE PreviousMode
)
189 PUNICODE_STRING KeyName
;
191 NTSTATUS Status
= STATUS_SUCCESS
;
192 PCM_KEY_BODY KeyBody
= (PCM_KEY_BODY
)ObjectBody
;
193 PCM_KEY_CONTROL_BLOCK Kcb
= KeyBody
->KeyControlBlock
;
195 /* Acquire hive lock */
198 /* Lock KCB shared */
199 CmpAcquireKcbLockShared(Kcb
);
201 /* Check if it's a deleted block */
204 /* Release the locks */
205 CmpReleaseKcbLock(Kcb
);
208 /* Let the caller know it's deleted */
209 return STATUS_KEY_DELETED
;
213 KeyName
= CmpConstructName(Kcb
);
215 /* Release the locks */
216 CmpReleaseKcbLock(Kcb
);
219 /* Check if we got the name */
220 if (!KeyName
) return STATUS_INSUFFICIENT_RESOURCES
;
222 /* Set the returned length */
223 *ReturnLength
= KeyName
->Length
+ sizeof(OBJECT_NAME_INFORMATION
) + sizeof(WCHAR
);
225 /* Calculate amount of bytes to copy into the buffer */
226 BytesToCopy
= KeyName
->Length
+ sizeof(WCHAR
);
228 /* Check if the provided buffer is too small to fit even anything */
229 if ((Length
<= sizeof(OBJECT_NAME_INFORMATION
)) ||
230 ((Length
< (*ReturnLength
)) && (BytesToCopy
< sizeof(WCHAR
))))
232 /* Free the buffer allocated by CmpConstructName */
233 ExFreePoolWithTag(KeyName
, TAG_CM
);
235 /* Return buffer length failure without writing anything there because nothing fits */
236 return STATUS_INFO_LENGTH_MISMATCH
;
239 /* Check if the provided buffer can be partially written */
240 if (Length
< (*ReturnLength
))
242 /* Yes, indicate so in the return status */
243 Status
= STATUS_INFO_LENGTH_MISMATCH
;
245 /* Calculate amount of bytes which the provided buffer could handle */
246 BytesToCopy
= Length
- sizeof(OBJECT_NAME_INFORMATION
);
249 /* Remove the null termination character from the size */
250 BytesToCopy
-= sizeof(WCHAR
);
252 /* Fill in the result */
255 /* Return data to user */
256 ObjectNameInfo
->Name
.Buffer
= (PWCHAR
)(ObjectNameInfo
+ 1);
257 ObjectNameInfo
->Name
.MaximumLength
= KeyName
->Length
;
258 ObjectNameInfo
->Name
.Length
= KeyName
->Length
;
260 /* Copy string content*/
261 RtlCopyMemory(ObjectNameInfo
->Name
.Buffer
,
265 /* Null terminate it */
266 ObjectNameInfo
->Name
.Buffer
[BytesToCopy
/ sizeof(WCHAR
)] = 0;
268 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
271 Status
= _SEH2_GetExceptionCode();
275 /* Free the buffer allocated by CmpConstructName */
276 ExFreePoolWithTag(KeyName
, TAG_CM
);
284 CmpInitHiveFromFile(IN PCUNICODE_STRING HiveName
,
290 ULONG HiveDisposition
, LogDisposition
;
291 HANDLE FileHandle
= NULL
, LogHandle
= NULL
;
293 ULONG Operation
, FileType
;
300 /* Open or create the hive files */
301 Status
= CmpOpenHiveFiles(HiveName
,
311 if (!NT_SUCCESS(Status
)) return Status
;
313 /* Check if we have a log handle */
314 FileType
= (LogHandle
) ? HFILE_TYPE_LOG
: HFILE_TYPE_PRIMARY
;
316 /* Check if we created or opened the hive */
317 if (HiveDisposition
== FILE_CREATED
)
319 /* Do a create operation */
320 Operation
= HINIT_CREATE
;
325 /* Open it as a file */
326 Operation
= HINIT_FILE
;
330 /* Check if we're sharing hives */
331 if (CmpShareSystemHives
)
333 /* Then force using the primary hive */
334 FileType
= HFILE_TYPE_PRIMARY
;
337 /* Get rid of the log handle */
343 /* Check if we're too late */
344 if (HvShutdownComplete
)
348 if (LogHandle
) ZwClose(LogHandle
);
349 return STATUS_TOO_LATE
;
352 /* Initialize the hive */
353 Status
= CmpInitializeHive((PCMHIVE
*)&NewHive
,
363 if (!NT_SUCCESS(Status
))
367 if (LogHandle
) ZwClose(LogHandle
);
371 /* Success, return hive */
374 /* HACK: ROS: Init root key cell and prepare the hive */
375 if (Operation
== HINIT_CREATE
) CmCreateRootNode(&NewHive
->Hive
, L
"");
377 /* Duplicate the hive name */
378 NewHive
->FileFullPath
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
381 if (NewHive
->FileFullPath
.Buffer
)
383 /* Copy the string */
384 RtlCopyMemory(NewHive
->FileFullPath
.Buffer
,
387 NewHive
->FileFullPath
.Length
= HiveName
->Length
;
388 NewHive
->FileFullPath
.MaximumLength
= HiveName
->MaximumLength
;
392 return STATUS_SUCCESS
;
398 CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
400 OBJECT_ATTRIBUTES ObjectAttributes
;
401 UNICODE_STRING KeyName
, ValueName
= { 0, 0, NULL
};
402 HANDLE KeyHandle
= NULL
;
404 ASSERT(LoaderBlock
!= NULL
);
406 /* Setup attributes for loader options */
407 RtlInitUnicodeString(&KeyName
,
408 L
"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\"
410 InitializeObjectAttributes(&ObjectAttributes
,
412 OBJ_CASE_INSENSITIVE
,
415 Status
= NtOpenKey(&KeyHandle
, KEY_WRITE
, &ObjectAttributes
);
416 if (!NT_SUCCESS(Status
)) goto Quickie
;
418 /* Key opened, now write to the key */
419 RtlInitUnicodeString(&KeyName
, L
"SystemStartOptions");
420 Status
= NtSetValueKey(KeyHandle
,
424 CmpLoadOptions
.Buffer
,
425 CmpLoadOptions
.Length
);
426 if (!NT_SUCCESS(Status
)) goto Quickie
;
428 /* Setup value name for system boot device in ARC format */
429 RtlInitUnicodeString(&KeyName
, L
"SystemBootDevice");
430 RtlCreateUnicodeStringFromAsciiz(&ValueName
, LoaderBlock
->ArcBootDeviceName
);
431 Status
= NtSetValueKey(KeyHandle
,
439 /* Free the buffers */
440 RtlFreeUnicodeString(&ValueName
);
442 /* Close the key and return */
443 if (KeyHandle
) NtClose(KeyHandle
);
445 /* Return the status */
446 return (ExpInTextModeSetup
? STATUS_SUCCESS
: Status
);
452 CmpCreateHardwareProfile(HANDLE ControlSetHandle
)
454 OBJECT_ATTRIBUTES ObjectAttributes
;
455 UNICODE_STRING KeyName
;
456 HANDLE ProfilesHandle
= NULL
;
457 HANDLE ProfileHandle
= NULL
;
461 DPRINT("CmpCreateHardwareProfile()\n");
463 /* Create the Hardware Profiles key */
464 RtlInitUnicodeString(&KeyName
, L
"Hardware Profiles");
465 InitializeObjectAttributes(&ObjectAttributes
,
467 OBJ_CASE_INSENSITIVE
,
470 Status
= NtCreateKey(&ProfilesHandle
,
477 if (!NT_SUCCESS(Status
))
479 DPRINT1("Creating the Hardware Profile key failed\n");
484 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
486 /* Create the 0000 key */
487 RtlInitUnicodeString(&KeyName
, L
"0000");
488 InitializeObjectAttributes(&ObjectAttributes
,
490 OBJ_CASE_INSENSITIVE
,
493 Status
= NtCreateKey(&ProfileHandle
,
500 if (!NT_SUCCESS(Status
))
502 DPRINT1("Creating the Hardware Profile\\0000 key failed\n");
507 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
511 NtClose(ProfilesHandle
);
514 NtClose(ProfileHandle
);
516 DPRINT1("CmpCreateHardwareProfile() done\n");
524 CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
526 UNICODE_STRING ConfigName
= RTL_CONSTANT_STRING(L
"Control\\IDConfigDB");
527 UNICODE_STRING SelectName
=
528 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\System\\Select");
529 UNICODE_STRING KeyName
;
530 OBJECT_ATTRIBUTES ObjectAttributes
;
531 CHAR ValueInfoBuffer
[128];
532 PKEY_VALUE_FULL_INFORMATION ValueInfo
;
534 WCHAR UnicodeBuffer
[128];
535 HANDLE SelectHandle
, KeyHandle
, ConfigHandle
= NULL
, ProfileHandle
= NULL
;
536 HANDLE ParentHandle
= NULL
;
537 ULONG ControlSet
, HwProfile
;
538 ANSI_STRING TempString
;
540 ULONG ResultLength
, Disposition
;
541 PLOADER_PARAMETER_EXTENSION LoaderExtension
;
544 /* Open the select key */
545 InitializeObjectAttributes(&ObjectAttributes
,
547 OBJ_CASE_INSENSITIVE
,
550 Status
= NtOpenKey(&SelectHandle
, KEY_READ
, &ObjectAttributes
);
551 if (!NT_SUCCESS(Status
))
553 /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
554 if (!LoaderBlock
->RegistryBase
)
556 /* Build the ControlSet001 key */
557 RtlInitUnicodeString(&KeyName
,
558 L
"\\Registry\\Machine\\System\\ControlSet001");
559 InitializeObjectAttributes(&ObjectAttributes
,
561 OBJ_CASE_INSENSITIVE
,
564 Status
= NtCreateKey(&KeyHandle
,
571 if (!NT_SUCCESS(Status
)) return Status
;
573 /* Create the Hardware Profile keys */
574 Status
= CmpCreateHardwareProfile(KeyHandle
);
575 if (!NT_SUCCESS(Status
))
578 /* Don't need the handle */
581 /* Use hard-coded setting */
586 /* Fail for real boots */
590 /* Open the current value */
591 RtlInitUnicodeString(&KeyName
, L
"Current");
592 Status
= NtQueryValueKey(SelectHandle
,
594 KeyValueFullInformation
,
596 sizeof(ValueInfoBuffer
),
598 NtClose(SelectHandle
);
599 if (!NT_SUCCESS(Status
)) return Status
;
601 /* Get the actual value pointer, and get the control set ID */
602 ValueInfo
= (PKEY_VALUE_FULL_INFORMATION
)ValueInfoBuffer
;
603 ControlSet
= *(PULONG
)((PUCHAR
)ValueInfo
+ ValueInfo
->DataOffset
);
605 /* Create the current control set key */
607 RtlInitUnicodeString(&KeyName
,
608 L
"\\Registry\\Machine\\System\\CurrentControlSet");
609 InitializeObjectAttributes(&ObjectAttributes
,
611 OBJ_CASE_INSENSITIVE
,
614 Status
= NtCreateKey(&KeyHandle
,
619 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
621 if (!NT_SUCCESS(Status
)) return Status
;
624 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
626 /* Initialize the symbolic link name */
628 "\\Registry\\Machine\\System\\ControlSet%03ld",
630 RtlInitAnsiString(&TempString
, Buffer
);
632 /* Create a Unicode string out of it */
633 KeyName
.MaximumLength
= sizeof(UnicodeBuffer
);
634 KeyName
.Buffer
= UnicodeBuffer
;
635 Status
= RtlAnsiStringToUnicodeString(&KeyName
, &TempString
, FALSE
);
638 Status
= NtSetValueKey(KeyHandle
,
639 &CmSymbolicLinkValueName
,
644 if (!NT_SUCCESS(Status
)) return Status
;
646 /* Get the configuration database key */
647 InitializeObjectAttributes(&ObjectAttributes
,
649 OBJ_CASE_INSENSITIVE
,
652 Status
= NtOpenKey(&ConfigHandle
, KEY_READ
, &ObjectAttributes
);
655 /* Check if we don't have one */
656 if (!NT_SUCCESS(Status
))
658 /* Cleanup and exit */
663 /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
664 if (!LoaderBlock
->RegistryBase
)
670 /* Now get the current config */
671 RtlInitUnicodeString(&KeyName
, L
"CurrentConfig");
672 Status
= NtQueryValueKey(ConfigHandle
,
674 KeyValueFullInformation
,
676 sizeof(ValueInfoBuffer
),
679 /* Set pointer to buffer */
680 ValueInfo
= (PKEY_VALUE_FULL_INFORMATION
)ValueInfoBuffer
;
682 /* Check if we failed or got a non DWORD-value */
683 if (!(NT_SUCCESS(Status
)) || (ValueInfo
->Type
!= REG_DWORD
)) goto Cleanup
;
685 /* Get the hadware profile */
686 HwProfile
= *(PULONG
)((PUCHAR
)ValueInfo
+ ValueInfo
->DataOffset
);
689 /* Open the hardware profile key */
690 RtlInitUnicodeString(&KeyName
,
691 L
"\\Registry\\Machine\\System\\CurrentControlSet"
692 L
"\\Hardware Profiles");
693 InitializeObjectAttributes(&ObjectAttributes
,
695 OBJ_CASE_INSENSITIVE
,
698 Status
= NtOpenKey(&ParentHandle
, KEY_READ
, &ObjectAttributes
);
699 if (!NT_SUCCESS(Status
))
701 /* Exit and clean up */
706 /* Build the profile name */
707 sprintf(Buffer
, "%04ld", HwProfile
);
708 RtlInitAnsiString(&TempString
, Buffer
);
710 /* Convert it to Unicode */
711 KeyName
.MaximumLength
= sizeof(UnicodeBuffer
);
712 KeyName
.Buffer
= UnicodeBuffer
;
713 Status
= RtlAnsiStringToUnicodeString(&KeyName
,
716 ASSERT(Status
== STATUS_SUCCESS
);
718 /* Open the associated key */
719 InitializeObjectAttributes(&ObjectAttributes
,
721 OBJ_CASE_INSENSITIVE
,
724 Status
= NtOpenKey(&ProfileHandle
,
725 KEY_READ
| KEY_WRITE
,
727 if (!NT_SUCCESS (Status
))
729 /* Cleanup and exit */
734 /* Check if we have a loader block extension */
735 LoaderExtension
= LoaderBlock
->Extension
;
738 DPRINT("ReactOS doesn't support NTLDR Profiles yet!\n");
741 /* Create the current hardware profile key */
742 RtlInitUnicodeString(&KeyName
,
743 L
"\\Registry\\Machine\\System\\CurrentControlSet\\"
744 L
"Hardware Profiles\\Current");
745 InitializeObjectAttributes(&ObjectAttributes
,
747 OBJ_CASE_INSENSITIVE
,
750 Status
= NtCreateKey(&KeyHandle
,
755 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
757 if (NT_SUCCESS(Status
))
760 ASSERT(Disposition
== REG_CREATED_NEW_KEY
);
762 /* Create the profile name */
764 "\\Registry\\Machine\\System\\CurrentControlSet\\"
765 "Hardware Profiles\\%04ld",
767 RtlInitAnsiString(&TempString
, Buffer
);
769 /* Convert it to Unicode */
770 KeyName
.MaximumLength
= sizeof(UnicodeBuffer
);
771 KeyName
.Buffer
= UnicodeBuffer
;
772 Status
= RtlAnsiStringToUnicodeString(&KeyName
,
775 ASSERT(STATUS_SUCCESS
== Status
);
778 Status
= NtSetValueKey(KeyHandle
,
779 &CmSymbolicLinkValueName
,
787 /* Close every opened handle */
789 if (ConfigHandle
) NtClose(ConfigHandle
);
790 if (ProfileHandle
) NtClose(ProfileHandle
);
791 if (ParentHandle
) NtClose(ParentHandle
);
793 DPRINT1("CmpCreateControlSet() done\n");
796 return STATUS_SUCCESS
;
801 CmpLinkHiveToMaster(IN PUNICODE_STRING LinkName
,
802 IN HANDLE RootDirectory
,
803 IN PCMHIVE RegistryHive
,
805 IN PSECURITY_DESCRIPTOR SecurityDescriptor
)
807 OBJECT_ATTRIBUTES ObjectAttributes
;
809 CM_PARSE_CONTEXT ParseContext
= {0};
811 PCM_KEY_BODY KeyBody
;
814 /* Setup the object attributes */
815 InitializeObjectAttributes(&ObjectAttributes
,
817 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
821 /* Setup the parse context */
822 ParseContext
.CreateLink
= TRUE
;
823 ParseContext
.CreateOperation
= TRUE
;
824 ParseContext
.ChildHive
.KeyHive
= &RegistryHive
->Hive
;
826 /* Check if we have a root keycell or if we need to create it */
830 ParseContext
.ChildHive
.KeyCell
= HCELL_NIL
;
835 ParseContext
.ChildHive
.KeyCell
= RegistryHive
->Hive
.BaseBlock
->RootCell
;
838 /* Create the link node */
839 Status
= ObOpenObjectByName(&ObjectAttributes
,
843 KEY_READ
| KEY_WRITE
,
844 (PVOID
)&ParseContext
,
846 if (!NT_SUCCESS(Status
)) return Status
;
848 /* Mark the hive as clean */
849 RegistryHive
->Hive
.DirtyFlag
= FALSE
;
851 /* ReactOS Hack: Keep alive */
852 Status
= ObReferenceObjectByHandle(KeyHandle
,
858 ASSERT(NT_SUCCESS(Status
));
860 /* Close the extra handle */
862 return STATUS_SUCCESS
;
868 CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
871 ANSI_STRING LoadString
;
876 UNICODE_STRING KeyName
;
877 PCMHIVE SystemHive
= NULL
;
878 UNICODE_STRING HiveName
= RTL_CONSTANT_STRING(L
"SYSTEM");
879 PSECURITY_DESCRIPTOR SecurityDescriptor
;
882 /* Setup the ansi string */
883 RtlInitAnsiString(&LoadString
, LoaderBlock
->LoadOptions
);
885 /* Allocate the unicode buffer */
886 Length
= LoadString
.Length
* sizeof(WCHAR
) + sizeof(UNICODE_NULL
);
887 Buffer
= ExAllocatePoolWithTag(PagedPool
, Length
, TAG_CM
);
891 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
, 3, 1, (ULONG_PTR
)LoaderBlock
, 0);
894 /* Setup the unicode string */
895 RtlInitEmptyUnicodeString(&CmpLoadOptions
, Buffer
, (USHORT
)Length
);
897 /* Add the load options and null-terminate */
898 RtlAnsiStringToUnicodeString(&CmpLoadOptions
, &LoadString
, FALSE
);
899 CmpLoadOptions
.Buffer
[LoadString
.Length
] = UNICODE_NULL
;
900 CmpLoadOptions
.Length
+= sizeof(WCHAR
);
902 /* Get the System Hive base address */
903 HiveBase
= LoaderBlock
->RegistryBase
;
907 Status
= CmpInitializeHive((PCMHIVE
*)&SystemHive
,
917 if (!NT_SUCCESS(Status
)) return FALSE
;
919 /* Set the hive filename */
920 RtlCreateUnicodeString(&SystemHive
->FileFullPath
,
921 L
"\\SystemRoot\\System32\\Config\\SYSTEM");
923 /* We imported, no need to create a new hive */
926 /* Manually set the hive as volatile, if in Live CD mode */
927 if (CmpShareSystemHives
) SystemHive
->Hive
.HiveFlags
= HIVE_VOLATILE
;
932 Status
= CmpInitializeHive(&SystemHive
,
942 if (!NT_SUCCESS(Status
)) return FALSE
;
944 /* Set the hive filename */
945 RtlCreateUnicodeString(&SystemHive
->FileFullPath
,
946 L
"\\SystemRoot\\System32\\Config\\SYSTEM");
948 /* Tell CmpLinkHiveToMaster to allocate a hive */
952 /* Save the boot type */
953 CmpBootType
= SystemHive
->Hive
.BaseBlock
->BootType
;
955 /* Are we in self-healing mode? */
958 /* Disable self-healing internally and check if boot type wanted it */
962 /* We're disabled, so bugcheck */
963 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
,
966 (ULONG_PTR
)SystemHive
,
971 /* Create the default security descriptor */
972 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
974 /* Attach it to the system key */
975 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\SYSTEM");
976 Status
= CmpLinkHiveToMaster(&KeyName
,
982 /* Free the security descriptor */
983 ExFreePoolWithTag(SecurityDescriptor
, TAG_CM
);
984 if (!NT_SUCCESS(Status
)) return FALSE
;
986 /* Add the hive to the hive list */
987 CmpMachineHiveList
[3].CmHive
= (PCMHIVE
)SystemHive
;
996 CmpCreateObjectTypes(VOID
)
998 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer
;
1000 GENERIC_MAPPING CmpKeyMapping
= {KEY_READ
,
1006 /* Initialize the Key object type */
1007 RtlZeroMemory(&ObjectTypeInitializer
, sizeof(ObjectTypeInitializer
));
1008 RtlInitUnicodeString(&Name
, L
"Key");
1009 ObjectTypeInitializer
.Length
= sizeof(ObjectTypeInitializer
);
1010 ObjectTypeInitializer
.DefaultPagedPoolCharge
= sizeof(CM_KEY_BODY
);
1011 ObjectTypeInitializer
.GenericMapping
= CmpKeyMapping
;
1012 ObjectTypeInitializer
.PoolType
= PagedPool
;
1013 ObjectTypeInitializer
.ValidAccessMask
= KEY_ALL_ACCESS
;
1014 ObjectTypeInitializer
.UseDefaultObject
= TRUE
;
1015 ObjectTypeInitializer
.DeleteProcedure
= CmpDeleteKeyObject
;
1016 ObjectTypeInitializer
.ParseProcedure
= CmpParseKey
;
1017 ObjectTypeInitializer
.SecurityProcedure
= CmpSecurityMethod
;
1018 ObjectTypeInitializer
.QueryNameProcedure
= CmpQueryKeyName
;
1019 ObjectTypeInitializer
.CloseProcedure
= CmpCloseKeyObject
;
1020 ObjectTypeInitializer
.SecurityRequired
= TRUE
;
1021 ObjectTypeInitializer
.InvalidAttributes
= OBJ_EXCLUSIVE
| OBJ_PERMANENT
;
1024 return ObCreateObjectType(&Name
, &ObjectTypeInitializer
, NULL
, &CmpKeyObjectType
);
1030 CmpCreateRootNode(IN PHHIVE Hive
,
1032 OUT PHCELL_INDEX Index
)
1034 UNICODE_STRING KeyName
;
1035 PCM_KEY_NODE KeyCell
;
1036 LARGE_INTEGER SystemTime
;
1039 /* Initialize the node name and allocate it */
1040 RtlInitUnicodeString(&KeyName
, Name
);
1041 *Index
= HvAllocateCell(Hive
,
1042 FIELD_OFFSET(CM_KEY_NODE
, Name
) +
1043 CmpNameSize(Hive
, &KeyName
),
1046 if (*Index
== HCELL_NIL
) return FALSE
;
1048 /* Set the cell index and get the data */
1049 Hive
->BaseBlock
->RootCell
= *Index
;
1050 KeyCell
= (PCM_KEY_NODE
)HvGetCell(Hive
, *Index
);
1051 if (!KeyCell
) return FALSE
;
1053 /* Setup the cell */
1054 KeyCell
->Signature
= (USHORT
)CM_KEY_NODE_SIGNATURE
;
1055 KeyCell
->Flags
= KEY_HIVE_ENTRY
| KEY_NO_DELETE
;
1056 KeQuerySystemTime(&SystemTime
);
1057 KeyCell
->LastWriteTime
= SystemTime
;
1058 KeyCell
->Parent
= HCELL_NIL
;
1059 KeyCell
->SubKeyCounts
[Stable
] = 0;
1060 KeyCell
->SubKeyCounts
[Volatile
] = 0;
1061 KeyCell
->SubKeyLists
[Stable
] = HCELL_NIL
;
1062 KeyCell
->SubKeyLists
[Volatile
] = HCELL_NIL
;
1063 KeyCell
->ValueList
.Count
= 0;
1064 KeyCell
->ValueList
.List
= HCELL_NIL
;
1065 KeyCell
->Security
= HCELL_NIL
;
1066 KeyCell
->Class
= HCELL_NIL
;
1067 KeyCell
->ClassLength
= 0;
1068 KeyCell
->MaxNameLen
= 0;
1069 KeyCell
->MaxClassLen
= 0;
1070 KeyCell
->MaxValueNameLen
= 0;
1071 KeyCell
->MaxValueDataLen
= 0;
1073 /* Copy the name (this will also set the length) */
1074 KeyCell
->NameLength
= CmpCopyName(Hive
, (PWCHAR
)KeyCell
->Name
, &KeyName
);
1076 /* Check if the name was compressed */
1077 if (KeyCell
->NameLength
< KeyName
.Length
)
1080 KeyCell
->Flags
|= KEY_COMP_NAME
;
1083 /* Return success */
1084 HvReleaseCell(Hive
, *Index
);
1091 CmpCreateRegistryRoot(VOID
)
1093 UNICODE_STRING KeyName
;
1094 OBJECT_ATTRIBUTES ObjectAttributes
;
1095 PCM_KEY_BODY RootKey
;
1096 HCELL_INDEX RootIndex
;
1098 PCM_KEY_NODE KeyCell
;
1099 PSECURITY_DESCRIPTOR SecurityDescriptor
;
1100 PCM_KEY_CONTROL_BLOCK Kcb
;
1103 /* Setup the root node */
1104 if (!CmpCreateRootNode(&CmiVolatileHive
->Hive
, L
"REGISTRY", &RootIndex
))
1110 /* Create '\Registry' key. */
1111 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY");
1112 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
1113 InitializeObjectAttributes(&ObjectAttributes
,
1115 OBJ_CASE_INSENSITIVE
,
1118 Status
= ObCreateObject(KernelMode
,
1123 sizeof(CM_KEY_BODY
),
1127 ExFreePoolWithTag(SecurityDescriptor
, TAG_CM
);
1128 if (!NT_SUCCESS(Status
)) return FALSE
;
1130 /* Sanity check, and get the key cell */
1131 ASSERT((&CmiVolatileHive
->Hive
)->ReleaseCellRoutine
== NULL
);
1132 KeyCell
= (PCM_KEY_NODE
)HvGetCell(&CmiVolatileHive
->Hive
, RootIndex
);
1133 if (!KeyCell
) return FALSE
;
1135 /* Create the KCB */
1136 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY");
1137 Kcb
= CmpCreateKeyControlBlock(&CmiVolatileHive
->Hive
,
1145 ObDereferenceObject(RootKey
);
1149 /* Initialize the object */
1150 RootKey
->KeyControlBlock
= Kcb
;
1151 RootKey
->Type
= CM_KEY_BODY_TYPE
;
1152 RootKey
->NotifyBlock
= NULL
;
1153 RootKey
->ProcessID
= PsGetCurrentProcessId();
1156 EnlistKeyBodyWithKCB(RootKey
, 0);
1158 /* Insert the key into the namespace */
1159 Status
= ObInsertObject(RootKey
,
1164 &CmpRegistryRootHandle
);
1165 if (!NT_SUCCESS(Status
))
1167 ObDereferenceObject(RootKey
);
1171 /* Reference the key again so that we never lose it */
1172 Status
= ObReferenceObjectByHandle(CmpRegistryRootHandle
,
1178 if (!NT_SUCCESS(Status
))
1180 ObDereferenceObject(RootKey
);
1184 /* Completely sucessful */
1190 CmpGetRegistryPath(IN PWCHAR ConfigPath
)
1192 OBJECT_ATTRIBUTES ObjectAttributes
;
1195 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo
;
1196 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\HARDWARE");
1197 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"InstallPath");
1198 ULONG BufferSize
, ResultSize
;
1200 /* Check if we are booted in setup */
1201 if (ExpInTextModeSetup
)
1203 /* Setup the object attributes */
1204 InitializeObjectAttributes(&ObjectAttributes
,
1206 OBJ_CASE_INSENSITIVE
,
1210 Status
= ZwOpenKey(&KeyHandle
,
1213 if (!NT_SUCCESS(Status
)) return Status
;
1215 /* Allocate the buffer */
1216 BufferSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 4096;
1217 ValueInfo
= ExAllocatePoolWithTag(PagedPool
, BufferSize
, TAG_CM
);
1222 return STATUS_INSUFFICIENT_RESOURCES
;
1225 /* Query the value */
1226 Status
= ZwQueryValueKey(KeyHandle
,
1228 KeyValuePartialInformation
,
1233 if (!NT_SUCCESS(Status
))
1236 ExFreePoolWithTag(ValueInfo
, TAG_CM
);
1240 /* Copy the config path and null-terminate it */
1241 RtlCopyMemory(ConfigPath
,
1243 ValueInfo
->DataLength
);
1244 ConfigPath
[ValueInfo
->DataLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1245 ExFreePoolWithTag(ValueInfo
, TAG_CM
);
1249 /* Just use default path */
1250 wcscpy(ConfigPath
, L
"\\SystemRoot");
1253 /* Add registry path */
1254 wcscat(ConfigPath
, L
"\\System32\\Config\\");
1257 return STATUS_SUCCESS
;
1262 CmpLoadHiveThread(IN PVOID StartContext
)
1264 WCHAR FileBuffer
[MAX_PATH
], RegBuffer
[MAX_PATH
], ConfigPath
[MAX_PATH
];
1265 UNICODE_STRING TempName
, FileName
, RegName
;
1266 ULONG i
, ErrorResponse
, WorkerCount
, Length
;
1269 ULONG PrimaryDisposition
, SecondaryDisposition
, ClusterSize
;
1271 HANDLE PrimaryHandle
= NULL
, LogHandle
= NULL
;
1272 NTSTATUS Status
= STATUS_SUCCESS
;
1273 PVOID ErrorParameters
;
1276 /* Get the hive index, make sure it makes sense */
1277 i
= PtrToUlong(StartContext
);
1278 ASSERT(CmpMachineHiveList
[i
].Name
!= NULL
);
1280 /* We were started */
1281 CmpMachineHiveList
[i
].ThreadStarted
= TRUE
;
1283 /* Build the file name and registry name strings */
1284 RtlInitEmptyUnicodeString(&FileName
, FileBuffer
, MAX_PATH
);
1285 RtlInitEmptyUnicodeString(&RegName
, RegBuffer
, MAX_PATH
);
1287 /* Now build the system root path */
1288 CmpGetRegistryPath(ConfigPath
);
1289 RtlInitUnicodeString(&TempName
, ConfigPath
);
1290 RtlAppendStringToString((PSTRING
)&FileName
, (PSTRING
)&TempName
);
1291 FileStart
= FileName
.Length
;
1293 /* And build the registry root path */
1294 RtlInitUnicodeString(&TempName
, L
"\\REGISTRY\\");
1295 RtlAppendStringToString((PSTRING
)&RegName
, (PSTRING
)&TempName
);
1296 //RegStart = RegName.Length;
1298 /* Build the base name */
1299 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].BaseName
);
1300 RtlAppendStringToString((PSTRING
)&RegName
, (PSTRING
)&TempName
);
1302 /* Check if this is a child of the root */
1303 if (RegName
.Buffer
[RegName
.Length
/ sizeof(WCHAR
) - 1] == '\\')
1305 /* Then setup the whole name */
1306 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].Name
);
1307 RtlAppendStringToString((PSTRING
)&RegName
, (PSTRING
)&TempName
);
1310 /* Now add the rest of the file name */
1311 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].Name
);
1312 FileName
.Length
= FileStart
;
1313 RtlAppendStringToString((PSTRING
)&FileName
, (PSTRING
)&TempName
);
1314 if (!CmpMachineHiveList
[i
].CmHive
)
1316 /* We need to allocate a new hive structure */
1317 CmpMachineHiveList
[i
].Allocate
= TRUE
;
1319 /* Load the hive file */
1320 Status
= CmpInitHiveFromFile(&FileName
,
1321 CmpMachineHiveList
[i
].HHiveFlags
,
1323 &CmpMachineHiveList
[i
].Allocate
,
1325 if (!(NT_SUCCESS(Status
)) ||
1326 (!(CmHive
->FileHandles
[HFILE_TYPE_LOG
]) && !(CmpMiniNTBoot
))) // HACK
1328 /* We failed or couldn't get a log file, raise a hard error */
1329 ErrorParameters
= &FileName
;
1330 NtRaiseHardError(STATUS_CANNOT_LOAD_REGISTRY_FILE
,
1333 (PULONG_PTR
)&ErrorParameters
,
1338 /* Set the hive flags and newly allocated hive pointer */
1339 CmHive
->Flags
= CmpMachineHiveList
[i
].CmHiveFlags
;
1340 CmpMachineHiveList
[i
].CmHive2
= CmHive
;
1344 /* We already have a hive, is it volatile? */
1345 CmHive
= CmpMachineHiveList
[i
].CmHive
;
1346 if (!(CmHive
->Hive
.HiveFlags
& HIVE_VOLATILE
))
1348 /* It's now, open the hive file and log */
1349 Status
= CmpOpenHiveFiles(&FileName
,
1353 &PrimaryDisposition
,
1354 &SecondaryDisposition
,
1359 if (!(NT_SUCCESS(Status
)) || !(LogHandle
))
1361 /* Couldn't open the hive or its log file, raise a hard error */
1362 ErrorParameters
= &FileName
;
1363 NtRaiseHardError(STATUS_CANNOT_LOAD_REGISTRY_FILE
,
1366 (PULONG_PTR
)&ErrorParameters
,
1370 /* And bugcheck for posterity's sake */
1371 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
, 9, 0, i
, Status
);
1374 /* Save the file handles. This should remove our sync hacks */
1375 CmHive
->FileHandles
[HFILE_TYPE_LOG
] = LogHandle
;
1376 CmHive
->FileHandles
[HFILE_TYPE_PRIMARY
] = PrimaryHandle
;
1378 /* Allow lazy flushing since the handles are there -- remove sync hacks */
1379 //ASSERT(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH);
1380 CmHive
->Hive
.HiveFlags
&= ~HIVE_NOLAZYFLUSH
;
1382 /* Get the real size of the hive */
1383 Length
= CmHive
->Hive
.Storage
[Stable
].Length
+ HBLOCK_SIZE
;
1385 /* Check if the cluster size doesn't match */
1386 if (CmHive
->Hive
.Cluster
!= ClusterSize
) ASSERT(FALSE
);
1388 /* Set the file size */
1389 DPRINT("FIXME: Should set file size: %lx\n", Length
);
1390 //if (!CmpFileSetSize((PHHIVE)CmHive, HFILE_TYPE_PRIMARY, Length, Length))
1392 /* This shouldn't fail */
1396 /* Another thing we don't support is NTLDR-recovery */
1397 if (CmHive
->Hive
.BaseBlock
->BootRecover
) ASSERT(FALSE
);
1399 /* Finally, set our allocated hive to the same hive we've had */
1400 CmpMachineHiveList
[i
].CmHive2
= CmHive
;
1401 ASSERT(CmpMachineHiveList
[i
].CmHive
== CmpMachineHiveList
[i
].CmHive2
);
1406 CmpMachineHiveList
[i
].ThreadFinished
= TRUE
;
1408 /* Check if we're the last worker */
1409 WorkerCount
= InterlockedIncrement(&CmpLoadWorkerIncrement
);
1410 if (WorkerCount
== CM_NUMBER_OF_MACHINE_HIVES
)
1412 /* Signal the event */
1413 KeSetEvent(&CmpLoadWorkerEvent
, 0, FALSE
);
1416 /* Kill the thread */
1417 PsTerminateSystemThread(Status
);
1422 CmpInitializeHiveList(IN USHORT Flag
)
1424 WCHAR FileBuffer
[MAX_PATH
], RegBuffer
[MAX_PATH
], ConfigPath
[MAX_PATH
];
1425 UNICODE_STRING TempName
, FileName
, RegName
;
1430 PSECURITY_DESCRIPTOR SecurityDescriptor
;
1433 /* Allow writing for now */
1436 /* Build the file name and registry name strings */
1437 RtlInitEmptyUnicodeString(&FileName
, FileBuffer
, MAX_PATH
);
1438 RtlInitEmptyUnicodeString(&RegName
, RegBuffer
, MAX_PATH
);
1440 /* Now build the system root path */
1441 CmpGetRegistryPath(ConfigPath
);
1442 RtlInitUnicodeString(&TempName
, ConfigPath
);
1443 RtlAppendStringToString((PSTRING
)&FileName
, (PSTRING
)&TempName
);
1445 /* And build the registry root path */
1446 RtlInitUnicodeString(&TempName
, L
"\\REGISTRY\\");
1447 RtlAppendStringToString((PSTRING
)&RegName
, (PSTRING
)&TempName
);
1448 RegStart
= RegName
.Length
;
1450 /* Setup the event to synchronize workers */
1451 KeInitializeEvent(&CmpLoadWorkerEvent
, SynchronizationEvent
, FALSE
);
1453 /* Enter special boot condition */
1454 CmpSpecialBootCondition
= TRUE
;
1456 /* Create the SD for the root hives */
1457 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
1459 /* Loop every hive we care about */
1460 for (i
= 0; i
< CM_NUMBER_OF_MACHINE_HIVES
; i
++)
1462 /* Make sure the list is setup */
1463 ASSERT(CmpMachineHiveList
[i
].Name
!= NULL
);
1465 /* Create a thread to handle this hive */
1466 Status
= PsCreateSystemThread(&Thread
,
1473 if (NT_SUCCESS(Status
))
1475 /* We don't care about the handle -- the thread self-terminates */
1480 /* Can't imagine this happening */
1481 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO
, 9, 3, i
, Status
);
1485 /* Make sure we've reached the end of the list */
1486 ASSERT(CmpMachineHiveList
[i
].Name
== NULL
);
1488 /* Wait for hive loading to finish */
1489 KeWaitForSingleObject(&CmpLoadWorkerEvent
,
1495 /* Exit the special boot condition and make sure all workers completed */
1496 CmpSpecialBootCondition
= FALSE
;
1497 ASSERT(CmpLoadWorkerIncrement
== CM_NUMBER_OF_MACHINE_HIVES
);
1499 /* Loop hives again */
1500 for (i
= 0; i
< CM_NUMBER_OF_MACHINE_HIVES
; i
++)
1502 /* Make sure the thread ran and finished */
1503 ASSERT(CmpMachineHiveList
[i
].ThreadFinished
== TRUE
);
1504 ASSERT(CmpMachineHiveList
[i
].ThreadStarted
== TRUE
);
1506 /* Check if this was a new hive */
1507 if (!CmpMachineHiveList
[i
].CmHive
)
1509 /* Make sure we allocated something */
1510 ASSERT(CmpMachineHiveList
[i
].CmHive2
!= NULL
);
1512 /* Build the base name */
1513 RegName
.Length
= RegStart
;
1514 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].BaseName
);
1515 RtlAppendStringToString((PSTRING
)&RegName
, (PSTRING
)&TempName
);
1517 /* Check if this is a child of the root */
1518 if (RegName
.Buffer
[RegName
.Length
/ sizeof(WCHAR
) - 1] == '\\')
1520 /* Then setup the whole name */
1521 RtlInitUnicodeString(&TempName
, CmpMachineHiveList
[i
].Name
);
1522 RtlAppendStringToString((PSTRING
)&RegName
, (PSTRING
)&TempName
);
1525 /* Now link the hive to its master */
1526 Status
= CmpLinkHiveToMaster(&RegName
,
1528 CmpMachineHiveList
[i
].CmHive2
,
1529 CmpMachineHiveList
[i
].Allocate
,
1530 SecurityDescriptor
);
1531 if (Status
!= STATUS_SUCCESS
)
1533 /* Linking needs to work */
1534 KeBugCheckEx(CONFIG_LIST_FAILED
, 11, Status
, i
, (ULONG_PTR
)&RegName
);
1537 /* Check if we had to allocate a new hive */
1538 if (CmpMachineHiveList
[i
].Allocate
)
1540 /* Sync the new hive */
1541 //HvSyncHive((PHHIVE)(CmpMachineHiveList[i].CmHive2));
1545 /* Check if we created a new hive */
1546 if (CmpMachineHiveList
[i
].CmHive2
)
1548 /* Add to HiveList key */
1549 CmpAddToHiveFileList(CmpMachineHiveList
[i
].CmHive2
);
1553 /* Get rid of the SD */
1554 ExFreePoolWithTag(SecurityDescriptor
, TAG_CM
);
1556 /* Link SECURITY to SAM */
1557 CmpLinkKeyToHive(L
"\\Registry\\Machine\\Security\\SAM",
1558 L
"\\Registry\\Machine\\SAM\\SAM");
1560 /* Link S-1-5-18 to .Default */
1561 CmpNoVolatileCreates
= FALSE
;
1562 CmpLinkKeyToHive(L
"\\Registry\\User\\S-1-5-18",
1563 L
"\\Registry\\User\\.Default");
1564 CmpNoVolatileCreates
= TRUE
;
1572 OBJECT_ATTRIBUTES ObjectAttributes
;
1573 UNICODE_STRING KeyName
;
1576 PCMHIVE HardwareHive
;
1577 PSECURITY_DESCRIPTOR SecurityDescriptor
;
1580 /* Check if this is PE-boot */
1581 if (InitIsWinPEMode
)
1583 /* Set registry to PE mode */
1584 CmpMiniNTBoot
= TRUE
;
1585 CmpShareSystemHives
= TRUE
;
1588 /* Initialize the hive list and lock */
1589 InitializeListHead(&CmpHiveListHead
);
1590 ExInitializePushLock(&CmpHiveListHeadLock
);
1591 ExInitializePushLock(&CmpLoadHiveLock
);
1593 /* Initialize registry lock */
1594 ExInitializeResourceLite(&CmpRegistryLock
);
1596 /* Initialize the cache */
1597 CmpInitializeCache();
1599 /* Initialize allocation and delayed dereferencing */
1600 CmpInitCmPrivateAlloc();
1601 CmpInitCmPrivateDelayAlloc();
1602 CmpInitDelayDerefKCBEngine();
1604 /* Initialize callbacks */
1607 /* Initialize self healing */
1608 KeInitializeGuardedMutex(&CmpSelfHealQueueLock
);
1609 InitializeListHead(&CmpSelfHealQueueListHead
);
1611 /* Save the current process and lock the registry */
1612 CmpSystemProcess
= PsGetCurrentProcess();
1614 /* Create the key object types */
1615 Status
= CmpCreateObjectTypes();
1616 if (!NT_SUCCESS(Status
))
1619 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 1, Status
, 0);
1622 /* Build the master hive */
1623 Status
= CmpInitializeHive(&CmiVolatileHive
,
1633 if (!NT_SUCCESS(Status
))
1636 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 2, Status
, 0);
1639 /* Create the \REGISTRY key node */
1640 if (!CmpCreateRegistryRoot())
1643 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 3, 0, 0);
1646 /* Create the default security descriptor */
1647 SecurityDescriptor
= CmpHiveRootSecurityDescriptor();
1649 /* Create '\Registry\Machine' key. */
1650 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY\\MACHINE");
1651 InitializeObjectAttributes(&ObjectAttributes
,
1653 OBJ_CASE_INSENSITIVE
,
1655 SecurityDescriptor
);
1656 Status
= NtCreateKey(&KeyHandle
,
1657 KEY_READ
| KEY_WRITE
,
1663 if (!NT_SUCCESS(Status
))
1666 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 5, Status
, 0);
1669 /* Close the handle */
1672 /* Create '\Registry\User' key. */
1673 RtlInitUnicodeString(&KeyName
, L
"\\REGISTRY\\USER");
1674 InitializeObjectAttributes(&ObjectAttributes
,
1676 OBJ_CASE_INSENSITIVE
,
1678 SecurityDescriptor
);
1679 Status
= NtCreateKey(&KeyHandle
,
1680 KEY_READ
| KEY_WRITE
,
1686 if (!NT_SUCCESS(Status
))
1689 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 6, Status
, 0);
1692 /* Close the handle */
1695 /* After this point, do not allow creating keys in the master hive */
1696 CmpNoVolatileCreates
= TRUE
;
1698 /* Initialize the system hive */
1699 if (!CmpInitializeSystemHive(KeLoaderBlock
))
1702 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 7, 0, 0);
1705 /* Create the 'CurrentControlSet' link. */
1706 Status
= CmpCreateControlSet(KeLoaderBlock
);
1707 if (!NT_SUCCESS(Status
))
1710 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 8, Status
, 0);
1713 /* Create the hardware hive */
1714 Status
= CmpInitializeHive((PCMHIVE
*)&HardwareHive
,
1724 if (!NT_SUCCESS(Status
))
1727 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 11, Status
, 0);
1730 /* Add the hive to the hive list */
1731 CmpMachineHiveList
[0].CmHive
= (PCMHIVE
)HardwareHive
;
1733 /* Attach it to the machine key */
1734 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\HARDWARE");
1735 Status
= CmpLinkHiveToMaster(&KeyName
,
1737 (PCMHIVE
)HardwareHive
,
1739 SecurityDescriptor
);
1740 if (!NT_SUCCESS(Status
))
1743 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 12, Status
, 0);
1746 /* Add to HiveList key */
1747 CmpAddToHiveFileList(HardwareHive
);
1749 /* Free the security descriptor */
1750 ExFreePoolWithTag(SecurityDescriptor
, TAG_CM
);
1752 /* Fill out the Hardware key with the ARC Data from the Loader */
1753 Status
= CmpInitializeHardwareConfiguration(KeLoaderBlock
);
1754 if (!NT_SUCCESS(Status
))
1757 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 13, Status
, 0);
1760 /* Initialize machine-dependent information into the registry */
1761 Status
= CmpInitializeMachineDependentConfiguration(KeLoaderBlock
);
1762 if (!NT_SUCCESS(Status
))
1765 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 14, Status
, 0);
1768 /* Initialize volatile registry settings */
1769 Status
= CmpSetSystemValues(KeLoaderBlock
);
1770 if (!NT_SUCCESS(Status
))
1773 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 1, 15, Status
, 0);
1776 /* Free the load options */
1777 ExFreePoolWithTag(CmpLoadOptions
.Buffer
, TAG_CM
);
1779 /* If we got here, all went well */
1786 CmpFreeDriverList(IN PHHIVE Hive
,
1787 IN PLIST_ENTRY DriverList
)
1789 PLIST_ENTRY NextEntry
, OldEntry
;
1790 PBOOT_DRIVER_NODE DriverNode
;
1793 /* Parse the current list */
1794 NextEntry
= DriverList
->Flink
;
1795 while (NextEntry
!= DriverList
)
1797 /* Get the driver node */
1798 DriverNode
= CONTAINING_RECORD(NextEntry
, BOOT_DRIVER_NODE
, ListEntry
.Link
);
1800 /* Get the next entry now, since we're going to free it later */
1801 OldEntry
= NextEntry
;
1802 NextEntry
= NextEntry
->Flink
;
1804 /* Was there a name? */
1805 if (DriverNode
->Name
.Buffer
)
1808 CmpFree(DriverNode
->Name
.Buffer
, DriverNode
->Name
.Length
);
1811 /* Was there a registry path? */
1812 if (DriverNode
->ListEntry
.RegistryPath
.Buffer
)
1815 CmpFree(DriverNode
->ListEntry
.RegistryPath
.Buffer
,
1816 DriverNode
->ListEntry
.RegistryPath
.MaximumLength
);
1819 /* Was there a file path? */
1820 if (DriverNode
->ListEntry
.FilePath
.Buffer
)
1823 CmpFree(DriverNode
->ListEntry
.FilePath
.Buffer
,
1824 DriverNode
->ListEntry
.FilePath
.MaximumLength
);
1827 /* Now free the node, and move on */
1828 CmpFree(OldEntry
, sizeof(BOOT_DRIVER_NODE
));
1835 CmGetSystemDriverList(VOID
)
1837 LIST_ENTRY DriverList
;
1838 OBJECT_ATTRIBUTES ObjectAttributes
;
1840 PCM_KEY_BODY KeyBody
;
1842 HCELL_INDEX RootCell
, ControlCell
;
1844 UNICODE_STRING KeyName
;
1845 PLIST_ENTRY NextEntry
;
1847 PUNICODE_STRING
* ServicePath
= NULL
;
1848 BOOLEAN Success
, AutoSelect
;
1849 PBOOT_DRIVER_LIST_ENTRY DriverEntry
;
1852 /* Initialize the driver list */
1853 InitializeListHead(&DriverList
);
1855 /* Open the system hive key */
1856 RtlInitUnicodeString(&KeyName
, L
"\\Registry\\Machine\\System");
1857 InitializeObjectAttributes(&ObjectAttributes
,
1859 OBJ_CASE_INSENSITIVE
,
1862 Status
= NtOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
1863 if (!NT_SUCCESS(Status
)) return NULL
;
1865 /* Reference the key object to get the root hive/cell to access directly */
1866 Status
= ObReferenceObjectByHandle(KeyHandle
,
1872 if (!NT_SUCCESS(Status
))
1879 /* Do all this under the registry lock */
1880 CmpLockRegistryExclusive();
1882 /* Get the hive and key cell */
1883 Hive
= KeyBody
->KeyControlBlock
->KeyHive
;
1884 RootCell
= KeyBody
->KeyControlBlock
->KeyCell
;
1886 /* Open the current control set key */
1887 RtlInitUnicodeString(&KeyName
, L
"Current");
1888 ControlCell
= CmpFindControlSet(Hive
, RootCell
, &KeyName
, &AutoSelect
);
1889 if (ControlCell
== HCELL_NIL
) goto EndPath
;
1891 /* Find all system drivers */
1892 Success
= CmpFindDrivers(Hive
, ControlCell
, SystemLoad
, NULL
, &DriverList
);
1893 if (!Success
) goto EndPath
;
1895 /* Sort by group/tag */
1896 if (!CmpSortDriverList(Hive
, ControlCell
, &DriverList
)) goto EndPath
;
1898 /* Remove circular dependencies (cycles) and sort */
1899 if (!CmpResolveDriverDependencies(&DriverList
)) goto EndPath
;
1901 /* Loop the list to count drivers */
1902 for (i
= 0, NextEntry
= DriverList
.Flink
;
1903 NextEntry
!= &DriverList
;
1904 i
++, NextEntry
= NextEntry
->Flink
);
1906 /* Allocate the array */
1907 ServicePath
= ExAllocatePool(NonPagedPool
, (i
+ 1) * sizeof(PUNICODE_STRING
));
1908 if (!ServicePath
) KeBugCheckEx(CONFIG_INITIALIZATION_FAILED
, 2, 1, 0, 0);
1910 /* Loop the driver list */
1911 for (i
= 0, NextEntry
= DriverList
.Flink
;
1912 NextEntry
!= &DriverList
;
1913 i
++, NextEntry
= NextEntry
->Flink
)
1916 DriverEntry
= CONTAINING_RECORD(NextEntry
, BOOT_DRIVER_LIST_ENTRY
, Link
);
1918 /* Allocate the path for the caller and duplicate the registry path */
1919 ServicePath
[i
] = ExAllocatePool(NonPagedPool
, sizeof(UNICODE_STRING
));
1920 RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
,
1921 &DriverEntry
->RegistryPath
,
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 representation,
2178 // 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
,
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
,
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
,
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
,
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");
2298 swprintf(Buffer
, L
"%s %s",
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
);