ReactOS  0.4.13-dev-961-g238ea69
dldetect.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _THREAD_STRUCT
 
struct  _THREAD_REC_BLOCK
 

Macros

#define DLDAllocatePool(size)   MyAllocatePool__(NonPagedPool,size)
 
#define DLDFreePool(addr)   MyFreePool__((addr))
 
#define DLDGetCurrentResourceThread()   ((ERESOURCE_THREAD)PsGetCurrentThread())
 
#define ResourceOwnedExclusive   0x80
 
#define ResourceDisableBoost   0x08
 

Typedefs

typedef struct _THREAD_STRUCT THREAD_STRUCT
 
typedef struct _THREAD_STRUCTPTHREAD_STRUCT
 
typedef struct _THREAD_REC_BLOCK THREAD_REC_BLOCK
 
typedef struct _THREAD_REC_BLOCKPTHREAD_REC_BLOCK
 

Functions

VOID DLDInit (ULONG MaxThrdCount)
 Initialize deadlock detector. More...
 
VOID DLDAcquireExclusive (PERESOURCE Resource, ULONG BugCheckId, ULONG Line)
 
VOID DLDAcquireShared (PERESOURCE Resource, ULONG BugCheckId, ULONG Line, BOOLEAN WaitForExclusive)
 
VOID DLDAcquireSharedStarveExclusive (PERESOURCE Resource, ULONG BugCheckId, ULONG Line)
 
VOID DLDUnblock (PERESOURCE Resource)
 
VOID DLDFree (VOID)
 

Macro Definition Documentation

◆ DLDAllocatePool

#define DLDAllocatePool (   size)    MyAllocatePool__(NonPagedPool,size)

Definition at line 25 of file dldetect.h.

◆ DLDFreePool

#define DLDFreePool (   addr)    MyFreePool__((addr))

Definition at line 26 of file dldetect.h.

◆ DLDGetCurrentResourceThread

#define DLDGetCurrentResourceThread ( )    ((ERESOURCE_THREAD)PsGetCurrentThread())

Definition at line 28 of file dldetect.h.

◆ ResourceDisableBoost

#define ResourceDisableBoost   0x08

Definition at line 34 of file dldetect.h.

◆ ResourceOwnedExclusive

#define ResourceOwnedExclusive   0x80

Definition at line 32 of file dldetect.h.

Typedef Documentation

◆ PTHREAD_REC_BLOCK

◆ PTHREAD_STRUCT

◆ THREAD_REC_BLOCK

◆ THREAD_STRUCT

Function Documentation

◆ DLDAcquireExclusive()

VOID DLDAcquireExclusive ( PERESOURCE  Resource,
ULONG  BugCheckId,
ULONG  Line 
)

Definition at line 313 of file dldetect.cpp.

316  {
317 
318  KIRQL oldIrql;
319 
320  KeAcquireSpinLock(&Resource->SpinLock, &oldIrql);
321 
323 
324  if (!Resource->ActiveCount) goto SimpleAcquire;
325  if ((Resource->Flag & ResourceOwnedExclusive) && Resource->OwnerThreads[0].OwnerThread == Thread) {
326  Resource->OwnerThreads[0].OwnerCount++;
327  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
328  return;
329  }
330 
331  DLDpAcquireResourceExclusiveLite(Resource, Thread, oldIrql,BugCheckId,Line);
332  return;
333 
334 SimpleAcquire:
335 
337  Resource->ActiveCount = 1;
338  Resource->OwnerThreads[0].OwnerThread = Thread;
339  Resource->OwnerThreads[0].OwnerCount = 1;
340 
341  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
342 }
ULONG_PTR ERESOURCE_THREAD
Definition: extypes.h:208
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:848
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Definition: ncftp.h:79
VOID DLDpAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread, IN KIRQL oldIrql, IN ULONG BugCheckId, IN ULONG Line)
Definition: dldetect.cpp:261
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ResourceOwnedExclusive
Definition: dldetect.h:32

Referenced by DLDpAcquireResourceExclusiveLite().

◆ DLDAcquireShared()

VOID DLDAcquireShared ( PERESOURCE  Resource,
ULONG  BugCheckId,
ULONG  Line,
BOOLEAN  WaitForExclusive 
)

Definition at line 398 of file dldetect.cpp.

