Move more stuff to wdm.h
[reactos.git] / include / ddk / wdm.h
index 0f338f9..365b3e0 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,179 @@ 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
+
+/*
+** Forward declarations
+*/
+
+struct _IRP;
+struct _MDL;
+struct _KAPC;
+struct _KDPC;
+struct _FILE_OBJECT;
+struct _DMA_ADAPTER;
+struct _DEVICE_OBJECT;
+struct _DRIVER_OBJECT;
+struct _IO_STATUS_BLOCK;
+struct _DEVICE_DESCRIPTION;
+struct _SCATTER_GATHER_LIST;
+struct _DRIVE_LAYOUT_INFORMATION;
+
+typedef PVOID PSID;
+
+/*
+** Simple structures
+*/
+
+typedef UCHAR KIRQL, *PKIRQL;
+
+typedef enum _MODE {
+  KernelMode,
+  UserMode,
+  MaximumMode
+} MODE;
+
+/* Constants */
+#define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
+#define ZwCurrentProcess() NtCurrentProcess()
+#define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
+#define ZwCurrentThread() NtCurrentThread()
+
+#if (_M_IX86)
+#define KIP0PCRADDRESS                      0xffdff000
+#endif
+
+#if defined(_WIN64)
+#define MAXIMUM_PROCESSORS 64
+#else
+#define MAXIMUM_PROCESSORS 32
+#endif
+
+#define MAXIMUM_WAIT_OBJECTS              64
+
+#define EX_RUNDOWN_ACTIVE                 0x1
+#define EX_RUNDOWN_COUNT_SHIFT            0x1
+#define EX_RUNDOWN_COUNT_INC              (1 << EX_RUNDOWN_COUNT_SHIFT)
+
+#define METHOD_BUFFERED                   0
+#define METHOD_IN_DIRECT                  1
+#define METHOD_OUT_DIRECT                 2
+#define METHOD_NEITHER                    3
+
+#define LOW_PRIORITY                      0
+#define LOW_REALTIME_PRIORITY             16
+#define HIGH_PRIORITY                     31
+#define MAXIMUM_PRIORITY                  32
+
+#define MAXIMUM_SUSPEND_COUNT             MAXCHAR
+
+#define MAXIMUM_FILENAME_LENGTH           256
+
+#define FILE_SUPERSEDED                   0x00000000
+#define FILE_OPENED                       0x00000001
+#define FILE_CREATED                      0x00000002
+#define FILE_OVERWRITTEN                  0x00000003
+#define FILE_EXISTS                       0x00000004
+#define FILE_DOES_NOT_EXIST               0x00000005
+
+#define FILE_USE_FILE_POINTER_POSITION    0xfffffffe
+#define FILE_WRITE_TO_END_OF_FILE         0xffffffff
+
+/* also in winnt.h */
+#define FILE_LIST_DIRECTORY               0x00000001
+#define FILE_READ_DATA                    0x00000001
+#define FILE_ADD_FILE                     0x00000002
+#define FILE_WRITE_DATA                   0x00000002
+#define FILE_ADD_SUBDIRECTORY             0x00000004
+#define FILE_APPEND_DATA                  0x00000004
+#define FILE_CREATE_PIPE_INSTANCE         0x00000004
+#define FILE_READ_EA                      0x00000008
+#define FILE_WRITE_EA                     0x00000010
+#define FILE_EXECUTE                      0x00000020
+#define FILE_TRAVERSE                     0x00000020
+#define FILE_DELETE_CHILD                 0x00000040
+#define FILE_READ_ATTRIBUTES              0x00000080
+#define FILE_WRITE_ATTRIBUTES             0x00000100
+
+#define FILE_SHARE_READ                   0x00000001
+#define FILE_SHARE_WRITE                  0x00000002
+#define FILE_SHARE_DELETE                 0x00000004
+#define FILE_SHARE_VALID_FLAGS            0x00000007
+
+#define FILE_ATTRIBUTE_READONLY           0x00000001
+#define FILE_ATTRIBUTE_HIDDEN             0x00000002
+#define FILE_ATTRIBUTE_SYSTEM             0x00000004
+#define FILE_ATTRIBUTE_DIRECTORY          0x00000010
+#define FILE_ATTRIBUTE_ARCHIVE            0x00000020
+#define FILE_ATTRIBUTE_DEVICE             0x00000040
+#define FILE_ATTRIBUTE_NORMAL             0x00000080
+#define FILE_ATTRIBUTE_TEMPORARY          0x00000100
+#define FILE_ATTRIBUTE_SPARSE_FILE        0x00000200
+#define FILE_ATTRIBUTE_REPARSE_POINT      0x00000400
+#define FILE_ATTRIBUTE_COMPRESSED         0x00000800
+#define FILE_ATTRIBUTE_OFFLINE            0x00001000
+#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
+#define FILE_ATTRIBUTE_ENCRYPTED          0x00004000
+
+#define FILE_ATTRIBUTE_VALID_FLAGS        0x00007fb7
+#define FILE_ATTRIBUTE_VALID_SET_FLAGS    0x000031a7
+
+#define FILE_VALID_OPTION_FLAGS           0x00ffffff
+#define FILE_VALID_PIPE_OPTION_FLAGS      0x00000032
+#define FILE_VALID_MAILSLOT_OPTION_FLAGS  0x00000032
+#define FILE_VALID_SET_FLAGS              0x00000036
+
+#define FILE_SUPERSEDE                    0x00000000
+#define FILE_OPEN                         0x00000001
+#define FILE_CREATE                       0x00000002
+#define FILE_OPEN_IF                      0x00000003
+#define FILE_OVERWRITE                    0x00000004
+#define FILE_OVERWRITE_IF                 0x00000005
+#define FILE_MAXIMUM_DISPOSITION          0x00000005
+
+#define FILE_DIRECTORY_FILE               0x00000001
+#define FILE_WRITE_THROUGH                0x00000002
+#define FILE_SEQUENTIAL_ONLY              0x00000004
+#define FILE_NO_INTERMEDIATE_BUFFERING    0x00000008
+#define FILE_SYNCHRONOUS_IO_ALERT         0x00000010
+#define FILE_SYNCHRONOUS_IO_NONALERT      0x00000020
+#define FILE_NON_DIRECTORY_FILE           0x00000040
+#define FILE_CREATE_TREE_CONNECTION       0x00000080
+#define FILE_COMPLETE_IF_OPLOCKED         0x00000100
+#define FILE_NO_EA_KNOWLEDGE              0x00000200
+
+
 /* Simple types */
 typedef UCHAR KPROCESSOR_MODE;
 typedef LONG KPRIORITY;
@@ -212,7 +394,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 +750,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 +779,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 +1246,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 +2583,7 @@ typedef struct _ERESOURCE
     ULONG ContentionCount;
     ULONG NumberOfSharedWaiters;
     ULONG NumberOfExclusiveWaiters;
-    union
+    __GNU_EXTENSION union
     {
         PVOID Address;
         ULONG_PTR CreatorBackTraceIndex;
@@ -2498,7 +2683,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;
     };