MxMapVa

__int64 __fastcall MxMapVa(__int64 a1){
  int v1; 
  UINT64 v3; 
  int i; 
  UINT64 v5; 
  INT64 NextPage; 
  _MMPTE *PteBase; 
  int v9; 
  void *v10; 
  UINT64 a1a[2]; 
  __int128 v12; 
  v1 = 0;
  v3 = *(_QWORD *)a1;
  *(_OWORD *)a1a = 0i64;
  if( qword_140C525D0 > 0x20000 )
    v1 = 1;
  v12 = 0i64;
  MiFillPteHierarchy(v3, a1a);
  for( i = 3; ; --i )
  {
    v5 = a1a[i];
    if( (*(_QWORD *)v5 & 1) == 0 )
      break;
    if( !i )
      return 1i64;
    if( (*(_QWORD *)v5 & 0x80u) != 0i64 )
    {
      *(_DWORD *)(a1 + 32) = i;
      return 1i64;
    }
LABEL_7:
    if( !i )
      return 1i64;
  }
  if( i == 1 && v1 == 1 )
  {
    NextPage = MxGetNextPage(*(unsigned int *)(a1 + 8), 1ui64);
    if( NextPage != -1 )
    {
      qword_140C4ED18 += 512i64;
      *(_QWORD *)v5 = MiMakeValidPte(v5, NextPage, 3019898884i64);
      PteBase = MmGetPteBase();
      v9 = *(_DWORD *)(a1 + 12);
      if( !v9 )
      {
        if( (_MMPTE *)v5 != (_MMPTE *)((char *)PteBase + ((*(_QWORD *)(a1 + 16) >> 9) & 0x7FFFFFFFF8i64))
          && (_MMPTE *)v5 != (_MMPTE *)((char *)PteBase + ((*(_QWORD *)(a1 + 24) >> 9) & 0x7FFFFFFFF8i64)) )
        {
          goto LABEL_17;
        }
        v9 = 1;
      }
      if( v9 == 1 )
        KeZeroPages(
          (PVOID)((((__int64)((v5 << 25) - ((_QWORD)PteBase << 25)) >> 16 << 25) - ((_QWORD)PteBase << 25)) >> 16),
          0x200000ui64);
LABEL_17:
      *(_DWORD *)(a1 + 32) = 1;
      return 1i64;
    }
  }
  v10 = (void *)MxGetNextPage(*(unsigned int *)(a1 + 8), 0i64);
  if( v10 != (void *)-1i64 )
  {
    ++qword_140C4ED18;
    if( i || *(_DWORD *)(a1 + 12) == 1 )
      MiFillPhysicalPages(v10);
    *(_QWORD *)v5 = MiMakeValidPte(v5, (INT64)v10, i != 0 ? -1744830460 : -1342177276);
    goto LABEL_7;
  }
  return 0i64;
}

Referenced by:

MxMapPfnRange