HalpMap

UINT64 __stdcall HalpMap(
        _LARGE_INTEGER PhysicalAddress,
        _MEMORY_CACHING_TYPE CacheType,
        _MEMORY_CACHING_TYPE FlushCurrentTLB,
        UINT8 a4,
        UINT64 Protection){
  __int64 v9; 
  unsigned __int64 v10; 
  unsigned int v11; 
  char *v12; 
  _HARDWARE_PTE *PteAddressSafe; 
  bool v14; 
  UINT64 v15; 
  __int64 v16; 
  unsigned __int64 v17; 
  __int64 v18; 
  union {unsigned __int64 Long;volatile unsigned __int64 VolatileLong;_MMPTE_HARDWARE Hard;_MMPTE_PROTOTYPE Proto;_MMPTE_SOFTWARE Soft;_MMPTE_TIMESTAMP TimeStamp;_MMPTE_TRANSITION Trans;_MMPTE_SUBSECTION Subsect;_MMPTE_LIST List;} v19; 

  if( (unsigned int)FlushCurrentTLB > MmCached )
    return 0i64;
  if( (unsigned int)Protection > 0x20 )
    return 0i64;
  v9 = 0x100000014i64;
  if( !_bittest64(&v9, (unsigned int)Protection) )
    return 0i64;
  v10 = (unsigned __int64)qword_140C50660;
  v11 = 0;
  if( CacheType )
  {
    while( 2 )
    {
      v11 = 0;
      v12 = (char *)v10;
      while( 1 )
      {
        if( v12 == (char *)qword_140C50658 )
          return 0i64;
        PteAddressSafe = HalpMmGetPteAddressSafe(v12);
        if( !PteAddressSafe )
          return 0i64;
        v12 += 4096;
        if( (PteAddressSafe->_bf_0 & 1) != 0 )
          break;
        if( ++v11 >= CacheType )
          goto LABEL_10;
      }
      v10 = (unsigned __int64)v12;
LABEL_10:
      if( (_DWORD)Protection == 32 )
      {
        v14 = v11 < CacheType;
        if( v11 != CacheType )
        {
LABEL_12:
          if( v14 )
            continue;
          goto LABEL_13;
        }
        if( HalpIsHeap64KRegionExecutable(v10)
          || HalpIsHeap64KRegionExecutable(v10 + (unsigned int)((CacheType << 12) - 4096)) )
        {
          v11 = 0;
        }
      }
      break;
    }
    v14 = v11 < CacheType;
    goto LABEL_12;
  }
LABEL_13:
  v15 = v10 | PhysicalAddress.anonymous_0.LowPart & 0xFFF;
  if( (VOID *)v10 == qword_140C50660 )
    qword_140C50660 = (VOID *)(v10 + (unsigned int)(CacheType << 12));
  if( v11 )
  {
    v16 = 3i64;
    if( (_DWORD)Protection != 4 )
      v16 = 1i64;
    v17 = v16 | 0x8000000000000000ui64;
    if( (_DWORD)Protection == 32 )
      v17 = v16;
    v18 = v17 | 0x18;
    if( FlushCurrentTLB == MmCached )
      v18 = v17;
    do
    {
      v19.Long = v18 | PhysicalAddress.QuadPart & 0xFFFFFFFFF000i64;
      PhysicalAddress.QuadPart += 4096i64;
      MmGetPteBase()[(v10 >> 12) & 0xFFFFFFFFFi64] = (_MMPTE)v19.Long;
      if( a4 )
        __invlpg((void *)v10);
      v10 += 4096i64;
      --v11;
    }
    while( v11 );
  }
  if( !a4 )
    HalpFlushTLB();
  return v15;
}

Referenced by:

HalMapIoSpace
HalpAcpiAllocateMemory
HalpAcpiCheckAndMapTable
HalpAcpiGetRsdt
HalpAcpiTableCacheInit
HalpAllocateEarlyPages
HalpAllocateNumaConfigData
HalpBlkAllocateAndShadowMemory
HalpBlkAllocatePageTablePage
HalpBlkInitializeVirtualAddressSpace
HalpInterruptMapParkedPage
HalpMapEarlyPages
HalpMapPhysicalMemory64
HalpMapPhysicalMemoryWriteThrough64
HalpMmAllocateMemoryInternal
HalpPciMapMmConfigPhysicalAddress
HalpPowerWriteResetCommand
HalpSetupAcpiPhase0
HalpUsbLegacyStopOhciInterrupt