MmMapLockedPagesSpecifyCache

VOID *__stdcall MmMapLockedPagesSpecifyCache(
        _MDL *MemoryDescriptorList,
        CHAR AccessMode,
        _MEMORY_CACHING_TYPE CacheType,
        VOID *RequestedAddress,
        UINT64 BugCheckOnFailure,
        UINT64 Priority){
  char *v8; 
  int v9; 
  unsigned __int64 v10; 
  int v11; 
  unsigned __int64 v12; 
  unsigned __int64 v13; 
  unsigned int v14; 
  UINT64 v15; 
  _MMPTE *v16; 
  unsigned int v17; 
  VOID *v18; 
  unsigned int v19; 
  NTSTATUS v20; 
  _KTBFLUSH_TYPE v21; 
  __int16 MdlFlags; 
  char v23; 
  __int16 v24; 
  unsigned int v25; 
  _MI_PFN_CACHE_ATTRIBUTE v27; 
  INT64 a5; 
  INT64 a6; 

  LODWORD(a6) = 0;
  v8 = (char *)MemoryDescriptorList->StartVa + MemoryDescriptorList->ByteOffset;
  if( AccessMode )
  {
    LODWORD(a5) = Priority;
    v18 = MiMapLockedPagesInUserSpace(MemoryDescriptorList, v8, CacheType, RequestedAddress, a5);
    if( !v18 )
      return 0i64;
    return v18;
  }
  v9 = Priority;
  v10 = (((unsigned __int16)v8 & 0xFFF) + (unsigned __int64)MemoryDescriptorList->ByteCount + 4095) >> 12;
  if( (Priority & 0x20) == 0 )
  {
    v11 = Priority & 0x3FFFFFFF;
    v12 = 512i64;
    if( (Priority & 0x3FFFFFFF) != 16 )
      v12 = 2048i64;
    v13 = v11 == 16 ? 0x2000000i64 : 0x4000000 / ((unsigned int)(v11 == 16) + 1);
    if( ((*(&stru_140C4DB30 + 87) << 9) - *(&stru_140C4DB30 + 561)) << 12 < v13
      && (v12 >= *(&stru_140C4DB30 + 565) || v10 >= *(&stru_140C4DB30 + 565) - v12)
      && (*(_DWORD *)&KeGetCurrentThread()[1].gapD8[12] & 2) == 0
      && (KeGetPcr()->Prcb._bf_0 & 0x10001) == 0 )
    {
      ++*(&stru_140C4DB30 + 1118);
      return 0i64;
    }
  }
  v14 = v10;
  if( MmProtectFreedNonPagedPool == 1 )
    v14 = v10 + 1;
  v15 = (UINT64)MiReservePtes((_MI_SYSTEM_PTE_TYPE *)((char *)&stru_140C4DB30 + 4432), v14);
  v16 = (_MMPTE *)v15;
  if( !v15 )
  {
    if( (MemoryDescriptorList->MdlFlags & 0x2000) != 0 || !(_DWORD)BugCheckOnFailure )
      return 0i64;
    goto LABEL_39;
  }
  v17 = ((v9 >> 31) & 0xFFFFFFFD) + 4;
  v18 = (VOID *)(MemoryDescriptorList->ByteOffset + ((__int64)((v15 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16));
  if( (MiFlags & 0x10000) != 0 )
    v9 = 0x40000000;
  v19 = v17 | 2;
  if( (v9 & 0x40000000) != 0 )
    v19 = v17;
  if( CacheType )
  {
    if( CacheType == MmWriteCombined )
      v19 |= 0x18u;
  }
  else
  {
    v19 |= 8u;
  }
  LODWORD(a5) = 0;
  v20 = MiFillSystemPtes(v15, v10, (INT64)&MemoryDescriptorList[1], v19, a5, (INT64)&a6);
  MdlFlags = MemoryDescriptorList->MdlFlags;
  if( v20 >= 0 )
  {
    v23 = a6;
    v24 = MdlFlags | 1;
    MemoryDescriptorList->MappedSystemVa = v18;
    MemoryDescriptorList->MdlFlags = v24;
    v25 = v23 & 1;
    if( v25 )
    {
      MiMappingHasIoReferences(v18);
      MemoryDescriptorList->MdlFlags |= 0x800u;
      v24 = MemoryDescriptorList->MdlFlags;
    }
    if( (dword_140CFA17C & 1) != 0 )
    {
      if( MmProtectFreedNonPagedPool == 1 )
        v25 |= 2u;
      v27 = MiProtectionToCacheAttribute(v19);
      MiInsertPteTracker(MemoryDescriptorList, MiPteTrackerMdl, v25, v27);
      v24 = MemoryDescriptorList->MdlFlags;
    }
    if( (v24 & 0x10) != 0 )
      MemoryDescriptorList->MdlFlags = v24 | 0x20;
    return v18;
  }
  if( (MdlFlags & 0x2000) == 0 && (_DWORD)BugCheckOnFailure )
LABEL_39:
    MiIssueNoPtesBugcheck((unsigned int)v10);
  MiReleasePtes((_MI_SYSTEM_PTE_TYPE *)((char *)&stru_140C4DB30 + 4432), v16, v14, v21);
  return 0i64;
}

Referenced by:

AlpcpInitializeCompletionList
BgpFwAllocateMemory
CcCompleteAsyncRead
CcLockSystemCacheBuffer
EtwpAllocatePartitionMemory
EtwpAllocateTraceBuffer
ExInitializeLeapSecondData
ExLockUserBuffer
FsRtlCancelNotify
FsRtlNotifyCompleteIrp
FsRtlNotifyFilterReportChange
FsRtlNotifyFilterReportChangeLiteEx
HalAllocateCommonBufferVector
HalInitializeBios
HalpAllocateCommonBufferThin
HalpDmaAcquireBufferMappings
HalpDmaAllocateScatterMemory
HalpDmaCheckMdlAccessibility
HalpDmaFlushBuffer
HalpDmaSyncMapBuffers
IoReserveKsrPersistentMemory
IopLiveDumpAllocateFromVMMemoryPartition
IopSetFileObjectIosbRange
KeFlushIoBuffers
KiComputeNumaCosts
KiOpPatchCode
MdlInvariantPostProcessing1
MdlInvariantPreProcessing1
MiApplyImageHotPatch
MiCopyPagesIntoEnclave
MiCreateMdl
MiFlushFileOnlyMdl
MiFreePagesFromMdl
MiGetWorkingSetInfo
MiGetWorkingSetInfoList
MiInitializeImageProtos
MiLoadSectionIntoVsmEnclave
MiMapPageFileHash
MiQueryMemoryPhysicalContiguity
MiValidateInPage
MiValidatePagefilePageHash
MiWritePageFileHash
MmCopyVirtualMemory
MmMapLockedPages
NtPssCaptureVaSpaceBulk
NtStartProfile
PipGetPersistentMemory
PopAllocatePages
PpmHeteroInitializeHgsSupport
PsDispatchIumService
PspIumAllocatePhysicalPages
PspIumAllocateSecurePool
PspIumFreePhysicalPages
ResFwGetContext
SMKM_STORE_MGR::SmIoCtxWorkItemComplete
SMKM_STORE_MGR::SmPageWrite
SmFpAllocate
SmMapPage
SmPrepareForFatalPageError
VerifierMmMapLockedPagesSpecifyCache
VfFillAllocatePagesForMdl
ViAllocateMapRegisterFile
ViGetMdlBufferSa
ViMapDoubleBuffer
WbMakeUserDataPagesKernelWritable
WbMakeUserExecutablePagesKernelWritable