]> xenbits.xensource.com Git - pvdrivers/win/xeniface.git/commitdiff
Fix CodeQL warnings
authorOwen Smith <owen.smith@citrix.com>
Thu, 12 Aug 2021 12:36:12 +0000 (13:36 +0100)
committerPaul Durrant <pdurrant@amazon.com>
Mon, 20 Sep 2021 09:00:53 +0000 (10:00 +0100)
- ExAllocatePoolWithTag is deprecated for Win10 2004, use
    ExAllocatePoolUninitialized instead
- Add "(VOID)" before AccessWmiBuffer, where the return value is not needed

Signed-off-by: Owen Smith <owen.smith@citrix.com>
Extend patch to cover ioctl_gnttab.c, ioctl_store.c and ioctl_suspend.c

Signed-off-by: Paul Durrant <paul@xen.org>
src/xeniface/driver.c
src/xeniface/ioctl_evtchn.c
src/xeniface/ioctl_gnttab.c
src/xeniface/ioctl_store.c
src/xeniface/ioctl_suspend.c
src/xeniface/ioctls.c
src/xeniface/util.h
src/xeniface/wmi.c

index 2087cad3a13bda03aaf1e15071b7c29018751e03..db41cfefec55df81b98e0b6530a642c1aa013cbd 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "assert.h"
 #include "wmi.h"
+#include "util.h"
 
 PDRIVER_OBJECT      DriverObject;
 
