MiUpdateLastSubsectionSize

NTSTATUS __fastcall MiUpdateLastSubsectionSize(__int64 a1, _QWORD *a2, unsigned int a3){
  _WORD *v3; 
  UINT64 v5; 
  int v7; 
  volatile LONG *v8; 
  unsigned __int64 v9; 
  INT64 SubsectionHoldingCrossPartitionReferences; 
  __int64 v11; 
  __int16 v12; 
  __int64 v13; 
  NTSTATUS result; 
  v3 = *(_WORD **)a1;
  v5 = a3;
  v7 = 0;
  v8 = (volatile LONG *)(*(_QWORD *)a1 + 72i64);
  while( 1 )
  {
    v9 = ExAcquireSpinLockExclusive(v8);
    if( !(_DWORD)v5 )
      break;
    SubsectionHoldingCrossPartitionReferences = MiGetSubsectionHoldingCrossPartitionReferences(a1);
    if( (*(_DWORD *)(MiGetSubsectionHoldingCrossPartitionReferences(SubsectionHoldingCrossPartitionReferences) + 48) & 0x3FFFFFFF) == 0 )
    {
      if( v7 == 1 )
        v7 = 2;
LABEL_6:
      *(_DWORD *)(a1 + 52) ^= (*(_DWORD *)(a1 + 52) ^ (*(_DWORD *)(a1 + 52) - v5)) & 0x3FFFFFFF;
      break;
    }
    if( v7 )
      goto LABEL_6;
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v8);
    __writecr8(v9);
    result = MiGetSubsectionCharges(a1);
    if( result < 0 )
      return result;
    v7 = 1;
  }
  *(_DWORD *)(a1 + 40) = (*a2 >> 12) - (*(_DWORD *)(a1 + 36) | ((*(_WORD *)(a1 + 32) & 0xFFC0) << 26));
  *(_WORD *)(a1 + 34) = *(_WORD *)(a1 + 34) & 0xF | (16 * *(_WORD *)a2);
  ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v8);
  __writecr8(v9);
  if( (_DWORD)v5 )
  {
    v11 = *(_QWORD *)v3;
    _InterlockedExchange64(
      (volatile __int64 *)(*(_QWORD *)v3 + 24i64),
      _InterlockedCompareExchange64((volatile signed __int64 *)(*(_QWORD *)v3 + 24i64), -1i64, -1i64) + (v5 << 12));
    v12 = *(_WORD *)(v11 + 12);
    v13 = *(unsigned int *)(v11 + 8);
    *(_DWORD *)(v11 + 8) = v5 + v13;
    *(_WORD *)(v11 + 12) = v12 ^ (v12 ^ ((v5 + (v13 | ((unsigned __int64)(v12 & 0x3FF) << 32))) >> 32)) & 0x3FF;
    if( v7 == 2 )
      MiReturnCrossPartitionSectionCharges(*(volatile INT64 **)(qword_140C4E388 + 8i64 * (v3[30] & 0x3FF)), 1i64, v5);
  }
  return 0;
}

Referenced by:

MmExtendSection