Skip to content

Commit

Permalink
[VIDEOPRT] Honour UseNewKey setting in registry
Browse files Browse the repository at this point in the history
This changes:
- which device key is written to DEVICEMAP\Video
- which registry key is used in VideoPortSetRegistryParameters()

CORE-17896
  • Loading branch information
hpoussin committed Jan 26, 2022
1 parent ff9301e commit b80d806
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion win32ss/drivers/videoprt/registry.c
Expand Up @@ -668,7 +668,12 @@ IntCreateRegistryPath(
}
}

if (Valid)
if (!VideoPortUseNewKey)
{
INFO_(VIDEOPRT, "Using old registry key as 'UseNewKey' is FALSE\n");
Valid = FALSE;
}
else if (Valid)
{
DeviceRegistryPath->MaximumLength = DriverRegistryPath->Length + sizeof(Insert1) + sizeof(Insert2)
+ DeviceNumberString.Length;
Expand Down
27 changes: 25 additions & 2 deletions win32ss/drivers/videoprt/videoprt.c
Expand Up @@ -38,6 +38,7 @@ BOOLEAN VpNoVesa = FALSE;

PKPROCESS CsrProcess = NULL;
static ULONG VideoPortMaxObjectNumber = -1;
BOOLEAN VideoPortUseNewKey = FALSE;
KMUTEX VideoPortInt10Mutex;
KSPIN_LOCK HwResetAdaptersLock;
RTL_STATIC_LIST_HEAD(HwResetAdaptersList);
Expand All @@ -58,6 +59,7 @@ NTSTATUS
IntVideoPortAddDeviceMapLink(
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
{
PUNICODE_STRING RegistryPath;
WCHAR DeviceBuffer[20];
UNICODE_STRING DeviceName;
WCHAR SymlinkBuffer[20];
Expand All @@ -69,13 +71,18 @@ IntVideoPortAddDeviceMapLink(
DeviceNumber = DeviceExtension->DeviceNumber;
swprintf(DeviceBuffer, L"\\Device\\Video%lu", DeviceNumber);

if (VideoPortUseNewKey)
RegistryPath = &DeviceExtension->NewRegistryPath;
else
RegistryPath = &DeviceExtension->RegistryPath;

/* Add entry to DEVICEMAP\VIDEO key in registry. */
Status = RtlWriteRegistryValue(RTL_REGISTRY_DEVICEMAP,
L"VIDEO",
DeviceBuffer,
REG_SZ,
DeviceExtension->NewRegistryPath.Buffer,
DeviceExtension->NewRegistryPath.Length + sizeof(UNICODE_NULL));
RegistryPath->Buffer,
RegistryPath->Length + sizeof(UNICODE_NULL));
if (!NT_SUCCESS(Status))
{
ERR_(VIDEOPRT, "Failed to create DEViCEMAP registry entry: 0x%X\n", Status);
Expand Down Expand Up @@ -516,12 +523,28 @@ IntLoadRegistryParameters(VOID)
{
NTSTATUS Status;
HANDLE KeyHandle;
UNICODE_STRING UseNewKeyPath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\GraphicsDrivers\\UseNewKey");
UNICODE_STRING Path = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control");
UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"SystemStartOptions");
OBJECT_ATTRIBUTES ObjectAttributes;
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
ULONG Length, NewLength;

/* Check if we need to use new registry */
InitializeObjectAttributes(&ObjectAttributes,
&UseNewKeyPath,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
Status = ZwOpenKey(&KeyHandle,
GENERIC_READ | GENERIC_WRITE,
&ObjectAttributes);
if (NT_SUCCESS(Status))
{
VideoPortUseNewKey = TRUE;
ZwClose(KeyHandle);
}

/* Initialize object attributes with the path we want */
InitializeObjectAttributes(&ObjectAttributes,
&Path,
Expand Down
1 change: 1 addition & 0 deletions win32ss/drivers/videoprt/videoprt.h
Expand Up @@ -249,6 +249,7 @@ IntVideoPortMapPhysicalMemory(

extern PKPROCESS CsrProcess;
extern ULONG VideoPortDeviceNumber;
extern BOOLEAN VideoPortUseNewKey;
extern KMUTEX VideoPortInt10Mutex;
extern KSPIN_LOCK HwResetAdaptersLock;
extern LIST_ENTRY HwResetAdaptersList;
Expand Down

0 comments on commit b80d806

Please sign in to comment.