MiIncrementLargeSubsections

NTSTATUS __stdcall MiIncrementLargeSubsections(INT64 *a1, UINT64 a2){
  INT64 *v2; 
  NTSTATUS v4; 
  INT64 v5; 
  INT64 *v6; 
  unsigned __int64 v7; 
  int v8; 
  int v9; 
  CHAR v10; 
  int v11; 
  NTSTATUS v12; 
  _MI_CONTROL_AREA_WAIT_BLOCK *v13; 
  UINT64 v14; 
  _MI_CONTROL_AREA_WAIT_BLOCK *WaitList; 
  int v17; 
  int v18; 
  int v19[2]; 
  __int64 v20[3]; 
  _CONTROL_AREA *ControlArea; 

  v2 = a1;
  ControlArea = (_CONTROL_AREA *)*a1;
  v4 = 0;
  v5 = 0i64;
  v6 = (INT64 *)(*a1 + 72);
  v7 = (unsigned __int8)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 )
    {
      v18 = 0;
      v19[1] = 0;
      v20[1] = (__int64)v20;
      v20[0] = (__int64)v20;
      WaitList = ControlArea->WaitList;
      ControlArea->WaitList = (_MI_CONTROL_AREA_WAIT_BLOCK *)&WaitList;
      v19[0] = 393479;
      v17 = 512;
      ExReleaseSpinLockExclusiveFromDpcLevel(v6);
      __writecr8(v7);
      KeWaitForGate((_KGATE *)v19, WrPageOut, v10);
    }
    else
    {
      v11 = v9 + 1;
      *((_DWORD *)v2 + 27) = v11;
      if( v11 == 1 )
      {
        ExReleaseSpinLockExclusiveFromDpcLevel(v6);
        __writecr8(v7);
        v12 = MiEnableLargeSubsection((INT64)v2);
        ExAcquireSpinLockExclusive(v6);
        v13 = MiBuildWakeList(ControlArea, 0x200ui64);
        MiReleaseControlAreaWaiters(v13);
        if( !v12 )
        {
          v4 = -1;
          --*((_DWORD *)v2 + 27);
          goto LABEL_20;
        }
        ++*((_DWORD *)v2 + 27);
      }
      v5 = (INT64)v2;
      if( a2 )
      {
        v14 = *((unsigned int *)v2 + 11);
        if( a2 <= v14 )
          goto LABEL_20;
        a2 -= v14;
      }
      v2 = (INT64 *)v2[2];
    }
    if( !v2 )
      goto LABEL_20;
  }
  v4 = -1;
LABEL_20:
  ExReleaseSpinLockExclusiveFromDpcLevel(v6);
  __writecr8(v7);
  if( v4 == -1 && v5 )
    MiDecrementLargeSubsections((_CONTROL_AREA **)a1, v5);
  return v4;
}

Referenced by:

MiCloneLargeFileOnlyVad
MiMapViewOfDataSection
MiReferenceDataSubsections