MiInitializeSystemPageTable

VOID __stdcall MiInitializeSystemPageTable(_MMPTE *PointerPte, _MMPFN *Pfn1){
  INT64 v2; 
  char *v3; 
  char *v4; 
  UINT64 v5; 
  unsigned int v6; 
  unsigned int v7; 
  _MMPTE *PteBase; 
  __int64 v9; 
  unsigned __int64 v10; 
  _MMPTE *v11; 
  _MMPTE *PteLimit; 
  unsigned int v13; 
  unsigned __int64 LeafVa; 
  UINT64 ContainingPageTable; 
  unsigned __int64 v16; 
  INT64 ValidPte; 
  struct _KLOCK_QUEUE_HANDLE LockHandle; 
  INT64 v19; 
  memset(&LockHandle, 0, sizeof(LockHandle));
  v4 = v3;
  v5 = v2;
  v6 = (unsigned int)Pfn1;
  v7 = 0;
  MI_READ_PTE_LOCK_FREE(v2);
  PteBase = MmGetPteBase();
  v9 = (v4 - (char *)MmGetPfnDb()) / 48;
  v10 = (__int64)((v5 << 25) - ((_QWORD)PteBase << 25)) >> 16;
  v11 = PteBase;
  PteLimit = MmGetPteLimit();
  if( v10 < (unsigned __int64)v11 || v10 > (unsigned __int64)PteLimit )
  {
    MiFillPhysicalPages((PVOID)v9);
    v13 = -1879048188;
  }
  else
  {
    v13 = -1879048186;
  }
  LeafVa = MiGetLeafVa(v5);
  if( (unsigned int)MiGetSystemRegionType(LeafVa) == 1 )
  {
    v7 = 1;
  }
  else if( LeafVa <= 0x7FFFFFFEFFFFi64
         || LeafVa >= qword_140C4F878 && LeafVa <= qword_140C4E0A8
         || LeafVa >= (unsigned __int64)MmGetPteBase() && LeafVa <= (unsigned __int64)MmGetPteLimit() )
  {
    v7 = 4;
  }
  *(_QWORD *)v4 = 0i64;
  ContainingPageTable = MiGetContainingPageTable(v5);
  if( v10 >= (unsigned __int64)MmGetPteBase() && v10 <= v16 )
    v13 |= 0x8000000u;
  ValidPte = MiMakeValidPte(v5, v9, v13);
  if( v6 == 3 && (MiFlags & 0x30) != 0 )
  {
    if( (v7 & 1) != 0 )
    {
      ContainingPageTable = MiUpdateSessionPdeMaster();
    }
    else if( v7 < 4 )
    {
      if( PsInitialSystemProcess )
        ContainingPageTable = *((_QWORD *)PsInitialSystemProcess + 5) >> 12;
      else
        ContainingPageTable = ((unsigned __int64)MI_READ_PTE_LOCK_FREE((INT64)MmGetPteBase() + ((v5 >> 9) & 0x7FFFFFFFF8i64)) >> 12) & 0xFFFFFFFFFi64;
    }
  }
  MiInitializePfnForOtherProcess(v9, (MMPTE *)v5, ContainingPageTable, 0x200ui64);
  if( v6 == 3 )
    KeAcquireInStackQueuedSpinLock(&WorkerRoutine, &LockHandle);
  if( (MI_READ_PTE_LOCK_FREE(v5) & 1) != 0 )
  {
    MiTransformValidPteInPlace((volatile INT64 *)v5, v5, ValidPte, v6);
    if( v6 != 3 )
      return;
    MiInsertRecursiveTbFlushEntries(v19, 3i64, v5);
  }
  else
  {
    *(_QWORD *)v5 = ValidPte;
  }
  if( v6 == 3 )
  {
    KeReleaseInStackQueuedSpinLockFromDpcLevel(&LockHandle);
    __writecr8(LockHandle.OldIrql);
  }
}

Referenced by:

MiCreateSystemPageTable