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

[win-pv-devel] [PATCH 1/2] Re-synchronize util.h with XENBUS and use __toupper()



A recent patch introduced __tolower() and __toupper() into util.h as
replacements for tolower() and toupper() respectively as the latter do
a hidden conversion to Unicode which make then unsafe at any IRQL other
than PASSIVE_LEVEL.
This patch imports util.h from XENBUS and fixes other code to be compatible.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/bus.c         |   2 +-
 src/xenvif/fdo.c         |   4 +-
 src/xenvif/frontend.c    |   2 +-
 src/xenvif/link.c        |   2 +-
 src/xenvif/mac.c         |   2 +-
 src/xenvif/pdo.c         |   2 +-
 src/xenvif/receiver.c    |   2 +-
 src/xenvif/registry.c    |   2 +-
 src/xenvif/settings.c    |   2 +-
 src/xenvif/thread.c      |   2 +-
 src/xenvif/transmitter.c |   2 +-
 src/xenvif/util.h        | 105 +++++++++++++++++------------------------------
 src/xenvif/vif.c         |   2 +-
 13 files changed, 50 insertions(+), 81 deletions(-)

diff --git a/src/xenvif/bus.c b/src/xenvif/bus.c
index 9190535..d3796e3 100644
--- a/src/xenvif/bus.c
+++ b/src/xenvif/bus.c
@@ -53,7 +53,7 @@ __BusAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, BUS_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, BUS_TAG);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c
index 82c3fd2..dae1ad8 100644
--- a/src/xenvif/fdo.c
+++ b/src/xenvif/fdo.c
@@ -112,7 +112,7 @@ __FdoAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, FDO_POOL);
+    return __AllocatePoolWithTag(NonPagedPool, Length, FDO_POOL);
 }
 
 static FORCEINLINE VOID
@@ -857,7 +857,7 @@ __FdoMultiSzToUpcaseAnsi(
             if (Buffer[Index] == '\0')
                 break;
         } else {
-            Buffer[Index] = (CHAR)toupper(Buffer[Index]);
+            Buffer[Index] = __toupper(Buffer[Index]);
             Index++;
         }
     }
diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c
index a43a534..9500a58 100644
--- a/src/xenvif/frontend.c
+++ b/src/xenvif/frontend.c
@@ -126,7 +126,7 @@ __FrontendAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, FRONTEND_POOL);
+    return __AllocatePoolWithTag(NonPagedPool, Length, FRONTEND_POOL);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/link.c b/src/xenvif/link.c
index 5161159..a9b75b3 100644
--- a/src/xenvif/link.c
+++ b/src/xenvif/link.c
@@ -45,7 +45,7 @@ __LinkAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, LINK_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, LINK_TAG);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/mac.c b/src/xenvif/mac.c
index 0a771a4..3d04670 100644
--- a/src/xenvif/mac.c
+++ b/src/xenvif/mac.c
@@ -73,7 +73,7 @@ __MacAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, XENVIF_MAC_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, XENVIF_MAC_TAG);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c
index 07cf23a..bda8925 100644
--- a/src/xenvif/pdo.c
+++ b/src/xenvif/pdo.c
@@ -100,7 +100,7 @@ __PdoAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, PDO_POOL);
+    return __AllocatePoolWithTag(NonPagedPool, Length, PDO_POOL);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/receiver.c b/src/xenvif/receiver.c
index 53f322f..d3073e1 100644
--- a/src/xenvif/receiver.c
+++ b/src/xenvif/receiver.c
@@ -145,7 +145,7 @@ __ReceiverAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, XENVIF_RECEIVER_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, XENVIF_RECEIVER_TAG);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/registry.c b/src/xenvif/registry.c
index 23b948b..9a7472b 100644
--- a/src/xenvif/registry.c
+++ b/src/xenvif/registry.c
@@ -45,7 +45,7 @@ __RegistryAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, REGISTRY_POOL);
+    return __AllocatePoolWithTag(NonPagedPool, Length, REGISTRY_POOL);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/settings.c b/src/xenvif/settings.c
index 3ce4771..5cb9984 100644
--- a/src/xenvif/settings.c
+++ b/src/xenvif/settings.c
@@ -45,7 +45,7 @@ __SettingsAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, SETTINGS_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, SETTINGS_TAG);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/thread.c b/src/xenvif/thread.c
index 2fa0c1c..1357473 100644
--- a/src/xenvif/thread.c
+++ b/src/xenvif/thread.c
@@ -52,7 +52,7 @@ __ThreadAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, THREAD_POOL);
+    return __AllocatePoolWithTag(NonPagedPool, Length, THREAD_POOL);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/transmitter.c b/src/xenvif/transmitter.c
index f01fc40..a8b0162 100644
--- a/src/xenvif/transmitter.c
+++ b/src/xenvif/transmitter.c
@@ -232,7 +232,7 @@ __TransmitterAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, XENVIF_TRANSMITTER_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, XENVIF_TRANSMITTER_TAG);
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenvif/util.h b/src/xenvif/util.h
index 5fec116..6d140b0 100644
--- a/src/xenvif/util.h
+++ b/src/xenvif/util.h
@@ -29,8 +29,8 @@
  * SUCH DAMAGE.
  */
 
