MmPurgeSection

UINT8 __stdcall MmPurgeSection(
        _SECTION_OBJECT_POINTERS *FsSectionObjectPointer,
        LARGE_INTEGER *Offset,
        UINT64 RegionSize,
        UINT64 PurgeFlags,
        UINT8 *ExtentPagesActive){
  char v5; 
  LARGE_INTEGER *v7; 
  UINT64 v8; 
  volatile INT64 *v9; 
  unsigned __int8 v10; 
  INT64 v11; 
  UINT64 v13; 
  BYTE v14; 
  char v15; 
  ULONG_PTR v16; 
  unsigned __int64 v17; 
  BOOL v18; 
  __int64 v19; 
  _MMPFN *v20; 
  unsigned int v21; 
  unsigned __int64 v22; 
  unsigned __int64 v23; 
  char *v24; 
  ULONG_PTR BugCheckParameter4; 
  UINT8 *v26; 
  unsigned __int8 v27; 
  bool v28; 
  ULONG_PTR v29; 
  UINT64 v30; 
  UINT8 v31; 
  UINT64 v32; 
  UINT64 v33; 
  UINT64 v34; 
  volatile INT64 *v35; 
  char v36; 
  _MMPFN *ProtoPagePfn; 
  ULONG_PTR v38; 
  UINT64 v39; 
  UINT64 SpinCount; 
  LONGLONG QuadPart; 
  ULONG_PTR BugCheckParameter2[2]; 
  ULONG_PTR v43[2]; 
  _SUBSECTION *LastSubsection[2]; 
  __int128 a2[2]; 
  __int64 v46; 
  UINT8 PageIrql; 
  BYTE v48; 
  int v49; 
  v49 = PurgeFlags;
  v48 = 0;
  v46 = 0i64;
  PageIrql = 0;
  QuadPart = 0i64;
  v5 = PurgeFlags;
  v7 = Offset;
  *ExtentPagesActive = 0;
  *(_OWORD *)BugCheckParameter2 = 0i64;
  *(_OWORD *)v43 = 0i64;
  *(_OWORD *)LastSubsection = 0i64;
  memset(a2, 0, sizeof(a2));
  if( Offset )
  {
    v7 = (LARGE_INTEGER *)&QuadPart;
    QuadPart = Offset->QuadPart;
  }
  v39 = 0i64;
  v8 = 0i64;
  v9 = MiCanFileBeTruncatedInternal(
         FsSectionObjectPointer,
         (UINT64 *)&v7->QuadPart,
         1i64,
         ((unsigned int)PurgeFlags >> 1) & 1,
         &v48);
  v10 = v48;
  v11 = (INT64)v9;
  if( v48 == 17 )
    return 0;
  if( !v9 )
    return 1;
  if( (v5 & 1) == 0 && *((_DWORD *)v9 + 22) || !*((_QWORD *)v9 + 8) )
  {
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)v9 + 9);
    __writecr8(v10);
    return 0;
  }
  *((_DWORD *)v9 + 14) |= 0x8000u;
  if( !(unsigned int)MiComputeDataFlushRange(
                        (__int64)v9,
                        v10,
                        (unsigned __int64 *)&v7->QuadPart,
                        RegionSize,
                        1,
                        (__int64)BugCheckParameter2) )
    return 1;
  v13 = BugCheckParameter2[1];
  v14 = 17;
  v15 = 1;
  v16 = v43[1];
  v48 = 17;
  v36 = 1;
