MiPfnsWorthTrying

VOID __fastcall MiPfnsWorthTrying(
        _MI_PARTITION *Partition,
        _MMPFN *FirstPfn,
        UINT64 SizeInPages,
        UINT64 Flags,
        UINT64 *DrainStacks,
        UINT64 *ZeroFreeCount){
  unsigned __int16 PartitionId; 
  _MMPFN *v8; 
  int v9; 
  UINT64 v10; 
  _MMPFN *PfnDb; 
  unsigned __int64 EntireField; 
  NTSTATUS PfnPageSizeIndexUnsynchronized; 
  int v15; 
  signed __int64 v16; 
  int v17; 
  __int64 v18; 
  _QWORD *v19; 
  unsigned int v20; 
  unsigned int v21; 
  _QWORD *v22; 
  unsigned __int64 v23; 
  bool v24; 
  unsigned __int64 v25; 
  char v26; 
  int v27; 
  bool v28; 
  _LIST_ENTRY *Blink; 
  _UNICODE_STRING *v30; 
  __int64 v31; 
  unsigned __int64 LeafPfnBuddy; 
  int v33; 
  __int64 v34; 
  unsigned __int64 v35; 
  unsigned __int16 v36; 
  INT64 a2; 
  INT64 a3; 

  PartitionId = Partition->Core.PartitionId;
  v8 = &FirstPfn[SizeInPages];
  v36 = Partition->Core.PartitionId;
  v9 = Flags;
  *(_DWORD *)DrainStacks = 0;
  v10 = -1i64;
  v35 = -1i64;
  if( FirstPfn >= v8 )
    return;
  PfnDb = MmGetPfnDb();
  while( 1 )
  {
    EntireField = FirstPfn->u4.EntireField;
    if( ((EntireField >> 39) & 0x3FF) != PartitionId )
    {
      MiPfnLargeBitSet((UINT64)&Irp);
      return;
    }
    PfnPageSizeIndexUnsynchronized = -1;
    v15 = *(_BYTE *)(&FirstPfn->u3 + 1) & 7;
    LODWORD(a2) = v15;
    if( (EntireField & 0x1000000000i64) != 0 )
    {
      LODWORD(a3) = 0;
      PfnPageSizeIndexUnsynchronized = MiGetPfnPageSizeIndexUnsynchronized(FirstPfn, &a2, &a3);
      if( PfnPageSizeIndexUnsynchronized == -1 )
        goto LABEL_67;
      v15 = a2;
      v16 = (char *)FirstPfn - (char *)PfnDb;
      if( (_DWORD)a2 == 6 )
        return;
      v10 = v35;
    }
    else
    {
      v16 = (char *)FirstPfn - (char *)PfnDb;
    }
    if( v15 == 5 )
      break;
    if( v15 <= 1 )
    {
      if( PfnPageSizeIndexUnsynchronized == -1 )
        goto LABEL_67;
      goto LABEL_22;
    }
    v26 = *((_BYTE *)&FirstPfn->u3 + 3);
    v27 = 0;
    if( v26 < 0 )
    {
      if( v15 == 2 )
      {
        v28 = FirstPfn->u3.ReferenceCount == 0;
        goto LABEL_32;
      }
      if( v15 != 6
        || (*(_BYTE *)(&FirstPfn->u3 + 1) & 0x10) != 0
        || FirstPfn->u3.ReferenceCount != 1
        || (((unsigned __int64)FirstPfn->u4._bf_0 >> 60) & 7) == 2
        || (v26 & 8) != 0
        || (FirstPfn->$976DF529DAC3D73085C9E386D94B91E6::$E228DCF3D8940E384DBC5EFCA756D8B6::gap0[0] & 1) == 0 )
      {
        return;
      }
LABEL_62:
      MiActivePageClaimCandidate(Partition, FirstPfn, 0i64, v10);
      if( v34 || (v9 & 8) != 0 || v27 == 1 && MiClusterVadFull(FirstPfn, 0i64) == 1 )
        return;
      goto LABEL_66;
    }
    if( v15 <= 4 )
    {
      if( FirstPfn->u3.ReferenceCount )
        return;
      if( (v9 & 0x4000000) == 0 && (FirstPfn->u4._bf_0 & 0x1000000000i64) == 0 )
      {
        Blink = FirstPfn->ListEntry.Blink;
        v28 = Blink == 0i64;
        if( (__int64)Blink >= 0 )
        {
LABEL_32:
          if( !v28 )
            return;
        }
      }
LABEL_66:
      PfnDb = MmGetPfnDb();
      goto LABEL_67;
    }
    v30 = (_UNICODE_STRING *)((unsigned __int128)(v16 * (__int128)0x2AAAAAAAAAAAAAABi64) >> 64);
    v31 = v16 / 48;
    if( ((v16 / 48) & 0xFFFFFFFFFFFFFE00ui64) != v10 )
    {
      v35 = v31 & 0xFFFFFFFFFFFFFE00ui64;
      if( MiPfnLargeBitSet((UINT64)Partition) != -1 )
        return;
    }
    if( v15 != 6 )
      return;
    if( (((unsigned __int64)FirstPfn->u4._bf_0 >> 60) & 7) != 2 )
    {
      if( (v9 & 0x800000) != 0 )
      {
        LOBYTE(v33) = MI_PFN_IS_PROTO((_UNICODE_STRING *)FirstPfn, v30, PfnPageSizeIndexUnsynchronized, (PWCHAR)v10);
        if( v33 )
        {
          if( (FirstPfn->u2._bf_0 & 0x3FFFFFFFFFFFFFFFui64) > 1 )
            return;
        }
        else if( v31 == (v31 & 0xFFFFFFFFFFFFFFF0ui64) && (char *)v8 - (char *)FirstPfn >= 768 )
        {
          v27 = 1;
        }
      }
      goto LABEL_62;
    }
    if( (v9 & 8) != 0 )
      return;
    LeafPfnBuddy = MiGetLeafPfnBuddy(FirstPfn);
    if( LeafPfnBuddy == -32i64 )
      return;
    PfnDb = MmGetPfnDb();
    if( !LeafPfnBuddy )
      *(_DWORD *)DrainStacks = 1;
LABEL_67:
    if( ++FirstPfn >= v8 )
      return;
    v10 = v35;
    PartitionId = v36;
  }
  LOBYTE(v17) = MiIsPageOnBadList((INT64)FirstPfn);
  if( v17 )
    return;
  if( PfnPageSizeIndexUnsynchronized != -1 )
  {
LABEL_22:
    v23 = MiLargePageSizes[PfnPageSizeIndexUnsynchronized];
    if( v23 < 0x200 )
      v24 = (v9 & 0x1000000) == 0;
    else
      v24 = (v9 & 0x2000000) == 0;
    if( !v24 )
      return;
    v25 = v23 - ((v16 / 48) & (v23 - 1));
    if( v25 > v8 - FirstPfn )
      v25 = v8 - FirstPfn;
    FirstPfn += v25 - 1;
    goto LABEL_67;
  }
  if( (FirstPfn->$976DF529DAC3D73085C9E386D94B91E6::$E228DCF3D8940E384DBC5EFCA756D8B6::gap0[0] & 1) != 0 )
    goto LABEL_67;
  v18 = v16 / 48;
  v19 = (_QWORD *)((char *)&stru_140C4DB30 + 4056);
  v20 = 0;
  while( v18 != *v19 )
  {
    ++v20;
    ++v19;
    if( v20 >= 4 )
    {
      v21 = 0;
      v22 = (_QWORD *)((char *)&stru_140C4DB30 + 4024);
      while( v18 != *v22 )
      {
        ++v21;
        ++v22;
        if( v21 >= 4 )
          goto LABEL_67;
      }
      return;
    }
  }
}

Referenced by:

MiFindContiguousPages
MiFindRebuildCandidate
MiScrubNode
MmRelocatePfnList