[NTOS:KE] Added *Thread versions of macros with ASSERT(_Thread == KeGetCurrentThread...
authorDmitry Chapyshev <dmitry@reactos.org>
Mon, 26 Sep 2016 12:03:57 +0000 (12:03 +0000)
committerDmitry Chapyshev <dmitry@reactos.org>
Mon, 26 Sep 2016 12:03:57 +0000 (12:03 +0000)
svn path=/trunk/; revision=72811

reactos/ntoskrnl/include/internal/ke_x.h

index 588aefb..a9ed51c 100644 (file)
@@ -19,12 +19,11 @@ KeGetPreviousMode(VOID)
 //
 // Enters a Guarded Region
 //
-#define KeEnterGuardedRegion()                                              \
+#define KeEnterGuardedRegionThread(_Thread)                                 \
 {                                                                           \
-    PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
     /* Sanity checks */                                                     \
     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);                                \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
     ASSERT((_Thread->SpecialApcDisable <= 0) &&                             \
            (_Thread->SpecialApcDisable != -32768));                         \
                                                                             \
@@ -32,15 +31,20 @@ KeGetPreviousMode(VOID)
     _Thread->SpecialApcDisable--;                                           \
 }
 
+#define KeEnterGuardedRegion()                                              \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    KeEnterGuardedRegionThread(_Thread);                                    \
+}
+
 //
 // Leaves a Guarded Region
 //
-#define KeLeaveGuardedRegion()                                              \
+#define KeLeaveGuardedRegionThread(_Thread)                                 \
 {                                                                           \
-    PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
     /* Sanity checks */                                                     \
     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);                                \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
     ASSERT(_Thread->SpecialApcDisable < 0);                                 \
                                                                             \
     /* Leave region and check if APCs are OK now */                         \
@@ -56,14 +60,19 @@ KeGetPreviousMode(VOID)
     }                                                                       \
 }
 
+#define KeLeaveGuardedRegion()                                              \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    KeLeaveGuardedRegionThread(_Thread);                                    \
+}
+
 //
 // Enters a Critical Region
 //
-#define KeEnterCriticalRegion()                                             \
+#define KeEnterCriticalRegionThread(_Thread)                                \
 {                                                                           \
-    PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
     /* Sanity checks */                                                     \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
     ASSERT((_Thread->KernelApcDisable <= 0) &&                              \
            (_Thread->KernelApcDisable != -32768));                          \
                                                                             \
@@ -71,14 +80,19 @@ KeGetPreviousMode(VOID)
     _Thread->KernelApcDisable--;                                            \
 }
 
+#define KeEnterCriticalRegion()                                             \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    KeEnterCriticalRegionThread(_Thread);                                   \
+}
+
 //
 // Leaves a Critical Region
 //
-#define KeLeaveCriticalRegion()                                             \
+#define KeLeaveCriticalRegionThread(_Thread)                                \
 {                                                                           \
-    PKTHREAD _Thread = KeGetCurrentThread();                                \
-                                                                            \
     /* Sanity checks */                                                     \
+    ASSERT(_Thread == KeGetCurrentThread());                                \
     ASSERT(_Thread->KernelApcDisable < 0);                                  \
                                                                             \
     /* Enable Kernel APCs */                                                \
@@ -97,6 +111,12 @@ KeGetPreviousMode(VOID)
     }                                                                       \
 }
 
+#define KeLeaveCriticalRegion()                                             \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    KeLeaveCriticalRegionThread(_Thread);                                   \
+}
+
 #ifndef CONFIG_SMP
 
 //
@@ -1559,7 +1579,7 @@ _KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
     ASSERT(GuardedMutex->Owner != Thread);
 
     /* Disable Special APCs */
-    KeEnterGuardedRegion();
+    KeEnterGuardedRegionThread(Thread);
 
     /* Remove the lock */
     if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
@@ -1577,13 +1597,13 @@ FORCEINLINE
 VOID
 _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
 {
+    PKTHREAD Thread = KeGetCurrentThread();
     LONG OldValue, NewValue;
 
     /* Sanity checks */
     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
     ASSERT(GuardedMutex->Owner == KeGetCurrentThread());
-    ASSERT(KeGetCurrentThread()->SpecialApcDisable ==
-           GuardedMutex->SpecialApcDisable);
+    ASSERT(Thread->SpecialApcDisable == GuardedMutex->SpecialApcDisable);
 
     /* Destroy the Owner */
     GuardedMutex->Owner = NULL;
@@ -1613,7 +1633,7 @@ _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
     }
 
     /* Re-enable APCs */
-    KeLeaveGuardedRegion();
+    KeLeaveGuardedRegionThread(Thread);
 }
 
 FORCEINLINE
@@ -1623,13 +1643,13 @@ _KeTryToAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
     PKTHREAD Thread = KeGetCurrentThread();
 
     /* Block APCs */
-    KeEnterGuardedRegion();
+    KeEnterGuardedRegionThread(Thread);
 
     /* Remove the lock */
     if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
     {
         /* Re-enable APCs */
-        KeLeaveGuardedRegion();
+        KeLeaveGuardedRegionThread(Thread);
         YieldProcessor();
 
         /* Return failure */