Skip to content

Commit

Permalink
[NTOS:CM] Add debug code for analyzing lock issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tkreuzer committed May 23, 2024
1 parent 53518bb commit da64119
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ntoskrnl/include/internal/cm.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 160,9 @@ typedef struct _CM_KEY_HASH_TABLE_ENTRY
EX_PUSH_LOCK Lock;
PKTHREAD Owner;
PCM_KEY_HASH Entry;
#if DBG
PVOID LockBackTrace[5];
#endif
} CM_KEY_HASH_TABLE_ENTRY, *PCM_KEY_HASH_TABLE_ENTRY;

//
Expand Down
17 changes: 17 additions & 0 deletions ntoskrnl/include/internal/cm_x.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,19 @@
* PROGRAMMERS: Alex Ionescu ([email protected])
*/

#if DBG
FORCEINLINE
VOID
CmpCaptureLockBackTraceByIndex(_In_ ULONG Index)
{
/* Capture the backtrace */
RtlCaptureStackBackTrace(1,
_countof(CmpCacheTable[Index].LockBackTrace),
CmpCacheTable[Index].LockBackTrace,
NULL);
}
#endif

//
// Returns the hashkey corresponding to a convkey
//
Expand Down Expand Up @@ -104,8 117,12 @@ FORCEINLINE
VOID
CmpAcquireKcbLockExclusiveByIndex(ULONG Index)
{
ASSERT(CmpCacheTable[Index].Owner != KeGetCurrentThread());
ExAcquirePushLockExclusive(&CmpCacheTable[Index].Lock);
CmpCacheTable[Index].Owner = KeGetCurrentThread();
#if DBG
CmpCaptureLockBackTraceByIndex(Index);
#endif
}

//
Expand Down

0 comments on commit da64119

Please sign in to comment.