MiMapNewPfns

VOID __stdcall MiMapNewPfns(UINT64 StartPage, UINT64 LastPage, UINT16 PartitionId, UINT64 Flags){
  unsigned int v5; 
  INT64 PteAddress; 
  __int64 v7; 
  __int64 v8; 
  INT64 v9; 
  UINT64 v10; 
  INT64 v11; 
  UINT64 v12; 
  unsigned __int64 v13; 
  unsigned __int64 v14; 
  int v15; 
  int ClosestImplicitNode; 
  unsigned int v17; 
  _ETHREAD *CurrentThread; 
  void *v19; 
  void *v20; 
  INT64 v21; 
  v5 = Flags;
  PteAddress = (INT64)MiGetPteAddress((char *)MmGetPfnDb() + 48 * StartPage);
  v9 = (INT64)MiGetPteAddress((PVOID)(v8 - 1 + 48 * v7));
  v11 = v9;
  v12 = v10 - StartPage;
  if( v10 - StartPage >= 0x40000 && qword_140C525D0 >= 0x200000 )
  {
    v10 = -4096i64;
    v13 = PteAddress & 0xFFFFFFFFFFFFF000ui64;
    if( PteAddress == (PteAddress & 0xFFFFFFFFFFFFF000ui64) )
      v13 = PteAddress;
    v14 = (v9 & 0xFFFFFFFFFFFFF000ui64) + 4088;
    PteAddress = v13;
    if( v11 != v14 )
      v11 = v14;
  }
  MiPageToNode(StartPage, v10);
  ClosestImplicitNode = MiGetClosestImplicitNode((unsigned int)(v15 + 1));
  v17 = ((v5 & 0x2000 | 0x1508) >> 3) | 0x100;
  if( (v5 & 0x4000) == 0 )
    v17 = (v5 & 0x2000 | 0x1508) >> 3;
  if( (v5 & 2) != 0 )
  {
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    MiLockDynamicMemoryShared((INT64)&MiSystemPartition, (INT64)CurrentThread);
  }
  else
  {
    CurrentThread = 0i64;
  }
  LODWORD(v21) = ClosestImplicitNode;
  if( !(unsigned int)MiMakeZeroedPageTablesEx(PteAddress, v11, v17, 4i64, v21) )
  {
    if( CurrentThread )
      MiUnlockDynamicMemoryShared((INT64)&MiSystemPartition, (INT64)CurrentThread);
    return;
  }
  v19 = 0i64;
  if( (v5 & 2) == 0 )
  {
    if( (v5 & 0x200) != 0 )
    {
      MmMapIoSpaceEx((_LARGE_INTEGER)(StartPage << 12), v12 << 12, 4ui64);
      v19 = v20;
      if( !v20 )
        return;
    }
    if( !(unsigned int)MiIncreaseCommitLimits((_MI_PARTITION *)&MiSystemPartition, v12, v12, (v5 & 4) != 0, 0i64) )
    {
      if( v19 )
        MmUnmapIoSpace(v19, v12 << 12);
      return;
    }
    if( (v5 & 0x404) == 0 )
      KeConfigureDynamicMemory(StartPage, LastPage - 1, 1ui64);
  }
  MiInitializeDynamicPfns(StartPage, v12, PartitionId, v5);
  if( CurrentThread )
    MiUnlockDynamicMemoryShared((INT64)&MiSystemPartition, (INT64)CurrentThread);
  if( v19 )
    MmUnmapIoSpace(v19, v12 << 12);
}

Referenced by:

MiAddPhysicalMemory