VfDeadlockBeforeCallDriver

NTSTATUS __stdcall VfDeadlockBeforeCallDriver(_IRP *Irp){
  NTSTATUS v1; 
  VOID *v2; 
  _ETHREAD *CurrentThread; 
  unsigned int v4; 
  UINT8 v5; 
  _VI_DEADLOCK_THREAD *v6; 

  v1 = 0;
  v2 = 0i64;
  if( (Irp->Flags & 2) == 0 )
    return 0;
  if( (unsigned int)KeNumberProcessors_0 > 4 )
    return 0;
  if( !ViDeadlockGlobals )
    return 0;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  if( ViDeadlockDetectionEnabled )
  {
    v2 = ViDeadlockAllocate(ViDeadlockThread);
    if( !v2 )
      return 0;
  }
  v4 = 0;
  v5 = ViRaiseIrqlToDpcLevel();
  while( 1 )
  {
    ViDeadlockDetectionLock(v4);
    v6 = ViDeadlockSearchThread(&CurrentThread->Tcb);
    if( v6 )
      break;
    if( !ViDeadlockDetectionEnabled )
      goto LABEL_14;
    if( v4 || (v4 = 1, (unsigned int)ViDeadlockDetectionTryConvertSharedToExclusive()) )
    {
      v6 = ViDeadlockAddThread(&CurrentThread->Tcb, v2);
      v2 = 0i64;
      break;
    }
    ViDeadlockDetectionUnlock(0i64);
  }
  _InterlockedIncrement((volatile signed __int32 *)&v6->PagingCount);
  v1 = 1;
LABEL_14:
  ViDeadlockDetectionUnlock(v4);
  ViLowerIrql(v5);
  if( v2 )
    ViDeadlockFree(v2, ViDeadlockThread);
  return v1;
}

Referenced by:

VfBeforeCallDriver