-#ifndef _UTIL_H
-#define _UTIL_H
+#ifndef _XENVIF_UTIL_H
+#define _XENVIF_UTIL_H
 
 #include <ntddk.h>
 
@@ -138,85 +138,32 @@ __InterlockedSubtract(
     return New;
 }
 
-typedef struct _NON_PAGED_BUFFER_HEADER {
-    SIZE_T  Length;
-    ULONG   Tag;
-} NON_PAGED_BUFFER_HEADER, *PNON_PAGED_BUFFER_HEADER;
-
-typedef struct _NON_PAGED_BUFFER_TRAILER {
-    ULONG   Tag;
-} NON_PAGED_BUFFER_TRAILER, *PNON_PAGED_BUFFER_TRAILER;
-
 static FORCEINLINE PVOID
-__AllocateNonPagedPoolWithTag(
-    IN  SIZE_T                  Length,
-    IN  ULONG                   Tag
+__AllocatePoolWithTag(
+    IN  POOL_TYPE   PoolType,
+    IN  SIZE_T      NumberOfBytes,
+    IN  ULONG       Tag
     )
 {
-    PUCHAR                      Buffer;
-    PNON_PAGED_BUFFER_HEADER    Header;
-    PNON_PAGED_BUFFER_TRAILER   Trailer;
+    PUCHAR          Buffer;
 
-    ASSERT(Length != 0);
+    __analysis_assume(PoolType == NonPagedPool ||
+                      PoolType == PagedPool);
 
-    Buffer = ExAllocatePoolWithTag(NonPagedPool,
-                                   sizeof (NON_PAGED_BUFFER_HEADER) +
-                                   Length +
-                                   sizeof (NON_PAGED_BUFFER_TRAILER),
-                                   Tag);
+    Buffer = ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
     if (Buffer == NULL)
-        goto done;
-
-    RtlZeroMemory(Buffer,
-                  sizeof (NON_PAGED_BUFFER_HEADER) +
-                  Length +
-                  sizeof (NON_PAGED_BUFFER_TRAILER));
-
-    Header = (PNON_PAGED_BUFFER_HEADER)Buffer;
-    Header->Length = Length;
-    Header->Tag = Tag;
-
-    Buffer += sizeof (NON_PAGED_BUFFER_HEADER);
-
-    Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length);
-    Trailer->Tag = Tag;
+        return NULL;
 
-done:
+    RtlZeroMemory(Buffer, NumberOfBytes);
     return Buffer;
 }
 
 static FORCEINLINE VOID
 __FreePoolWithTag(
-    IN  PVOID                   _Buffer,
-    IN  ULONG                   Tag
+    IN  PVOID   Buffer,
+    IN  ULONG   Tag
     )
 {
-    PUCHAR                      Buffer = _Buffer;
-    SIZE_T                      Length;
-    PNON_PAGED_BUFFER_HEADER    Header;
-    PNON_PAGED_BUFFER_TRAILER   Trailer;
-
-    ASSERT(Buffer != NULL);
-
-    Buffer -= sizeof (NON_PAGED_BUFFER_HEADER);
-
-    Header = (PNON_PAGED_BUFFER_HEADER)Buffer;
-    ASSERT3U(Tag, ==, Header->Tag);
-    Length = Header->Length;
-
-    Buffer += sizeof (NON_PAGED_BUFFER_HEADER);
-
-    Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length);
-    ASSERT3U(Tag, ==, Trailer->Tag);
-
-    Buffer -= sizeof (NON_PAGED_BUFFER_HEADER);
-
-    RtlFillMemory(Buffer,
-                  sizeof (NON_PAGED_BUFFER_HEADER) +
-                  Length +
-                  sizeof (NON_PAGED_BUFFER_TRAILER),
-                  0xAA);
-
     ExFreePoolWithTag(Buffer, Tag);
 }
 
@@ -340,4 +287,26 @@ __strtok_r(
     return Token;
 }
 
-#endif  // _UTIL_H
+static FORCEINLINE CHAR
+__toupper(
+    IN  CHAR    Character
+    )
+{
+    if (Character < 'a' || Character > 'z')
+        return Character;
+
+    return 'A' + Character - 'a';
+}
+
+static FORCEINLINE CHAR
+__tolower(
+    IN  CHAR    Character
+    )
+{
+    if (Character < 'A' || Character > 'Z')
+        return Character;
+
+    return 'a' + Character - 'A';
+}
+
+#endif  // _XENVIF_UTIL_H
diff --git a/src/xenvif/vif.c b/src/xenvif/vif.c
index 76365d2..cd8aafc 100644
--- a/src/xenvif/vif.c
+++ b/src/xenvif/vif.c
@@ -64,7 +64,7 @@ __VifAllocate(
     IN  ULONG   Length
     )
 {
-    return __AllocateNonPagedPoolWithTag(Length, XENVIF_VIF_TAG);
+    return __AllocatePoolWithTag(NonPagedPool, Length, XENVIF_VIF_TAG);
 }
 
 static FORCEINLINE VOID
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

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