Move GUID comparison macro to wdm.h
[reactos.git] / include / ddk / wdm.h
index 0f338f9..3db6a24 100644 (file)
@@ -1,6 +1,15 @@
 #ifndef _WDMDDK_
 #define _WDMDDK_
 
+/* Helper macro to enable gcc's extension.  */
+#ifndef __GNU_EXTENSION
+#ifdef __GNUC__
+#define __GNU_EXTENSION __extension__
+#else
+#define __GNU_EXTENSION
+#endif
+#endif
+
 //
 // Dependencies
 //
@@ -47,6 +56,38 @@ extern "C" {
 #endif
 
 
+/*
+ * Alignment Macros
+ */
+#define ALIGN_DOWN(s, t) \
+    ((ULONG)(s) & ~(sizeof(t) - 1))
+
+#define ALIGN_UP(s, t) \
+    (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
+
+#define ALIGN_DOWN_POINTER(p, t) \
+    ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
+
+#define ALIGN_UP_POINTER(p, t) \
+    (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
+
+/*
+ * GUID Comparison
+ */
+
+#ifndef __IID_ALIGNED__
+    #define __IID_ALIGNED__
+    #ifdef __cplusplus
+        inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
+        {
+            return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
+        }
+    #else
+        #define IsEqualGUIDAligned(guid1, guid2) \
+            ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
+    #endif 
+#endif
+
 /* Simple types */
 typedef UCHAR KPROCESSOR_MODE;
 typedef LONG KPRIORITY;
@@ -212,7 +253,7 @@ typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
     } Interrupt;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
     struct {
-      union {
+      __GNU_EXTENSION union {
         struct {
           USHORT Reserved;
           USHORT MessageCount;
@@ -568,11 +609,11 @@ InterlockedAdd64(
 #ifndef _SLIST_HEADER_
 #define _SLIST_HEADER_
 
-#define SLIST_ENTRY SINGLE_LIST_ENTRY
-#define _SLIST_ENTRY _SINGLE_LIST_ENTRY
-#define PSLIST_ENTRY PSINGLE_LIST_ENTRY
-
 #if defined(_WIN64)
+typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
+typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
+       PSLIST_ENTRY Next;
+} SLIST_ENTRY;
 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
     struct {
         ULONGLONG Alignment;
@@ -597,6 +638,9 @@ typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
     } Header16;
 } SLIST_HEADER, *PSLIST_HEADER;
 #else
+#define SLIST_ENTRY SINGLE_LIST_ENTRY
+#define _SLIST_ENTRY _SINGLE_LIST_ENTRY
+#define PSLIST_ENTRY PSINGLE_LIST_ENTRY
 typedef union _SLIST_HEADER {
     ULONGLONG Alignment;
     struct {
@@ -1061,22 +1105,22 @@ InterlockedPushEntrySList(
 
 typedef struct _DISPATCHER_HEADER
 {
-    union
+    __GNU_EXTENSION union
     {
-        struct
+        __GNU_EXTENSION struct
         {
             UCHAR Type;
-            union
+            __GNU_EXTENSION union
             {
                 UCHAR Absolute;
                 UCHAR NpxIrql;
             };
-            union
+            __GNU_EXTENSION union
             {
                 UCHAR Size;
                 UCHAR Hand;
             };
-            union
+            __GNU_EXTENSION union
             {
                 UCHAR Inserted;
                 BOOLEAN DebugActive;
@@ -2398,7 +2442,7 @@ typedef struct _ERESOURCE
     ULONG ContentionCount;
     ULONG NumberOfSharedWaiters;
     ULONG NumberOfExclusiveWaiters;
-    union
+    __GNU_EXTENSION union
     {
         PVOID Address;
         ULONG_PTR CreatorBackTraceIndex;
@@ -2498,7 +2542,7 @@ typedef struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST {
 //} LOOKASIDE_LIST_EX, *PLOOKASIDE_LIST_EX;
 
 typedef struct _EX_RUNDOWN_REF {
-    union {
+    __GNU_EXTENSION union {
         volatile ULONG_PTR Count;
         volatile PVOID Ptr;
     };