MiTrimWorkingSetBuildup

VOID __stdcall MiTrimWorkingSetBuildup(_MMMOD_WRITER_MDL_ENTRY *ModWriterEntry, UINT64 ReleaseCommit){
  int v2; 
  __int64 v4; 
  UINT64 v5; 
  __int64 v6; 
  unsigned int v7; 
  __int64 v8; 
  __int64 v9; 
  __int64 v10; 
  int v11; 
  char *v12; 
  unsigned int v13; 
  unsigned int v14; 
  unsigned int v15; 
  unsigned int v16; 
  char *v17; 
  __int64 i; 
  unsigned __int64 v19; 
  unsigned int v20; 
  UINT32 v21; 
  _DWORD *v22; 
  unsigned int v23; 
  _DWORD *v24; 
  __int64 v25; 
  int v26; 
  __int64 v27; 
  unsigned int j; 
  UINT32 v29; 
  _DWORD *v30; 
  unsigned int SizeOfBitMap; 
  _RTL_BITMAP BitMapHeader; 
  _MMSUPPORT_INSTANCE *Vm; 

  v2 = 0;
  Vm = (_MMSUPPORT_INSTANCE *)ModWriterEntry->u.IoStatus.Information;
  BitMapHeader = 0i64;
  while( v2 != 2 )
  {
    v4 = 80i64 * v2;
    v5 = v4 + ReleaseCommit + 248;
    if( !*(_BYTE *)(v5 + 72) )
      goto LABEL_4;
    v7 = 0;
    v8 = (_QWORD)MmGetPteBase() << 25;
    v9 = v8 + ((*(_QWORD *)(v5 + 64) & 0xFFFFFFFFFFFFF000ui64) << 16);
    BitMapHeader.SizeOfBitMap = 512;
    BitMapHeader.Buffer = (unsigned int *)(v4 + ReleaseCommit + 248);
    v10 = (__int64)((v9 & 0xFFFFFFE000000000ui64) - v8) >> 16;
    v11 = (((_BYTE)v4 + (_BYTE)ReleaseCommit - 8) & 4) != 0i64 ? 0x20 : 0;
    v12 = (char *)BitMapHeader.Buffer - ((((_BYTE)v4 + (_BYTE)ReleaseCommit - 8) & 4) != 0i64 ? 4 : 0);
    while( 1 )
    {
      v13 = v7 < BitMapHeader.SizeOfBitMap ? v7 : 0;
      v14 = BitMapHeader.SizeOfBitMap - 1;
      while( 1 )
      {
        v15 = v14 + v11;
        v16 = v13 + v11;
        if( v14 - v13 == -1 )
          goto LABEL_41;
        v17 = &v12[8 * ((unsigned __int64)v16 >> 6)];
        for( i = ~*(_QWORD *)v17 | ((1i64 << (v16 & 0x3F)) - 1); i == -1; i = ~*(_QWORD *)v17 )
        {
          v17 += 8;
          if( v17 > &v12[8 * ((unsigned __int64)v15 >> 6)] )
            goto LABEL_41;
        }
        _BitScanForward64(&v19, ~i);
        v20 = v19 + ((unsigned int)((v17 - v12) >> 3) << 6);
        if( v20 > v15 )
        {
LABEL_41:
          v20 = -1;
        }
        else if( v20 != -1 )
        {
          break;
        }
        if( !v13 )
          break;
        SizeOfBitMap = v7 + 1;
        if( v7 + 1 > BitMapHeader.SizeOfBitMap )
          SizeOfBitMap = BitMapHeader.SizeOfBitMap;
        v14 = SizeOfBitMap - 1;
        v13 = 0;
      }
      v21 = v20 - v11;
      if( v20 == -1 )
        v21 = -1;
      if( v21 < v7 || v21 == -1 )
        break;
      if( v21 < 0x200 )
      {
        v22 = (_DWORD *)(v5 + 60);
        v23 = v21;
        v24 = (_DWORD *)(v5 + 4 * ((unsigned __int64)v21 >> 5));
        if( v24 != (_DWORD *)(v5 + 60) )
        {
          v25 = v21 & 0x1F;
          if( (*v24 | *((_DWORD *)qword_140011CE0 + v25)) == -1 )
          {
            v23 = v21 - v25 + 32;
            for( ++v24; v24 < v22 && *v24 == -1; ++v24 )
              v23 += 32;
          }
        }
        while( v23 < 0x200 && _bittest((const signed __int32 *)v5, v23) )
          ++v23;
        v26 = 0;
        if( v24 == v22 )
          goto LABEL_32;
        v27 = v23 & 0x1F;
        if( (*v24 & ~*((_DWORD *)qword_140011CE0 + v27)) != 0 )
          goto LABEL_32;
        v26 = 32 - v27;
        if( (_DWORD)v27 != 33 )
        {
          v30 = v24 + 1;
          while( v30 < v22 && !*v30 )
          {
            ++v30;
            v26 += 32;
            if( v26 == -1 )
              goto LABEL_37;
          }
LABEL_32:
          for( j = v26 + v23; j < 0x200 && !_bittest((const signed __int32 *)v5, j) && v26 != -1; ++j )
            ++v26;
        }
LABEL_37:
        if( v26 )
          goto LABEL_38;
        goto LABEL_49;
      }
      v26 = 0;
LABEL_49:
      v23 = 512;
LABEL_38:
      v29 = v23 - v21;
      MiSetVaAgeList(Vm, v10 + (v21 << 12), v29, v2 != 0 ? 6 : 0);
      RtlClearBits(&BitMapHeader, v21, v29);
      v7 = v21 + v26 + v29;
      if( v26 )
      {
        v12 = (char *)(v5 - ((v5 & 4) != 0 ? 4 : 0));
        if( v7 != 512 )
          continue;
      }
      break;
    }
    *(_BYTE *)(v5 + 72) = 0;
LABEL_4:
    ++v2;
  }
  if( *(_DWORD *)(ReleaseCommit + 68) )
  {
    LODWORD(v6) = MiFreeWsleList(Vm, (_MMWSLE_FLUSH_LIST *)(ReleaseCommit + 56), (*(_DWORD *)ReleaseCommit >> 8) & 1);
    *(_QWORD *)(ReleaseCommit + 16) -= v6;
  }
}

Referenced by:

MiTrimPte
MiTrimPteWorker
MiTrimWorkingSetTail