PspExitProcess

VOID __stdcall PspExitProcess(UINT8 LastThreadExit, _EPROCESS *Process){
  _ETHREAD *CurrentThread; 
  _ADAPTER_OBJECT *SecurityPort; 

  _InterlockedOr((volatile signed __int32 *)&Process->1124, 4u);
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  if( LastThreadExit )
  {
    PsSetProcessTelemetryAppState(Process, PsTelemetryAppStateTerminate);
    if( (Process->Flags3 & 1) == 0 || Process->PicoContext )
    {
      --CurrentThread->Tcb.KernelApcDisable;
      PspCallProcessNotifyRoutines((_EX_RUNDOWN_REF *)Process, 0i64, 0);
      KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
    }
  }
  SecurityPort = (_ADAPTER_OBJECT *)Process->SecurityPort;
  if( !SecurityPort )
    goto LABEL_5;
  if( SecurityPort != (_ADAPTER_OBJECT *)1 )
  {
    HalPutDmaAdapter(SecurityPort);
LABEL_5:
    Process->SecurityPort = (void *)1;
  }
  if( LastThreadExit )
  {
    if( Process->$1F247424BFCF625481CFD4988DD60FD2::_bf_0 < 0 )
      ExCleanTimerResolutionRequest();
    DbgkFlushErrorPort((INT64)Process);
    PfpLogApplicationEvent(Process, 0i64, 1u);
    if( PfSnNumActiveTraces )
      PfSnEndProcessTrace(Process, 2, 0i64);
    PspProcessUnbindVirtualizedTimers(Process);
  }
}

Referenced by:

PspExitThread