LABEL_11:
  v38 = v16;
  if( v14 == 17 )
  {
    v14 = ExAcquireSpinLockExclusive((PEX_SPIN_LOCK)(v11 + 72));
    v48 = v14;
  }
  if( LastSubsection[0] == (_SUBSECTION *)v16 )
    v17 = v43[0] + 8;
  else
    v17 = *(_QWORD *)(v16 + 8) + 8i64 * (*(_DWORD *)(v16 + 44) - (*(_DWORD *)(v16 + 52) & 0x3FFFFFFFu));
  v18 = MiControlAreaUsingExtents(v11);
  if( v19 )
  {
    if( *(_DWORD *)(v38 + 108) )
    {
      v31 = 0;
      goto LABEL_49;
    }
    MiIncrementSubsectionViewCount((INT64 *)v38, 0);
    if( (*(_BYTE *)(v38 + 34) & 8) != 0 )
      MiRemoveUnusedSubsection((_MSUBSECTION *)v38);
    *(_WORD *)(v38 + 32) |= 1u;
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v11 + 72));
    __writecr8(v14);
    v20 = 0i64;
    PageIrql = 17;
    ProtoPagePfn = 0i64;
    if( v18 )
    {
      MiChangingSubsectionProtos((PVOID)v38);
      v20 = 0i64;
    }
    v21 = 0;
    if( v13 >= v17 )
      goto LABEL_43;
    while( 1 )
    {
      if( (v13 & 0xFFF) != 0 )
      {
        if( PageIrql != 17 )
          goto LABEL_24;
      }
      else if( PageIrql != 17 )
      {
        MiUnlockProtoPoolPage(v20, PageIrql);
      }
      v20 = MiCheckProtoPtePageState((_MMPTE *)v13, &PageIrql);
      ProtoPagePfn = v20;
      if( v20 )
        break;
      v13 = (v13 & 0xFFFFFFFFFFFFF000ui64) + 4096;
LABEL_60:
      if( v13 >= v17 )
        goto LABEL_61;
    }
    while( 1 )
    {
LABEL_24:
      while( 1 )
      {
        v22 = *(_QWORD *)v13;
        v23 = *(_QWORD *)v13;
        if( (*(_QWORD *)v13 & 1) == 0 )
          break;
LABEL_32:
        if( (*((_QWORD *)MmGetPfnDb() + 6 * ((v23 >> 12) & 0xFFFFFFFFFi64) + 5) & 0x4000000000000i64) != 0 )
        {
          v24 = (char *)MmGetPfnDb() + 48 * ((v23 >> 12) & 0xFFFFFFFFFi64);
          LODWORD(SpinCount) = 0;
          while( _interlockedbittestandset64((volatile signed __int32 *)v24 + 6, 0x3Fui64) )
          {
            do
              KeYieldProcessorEx(&SpinCount);
            while( *((__int64 *)v24 + 3) < 0 );
          }
          if( *(_QWORD *)v13 == v22 )
          {
            if( !v24 )
            {
LABEL_54:
              v13 += 8i64;
LABEL_59:
              v20 = ProtoPagePfn;
              goto LABEL_60;
            }
            BugCheckParameter4 = *(_QWORD *)v13;
            MiPteInShadowRange(v13);
            if( (BugCheckParameter4 & 1) != 0 )
              goto LABEL_40;
            if( (*((_DWORD *)v24 + 4) & 0x401) != 1024i64 || (*((_QWORD *)v24 + 1) | 0x8000000000000000ui64) != v13 )
              KeBugCheckEx(0xDEu, 2ui64, v13, *((_QWORD *)v24 + 1), BugCheckParameter4);
            v27 = v24[34];
            if( (((v49 & 2) != 0) & (v27 >> 4)) != 0 )
            {
LABEL_40:
              _InterlockedAnd64((volatile signed __int64 *)v24 + 3, 0x7FFFFFFFFFFFFFFFui64);
              v15 = 0;
              v36 = 0;
              goto LABEL_41;
            }
            if( (v27 & 8) != 0 )
            {
              MiWaitForPageWriteCompletion((_MMPFN *)v24, (_CONTROL_AREA *)v11, ProtoPagePfn, PageIrql);
              PageIrql = 17;
              goto LABEL_59;
            }
            if( v18 && *((_WORD *)v24 + 16) )
              *ExtentPagesActive = 1;
            LOBYTE(v26) = 17;
            MiDeleteTransitionPte((_MMPTE *)v13, (_MMPFN *)v24, v26, 1ui64);
            v21 = 1;
            if( *(_QWORD *)(v11 + 32) )
            {
              v13 += 8i64;
              if( (v13 & 0x78) == 0 && KeShouldYieldProcessor() )
              {
                MiUnlockProtoPoolPage(ProtoPagePfn, PageIrql);
                PageIrql = 17;
              }
              goto LABEL_59;
            }
LABEL_61:
            v15 = v36;
LABEL_41:
            if( PageIrql != 17 )
              MiUnlockProtoPoolPage(ProtoPagePfn, PageIrql);
LABEL_43:
            v28 = !v18;
            v29 = v38;
            if( !v28 )
              MiSubsectionProtosCreated((INT64 *)v38, (INT64)a2, 0i64, v21);
            v48 = ExAcquireSpinLockExclusive((PEX_SPIN_LOCK)(v11 + 72));
            v14 = v48;
            MiDecrementSubsectionViewCount((INT64 *)v38, 0);
            if( *(_QWORD *)(v38 + 96) || (*(_BYTE *)(v38 + 34) & 1) != 0 )
            {
              v8 = v39;
            }
            else
            {
              v8 = MiInsertUnusedSubsection((_MSUBSECTION *)v38, v30) + v39;
              v39 = v8;
            }
LABEL_47:
            if( (_SUBSECTION *)v29 == LastSubsection[0] || !v15 )
              goto LABEL_48;
            v16 = *(_QWORD *)(v29 + 16);
            v13 = *(_QWORD *)(v16 + 8);
            goto LABEL_11;
          }
          _InterlockedAnd64((volatile signed __int64 *)v24 + 3, 0x7FFFFFFFFFFFFFFFui64);
        }
      }
      if( (*(_QWORD *)v13 & 0xC00i64) != 2048 )
        goto LABEL_54;
      if( !v22 || !qword_140C4DC80 || (v22 & qword_140C4DC80) != 0 )
      {
        v23 = *(_QWORD *)v13;
        if( qword_140C4DC80 && (v22 & 0x10) == 0 )
          v23 = v22 & ~qword_140C4DC80;
        goto LABEL_32;
      }
    }
  }
  v29 = v38;
  if( (_SUBSECTION *)v38 != LastSubsection[0] )
    goto LABEL_47;
LABEL_48:
  v31 = v36;
LABEL_49:
  v32 = MiDecrementSubsections((_SUBSECTION *)v43[1], (_SUBSECTION *)v43[1], 0i64) + v8;
  v33 = MiDecrementSubsections(LastSubsection[0], LastSubsection[0], 0i64);
  --*(_QWORD *)(v11 + 40);
  *(_DWORD *)(v11 + 56) &= ~4u;
  v34 = v33 + v32;
  if( v34 )
    v35 = *(volatile INT64 **)(qword_140C4E388 + 8i64 * (*(_WORD *)(v11 + 60) & 0x3FF));
  else
    v35 = 0i64;
  MiCheckControlArea((_CONTROL_AREA *)v11, v14);
  if( v34 )
    MiReturnCrossPartitionSectionCharges(v35, 1i64, v34);
  return v31;
}

Referenced by:

CcPurgeCacheSection