- Fix KiDispatchException to unmask KI_EXCEPTION_INTERNAL when setting the exception...
[reactos.git] / reactos / include / ndk / ketypes.h
index fc98ba9..83354dd 100644 (file)
@@ -39,10 +39,16 @@ Author:
 //
 #define SSDT_MAX_ENTRIES                2
 
+//
+// Processor Architectures
+//
+#define PROCESSOR_ARCHITECTURE_INTEL    0
+
 //
 // Object Type Mask for Kernel Dispatcher Objects
 //
 #define KOBJECT_TYPE_MASK               0x7F
+#define KOBJECT_LOCK_BIT                0x80
 
 //
 // Dispatcher Priority increments
@@ -59,6 +65,13 @@ Author:
 //
 #define KI_USER_SHARED_DATA_PHYSICAL    0x41000
 
+//
+// Quantum values and decrements
+//
+#define MAX_QUANTUM                     0x7F
+#define WAIT_QUANTUM_DECREMENT          1
+#define CLOCK_QUANTUM_DECREMENT         3
+
 //
 // Kernel Feature Bits
 //
@@ -78,13 +91,28 @@ Author:
 #define KF_XMMI                         0x00002000
 #define KF_3DNOW                        0x00004000
 #define KF_AMDK6MTRR                    0x00008000
+#define KF_XMMI64                       0x00010000
+#define KF_DTS                          0x00020000
+#define KF_NX_BIT                       0x20000000
+#define KF_NX_DISABLED                  0x40000000
+#define KF_NX_ENABLED                   0x80000000
+
+//
+// Internal Exception Codes
+//
+#define KI_EXCEPTION_INTERNAL           0x10000000
+#define KI_EXCEPTION_ACCESS_VIOLATION   (KI_EXCEPTION_INTERNAL | 0x04)
 
 //
 // KPCR Access for non-IA64 builds
 //
 #define K0IPCR                          ((ULONG_PTR)(KIP0PCRADDRESS))
 #define PCR                             ((volatile KPCR * const)K0IPCR)
+#if !defined(CONFIG_SMP) && !defined(NT_BUILD)
 #define KeGetPcr()                      PCR
+#else
+#define KeGetPcr()                      ((volatile KPCR * const)__readfsdword(0x1C))
+#endif
 
 //
 // Number of dispatch codes supported by KINTERRUPT
@@ -265,6 +293,27 @@ typedef enum _KTHREAD_STATE
 #endif
 } KTHREAD_STATE, *PKTHREAD_STATE;
 
+//
+// Adjust reasons
+//
+typedef enum _ADJUST_REASON
+{
+    AdjustNone = 0,
+    AdjustUnwait = 1,
+    AdjustBoost = 2
+} ADJUST_REASON;
+
+//
+// Continue Status
+//
+typedef enum _KCONTINUE_STATUS
+{
+    ContinueError = 0,
+    ContinueSuccess,
+    ContinueProcessorReselected,
+    ContinueNextProcessor
+} KCONTINUE_STATUS;
+
 //
 // Process States
 //
@@ -466,7 +515,8 @@ typedef enum _KAPC_ENVIRONMENT
 {
     OriginalApcEnvironment,
     AttachedApcEnvironment,
-    CurrentApcEnvironment
+    CurrentApcEnvironment,
+    InsertApcEnvironment
 } KAPC_ENVIRONMENT;
 
 //
@@ -487,7 +537,7 @@ typedef struct _KDPC_DATA
 {
     LIST_ENTRY DpcListHead;
     ULONG DpcLock;
-    ULONG DpcQueueDepth;
+    volatile ULONG DpcQueueDepth;
     ULONG DpcCount;
 } KDPC_DATA, *PKDPC_DATA;
 
@@ -653,7 +703,6 @@ typedef enum _KOBJECTS
 //
 // Kernel Thread (KTHREAD)
 //
-#include <pshpack1.h>
 typedef struct _KTHREAD
 {
     DISPATCHER_HEADER DispatcherHeader;
@@ -674,31 +723,31 @@ typedef struct _KTHREAD
         {
             UCHAR ApcStateFill[23];
             UCHAR ApcQueueable;
+            volatile UCHAR NextProcessor;
+            volatile UCHAR DeferredProcessor;
+            UCHAR AdjustReason;
+            SCHAR AdjustIncrement;
         };
     };
-    UCHAR NextProcessor;
-    UCHAR DeferredProcessor;
-    UCHAR AdjustReason;
-    UCHAR AdjustIncrement;
     KSPIN_LOCK ApcQueueLock;
     ULONG ContextSwitches;
