MiGetLargePagesForSystemMapping

INT64 __fastcall MiGetLargePagesForSystemMapping(INT64 a1, UINT64 a2){
  PVOID v3; 
  MMPTE *PteAddress; 
  unsigned __int64 v5; 
  __int64 v6; 
  unsigned __int64 v7; 
  INT64 result; 
  int v9; 
  INT64 v10; 
  int v11; 
  __int64 v12; 
  int v13; 
  unsigned int v14; 
  __int64 v15; 
  bool v16; 
  UINT64 v17; 
  unsigned int v18; 
  unsigned int *v19; 
  unsigned int *v20; 
  UINT64 ProtectionMask; 
  MiGetPteAddress((PVOID)a2);
  PteAddress = MiGetPteAddress(v3);
  v7 = v6 & ((unsigned __int64)PteAddress + 8);
  if( v5 >= v7 )
    return 1i64;
  v9 = *(_DWORD *)(a1 + 64);
  v10 = *(_QWORD *)(a1 + 32);
  v11 = 0;
  v12 = (__int64)(v7 - v5) >> 3;
  if( (v9 & 8) == 0 && *(_QWORD *)(v10 + 7592) )
  {
    result = MiObtainSystemCharges(*(_MI_PARTITION **)(a1 + 32), v12, *(unsigned int *)(a1 + 56));
    if( !(_DWORD)result )
      return result;
    *(_QWORD *)(a1 + 40) += v12;
    v11 = 1;
    v9 = *(_DWORD *)(a1 + 64);
  }
  v13 = *(_DWORD *)(a1 + 60);
  if( v13 )
    v14 = v13 - 1;
  else
    v14 = MiThreadIdealNode();
  v15 = (unsigned __int16)KeNumberNodes;
  v16 = (v9 & 0x400) != 0;
  v17 = v14;
  if( v16 )
    v15 = 1i64;
  v18 = 0;
  v19 = (unsigned int *)(qword_140C4DBD8 + 4i64 * v14 * (unsigned __int16)KeNumberNodes);
  v20 = &v19[v15];
  while( 1 )
  {
    LODWORD(ProtectionMask) = 4;
    v12 -= MiAllocateLargeZeroPages(v10, v12, 0x200ui64, v17, ProtectionMask, a1, 1);
    if( !v12 )
      break;
    if( ++v19 == v20 )
      goto LABEL_17;
    v17 = *v19;
  }
  v18 = 1;
LABEL_17:
  if( v11 )
  {
    if( v12 )
    {
      MiReturnCommit((_MI_PARTITION *)v10, v12);
      MiReturnSystemCharges(v10, v12, *(unsigned int *)(a1 + 56));
      *(_QWORD *)(a1 + 40) -= v12;
    }
  }
  return v18;
}

Referenced by:

MiMakeZeroedPageTablesEx