MiAllocateVirtualMemoryCommon

NTSTATUS __stdcall MiAllocateVirtualMemoryCommon(
        VOID *a1,
        INT64 *a2,
        UINT64 a3,
        UINT64 *a4,
        INT64 a5,
        INT64 a6,
        INT64 a7,
        CHAR a8,
        INT64 a9,
        INT64 a10,
        INT64 a11){
  unsigned __int64 v13; 
  NTSTATUS VirtualMemoryPrepare; 
  UINT64 *v15; 
  VOID *v16; 
  NTSTATUS VirtualMemory; 
  NTSTATUS v19; 
  INT64 AllocationType; 
  UINT64 AllocationTypea; 
  UINT64 Protect; 
  INT8 PreviousMode; 
  UINT64 InternalFlags; 
  _MMVAD_SHORT **OutVad; 
  _MMVAD_SHORT **OutVada; 
  unsigned __int64 v27; 
  UINT64 ZeroBits; 
  void *Object[2]; 
  __int64 ProcessHandle[22]; 

  memset(ProcessHandle, 0i64, 0x80u);
  v13 = 0i64;
  ZeroBits = 0i64;
  Object[0] = 0i64;
  LODWORD(OutVad) = a9;
  v27 = 0i64;
  LODWORD(AllocationType) = a5;
  VirtualMemoryPrepare = MiAllocateVirtualMemoryPrepare(
                           a1,
                           *a2,
                           a3,
                           *a4,
                           AllocationType,
                           a6,
                           a7,
                           a8,
                           (INT64)OutVad,
                           a10,
                           a11,
                           (__int64)ProcessHandle,
                           (__int64)Object);
  if( VirtualMemoryPrepare < 0 )
    goto LABEL_19;
  v16 = *(VOID **)(a7 + 24);
  if( v16 )
  {
    if( v16 == (VOID *)-3i64 )
    {
      v13 = 1i64;
    }
    else
    {
      v19 = PsReferencePartitionByHandle(v16, 2ui64, a8, 0x61566D4Du, &v27);
      v13 = v27;
      VirtualMemoryPrepare = v19;
      if( v19 < 0 )
        goto LABEL_19;
    }
  }
  if( *(_BYTE *)(a7 + 48) != 1 || (a5 & 0x20400000) == 0x400000 )
  {
    if( (int)a9 >= 0 )
    {
      VirtualMemoryPrepare = MiAllocateVirtualMemory(
                               ProcessHandle,
                               (PVOID *)v13,
                               (UINT64)&ZeroBits,
                               v15,
                               AllocationTypea,
                               Protect,
                               PreviousMode,
                               InternalFlags,
                               OutVada);
    }
    else
    {
      v27 = 0i64;
      if( (ProcessHandle[7] & 0x4000000000000000i64) != 0 )
      {
        HIDWORD(ProcessHandle[9]) = 536870913;
        ProcessHandle[10] = (__int64)&v27;
      }
      VirtualMemory = MiAllocateVirtualMemory(
                        ProcessHandle,
                        0i64,
                        (UINT64)&ZeroBits,
                        v15,
                        AllocationTypea,
                        Protect,
                        PreviousMode,
                        InternalFlags,
                        OutVada);
      ProcessHandle[10] = 0i64;
      VirtualMemoryPrepare = VirtualMemory;
      HIDWORD(ProcessHandle[9]) = 0;
      if( VirtualMemory >= 0 )
        VirtualMemoryPrepare = 0;
    }
    if( VirtualMemoryPrepare >= 0 )
    {
      *a2 = ZeroBits;
      *a4 = ProcessHandle[3];
      goto LABEL_11;
    }
  }
  else
  {
    VirtualMemoryPrepare = -1073741811;
  }
LABEL_19:
  if( ProcessHandle[0] )
    ++*(&stru_140C4DB30 + 639);
  else
    ++*(&stru_140C4DB30 + 638);
LABEL_11:
  if( v13 >= 2 )
    PsDereferencePartition(v13);
  if( Object[0] )
    ObfDereferenceObjectWithTag(Object[0], 0x6D566D4Dui64);
  return VirtualMemoryPrepare;
}

Referenced by:

MmAllocateUserStack