[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH 2/2] Re-synchrinize registry.c with XENBUS



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@xxxxxxxxxx>
---
 src/xenvif/registry.c | 79 +++++++++++++++++++++++++++++++++++++++------------
 src/xenvif/registry.h | 13 +++++++++
 2 files changed, 74 insertions(+), 18 deletions(-)

diff --git a/src/xenvif/registry.c b/src/xenvif/registry.c
index 9a7472b..d994e13 100644
--- a/src/xenvif/registry.c
+++ b/src/xenvif/registry.c
@@ -30,13 +30,12 @@
  */
 
 #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
@@ -117,6 +116,40 @@ fail1:
 }
 
 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,
     OUT PHANDLE         Key
@@ -126,6 +159,14 @@ RegistryOpenServiceKey(
 }
 
 NTSTATUS
+RegistryCreateServiceKey(
+    OUT PHANDLE         Key
+    )
+{
+    return RegistryCreateKey(NULL, &RegistryPath, REG_OPTION_NON_VOLATILE, 
Key);
+}
+
+NTSTATUS
 RegistryOpenSoftwareKey(
     IN  PDEVICE_OBJECT  DeviceObject,
     IN  ACCESS_MASK     DesiredAccess,
@@ -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;
diff --git a/src/xenvif/registry.h b/src/xenvif/registry.h
index e39ccb5..faa6c71 100644
--- a/src/xenvif/registry.h
+++ b/src/xenvif/registry.h
@@ -53,12 +53,25 @@ RegistryOpenKey(
     );
 
 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,
     IN  ACCESS_MASK     DesiredAccess,
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.