MiUpdateActiveSubsection

NTSTATUS __stdcall MiUpdateActiveSubsection(_SUBSECTION *LastSubsection, UINT64 PtesUsed){
  _SUBSECTION *v2; 
  unsigned int v3; 
  NTSTATUS FileExtents; 
  UINT64 v5; 
  volatile LONG *v6; 
  KIRQL v7; 
  int v8; 
  int v9; 
  int v10; 
  int v12; 
  __int64 v13; 
  v2 = LastSubsection;
  v3 = 0;
  v13 = *(_QWORD *)LastSubsection;
  FileExtents = 0;
  v5 = 0i64;
  v6 = (volatile LONG *)(*(_QWORD *)LastSubsection + 72i64);
  v7 = ExAcquireSpinLockExclusive(v6);
  do
  {
    if( !*((_QWORD *)v2 + 1) || (*((_DWORD *)v2 + 13) & 0x40000000) == 0 )
      goto LABEL_10;
    MiReferenceSubsection(v2, 0i64);
    if( v8 < 2 )
    {
      ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v6);
      __writecr8(v7);
      return 0;
    }
    v9 = *((_DWORD *)v2 + 11) - (*((_DWORD *)v2 + 13) & 0x3FFFFFFF);
    v12 = v9;
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v6);
    __writecr8(v7);
    FileExtents = MiAllocateFileExtents((ULONG_PTR)v2, 0, *((_QWORD *)v2 + 1), v9, 0);
    v10 = 0;
    v7 = ExAcquireSpinLockExclusive(v6);
    if( FileExtents >= 0 && v12 != *((_DWORD *)v2 + 11) - (*((_DWORD *)v2 + 13) & 0x3FFFFFFF) )
      v10 = 1;
    v5 += MiDecrementSubsections(v2, v2, 0i64);
    if( v10 != 1 )
    {
      if( FileExtents < 0 )
        break;
LABEL_10:
      v2 = (_SUBSECTION *)*((_QWORD *)v2 + 2);
    }
  }
  while( v2 );
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v6);
  __writecr8(v7);
  if( v5 )
  {
    LOBYTE(v3) = *(_QWORD *)(v13 + 64) != 0i64;
    MiReturnCrossPartitionSectionCharges(
      *(volatile INT64 **)(qword_140C4E388 + 8i64 * (*(_WORD *)(v13 + 60) & 0x3FF)),
      v3,
      v5);
  }
  return FileExtents;
}

Referenced by:

MmExtendSection