MiIncrementLargeSubsections

INT64 __fastcall MiIncrementLargeSubsections(INT64 *a1, UINT64 a2){
  INT64 *v2; 
  unsigned int v4; 
  __int64 v5; 
  volatile LONG *v6; 
  unsigned __int64 v7; 
  int v8; 
  int v9; 
  int v10; 
  int v11; 
  _QWORD *v12; 
  UINT64 v13; 
  __int64 v15; 
  int v16; 
  int v17; 
  int PcValue[2]; 
  __int64 v19[3]; 
  _CONTROL_AREA *ControlArea; 
  v2 = a1;
  ControlArea = (_CONTROL_AREA *)*a1;
  v4 = 0;
  v5 = 0i64;
  v6 = (volatile LONG *)(*a1 + 72);
  v7 = ExAcquireSpinLockExclusive(v6);
  while( 1 )
  {
    v8 = *((_DWORD *)v2 + 12) >> 30;
    if( !v8 )
      break;
    if( v8 == 1 && !v4 )
      v4 = 1;
    v9 = *((_DWORD *)v2 + 27);
    if( v9 == -1 )
      break;
    if( v9 == 1 )
    {
      v17 = 0;
      PcValue[1] = 0;
      v19[1] = (__int64)v19;
      v19[0] = (__int64)v19;
      v15 = *((_QWORD *)ControlArea + 10);
      *((_QWORD *)ControlArea + 10) = &v15;
      PcValue[0] = 393479;
      v16 = 512;
      ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v6);
      __writecr8(v7);
      KeWaitForGate(PcValue, 19);
    }
    else
    {
      v10 = v9 + 1;
      *((_DWORD *)v2 + 27) = v10;
      if( v10 == 1 )
      {
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v6);
        __writecr8(v7);
        v11 = MiEnableLargeSubsection((INT64)v2);
        ExAcquireSpinLockExclusive(v6);
        MiBuildWakeList(ControlArea, 0x200ui64);
        MiReleaseControlAreaWaiters(v12);
        if( !v11 )
        {
          v4 = -1;
          --*((_DWORD *)v2 + 27);
          goto LABEL_20;
        }
        ++*((_DWORD *)v2 + 27);
      }
      v5 = (__int64)v2;
      if( a2 )
      {
        v13 = *((unsigned int *)v2 + 11);
        if( a2 <= v13 )
          goto LABEL_20;
        a2 -= v13;
      }
      v2 = (INT64 *)v2[2];
    }
    if( !v2 )
      goto LABEL_20;
  }
  v4 = -1;
LABEL_20:
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v6);
  __writecr8(v7);
  if( v4 == -1 && v5 )
    MiDecrementLargeSubsections(a1, v5);
  return v4;
}

Referenced by:

MiCloneLargeFileOnlyVad
MiMapViewOfDataSection
MiReferenceDataSubsections