402 {
403 
404  KIRQL oldIrql;
405 
407  POWNER_ENTRY pOwnerEntry;
408 
409  KeAcquireSpinLock(&Resource->SpinLock, &oldIrql);
410 
411  if (!Resource->ActiveCount) {
413  Resource->ActiveCount = 1;
414  Resource->OwnerThreads[1].OwnerThread = Thread;
415  Resource->OwnerThreads[1].OwnerCount = 1;
416  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
417  return;
418  }
419 
420  if (Resource->Flag & ResourceOwnedExclusive ) {
421  if (Resource->OwnerThreads[0].OwnerThread == Thread) {
422  Resource->OwnerThreads[0].OwnerCount++;
423  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
424  return;
425  }
426 
427  pOwnerEntry = DLDpFindCurrentThread(Resource, 0);
428 
429  } else {
430  // owned shared by some thread(s)
431 
432  pOwnerEntry = DLDpFindCurrentThread(Resource, Thread);
433 
434  if (!WaitForExclusive && pOwnerEntry->OwnerThread == Thread) {
435  pOwnerEntry->OwnerCount++;
436  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
437  return;
438  }
439 
440  if (!(Resource->NumberOfExclusiveWaiters)) {
441 
442  pOwnerEntry->OwnerThread = Thread;
443  pOwnerEntry->OwnerCount = 1;
444  Resource->ActiveCount++;
445  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
446 
447  return;
448  }
449  }
450 
451  if (!(Resource->SharedWaiters)) {
453  KeInitializeSemaphore(Resource->SharedWaiters,0,0x7fffffff);
454  }
455 
456  Resource->NumberOfSharedWaiters++;
457 
459 
460 
461  // Set WaitingResource for current thread
462  ThrdStruct->WaitingResource = Resource;
463  ThrdStruct->BugCheckId = BugCheckId;
464  ThrdStruct->Line = Line;
465 
466  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
467 
468  DLDpWaitForResource(Resource,&(Resource->SharedWaiters->Header),ThrdStruct);
469 
470  KeAcquireSpinLock(&Resource->SpinLock, &oldIrql);
471 
472  pOwnerEntry = DLDpFindCurrentThread(Resource, Thread);
473  pOwnerEntry->OwnerThread = Thread;
474  pOwnerEntry->OwnerCount = 1;
475 
476  ThrdStruct->WaitingResource = NULL;
477  ThrdStruct->ThreadId = 0;
478  ThrdStruct->BugCheckId = 0;
479  ThrdStruct->Line = 0;
480 
481  KeReleaseSpinLock(&Resource->SpinLock, oldIrql);
482 
483  return;
484 
485 }
Definition: extypes.h:210
ULONG_PTR ERESOURCE_THREAD
Definition: extypes.h:208
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
PERESOURCE WaitingResource
Definition: dldetect.h:60
ERESOURCE_THREAD ThreadId
Definition: dldetect.h:59
ULONG Line
Definition: dldetect.h:62
PTHREAD_STRUCT DLDAllocFindThread(ULONG ThreadId)
Definition: dldetect.cpp:70
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:848
struct _KSEMAPHORE * PKSEMAPHORE
smooth NULL
Definition: ftsmooth.c:416
ULONG OwnerCount
Definition: extypes.h:216
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define RESOURCE_SEMAFORE_TAG
Resource semaphore (SharedWaiters)
Definition: dldetect.cpp:31
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
ERESOURCE_THREAD OwnerThread
Definition: extypes.h:211
POWNER_ENTRY DLDpFindCurrentThread(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: dldetect.cpp:345
VOID DLDpWaitForResource(IN PERESOURCE Resource, IN DISPATCHER_HEADER *DispatcherObject, IN PTHREAD_STRUCT ThrdStruct)
Definition: dldetect.cpp:225
ULONG BugCheckId
Definition: dldetect.h:61
#define ResourceOwnedExclusive
Definition: dldetect.h:32
struct Line Line

◆ DLDAcquireSharedStarveExclusive()

VOID DLDAcquireSharedStarveExclusive ( PERESOURCE  Resource,
ULONG  BugCheckId,
ULONG  Line 
)

◆ DLDFree()

VOID DLDFree ( VOID  )

Definition at line 64 of file dldetect.cpp.

64  {
65 
67 
68 }
#define DLDFreePool(addr)
Definition: dldetect.h:26
PTHREAD_STRUCT DLDThreadTable
Waiters table.
Definition: dldetect.cpp:42

Referenced by DriverEntry().

◆ DLDInit()

VOID DLDInit ( ULONG  MaxThrdCount)

Initialize deadlock detector.

Parameters
MaxThrdCountMaximum supported number of threads

Definition at line 51 of file dldetect.cpp.

52  {
53  if (KeNumberProcessors>1) {
54  UDFPrint(("Deadlock Detector is designed for uniprocessor machines only!\n"));
55  BrutePoint();
56  }
57  DLDpTimeout.QuadPart = -40000000I64;
58 
59  MaxThreadCount = MaxThrdCount;
62 }
#define UDFPrint(Args)
Definition: udffs.h:225
LARGE_INTEGER DLDpTimeout
4 sec
Definition: dldetect.cpp:44
#define DLDAllocatePool(size)
Definition: dldetect.h:25
ULONG MaxThreadCount
Maximum supported number of threads (initialized by DLDInit())
Definition: dldetect.cpp:39
PTHREAD_STRUCT DLDThreadTable
Waiters table.
Definition: dldetect.cpp:42
#define BrutePoint()
Definition: env_spec_w32.h:504
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define I64(x)
Definition: byte_order.h:110
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _THREAD_STRUCT * PTHREAD_STRUCT
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by DriverEntry().

◆ DLDUnblock()

VOID DLDUnblock ( PERESOURCE  Resource)