-    UCHAR State;
+    volatile UCHAR State;
     UCHAR NpxState;
-    UCHAR WaitIrql;
-    UCHAR WaitMode;
-    LONG WaitStatus;
+    KIRQL WaitIrql;
+    KPROCESSOR_MODE WaitMode;
+    LONG_PTR WaitStatus;
     union
     {
         PKWAIT_BLOCK WaitBlockList;
         PKGATE GateObject;
     };
-    UCHAR Alertable;
-    UCHAR WaitNext;
+    BOOLEAN Alertable;
+    BOOLEAN WaitNext;
     UCHAR WaitReason;
-    UCHAR Priority;
-    UCHAR EnableStackSwap;
-    UCHAR SwapBusy;
-    UCHAR Alerted[2];
+    SCHAR Priority;
+    BOOLEAN EnableStackSwap;
+    volatile UCHAR SwapBusy;
+    BOOLEAN Alerted[MaximumMode];
     union
     {
         LIST_ENTRY WaitListEntry;
@@ -719,51 +768,50 @@ typedef struct _KTHREAD
     union
     {
         KTIMER Timer;
-        UCHAR TimerFill[40];
-    };
-    union
-    {
         struct
         {
-            LONG AutoAlignment:1;
-            LONG DisableBoost:1;
+            UCHAR TimerFill[40];
+            union
+            {
+                struct
+                {
+                    LONG AutoAlignment:1;
+                    LONG DisableBoost:1;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
-            LONG EtwStackTrace1ApcInserted:1;
-            LONG EtwStackTrace2ApcInserted:1;
-            LONG CycleChargePending:1;
-            LONG ReservedFlags:27;
+                    LONG EtwStackTrace1ApcInserted:1;
+                    LONG EtwStackTrace2ApcInserted:1;
+                    LONG CycleChargePending:1;
+                    LONG ReservedFlags:27;
 #else
-            LONG ReservedFlags:30;
+                    LONG ReservedFlags:30;
 #endif
+                };
+                LONG ThreadFlags;
+            };
         };
-        LONG ThreadFlags;
     };
-    PVOID Padding;
     union
     {
-        KWAIT_BLOCK WaitBlock[4];
-        union
+        KWAIT_BLOCK WaitBlock[THREAD_WAIT_OBJECTS + 1];
+        struct
         {
-            struct
-            {
-                UCHAR WaitBlockFill0[23];
-                UCHAR SystemAffinityActive;
-            };
-            struct
-            {
-                UCHAR WaitBlockFill1[47];
-                UCHAR PreviousMode;
-            };
-            struct
-            {
-                UCHAR WaitBlockFill2[71];
-                UCHAR ResourceIndex;
-            };
-            struct
-            {
-                UCHAR WaitBlockFill3[95];
-                UCHAR LargeStack;
-            };
+            UCHAR WaitBlockFill0[23];
+            BOOLEAN SystemAffinityActive;
+        };
+        struct
+        {
+            UCHAR WaitBlockFill1[47];
+            CCHAR PreviousMode;
+        };
+        struct
+        {
+            UCHAR WaitBlockFill2[71];
+            UCHAR ResourceIndex;
+        };
+        struct
+        {
+            UCHAR WaitBlockFill3[95];
+            UCHAR LargeStack;
         };
     };
     LIST_ENTRY QueueListEntry;
@@ -775,15 +823,15 @@ typedef struct _KTHREAD
     PVOID ServiceTable;
     UCHAR ApcStateIndex;
     UCHAR IdealProcessor;
-    UCHAR Preempted;
+    BOOLEAN Preempted;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
-    UCHAR CalloutActive;
+    BOOLEAN CalloutActive;
 #else
-    UCHAR ProcessReadyQueue;
+    BOOLEAN ProcessReadyQueue;
 #endif
-    UCHAR KernelStackResident;
-    CHAR BasePriority;
-    CHAR PriorityDecrement;
+    BOOLEAN KernelStackResident;
+    SCHAR BasePriority;
+    SCHAR PriorityDecrement;
     CHAR Saturation;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
     ULONG SystemCallNumber;
@@ -807,29 +855,29 @@ typedef struct _KTHREAD
     union
     {
         KAPC_STATE SavedApcState;
-        union
+        struct
         {
             UCHAR SavedApcStateFill[23];
-            CHAR FreezeCount;
-        };
-    };
-    CHAR SuspendCount;
-    UCHAR UserIdealProcessor;
+            CCHAR FreezeCount;
+            CCHAR SuspendCount;
+            UCHAR UserIdealProcessor;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
-    union
-    {
-        struct
-        {
-            UCHAR ReservedBits0:1;
-            UCHAR SegmentsPresent:1;
-            UCHAR Reservedbits1:1;
-        };
-        UCHAR NestedStateFlags;
-    };
+            union
+            {
+                struct
+                {
+                    UCHAR ReservedBits0:1;
+                    UCHAR SegmentsPresent:1;
+                    UCHAR Reservedbits1:1;
+                };
+                UCHAR NestedStateFlags;
+            };
 #else
-    UCHAR CalloutActive;
+            UCHAR CalloutActive;
 #endif
-    UCHAR Iopl;
+            UCHAR Iopl;
+        };
+    };
     PVOID Win32Thread;
     PVOID StackBase;
     union
