[NTOS:KE] Added *Thread versions of macros with ASSERT(_Thread == KeGetCurrentThread()). Use new macros in _KeAcquireGuardedMutex, _KeReleaseGuardedMutex, _KeTryToAcquireGuardedMutex. Thanks Alex!

svn path=/trunk/; revision=72811
This commit is contained in:
Dmitry Chapyshev 2016-09-26 12:03:57 +00:00
parent 4e21017693
commit aac32378ed

View file

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