PspIumAllocatePhysicalPages

__int64 __fastcall PspIumAllocatePhysicalPages(int a1, void *a2, unsigned int a3, __int64 *a4, _DWORD *a5){
  __int64 v7; 
  unsigned int v8; 
  _MDL *v9; 
  __int64 v11; 
  unsigned int v12; 
  unsigned int v13; 
  _DWORD *v14; 
  _DWORD *v15; 
  UINT64 BugCheckOnFailure; 
  UINT64 Priority; 
  _MDL MemoryDescriptorList; 
  __int64 v19; 

  v19 = 0i64;
  memset(&MemoryDescriptorList, 0, sizeof(MemoryDescriptorList));
  LODWORD(v7) = MmAllocateSecureKernelPages(a2, (unsigned int)(a1 + 1), a3, 0, a5);
  v8 = 0;
  v9 = (_MDL *)v7;
  if( !v7 )
    return 3221225495i64;
  if( a1 )
  {
    v12 = *(_DWORD *)(v7 + 40);
    *(_DWORD *)&MemoryDescriptorList.Size = 131128;
    MemoryDescriptorList.StartVa = 0i64;
    *(_QWORD *)&MemoryDescriptorList.ByteCount = 4096i64;
    v13 = v12 >> 12;
    LODWORD(Priority) = 1073741840;
    LODWORD(BugCheckOnFailure) = 0;
    v19 = *(_QWORD *)(v7 + 8i64 * (v13 - 1) + 48);
    v14 = MmMapLockedPagesSpecifyCache(&MemoryDescriptorList, 0, MmCached, 0i64, BugCheckOnFailure, Priority);
    v15 = v14;
    if( !v14 )
    {
      MmFreeSecureKernelPages(v9);
      v8 = -1073741670;
      goto LABEL_9;
    }
    memmove(v14, v9, 8 * v13 + 48);
    v15[10] -= 4096;
    MmUnmapLockedPages(v15, &MemoryDescriptorList);
    v11 = v19;
  }
  else
  {
    v11 = *(_QWORD *)(v7 + 48);
  }
  *a4 = v11;
LABEL_9:
  ExFreePoolWithTag(v9, 0);
  return v8;
}

Referenced by:

PsDispatchIumService