MiSessionCreate

INT64 __stdcall MiSessionCreate(UINT64 SessionId){
  INT64 result; 
  __int64 v2; 
  UINT64 v3; 
  _MI_PARTITION *v4; 
  __int64 v5; 
  INT64 v6; 
  __int64 v7; 
  MMPTE *PteAddress; 
  MMPTE *v9; 
  UINT64 v10; 
  MMPTE *v11; 
  int v12; 
  UINT64 v13; 
  int v14; 
  INT64 DemandZeroPte; 
  INT64 v16; 
  INT64 v17; 
  __int64 v18; 
  void *v19; 
  int v20; 
  result = MiInitializeSessionGlobals();
  if( (int)result < 0 )
    return result;
  v2 = *((_QWORD *)KeGetCurrentThread() + 23);
  MiGetProcessPartition((_EPROCESS *)v2);
  v4 = (_MI_PARTITION *)v3;
  result = MiSessionCreateInternal(v3);
  if( (int)result < 0 )
    return result;
  v5 = *(_QWORD *)(v2 + 1368);
  v6 = v5 + 256;
  if( !(unsigned int)MiCreateSystemWsles()
    || !(unsigned int)MiInitializeDynamicBitmap((RTL_BITMAP *)(v5 + 880), BitmapStart, 0x200000ui64, 0i64) )
  {
    goto LABEL_21;
  }
  *(_QWORD *)(v5 + 840) = qword_140C4CAD0;
  *(_QWORD *)(v5 + 832) = 0x10000i64;
  PteAddress = MiGetPteAddress(qword_140C4CAD0);
  v9 = MiGetPteAddress((PVOID)(v7 + 0x1FFF));
  v10 = QuotaCharge;
  v11 = v9;
  if( !QuotaCharge )
  {
    v10 = ((v9 - PteAddress) >> 3) + 1;
    QuotaCharge = v10;
  }
  if( !(unsigned int)MiChargeCommit(v4, v10, 0i64) )
    goto LABEL_21;
  LOBYTE(v12) = MiMakeZeroedPageTables(PteAddress);
  if( !v12 )
  {
    MiReturnCommit(v4, QuotaCharge);
    goto LABEL_21;
  }
  v13 = QuotaCharge + *(_QWORD *)(v5 + 48);
  *(_DWORD *)(v5 + 4) |= 8u;
  *(_QWORD *)(v5 + 48) = v13;
  DemandZeroPte = MiMakeDemandZeroPte(4);
  if( PteAddress <= v11 )
  {
    do
    {
      *(_QWORD *)PteAddress = DemandZeroPte;
      PteAddress = (MMPTE *)((char *)PteAddress + 8);
    }
    while( PteAddress <= v11 );
    v14 = *(_DWORD *)(v5 + 4);
    v6 = v5 + 256;
  }
  *(_DWORD *)(v5 + 4) = v14 | 0x10;
  MiInitializeSystemWorkingSetList((UINT64 *)v4, v6, 1i64, 0i64);
  v16 = qword_140C4CAE0;
  *(_QWORD *)(v5 + 56) = qword_140C4CAE0;
  v17 = qword_140C4CAE0 + 0x1FFFFFFFFFi64;
  *(_QWORD *)(v5 + 64) = qword_140C4CAE0 + 0x1FFFFFFFFFi64;
  result = ExInitializeSessionHeapManager(v16, v17);
  if( (int)result >= 0 )
  {
    *(_DWORD *)(v5 + 4) |= 0x80u;
    v18 = *(_QWORD *)(*((_QWORD *)KeGetCurrentThread() + 23) + 1368i64);
    *(_QWORD *)(v18 + 168) = 0i64;
    *(_QWORD *)(v18 + 176) = 0x2000000i64;
    *(_DWORD *)(v18 + 4) |= 4u;
    LODWORD(v19) = MiAllocatePool((struct _SLIST_ENTRY *)0x104);
    if( v19 )
      ExFreePoolWithTag(v19, 0);
    *(_DWORD *)(v5 + 4) |= 1u;
    if( (unsigned int)MiInitializeSystemSpaceMap() )
    {
      v20 = MiSessionObjectCreate();
      if( v20 < 0 )
        MiDereferenceSession();
      return(unsigned int)v20;
    }
LABEL_21:
    MiDereferenceSession();
    return 3221225626i64;
  }
  return result;
}

Referenced by:

MiMapProcessExecutable
MmInitializeProcessAddressSpace