https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b80d806e05380aef33e3f7626807271e661c4b94

commit b80d806e05380aef33e3f7626807271e661c4b94
Author:     Hervé Poussineau <[email protected]>
AuthorDate: Sun Jan 23 21:11:59 2022 +0100
Commit:     Hervé Poussineau <[email protected]>
CommitDate: Wed Jan 26 19:30:32 2022 +0100

    [VIDEOPRT] Honour UseNewKey setting in registry
    
    This changes:
    - which device key is written to DEVICEMAP\Video
    - which registry key is used in VideoPortSetRegistryParameters()
    
    CORE-17896
---
 win32ss/drivers/videoprt/registry.c |  7 ++++++-
 win32ss/drivers/videoprt/videoprt.c | 27 +++++++++++++++++++++++++--
 win32ss/drivers/videoprt/videoprt.h |  1 +
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/win32ss/drivers/videoprt/registry.c 
b/win32ss/drivers/videoprt/registry.c
index 76b3ead0846..64be3601827 100644
--- a/win32ss/drivers/videoprt/registry.c
+++ b/win32ss/drivers/videoprt/registry.c
@@ -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;
diff --git a/win32ss/drivers/videoprt/videoprt.c 
b/win32ss/drivers/videoprt/videoprt.c
index 4398d82e480..0348b677c7b 100644
--- a/win32ss/drivers/videoprt/videoprt.c
+++ b/win32ss/drivers/videoprt/videoprt.c
@@ -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);
@@ -58,6 +59,7 @@ NTSTATUS
 IntVideoPortAddDeviceMapLink(
     PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
 {
+    PUNICODE_STRING RegistryPath;
     WCHAR DeviceBuffer[20];
     UNICODE_STRING DeviceName;
     WCHAR SymlinkBuffer[20];
@@ -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);
@@ -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,
diff --git a/win32ss/drivers/videoprt/videoprt.h 
b/win32ss/drivers/videoprt/videoprt.h
index bf4290e014d..44824dc2bdd 100644
--- a/win32ss/drivers/videoprt/videoprt.h
+++ b/win32ss/drivers/videoprt/videoprt.h
@@ -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;

Reply via email to