MiCreateLargePfnList

INT64 __fastcall MiCreateLargePfnList(INT64 a1, INT64 a2, CHAR a3, INT64 *a4, CHAR *a5){
  unsigned __int64 v5; 
  unsigned int v7; 
  INT64 v8; 
  INT64 v9; 
  int CrossPartitionCharges; 
  unsigned int v11; 
  unsigned int v12; 
  unsigned int *v13; 
  __int64 v14; 
  __int64 v15; 
  UINT64 v16; 
  CHAR v17; 
  UINT64 LargeZeroPages; 
  UINT64 v19; 
  unsigned __int64 v20; 
  struct _KPRCB *CurrentPrcb; 
  __int64 v22; 
  bool v23; 
  signed __int32 v24; 
  UINT64 ProtectionMask; 
  UINT64 ProtectionMaska; 
  UINT64 v28; 
  unsigned int *v29; 
  int v32; 
  v5 = a2;
  v7 = 0;
  v8 = *(_QWORD *)(qword_140C4E388 + 8i64 * *(unsigned __int16 *)(*((_QWORD *)KeGetCurrentThread() + 23) + 1838i64));
  if( a4 )
  {
    v9 = *a4;
    v8 = *a4;
    CrossPartitionCharges = MiGetCrossPartitionCharges(*a4, 4i64, 1, a2);
    if( CrossPartitionCharges < 0 )
      goto LABEL_25;
    v7 = 1;
  }
  else
  {
    v9 = 0i64;
  }
  v11 = MiComputePreferredNode(a1);
  if( v9 )
  {
    if( !(unsigned int)MiChargeCommit((_MI_PARTITION *)v8, v5, 0i64) )
    {
      CrossPartitionCharges = -1073741523;
      goto LABEL_25;
    }
    v7 |= 2u;
  }
  if( !(unsigned int)MiChargeResident((ULONG_PTR *)v8, v5, 0i64) )
    goto LABEL_10;
  v12 = *(_DWORD *)(a1 + 48);
  v32 = MmMakeProtectNotWriteCopy[(v12 >> 7) & 0x1F];
  v13 = (unsigned int *)(qword_140C4DBD8 + 4i64 * v11 * (unsigned __int16)KeNumberNodes);
  v14 = (v12 >> 18) & 3;
  v29 = &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;
  }
  v16 = MiLargePageSizes[v15];
  v28 = v16;
  v17 = 2;
  if( (v12 & 0xD00000) != 13631488 )
    v17 = 0;
  LODWORD(ProtectionMask) = MmMakeProtectNotWriteCopy[(v12 >> 7) & 0x1F];
  LargeZeroPages = MiAllocateLargeZeroPages(v8, v5, v16, v11, ProtectionMask, (INT64)a5, v17);
  v19 = v5 - LargeZeroPages;
  if( v5 != LargeZeroPages )
  {
    do
    {
      if( a3 )
        break;
      if( ++v13 == v29 )
        break;
      LODWORD(ProtectionMaska) = v32;
      v19 -= MiAllocateLargeZeroPages(v8, v19, v28, *v13, ProtectionMaska, (INT64)a5, v17);
    }
    while( v19 );
    v7 |= 4u;
    v5 = a2;
    if( v19 )
    {
      MiFreeLargeZeroPages(v8, a5, (v12 & 0xD00000) == 13631488);
LABEL_10:
      CrossPartitionCharges = -1073741670;
      goto LABEL_25;
    }
  }
  v7 = 0;
  CrossPartitionCharges = 0;
LABEL_25:
  if( v7 >= 4 )
  {
    v20 = v5;
    if( (ULONG_PTR *)v8 == &MiSystemPartition )
    {
      CurrentPrcb = KeGetCurrentPrcb();
      v22 = *((int *)CurrentPrcb + 8391);
      if( (_DWORD)v22 != -1 )
      {
        if( v5 + v22 <= 0x100 )
        {
          do
          {
            if( v5 >= 0x80000 )
              break;
            v24 = _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, v22 + v5, v22);
            v23 = (_DWORD)v22 == v24;
            LODWORD(v22) = v24;
            if( v23 )
              goto LABEL_39;
          }
          while( v24 != -1 && v5 + v24 <= 0x100 );
        }
        if( (int)v22 > 192
          && (_DWORD)v22 != -1
          && (_DWORD)v22 == _InterlockedCompareExchange((volatile signed __int32 *)CurrentPrcb + 8391, 192, v22) )
        {
          v20 = v5 + (int)v22 - 192;
        }
      }
    }
    if( v20 )
      _InterlockedExchangeAdd64((volatile signed __int64 *)(v8 + 7168), v20);
  }
LABEL_39:
  if( (v7 & 2) != 0 )
    MiReturnCommit((_MI_PARTITION *)v8, v5);
  if( (v7 & 1) != 0 )
    MiReturnCrossPartitionCharges((_MI_CROSS_PARTITION_CHARGES *)v8, 4ui64);
  return(unsigned int)CrossPartitionCharges;
}

Referenced by:

MiCommitExistingVad
MiMapUserLargePages