|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XENVKBD-SYNC] xenvkbd: Sync common helper files with xenbus
Take assert.h, dbg_print.h, mutex.h, util.h, registry.c/h and
thread.c/h from xenbus. This brings TryAcquireMutex, the TIME_* macros,
the Contiguous parameter of __AllocatePages, RegistryOpenParametersKey,
RegistryQueryQwordValue and the IoOpenDriverRegistryKey support of
RegistryInitialize, which now takes the driver object, along with the
updated annotations.
Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
src/xenvkbd/assert.h | 8 ++--
src/xenvkbd/dbg_print.h | 63 ++++++++++++++++-----------
src/xenvkbd/driver.c | 2 +-
src/xenvkbd/mutex.h | 93 ++++++++++++++++++++++++++--------------
src/xenvkbd/names.h | 24 +++++------
src/xenvkbd/registry.c | 52 ++++++++++++++---------
src/xenvkbd/registry.h | 94 +++++++++++++++++++++++------------------
src/xenvkbd/thread.c | 6 +--
src/xenvkbd/util.h | 23 +++++++---
9 files changed, 226 insertions(+), 139 deletions(-)
diff --git a/src/xenvkbd/assert.h b/src/xenvkbd/assert.h
index c5fab23..2106c0d 100644
--- a/src/xenvkbd/assert.h
+++ b/src/xenvkbd/assert.h
@@ -178,10 +178,10 @@ _IsZeroMemory(
static __inline BOOLEAN
_IsZeroMemory(
- _In_ PCSTR Caller,
- _In_ PCSTR Name,
- _In_ PVOID Buffer,
- _In_ ULONG Length
+ _In_ PCSTR Caller,
+ _In_ PCSTR Name,
+ _In_reads_bytes_(Length) PVOID Buffer,
+ _In_ ULONG Length
)
{
UNREFERENCED_PARAMETER(Caller);
diff --git a/src/xenvkbd/dbg_print.h b/src/xenvkbd/dbg_print.h
index 6ab4606..e38a6ab 100644
--- a/src/xenvkbd/dbg_print.h
+++ b/src/xenvkbd/dbg_print.h
@@ -1,32 +1,32 @@
/* Copyright (c) Xen Project.
* Copyright (c) Cloud Software Group, Inc.
* All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
* that the following conditions are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
* following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
* materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
@@ -89,7 +89,6 @@ __Warning(
__Warning(__MODULE__ "|" __FUNCTION__ ": ", __VA_ARGS__)
#if DBG
-
static __inline VOID
__Trace(
_In_ PCSTR Prefix,
@@ -139,4 +138,20 @@ __Info(
#define Info(...) \
__Info(__MODULE__ "|" __FUNCTION__ ": ", __VA_ARGS__)
+#define DBG_PRINT_ENABLE_FILTER(_Id, _Level) \
+ do { \
+ DbgSetDebugFilterState((_Id), (_Level), TRUE); \
+ } while (FALSE)
+
+static __inline VOID
+__DbgPrintEnable(
+ VOID
+ )
+{
+ DBG_PRINT_ENABLE_FILTER(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL);
+ DBG_PRINT_ENABLE_FILTER(DPFLTR_IHVDRIVER_ID, DPFLTR_WARNING_LEVEL);
+ DBG_PRINT_ENABLE_FILTER(DPFLTR_IHVDRIVER_ID, DPFLTR_TRACE_LEVEL);
+ DBG_PRINT_ENABLE_FILTER(DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL);
+}
+
#endif // _XENVKBD_DBG_PRINT_H
diff --git a/src/xenvkbd/driver.c b/src/xenvkbd/driver.c
index c35f9c6..0cab7a8 100644
--- a/src/xenvkbd/driver.c
+++ b/src/xenvkbd/driver.c
@@ -364,7 +364,7 @@ DriverEntry(
MONTH,
YEAR);
- status = RegistryInitialize(RegistryPath);
+ status = RegistryInitialize(DriverObject, RegistryPath);
if (!NT_SUCCESS(status))
goto fail1;
diff --git a/src/xenvkbd/mutex.h b/src/xenvkbd/mutex.h
index 9e66475..1bd9c8d 100644
--- a/src/xenvkbd/mutex.h
+++ b/src/xenvkbd/mutex.h
@@ -1,32 +1,32 @@
/* Copyright (c) Xen Project.
* Copyright (c) Cloud Software Group, Inc.
* All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
* that the following conditions are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
* following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
* materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
@@ -44,7 +44,7 @@ typedef struct _MUTEX {
static FORCEINLINE VOID
InitializeMutex(
- _In_ PMUTEX Mutex
+ _Out_ PMUTEX Mutex
)
{
RtlZeroMemory(Mutex, sizeof (MUTEX));
@@ -52,17 +52,48 @@ InitializeMutex(
KeInitializeEvent(&Mutex->Event, SynchronizationEvent, TRUE);
}
+static FORCEINLINE BOOLEAN
+_IRQL_requires_max_(PASSIVE_LEVEL)
+TryAcquireMutex(
+ _Inout_ PMUTEX Mutex
+ )
+{
+ LARGE_INTEGER Timeout;
+ NTSTATUS status;
+
+ Timeout.QuadPart = 0;
+
+ status = KeWaitForSingleObject(&Mutex->Event,
+ Executive,
+ KernelMode,
+ FALSE,
+ &Timeout);
+ if (status == STATUS_TIMEOUT)
+ return FALSE;
+
+ ASSERT(NT_SUCCESS(status));
+
+ ASSERT3P(Mutex->Owner, ==, NULL);
+ Mutex->Owner = KeGetCurrentThread();
+
+ return TRUE;
+}
+
static FORCEINLINE VOID
_IRQL_requires_max_(PASSIVE_LEVEL)
AcquireMutex(
- _In_ PMUTEX Mutex
+ _Inout_ PMUTEX Mutex
)
{
- (VOID) KeWaitForSingleObject(&Mutex->Event,
- Executive,
- KernelMode,
- FALSE,
- NULL);
+ NTSTATUS status;
+
+ status = KeWaitForSingleObject(&Mutex->Event,
+ Executive,
+ KernelMode,
+ FALSE,
+ NULL);
+
+ ASSERT(NT_SUCCESS(status));
ASSERT3P(Mutex->Owner, ==, NULL);
Mutex->Owner = KeGetCurrentThread();
@@ -71,7 +102,7 @@ AcquireMutex(
static FORCEINLINE VOID
_IRQL_requires_max_(PASSIVE_LEVEL)
ReleaseMutex(
- _In_ PMUTEX Mutex
+ _Inout_ PMUTEX Mutex
)
{
ASSERT3P(Mutex->Owner, ==, KeGetCurrentThread());
diff --git a/src/xenvkbd/names.h b/src/xenvkbd/names.h
index c651210..0de488e 100644
--- a/src/xenvkbd/names.h
+++ b/src/xenvkbd/names.h
@@ -36,7 +36,7 @@
#include <ntddk.h>
#include <xen.h>
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerTypeName(
_In_ POWER_STATE_TYPE Type
)
@@ -56,7 +56,7 @@ PowerTypeName(
#undef _POWER_ACTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerSystemStateName(
_In_ SYSTEM_POWER_STATE State
)
@@ -82,7 +82,7 @@ PowerSystemStateName(
#undef _POWER_SYSTEM_STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerDeviceStateName(
_In_ DEVICE_POWER_STATE State
)
@@ -106,7 +106,7 @@ PowerDeviceStateName(
#undef _POWER_DEVICE_STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerActionName(
_In_ POWER_ACTION Type
)
@@ -132,7 +132,7 @@ PowerActionName(
#undef _POWER_ACTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerMinorFunctionName(
_In_ ULONG MinorFunction
)
@@ -155,7 +155,7 @@ PowerMinorFunctionName(
#undef _POWER_MINOR_FUNCTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PnpMinorFunctionName(
_In_ ULONG Function
)
@@ -198,7 +198,7 @@ PnpMinorFunctionName(
#undef _PNP_MINOR_FUNCTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PartialResourceDescriptorTypeName(
_In_ UCHAR Type
)
@@ -227,7 +227,7 @@ PartialResourceDescriptorTypeName(
#undef _PARTIAL_RESOURCE_DESCRIPTOR_TYPE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
DeviceUsageTypeName(
_In_ DEVICE_USAGE_NOTIFICATION_TYPE Type
)
@@ -249,7 +249,7 @@ DeviceUsageTypeName(
#undef _DEVICE_USAGE_TYPE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
InterfaceTypeName(
_In_ INTERFACE_TYPE Type
)
@@ -287,7 +287,7 @@ InterfaceTypeName(
#undef _INTERFACE_TYPE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
DmaWidthName(
_In_ DMA_WIDTH Width
)
@@ -311,7 +311,7 @@ DmaWidthName(
#undef _DMA_WIDTH_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
DmaSpeedName(
_In_ DMA_SPEED Speed
)
@@ -336,7 +336,7 @@ DmaSpeedName(
#undef _DMA_SPEED_NAME
}
-static FORCEINLINE const PCHAR
+static FORCEINLINE PCSTR
XenbusStateName(
_In_ XenbusState State
)
diff --git a/src/xenvkbd/registry.c b/src/xenvkbd/registry.c
index 5cc6b99..d576990 100644
--- a/src/xenvkbd/registry.c
+++ b/src/xenvkbd/registry.c
@@ -62,11 +62,15 @@ __RegistryFree(
}
NTSTATUS
+#pragma prefast(suppress:28101) // unannotated DriverEntry function
RegistryInitialize(
+ _In_opt_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING Path
)
{
- NTSTATUS status;
+ UNICODE_STRING Unicode;
+ PVOID Func;
+ NTSTATUS status;
ASSERT3P(RegistryPath.Buffer, ==, NULL);
@@ -74,6 +78,16 @@ RegistryInitialize(
if (!NT_SUCCESS(status))
goto fail1;
+ ASSERT3P(RegistryDriverObject, ==, NULL);
+ RegistryDriverObject = DriverObject;
+
+ ASSERT3P(__IoOpenDriverRegistryKey, ==, NULL);
+ RtlInitUnicodeString(&Unicode, L"IoOpenDriverRegistryKey");
+
+ Func = MmGetSystemRoutineAddress(&Unicode);
+ if (Func != NULL)
+ __IoOpenDriverRegistryKey = (IOOPENDRIVERREGISTRYKEY)Func;
+
return STATUS_SUCCESS;
fail1:
@@ -152,8 +166,8 @@ RegistryOpenKey(
_Out_ PHANDLE Key
)
{
- OBJECT_ATTRIBUTES Attributes;
- NTSTATUS status;
+ OBJECT_ATTRIBUTES Attributes;
+ NTSTATUS status;
InitializeObjectAttributes(&Attributes,
Path,
@@ -214,13 +228,13 @@ RegistryCreateKey(
_Out_ PHANDLE Key
)
{
- PWCHAR Buffer;
- HANDLE Root;
- PWCHAR ChildPath;
- PWCHAR ChildName;
- PWCHAR Context;
- HANDLE Child;
- NTSTATUS status;
+ PWSTR Buffer;
+ HANDLE Root;
+ PWSTR ChildPath;
+ PWSTR ChildName;
+ PWSTR Context;
+ HANDLE Child;
+ NTSTATUS status;
//
// UNICODE_STRINGs are not guaranteed to have NUL terminated
@@ -1155,17 +1169,17 @@ fail1:
NTSTATUS
RegistryQueryBinaryValue(
- _In_ HANDLE Key,
- _In_ PSTR Name,
- _Outptr_ PVOID *Buffer,
- _Out_ PULONG Length
+ _In_ HANDLE Key,
+ _In_ PSTR Name,
+ _Outptr_result_bytebuffer_(*Length) PVOID *Buffer,
+ _Out_ PULONG Length
)
{
- ANSI_STRING Ansi;
- UNICODE_STRING Unicode;
- PKEY_VALUE_PARTIAL_INFORMATION Partial;
- ULONG Size;
- NTSTATUS status;
+ ANSI_STRING Ansi;
+ UNICODE_STRING Unicode;
+ PKEY_VALUE_PARTIAL_INFORMATION Partial;
+ ULONG Size;
+ NTSTATUS status;
RtlInitAnsiString(&Ansi, Name);
diff --git a/src/xenvkbd/registry.h b/src/xenvkbd/registry.h
index 4535747..9591468 100644
--- a/src/xenvkbd/registry.h
+++ b/src/xenvkbd/registry.h
@@ -1,32 +1,32 @@
/* Copyright (c) Xen Project.
* Copyright (c) Cloud Software Group, Inc.
* All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
* that the following conditions are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
* following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
* materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
@@ -37,6 +37,7 @@
extern NTSTATUS
RegistryInitialize(
+ _In_opt_ PDRIVER_OBJECT DrvObj,
_In_ PUNICODE_STRING Path
);
@@ -45,6 +46,12 @@ RegistryTeardown(
VOID
);
+extern NTSTATUS
+RegistryOpenParametersKey(
+ _In_ ACCESS_MASK DesiredAccess,
+ _Out_ PHANDLE Key
+ );
+
extern NTSTATUS
RegistryOpenKey(
_In_opt_ HANDLE Parent,
@@ -104,8 +111,8 @@ RegistryCreateSubKey(
extern NTSTATUS
RegistryDeleteSubKey(
- _In_ HANDLE Key,
- _In_ PSTR Name
+ _In_ HANDLE Key,
+ _In_ PSTR Name
);
extern NTSTATUS
@@ -124,24 +131,31 @@ RegistryEnumerateValues(
extern NTSTATUS
RegistryDeleteValue(
- _In_ HANDLE Key,
- _In_ PSTR Name
+ _In_ HANDLE Key,
+ _In_ PSTR Name
);
extern NTSTATUS
RegistryQueryDwordValue(
- _In_ HANDLE Key,
- _In_ PSTR Name,
- _Out_ PULONG Value
+ _In_ HANDLE Key,
+ _In_ PSTR Name,
+ _Out_ PULONG Value
);
-
+
+extern NTSTATUS
+RegistryQueryQwordValue(
+ _In_ HANDLE Key,
+ _In_ PSTR Name,
+ _Out_ PULONGLONG Value
+ );
+
extern NTSTATUS
RegistryUpdateDwordValue(
- _In_ HANDLE Key,
- _In_ PSTR Name,
- _In_ ULONG Value
+ _In_ HANDLE Key,
+ _In_ PSTR Name,
+ _In_ ULONG Value
);
-
+
extern NTSTATUS
RegistryQuerySzValue(
_In_ HANDLE Key,
@@ -152,10 +166,10 @@ RegistryQuerySzValue(
extern NTSTATUS
RegistryQueryBinaryValue(
- _In_ HANDLE Key,
- _In_ PSTR Name,
- _Outptr_ PVOID *Buffer,
- _Out_ PULONG Length
+ _In_ HANDLE Key,
+ _In_ PSTR Name,
+ _Outptr_result_bytebuffer_(*Length) PVOID *Buffer,
+ _Out_ PULONG Length
);
extern NTSTATUS
@@ -185,7 +199,7 @@ RegistryFreeSzValue(
extern VOID
RegistryFreeBinaryValue(
- _In_ PVOID Buffer
+ _In_ PVOID Buffer
);
extern NTSTATUS
diff --git a/src/xenvkbd/thread.c b/src/xenvkbd/thread.c
index 68178d4..2f1427d 100644
--- a/src/xenvkbd/thread.c
+++ b/src/xenvkbd/thread.c
@@ -37,7 +37,7 @@
#include "assert.h"
#include "util.h"
-#define THREAD_POOL 'ERHT'
+#define THREAD_TAG 'ERHT'
struct _XENVKBD_THREAD {
XENVKBD_THREAD_FUNCTION Function;
@@ -53,7 +53,7 @@ __ThreadAllocate(
_In_ ULONG Length
)
{
- return __AllocatePoolWithTag(NonPagedPool, Length, THREAD_POOL);
+ return __AllocatePoolWithTag(NonPagedPool, Length, THREAD_TAG);
}
static FORCEINLINE VOID
@@ -61,7 +61,7 @@ __ThreadFree(
_In_ PVOID Buffer
)
{
- __FreePoolWithTag(Buffer, THREAD_POOL);
+ __FreePoolWithTag(Buffer, THREAD_TAG);
}
static FORCEINLINE VOID
diff --git a/src/xenvkbd/util.h b/src/xenvkbd/util.h
index 431f433..2c94d63 100644
--- a/src/xenvkbd/util.h
+++ b/src/xenvkbd/util.h
@@ -41,6 +41,11 @@
#define P2ROUNDUP(_t, _x, _a) \
(-(-((_t)(_x)) & -(((_t)(_a)))))
+#define TIME_US(_us) ((_us) * 10ll)
+#define TIME_MS(_ms) (TIME_US((_ms) * 1000ll))
+#define TIME_S(_s) (TIME_MS((_s) * 1000ll))
+#define TIME_RELATIVE(_t) (-(_t))
+
static FORCEINLINE LONG
__ffs(
_In_ unsigned long long mask
@@ -89,7 +94,7 @@ __CpuId(
_Out_opt_ PULONG EDX
)
{
- int Value[4] = {0};
+ int Value[4] = {0};
__cpuid(Value, Leaf);
@@ -181,13 +186,15 @@ __FreePoolWithTag(
static FORCEINLINE PMDL
__AllocatePages(
- _In_ ULONG Count
+ _In_ ULONG Count,
+ _In_ BOOLEAN Contiguous
)
{
PHYSICAL_ADDRESS LowAddress;
PHYSICAL_ADDRESS HighAddress;
LARGE_INTEGER SkipBytes;
SIZE_T TotalBytes;
+ ULONG Flags;
PMDL Mdl;
PUCHAR MdlMappedSystemVa;
NTSTATUS status;
@@ -197,12 +204,18 @@ __AllocatePages(
SkipBytes.QuadPart = 0ull;
TotalBytes = (SIZE_T)PAGE_SIZE * Count;
+ if (Contiguous) {
+ Flags = MM_ALLOCATE_REQUIRE_CONTIGUOUS_CHUNKS;
+ } else {
+ Flags = MM_ALLOCATE_FULLY_REQUIRED;
+ }
+
Mdl = MmAllocatePagesForMdlEx(LowAddress,
HighAddress,
SkipBytes,
TotalBytes,
MmCached,
- MM_ALLOCATE_FULLY_REQUIRED);
+ Flags);
status = STATUS_NO_MEMORY;
if (Mdl == NULL)
@@ -246,14 +259,14 @@ fail1:
return NULL;
}
-#define __AllocatePage() __AllocatePages(1)
+#define __AllocatePage() __AllocatePages(1, FALSE)
static FORCEINLINE VOID
__FreePages(
_In_ PMDL Mdl
)
{
- PUCHAR MdlMappedSystemVa;
+ PUCHAR MdlMappedSystemVa;
ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
MdlMappedSystemVa = Mdl->MappedSystemVa;
--
2.55.0.windows.5
--
Césaire Mounah | Vates Windows Guest Tools Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |