|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 2/3] xeniface: Sync common helper files with xenbus
Take assert.h, dbg_print.h (as log.h), mutex.h, util.h, registry.c/h
and thread.c/h from xenbus, keeping the XENIFACE_MUTEX type name and
RegistryGetPath(). This brings TryAcquireMutex, PCSTR log format
strings and the updated direction and buffer-size annotations.
Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
src/xeniface/assert.h | 18 ++++-----
src/xeniface/log.h | 82 ++++++++++++++++++++++++-----------------
src/xeniface/mutex.h | 39 ++++++++++++++++++--
src/xeniface/names.h | 18 ++++-----
src/xeniface/registry.c | 26 ++++++-------
src/xeniface/registry.h | 16 ++++----
src/xeniface/thread.c | 20 +++++-----
src/xeniface/thread.h | 6 +--
src/xeniface/util.h | 36 +++++++++---------
9 files changed, 153 insertions(+), 108 deletions(-)
diff --git a/src/xeniface/assert.h b/src/xeniface/assert.h
index dfac6e1..a5f2f2e 100644
--- a/src/xeniface/assert.h
+++ b/src/xeniface/assert.h
@@ -154,13 +154,13 @@ __Bug(
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
)
{
- ULONG Offset;
+ ULONG Offset;
Offset = 0;
while (Offset < Length) {
@@ -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/xeniface/log.h b/src/xeniface/log.h
index 523a4af..21543ff 100644
--- a/src/xeniface/log.h
+++ b/src/xeniface/log.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.
*/
@@ -36,16 +36,16 @@
#include <ntddk.h>
#include <stdarg.h>
-#pragma warning(disable:4127) // conditional expression is constant
-
#define stringify_literal(_text) #_text
#define stringify(_text) stringify_literal(_text)
#define __MODULE__ stringify(PROJECT)
+#pragma warning(disable:4127) // conditional expression is constant
+
static __inline VOID
__Error(
- _In_ const CHAR *Prefix,
- _In_ const CHAR *Format,
+ _In_ PCSTR Prefix,
+ _In_ PCSTR Format,
...
)
{
@@ -67,8 +67,8 @@ __Error(
static __inline VOID
__Warning(
- _In_ const CHAR *Prefix,
- _In_ const CHAR *Format,
+ _In_ PCSTR Prefix,
+ _In_ PCSTR Format,
...
)
{
@@ -91,8 +91,8 @@ __Warning(
#if DBG
static __inline VOID
__Trace(
- _In_ const CHAR *Prefix,
- _In_ const CHAR *Format,
+ _In_ PCSTR Prefix,
+ _In_ PCSTR Format,
...
)
{
@@ -117,8 +117,8 @@ __Trace(
static __inline VOID
__Info(
- _In_ const CHAR *Prefix,
- _In_ const CHAR *Format,
+ _In_ PCSTR Prefix,
+ _In_ PCSTR Format,
...
)
{
@@ -138,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 // _XENIFACE_LOG_H
diff --git a/src/xeniface/mutex.h b/src/xeniface/mutex.h
index 966206d..5609582 100644
--- a/src/xeniface/mutex.h
+++ b/src/xeniface/mutex.h
@@ -44,7 +44,7 @@ typedef struct _XENIFACE_MUTEX {
static FORCEINLINE VOID
InitializeMutex(
- _In_ PXENIFACE_MUTEX Mutex
+ _Out_ PXENIFACE_MUTEX Mutex
)
{
RtlZeroMemory(Mutex, sizeof (XENIFACE_MUTEX));
@@ -52,18 +52,49 @@ InitializeMutex(
KeInitializeEvent(&Mutex->Event, SynchronizationEvent, TRUE);
}
+static FORCEINLINE BOOLEAN
+_IRQL_requires_max_(PASSIVE_LEVEL)
+TryAcquireMutex(
+ _Inout_ PXENIFACE_MUTEX 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_ PXENIFACE_MUTEX Mutex
+ _Inout_ PXENIFACE_MUTEX Mutex
)
{
- (VOID) KeWaitForSingleObject(&Mutex->Event,
+ 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_ PXENIFACE_MUTEX Mutex
+ _Inout_ PXENIFACE_MUTEX Mutex
)
{
ASSERT3P(Mutex->Owner, ==, KeGetCurrentThread());
diff --git a/src/xeniface/names.h b/src/xeniface/names.h
index 37d196d..20e4695 100644
--- a/src/xeniface/names.h
+++ b/src/xeniface/names.h
@@ -37,7 +37,7 @@
#include "types.h"
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerTypeName(
_In_ POWER_STATE_TYPE Type
)
@@ -57,7 +57,7 @@ PowerTypeName(
#undef _POWER_ACTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerSystemStateName(
_In_ SYSTEM_POWER_STATE State
)
@@ -83,7 +83,7 @@ PowerSystemStateName(
#undef _POWER_SYSTEM_STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerDeviceStateName(
_In_ DEVICE_POWER_STATE State
)
@@ -107,7 +107,7 @@ PowerDeviceStateName(
#undef _POWER_DEVICE_STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PowerActionName(
_In_ POWER_ACTION Type
)
@@ -133,7 +133,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
PnpDeviceStateName(
_In_ DEVICE_PNP_STATE State
)
@@ -182,7 +182,7 @@ PnpDeviceStateName(
#undef _STATE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PnpMinorFunctionName(
_In_ ULONG Function
)
@@ -225,7 +225,7 @@ PnpMinorFunctionName(
#undef _PNP_MINOR_FUNCTION_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
PartialResourceDescriptorTypeName(
_In_ UCHAR Type
)
@@ -254,7 +254,7 @@ PartialResourceDescriptorTypeName(
#undef _PARTIAL_RESOURCE_DESCRIPTOR_TYPE_NAME
}
-static FORCEINLINE const CHAR *
+static FORCEINLINE PCSTR
DeviceUsageTypeName(
_In_ DEVICE_USAGE_NOTIFICATION_TYPE Type
)
diff --git a/src/xeniface/registry.c b/src/xeniface/registry.c
index 9789db9..8f631ff 100644
--- a/src/xeniface/registry.c
+++ b/src/xeniface/registry.c
@@ -1169,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);
@@ -1256,7 +1256,7 @@ NTSTATUS
RegistryUpdateBinaryValue(
_In_ HANDLE Key,
_In_ PSTR Name,
- _In_ PVOID Buffer,
+ _In_reads_bytes_(Length) PVOID Buffer,
_In_ ULONG Length
)
{
@@ -1444,7 +1444,7 @@ fail1:
static PKEY_VALUE_PARTIAL_INFORMATION
RegistryAnsiToSz(
- PANSI_STRING Ansi
+ _In_ PANSI_STRING Ansi
)
{
ULONG Length;
@@ -1490,7 +1490,7 @@ fail1:
static PKEY_VALUE_PARTIAL_INFORMATION
RegistryAnsiToMultiSz(
- PANSI_STRING Ansi
+ _In_ PANSI_STRING Ansi
)
{
ULONG Length;
@@ -1649,4 +1649,4 @@ RegistryGetPath(
)
{
return &RegistryPath;
-}
\ No newline at end of file
+}
diff --git a/src/xeniface/registry.h b/src/xeniface/registry.h
index 867aefc..de16ac1 100644
--- a/src/xeniface/registry.h
+++ b/src/xeniface/registry.h
@@ -166,18 +166,18 @@ 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
RegistryUpdateBinaryValue(
- _In_ HANDLE Key,
- _In_ PSTR Name,
- _In_ PVOID Buffer,
- _In_ ULONG Length
+ _In_ HANDLE Key,
+ _In_ PSTR Name,
+ _In_reads_bytes_(Length) PVOID Buffer,
+ _In_ ULONG Length
);
extern NTSTATUS
diff --git a/src/xeniface/thread.c b/src/xeniface/thread.c
index 6905d29..0f144fe 100644
--- a/src/xeniface/thread.c
+++ b/src/xeniface/thread.c
@@ -33,11 +33,11 @@
#include <ntddk.h>
#include "thread.h"
-#include "util.h"
#include "log.h"
#include "assert.h"
+#include "util.h"
-#define THREAD_POOL 'ERHT'
+#define THREAD_TAG 'ERHT'
struct _XENIFACE_THREAD {
XENIFACE_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,12 +61,12 @@ __ThreadFree(
_In_ PVOID Buffer
)
{
- __FreePoolWithTag(Buffer, THREAD_POOL);
+ __FreePoolWithTag(Buffer, THREAD_TAG);
}
static FORCEINLINE VOID
__ThreadWake(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
)
{
KeSetEvent(&Thread->Event, IO_NO_INCREMENT, FALSE);
@@ -74,7 +74,7 @@ __ThreadWake(
VOID
ThreadWake(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
)
{
__ThreadWake(Thread);
@@ -82,7 +82,7 @@ ThreadWake(
static FORCEINLINE VOID
__ThreadAlert(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
)
{
Thread->Alerted = TRUE;
@@ -91,7 +91,7 @@ __ThreadAlert(
VOID
ThreadAlert(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
)
{
__ThreadAlert(Thread);
@@ -131,8 +131,6 @@ ThreadCreate(
(*Thread) = __ThreadAllocate(sizeof (XENIFACE_THREAD));
- Trace("Create thread %p %p\n", Function, Thread);
-
status = STATUS_NO_MEMORY;
if (*Thread == NULL)
goto fail1;
@@ -207,7 +205,7 @@ ThreadIsAlerted(
VOID
ThreadJoin(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
)
{
LONG References;
diff --git a/src/xeniface/thread.h b/src/xeniface/thread.h
index 5047d9f..02ac35e 100644
--- a/src/xeniface/thread.h
+++ b/src/xeniface/thread.h
@@ -59,17 +59,17 @@ ThreadIsAlerted(
extern VOID
ThreadWake(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
);
extern VOID
ThreadAlert(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
);
extern VOID
ThreadJoin(
- _In_ PXENIFACE_THREAD Thread
+ _Inout_ PXENIFACE_THREAD Thread
);
#endif // _XENIFACE_THREAD_H
diff --git a/src/xeniface/util.h b/src/xeniface/util.h
index 9709a10..db40d4f 100644
--- a/src/xeniface/util.h
+++ b/src/xeniface/util.h
@@ -113,12 +113,12 @@ __CpuId(
static FORCEINLINE LONG
__InterlockedAdd(
- _In_ LONG *Value,
- _In_ LONG Delta
+ _Inout_ LONG *Value,
+ _In_ LONG Delta
)
{
- LONG New;
- LONG Old;
+ LONG New;
+ LONG Old;
do {
Old = *Value;
@@ -130,12 +130,12 @@ __InterlockedAdd(
static FORCEINLINE LONG
__InterlockedSubtract(
- _In_ LONG *Value,
- _In_ LONG Delta
+ _Inout_ LONG *Value,
+ _In_ LONG Delta
)
{
- LONG New;
- LONG Old;
+ LONG New;
+ LONG Old;
do {
Old = *Value;
@@ -281,15 +281,15 @@ __FreePages(
static FORCEINLINE PSTR
__strtok_r(
- _In_opt_ PSTR Buffer,
- _In_ PSTR Delimiter,
+ _Inout_opt_ PSTR Buffer,
+ _In_ PSTR Delimiter,
_When_(Buffer != NULL, _Outptr_)
_When_(Buffer == NULL, _Inout_)
- PSTR *Context
+ PSTR *Context
)
{
- PSTR Token;
- PSTR End;
+ PSTR Token;
+ PSTR End;
if (Buffer != NULL)
*Context = Buffer;
@@ -321,15 +321,15 @@ __strtok_r(
static FORCEINLINE PWSTR
__wcstok_r(
- _In_opt_ PWSTR Buffer,
- _In_ PWSTR Delimiter,
+ _Inout_opt_ PWSTR Buffer,
+ _In_ PWSTR Delimiter,
_When_(Buffer != NULL, _Outptr_)
_When_(Buffer == NULL, _Inout_)
- PWSTR *Context
+ PWSTR *Context
)
{
- PWSTR Token;
- PWSTR End;
+ PWSTR Token;
+ PWSTR End;
if (Buffer != NULL)
*Context = Buffer;
--
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 |