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

[XENBUS-SYNC 2/2] Annotate common helpers with their actual direction and size


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
  • Date: Thu, 22 Oct 2026 13:22:17 +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 11:22:24 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Some parameters of the common helpers were annotated _In_ although the
function writes them (mutex, thread, interlocked and tokenizer helpers),
used const PSTR (a const pointer to mutable characters) for read-only
strings, or had no size on byte buffers.

Annotate them with their actual direction, use PCSTR for read-only
strings, and give the buffers of IsZeroMemory and the registry binary
value functions their size in bytes. Apply the same change to the
xenfilt copy of thread.c/h.
No functional change.

Signed-off-by: Césaire Mounah <cesaire.mounah@xxxxxxxxxx>
---
 src/common/assert.h   | 18 +++++++++---------
 src/common/mutex.h    | 10 +++++-----
 src/common/registry.c | 24 ++++++++++++------------
 src/common/registry.h | 16 ++++++++--------
 src/common/util.h     | 36 ++++++++++++++++++------------------
 src/xenbus/thread.c   | 10 +++++-----
 src/xenbus/thread.h   |  6 +++---
 src/xenfilt/thread.c  | 10 +++++-----
 src/xenfilt/thread.h  |  6 +++---
 9 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/src/common/assert.h b/src/common/assert.h
index 90a839f..7e88216 100644
--- a/src/common/assert.h
+++ b/src/common/assert.h
@@ -154,13 +154,13 @@ __Bug(
 
 static __inline BOOLEAN
 _IsZeroMemory(
-    _In_ const PSTR     Caller,
-    _In_ const PSTR     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_ const PSTR     Caller,
-    _In_ const PSTR     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/common/mutex.h b/src/common/mutex.h
index bdacddb..d311a91 100644
--- a/src/common/mutex.h
+++ b/src/common/mutex.h
@@ -44,7 +44,7 @@ typedef struct _MUTEX {
 
 static FORCEINLINE VOID
 InitializeMutex(
-    _In_ PMUTEX Mutex
+    _Out_ PMUTEX    Mutex
     )
 {
     RtlZeroMemory(Mutex, sizeof (MUTEX));
@@ -55,7 +55,7 @@ InitializeMutex(
 static FORCEINLINE BOOLEAN
 _IRQL_requires_max_(PASSIVE_LEVEL)
 TryAcquireMutex(
-    _In_ PMUTEX     Mutex
+    _Inout_ PMUTEX  Mutex
     )
 {
     LARGE_INTEGER   Timeout;
@@ -82,10 +82,10 @@ TryAcquireMutex(
 static FORCEINLINE VOID
 _IRQL_requires_max_(PASSIVE_LEVEL)
 AcquireMutex(
-    _In_ PMUTEX Mutex
+    _Inout_ PMUTEX  Mutex
     )
 {
-    NTSTATUS    status;
+    NTSTATUS        status;
 
     status = KeWaitForSingleObject(&Mutex->Event,
                                    Executive,
@@ -102,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/common/registry.c b/src/common/registry.c
index 4f7c5ef..d576990 100644
--- a/src/common/registry.c
+++ b/src/common/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/common/registry.h b/src/common/registry.h
index 26bc0c6..ba1eace 100644
--- a/src/common/registry.h
+++ b/src/common/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/common/util.h b/src/common/util.h
index 9709a10..db40d4f 100644
--- a/src/common/util.h
+++ b/src/common/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;
diff --git a/src/xenbus/thread.c b/src/xenbus/thread.c
index 2a3c190..a8cfce2 100644
--- a/src/xenbus/thread.c
+++ b/src/xenbus/thread.c
@@ -66,7 +66,7 @@ __ThreadFree(
 
 static FORCEINLINE VOID
 __ThreadWake(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     )
 {
     KeSetEvent(&Thread->Event, IO_NO_INCREMENT, FALSE);
@@ -74,7 +74,7 @@ __ThreadWake(
 
 VOID
 ThreadWake(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     )
 {
     __ThreadWake(Thread);
@@ -82,7 +82,7 @@ ThreadWake(
 
 static FORCEINLINE VOID
 __ThreadAlert(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     )
 {
     Thread->Alerted = TRUE;
@@ -91,7 +91,7 @@ __ThreadAlert(
 
 VOID
 ThreadAlert(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     )
 {
     __ThreadAlert(Thread);
@@ -205,7 +205,7 @@ ThreadIsAlerted(
 
 VOID
 ThreadJoin(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     )
 {
     LONG                References;
diff --git a/src/xenbus/thread.h b/src/xenbus/thread.h
index 28d6f9d..4597f14 100644
--- a/src/xenbus/thread.h
+++ b/src/xenbus/thread.h
@@ -59,17 +59,17 @@ ThreadIsAlerted(
 
 extern VOID
 ThreadWake(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     );
 
 extern VOID
 ThreadAlert(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     );
 
 extern VOID
 ThreadJoin(
-    _In_ PXENBUS_THREAD Thread
+    _Inout_ PXENBUS_THREAD  Thread
     );
 
 #endif  // _XENBUS_THREAD_H
diff --git a/src/xenfilt/thread.c b/src/xenfilt/thread.c
index 3f3b008..e26469b 100644
--- a/src/xenfilt/thread.c
+++ b/src/xenfilt/thread.c
@@ -66,7 +66,7 @@ __ThreadFree(
 
 static FORCEINLINE VOID
 __ThreadWake(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     )
 {
     KeSetEvent(&Thread->Event, IO_NO_INCREMENT, FALSE);
@@ -74,7 +74,7 @@ __ThreadWake(
 
 VOID
 ThreadWake(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     )
 {
     __ThreadWake(Thread);
@@ -82,7 +82,7 @@ ThreadWake(
 
 static FORCEINLINE VOID
 __ThreadAlert(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     )
 {
     Thread->Alerted = TRUE;
@@ -91,7 +91,7 @@ __ThreadAlert(
 
 VOID
 ThreadAlert(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     )
 {
     __ThreadAlert(Thread);
@@ -205,7 +205,7 @@ ThreadIsAlerted(
 
 VOID
 ThreadJoin(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     )
 {
     LONG                References;
diff --git a/src/xenfilt/thread.h b/src/xenfilt/thread.h
index 9cc35a0..4d85ead 100644
--- a/src/xenfilt/thread.h
+++ b/src/xenfilt/thread.h
@@ -59,17 +59,17 @@ ThreadIsAlerted(
 
 extern VOID
 ThreadWake(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     );
 
 extern VOID
 ThreadAlert(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     );
 
 extern VOID
 ThreadJoin(
-    _In_ PXENFILT_THREAD    Thread
+    _Inout_ PXENFILT_THREAD Thread
     );
 
 #endif  // _XENFILT_THREAD_H
-- 
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®.