@@ -838,7 +886,7 @@ typedef struct _KTHREAD
         struct
         {
             UCHAR SuspendApcFill0[1];
-            CHAR Quantum;
+            SCHAR Quantum;
         };
         struct
         {
@@ -868,15 +916,18 @@ typedef struct _KTHREAD
         {
             UCHAR SuspendApcFill5[47];
             UCHAR PowerState;
+            ULONG UserTime;
         };
     };
-    ULONG UserTime;
     union
     {
         KSEMAPHORE SuspendSemaphore;
-        UCHAR SuspendSemaphorefill[20];
+        struct
+        {
+            UCHAR SuspendSemaphorefill[20];
+            ULONG SListFaultCount;
+        };
     };
-    ULONG SListFaultCount;
     LIST_ENTRY ThreadListEntry;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
     LIST_ENTRY MutantListHead;
@@ -886,7 +937,9 @@ typedef struct _KTHREAD
     PVOID MdlForLockedteb;
 #endif
 } KTHREAD;
-#include <poppack.h>
+
+#define ASSERT_THREAD(object) \
+    ASSERT((((object)->DispatcherHeader.Type & KOBJECT_TYPE_MASK) == ThreadObject))
 
 //
 // Kernel Process (KPROCESS)
@@ -895,7 +948,7 @@ typedef struct _KPROCESS
 {
     DISPATCHER_HEADER Header;
     LIST_ENTRY ProfileListHead;
-    PHYSICAL_ADDRESS DirectoryTableBase;
+    LARGE_INTEGER DirectoryTableBase;
 #if defined(_M_IX86)
     KGDTENTRY LdtDescriptor;
     KIDTENTRY Int21Descriptor;
@@ -903,7 +956,7 @@ typedef struct _KPROCESS
     UCHAR Iopl;
     UCHAR Unused;
 #endif
-    ULONG ActiveProcessors;
+    volatile ULONG ActiveProcessors;
     ULONG KernelTime;
     ULONG UserTime;
     LIST_ENTRY ReadyListHead;
@@ -916,15 +969,15 @@ typedef struct _KPROCESS
     {
         struct
         {
-            ULONG AutoAlignment:1;
-            ULONG DisableBoost:1;
-            ULONG DisableQuantum:1;
-            ULONG ReservedFlags:29;
+            LONG AutoAlignment:1;
+            LONG DisableBoost:1;
+            LONG DisableQuantum:1;
+            LONG ReservedFlags:29;
         };
-        ULONG ProcessFlags;
+        LONG ProcessFlags;
     };
-    CHAR BasePriority;
-    CHAR QuantumReset;
+    SCHAR BasePriority;
+    SCHAR QuantumReset;
     UCHAR State;
     UCHAR ThreadSeed;
     UCHAR PowerState;
@@ -933,9 +986,7 @@ typedef struct _KPROCESS
     union
     {
         KEXECUTE_OPTIONS Flags;
-#if (NTDDI_VERSION >= NTDDI_LONGHORN)
         UCHAR ExecuteOptions;
-#endif
     };
     ULONG StackCount;
     LIST_ENTRY ProcessListEntry;
@@ -964,11 +1015,7 @@ typedef struct _KSERVICE_TABLE_DESCRIPTOR
 //
 // Exported Loader Parameter Block
 //
-#ifndef _REACTOS_
 extern struct _LOADER_PARAMETER_BLOCK NTSYSAPI *KeLoaderBlock;
-#else
-extern struct _ROS_LOADER_PARAMETER_BLOCK NTSYSAPI KeLoaderBlock;
-#endif
 
 //
 // Exported Hardware Data