|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] xencons: 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 replaces the remaining IN annotations of
mutex.h, brings TryAcquireMutex and annotates the helpers with their
actual direction and buffer sizes.
Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
src/xencons/assert.h | 18 +++----
src/xencons/dbg_print.h | 16 ++++++
src/xencons/mutex.h | 117 +++++++++++++++++++++++++---------------
src/xencons/registry.c | 24 ++++-----
src/xencons/registry.h | 16 +++---
src/xencons/thread.c | 10 ++--
src/xencons/thread.h | 6 +--
src/xencons/util.h | 36 ++++++-------
8 files changed, 145 insertions(+), 98 deletions(-)
diff --git a/src/xencons/assert.h b/src/xencons/assert.h
index 9db2d0c..d99333a 100644
--- a/src/xencons/assert.h
+++ b/src/xencons/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/xencons/dbg_print.h b/src/xencons/dbg_print.h
index 132c051..80b8a24 100644
--- a/src/xencons/dbg_print.h
+++ b/src/xencons/dbg_print.h
@@ -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 // _XENCONS_DBG_PRINT_H
diff --git a/src/xencons/mutex.h b/src/xencons/mutex.h
index c6cd2f9..578165f 100644
--- a/src/xencons/mutex.h
+++ b/src/xencons/mutex.h
@@ -1,34 +1,34 @@
/* 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
-* that the following conditions are met:
-*
-* * 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
-* 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
-* SUCH DAMAGE.
-*/
+ * All rights reserved.
+ *
+ * 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
+ * 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
+ * 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
+ * SUCH DAMAGE.
+ */
#ifndef _XENCONS_MUTEX_H
#define _XENCONS_MUTEX_H
@@ -44,37 +44,68 @@ typedef struct _MUTEX {
static FORCEINLINE VOID
InitializeMutex(
- IN PMUTEX Mutex
-)
+ _Out_ PMUTEX Mutex
+ )
{
- RtlZeroMemory(Mutex, sizeof(MUTEX));
+ RtlZeroMemory(Mutex, sizeof (MUTEX));
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);
+ ASSERT3P(Mutex->Owner, ==, NULL);
Mutex->Owner = KeGetCurrentThread();
}
static FORCEINLINE VOID
_IRQL_requires_max_(PASSIVE_LEVEL)
ReleaseMutex(
- IN PMUTEX Mutex
-)
+ _Inout_ PMUTEX Mutex
+ )
{
- ASSERT3P(Mutex->Owner, == , KeGetCurrentThread());
+ ASSERT3P(Mutex->Owner, ==, KeGetCurrentThread());
Mutex->Owner = NULL;
KeSetEvent(&Mutex->Event, IO_NO_INCREMENT, FALSE);
diff --git a/src/xencons/registry.c b/src/xencons/registry.c
index 4f7c5ef..d576990 100644
--- a/src/xencons/registry.c
+++ b/src/xencons/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;
diff --git a/src/xencons/registry.h b/src/xencons/registry.h
index 170445b..98801d5 100644
--- a/src/xencons/registry.h
+++ b/src/xencons/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/xencons/thread.c b/src/xencons/thread.c
index e8e4a6c..ad30f8f 100644
--- a/src/xencons/thread.c
+++ b/src/xencons/thread.c
@@ -66,7 +66,7 @@ __ThreadFree(
static FORCEINLINE VOID
__ThreadWake(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
)
{
KeSetEvent(&Thread->Event, IO_NO_INCREMENT, FALSE);
@@ -74,7 +74,7 @@ __ThreadWake(
VOID
ThreadWake(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
)
{
__ThreadWake(Thread);
@@ -82,7 +82,7 @@ ThreadWake(
static FORCEINLINE VOID
__ThreadAlert(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
)
{
Thread->Alerted = TRUE;
@@ -91,7 +91,7 @@ __ThreadAlert(
VOID
ThreadAlert(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
)
{
__ThreadAlert(Thread);
@@ -205,7 +205,7 @@ ThreadIsAlerted(
VOID
ThreadJoin(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
)
{
LONG References;
diff --git a/src/xencons/thread.h b/src/xencons/thread.h
index d344cb8..b934e8d 100644
--- a/src/xencons/thread.h
+++ b/src/xencons/thread.h
@@ -59,17 +59,17 @@ ThreadIsAlerted(
extern VOID
ThreadWake(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
);
extern VOID
ThreadAlert(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
);
extern VOID
ThreadJoin(
- _In_ PXENCONS_THREAD Thread
+ _Inout_ PXENCONS_THREAD Thread
);
#endif // _XENCONS_THREAD_H
diff --git a/src/xencons/util.h b/src/xencons/util.h
index 9709a10..db40d4f 100644
--- a/src/xencons/util.h
+++ b/src/xencons/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 |