- RTL_QUERY_REGISTRY_TABLE QueryTable[3];
- ULONG ServiceStart;
- UNICODE_STRING ServiceImagePath, CCSName;
- NTSTATUS Status;
- HANDLE CCSKey, ServiceKey;
- PVOID BaseAddress;
-
- DPRINT("IopLoadServiceModule(%wZ, 0x%p)\n", ServiceName, ModuleObject);
-
- /* FIXME: This check may be removed once the bug is fixed */
- if (ServiceName->Buffer == NULL)
- {
- DPRINT1("If you see this, please report to Fireball or hpoussin!\n");
- return STATUS_UNSUCCESSFUL;
- }
-
- if (ExpInTextModeSetup)
- {
- /* We have no registry, but luckily we know where all the drivers are */
-
- /* ServiceStart < 4 is all that matters */
- ServiceStart = 0;
-
- /* IopNormalizeImagePath will do all of the work for us if we give it an empty string */
- ServiceImagePath.Length = ServiceImagePath.MaximumLength = 0;
- ServiceImagePath.Buffer = NULL;
- }
- else
- {
- /* Open CurrentControlSet */
- RtlInitUnicodeString(&CCSName,
- L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services");
- Status = IopOpenRegistryKeyEx(&CCSKey, NULL, &CCSName, KEY_READ);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
- return Status;
- }
-
- /* Open service key */
- Status = IopOpenRegistryKeyEx(&ServiceKey, CCSKey, ServiceName, KEY_READ);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
- ZwClose(CCSKey);
- return Status;
- }
-
- /*
- * Get information about the service.
- */
-
- RtlZeroMemory(QueryTable, sizeof(QueryTable));
-
- RtlInitUnicodeString(&ServiceImagePath, NULL);
-
- QueryTable[0].Name = L"Start";
- QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
- QueryTable[0].EntryContext = &ServiceStart;
-
- QueryTable[1].Name = L"ImagePath";
- QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
- QueryTable[1].EntryContext = &ServiceImagePath;
-
- Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
- (PWSTR)ServiceKey, QueryTable, NULL, NULL);
-
- ZwClose(ServiceKey);
- ZwClose(CCSKey);
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("RtlQueryRegistryValues() failed (Status %x)\n", Status);
- return Status;
- }
- }
-
- /*
- * Normalize the image path for all later processing.
- */
-
- Status = IopNormalizeImagePath(&ServiceImagePath, ServiceName);
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
- return Status;
- }
-
- /*
- * Case for disabled drivers
- */
-
- if (ServiceStart >= 4)
- {
- /* We can't load this */
- Status = STATUS_DRIVER_UNABLE_TO_LOAD;
- }
- else
- {
- DPRINT("Loading module from %wZ\n", &ServiceImagePath);
- Status = MmLoadSystemImage(&ServiceImagePath, NULL, NULL, 0, (PVOID)ModuleObject, &BaseAddress);
- if (NT_SUCCESS(Status))
- {
- IopDisplayLoadingMessage(ServiceName);
- }
- }
-
- ExFreePool(ServiceImagePath.Buffer);
-
- /*
- * Now check if the module was loaded successfully.
- */
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Module loading failed (Status %x)\n", Status);
- }
-
- DPRINT("Module loading (Status %x)\n", Status);
-
- return Status;
+ RTL_QUERY_REGISTRY_TABLE QueryTable[3];
+ ULONG ServiceStart;
+ UNICODE_STRING ServiceImagePath, CCSName;
+ NTSTATUS Status;
+ HANDLE CCSKey, ServiceKey;
+ PVOID BaseAddress;
+
+ ASSERT(ExIsResourceAcquiredExclusiveLite(&IopDriverLoadResource));
+ ASSERT(ServiceName->Length);
+ DPRINT("IopLoadServiceModule(%wZ, 0x%p)\n", ServiceName, ModuleObject);
+
+ if (ExpInTextModeSetup)
+ {
+ /* We have no registry, but luckily we know where all the drivers are */
+
+ /* ServiceStart < 4 is all that matters */
+ ServiceStart = 0;
+
+ /* IopNormalizeImagePath will do all of the work for us if we give it an empty string */
+ RtlInitEmptyUnicodeString(&ServiceImagePath, NULL, 0);
+ }
+ else
+ {
+ /* Open CurrentControlSet */
+ RtlInitUnicodeString(&CCSName,
+ L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services");
+ Status = IopOpenRegistryKeyEx(&CCSKey, NULL, &CCSName, KEY_READ);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with Status %08X\n",
+ &CCSName, Status);
+ return Status;
+ }
+
+ /* Open service key */
+ Status = IopOpenRegistryKeyEx(&ServiceKey, CCSKey, ServiceName, KEY_READ);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with Status %08X\n",
+ ServiceName, Status);
+ ZwClose(CCSKey);
+ return Status;
+ }
+
+ /*
+ * Get information about the service.
+ */
+ RtlZeroMemory(QueryTable, sizeof(QueryTable));
+
+ RtlInitUnicodeString(&ServiceImagePath, NULL);
+
+ QueryTable[0].Name = L"Start";
+ QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
+ QueryTable[0].EntryContext = &ServiceStart;
+
+ QueryTable[1].Name = L"ImagePath";
+ QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
+ QueryTable[1].EntryContext = &ServiceImagePath;
+
+ Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
+ (PWSTR)ServiceKey,
+ QueryTable,
+ NULL,
+ NULL);
+
+ ZwClose(ServiceKey);
+ ZwClose(CCSKey);
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("RtlQueryRegistryValues() failed (Status %x)\n", Status);
+ return Status;
+ }
+ }
+
+ /*
+ * Normalize the image path for all later processing.
+ */
+ Status = IopNormalizeImagePath(&ServiceImagePath, ServiceName);
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
+ return Status;
+ }
+
+ /*
+ * Case for disabled drivers
+ */
+ if (ServiceStart >= 4)
+ {
+ /* We can't load this */
+ Status = STATUS_DRIVER_UNABLE_TO_LOAD;
+ }
+ else
+ {
+ DPRINT("Loading module from %wZ\n", &ServiceImagePath);
+ Status = MmLoadSystemImage(&ServiceImagePath, NULL, NULL, 0, (PVOID)ModuleObject, &BaseAddress);
+ if (NT_SUCCESS(Status))
+ {
+ IopDisplayLoadingMessage(ServiceName);
+ }
+ }
+
+ ExFreePool(ServiceImagePath.Buffer);
+
+ /*
+ * Now check if the module was loaded successfully.
+ */
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Module loading failed (Status %x)\n", Status);
+ }
+
+ DPRINT("Module loading (Status %x)\n", Status);
+
+ return Status;