switch (stack->Parameters.QueryId.IdType) {
case BusQueryDeviceID:
+
+ /* This is a REG_SZ value */
+
if (DeviceData->AcpiHandle)
{
acpi_bus_get_device(DeviceData->AcpiHandle, &Device);
L"ACPI\\FixedButton");
}
- temp[++length] = UNICODE_NULL;
+ temp[length++] = UNICODE_NULL;
- buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof(WCHAR), 'IPCA');
+ NT_ASSERT(length * sizeof(WCHAR) <= sizeof(temp));
+
+ buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof(WCHAR), 'IPCA');
if (!buffer) {
status = STATUS_INSUFFICIENT_RESOURCES;
break;
case BusQueryInstanceID:
+
+ /* This is a REG_SZ value */
+
/* See comment in BusQueryDeviceID case */
if(DeviceData->AcpiHandle)
{
length = swprintf(temp, L"%ls", L"0000");
}
else
+ {
/* FIXME: Generate unique id! */
length = swprintf(temp, L"%ls", L"0000");
+ }
+
+ temp[length++] = UNICODE_NULL;
- temp[++length] = UNICODE_NULL;
+ NT_ASSERT(length * sizeof(WCHAR) <= sizeof(temp));
buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof (WCHAR), 'IPCA');
if (!buffer) {
break;
case BusQueryHardwareIDs:
+
+ /* This is a REG_MULTI_SZ value */
length = 0;
/* See comment in BusQueryDeviceID case */
if (strcmp(Device->pnp.hardware_id, "Processor") == 0)
{
-/*
- length += swprintf(&temp[length],
- L"ACPI\\%s - %s",
- ProcessorVendorIdentifier, ProcessorIdentifier);
- length++;
-
- length += swprintf(&temp[length],
- L"*%s - %s",
- ProcessorVendorIdentifier, ProcessorIdentifier);
- length++;
-*/
length = ProcessorHardwareIds.Length / sizeof(WCHAR);
src = ProcessorHardwareIds.Buffer;
}
length += swprintf(&temp[length],
L"ACPI\\%hs",
Device->pnp.hardware_id);
- length++;
+ temp[length++] = UNICODE_NULL;
length += swprintf(&temp[length],
L"*%hs",
Device->pnp.hardware_id);
- length++;
-
- temp[length] = UNICODE_NULL;
-
- length++;
-
- temp[length] = UNICODE_NULL;
- src = temp;
-
+ temp[length++] = UNICODE_NULL;
+ temp[length++] = UNICODE_NULL;
+ src = temp;
}
- }
- else
- {
+ }
+ else
+ {
length += swprintf(&temp[length],
L"ACPI\\FixedButton");
- length++;
+ temp[length++] = UNICODE_NULL;
length += swprintf(&temp[length],
L"*FixedButton");
- length++;
-
- temp[length] = UNICODE_NULL;
-
- length++;
-
- temp[length] = UNICODE_NULL;
- src = temp;
- }
+ temp[length++] = UNICODE_NULL;
+ temp[length++] = UNICODE_NULL;
+ src = temp;
+ }
+ NT_ASSERT(length * sizeof(WCHAR) <= sizeof(temp));
buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof(WCHAR), 'IPCA');
break;
case BusQueryCompatibleIDs:
+
+ /* This is a REG_MULTI_SZ value */
length = 0;
status = STATUS_NOT_SUPPORTED;
length += swprintf(&temp[length],
L"ACPI\\%hs",
Device->pnp.hardware_id);
- length++;
+ temp[length++] = UNICODE_NULL;
length += swprintf(&temp[length],
L"*%hs",
Device->pnp.hardware_id);
- length++;
-
- temp[length] = UNICODE_NULL;
-
- length++;
+ temp[length++] = UNICODE_NULL;
+ temp[length++] = UNICODE_NULL;
- temp[length] = UNICODE_NULL;
+ NT_ASSERT(length * sizeof(WCHAR) <= sizeof(temp));
buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof(WCHAR), 'IPCA');
if (!buffer)
ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
ResourceDescriptor->u.Port.Start.QuadPart = io_data->Address;
ResourceDescriptor->u.Port.Length = io_data->AddressLength;
-
+
ResourceDescriptor++;
break;
}
case ACPI_CACHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
case ACPI_WRITE_COMBINING_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
case ACPI_PREFETCHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
- }
+ }
ResourceDescriptor->u.Memory.Start.QuadPart = addr64_data->Minimum;
ResourceDescriptor->u.Memory.Length = addr64_data->AddressLength;
}
case ACPI_CACHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
case ACPI_WRITE_COMBINING_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
case ACPI_PREFETCHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
- }
+ }
ResourceDescriptor->u.Memory.Start.QuadPart = addr64_data->Minimum;
ResourceDescriptor->u.Memory.Length = addr64_data->AddressLength;
}
ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
ResourceDescriptor->u.Memory.Start.QuadPart = memfixed32_data->Address;
ResourceDescriptor->u.Memory.Length = memfixed32_data->AddressLength;
-
+
ResourceDescriptor++;
break;
}
RequirementDescriptor->u.Port.Alignment = 1;
RequirementDescriptor->u.Port.MinimumAddress.QuadPart = io_data->Address;
RequirementDescriptor->u.Port.MaximumAddress.QuadPart = io_data->Address + io_data->AddressLength - 1;
-
+
RequirementDescriptor++;
break;
}
case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
- }
+ }
RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr64_data->Minimum;
RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr64_data->Maximum + addr64_data->AddressLength - 1;
RequirementDescriptor->u.Memory.Length = addr64_data->AddressLength;
case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
- }
+ }
RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr64_data->Minimum;
RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr64_data->Maximum + addr64_data->AddressLength - 1;
RequirementDescriptor->u.Memory.Length = addr64_data->AddressLength;
RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = fixedmem32_data->Address;
RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = fixedmem32_data->Address + fixedmem32_data->AddressLength - 1;
RequirementDescriptor->u.Memory.Length = fixedmem32_data->AddressLength;
-
+
RequirementDescriptor++;
break;
}
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
-
+
NTSTATUS
NTAPI
ULONG BufferLength = 0;
NTSTATUS Status;
- RtlInitUnicodeString(&Name,
- ValueName);
+ RtlInitUnicodeString(&Name, ValueName);
if (DataLength != NULL)
BufferLength = *DataLength;
- BufferLength += FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
+ /* Check if the caller provided a valid buffer */
+ if ((Data != NULL) && (BufferLength != 0))
+ {
+ BufferLength += FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
- /* Allocate memory for the value */
- ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferLength, 'IPCA');
- if (ValueInfo == NULL)
- return STATUS_NO_MEMORY;
+ /* Allocate memory for the value */
+ ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferLength, 'IPCA');
+ if (ValueInfo == NULL)
+ return STATUS_NO_MEMORY;
+ }
+ else
+ {
+ /* Caller didn't provide a valid buffer, assume he wants the size only */
+ ValueInfo = NULL;
+ BufferLength = 0;
+ }
/* Query the value */
Status = ZwQueryValueKey(KeyHandle,
ValueInfo,
BufferLength,
&BufferLength);
- if ((NT_SUCCESS(Status)) || (Status == STATUS_BUFFER_OVERFLOW))
+
+ if (DataLength != NULL)
+ *DataLength = BufferLength;
+
+ /* Check if we have the size only */
+ if (ValueInfo == NULL)
{
- if (Type != NULL)
- *Type = ValueInfo->Type;
+ /* Check for unexpected status */
+ if ((Status != STATUS_BUFFER_OVERFLOW) &&
+ (Status != STATUS_BUFFER_TOO_SMALL))
+ {
+ return Status;
+ }
- if (DataLength != NULL)
- *DataLength = ValueInfo->DataLength;
+ /* All is well */
+ Status = STATUS_SUCCESS;
}
-
- /* Check if the caller wanted data back, and we got it */
- if ((NT_SUCCESS(Status)) && (Data != NULL))
+ /* Otherwise the caller wanted data back, check if we got it */
+ else if (NT_SUCCESS(Status))
{
+ if (Type != NULL)
+ *Type = ValueInfo->Type;
+
/* Copy it */
- RtlMoveMemory(Data,
- ValueInfo->Data,
- ValueInfo->DataLength);
+ RtlMoveMemory(Data, ValueInfo->Data, ValueInfo->DataLength);
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \0 */
- if (((ValueInfo->Type == REG_SZ) || (ValueInfo->Type == REG_EXPAND_SZ) || (ValueInfo->Type == REG_MULTI_SZ)) &&
+ if (((ValueInfo->Type == REG_SZ) ||
+ (ValueInfo->Type == REG_EXPAND_SZ) ||
+ (ValueInfo->Type == REG_MULTI_SZ)) &&
(ValueInfo->DataLength <= *DataLength - sizeof(WCHAR)))
{
WCHAR *ptr = (WCHAR *)((ULONG_PTR)Data + ValueInfo->DataLength);
}
/* Free the memory and return status */
- ExFreePoolWithTag(ValueInfo, 'IPCA');
-
- if ((Data == NULL) && (Status == STATUS_BUFFER_OVERFLOW))
- Status = STATUS_SUCCESS;
+ if (ValueInfo != NULL)
+ {
+ ExFreePoolWithTag(ValueInfo, 'IPCA');
+ }
return Status;
}
LPWSTR HardwareIdsBuffer = NULL;
HANDLE ProcessorHandle = NULL;
ULONG Length, Level1Length = 0, Level2Length = 0, Level3Length = 0;
- ULONG HardwareIdsLength = 0;
+ SIZE_T HardwareIdsLength = 0;
+ SIZE_T VendorIdentifierLength;
ULONG i;
PWCHAR Ptr;
NTSTATUS Status;
DPRINT1("GetProcessorInformation()\n");
+ /* Open the key for CPU 0 */
Status = AcpiRegOpenKey(NULL,
L"\\Registry\\Machine\\Hardware\\Description\\System\\CentralProcessor\\0",
KEY_READ,
if (!NT_SUCCESS(Status))
goto done;
- AcpiRegQueryValue(ProcessorHandle,
- L"Identifier",
- NULL,
- NULL,
- &Length);
-
- if (Length != 0)
- {
- ProcessorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IPCA');
- if (ProcessorIdentifier == NULL)
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto done;
- }
+ /* Query the processor identifier length */
+ Status = AcpiRegQueryValue(ProcessorHandle,
+ L"Identifier",
+ NULL,
+ NULL,
+ &Length);
+ if (!NT_SUCCESS(Status))
+ goto done;
- Status = AcpiRegQueryValue(ProcessorHandle,
- L"Identifier",
- NULL,
- ProcessorIdentifier,
- &Length);
- if (!NT_SUCCESS(Status))
- goto done;
+ /* Remember the length as fallback for level 1-3 length */
+ Level1Length = Level2Length = Level3Length = Length;
- Length = 0;
+ /* Allocate a buffer large enough to be zero terminated */
+ Length += sizeof(UNICODE_NULL);
+ ProcessorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IPCA');
+ if (ProcessorIdentifier == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto done;
}
- AcpiRegQueryValue(ProcessorHandle,
- L"ProcessorNameString",
- NULL,
- NULL,
- &Length);
-
- if (Length != 0)
- {
- ProcessorNameString = ExAllocatePoolWithTag(PagedPool, Length, 'IPCA');
- if (ProcessorNameString == NULL)
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto done;
- }
+ /* Query the processor identifier string */
+ Status = AcpiRegQueryValue(ProcessorHandle,
+ L"Identifier",
+ NULL,
+ ProcessorIdentifier,
+ &Length);
+ if (!NT_SUCCESS(Status))
+ goto done;
- Status = AcpiRegQueryValue(ProcessorHandle,
- L"ProcessorNameString",
- NULL,
- ProcessorNameString,
- &Length);
- if (!NT_SUCCESS(Status))
- goto done;
+ /* Query the processor name length */
+ Length = 0;
+ Status = AcpiRegQueryValue(ProcessorHandle,
+ L"ProcessorNameString",
+ NULL,
+ NULL,
+ &Length);
+ if (!NT_SUCCESS(Status))
+ goto done;
- Length = 0;
+ /* Allocate a buffer large enough to be zero terminated */
+ Length += sizeof(UNICODE_NULL);
+ ProcessorNameString = ExAllocatePoolWithTag(PagedPool, Length, 'IPCA');
+ if (ProcessorNameString == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto done;
}
- AcpiRegQueryValue(ProcessorHandle,
- L"VendorIdentifier",
- NULL,
- NULL,
- &Length);
-
- if (Length != 0)
- {
- ProcessorVendorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IPCA');
- if (ProcessorVendorIdentifier == NULL)
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto done;
- }
+ /* Query the processor name string */
+ Status = AcpiRegQueryValue(ProcessorHandle,
+ L"ProcessorNameString",
+ NULL,
+ ProcessorNameString,
+ &Length);
+ if (!NT_SUCCESS(Status))
+ goto done;
- Status = AcpiRegQueryValue(ProcessorHandle,
- L"VendorIdentifier",
- NULL,
- ProcessorVendorIdentifier,
- &Length);
- if (!NT_SUCCESS(Status))
- goto done;
+ /* Query the vendor identifier length */
+ Length = 0;
+ Status = AcpiRegQueryValue(ProcessorHandle,
+ L"VendorIdentifier",
+ NULL,
+ NULL,
+ &Length);
+ if (!NT_SUCCESS(Status) || (Length == 0))
+ goto done;
- Length = 0;
+ /* Allocate a buffer large enough to be zero terminated */
+ Length += sizeof(UNICODE_NULL);
+ ProcessorVendorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IPCA');
+ if (ProcessorVendorIdentifier == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto done;
}
+ /* Query the vendor identifier string */
+ Status = AcpiRegQueryValue(ProcessorHandle,
+ L"VendorIdentifier",
+ NULL,
+ ProcessorVendorIdentifier,
+ &Length);
+ if (!NT_SUCCESS(Status))
+ goto done;
+
+ /* Change spaces to underscores */
for (i = 0; i < wcslen(ProcessorIdentifier); i++)
{
if (ProcessorIdentifier[i] == L' ')
Level3Length = (ULONG)(Ptr - ProcessorIdentifier);
}
- HardwareIdsLength = 5 + wcslen(ProcessorVendorIdentifier) + 3 + Level1Length + 1 +
- 1 + wcslen(ProcessorVendorIdentifier) + 3 + Level1Length + 1 +
- 5 + wcslen(ProcessorVendorIdentifier) + 3 + Level2Length + 1 +
- 1 + wcslen(ProcessorVendorIdentifier) + 3 + Level2Length + 1 +
- 5 + wcslen(ProcessorVendorIdentifier) + 3 + Level3Length + 1 +
- 1 + wcslen(ProcessorVendorIdentifier) + 3 + Level3Length + 1 +
- 2;
+ VendorIdentifierLength = (USHORT)wcslen(ProcessorVendorIdentifier);
- HardwareIdsBuffer = ExAllocatePoolWithTag(PagedPool, HardwareIdsLength * sizeof(WCHAR), 'IPCA');
+ /* Calculate the size of the full REG_MULTI_SZ data (see swprintf below) */
+ HardwareIdsLength = (5 + VendorIdentifierLength + 3 + Level1Length + 1 +
+ 1 + VendorIdentifierLength + 3 + Level1Length + 1 +
+ 5 + VendorIdentifierLength + 3 + Level2Length + 1 +
+ 1 + VendorIdentifierLength + 3 + Level2Length + 1 +
+ 5 + VendorIdentifierLength + 3 + Level3Length + 1 +
+ 1 + VendorIdentifierLength + 3 + Level3Length + 1 +
+ 1) * sizeof(WCHAR);
+
+ /* Allocate a buffer to the data */
+ HardwareIdsBuffer = ExAllocatePoolWithTag(PagedPool, HardwareIdsLength, 'IPCA');
if (HardwareIdsBuffer == NULL)
{
Status = STATUS_INSUFFICIENT_RESOURCES;
Length = 0;
Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
- Length++;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
- Length++;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level2Length, ProcessorIdentifier);
- Length++;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level2Length, ProcessorIdentifier);
- Length++;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level3Length, ProcessorIdentifier);
- Length++;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level3Length, ProcessorIdentifier);
- Length++;
- HardwareIdsBuffer[Length] = UNICODE_NULL;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
+ HardwareIdsBuffer[Length++] = UNICODE_NULL;
+
+ /* Make sure we counted correctly */
+ NT_ASSERT(Length * sizeof(WCHAR) == HardwareIdsLength);
- ProcessorHardwareIds.Length = HardwareIdsLength * sizeof(WCHAR);
+ ProcessorHardwareIds.Length = (SHORT)HardwareIdsLength;
ProcessorHardwareIds.MaximumLength = ProcessorHardwareIds.Length;
ProcessorHardwareIds.Buffer = HardwareIdsBuffer;
PUNICODE_STRING RegistryPath
)
{
+ NTSTATUS Status;
DPRINT("Driver Entry \n");
- GetProcessorInformation();
+ Status = GetProcessorInformation();
+ if (!NT_SUCCESS(Status))
+ {
+ NT_ASSERT(FALSE);
+ return Status;
+ }
//
// Set entry points into the driver