@@ -55,7 +56,8 @@ DriverUnload(
     Trace("====>\n");
 
     if (DriverParameters.RegistryPath.Buffer != NULL) {
-        ExFreePool(DriverParameters.RegistryPath.Buffer);
+        __FreePoolWithTag(DriverParameters.RegistryPath.Buffer,
+                          XENIFACE_POOL_TAG);
     }
 
     DriverObject = NULL;
@@ -154,7 +156,7 @@ DriverEntry(
 
     DriverParameters.RegistryPath.MaximumLength = RegistryPath->Length + sizeof(UNICODE_NULL);
     DriverParameters.RegistryPath.Length = RegistryPath->Length;
-    DriverParameters.RegistryPath.Buffer = ExAllocatePoolWithTag (PagedPool,
+    DriverParameters.RegistryPath.Buffer = __AllocatePoolWithTag(PagedPool,
                                                 DriverParameters.RegistryPath.MaximumLength,
                                                 XENIFACE_POOL_TAG);
     if (NULL == DriverParameters.RegistryPath.Buffer) {
index 85b66af73dd410a810ea616cfd4c407f39d7697a..f5284858076e4644e1667ece5bd027addc9f95c5 100644 (file)
@@ -35,6 +35,7 @@
 #include "ioctls.h"
 #include "xeniface_ioctls.h"
 #include "log.h"
+#include "util.h"
 
 _Function_class_(KDEFERRED_ROUTINE)
 _IRQL_requires_(DISPATCH_LEVEL)
@@ -82,7 +83,7 @@ EvtchnInterruptHandler(
 
     ASSERT(Context != NULL);
 
-    KeGetCurrentProcessorNumberEx(&ProcNumber);
+    (VOID) KeGetCurrentProcessorNumberEx(&ProcNumber);
     ProcIndex = KeGetProcessorIndexFromNumber(&ProcNumber);
 
     (VOID) KeInsertQueueDpc(&Context->Dpc, NULL, NULL);
@@ -112,7 +113,7 @@ EvtchnFree(
 
     ObDereferenceObject(Context->Event);
     RtlZeroMemory(Context, sizeof(XENIFACE_EVTCHN_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 }
 
 _Requires_exclusive_lock_held_(Fdo->EvtchnLock)
@@ -170,11 +171,10 @@ IoctlEvtchnBindUnbound(
     }
 
     status = STATUS_NO_MEMORY;
-    Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_EVTCHN_CONTEXT), XENIFACE_POOL_TAG);
+    Context = __AllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_EVTCHN_CONTEXT), XENIFACE_POOL_TAG);
     if (Context == NULL)
         goto fail2;
 
-    RtlZeroMemory(Context, sizeof(XENIFACE_EVTCHN_CONTEXT));
     Context->FileObject = FileObject;
 
     Trace("> RemoteDomain %d, Mask %d, FO %p\n",
@@ -231,7 +231,7 @@ fail4:
 fail3:
     Error("Fail3\n");
     RtlZeroMemory(Context, sizeof(XENIFACE_EVTCHN_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 
 fail2:
     Error("Fail2\n");
@@ -264,11 +264,10 @@ IoctlEvtchnBindInterdomain(
     }
 
     status = STATUS_NO_MEMORY;
-    Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_EVTCHN_CONTEXT), XENIFACE_POOL_TAG);
+    Context = __AllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_EVTCHN_CONTEXT), XENIFACE_POOL_TAG);
     if (Context == NULL)
         goto fail2;
 
-    RtlZeroMemory(Context, sizeof(XENIFACE_EVTCHN_CONTEXT));
     Context->FileObject = FileObject;
 
     Trace("> RemoteDomain %d, RemotePort %lu, Mask %d, FO %p\n",
@@ -327,7 +326,7 @@ fail4:
 fail3:
     Error("Fail3\n");
     RtlZeroMemory(Context, sizeof(XENIFACE_EVTCHN_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 
 fail2:
     Error("Fail2\n");
index dc5eb7f95ce69818b88f09dd1555804eb185582f..c3cf1293deba71c5ba03d04908275b60fe3aab65 100644 (file)
@@ -34,6 +34,7 @@
 #include "xeniface_ioctls.h"
 #include "log.h"
 #include "irp_queue.h"
+#include "util.h"
 
 // Complete a canceled gnttab IRP, cleanup associated grant/map.
 _Function_class_(IO_WORKITEM_ROUTINE)
@@ -177,7 +178,7 @@ IoctlGnttabPermitForeignAccess(
         goto fail5;
 
     status = STATUS_NO_MEMORY;
-    Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_GRANT_CONTEXT), XENIFACE_POOL_TAG);
+    Context = __AllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_GRANT_CONTEXT), XENIFACE_POOL_TAG);
     if (Context == NULL)
         goto fail6;
 
@@ -204,7 +205,7 @@ IoctlGnttabPermitForeignAccess(
         goto fail7;
 
     status = STATUS_NO_MEMORY;
-    Context->Grants = ExAllocatePoolWithTag(NonPagedPool, Context->NumberPages * sizeof(PXENBUS_GNTTAB_ENTRY), XENIFACE_POOL_TAG);
+    Context->Grants = __AllocatePoolWithTag(NonPagedPool, Context->NumberPages * sizeof(PXENBUS_GNTTAB_ENTRY), XENIFACE_POOL_TAG);
     if (Context->Grants == NULL)
         goto fail8;
 
@@ -212,7 +213,7 @@ IoctlGnttabPermitForeignAccess(
 
     // allocate memory to share
     status = STATUS_NO_MEMORY;
-    Context->KernelVa = ExAllocatePoolWithTag(NonPagedPool, Context->NumberPages * PAGE_SIZE, XENIFACE_POOL_TAG);
+    Context->KernelVa = __AllocatePoolWithTag(NonPagedPool, Context->NumberPages * PAGE_SIZE, XENIFACE_POOL_TAG);
     if (Context->KernelVa == NULL)
         goto fail9;
 
@@ -321,11 +322,11 @@ fail11:
 
 fail10:
     Error("Fail10\n");
-    ExFreePoolWithTag(Context->KernelVa, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context->KernelVa, XENIFACE_POOL_TAG);
 
 fail9:
     Error("Fail9\n");
-    ExFreePoolWithTag(Context->Grants, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context->Grants, XENIFACE_POOL_TAG);
 
 fail8:
     Error("Fail8\n");
@@ -333,7 +334,7 @@ fail8:
 fail7:
     Error("Fail7\n");
     RtlZeroMemory(Context, sizeof(XENIFACE_GRANT_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 
 fail6:
     Error("Fail6\n");
@@ -398,13 +399,13 @@ GnttabFreeGrant(
     IoFreeMdl(Context->Mdl);
 
     RtlZeroMemory(Context->KernelVa, Context->NumberPages * PAGE_SIZE);
-    ExFreePoolWithTag(Context->KernelVa, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context->KernelVa, XENIFACE_POOL_TAG);
 
     RtlZeroMemory(Context->Grants, Context->NumberPages * sizeof(PXENBUS_GNTTAB_ENTRY));
-    ExFreePoolWithTag(Context->Grants, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context->Grants, XENIFACE_POOL_TAG);
 
     RtlZeroMemory(Context, sizeof(XENIFACE_GRANT_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 }
 
 DECLSPEC_NOINLINE
@@ -505,7 +506,7 @@ IoctlGnttabMapForeignPages(
         goto fail5;
 
     status = STATUS_NO_MEMORY;
-    Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_MAP_CONTEXT), XENIFACE_POOL_TAG);
+    Context = __AllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_MAP_CONTEXT), XENIFACE_POOL_TAG);
     if (Context == NULL)
         goto fail6;
 
@@ -628,7 +629,7 @@ fail8:
 fail7:
     Error("Fail7\n");
     RtlZeroMemory(Context, sizeof(XENIFACE_MAP_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 
 fail6:
     Error("Fail6\n");
@@ -692,7 +693,7 @@ GnttabFreeMap(
     ASSERT(NT_SUCCESS(status));
 
     RtlZeroMemory(Context, sizeof(XENIFACE_MAP_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 }
 
 DECLSPEC_NOINLINE
index c1db0ba087b185c6db871f329b299f9b09e96e76..9116e82bdcf550401499a6ba2018345d738f84a3 100644 (file)
@@ -34,6 +34,7 @@
 #include "ioctls.h"
 #include "xeniface_ioctls.h"
 #include "log.h"
+#include "util.h"
 
 #define XENSTORE_ABS_PATH_MAX 3072
 #define XENSTORE_REL_PATH_MAX 2048
@@ -317,7 +318,7 @@ __ConvertPermissions(
     if (NumberPermissions > 255)
         goto fail1;
 
-    XenbusPermissions = ExAllocatePoolWithTag(NonPagedPool, NumberPermissions * sizeof(XENBUS_STORE_PERMISSION), XENIFACE_POOL_TAG);
+    XenbusPermissions = __AllocatePoolWithTag(NonPagedPool, NumberPermissions * sizeof(XENBUS_STORE_PERMISSION), XENIFACE_POOL_TAG);
     if (XenbusPermissions == NULL)
         goto fail2;
 
@@ -348,7 +349,7 @@ __ConvertPermissions(
 
 fail3:
     Error("Fail3\n");
-    ExFreePoolWithTag(XenbusPermissions, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(XenbusPermissions, XENIFACE_POOL_TAG);
 
 fail2:
     Error("Fail2\n");
@@ -364,7 +365,7 @@ __FreePermissions(
     __in  PXENBUS_STORE_PERMISSION    Permissions
     )
 {
-    ExFreePoolWithTag(Permissions, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Permissions, XENIFACE_POOL_TAG);
 }
 
 DECLSPEC_NOINLINE
@@ -515,7 +516,7 @@ IoctlStoreAddWatch(
     Path[In->PathLength - 1] = 0;
 
     status = STATUS_NO_MEMORY;
-    Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_STORE_CONTEXT), XENIFACE_POOL_TAG);
+    Context = __AllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_STORE_CONTEXT), XENIFACE_POOL_TAG);
     if (Context == NULL)
         goto fail4;
 
@@ -573,7 +574,7 @@ fail6:
 fail5:
     Error("Fail5\n");
     RtlZeroMemory(Context, sizeof(XENIFACE_STORE_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 
 fail4:
     Error("Fail4\n");
@@ -617,7 +618,7 @@ StoreFreeWatch(
 
     ObDereferenceObject(Context->Event);
     RtlZeroMemory(Context, sizeof(XENIFACE_STORE_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 }
 
 DECLSPEC_NOINLINE
index 94cfd242785498c3bb4d7c917716067d33d8a64a..6289a94222702c9b1b39d49f33dd32a7f130cba9 100644 (file)
@@ -33,6 +33,7 @@
 #include "ioctls.h"
 #include "xeniface_ioctls.h"
 #include "log.h"
+#include "util.h"
 
 DECLSPEC_NOINLINE
 NTSTATUS
@@ -91,7 +92,7 @@ IoctlSuspendRegister(
     }
 
     status = STATUS_NO_MEMORY;
-    Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_SUSPEND_CONTEXT), XENIFACE_POOL_TAG);
+    Context = __AllocatePoolWithTag(NonPagedPool, sizeof(XENIFACE_SUSPEND_CONTEXT), XENIFACE_POOL_TAG);
     if (Context == NULL)
         goto fail2;
 
@@ -119,7 +120,7 @@ IoctlSuspendRegister(
 fail3:
     Error("Fail3\n");
     RtlZeroMemory(Context, sizeof(XENIFACE_SUSPEND_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 
 fail2:
     Error("Fail2\n");
@@ -141,7 +142,7 @@ SuspendFreeEvent(
 
     ObDereferenceObject(Context->Event);
     RtlZeroMemory(Context, sizeof(XENIFACE_SUSPEND_CONTEXT));
-    ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+    __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
 }
 
 DECLSPEC_NOINLINE
index bf280cbbfe413de1aaab20bce6d176a1bd7f0770..a624bd1dc8f17fe11373f80dd7329b5f0396aa28 100644 (file)
@@ -36,6 +36,7 @@
 #include "ioctls.h"
 #include "xeniface_ioctls.h"
 #include "log.h"
+#include "util.h"
 
 NTSTATUS
 __CaptureUserBuffer(
@@ -53,7 +54,7 @@ __CaptureUserBuffer(
     }
 
     Status = STATUS_NO_MEMORY;
-    TempBuffer = ExAllocatePoolWithTag(NonPagedPool, Length, XENIFACE_POOL_TAG);
+    TempBuffer = __AllocatePoolWithTag(NonPagedPool, Length, XENIFACE_POOL_TAG);
     if (TempBuffer == NULL)
         return STATUS_INSUFFICIENT_RESOURCES;
 
@@ -65,7 +66,7 @@ __CaptureUserBuffer(
         RtlCopyMemory(TempBuffer, Buffer, Length);
     } except(EXCEPTION_EXECUTE_HANDLER) {
         Error("Exception while probing/reading buffer at %p, size 0x%lx\n", Buffer, Length);
-        ExFreePoolWithTag(TempBuffer, XENIFACE_POOL_TAG);
+        __FreePoolWithTag(TempBuffer, XENIFACE_POOL_TAG);
         TempBuffer = NULL;
         Status = GetExceptionCode();
     }
@@ -81,7 +82,7 @@ __FreeCapturedBuffer(
     )
 {
     if (CapturedBuffer != NULL) {
-        ExFreePoolWithTag(CapturedBuffer, XENIFACE_POOL_TAG);
+        __FreePoolWithTag(CapturedBuffer, XENIFACE_POOL_TAG);
     }
 }
 
index f07f708e222517d041a293b8c3b0aa4eabf44170..bc7518ac23f5c25c46c15c5027eebcf18b639bca 100644 (file)
@@ -151,8 +151,12 @@ __AllocatePoolWithTag(
     __analysis_assume(PoolType == NonPagedPool ||
                       PoolType == PagedPool);
 
+#if (_MSC_VER >= 1928) // VS 16.9 (EWDK 20344 or later)
+    Buffer = ExAllocatePoolUninitialized(PoolType, NumberOfBytes, Tag);
+#else
 #pragma warning(suppress:28160) // annotation error
     Buffer = ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
+#endif
     if (Buffer == NULL)
         return NULL;
 
index 7cdb20dd38573246fa48a79bfa201cf9395ec029..3ee68d5259fa1c94fb581d39e46559e4d25c8e91 100644 (file)
 #include "log.h"
 #include "xeniface_ioctls.h"
 #include <version.h>
+#include "util.h"
+
+#define WMI_POOL_TAG    'XenP'
+
+static FORCEINLINE PVOID
+WmiAllocate(
+    IN  ULONG   Length
+    )
+{
+    // Zeroes the allocation
+    return __AllocatePoolWithTag(NonPagedPool, Length, WMI_POOL_TAG);
+}
+
+static FORCEINLINE VOID
+WmiFree(
+    IN  PVOID   Buffer
+    )
+{
+    __FreePoolWithTag(Buffer, WMI_POOL_TAG);
+}
 
 void LockSessions(
         XENIFACE_FDO* fdoData)
@@ -266,7 +286,7 @@ NTSTATUS GetUTF8String(UTF8_STRING** utf8, USHORT bufsize, LPWSTR ustring)
         bytecount += CountUtf8FromUtf32(utf32);
     }
 
-    *utf8 = ExAllocatePoolWithTag(NonPagedPool, sizeof(UTF8_STRING)+bytecount, 'XIU8');
+    *utf8 = WmiAllocate(sizeof(UTF8_STRING) + bytecount);
     if ((*utf8) == NULL)
         return STATUS_INSUFFICIENT_RESOURCES;
 
@@ -284,7 +304,7 @@ NTSTATUS GetUTF8String(UTF8_STRING** utf8, USHORT bufsize, LPWSTR ustring)
 }
 
 void FreeUTF8String(UTF8_STRING *utf8) {
-    ExFreePoolWithTag(utf8, 'XIU8');
+    WmiFree(utf8);
 }
 
 NTSTATUS GetCountedUTF8String(UTF8_STRING **utf8, UCHAR *location)
@@ -504,11 +524,10 @@ WriteCountedUTF8String(const char * string, UCHAR *location) {
     NTSTATUS status = STATUS_SUCCESS;
     WCHAR *buffer;
     bytesize = CountBytesUtf16FromUtf8(string);
-    buffer = ExAllocatePoolWithTag(NonPagedPool, bytesize+sizeof(WCHAR), 'XSUc');
-
-    if (buffer == NULL) {
+    buffer = WmiAllocate(bytesize + sizeof(WCHAR));
+    if (buffer == NULL)
         return STATUS_INSUFFICIENT_RESOURCES;
-    }
+
     buffer[bytesize/sizeof(WCHAR)] = 0;
 
     i=0;
@@ -519,7 +538,7 @@ WriteCountedUTF8String(const char * string, UCHAR *location) {
     }
     RtlInitUnicodeString(&unicode, buffer);
     status = WriteCountedUnicodeString(&unicode, location);
-    ExFreePoolWithTag(buffer, 'XSUc');
+    WmiFree(buffer);
 
     return status;
 }
@@ -547,7 +566,7 @@ WriteCountedString(
 }
 
 void AllocUnicodeStringBuffer(UNICODE_STRING *string, USHORT buffersize) {
-    string->Buffer = ExAllocatePoolWithTag(NonPagedPool, buffersize, 'XIUC');
+    string->Buffer = WmiAllocate(buffersize);
     string->Length = 0;
     if (string->Buffer == NULL) {
         string->MaximumLength=0;
@@ -559,7 +578,7 @@ void AllocUnicodeStringBuffer(UNICODE_STRING *string, USHORT buffersize) {
 }
 void FreeUnicodeStringBuffer(UNICODE_STRING *string) {
     if (string->Buffer)
-        ExFreePoolWithTag(string->Buffer, 'XIUC');
+        WmiFree(string->Buffer);
     string->Length=0;
     string->MaximumLength=0;
     string->Buffer = NULL;
@@ -771,14 +790,14 @@ void FireWatch(XenStoreWatch* watch) {
     ULONG RequiredSize;
     UCHAR *sesbuf;
 
-    AccessWmiBuffer(0, FALSE, &RequiredSize, 0,
+    (VOID) AccessWmiBuffer(0, FALSE, &RequiredSize, 0,
             WMI_STRING, GetCountedUnicodeStringSize(&watch->path),
                 &sesbuf,
             WMI_DONE);
 
-    eventdata = ExAllocatePoolWithTag(NonPagedPool, RequiredSize,'XIEV');
+    eventdata = WmiAllocate(RequiredSize);
     if (eventdata!=NULL) {
-        AccessWmiBuffer(eventdata, FALSE, &RequiredSize, RequiredSize,
+        (VOID) AccessWmiBuffer(eventdata, FALSE, &RequiredSize, RequiredSize,
             WMI_STRING, GetCountedUnicodeStringSize(&watch->path),
                 &sesbuf,
             WMI_DONE);
@@ -808,24 +827,24 @@ StartWatch(XENIFACE_FDO *fdoData, XenStoreWatch *watch)
     if (!NT_SUCCESS(status)) {
         return STATUS_INSUFFICIENT_RESOURCES;
     }
-    tmppath = ExAllocatePoolWithTag(NonPagedPool, ansipath.Length+1, 'XenP');
+    tmppath = WmiAllocate(ansipath.Length + 1);
     if (!tmppath) {
         RtlFreeAnsiString(&ansipath);
         return STATUS_INSUFFICIENT_RESOURCES;
     }
-    RtlZeroMemory(tmppath, ansipath.Length+1);
+
     RtlCopyBytes(tmppath,ansipath.Buffer, ansipath.Length);
 
     status = XENBUS_STORE(WatchAdd, &fdoData->StoreInterface, NULL, tmppath, &watch->watchevent, &watch->watchhandle );
     if (!NT_SUCCESS(status)) {
-        ExFreePool(tmppath);
+        WmiFree(tmppath);
         RtlFreeAnsiString(&ansipath);
         return status;
     }
 
     Info("Start Watch %p\n", watch->watchhandle);
 
-    ExFreePool(tmppath);
+    WmiFree(tmppath);
     RtlFreeAnsiString(&ansipath);
 
     return STATUS_SUCCESS;
@@ -866,7 +885,7 @@ VOID WatchCallbackThread(__in PVOID StartContext) {
             if (watch->finished) {
                 FreeUnicodeStringBuffer(&watch->path);
                 RemoveEntryList((LIST_ENTRY*)watch);
-                ExFreePool(watch);
+                WmiFree(watch);
                 session->mapchanged = TRUE;
                 session->watchcount --;
             } else if (!session->suspended &&
@@ -894,7 +913,7 @@ VOID WatchCallbackThread(__in PVOID StartContext) {
                         watch=(XenStoreWatch *)session->watches.Flink) {
                             FreeUnicodeStringBuffer(&watch->path);
                             RemoveEntryList((LIST_ENTRY*)watch);
-                            ExFreePool(watch);
+                            WmiFree(watch);
                             session->mapchanged = TRUE;
                             session->watchcount --;
                     }
@@ -927,10 +946,9 @@ SessionAddWatchLocked(XenStoreSession *session,
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-    *watch = ExAllocatePoolWithTag(NonPagedPool, sizeof(XenStoreWatch), 'XenP');
-    if (*watch == NULL) {
+    *watch = WmiAllocate(sizeof(XenStoreWatch));
+    if (*watch == NULL)
         return STATUS_INSUFFICIENT_RESOURCES;
-    }
 
     (*watch)->finished = FALSE;
     (*watch)->fdoData = fdoData;
@@ -946,7 +964,7 @@ SessionAddWatchLocked(XenStoreSession *session,
 
     status = StartWatch(fdoData, *watch);
     if ((!NT_SUCCESS(status)) || ((*watch)->watchhandle == NULL)) {
-        ExFreePool(*watch);
+        WmiFree(*watch);
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
@@ -1052,16 +1070,16 @@ PSTR Xmasprintf(const char *fmt, ...) {
     va_start(argv, fmt);
     do{
         basesize = basesize * 2;
-        out =  ExAllocatePoolWithTag(NonPagedPool, basesize, 'XenP');
+        out =  WmiAllocate((ULONG)basesize);
         if (out == NULL)
             return NULL;
 
         status = RtlStringCbVPrintfExA(out, basesize, NULL, &unused,0, fmt, argv);
 
-        ExFreePool(out);
+        WmiFree(out);
     }while (status != STATUS_SUCCESS);
 
-    out = ExAllocatePoolWithTag(NonPagedPool, basesize-unused +1, 'XenP');
+    out = WmiAllocate((ULONG)(basesize - unused + 1));
     if (out == NULL)
         return NULL;
 
@@ -1085,16 +1103,15 @@ CreateNewSession(XENIFACE_FDO *fdoData,
     if (fdoData->Sessions == MAX_SESSIONS) {
         return STATUS_INSUFFICIENT_RESOURCES;
     }
-    session = ExAllocatePoolWithTag(NonPagedPool, sizeof(XenStoreSession), 'XenP');
+    session = WmiAllocate(sizeof(XenStoreSession));
     if (session == NULL)
         return STATUS_INSUFFICIENT_RESOURCES;
-    RtlZeroMemory(session, sizeof(XenStoreSession));
 
     InitializeMutex(&session->WatchMapLock);
     session->mapchanged = TRUE;
     status = RtlUnicodeStringToAnsiString(&ansi, stringid, TRUE);
     if (!NT_SUCCESS(status)) {
-        ExFreePool(session);
+        WmiFree(session);
         return status;
     }
     LockSessions(fdoData);
@@ -1106,16 +1123,16 @@ CreateNewSession(XENIFACE_FDO *fdoData,
         if (iname == NULL) {
             UnlockSessions(fdoData);
             RtlFreeAnsiString(&ansi);
-            ExFreePool(session);
+            WmiFree(session);
             return status;
         }
 
         status = GetInstanceName(&session->instancename ,fdoData,iname);
-        ExFreePool(iname);
+        WmiFree(iname);
         if (!NT_SUCCESS(status)) {
             UnlockSessions(fdoData);
             RtlFreeAnsiString(&ansi);
-            ExFreePool(session);
+            WmiFree(session);
             return status;
         }
         count++;
@@ -1157,7 +1174,7 @@ CreateNewSession(XENIFACE_FDO *fdoData,
     status = PsCreateSystemThread(&hthread, THREAD_ALL_ACCESS, &oa, NULL, NULL, WatchCallbackThread, session);
     if (!NT_SUCCESS(status)) {
             RtlFreeAnsiString(&ansi);
-            ExFreePool(session);
+            WmiFree(session);
             return status;
     }
     ObReferenceObjectByHandle(hthread, THREAD_ALL_ACCESS, NULL, KernelMode,  &session->WatchThread, NULL);
@@ -1184,7 +1201,7 @@ RemoveSessionLocked(XENIFACE_FDO *fdoData,
     ObDereferenceObject(session->WatchThread);
     FreeUnicodeStringBuffer(&session->stringid);
     FreeUnicodeStringBuffer(&session->instancename);
-    ExFreePool(session);
+    WmiFree(session);
 }
 
 void
@@ -1472,11 +1489,11 @@ SessionExecuteRemoveValue(UCHAR *InBuffer,
         return status;
 
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmpbuffer = ExAllocatePoolWithTag(NonPagedPool, pathname->Length+1, 'XenP');
+    tmpbuffer = WmiAllocate(pathname->Length + 1);
     if (!tmpbuffer) {
         goto fail1;
     }
-    RtlZeroMemory(tmpbuffer, pathname->Length+1);
+
     RtlCopyBytes(tmpbuffer,pathname->Buffer, pathname->Length);
 
     status = STATUS_WMI_INSTANCE_NOT_FOUND;
@@ -1488,7 +1505,7 @@ SessionExecuteRemoveValue(UCHAR *InBuffer,
     UnlockSessions(fdoData);
 
 fail2:
-    ExFreePool(tmpbuffer);
+    WmiFree(tmpbuffer);
 
 fail1:
     FreeUTF8String(pathname);
@@ -1647,22 +1664,22 @@ SessionExecuteSetValue(UCHAR *InBuffer,
         return status;
 
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmppath = ExAllocatePoolWithTag(NonPagedPool, pathname->Length+1, 'XenP');
+    tmppath = WmiAllocate(pathname->Length + 1);
     if (!tmppath) {
         goto fail1;
     }
-    RtlZeroMemory(tmppath, pathname->Length+1);
+
     RtlCopyBytes(tmppath,pathname->Buffer, pathname->Length);
     status = GetCountedUTF8String(&value, uvalue);
     if (!NT_SUCCESS(status)){
         goto fail2;
     }
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmpvalue = ExAllocatePoolWithTag(NonPagedPool,value->Length+1,'XenP');
+    tmpvalue = WmiAllocate(value->Length + 1);
     if (!tmpvalue) {
         goto fail3;
     }
-    RtlZeroMemory(tmpvalue, value->Length+1);
+
     RtlCopyBytes(tmpvalue,value->Buffer, value->Length);
 
     status = STATUS_WMI_INSTANCE_NOT_FOUND;
@@ -1675,13 +1692,13 @@ SessionExecuteSetValue(UCHAR *InBuffer,
     UnlockSessions(fdoData);
 
 fail4:
-    ExFreePool(tmpvalue);
+    WmiFree(tmpvalue);
 
 fail3:
     FreeUTF8String(value);
 
 fail2:
-    ExFreePool(tmppath);
+    WmiFree(tmppath);
 
 fail1:
     FreeUTF8String(pathname);
@@ -1723,11 +1740,11 @@ SessionExecuteGetFirstChild(UCHAR *InBuffer,
     }
 
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmppath = ExAllocatePoolWithTag(NonPagedPool,path->Length+1, 'XenP');
+    tmppath = WmiAllocate(path->Length + 1);
     if (!tmppath) {
         goto fail1;
     }
-    RtlZeroMemory(tmppath, path->Length+1);
+
     RtlCopyBytes(tmppath,path->Buffer, path->Length);
 
     status = STATUS_WMI_INSTANCE_NOT_FOUND;
@@ -1781,7 +1798,7 @@ SessionExecuteGetFirstChild(UCHAR *InBuffer,
 
         WriteCountedUTF8String(fullpath, valuepos);
         valuepos+=GetCountedUtf8Size(fullpath);
-        ExFreePool(fullpath);
+        WmiFree(fullpath);
     }
     else {
         WriteCountedUTF8String("", valuepos);
@@ -1794,7 +1811,7 @@ fail3:
     *byteswritten = RequiredSize;
 
 fail2:
-    ExFreePool(tmppath);
+    WmiFree(tmppath);
 
 fail1:
     FreeUTF8String(path);
@@ -1841,17 +1858,16 @@ SessionExecuteGetNextSibling(UCHAR *InBuffer,
     }
 
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmppath = ExAllocatePoolWithTag(NonPagedPool,path->Length+1,'XenP');
+    tmppath = WmiAllocate(path->Length + 1);
 
     if (!tmppath) {
         goto fail1;
     }
-    RtlZeroMemory(tmppath, path->Length+1);
-    tmpleaf = ExAllocatePoolWithTag(NonPagedPool,path->Length+1,'XenP');
+
+    tmpleaf = WmiAllocate(path->Length + 1);
     if (!tmpleaf) {
         goto fail2;
     }
-    RtlZeroMemory(tmpleaf, path->Length+1);
 
     status = STATUS_WMI_INSTANCE_NOT_FOUND;
     if ((session = FindSessionByInstanceAndLock(fdoData, instance)) ==
@@ -1955,7 +1971,7 @@ SessionExecuteGetNextSibling(UCHAR *InBuffer,
         }
 
         WriteCountedUTF8String(fullpath, valuepos);
-        ExFreePool(fullpath);
+        WmiFree(fullpath);
     }
     else {
         WriteCountedUTF8String("", valuepos);
@@ -1968,10 +1984,10 @@ fail4:
     XENBUS_STORE(Free, &fdoData->StoreInterface, listresults);
 
 fail3:
-    ExFreePool(tmpleaf);
+    WmiFree(tmpleaf);
 
 fail2:
-    ExFreePool(tmppath);
+    WmiFree(tmppath);
 
 fail1:
     FreeUTF8String(path);
@@ -2016,11 +2032,11 @@ SessionExecuteGetChildren(UCHAR *InBuffer,
     }
 
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmppath = ExAllocatePoolWithTag(NonPagedPool,path->Length+1,'XenP');
+    tmppath = WmiAllocate(path->Length + 1);
     if (!tmppath) {
         goto fail1;
     }
-    RtlZeroMemory(tmppath, path->Length+1);
+
     RtlCopyBytes(tmppath,path->Buffer, path->Length);
 
     status = STATUS_WMI_INSTANCE_NOT_FOUND;
@@ -2078,7 +2094,7 @@ SessionExecuteGetChildren(UCHAR *InBuffer,
 
         WriteCountedUTF8String(fullpath, valuepos);
         valuepos+=GetCountedUtf8Size(fullpath);
-        ExFreePool(fullpath);
+        WmiFree(fullpath);
         for (;*nextresults!=0;nextresults++);
         nextresults++;
         i++;
@@ -2092,7 +2108,7 @@ fail3:
     XENBUS_STORE(Free, &fdoData->StoreInterface, listresults);
 
 fail2:
-    ExFreePool(tmppath);
+    WmiFree(tmppath);
 
 fail1:
     FreeUTF8String(path);
@@ -2284,13 +2300,12 @@ SessionExecuteGetValue(UCHAR *InBuffer,
         return status;;
 
     status = STATUS_INSUFFICIENT_RESOURCES;
-    tmppath = ExAllocatePoolWithTag(NonPagedPool,path->Length+1,'XenP');
+    tmppath = WmiAllocate(path->Length + 1);
     if (!tmppath) {
         goto fail1;
     }
-    RtlZeroMemory(tmppath, path->Length+1);
-    RtlCopyBytes(tmppath,path->Buffer, path->Length);
 
+    RtlCopyBytes(tmppath,path->Buffer, path->Length);
 
     status = STATUS_WMI_INSTANCE_NOT_FOUND;
     if ((session = FindSessionByInstanceAndLock(fdoData, instance)) ==
@@ -2317,7 +2332,7 @@ fail3:
     *byteswritten = RequiredSize;
 
 fail2:
-    ExFreePool(tmppath);
+    WmiFree(tmppath);
 
 fail1:
     FreeUTF8String(path);
@@ -2615,7 +2630,7 @@ GenerateSessionBlock(UCHAR *Buffer,
         UCHAR *sesbuf;
         UCHAR *inamebuf;
 
-        AccessWmiBuffer((PUCHAR)nodesizerequired, FALSE, &RequiredSize, 0,
+        (VOID) AccessWmiBuffer((PUCHAR)nodesizerequired, FALSE, &RequiredSize, 0,
                         WMI_UINT32, &id,
                         WMI_STRING,
                             GetCountedUnicodeStringSize(&session->stringid),
@@ -2623,7 +2638,7 @@ GenerateSessionBlock(UCHAR *Buffer,
                         WMI_DONE);
         nodesizerequired += RequiredSize;
 
-        AccessWmiBuffer((PUCHAR)namesizerequired, FALSE, &RequiredSize, 0,
+        (VOID) AccessWmiBuffer((PUCHAR)namesizerequired, FALSE, &RequiredSize, 0,
                         WMI_STRING,
                             GetCountedUnicodeStringSize(&session->instancename),
                             &inamebuf,
@@ -2665,7 +2680,7 @@ GenerateSessionBlock(UCHAR *Buffer,
             UCHAR *sesbuf;
             UCHAR *inamebuf;
 
-            AccessWmiBuffer(datapos, FALSE, &RequiredSize, BufferSize+Buffer-datapos,
+            (VOID) AccessWmiBuffer(datapos, FALSE, &RequiredSize, BufferSize+Buffer-datapos,
                             WMI_UINT32, &id,
                             WMI_STRING,
                                 GetCountedUnicodeStringSize(&session->stringid),
@@ -2680,7 +2695,7 @@ GenerateSessionBlock(UCHAR *Buffer,
             WriteCountedUnicodeString(&session->stringid, sesbuf);
             datapos+=RequiredSize;
 
-            AccessWmiBuffer(namepos, FALSE, &RequiredSize, BufferSize+Buffer-namepos,
+            (VOID) AccessWmiBuffer(namepos, FALSE, &RequiredSize, BufferSize+Buffer-namepos,
                             WMI_STRING,
                                 GetCountedUnicodeStringSize(&session->instancename),
                                 &inamebuf,