MiCreateLargePfnList

NTSTATUS __stdcall MiCreateLargePfnList(INT64 a1, INT64 rdx0, CHAR a3, INT64 *a4, CHAR *a2){
  unsigned __int64 v5; 
  unsigned int v7; 
  _MI_PARTITION *v8; 
  INT64 v9; 
  int CrossPartitionCharges; 
  unsigned int v11; 
  unsigned int v12; 
  unsigned int *v13; 
  __int64 v14; 
  __int64 v15; 
  _MI_LARGEPAGE_MEMORY_INFO *LargeZeroPages; 
  UINT64 v17; 
  unsigned __int64 v18; 
  struct _KPRCB *CurrentPrcb; 
  __int64 CachedResidentAvailable; 
  bool v21; 
  signed __int32 v22; 
  UINT64 ZeroFillNeeded; 
  UINT64 ZeroFillNeededa; 
  __int64 ProtectionMask; 
  unsigned int *v27; 
  int v30; 

  v5 = rdx0;
  v7 = 0;
  v8 = *(_MI_PARTITION **)(*(&stru_140C4DB30 + 267)
                         + 8i64 * KeGetCurrentThread()->ApcState.Process->Vm.Instance.PartitionId);
  if( a4 )
  {
    v9 = *a4;
    v8 = (_MI_PARTITION *)*a4;
    CrossPartitionCharges = MiGetCrossPartitionCharges((_MI_CROSS_PARTITION_CHARGES *)*a4, 4ui64, 1i64);
    if( CrossPartitionCharges < 0 )
      goto LABEL_23;
    v7 = 1;
  }
  else
  {
    v9 = 0i64;
  }
  v11 = MiComputePreferredNode(a1);
  if( v9 )
  {
    if( !MiChargeCommit(v8, v5, 0i64) )
    {
      CrossPartitionCharges = -1073741523;
      goto LABEL_23;
    }
    v7 |= 2u;
  }
  if( MiChargeResident((ULONG_PTR *)&v8->Core.PartitionId, v5, 0i64) == MiChargeFailed )
    goto LABEL_10;
  v12 = *(_DWORD *)(a1 + 48);
  v30 = MmMakeProtectNotWriteCopy[(v12 >> 7) & 0x1F];
  v13 = (unsigned int *)(*(&stru_140C4DB30 + 21) + 4i64 * v11 * (unsigned __int16)KeNumberNodes);
  v14 = (v12 >> 18) & 3;
  v27 = &v13[(unsigned __int16)KeNumberNodes];
  if( (unsigned int)MiVadPageSizes[v14] == 16 )
  {
    v15 = 2i64;
  }
  else if( (v12 & 0x500000) == 5242880 )
  {
    v15 = (unsigned int)MiVadPageIndices[v14];
  }
  else
  {
    v15 = 1i64;
  }
  ProtectionMask = MiLargePageSizes[v15];
  LODWORD(ZeroFillNeeded) = MmMakeProtectNotWriteCopy[(v12 >> 7) & 0x1F];
  LargeZeroPages = MiAllocateLargeZeroPages((UINT64)v8, v5, ProtectionMask, v11, ZeroFillNeeded);
  v17 = v5 - (_QWORD)LargeZeroPages;
  if( (_MI_LARGEPAGE_MEMORY_INFO *)v5 != LargeZeroPages )
  {
    do
    {
      if( a3 )
        break;
      if( ++v13 == v27 )
        break;
      LODWORD(ZeroFillNeededa) = v30;
      v17 -= (unsigned __int64)MiAllocateLargeZeroPages((UINT64)v8, v17, ProtectionMask, *v13, ZeroFillNeededa);
    }
    while( v17 );
    v7 |= 4u;
    v5 = rdx0;
    if( v17 )
    {
      MiFreeLargeZeroPages((UINT64)v8, (_MMPFN **)a2, (v12 & 0xD00000) == 13631488);
LABEL_10:
      CrossPartitionCharges = -1073741670;
      goto LABEL_23;
    }
  }
  v7 = 0;
  CrossPartitionCharges = 0;
LABEL_23:
  if( v7 >= 4 )
  {
    v18 = v5;
    if( v8 == &Irp )
    {
      CurrentPrcb = KeGetCurrentPrcb();
      CachedResidentAvailable = (int)CurrentPrcb->CachedResidentAvailable;
      if( (_DWORD)CachedResidentAvailable != -1 )
      {
        if( v5 + CachedResidentAvailable <= 0x100 )
        {
          do
          {
            if( v5 >= 0x80000 )
              break;
            v22 = _InterlockedCompareExchange(
                    (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
                    CachedResidentAvailable + v5,
                    CachedResidentAvailable);
            v21 = (_DWORD)CachedResidentAvailable == v22;
            LODWORD(CachedResidentAvailable) = v22;
            if( v21 )
              goto LABEL_37;
          }
          while( v22 != -1 && v5 + v22 <= 0x100 );
        }
        if( (int)CachedResidentAvailable > 192
          && (_DWORD)CachedResidentAvailable != -1
          && (_DWORD)CachedResidentAvailable == _InterlockedCompareExchange(
                                                  (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
                                                  192,
                                                  CachedResidentAvailable) )
        {
          v18 = v5 + (int)CachedResidentAvailable - 192;
        }
      }
    }
    if( v18 )
      _InterlockedExchangeAdd64((volatile signed __int64 *)&v8->Vp.ResidentAvailablePages, v18);
  }
LABEL_37:
  if( (v7 & 2) != 0 )
    MiReturnCommit(v8, v5);
  if( (v7 & 1) != 0 )
    MiReturnCrossPartitionCharges((_MI_CROSS_PARTITION_CHARGES *)v8, 4ui64);
  return CrossPartitionCharges;
}

Referenced by:

MiCommitExistingVad
MiMapUserLargePages