return STATUS_SUCCESS;
}
+INIT_FUNCTION
NTSTATUS
NTAPI
-INIT_FUNCTION
CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
+ NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
+ HANDLE KeyHandle;
UNICODE_STRING KeyName, ValueName = { 0, 0, NULL };
- HANDLE KeyHandle = NULL;
- NTSTATUS Status;
+
ASSERT(LoaderBlock != NULL);
/* Setup attributes for loader options */
NULL,
NULL);
Status = NtOpenKey(&KeyHandle, KEY_WRITE, &ObjectAttributes);
- if (!NT_SUCCESS(Status)) goto Quickie;
+ if (!NT_SUCCESS(Status))
+ return Status;
- /* Key opened, now write to the key */
+ /* Setup the value for the system start options */
RtlInitUnicodeString(&KeyName, L"SystemStartOptions");
Status = NtSetValueKey(KeyHandle,
&KeyName,
REG_SZ,
CmpLoadOptions.Buffer,
CmpLoadOptions.Length);
- if (!NT_SUCCESS(Status)) goto Quickie;
+ if (!NT_SUCCESS(Status))
+ goto Quit;
- /* Setup value name for system boot device in ARC format */
+ /* Setup the value for the system boot device in ARC format */
RtlInitUnicodeString(&KeyName, L"SystemBootDevice");
RtlCreateUnicodeStringFromAsciiz(&ValueName, LoaderBlock->ArcBootDeviceName);
Status = NtSetValueKey(KeyHandle,
ValueName.Buffer,
ValueName.Length);
-Quickie:
- /* Free the buffers */
+ /* Free the temporary string */
RtlFreeUnicodeString(&ValueName);
+Quit:
/* Close the key and return */
- if (KeyHandle) NtClose(KeyHandle);
-
- /* Return the status */
- return (ExpInTextModeSetup ? STATUS_SUCCESS : Status);
+ NtClose(KeyHandle);
+ return Status;
}
+INIT_FUNCTION
static
NTSTATUS
-INIT_FUNCTION
CmpCreateHardwareProfile(HANDLE ControlSetHandle)
{
OBJECT_ATTRIBUTES ObjectAttributes;
return Status;
}
+INIT_FUNCTION
NTSTATUS
NTAPI
-INIT_FUNCTION
CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
UNICODE_STRING ConfigName = RTL_CONSTANT_STRING(L"Control\\IDConfigDB");
CHAR ValueInfoBuffer[128];
PKEY_VALUE_FULL_INFORMATION ValueInfo;
WCHAR UnicodeBuffer[128];
- HANDLE SelectHandle, KeyHandle, ConfigHandle = NULL, ProfileHandle = NULL;
+ HANDLE SelectHandle = NULL;
+ HANDLE KeyHandle = NULL;
+ HANDLE ConfigHandle = NULL;
+ HANDLE ProfileHandle = NULL;
HANDLE ParentHandle = NULL;
ULONG ControlSet, HwProfile;
NTSTATUS Status;
PLOADER_PARAMETER_EXTENSION LoaderExtension;
PAGED_CODE();
- /* Open the select key */
- InitializeObjectAttributes(&ObjectAttributes,
- &SelectName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
- Status = NtOpenKey(&SelectHandle, KEY_READ, &ObjectAttributes);
- if (!NT_SUCCESS(Status))
+ /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
+ if (LoaderBlock->RegistryBase == NULL)
{
- /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
- if (!LoaderBlock->RegistryBase)
+ /* Build the ControlSet001 key */
+ RtlInitUnicodeString(&KeyName,
+ L"\\Registry\\Machine\\System\\ControlSet001");
+ InitializeObjectAttributes(&ObjectAttributes,
+ &KeyName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+ Status = NtCreateKey(&KeyHandle,
+ KEY_ALL_ACCESS,
+ &ObjectAttributes,
+ 0,
+ NULL,
+ 0,
+ &Disposition);
+ if (!NT_SUCCESS(Status))
{
- /* Build the ControlSet001 key */
- RtlInitUnicodeString(&KeyName,
- L"\\Registry\\Machine\\System\\ControlSet001");
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
- Status = NtCreateKey(&KeyHandle,
- KEY_ALL_ACCESS,
- &ObjectAttributes,
- 0,
- NULL,
- 0,
- &Disposition);
- if (!NT_SUCCESS(Status)) return Status;
-
- /* Create the Hardware Profile keys */
- Status = CmpCreateHardwareProfile(KeyHandle);
- if (!NT_SUCCESS(Status))
- return Status;
-
- /* Don't need the handle */
- ZwClose(KeyHandle);
+ DPRINT1("Failed to create ControlSet001 key: 0x%lx\n", Status);
+ goto Cleanup;
+ }
- /* Use hard-coded setting */
- ControlSet = 1;
- goto UseSet;
+ /* Create the Hardware Profile keys */
+ Status = CmpCreateHardwareProfile(KeyHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to create Hardware profile keys: 0x%lx\n", Status);
+ goto Cleanup;
}
- /* Fail for real boots */
- return Status;
+ /* Use hard-coded setting */
+ ControlSet = 1;
}
+ else
+ {
+ /* Open the select key */
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SelectName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+ Status = NtOpenKey(&SelectHandle, KEY_READ, &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to open select key: 0x%lx\n", Status);
+ goto Cleanup;
+ }
- /* Open the current value */
- RtlInitUnicodeString(&KeyName, L"Current");
- Status = NtQueryValueKey(SelectHandle,
- &KeyName,
- KeyValueFullInformation,
- ValueInfoBuffer,
- sizeof(ValueInfoBuffer),
- &ResultLength);
- NtClose(SelectHandle);
- if (!NT_SUCCESS(Status)) return Status;
+ /* Open the current value */
+ RtlInitUnicodeString(&KeyName, L"Current");
+ Status = NtQueryValueKey(SelectHandle,
+ &KeyName,
+ KeyValueFullInformation,
+ ValueInfoBuffer,
+ sizeof(ValueInfoBuffer),
+ &ResultLength);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to open the Current value: 0x%lx\n", Status);
+ goto Cleanup;
+ }
- /* Get the actual value pointer, and get the control set ID */
- ValueInfo = (PKEY_VALUE_FULL_INFORMATION)ValueInfoBuffer;
- ControlSet = *(PULONG)((PUCHAR)ValueInfo + ValueInfo->DataOffset);
+ /* Get the actual value pointer, and get the control set ID */
+ ValueInfo = (PKEY_VALUE_FULL_INFORMATION)ValueInfoBuffer;
+ ControlSet = *(PULONG)((PUCHAR)ValueInfo + ValueInfo->DataOffset);
+ }
/* Create the current control set key */
-UseSet:
RtlInitUnicodeString(&KeyName,
L"\\Registry\\Machine\\System\\CurrentControlSet");
InitializeObjectAttributes(&ObjectAttributes,
NULL,
REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK,
&Disposition);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ goto Cleanup;
/* Sanity check */
ASSERT(Disposition == REG_CREATED_NEW_KEY);
/* Initialize the target link name */
- RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
- L"\\Registry\\Machine\\System\\ControlSet%03ld",
- ControlSet);
+ Status = RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
+ L"\\Registry\\Machine\\System\\ControlSet%03ld",
+ ControlSet);
+ if (!NT_SUCCESS(Status))
+ goto Cleanup;
+
RtlInitUnicodeString(&KeyName, UnicodeBuffer);
/* Set the value */
REG_LINK,
KeyName.Buffer,
KeyName.Length);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ goto Cleanup;
/* Get the configuration database key */
InitializeObjectAttributes(&ObjectAttributes,
KeyHandle,
NULL);
Status = NtOpenKey(&ConfigHandle, KEY_READ, &ObjectAttributes);
- NtClose(KeyHandle);
/* Check if we don't have one */
if (!NT_SUCCESS(Status))
{
/* Cleanup and exit */
- ConfigHandle = NULL;
+ Status = STATUS_SUCCESS;
goto Cleanup;
}
/* ReactOS Hack: Hard-code current to 001 for SetupLdr */
- if (!LoaderBlock->RegistryBase)
+ if (LoaderBlock->RegistryBase == NULL)
{
HwProfile = 0;
}
ValueInfo = (PKEY_VALUE_FULL_INFORMATION)ValueInfoBuffer;
/* Check if we failed or got a non DWORD-value */
- if (!(NT_SUCCESS(Status)) || (ValueInfo->Type != REG_DWORD)) goto Cleanup;
+ if (!(NT_SUCCESS(Status)) || (ValueInfo->Type != REG_DWORD))
+ {
+ Status = STATUS_SUCCESS;
+ goto Cleanup;
+ }
/* Get the hadware profile */
HwProfile = *(PULONG)((PUCHAR)ValueInfo + ValueInfo->DataOffset);
if (!NT_SUCCESS(Status))
{
/* Exit and clean up */
- ParentHandle = NULL;
+ Status = STATUS_SUCCESS;
goto Cleanup;
}
if (!NT_SUCCESS (Status))
{
/* Cleanup and exit */
- ProfileHandle = 0;
+ Status = STATUS_SUCCESS;
goto Cleanup;
}
REG_LINK,
KeyName.Buffer,
KeyName.Length);
- NtClose(KeyHandle);
}
- /* Close every opened handle */
+ Status = STATUS_SUCCESS;
+
Cleanup:
+ /* Close every opened handle */
+ if (SelectHandle) NtClose(SelectHandle);
+ if (KeyHandle) NtClose(KeyHandle);
if (ConfigHandle) NtClose(ConfigHandle);
if (ProfileHandle) NtClose(ProfileHandle);
if (ParentHandle) NtClose(ParentHandle);
DPRINT("CmpCreateControlSet() done\n");
-
- /* Return success */
- return STATUS_SUCCESS;
+ return Status;
}
NTSTATUS
return STATUS_SUCCESS;
}
+INIT_FUNCTION
BOOLEAN
NTAPI
-INIT_FUNCTION
CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
+ static const UNICODE_STRING HiveName = RTL_CONSTANT_STRING(L"SYSTEM");
PVOID HiveBase;
ANSI_STRING LoadString;
PVOID Buffer;
ULONG Length;
NTSTATUS Status;
- BOOLEAN Allocate;
UNICODE_STRING KeyName;
PCMHIVE SystemHive = NULL;
- UNICODE_STRING HiveName = RTL_CONSTANT_STRING(L"SYSTEM");
PSECURITY_DESCRIPTOR SecurityDescriptor;
+ BOOLEAN Success;
+
PAGED_CODE();
/* Setup the ansi string */
RtlInitEmptyUnicodeString(&CmpLoadOptions, Buffer, (USHORT)Length);
/* Add the load options and null-terminate */
- RtlAnsiStringToUnicodeString(&CmpLoadOptions, &LoadString, FALSE);
+ Status = RtlAnsiStringToUnicodeString(&CmpLoadOptions, &LoadString, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ return FALSE;
+ }
+
CmpLoadOptions.Buffer[LoadString.Length] = UNICODE_NULL;
CmpLoadOptions.Length += sizeof(WCHAR);
/* Get the System Hive base address */
HiveBase = LoaderBlock->RegistryBase;
- if (HiveBase)
- {
- /* Import it */
- Status = CmpInitializeHive(&SystemHive,
- HINIT_MEMORY,
- HIVE_NOLAZYFLUSH,
- HFILE_TYPE_LOG,
- HiveBase,
- NULL,
- NULL,
- NULL,
- &HiveName,
- 2);
- if (!NT_SUCCESS(Status)) return FALSE;
-
- /* Set the hive filename */
- RtlCreateUnicodeString(&SystemHive->FileFullPath,
- L"\\SystemRoot\\System32\\Config\\SYSTEM");
-
- /* We imported, no need to create a new hive */
- Allocate = FALSE;
- /* Manually set the hive as volatile, if in Live CD mode */
- if (CmpShareSystemHives) SystemHive->Hive.HiveFlags = HIVE_VOLATILE;
- }
- else
+ Status = CmpInitializeHive(&SystemHive,
+ HiveBase ? HINIT_MEMORY : HINIT_CREATE,
+ HIVE_NOLAZYFLUSH,
+ HFILE_TYPE_LOG,
+ HiveBase,
+ NULL,
+ NULL,
+ NULL,
+ &HiveName,
+ HiveBase ? 2 : 0);
+ if (!NT_SUCCESS(Status))
{
- /* Create it */
- Status = CmpInitializeHive(&SystemHive,
- HINIT_CREATE,
- HIVE_NOLAZYFLUSH,
- HFILE_TYPE_LOG,
- NULL,
- NULL,
- NULL,
- NULL,
- &HiveName,
- 0);
- if (!NT_SUCCESS(Status)) return FALSE;
+ return FALSE;
+ }
- /* Set the hive filename */
- RtlCreateUnicodeString(&SystemHive->FileFullPath,
- L"\\SystemRoot\\System32\\Config\\SYSTEM");
+ /* Set the hive filename */
+ Success = RtlCreateUnicodeString(&SystemHive->FileFullPath,
+ L"\\SystemRoot\\System32\\Config\\SYSTEM");
+ if (!Success)
+ {
+ return FALSE;
+ }
- /* Tell CmpLinkHiveToMaster to allocate a hive */
- Allocate = TRUE;
+ /* Manually set the hive as volatile, if in Live CD mode */
+ if (HiveBase && CmpShareSystemHives)
+ {
+ SystemHive->Hive.HiveFlags = HIVE_VOLATILE;
}
/* Save the boot type */
SecurityDescriptor = CmpHiveRootSecurityDescriptor();
/* Attach it to the system key */
+ /* Let CmpLinkHiveToMaster allocate a new hive if we got none from the LoaderBlock. */
RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\SYSTEM");
Status = CmpLinkHiveToMaster(&KeyName,
NULL,
SystemHive,
- Allocate,
+ !HiveBase,
SecurityDescriptor);
/* Free the security descriptor */
return TRUE;
}
+INIT_FUNCTION
NTSTATUS
NTAPI
-INIT_FUNCTION
CmpCreateObjectTypes(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
return ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &CmpKeyObjectType);
}
+INIT_FUNCTION
BOOLEAN
NTAPI
-INIT_FUNCTION
CmpCreateRootNode(IN PHHIVE Hive,
IN PCWSTR Name,
OUT PHCELL_INDEX Index)
return TRUE;
}
+INIT_FUNCTION
BOOLEAN
NTAPI
-INIT_FUNCTION
CmpCreateRegistryRoot(VOID)
{
UNICODE_STRING KeyName;
return TRUE;
}
-NTSTATUS
-NTAPI
+static NTSTATUS
CmpGetRegistryPath(OUT PWCHAR ConfigPath)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- NTSTATUS Status;
- HANDLE KeyHandle;
- PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
- UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE");
- UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath");
- ULONG BufferSize, ResultSize;
+ /* Just use default path */
+ wcscpy(ConfigPath, L"\\SystemRoot");
/* Check if we are booted in setup */
- if (ExpInTextModeSetup)
+ if (!ExpInTextModeSetup)
{
- DPRINT1("CmpGetRegistryPath TextMode setup HACK!!\n");
-
- /* Setup the object attributes */
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
- NULL,
- NULL);
- /* Open the key */
- Status = ZwOpenKey(&KeyHandle,
- KEY_ALL_ACCESS,
- &ObjectAttributes);
- if (!NT_SUCCESS(Status)) return Status;
-
- /* Allocate the buffer */
- BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096;
- ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_CM);
- if (!ValueInfo)
- {
- /* Fail */
- ZwClose(KeyHandle);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- /* Query the value */
- Status = ZwQueryValueKey(KeyHandle,
- &ValueName,
- KeyValuePartialInformation,
- ValueInfo,
- BufferSize,
- &ResultSize);
- ZwClose(KeyHandle);
- if (!NT_SUCCESS(Status))
- {
- /* Fail */
- ExFreePoolWithTag(ValueInfo, TAG_CM);
- return Status;
- }
-
- /* Copy the config path and null-terminate it */
- RtlCopyMemory(ConfigPath,
- ValueInfo->Data,
- ValueInfo->DataLength);
- ConfigPath[ValueInfo->DataLength / sizeof(WCHAR)] = UNICODE_NULL;
- ExFreePoolWithTag(ValueInfo, TAG_CM);
+ /* Add registry path */
+#if 0
+ ResultSize = wcslen(ConfigPath);
+ if (ResultSize && ConfigPath[ResultSize - 1] == L'\\')
+ ConfigPath[ResultSize - 1] = UNICODE_NULL;
+#endif
+ wcscat(ConfigPath, L"\\System32\\Config\\");
}
else
{
- /* Just use default path */
- wcscpy(ConfigPath, L"\\SystemRoot");
+ wcscat(ConfigPath, L"\\");
}
- /* Add registry path */
- wcscat(ConfigPath, L"\\System32\\Config\\");
-
DPRINT1("CmpGetRegistryPath: ConfigPath = '%S'\n", ConfigPath);
/* Done */
return STATUS_SUCCESS;
}
+_Function_class_(KSTART_ROUTINE)
VOID
NTAPI
CmpLoadHiveThread(IN PVOID StartContext)
&CmpMachineHiveList[i].Allocate,
0);
if (!(NT_SUCCESS(Status)) ||
- (!(CmHive->FileHandles[HFILE_TYPE_LOG]) && !(CmpMiniNTBoot))) // HACK
+ (!(CmpShareSystemHives) && !(CmHive->FileHandles[HFILE_TYPE_LOG])))
{
- /* We failed or couldn't get a log file, raise a hard error */
+ /*
+ * We failed, or could not get a log file (unless
+ * the hive is shared), raise a hard error.
+ */
ErrorParameters = &FileName;
NtRaiseHardError(STATUS_CANNOT_LOAD_REGISTRY_FILE,
1,
Length = CmHive->Hive.Storage[Stable].Length + HBLOCK_SIZE;
/* Check if the cluster size doesn't match */
- if (CmHive->Hive.Cluster != ClusterSize) ASSERT(FALSE);
+ if (CmHive->Hive.Cluster != ClusterSize)
+ {
+ DPRINT1("FIXME: Support for CmHive->Hive.Cluster (%lu) != ClusterSize (%lu) is unimplemented!\n",
+ CmHive->Hive.Cluster, ClusterSize);
+ }
/* Set the file size */
- DPRINT("FIXME: Should set file size: %lx\n", Length);
+ DPRINT("FIXME: Should set file size: %lu\n", Length);
//if (!CmpFileSetSize((PHHIVE)CmHive, HFILE_TYPE_PRIMARY, Length, Length))
- {
+ //{
/* This shouldn't fail */
//ASSERT(FALSE);
- }
+ //}
/* Another thing we don't support is NTLDR-recovery */
if (CmHive->Hive.BaseBlock->BootRecover) ASSERT(FALSE);
VOID
NTAPI
-CmpInitializeHiveList(IN USHORT Flag)
+CmpInitializeHiveList(VOID)
{
WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH], ConfigPath[MAX_PATH];
UNICODE_STRING TempName, FileName, RegName;
/* Loop every hive we care about */
for (i = 0; i < CM_NUMBER_OF_MACHINE_HIVES; i++)
{
- /* Make sure the list is setup */
+ /* Make sure the list is set up */
ASSERT(CmpMachineHiveList[i].Name != NULL);
+ /* Load the hive as volatile, if in LiveCD mode */
+ if (CmpShareSystemHives)
+ CmpMachineHiveList[i].HHiveFlags |= HIVE_VOLATILE;
+
/* Create a thread to handle this hive */
Status = PsCreateSystemThread(&Thread,
THREAD_ALL_ACCESS,
CmpNoVolatileCreates = TRUE;
}
+INIT_FUNCTION
BOOLEAN
NTAPI
-INIT_FUNCTION
CmInitSystem1(VOID)
{
OBJECT_ATTRIBUTES ObjectAttributes;
return TRUE;
}
+INIT_FUNCTION
VOID
NTAPI
-INIT_FUNCTION
CmpFreeDriverList(IN PHHIVE Hive,
IN PLIST_ENTRY DriverList)
{
}
}
+INIT_FUNCTION
PUNICODE_STRING*
NTAPI
-INIT_FUNCTION
CmGetSystemDriverList(VOID)
{
LIST_ENTRY DriverList;
/* Get the entry */
DriverEntry = CONTAINING_RECORD(NextEntry, BOOT_DRIVER_LIST_ENTRY, Link);
- /* Allocate the path for the caller and duplicate the registry path */
+ /* Allocate the path for the caller */
ServicePath[i] = ExAllocatePool(NonPagedPool, sizeof(UNICODE_STRING));
- RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
- &DriverEntry->RegistryPath,
- ServicePath[i]);
+ if (!ServicePath[i])
+ {
+ KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 2, 1, 0, 0);
+ }
+
+ /* Duplicate the registry path */
+ Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE,
+ &DriverEntry->RegistryPath,
+ ServicePath[i]);
+ if (!NT_SUCCESS(Status))
+ {
+ KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 2, 1, 0, 0);
+ }
}
/* Terminate the list */