MiAllocateMdlPagesByLists

INT64 __fastcall MiAllocateMdlPagesByLists(
        _MI_PARTITION *Partition,
        _MDL *MemoryDescriptorList,
        UINT64 Flags,
        _MI_PFN_CACHE_ATTRIBUTE CacheAttribute,
        UINT64 HighPage,
        UINT64 SizeInPages,
        INT64 IdealNode){
  UINT64 v8; 
  __int64 v9; 
  _MI_PARTITION *v10; 
  __int16 v11; 
  signed __int32 v12; 
  unsigned int v13; 
  unsigned int v14; 
  int v15; 
  __int64 v16; 
  unsigned __int64 ByteCount; 
  int v18; 
  int v19; 
  _MMPFN *PfnDb; 
  UINT64 EnclavePage; 
  UINT64 v22; 
  INT64 v23; 
  BOOL v24; 
  __int64 v25; 
  unsigned __int64 v26; 
  void *v27; 
  __int64 v28; 
  int v29; 
  __int64 v30; 
  __int64 v31; 
  int v32; 
  int v33; 
  __int64 v34; 
  unsigned int v35; 
  unsigned int v37; 
  int v38; 
  _MDL **v39; 
  __int128 v40; 
  char v43; 
  int IdealNodea; 
  v43 = Flags;
  v8 = 0i64;
  v9 = 0i64;
  v10 = Partition;
  v40 = 0i64;
  MiInitializePageColorBase(0i64, (unsigned int)(IdealNode + 1), (INT64)&v40);
  v12 = _InterlockedExchangeAdd((volatile signed __int32 *)v40, 1u);
  v13 = 8;
  v14 = HIDWORD(v40) | v12 & DWORD2(v40);
  v15 = -1;
  v37 = v14;
  ByteCount = MemoryDescriptorList->ByteCount;
  v18 = v11 & 0x400;
  *(_QWORD *)&v40 = *(&KiProcessorBlock + *(unsigned int *)(v16 + 588));
  v38 = v18;
  v39 = &MemoryDescriptorList[1].Next + (ByteCount >> 12);
  v19 = 1;
  IdealNodea = 1;
  while( 1 )
  {
    PfnDb = MmGetPfnDb();
    if( v19 == 1 )
    {
      IdealNodea = 0;
      v13 = 2 * ((v11 & 1) == 0) + 8;
    }
    if( v18 )
      EnclavePage = MiGetEnclavePage(v10, 0i64);
    else
      EnclavePage = MiGetPage(v10, v14, v13);
    v22 = EnclavePage;
    if( EnclavePage == -1i64 )
    {
      v14 = v37;
LABEL_21:
      v35 = 1;
      goto LABEL_22;
    }
    v23 = (INT64)PfnDb + 48 * EnclavePage;
    if( EnclavePage > HighPage )
      break;
    v24 = MiPfnZeroingNeeded(v23, (unsigned int)CacheAttribute);
    v25 = v9 + 1;
    if( !v24 )
      v25 = v9;
    v9 = v25;
    if( v15 == -1 )
    {
      LODWORD(v34) = MiSearchNumaNodeTable((PVOID)((v23 - (__int64)PfnDb) / 48));
      v15 = *(_DWORD *)(v34 + 8);
    }
    v26 = (__int64)((unsigned __int128)((v23 - (__int64)PfnDb) * (__int128)0x2AAAAAAAAAAAAAABi64) >> 64) >> 3;
    v27 = (void *)((v26 >> 63) + v26);
    LODWORD(v28) = MiSearchNumaNodeTable(v27);
    if( *(_DWORD *)(v28 + 8) == v15 )
    {
      if( (*(_DWORD *)(v23 + 16) & 0x3E0i64) != 0 )
      {
        if( (v43 & 1) == 0 )
          v13 &= ~2u;
      }
      else
      {
        v29 = v13 | 2;
        if( (v43 & 1) == 0 )
          v29 = v13;
        v13 = v29;
      }
    }
    else
    {
      IdealNodea = 1;
    }
    LODWORD(v30) = MiSearchNumaNodeTable(v27);
    ++v8;
    v15 = *(_DWORD *)(v30 + 8);
    *v39++ = (_MDL *)v22;
    LODWORD(v31) = MiSearchNumaNodeTable(v27);
    v32 = *(_DWORD *)(v31 + 8);
    v33 = ((unsigned int)MiGetPfnChannel(v23) << byte_140C4DBCD) | dword_140C4DC38 & v22 | (v32 << byte_140C4DBCC);
    v14 = v33 & ~dword_140C4DBC0 | dword_140C4DBC0 & (v33 + 1);
    v37 = v14;
    if( v8 >= SizeInPages )
      goto LABEL_21;
    v19 = IdealNodea;
    LOBYTE(v11) = v43;
    v10 = Partition;
    v18 = v38;
  }
  MiReleaseFreshPage((_MMPFN *)v23);
  v14 = v37;
  v35 = 0;
LABEL_22:
  if( v8 )
    *(_DWORD *)(v40 + 32528) = v14;
  MemoryDescriptorList->ByteCount += (_DWORD)v8 << 12;
  if( v9 )
    MemoryDescriptorList->MappedSystemVa = (void *)1;
  return v35;
}

Referenced by:

MiFindPagesForMdl