VfDeadlockBeforeCallDriver

UINT64 __fastcall VfDeadlockBeforeCallDriver(_IRP *Irp){
  unsigned int v1; 
  VOID *v2; 
  _KTHREAD *CurrentThread; 
  VOID *v4; 
  unsigned int v5; 
  UINT8 v6; 
  _VI_DEADLOCK_THREAD *v7; 
  v1 = 0;
  v2 = 0i64;
  if( (*((_DWORD *)Irp + 4) & 2) == 0 )
    return 0i64;
  if( (unsigned int)KeNumberProcessors_0 > 4 )
    return 0i64;
  if( !ViDeadlockGlobals )
    return 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  if( ViDeadlockDetectionEnabled )
  {
    LODWORD(v4) = ViDeadlockAllocate(3);
    v2 = v4;
    if( !v4 )
      return 0i64;
  }
  v5 = 0;
  v6 = ViRaiseIrqlToDpcLevel();
  while( 1 )
  {
    ViDeadlockDetectionLock(v5);
    v7 = ViDeadlockSearchThread((_KTHREAD *)CurrentThread);
    if( v7 )
      break;
    if( !ViDeadlockDetectionEnabled )
      goto LABEL_14;
    if( v5 || (v5 = 1, (unsigned int)ViDeadlockDetectionTryConvertSharedToExclusive()) )
    {
      v7 = ViDeadlockAddThread((_KTHREAD *)CurrentThread, v2);
      v2 = 0i64;
      break;
    }
    ViDeadlockDetectionUnlock(0i64);
  }
  _InterlockedIncrement((volatile signed __int32 *)&v7->PagingCount);
  v1 = 1;
LABEL_14:
  ViDeadlockDetectionUnlock(v5);
  ViLowerIrql(v6);
  if( v2 )
    ViDeadlockFree(v2, 3);
  return v1;
}

Referenced by:

VfBeforeCallDriver