ReactOS  0.4.15-dev-1033-gd7d716a
procsup.c File Reference
#include <srv.h>
#include <winuser.h>
#include <debug.h>
Include dependency graph for procsup.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI CsrSetToNormalPriority (VOID)
 
VOID NTAPI CsrSetToShutdownPriority (VOID)
 
VOID NTAPI CsrProcessRefcountZero (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrLockedDereferenceProcess (PCSR_PROCESS CsrProcess)
 
PCSR_PROCESS NTAPI CsrAllocateProcess (VOID)
 
VOID NTAPI CsrLockedReferenceProcess (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrInitializeProcessStructure (VOID)
 
VOID NTAPI CsrDeallocateProcess (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrRemoveProcess (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrInsertProcess (IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrCreateProcess (IN HANDLE hProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN PCSR_NT_SESSION NtSession, IN ULONG Flags, IN PCLIENT_ID DebugCid)
 
NTSTATUS NTAPI CsrDebugProcess (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrDebugProcessStop (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrDereferenceProcess (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrDestroyProcess (IN PCLIENT_ID Cid, IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI CsrGetProcessLuid (IN HANDLE hProcess OPTIONAL, OUT PLUID Luid)
 
BOOLEAN NTAPI CsrImpersonateClient (IN PCSR_THREAD CsrThread)
 
NTSTATUS NTAPI CsrLockProcessByClientId (IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess)
 
BOOLEAN NTAPI CsrRevertToSelf (VOID)
 
VOID NTAPI CsrSetBackgroundPriority (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrSetForegroundPriority (IN PCSR_PROCESS CsrProcess)
 
PCSR_PROCESS NTAPI FindProcessForShutdown (IN PLUID CallerLuid)
 
NTSTATUS NTAPI CsrShutdownProcesses (IN PLUID CallerLuid, IN ULONG Flags)
 
NTSTATUS NTAPI CsrUnlockProcess (IN PCSR_PROCESS CsrProcess)
 

Variables

RTL_CRITICAL_SECTION CsrProcessLock
 
PCSR_PROCESS CsrRootProcess = NULL
 
SECURITY_QUALITY_OF_SERVICE CsrSecurityQos
 
ULONG CsrProcessSequenceCount = 5
 
ULONG CsrTotalPerProcessDataLength
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file procsup.c.

Function Documentation

◆ CsrAllocateProcess()

PCSR_PROCESS NTAPI CsrAllocateProcess ( VOID  )

Definition at line 188 of file procsup.c.

189 {
191  ULONG TotalSize;
192 
193  /* Calculate the amount of memory this should take */
194  TotalSize = sizeof(CSR_PROCESS) +
195  (CSR_SERVER_DLL_MAX * sizeof(PVOID)) +
197 
198  /* Allocate a Process */
200  if (!CsrProcess) return NULL;
201 
202  /* Handle the Sequence Number and protect against overflow */
203  CsrProcess->SequenceNumber = CsrProcessSequenceCount++;
205 
206  /* Increase the reference count */
208 
209  /* Initialize the Thread List */
210  InitializeListHead(&CsrProcess->ThreadList);
211 
212  /* Return the Process */
213  return CsrProcess;
214 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
ULONG CsrProcessSequenceCount
Definition: procsup.c:30
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
struct _CSR_PROCESS CSR_PROCESS
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int ULONG
Definition: retypes.h:1
HANDLE CsrHeap
Definition: init.c:25
ULONG CsrTotalPerProcessDataLength
Definition: init.c:35

Referenced by CsrCreateProcess(), CsrInitializeProcessStructure(), and CsrSbCreateSession().

◆ CsrCreateProcess()

NTSTATUS NTAPI CsrCreateProcess ( IN HANDLE  hProcess,
IN HANDLE  hThread,
IN PCLIENT_ID  ClientId,
IN PCSR_NT_SESSION  NtSession,
IN ULONG  Flags,
IN PCLIENT_ID  DebugCid 
)

Definition at line 421 of file procsup.c.

427 {
428  PCSR_THREAD CurrentThread = CsrGetClientThread();
429  CLIENT_ID CurrentCid;
431  PCSR_SERVER_DLL ServerDll;
432  PVOID ProcessData;
433  ULONG i;
436  PCSR_THREAD CsrThread;
437  KERNEL_USER_TIMES KernelTimes;
438 
439  /* Get the current CID and lock Processes */
440  CurrentCid = CurrentThread->ClientId;
442 
443  /* Get the current CSR Thread */
444  CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
445  if (!CurrentThread)
446  {
447  /* We've failed to locate the thread */
450  }
451 
452  /* Allocate a new Process Object */
454  if (!CsrProcess)
455  {
456  /* Couldn't allocate Process */
458  return STATUS_NO_MEMORY;
459  }
460 
461  /* Inherit the Process Data */
462  CurrentProcess = CurrentThread->Process;
463  ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
464  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
465  {
466  /* Get the current Server */
467  ServerDll = CsrLoadedServerDll[i];
468 
469  /* Check if the DLL is Loaded and has Per Process Data */
470  if (ServerDll && ServerDll->SizeOfProcessData)
471  {
472  /* Set the pointer */
473  CsrProcess->ServerData[i] = ProcessData;
474 
475  /* Copy the Data */
476  RtlMoveMemory(ProcessData,
477  CurrentProcess->ServerData[i],
478  ServerDll->SizeOfProcessData);
479 
480  /* Update next data pointer */
481  ProcessData = (PVOID)((ULONG_PTR)ProcessData +
482  ServerDll->SizeOfProcessData);
483  }
484  else
485  {
486  /* No data for this Server */
487  CsrProcess->ServerData[i] = NULL;
488  }
489  }
490 
491  /* Set the Exception Port for us */
494  &CsrApiPort,
495  sizeof(CsrApiPort));
496  if (!NT_SUCCESS(Status))
497  {
498  /* Failed */
501  return STATUS_NO_MEMORY;
502  }
503 
504  /* Check if CreateProcess got CREATE_NEW_PROCESS_GROUP */
506  {
507  /*
508  * We create the process group leader of a new process group, therefore
509  * its process group ID and sequence number are its own ones.
510  */
511  CsrProcess->ProcessGroupId = HandleToUlong(ClientId->UniqueProcess);
512  CsrProcess->ProcessGroupSequence = CsrProcess->SequenceNumber;
513  }
514  else
515  {
516  /* Inherit the process group ID and sequence number from the current process */
517  CsrProcess->ProcessGroupId = CurrentProcess->ProcessGroupId;
518  CsrProcess->ProcessGroupSequence = CurrentProcess->ProcessGroupSequence;
519  }
520 
521  /* Check if this is a console process */
523 
524  /* Mask out non-debug flags */
526 
527  /* Check if every process will be debugged */
528  if (!(Flags) && (CurrentProcess->DebugFlags & CsrDebugProcessChildren))
529  {
530  /* Pass it on to the current process */
531  CsrProcess->DebugFlags = CsrDebugProcessChildren;
532  CsrProcess->DebugCid = CurrentProcess->DebugCid;
533  }
534 
535  /* Check if Debugging was used on this process */
536  if ((Flags & (CsrDebugOnlyThisProcess | CsrDebugProcessChildren)) && (DebugCid))
537  {
538  /* Save the debug flag used */
539  CsrProcess->DebugFlags = Flags;
540 
541  /* Save the CID */
542  CsrProcess->DebugCid = *DebugCid;
543  }
544 
545  /* Check if Debugging is enabled */
546  if (CsrProcess->DebugFlags)
547  {
548  /* Set the Debug Port for us */
551  &CsrApiPort,
552  sizeof(CsrApiPort));
554  if (!NT_SUCCESS(Status))
555  {
556  /* Failed */
559  return STATUS_NO_MEMORY;
560  }
561  }
562 
563  /* Get the Thread Create Time */
565  ThreadTimes,
566  &KernelTimes,
567  sizeof(KernelTimes),
568  NULL);
569  if (!NT_SUCCESS(Status))
570  {
571  /* Failed */
574  return STATUS_NO_MEMORY;
575  }
576 
577  /* Allocate a CSR Thread Structure */
578  CsrThread = CsrAllocateThread(CsrProcess);
579  if (!CsrThread)
580  {
581  /* Failed */
584  return STATUS_NO_MEMORY;
585  }
586 
587  /* Save the data we have */
588  CsrThread->CreateTime = KernelTimes.CreateTime;
589  CsrThread->ClientId = *ClientId;
590  CsrThread->ThreadHandle = hThread;
592  CsrThread->Flags = 0;
593 
594  /* Insert the Thread into the Process */
595  Status = CsrInsertThread(CsrProcess, CsrThread);
596  if (!NT_SUCCESS(Status))
597  {
598  /* Bail out */
600  CsrDeallocateThread(CsrThread);
602  return Status;
603  }
604 
605  /* Reference the session */
606  CsrReferenceNtSession(NtSession);
607  CsrProcess->NtSession = NtSession;
608 
609  /* Setup Process Data */
610  CsrProcess->ClientId = *ClientId;
611  CsrProcess->ProcessHandle = hProcess;
612  CsrProcess->ShutdownLevel = 0x280;
613 
614  /* Set the Priority to Background */
616 
617  /* Insert the Process */
619 
620  /* Release lock and return */
622  return Status;
623 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
ULONG SizeOfProcessData
Definition: csrsrv.h:234
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:79
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
PKPROCESS CsrProcess
Definition: videoprt.c:39
HANDLE UniqueProcess
Definition: compat.h:573
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint32_t ULONG_PTR
Definition: typedefs.h:65
PCSR_PROCESS Process
Definition: csrsrv.h:69
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
void * PVOID
Definition: retypes.h:9
ULONG CurrentProcess
Definition: shell.c:125
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
VOID NTAPI CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:296
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2506
HANDLE ThreadHandle
Definition: csrsrv.h:71
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1106
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:188
VOID NTAPI CsrReferenceNtSession(IN PCSR_NT_SESSION Session)
Definition: session.c:118
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
HANDLE CsrApiPort
Definition: connect.c:21
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
HANDLE hThread
Definition: wizard.c:27
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2020
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:72
VOID NTAPI CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:365
#define CsrProcessPriorityFlags
Definition: csrsrv.h:97
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by CSR_API().

◆ CsrDeallocateProcess()

VOID NTAPI CsrDeallocateProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 296 of file procsup.c.

297 {
298  /* Free the process object from the heap */
300 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PKPROCESS CsrProcess
Definition: videoprt.c:39
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrCreateProcess(), CsrProcessRefcountZero(), and CsrSbCreateSession().

◆ CsrDebugProcess()

NTSTATUS NTAPI CsrDebugProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 642 of file procsup.c.

643 {
644  /* CSR does not handle debugging anymore */
645  DPRINT("CSRSRV: %s(0x%p) called\n", __FUNCTION__, CsrProcess);
646  return STATUS_UNSUCCESSFUL;
647 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define __FUNCTION__
Definition: types.h:112

◆ CsrDebugProcessStop()

NTSTATUS NTAPI CsrDebugProcessStop ( IN PCSR_PROCESS  CsrProcess)

Definition at line 666 of file procsup.c.

667 {
668  /* CSR does not handle debugging anymore */
669  DPRINT("CSRSRV: %s(0x%p) called\n", __FUNCTION__, CsrProcess);
670  return STATUS_UNSUCCESSFUL;
671 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define __FUNCTION__
Definition: types.h:112

◆ CsrDereferenceProcess()

VOID NTAPI CsrDereferenceProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 690 of file procsup.c.

691 {
692  LONG LockCount;
693 
694  /* Acquire process lock */
696 
697  /* Decrease reference count */
698  LockCount = --CsrProcess->ReferenceCount;
699  ASSERT(LockCount >= 0);
700  if (LockCount == 0)
701  {
702  /* Call the generic cleanup code */
704  }
705  else
706  {
707  /* Just release the lock */
709  }
710 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseProcessLock()
Definition: api.h:15
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by ConsoleClientShutdown(), CsrThreadRefcountZero(), NonConsoleProcessShutdown(), and UserClientShutdown().

◆ CsrDestroyProcess()

NTSTATUS NTAPI CsrDestroyProcess ( IN PCLIENT_ID  Cid,
IN NTSTATUS  ExitStatus 
)

Definition at line 734 of file procsup.c.

736 {
737  PCSR_THREAD CsrThread;
739  CLIENT_ID ClientId = *Cid;
740  PLIST_ENTRY NextEntry;
741 
742  /* Acquire lock */
744 
745  /* Find the thread */
747 
748  /* Make sure we got one back, and that it's not already gone */
749  if (!(CsrThread) || (CsrProcess->Flags & CsrProcessTerminating))
750  {
751  /* Release the lock and return failure */
754  }
755 
756  /* Set the terminated flag */
758 
759  /* Get the List Pointers */
760  NextEntry = CsrProcess->ThreadList.Flink;
761  while (NextEntry != &CsrProcess->ThreadList)
762  {
763  /* Get the current thread entry */
764  CsrThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
765 
766  /* Move to the next entry */
767  NextEntry = NextEntry->Flink;
768 
769  /* Make sure the thread isn't already dead */
770  if (CsrThread->Flags & CsrThreadTerminated)
771  {
772  /* Go the the next thread */
773  continue;
774  }
775 
776  /* Set the Terminated flag */
777  CsrThread->Flags |= CsrThreadTerminated;
778 
779  /* Acquire the Wait Lock */
781 
782  /* Do we have an active wait block? */
783  if (CsrThread->WaitBlock)
784  {
785  /* Notify waiters of termination */
786  CsrNotifyWaitBlock(CsrThread->WaitBlock,
787  NULL,
788  NULL,
789  NULL,
791  TRUE);
792  }
793 
794  /* Release the Wait Lock */
796 
797  /* Dereference the thread */
798  CsrLockedDereferenceThread(CsrThread);
799  }
800 
801  /* Release the Process Lock and return success */
803  return STATUS_SUCCESS;
804 }
BOOLEAN NTAPI CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock, IN PLIST_ENTRY WaitList, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags, IN BOOLEAN DereferenceThread)
Definition: wait.c:120
#define TRUE
Definition: types.h:120
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseWaitLock()
Definition: api.h:24
#define CsrReleaseProcessLock()
Definition: api.h:15
static int Link(const char **args)
Definition: vfdcmd.c:2414
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define CsrAcquireProcessLock()
Definition: api.h:12
Definition: typedefs.h:119
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
#define CsrAcquireWaitLock()
Definition: api.h:21
struct _CSR_WAIT_BLOCK * WaitBlock
Definition: csrsrv.h:70
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2020
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CSR_API(), and CsrApiRequestThread().

◆ CsrGetProcessLuid()

NTSTATUS NTAPI CsrGetProcessLuid ( IN HANDLE hProcess  OPTIONAL,
OUT PLUID  Luid 
)

Definition at line 827 of file procsup.c.

829 {
830  HANDLE hToken = NULL;
832  ULONG Length;
833  PTOKEN_STATISTICS TokenStats;
834 
835  /* Check if we have a handle to a CSR Process */
836  if (!hProcess)
837  {
838  /* We don't, so try opening the Thread's Token */
840  TOKEN_QUERY,
841  FALSE,
842  &hToken);
843 
844  /* Check for success */
845  if (!NT_SUCCESS(Status))
846  {
847  /* If we got some other failure, then return and quit */
848  if (Status != STATUS_NO_TOKEN) return Status;
849 
850  /* We don't have a Thread Token, use a Process Token */
852  hToken = NULL;
853  }
854  }
855 
856  /* Check if we have a token by now */
857  if (!hToken)
858  {
859  /* No token yet, so open the Process Token */
861  TOKEN_QUERY,
862  &hToken);
863  if (!NT_SUCCESS(Status))
864  {
865  /* Still no token, return the error */
866  return Status;
867  }
868  }
869 
870  /* Now get the size we'll need for the Token Information */
873  NULL,
874  0,
875  &Length);
877  {
878  /* Close the token and fail */
879  NtClose(hToken);
880  return Status;
881  }
882 
883  /* Allocate memory for the Token Info */
884  if (!(TokenStats = RtlAllocateHeap(CsrHeap, 0, Length)))
885  {
886  /* Fail and close the token */
887  NtClose(hToken);
888  return STATUS_NO_MEMORY;
889  }
890 
891  /* Now query the information */
894  TokenStats,
895  Length,
896  &Length);
897 
898  /* Close the handle */
899  NtClose(hToken);
900 
901  /* Check for success */
902  if (NT_SUCCESS(Status))
903  {
904  /* Return the LUID */
905  *Luid = TokenStats->AuthenticationId;
906  }
907 
908  /* Free the query information */
909  RtlFreeHeap(CsrHeap, 0, TokenStats);
910 
911  /* Return the Status */
912  return Status;
913 }
LUID AuthenticationId
Definition: setypes.h:1033
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define NtCurrentThread()
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
NTSTATUS NTAPI NtOpenProcessToken(IN HANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
Definition: security.c:350
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Definition: token.c:1839
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
NTSTATUS NTAPI NtOpenThreadToken(IN HANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN BOOLEAN OpenAsSelf, OUT PHANDLE TokenHandle)
Definition: token.c:3858
unsigned int ULONG
Definition: retypes.h:1
HANDLE CsrHeap
Definition: init.c:25

Referenced by FindProcessForShutdown(), and UserExitReactOS().

◆ CsrImpersonateClient()

BOOLEAN NTAPI CsrImpersonateClient ( IN PCSR_THREAD  CsrThread)

Definition at line 931 of file procsup.c.

932 {
934  PCSR_THREAD CurrentThread = CsrGetClientThread();
935 
936  /* Use the current thread if none given */
937  if (!CsrThread) CsrThread = CurrentThread;
938 
939  /* Still no thread, something is wrong */
940  if (!CsrThread)
941  {
942  /* Failure */
943  return FALSE;
944  }
945 
946  /* Make the call */
948  CsrThread->ThreadHandle,
949  &CsrSecurityQos);
950 
951  if (!NT_SUCCESS(Status))
952  {
953  /* Failure */
954 #ifdef CSR_DBG
955  DPRINT1("CSRSS: Can't impersonate client thread - Status = %lx\n", Status);
956  // if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
957 #endif
958  return FALSE;
959  }
960 
961  /* Increase the impersonation count for the current thread */
962  if (CurrentThread) ++CurrentThread->ImpersonationCount;
963 
964  /* Return Success */
965  return TRUE;
966 }
NTSTATUS NTAPI NtImpersonateThread(IN HANDLE ThreadHandle, IN HANDLE ThreadToImpersonateHandle, IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService)
Definition: security.c:973
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define NtCurrentThread()
#define FALSE
Definition: types.h:117
ULONG ImpersonationCount
Definition: csrsrv.h:74
SECURITY_QUALITY_OF_SERVICE CsrSecurityQos
Definition: procsup.c:23
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8

Referenced by BaseSrvIsVdmAllowed(), CheckForGlobalDriveLetter(), ConSrvInitConsole(), CSR_API(), FindProcessForShutdown(), GuiInit(), GuiLoadFrontEnd(), and UserExitReactOS().

◆ CsrInitializeProcessStructure()

NTSTATUS NTAPI CsrInitializeProcessStructure ( VOID  )

Definition at line 254 of file procsup.c.

255 {
257  ULONG i;
258 
259  /* Initialize the Lock */
261  if (!NT_SUCCESS(Status)) return Status;
262 
263  /* Set up the Root Process */
265  if (!CsrRootProcess) return STATUS_NO_MEMORY;
266 
267  /* Set up the minimal information for it */
270  CsrRootProcess->ClientId = NtCurrentTeb()->ClientId;
271 
272  /* Initialize the Thread Hash List */
274 
275  /* Initialize the Wait Lock */
277 }
RTL_CRITICAL_SECTION CsrProcessLock
Definition: procsup.c:21
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HANDLE ProcessHandle
Definition: csrsrv.h:46
CLIENT_ID ClientId
Definition: csrsrv.h:38
LIST_ENTRY ListLink
Definition: csrsrv.h:39
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
PVOID HANDLE
Definition: typedefs.h:73
Status
Definition: gdiplustypes.h:24
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:188
RTL_CRITICAL_SECTION CsrWaitListsLock
Definition: api.h:61
#define NUMBER_THREAD_HASH_BUCKETS
Definition: api.h:44
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned int ULONG
Definition: retypes.h:1

Referenced by CsrServerInitialization().

◆ CsrInsertProcess()

VOID NTAPI CsrInsertProcess ( IN PCSR_PROCESS ParentProcess  OPTIONAL,
IN PCSR_PROCESS  CsrProcess 
)

Definition at line 365 of file procsup.c.

367 {
368  PCSR_SERVER_DLL ServerDll;
369  ULONG i;
371 
372  /* Insert it into the Root List */
374 
375  /* Notify the Server DLLs */
376  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
377  {
378  /* Get the current Server DLL */
379  ServerDll = CsrLoadedServerDll[i];
380 
381  /* Make sure it's valid and that it has callback */
382  if (ServerDll && ServerDll->NewProcessCallback)
383  {
384  ServerDll->NewProcessCallback(ParentProcess, CsrProcess);
385  }
386  }
387 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define InsertTailList(ListHead, Entry)
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define ProcessStructureListLocked()
Definition: api.h:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LIST_ENTRY ListLink
Definition: csrsrv.h:39
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
PCSR_NEWPROCESS_CALLBACK NewProcessCallback
Definition: csrsrv.h:239
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by CsrCreateProcess(), and CsrSbCreateSession().

◆ CsrLockedDereferenceProcess()

VOID NTAPI CsrLockedDereferenceProcess ( PCSR_PROCESS  CsrProcess)

Definition at line 159 of file procsup.c.

160 {
161  LONG LockCount;
162 
163  /* Decrease reference count */
164  LockCount = --CsrProcess->ReferenceCount;
165  ASSERT(LockCount >= 0);
166  if (LockCount == 0)
167  {
168  /* Call the generic cleanup code */
169  DPRINT1("Should kill process: %p\n", CsrProcess);
172  }
173 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12
#define DPRINT1
Definition: precomp.h:8

Referenced by CsrApiHandleConnectionRequest(), CsrRemoveThread(), CsrShutdownProcesses(), and CsrUnlockProcess().

◆ CsrLockedReferenceProcess()

VOID NTAPI CsrLockedReferenceProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 232 of file procsup.c.

233 {
234  /* Increment the reference count */
235  ++CsrProcess->ReferenceCount;
236 }
PKPROCESS CsrProcess
Definition: videoprt.c:39

Referenced by CsrAllocateProcess(), CsrAllocateThread(), CsrApiHandleConnectionRequest(), CsrLockProcessByClientId(), and CsrShutdownProcesses().

◆ CsrLockProcessByClientId()

NTSTATUS NTAPI CsrLockProcessByClientId ( IN HANDLE  Pid,
OUT PCSR_PROCESS CsrProcess 
)

Definition at line 990 of file procsup.c.

992 {
993  PLIST_ENTRY NextEntry;
996 
997  /* Acquire the lock */
999 
1000  /* Assume failure */
1001  ASSERT(CsrProcess != NULL);
1002  *CsrProcess = NULL;
1003 
1004  /* Setup the List Pointers */
1005  NextEntry = &CsrRootProcess->ListLink;
1006  do
1007  {
1008  /* Get the Process */
1009  CurrentProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
1010 
1011  /* Check for PID Match */
1012  if (CurrentProcess->ClientId.UniqueProcess == Pid)
1013  {
1015  break;
1016  }
1017 
1018  /* Move to the next entry */
1019  NextEntry = NextEntry->Flink;
1020  } while (NextEntry != &CsrRootProcess->ListLink);
1021 
1022  /* Check if we didn't find it in the list */
1023  if (!NT_SUCCESS(Status))
1024  {
1025  /* Nothing found, release the lock */
1027  }
1028  else
1029  {
1030  /* Lock the found process and return it */
1033  }
1034 
1035  /* Return the result */
1036  return Status;
1037 }
LONG NTSTATUS
Definition: precomp.h:26
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY ListLink
Definition: csrsrv.h:39
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
ULONG CurrentProcess
Definition: shell.c:125
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CsrProcessRefcountZero()

VOID NTAPI CsrProcessRefcountZero ( IN PCSR_PROCESS  CsrProcess)

Definition at line 119 of file procsup.c.

120 {
122 
123  /* Remove the Process from the list */
125 
126  /* Check if there's a session */
127  if (CsrProcess->NtSession)
128  {
129  /* Dereference the Session */
130  CsrDereferenceNtSession(CsrProcess->NtSession, 0);
131  }
132 
133  /* Close the Client Port if there is one */
134  if (CsrProcess->ClientPort) NtClose(CsrProcess->ClientPort);
135 
136  /* Close the process handle */
137  NtClose(CsrProcess->ProcessHandle);
138 
139  /* Free the Proces Object */
141 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define ProcessStructureListLocked()
Definition: api.h:18
VOID NTAPI CsrDereferenceNtSession(IN PCSR_NT_SESSION Session, IN NTSTATUS ExitStatus)
Definition: session.c:156
VOID NTAPI CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:296
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI CsrRemoveProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:319

Referenced by CsrDereferenceProcess(), and CsrLockedDereferenceProcess().

◆ CsrRemoveProcess()

VOID NTAPI CsrRemoveProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 319 of file procsup.c.

320 {
321  PCSR_SERVER_DLL ServerDll;
322  ULONG i;
324 
325  /* Remove us from the Process List */
326  RemoveEntryList(&CsrProcess->ListLink);
327 
328  /* Release the lock */
330 
331  /* Loop every Server DLL */
332  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
333  {
334  /* Get the Server DLL */
335  ServerDll = CsrLoadedServerDll[i];
336 
337  /* Check if it's valid and if it has a Disconnect Callback */
338  if (ServerDll && ServerDll->DisconnectCallback)
339  {
340  /* Call it */
341  ServerDll->DisconnectCallback(CsrProcess);
342  }
343  }
344 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define ProcessStructureListLocked()
Definition: api.h:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PCSR_DISCONNECT_CALLBACK DisconnectCallback
Definition: csrsrv.h:236
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by CsrProcessRefcountZero().

◆ CsrRevertToSelf()

BOOLEAN NTAPI CsrRevertToSelf ( VOID  )

Definition at line 1056 of file procsup.c.

1057 {
1058  NTSTATUS Status;
1059  PCSR_THREAD CurrentThread = CsrGetClientThread();
1060  HANDLE ImpersonationToken = NULL;
1061 
1062  /* Check if we have a Current Thread */
1063  if (CurrentThread)
1064  {
1065  /* Make sure impersonation is on */
1066  if (!CurrentThread->ImpersonationCount)
1067  {
1068  DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
1069  // DbgBreakPoint();
1070  return FALSE;
1071  }
1072  else if ((--CurrentThread->ImpersonationCount) > 0)
1073  {
1074  /* Success; impersonation count decreased but still not zero */
1075  return TRUE;
1076  }
1077  }
1078 
1079  /* Impersonation has been totally removed, revert to ourselves */
1082  &ImpersonationToken,
1083  sizeof(ImpersonationToken));
1084 
1085  /* Return TRUE or FALSE */
1086  return NT_SUCCESS(Status);
1087 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define NtCurrentThread()
#define FALSE
Definition: types.h:117
ULONG ImpersonationCount
Definition: csrsrv.h:74
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:2023
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8

Referenced by BaseSrvIsVdmAllowed(), CheckForGlobalDriveLetter(), ConSrvInitConsole(), CSR_API(), FindProcessForShutdown(), GuiInit(), GuiLoadFrontEnd(), and UserExitReactOS().

◆ CsrSetBackgroundPriority()

VOID NTAPI CsrSetBackgroundPriority ( IN PCSR_PROCESS  CsrProcess)

Definition at line 1106 of file procsup.c.

1107 {
1108  PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
1109 
1110  /* Set the Foreground bit off */
1111  ProcessPriority.Foreground = FALSE;
1112 
1113  /* Set the new priority */
1114  NtSetInformationProcess(CsrProcess->ProcessHandle,
1116  &ProcessPriority,
1117  sizeof(ProcessPriority));
1118 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

Referenced by ConSrvSetProcessFocus(), CsrCreateProcess(), and CsrSbCreateSession().

◆ CsrSetForegroundPriority()

VOID NTAPI CsrSetForegroundPriority ( IN PCSR_PROCESS  CsrProcess)

Definition at line 1137 of file procsup.c.

1138 {
1139  PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
1140 
1141  /* Set the Foreground bit on */
1142  ProcessPriority.Foreground = TRUE;
1143 
1144  /* Set the new priority */
1145  NtSetInformationProcess(CsrProcess->ProcessHandle,
1147  &ProcessPriority,
1148  sizeof(ProcessPriority));
1149 }
#define TRUE
Definition: types.h:120
PKPROCESS CsrProcess
Definition: videoprt.c:39
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

Referenced by ConSrvSetProcessFocus().

◆ CsrSetToNormalPriority()

VOID NTAPI CsrSetToNormalPriority ( VOID  )

Definition at line 52 of file procsup.c.

53 {
54  KPRIORITY BasePriority = (8 + 1) + 4;
55 
56  /* Set the Priority */
59  &BasePriority,
60  sizeof(BasePriority));
61 }
LONG KPRIORITY
Definition: compat.h:551
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

Referenced by CsrShutdownProcesses().

◆ CsrSetToShutdownPriority()

VOID NTAPI CsrSetToShutdownPriority ( VOID  )

Definition at line 80 of file procsup.c.

81 {
82  KPRIORITY BasePriority = (8 + 1) + 6;
83  BOOLEAN Old;
84 
85  /* Get the shutdown privilege */
87  TRUE,
88  FALSE,
89  &Old)))
90  {
91  /* Set the Priority */
94  &BasePriority,
95  sizeof(BasePriority));
96  }
97 }
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
LONG KPRIORITY
Definition: compat.h:551
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

Referenced by CsrShutdownProcesses().

◆ CsrShutdownProcesses()

NTSTATUS NTAPI CsrShutdownProcesses ( IN PLUID  CallerLuid,
IN ULONG  Flags 
)

Definition at line 1276 of file procsup.c.

1278 {
1279  PLIST_ENTRY NextEntry;
1281  NTSTATUS Status;
1282  BOOLEAN FirstTry;
1283  ULONG i;
1284  PCSR_SERVER_DLL ServerDll;
1285  ULONG Result = 0;
1286 
1287  /* Acquire process lock */
1289 
1290  /* Add shutdown flag */
1292 
1293  /* Get the list pointers */
1294  NextEntry = CsrRootProcess->ListLink.Flink;
1295  while (NextEntry != &CsrRootProcess->ListLink)
1296  {
1297  /* Get the Process */
1298  CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
1299 
1300  /* Move to the next entry */
1301  NextEntry = NextEntry->Flink;
1302 
1303  /* Remove the skip flag, set shutdown flags to 0 */
1305  CsrProcess->ShutdownFlags = 0;
1306  }
1307 
1308  /* Set shutdown Priority */
1310 
1311  /* Start looping */
1312  while (TRUE)
1313  {
1314  /* Find the next process to shutdown */
1315  CsrProcess = FindProcessForShutdown(CallerLuid);
1316  if (!CsrProcess) break;
1317 
1318  /* Increase reference to process */
1320 
1321  FirstTry = TRUE;
1322  while (TRUE)
1323  {
1324  /* Loop all the servers */
1325  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
1326  {
1327  /* Get the current server */
1328  ServerDll = CsrLoadedServerDll[i];
1329 
1330  /* Check if it's valid and if it has a Shutdown Process Callback */
1331  if (ServerDll && ServerDll->ShutdownProcessCallback)
1332  {
1333  /* Release the lock, make the callback, and acquire it back */
1336  Flags,
1337  FirstTry);
1339 
1340  /* Check the result */
1342  {
1343  /* The callback unlocked the process */
1344  break;
1345  }
1346  else if (Result == CsrShutdownCancelled)
1347  {
1348 #ifdef CSR_DBG
1349  /* Check if this was a forced shutdown */
1350  if (Flags & EWX_FORCE)
1351  {
1352  DPRINT1("Process %x cancelled forced shutdown (Dll = %d)\n",
1353  CsrProcess->ClientId.UniqueProcess, i);
1354  DbgBreakPoint();
1355  }
1356 #endif
1357 
1358  /* Shutdown was cancelled, unlock and exit */
1361  goto Quickie;
1362  }
1363  }
1364  }
1365 
1366  /* No matches during the first try, so loop again */
1368  {
1369  FirstTry = FALSE;
1370  continue;
1371  }
1372 
1373  /* Second try, break out */
1374  break;
1375  }
1376 
1377  /* We've reached the final loop here, so dereference */
1378  if (i == CSR_SERVER_DLL_MAX)
1380  }
1381 
1382  /* Success path */
1385 
1386 Quickie:
1387  /* Return to normal priority */
1389 
1390  return Status;
1391 }
#define EWX_FORCE
Definition: winuser.h:630
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
ULONG ShutdownFlags
Definition: csrsrv.h:59
PKPROCESS CsrProcess
Definition: videoprt.c:39
void DbgBreakPoint()
Definition: mach.c:553
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY ListLink
Definition: csrsrv.h:39
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
PCSR_PROCESS NTAPI FindProcessForShutdown(IN PLUID CallerLuid)
Definition: procsup.c:1167
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
Definition: copy.c:32
PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
Definition: csrsrv.h:240
VOID NTAPI CsrSetToNormalPriority(VOID)
Definition: procsup.c:52
VOID NTAPI CsrSetToShutdownPriority(VOID)
Definition: procsup.c:80
#define DPRINT1
Definition: precomp.h:8
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2020
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
return STATUS_SUCCESS
Definition: btrfs.c:3014
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by UserExitReactOS().

◆ CsrUnlockProcess()

NTSTATUS NTAPI CsrUnlockProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 1409 of file procsup.c.

1410 {
1411  /* Dereference the process */
1413 
1414  /* Release the lock and return */
1416  return STATUS_SUCCESS;
1417 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API_NOCONSOLE(), CSR_API(), CsrCreateRemoteThread(), CsrCreateThread(), and NotifyUserProcessForShutdown().

◆ FindProcessForShutdown()

PCSR_PROCESS NTAPI FindProcessForShutdown ( IN PLUID  CallerLuid)

Definition at line 1167 of file procsup.c.

1168 {
1169  PCSR_PROCESS CsrProcess, ReturnCsrProcess = NULL;
1170  PCSR_THREAD CsrThread;
1171  NTSTATUS Status;
1172  ULONG Level = 0;
1173  LUID ProcessLuid;
1174  LUID SystemLuid = SYSTEM_LUID;
1175  PLIST_ENTRY NextEntry;
1176 
1177  /* Set the List Pointers */
1178  NextEntry = CsrRootProcess->ListLink.Flink;
1179  while (NextEntry != &CsrRootProcess->ListLink)
1180  {
1181  /* Get the process */
1182  CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
1183 
1184  /* Move to the next entry */
1185  NextEntry = NextEntry->Flink;
1186 
1187  /* Skip this process if it's already been processed */
1188  if (CsrProcess->Flags & CsrProcessSkipShutdown) continue;
1189 
1190  /* Get the LUID of this process */
1191  Status = CsrGetProcessLuid(CsrProcess->ProcessHandle, &ProcessLuid);
1192 
1193  /* Check if we didn't get access to the LUID */
1195  {
1196  /* Check if we have any threads */
1197  if (CsrProcess->ThreadCount)
1198  {
1199  /* Impersonate one of the threads and retry */
1200  CsrThread = CONTAINING_RECORD(CsrProcess->ThreadList.Flink,
1201  CSR_THREAD,
1202  Link);
1203  if (CsrImpersonateClient(CsrThread))
1204  {
1205  Status = CsrGetProcessLuid(NULL, &ProcessLuid);
1206  CsrRevertToSelf();
1207  }
1208  else
1209  {
1211  }
1212  }
1213  }
1214 
1215  if (!NT_SUCCESS(Status))
1216  {
1217  /* We didn't have access, so skip it */
1219  continue;
1220  }
1221 
1222  /* Check if this is the System LUID */
1223  if (RtlEqualLuid(&ProcessLuid, &SystemLuid))
1224  {
1225  /* Mark this process */
1226  CsrProcess->ShutdownFlags |= CsrShutdownSystem;
1227  }
1228  else if (!RtlEqualLuid(&ProcessLuid, CallerLuid))
1229  {
1230  /* Our LUID doesn't match with the caller's */
1231  CsrProcess->ShutdownFlags |= CsrShutdownOther;
1232  }
1233 
1234  /* Check if we're past the previous level */
1235  if ((CsrProcess->ShutdownLevel > Level) || !ReturnCsrProcess)
1236  {
1237  /* Update the level */
1238  Level = CsrProcess->ShutdownLevel;
1239 
1240  /* Set the final process */
1241  ReturnCsrProcess = CsrProcess;
1242  }
1243  }
1244 
1245  /* Check if we found a process */
1246  if (ReturnCsrProcess)
1247  {
1248  /* Skip this one next time */
1249  ReturnCsrProcess->Flags |= CsrProcessSkipShutdown;
1250  }
1251 
1252  return ReturnCsrProcess;
1253 }
#define STATUS_BAD_IMPERSONATION_LEVEL
Definition: ntstatus.h:401
BOOLEAN NTAPI CsrRevertToSelf(VOID)
Definition: procsup.c:1056
NTSTATUS NTAPI CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL, OUT PLUID Luid)
Definition: procsup.c:827
LONG NTSTATUS
Definition: precomp.h:26
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
PKPROCESS CsrProcess
Definition: videoprt.c:39
static int Link(const char **args)
Definition: vfdcmd.c:2414
BOOLEAN NTAPI CsrImpersonateClient(IN PCSR_THREAD CsrThread)
Definition: procsup.c:931
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:301
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY ListLink
Definition: csrsrv.h:39
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
Status
Definition: gdiplustypes.h:24
Definition: typedefs.h:119
#define SYSTEM_LUID
Definition: setypes.h:672
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2020
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:48

Referenced by CsrShutdownProcesses().

Variable Documentation

◆ CsrProcessLock

RTL_CRITICAL_SECTION CsrProcessLock

Definition at line 21 of file procsup.c.

Referenced by CsrInitializeProcessStructure().

◆ CsrProcessSequenceCount

ULONG CsrProcessSequenceCount = 5

Definition at line 30 of file procsup.c.

Referenced by CsrAllocateProcess().

◆ CsrRootProcess

◆ CsrSecurityQos

Initial value:
=
{
}
#define FALSE
Definition: types.h:117
#define SECURITY_STATIC_TRACKING
Definition: setypes.h:104
struct _SECURITY_QUALITY_OF_SERVICE SECURITY_QUALITY_OF_SERVICE

Definition at line 23 of file procsup.c.

Referenced by CsrImpersonateClient().

◆ CsrTotalPerProcessDataLength

ULONG CsrTotalPerProcessDataLength

Definition at line 35 of file init.c.

Referenced by CsrAllocateProcess(), CsrInitCsrRootProcess(), and CsrParseServerCommandLine().