From: Paul Durrant Date: Thu, 10 Dec 2015 11:24:08 +0000 (+0000) Subject: Re-synchrinize registry.c with XENBUS X-Git-Tag: 8.2.0-rc1~77 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=295280f87e676245a75969cfae00637bce00acde;p=pvdrivers%2Fwin%2Fxenvif.git 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 --- 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 -#include #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; 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 @@ -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,