MiInsertUnusedSubsection

UINT64 __stdcall MiInsertUnusedSubsection(_MSUBSECTION *MappedSubsection, UINT64 InsertTail){
  int v2; 
  __int64 v3; 
  unsigned __int64 v5; 
  __int64 v6; 
  unsigned __int64 v7; 
  unsigned __int64 v8; 
  UINT64 v9; 
  _QWORD *v10; 
  _QWORD *v11; 
  _QWORD *v13; 
  unsigned int v14; 
  v2 = 0;
  v3 = *((unsigned int *)MappedSubsection + 11);
  v5 = 8 * v3;
  v6 = *(_QWORD *)(qword_140C4E388 + 8i64 * (*(_WORD *)(*(_QWORD *)MappedSubsection + 60i64) & 0x3FF));
  if( (unsigned __int64)(8 * v3) > 0xFE0 )
  {
    if( v5 >= 0x10000 || ((8 * (_WORD)v3) & 0xFFFu) > 0xFC0 )
    {
      v8 = (v5 + 4095) & 0xFFFFFFFFFFFFF000ui64;
      goto LABEL_4;
    }
    v7 = v5 + 15;
  }
  else
  {
    v7 = v5 + 31;
  }
  v8 = v7 & 0xFFFFFFFFFFFFFFF0ui64;
LABEL_4:
  ExAcquireSpinLockExclusiveAtDpcLevel((INT64 *)(v6 + 1344));
  *((_WORD *)MappedSubsection + 17) |= 8u;
  *(_QWORD *)(v6 + 1696) += v8;
  _InterlockedExchangeAdd64(&qword_140C4C6D8, v8);
  v9 = 0i64;
  if( !MiControlAreaUsingExtents(*(_QWORD *)MappedSubsection) && (*((_DWORD *)MappedSubsection + 12) & 0x3FFFFFFF) != 0 )
  {
    MiUpdateSubsectionCrossPartitionRefs(MappedSubsection, 0i64);
    v9 = *((_DWORD *)MappedSubsection + 11) - (v14 & *((_DWORD *)MappedSubsection + 13));
  }
  v10 = (_QWORD *)((char *)MappedSubsection + 80);
  if( *((_DWORD *)MappedSubsection + 26) )
  {
    v11 = *(_QWORD **)(v6 + 1728);
    if( *v11 == v6 + 1720 )
    {
      *v10 = v6 + 1720;
      *((_QWORD *)MappedSubsection + 11) = v11;
      *v11 = v10;
      *(_QWORD *)(v6 + 1728) = v10;
      goto LABEL_10;
    }
LABEL_21:
    __fastfail(3u);
  }
  v13 = *(_QWORD **)(v6 + 1744);
  if( *v13 != v6 + 1736 )
    goto LABEL_21;
  *v10 = v6 + 1736;
  *((_QWORD *)MappedSubsection + 11) = v13;
  *v13 = v10;
  *(_QWORD *)(v6 + 1744) = v10;
  *(_QWORD *)(v6 + 1424) += v3;
  if( *(_QWORD *)(v6 + 1424) >= 0x20000ui64 )
    v2 = 1;
LABEL_10:
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v6 + 1344));
  if( v2 == 1 )
    KeSetEvent((PRKEVENT)(v6 + 1376), 0);
  return v9;
}

Referenced by:

MiAppendSubsectionChain
MiDecrementSubsections
MiDeleteCachedSubsection
MiDereferenceControlAreaPfnList
MiFlushSectionInternal
MiRemoveViewsFromSection
MmPurgeSection