#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)
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;
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;
// 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;
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");
fail7:
Error("Fail7\n");
RtlZeroMemory(Context, sizeof(XENIFACE_GRANT_CONTEXT));
- ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+ __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
fail6:
Error("Fail6\n");
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
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;
fail7:
Error("Fail7\n");
RtlZeroMemory(Context, sizeof(XENIFACE_MAP_CONTEXT));
- ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+ __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
fail6:
Error("Fail6\n");
ASSERT(NT_SUCCESS(status));
RtlZeroMemory(Context, sizeof(XENIFACE_MAP_CONTEXT));
- ExFreePoolWithTag(Context, XENIFACE_POOL_TAG);
+ __FreePoolWithTag(Context, XENIFACE_POOL_TAG);
}
DECLSPEC_NOINLINE
#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)
bytecount += CountUtf8FromUtf32(utf32);
}
- *utf8 = ExAllocatePoolWithTag(NonPagedPool, sizeof(UTF8_STRING)+bytecount, 'XIU8');
+ *utf8 = WmiAllocate(sizeof(UTF8_STRING) + bytecount);
if ((*utf8) == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
}
void FreeUTF8String(UTF8_STRING *utf8) {
- ExFreePoolWithTag(utf8, 'XIU8');
+ WmiFree(utf8);
}
NTSTATUS GetCountedUTF8String(UTF8_STRING **utf8, 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;
}
RtlInitUnicodeString(&unicode, buffer);
status = WriteCountedUnicodeString(&unicode, location);
- ExFreePoolWithTag(buffer, 'XSUc');
+ WmiFree(buffer);
return status;
}
}
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;
}
void FreeUnicodeStringBuffer(UNICODE_STRING *string) {
if (string->Buffer)
- ExFreePoolWithTag(string->Buffer, 'XIUC');
+ WmiFree(string->Buffer);
string->Length=0;
string->MaximumLength=0;
string->Buffer = NULL;
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);
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;
if (watch->finished) {
FreeUnicodeStringBuffer(&watch->path);
RemoveEntryList((LIST_ENTRY*)watch);
- ExFreePool(watch);
+ WmiFree(watch);
session->mapchanged = TRUE;
session->watchcount --;
} else if (!session->suspended &&
watch=(XenStoreWatch *)session->watches.Flink) {
FreeUnicodeStringBuffer(&watch->path);
RemoveEntryList((LIST_ENTRY*)watch);
- ExFreePool(watch);
+ WmiFree(watch);
session->mapchanged = TRUE;
session->watchcount --;
}
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;
status = StartWatch(fdoData, *watch);
if ((!NT_SUCCESS(status)) || ((*watch)->watchhandle == NULL)) {
- ExFreePool(*watch);
+ WmiFree(*watch);
return STATUS_INSUFFICIENT_RESOURCES;
}
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;
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);
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++;
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);
ObDereferenceObject(session->WatchThread);
FreeUnicodeStringBuffer(&session->stringid);
FreeUnicodeStringBuffer(&session->instancename);
- ExFreePool(session);
+ WmiFree(session);
}
void
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;
UnlockSessions(fdoData);
fail2:
- ExFreePool(tmpbuffer);
+ WmiFree(tmpbuffer);
fail1:
FreeUTF8String(pathname);
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;
UnlockSessions(fdoData);
fail4:
- ExFreePool(tmpvalue);
+ WmiFree(tmpvalue);
fail3:
FreeUTF8String(value);
fail2:
- ExFreePool(tmppath);
+ WmiFree(tmppath);
fail1:
FreeUTF8String(pathname);
}
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;
WriteCountedUTF8String(fullpath, valuepos);
valuepos+=GetCountedUtf8Size(fullpath);
- ExFreePool(fullpath);
+ WmiFree(fullpath);
}
else {
WriteCountedUTF8String("", valuepos);
*byteswritten = RequiredSize;
fail2:
- ExFreePool(tmppath);
+ WmiFree(tmppath);
fail1:
FreeUTF8String(path);
}
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)) ==
}
WriteCountedUTF8String(fullpath, valuepos);
- ExFreePool(fullpath);
+ WmiFree(fullpath);
}
else {
WriteCountedUTF8String("", valuepos);
XENBUS_STORE(Free, &fdoData->StoreInterface, listresults);
fail3:
- ExFreePool(tmpleaf);
+ WmiFree(tmpleaf);
fail2:
- ExFreePool(tmppath);
+ WmiFree(tmppath);
fail1:
FreeUTF8String(path);
}
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;
WriteCountedUTF8String(fullpath, valuepos);
valuepos+=GetCountedUtf8Size(fullpath);
- ExFreePool(fullpath);
+ WmiFree(fullpath);
for (;*nextresults!=0;nextresults++);
nextresults++;
i++;
XENBUS_STORE(Free, &fdoData->StoreInterface, listresults);
fail2:
- ExFreePool(tmppath);
+ WmiFree(tmppath);
fail1:
FreeUTF8String(path);
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)) ==
*byteswritten = RequiredSize;
fail2:
- ExFreePool(tmppath);
+ WmiFree(tmppath);
fail1:
FreeUTF8String(path);
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),
WMI_DONE);
nodesizerequired += RequiredSize;
- AccessWmiBuffer((PUCHAR)namesizerequired, FALSE, &RequiredSize, 0,
+ (VOID) AccessWmiBuffer((PUCHAR)namesizerequired, FALSE, &RequiredSize, 0,
WMI_STRING,
GetCountedUnicodeStringSize(&session->instancename),
&inamebuf,
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),
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,