[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xenhid: Sync common helper files with xenbus


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Date: Thu, 22 Oct 2026 09:31:15 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Delivery-date: Thu, 22 Oct 2026 07:31:32 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Take assert.h, dbg_print.h, util.h and thread.c/h from xenbus. This
replaces __analysis_assume with _Analysis_assume_, uses PCSTR for
read-only strings, drops the Warning-level log of every thread creation
and brings the updated direction and buffer-size annotations.

Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
 src/xenhid/assert.h    | 72 ++++++++++++++++++-------------------
 src/xenhid/dbg_print.h | 81 ++++++++++++++++++++++--------------------
 src/xenhid/names.h     | 18 +++++-----
 src/xenhid/string.c    |  2 +-
 src/xenhid/thread.c    | 20 +++++------
 src/xenhid/thread.h    |  6 ++--
 src/xenhid/util.h      | 36 +++++++++----------
 7 files changed, 118 insertions(+), 117 deletions(-)

diff --git a/src/xenhid/assert.h b/src/xenhid/assert.h
index 3c7398e..d24dbd8 100644
--- a/src/xenhid/assert.h
+++ b/src/xenhid/assert.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.
  */
 
@@ -58,8 +58,8 @@ __Bug(
 
 #define BUG(_TEXT)                                              \
         do {                                                    \
-            const CHAR  *_Text = (_TEXT);                       \
-            const CHAR  *_File = __FILE__;                      \
+            PCSTR       _Text = (_TEXT);                       \
+            PCSTR       _File = __FILE__;                      \
             ULONG       _Line = __LINE__;                       \
                                                                 \
             Error("BUG: " _TEXT "\n");                          \
@@ -89,7 +89,7 @@ __Bug(
 #define ASSERT(_EXP)                    \
         do {                            \
             __ASSERT(_EXP);             \
-            __analysis_assume(_EXP);    \
+            _Analysis_assume_(_EXP);    \
         } while (FALSE)
 
 #define ASSERT3U(_X, _OP, _Y)                       \
@@ -132,7 +132,7 @@ __Bug(
 
 #define ASSERT(_EXP)                    \
         do {                            \
-            __analysis_assume(_EXP);    \
+            _Analysis_assume_(_EXP);    \
         } while (FALSE)
 
 #define ASSERT3U(_X, _OP, _Y)           \
@@ -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/xenhid/dbg_print.h b/src/xenhid/dbg_print.h
index e13cd8e..d6d3a27 100644
--- a/src/xenhid/dbg_print.h
+++ b/src/xenhid/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,
@@ -110,23 +109,11 @@ __Trace(
     va_end(Arguments);
 }
 
-#else   // DBG
-
-static __inline VOID
-__Trace(
-    _In_ PCSTR  Prefix,
-    _In_ PCSTR  Format,
-    ...
-    )
-{
-    UNREFERENCED_PARAMETER(Prefix);
-    UNREFERENCED_PARAMETER(Format);
-}
-
-#endif  // DBG
-
 #define Trace(...)  \
         __Trace(__MODULE__ "|" __FUNCTION__ ": ", __VA_ARGS__)
+#else   // DBG
+#define Trace(...)  (VOID)(__VA_ARGS__)
+#endif  // DBG
 
 static __inline VOID
 __Info(
@@ -151,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  // _XENHID_DBG_PRINT_H
diff --git a/src/xenhid/names.h b/src/xenhid/names.h
index 1dacb4b..adc7608 100644
--- a/src/xenhid/names.h
+++ b/src/xenhid/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/xenhid/string.c b/src/xenhid/string.c
index ad82053..5b84568 100644
--- a/src/xenhid/string.c
+++ b/src/xenhid/string.c
@@ -53,7 +53,7 @@ __StringPut(
 
 static PCHAR
 FormatNumber(
-    _Inout_ PSTR    Buffer,
+    _Out_ PSTR      Buffer,
     _In_ ULONGLONG  Value,
     _In_ UCHAR      Base,
     _In_ BOOLEAN    UpperCase
diff --git a/src/xenhid/thread.c b/src/xenhid/thread.c
index 36d82d0..954e060 100644
--- a/src/xenhid/thread.c
+++ b/src/xenhid/thread.c
@@ -33,11 +33,11 @@
 #include <ntddk.h>
 
 #include "thread.h"
-#include "util.h"
 #include "dbg_print.h"
 #include "assert.h"
+#include "util.h"
 
-#define THREAD_POOL 'ERHT'
+#define THREAD_TAG 'ERHT'
 
 struct _XENHID_THREAD {
     XENHID_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_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     )
 {
     KeSetEvent(&Thread->Event, IO_NO_INCREMENT, FALSE);
@@ -74,7 +74,7 @@ __ThreadWake(
 
 VOID
 ThreadWake(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     )
 {
     __ThreadWake(Thread);
@@ -82,7 +82,7 @@ ThreadWake(
 
 static FORCEINLINE VOID
 __ThreadAlert(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     )
 {
     Thread->Alerted = TRUE;
@@ -91,7 +91,7 @@ __ThreadAlert(
 
 VOID
 ThreadAlert(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     )
 {
     __ThreadAlert(Thread);
@@ -131,8 +131,6 @@ ThreadCreate(
 
     (*Thread) = __ThreadAllocate(sizeof (XENHID_THREAD));
 
-    Warning("Create thread %p %p\n", Function, Thread);
-
     status = STATUS_NO_MEMORY;
     if (*Thread == NULL)
         goto fail1;
@@ -207,7 +205,7 @@ ThreadIsAlerted(
 
 VOID
 ThreadJoin(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     )
 {
     LONG                References;
diff --git a/src/xenhid/thread.h b/src/xenhid/thread.h
index adb9a62..3358171 100644
--- a/src/xenhid/thread.h
+++ b/src/xenhid/thread.h
@@ -59,17 +59,17 @@ ThreadIsAlerted(
 
 extern VOID
 ThreadWake(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     );
 
 extern VOID
 ThreadAlert(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     );
 
 extern VOID
 ThreadJoin(
-    _In_ PXENHID_THREAD Thread
+    _Inout_ PXENHID_THREAD  Thread
     );
 
 #endif  // _XENHID_THREAD_H
diff --git a/src/xenhid/util.h b/src/xenhid/util.h
index 9709a10..db40d4f 100644
--- a/src/xenhid/util.h
+++ b/src/xenhid/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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.