]> xenbits.xensource.com Git - pvdrivers/win/xenvif.git/commitdiff
Re-synchrinize registry.c with XENBUS
authorPaul Durrant <paul.durrant@citrix.com>
Thu, 10 Dec 2015 11:24:08 +0000 (11:24 +0000)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 10 Dec 2015 11:24:08 +0000 (11:24 +0000)
The registry code in XENBUS has some fixes that are not present in the
XENVIF copy, so import the updated code from XENBUS.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenvif/registry.c
src/xenvif/registry.h

index 9a7472b48fac5ed043302e27a5bb4845e3746706..d994e134694b3b6db5aeed8588c272634cf01ff8 100644 (file)
  */
 
 #include <ntddk.h>
-#include <stdlib.h>
 
 #include "registry.h"
 #include "assert.h"
 #include "util.h"
 
-#define REGISTRY_POOL 'GERX'
+#define REGISTRY_TAG 'GERX'
 
 static UNICODE_STRING   RegistryPath;
 
@@ -45,7 +44,7 @@ __RegistryAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocatePoolWithTag(NonPagedPool, Length, REGISTRY_POOL);
+    return __AllocatePoolWithTag(NonPagedPool, Length, REGISTRY_TAG);
 }
 
 static FORCEINLINE VOID
@@ -53,7 +52,7 @@ __RegistryFree(
     IN  PVOID   Buffer
     )
 {
-    __FreePoolWithTag(Buffer, REGISTRY_POOL);
+    __FreePoolWithTag(Buffer, REGISTRY_TAG);
 }
 
 NTSTATUS
@@ -116,6 +115,40 @@ fail1:
     return status;
 }
 
+NTSTATUS
+RegistryCreateKey(
+    IN  HANDLE          Parent,
+    IN  PUNICODE_STRING Path,
+    IN  ULONG           Options,
+    OUT PHANDLE         Key
+    )
+{
+    OBJECT_ATTRIBUTES   Attributes;
+    NTSTATUS            status;
+
+    InitializeObjectAttributes(&Attributes,
+                               Path,
+                               OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
+                               Parent,
+                               NULL);
+
+    status = ZwCreateKey(Key,
+                         KEY_ALL_ACCESS,
+                         &Attributes,
+                         0,
+                         NULL,
+                         Options,
+                         NULL
+                         );
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+    return STATUS_SUCCESS;
+
+fail1:
+    return status;
+}
+
 NTSTATUS
 RegistryOpenServiceKey(
     IN  ACCESS_MASK     DesiredAccess,
@@ -125,6 +158,14 @@ RegistryOpenServiceKey(
     return RegistryOpenKey(NULL, &RegistryPath, DesiredAccess, Key);
 }
 
+NTSTATUS
+RegistryCreateServiceKey(
+    OUT PHANDLE         Key
+    )
+{
+    return RegistryCreateKey(NULL, &RegistryPath, REG_OPTION_NON_VOLATILE, Key);
+}
+
 NTSTATUS
 RegistryOpenSoftwareKey(
     IN  PDEVICE_OBJECT  DeviceObject,
@@ -331,6 +372,8 @@ RegistryDeleteSubKey(
 
     ZwClose(SubKey);
 
+    (VOID) ZwFlushKey(Key);
+
     RtlFreeUnicodeString(&Unicode);
 
     return STATUS_SUCCESS;
@@ -569,6 +612,8 @@ RegistryDeleteValue(
 
     RtlFreeUnicodeString(&Unicode);
 
+    (VOID) ZwFlushKey(Key);
+
     return STATUS_SUCCESS;
 
 fail2:
@@ -689,6 +734,8 @@ RegistryUpdateDwordValue(
 
     __RegistryFree(Partial);
 
+    (VOID) ZwFlushKey(Key);
+
     RtlFreeUnicodeString(&Unicode);
 
     return STATUS_SUCCESS;
@@ -938,30 +985,25 @@ RegistryQueryBinaryValue(
     if (!NT_SUCCESS(status))
         goto fail4;
 
-    *Buffer = NULL;
-
     switch (Partial->Type) {
     case REG_BINARY:
-        *Length = Partial->DataLength;
-
-        if (*Length == 0)
-            break;
-
         *Buffer = __RegistryAllocate(Partial->DataLength);
 
         status = STATUS_NO_MEMORY;
         if (*Buffer == NULL)
             break;
 
+        *Length = Partial->DataLength;
         RtlCopyMemory(*Buffer, Partial->Data, Partial->DataLength);
         break;
 
     default:
         status = STATUS_INVALID_PARAMETER;
+        *Buffer = NULL;
         break;
     }
 
-    if (!NT_SUCCESS(status))
+    if (*Buffer == NULL)
         goto fail5;
 
     __RegistryFree(Partial);
@@ -1002,7 +1044,7 @@ RegistryUpdateBinaryValue(
         goto fail1;
 
     Partial = __RegistryAllocate(FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) +
-                                 __min(Length, 1));
+                                 Length);
 
     status = STATUS_NO_MEMORY;
     if (Partial == NULL)
@@ -1010,11 +1052,8 @@ RegistryUpdateBinaryValue(
 
     Partial->TitleIndex = 0;
     Partial->Type = REG_BINARY;
-
-    if (Length != 0) {
-        Partial->DataLength = Length;
-        RtlCopyMemory(Partial->Data, Buffer, Partial->DataLength);
-    }
+    Partial->DataLength = Length;
+    RtlCopyMemory(Partial->Data, Buffer, Partial->DataLength);
 
     status = ZwSetValueKey(Key,
                            &Unicode,
@@ -1027,6 +1066,8 @@ RegistryUpdateBinaryValue(
 
     __RegistryFree(Partial);
 
+    (VOID) ZwFlushKey(Key);
+
     RtlFreeUnicodeString(&Unicode);
 
     return STATUS_SUCCESS;
@@ -1317,6 +1358,8 @@ RegistryUpdateSzValue(
 
     __RegistryFree(Partial);
 
+    (VOID) ZwFlushKey(Key);
+
     RtlFreeUnicodeString(&Unicode);
 
     return STATUS_SUCCESS;
index e39ccb518ba8f568ee7ab309782fb85f4d875319..faa6c7135ca6354f03e66bdeaaea7287a24f31ea 100644 (file)
@@ -52,12 +52,25 @@ RegistryOpenKey(
     OUT PHANDLE         Key
     );
 
+extern NTSTATUS
+RegistryCreateKey(
+    IN  HANDLE          Parent,
+    IN  PUNICODE_STRING Path,
+    IN  ULONG           Options,
+    OUT PHANDLE         Key
+    );
+
 extern NTSTATUS
 RegistryOpenServiceKey(
     IN  ACCESS_MASK DesiredAccess,
     OUT PHANDLE     Key
     );
 
+extern NTSTATUS
+RegistryCreateServiceKey(
+    OUT PHANDLE     Key
+    );
+
 extern NTSTATUS
 RegistryOpenSoftwareKey(
     IN  PDEVICE_OBJECT  DeviceObject,