MiCleanSection

UINT64 __stdcall MiCleanSection(_CONTROL_AREA *ControlArea, UINT8 OldIrql, UINT8 DelayClose){
  bool v3; 
  _BOOL8 v4; 
  unsigned __int64 v6; 
  INT16 v8; 
  INT64 *v10; 
  int v11; 
  __int64 v12; 
  int v13; 
  UINT64 inserted; 
  volatile INT64 *v15; 
  __int128 v16; 
  __int128 v17; 
  __int128 v18; 
  __int64 v19; 
  v3 = *((_QWORD *)ControlArea + 8) == 0i64;
  v19 = 0i64;
  v4 = !v3;
  LOBYTE(v6) = OldIrql;
  v16 = 0i64;
  v17 = 0i64;
  v18 = 0i64;
  while( 1 )
  {
    if( (*((_DWORD *)ControlArea + 14) & 0x20) != 0 )
      goto LABEL_3;
    DWORD1(v18) = 0;
    v10 = (INT64 *)((char *)ControlArea + 72);
    v19 = (__int64)&v18 + 8;
    *((_QWORD *)&v17 + 1) = 4i64;
    *((_QWORD *)&v18 + 1) = (char *)&v18 + 8;
    *(_QWORD *)&v17 = *((_QWORD *)ControlArea + 10);
    *((_QWORD *)ControlArea + 10) = &v17;
    LOWORD(v18) = 263;
    BYTE2(v18) = 6;
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)ControlArea + 9);
    __writecr8((unsigned __int8)v6);
    v11 = MiFlushSectionInternal(0i64, 0i64, (__int64 *)ControlArea + 16, 0i64, 0i64, 0x80000000, (__int64)&v16);
    v6 = ExAcquireSpinLockExclusive((PEX_SPIN_LOCK)ControlArea + 18);
    MiRemoveWakeListEntry((__int64)ControlArea, (_QWORD **)&v17);
    if( !HIDWORD(v17) )
      break;
    v12 = *((_QWORD *)ControlArea + 5);
    if( v12 != 1 || *((_QWORD *)ControlArea + 3) )
    {
      v13 = 1;
      goto LABEL_10;
    }
  }
  if( v11 >= 0 )
  {
LABEL_3:
    *((_QWORD *)ControlArea + 5) = 0i64;
    LOBYTE(v8) = v6;
    MiDestroySection(ControlArea, v8, 0i64);
    return 1i64;
  }
  v12 = *((_QWORD *)ControlArea + 5);
  v13 = 2;
LABEL_10:
  *((_QWORD *)ControlArea + 5) = v12 - 1;
  if( DelayClose )
    *((_DWORD *)ControlArea + 14) |= 0x40000u;
  inserted = 0i64;
  if( v13 == 2 && (inserted = MiInsertUnusedSegment(ControlArea)) != 0 )
    v15 = *(volatile INT64 **)(qword_140C4E388 + 8i64 * (*((_WORD *)ControlArea + 30) & 0x3FF));
  else
    v15 = 0i64;
  ExReleaseSpinLockExclusiveFromDpcLevel(v10);
  __writecr8(v6);
  if( inserted )
    MiReturnCrossPartitionSectionCharges(v15, v4, inserted);
  return 0i64;
}

Referenced by:

MiAttemptSectionDelete
MiCheckControlArea