MiMapContiguousMemoryLarge

INT8 *__fastcall MiMapContiguousMemoryLarge(UINT64 Protection, UINT64 CacheAttribute, UINT64 a3, INT64 a4, INT64 a5){
  _DWORD *v5; 
  char *PageTablesForLargeMap; 
  _RTL_BALANCED_NODE *v7; 
  int v9; 
  unsigned __int64 v11; 
  union {$8D9ED47C9F2F2CD645B633E301950288 __s0;unsigned __int64 EntireField;} *p_u4; 
  UINT64 v13; 
  __int64 v14; 
  _MMPFN *v15; 
  unsigned __int64 v16; 
  unsigned __int8 *v17; 
  UINT64 v18; 
  unsigned __int8 CurrentIrql; 
  UINT64 v20; 
  __int64 v21; 
  VOID *v22; 
  _MMSUPPORT_INSTANCE *AnyMultiplexedVm; 
  int v25; 
  unsigned __int8 v26; 
  _RTL_BALANCED_NODE *v27; 
  _RTL_BALANCED_NODE *v28; 
  _MMPFN *v29; 
  int v30; 
  char *v31; 
  int v32; 
  int v33; 

  v33 = a4;
  v32 = a3;
  v5 = (_DWORD *)a5;
  PageTablesForLargeMap = 0i64;
  v7 = 0i64;
  v31 = 0i64;
  v28 = 0i64;
  *(_DWORD *)a5 = 0;
  v9 = 1;
  v27 = 0i64;
  v11 = 2i64;
  if( (unsigned int)a3 >> 3 == 1 )
  {
    v9 = 0;
  }
  else if( (unsigned int)a3 >> 3 == 3 && (a3 & 7) != 0 )
  {
    v9 = 2;
  }
  p_u4 = &MmGetPfnDb()->u4;
  if( Protection > 0xFFFFFFFFFi64 )
  {
    LODWORD(v14) = 0;
  }
  else
  {
    v13 = 6 * Protection;
    v14 = ((unsigned __int64)p_u4[v13]._bf_0 >> 50) & 1;
    if( (((unsigned __int64)p_u4[v13]._bf_0 >> 50) & 1) != 0 )
    {
      v15 = &MmGetPfnDb()[v13 / 6];
      goto LABEL_6;
    }
  }
  v15 = 0i64;
LABEL_6:
  v16 = 0i64;
  v29 = v15;
  if( !CacheAttribute )
    goto LABEL_17;
  v17 = (unsigned __int8 *)(&v15->u3 + 1);
  while( 1 )
  {
    v18 = v16 + Protection;
    if( v16 + Protection > 0xFFFFFFFFFi64 || (MmGetPfnDb()[v18].u4._bf_0 & 0x4000000000000i64) == 0 )
      break;
    if( ((unsigned __int8)a4 & (unsigned __int8)v11) != 0 )
    {
      if( (*v17 & 7) != 5 || (LOBYTE(v25) = MiIsPfnFileOnly((INT64)(v17 - 34)), !v25) )
        KeBugCheckEx(0x1Au, (PVOID)0x1160C, (PVOID)v18, 0i64, 0i64);
    }
    if( !v15 )
      goto LABEL_16;
    v26 = *v17;
    if( (*v17 & 0xC0) == 0xC0 )
    {
      MiAssignInitialPageAttribute((_MMPFN *)(v17 - 34), (_MI_PFN_CACHE_ATTRIBUTE)v9);
      v26 = *v17;
      v11 = 2i64;
      v7 = v27;
    }
    if( v26 >> 6 != v9 )
      goto LABEL_16;
LABEL_12:
    ++v16;
    v17 += 48;
    if( v16 >= CacheAttribute )
      goto LABEL_16;
    v15 = v29;
    LOBYTE(a4) = v33;
  }
  if( v15 )
    goto LABEL_16;
  if( v16 )
    goto LABEL_12;
  CurrentIrql = KeGetCurrentIrql();
  __writecr8(v11);
  v7 = MiIoSpaceIsConstant(Protection, CacheAttribute);
  v27 = v7;
  __writecr8(CurrentIrql);
  if( !v7 )
    goto LABEL_12;
  v16 = CacheAttribute;
LABEL_16:
  PageTablesForLargeMap = v31;
  v5 = (_DWORD *)a5;
LABEL_17:
  if( v16 == CacheAttribute )
  {
    if( (_DWORD)v14 || v7 )
    {
LABEL_23:
      LODWORD(v21) = MiSearchNumaNodeTable((PVOID)Protection);
      PageTablesForLargeMap = MiGetPageTablesForLargeMap(CacheAttribute, MiVaSystemPtes, 1, *(_DWORD *)(v21 + 8) + 1);
      if( PageTablesForLargeMap )
      {
        AnyMultiplexedVm = MiGetAnyMultiplexedVm(MiWorkingSetTypeSystemPtes, v22);
        MiMapWithLargePages(
          (UINT64)AnyMultiplexedVm,
          (UINT64)PageTablesForLargeMap,
          Protection,
          (_MI_PFN_CACHE_ATTRIBUTE)CacheAttribute,
          MiVaSessionSpace);
        if( v28 )
          *v5 |= 1u;
      }
      else if( !(_DWORD)v14 && !v27 )
      {
        v20 = Protection;
        goto LABEL_46;
      }
    }
    else
    {
      v30 = 0;
      if( (int)MiReferenceIoPages(1u, Protection, CacheAttribute, v9, &v30, &v28) >= 0 )
      {
        v20 = Protection;
        if( ((v30 - 1) & v30) == 0 )
        {
          LOWORD(a5) = *((_WORD *)v28[2].Children[0]->Children + (Protection & 0xFFFFFFFFFi64) - v28[1].ParentValue);
          goto LABEL_23;
        }
LABEL_46:
        MiDereferenceIoPages(1i64, v20, CacheAttribute);
      }
    }
  }
  return PageTablesForLargeMap;
}

Referenced by:

MiMapContiguousMemory