MiCleanSection

NTSTATUS __stdcall MiCleanSection(_CONTROL_AREA *ControlArea, UINT8 OldIrql, UINT8 DelayClose){
  bool v3; 
  _BOOL8 v4; 
  unsigned __int64 v6; 
  INT16 v8; 
  INT64 *p_ControlAreaLock; 
  NTSTATUS v11; 
  unsigned __int64 NumberOfMappedViews; 
  int v13; 
  UINT64 v14; 
  UINT64 v15; 
  _MI_CROSS_PARTITION_CHARGES *v16; 
  UINT64 Flags; 
  _IO_STATUS_BLOCK IoStatus; 
  __int128 v19; 
  __int128 v20; 
  __int64 v21; 

  v3 = ControlArea->FilePointer.Value == 0;
  v21 = 0i64;
  v4 = !v3;
  LOBYTE(v6) = OldIrql;
  IoStatus = 0i64;
  v19 = 0i64;
  v20 = 0i64;
  while( 1 )
  {
    if( (ControlArea->u.LongFlags & 0x20) != 0 )
      goto LABEL_3;
    DWORD1(v20) = 0;
    p_ControlAreaLock = (INT64 *)&ControlArea->ControlAreaLock;
    v21 = (__int64)&v20 + 8;
    *((_QWORD *)&v19 + 1) = 4i64;
    *((_QWORD *)&v20 + 1) = (char *)&v20 + 8;
    *(_QWORD *)&v19 = ControlArea->WaitList;
    ControlArea->WaitList = (_MI_CONTROL_AREA_WAIT_BLOCK *)&v19;
    LOWORD(v20) = 263;
    BYTE2(v20) = 6;
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&ControlArea->ControlAreaLock);
    __writecr8((unsigned __int8)v6);
    LODWORD(Flags) = 0x80000000;
    v11 = MiFlushSectionInternal(0i64, 0i64, (_SUBSECTION *)&ControlArea[1], 0i64, 0i64, Flags, &IoStatus);
    v6 = (unsigned __int8)ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
    MiRemoveWakeListEntry(ControlArea, (_MI_CONTROL_AREA_WAIT_BLOCK *)&v19);
    if( !HIDWORD(v19) )
      break;
    NumberOfMappedViews = ControlArea->NumberOfMappedViews;
    if( NumberOfMappedViews != 1 || ControlArea->NumberOfSectionReferences )
    {
      v13 = 1;
      goto LABEL_10;
    }
  }
  if( v11 >= 0 )
  {
LABEL_3:
    ControlArea->NumberOfMappedViews = 0i64;
    LOBYTE(v8) = v6;
    MiDestroySection(ControlArea, v8, 0i64);
    return 1;
  }
  NumberOfMappedViews = ControlArea->NumberOfMappedViews;
  v13 = 2;
LABEL_10:
  ControlArea->NumberOfMappedViews = NumberOfMappedViews - 1;
  if( DelayClose )
    ControlArea->u.LongFlags |= 0x40000u;
  v14 = 0i64;
  if( v13 == 2 && (MiInsertUnusedSegment(ControlArea), (v14 = v15) != 0) )
    v16 = *(_MI_CROSS_PARTITION_CHARGES **)(*(&stru_140C4DB30 + 267) + 8i64 * (ControlArea->u1.Flags._bf_0 & 0x3FF));
  else
    v16 = 0i64;
  ExReleaseSpinLockExclusiveFromDpcLevel(p_ControlAreaLock);
  __writecr8(v6);
  if( v14 )
    MiReturnCrossPartitionSectionCharges(v16, v4, v14);
  return 0;
}

Referenced by:

MiAttemptSectionDelete
MiCheckControlArea