MmResourcesAvailable

NTSTATUS __stdcall MmResourcesAvailable(POOL_TYPE PoolType, UINT64 NumberOfBytes, _EX_POOL_PRIORITY Priority){
  _MI_PARTITION *v3; 
  NTSTATUS v4; 
  char v7; 
  UINT64 v8; 
  _MM_SESSION_SPACE *Session; 
  __int32 v10; 
  __int64 v11; 
  _MM_SESSION_SPACE *v12; 
  unsigned __int64 v13; 
  unsigned __int64 v14; 
  __int64 v15; 
  UINT64 v16; 
  UINT64 v17; 
  UINT64 v18; 
  unsigned __int64 TotalCommittedPages; 
  _KEVENT *v20; 
  UINT64 v21; 
  _ETHREAD *CurrentThread; 
  _KEVENT *v24; 
  _KLOCK_QUEUE_HANDLE LockHandle; 

  v3 = &Irp;
  v4 = 0;
  memset(&LockHandle, 0, sizeof(LockHandle));
  v7 = PoolType;
  v8 = (NumberOfBytes >> 12) + ((NumberOfBytes & 0xFFF) != 0);
  Session = KeGetCurrentThread()->ApcState.Process->Session;
  v10 = PoolType & 1;
  if( (PoolType & 1) == 0 )
  {
    v11 = MiState[0] - qword_140C4C608;
LABEL_8:
    v16 = v11 << 12;
    goto LABEL_9;
  }
  if( (PoolType & 0x20) == 0 )
  {
    v11 = *(&stru_140C4DB30 + 553) - *(&stru_140C4DB30 + 551);
    goto LABEL_8;
  }
  v12 = KeGetCurrentThread()->ApcState.Process->Session;
  v13 = (__int64)*((int *)v12 + 217) << 21;
  v14 = *((_QWORD *)v12 + 23) << 12;
  v15 = v13 - v14;
  if( v13 <= v14 )
    v15 = 0i64;
  v16 = ((0x10000i64 - *((unsigned int *)v12 + 218)) << 21) + v15;
  v3 = *(_MI_PARTITION **)(*(&stru_140C4DB30 + 267) + 8i64 * *((unsigned __int16 *)Session + 215));
LABEL_9:
  v17 = NumberOfBytes + 0x80000;
  if( Priority != NormalPoolPriority )
    v17 = NumberOfBytes + 0x200000;
  if( v17 <= v16 )
  {
    if( (PoolType & 1) == 0 )
      goto LABEL_23;
    v18 = 0i64;
    TotalCommittedPages = v3->Vp.TotalCommittedPages;
    if( TotalCommittedPages <= v3->Commit.TotalCommitLimitMaximum )
      v18 = v3->Commit.TotalCommitLimitMaximum - TotalCommittedPages;
    if( v8 > v18 )
    {
      MiIssuePageExtendRequest(v3, v8, 2ui64, 0i64);
    }
    else
    {
LABEL_23:
      if( NumberOfBytes + 10485760 < v16 || v3->Vp.NumberOfPhysicalPages < 0x40000 )
        return 1;
      v4 = 1;
    }
  }
  if( (v7 & 0x20) == 0 )
  {
    if( v10 )
    {
      CurrentThread = (_ETHREAD *)KeGetCurrentThread();
      --CurrentThread->Tcb.SpecialApcDisable;
      ExAcquirePushLockExclusiveEx((_EX_PUSH_LOCK *)&stru_140C4DB30 + 549, 0i64);
      v24 = v3->Core.MemoryEvents[0];
      if( !*((_DWORD *)v24 + 1) )
        KePulseEvent(v24, 0, 0);
      if( (_InterlockedExchangeAdd64((_QWORD *)&stru_140C4DB30 + 549, 0xFFFFFFFFFFFFFFFFui64) & 6) == 2 )
        ExfTryToWakePushLock((_EX_PUSH_LOCK *)&stru_140C4DB30 + 549);
      KeAbPostRelease((char *)&stru_140C4DB30 + 4392);
      KiLeaveGuardedRegionUnsafe((__int64)CurrentThread);
    }
    else
    {
      KeAcquireInStackQueuedSpinLock(&v3->PageLists.AvailableEventsLock, &LockHandle);
      v20 = v3->Core.MemoryEvents[2];
      if( !*((_DWORD *)v20 + 1) )
        KePulseEvent(v20, 0, 0);
      KeReleaseInStackQueuedSpinLockFromDpcLevel(&LockHandle);
      __writecr8(LockHandle.OldIrql);
    }
    MiFreeExcessSegments(v21);
  }
  return v4;
}

Referenced by:

ExAllocatePoolWithTagPriority