PsGetCurrentProcessSessionId

NTSTATUS __stdcall PsGetCurrentProcessSessionId(){
  _EPROCESS *Process; 
  _MM_SESSION_SPACE *Session; 
  NTSTATUS v2; 
  NTSTATUS v3; 

  Process = KeGetCurrentThread()->ApcState.Process;
  Session = Process->Session;
  if( !Session || (Process->Flags3 & 0x1000) != 0 )
    v2 = -1;
  else
    v2 = *((_DWORD *)Session + 2);
  v3 = 0;
  if( v2 != -1 )
    return v2;
  return v3;
}

Referenced by:

EtwpWriteUserEvent
IoGetContainerInformation
IopParseDevice
NtSetInformationObject
ObpLookupObjectName
PfpProcessScenarioPhase
PnpNotifyDriverCallback
PopCreatePowerRequestObject