ExInitializeSessionHeapManager

NTSTATUS __stdcall ExInitializeSessionHeapManager(INT64 a1, INT64 a2){
  VOID **PoolWithTag; 
  VOID **v5; 
  INT64 v6; 
  INT64 v7; 
  INT64 v8; 
  INT64 v9; 
  int v10; 
  NTSTATUS Heap; 
  _DWORD *v12; 
  __int64 v14; 
  __int128 v15; 
  __int128 v16; 
  __int128 v17; 
  _RTL_RUN_ONCE v18; 

  PoolWithTag = ExAllocatePoolWithTag(0x200ui64, 0x38F0ui64, 1699967048i64);
  v5 = PoolWithTag;
  if( !PoolWithTag )
    return -1073741801;
  memset(PoolWithTag, 0i64, 0x38F0u);
  v18.Value = 0x500010200i64;
  RtlHpHeapManagerInitialize((_RTL_RUN_ONCE *)v5, &v18);
  v15 = 0i64;
  LOBYTE(v15) = 4;
  *((_QWORD *)KeGetCurrentThread()->ApcState.Process->Session + 84) = v5;
  *((_OWORD *)v5 + 909) = v15;
  RtlHpHeapManagerStart((_RTL_RUN_ONCE *)v5, 2, a1, a2 - a1, 0);
  Heap = v10;
  if( v10 >= 0 )
  {
    v16 = *((_OWORD *)v5 + 909);
    Heap = ExCreateHeap((__int64)&v16, 0i64, v5 + 1820);
    if( Heap >= 0 )
    {
      v17 = *((_OWORD *)v5 + 909);
      Heap = ExCreateHeap((__int64)&v17, 0i64, v5 + 1821);
      if( Heap >= 0 )
      {
        v12 = v5[1821];
        v12[204] |= 2u;
        *((_BYTE *)v12 + 269) |= 8u;
        *((_BYTE *)v12 + 461) |= 8u;
        if( !ExpSessionPoolTrackTable )
        {
          ExpSessionPoolTrackTable = MiSessionPoolTrackTable();
          LODWORD(v14) = MiSessionPoolTrackTableSize();
          ExpSessionPoolTrackTableSize = v14;
          ExpSessionPoolTrackTableMask = v14 - 1;
        }
        v5 = 0i64;
        Heap = 0;
      }
    }
  }
  if( v5 )
    ExCleanupSessionHeapManager(v7, v6, v8, v9);
  return Heap;
}

Referenced by:

MiSessionCreate