MiScrubNode

VOID __stdcall MiScrubNode(ULONG_PTR *Partition, _MISCRUB_PACKET *Packet){
  _KEVENT *v2; 
  UINT64 v3; 
  _MI_PARTITION *v5; 
  unsigned int *v6; 
  unsigned int *v7; 
  _DWORD *v8; 
  __int64 v9; 
  UINT64 v10; 
  UINT64 v11; 
  _MMPFN *i; 
  int v13; 
  unsigned __int64 v14; 
  __int64 v15; 
  NTSTATUS v16; 
  INT64 v17; 
  UINT64 v18; 
  unsigned __int64 v19; 
  UINT64 *DrainStacks; 
  UINT64 *ZeroFreeCount; 
  UINT64 *v22; 
  UINT64 v23; 
  _MI_PARTITION *v24; 

  v3 = Partition[2];
  v5 = *(_MI_PARTITION **)(*(_QWORD *)Partition + 48i64);
  v6 = (unsigned int *)*((_QWORD *)Partition + 27);
  v24 = v5;
  v7 = &v6[4 * *v6 + 4];
  MiScrubNodeLargePages(Partition, v5, v3, v2);
  v8 = (_DWORD *)*((_QWORD *)Partition + 27);
  v9 = 0i64;
  if( *v8 )
  {
    while( v7[2 * v9] != Partition[2] )
    {
LABEL_19:
      v8 = (_DWORD *)*((_QWORD *)Partition + 27);
      v9 = (unsigned int)(v9 + 1);
      if( (unsigned int)v9 >= *v8 )
        return;
    }
    v10 = *(_QWORD *)&v8[4 * (unsigned int)v9 + 4];
    v11 = v10 + *(_QWORD *)&v8[4 * (unsigned int)v9 + 6] - 1i64;
    for( i = &MmGetPfnDb()[v11]; ; --i )
    {
      if( v11 < v10 || !v10 )
        goto LABEL_19;
      LOBYTE(v13) = MiScrubInterrupted((INT64)Partition);
      if( v13 )
        return;
      LODWORD(v23) = 0;
      MiPfnsWorthTrying(v5, i, 1ui64, 0x7000000ui64, &v23, ZeroFreeCount);
      if( v14 )
      {
        if( v14 >= v11 - v10 + 1 )
          goto LABEL_19;
        i = (_MMPFN *)((char *)i + 48 - 48 * v14);
        v11 += 1 - v14;
      }
      else
      {
        if( (_DWORD)v23 == 1 )
          MiEmptyKernelStackCache();
        LODWORD(v22) = -1;
        LODWORD(ZeroFreeCount) = 117440512;
        LODWORD(v15) = MiClaimPhysicalRun(
                         v5,
                         v11,
                         1ui64,
                         (_MMPTE_COPY_LIST *)0xFFFFFFFFFi64,
                         (UINT64)(Partition + 44),
                         (UINT64)ZeroFreeCount,
                         v22);
        if( !v15 )
        {
          v16 = MiScrubPage(Partition, i, 0i64, 0i64);
          v19 = MiLockPageInline(i);
          if( v16 < 0 || (*((_BYTE *)&i->u3 + 3) & 0x40) != 0 )
          {
            v5 = v24;
            if( *(_MI_PARTITION **)(*(&stru_140C4DB30 + 267) + 8 * (((unsigned __int64)i->u4._bf_0 >> 39) & 0x3FF)) == v24 )
            {
              MiMakePageBad(i, 2ui64, v17);
LABEL_16:
              _InterlockedAnd64(&i->u2.Lock, 0x7FFFFFFFFFFFFFFFui64);
              __writecr8(v19);
              goto LABEL_17;
            }
          }
          else
          {
            v5 = v24;
          }
          MiInsertPageInFreeOrZeroedList(v11, 2ui64, v17, v18, (UINT64)DrainStacks, (UINT64)ZeroFreeCount);
          goto LABEL_16;
        }
      }
LABEL_17:
      --v11;
    }
  }
}

Referenced by:

MiScrubMemoryWorker