ReactOS  0.4.15-dev-1397-g19779b3
csrsrv.h File Reference
#include "csrmsg.h"
Include dependency graph for csrsrv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _CSR_NT_SESSION
 
struct  _CSR_PROCESS
 
struct  _CSR_THREAD
 
struct  _CSR_WAIT_BLOCK
 
struct  _CSR_SERVER_DLL
 

Macros

#define CSR_CSRSS_SECTION_SIZE   65536
 
#define CsrGetClientThread()   ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
 
#define CsrProcessPriorityFlags
 
#define CSR_API(n)
 
#define CSR_SERVER_DLL_INIT(n)   NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
 

Typedefs

typedef struct _CSR_NT_SESSION CSR_NT_SESSION
 
typedef struct _CSR_NT_SESSIONPCSR_NT_SESSION
 
typedef struct _CSR_PROCESS CSR_PROCESS
 
typedef struct _CSR_PROCESSPCSR_PROCESS
 
typedef struct _CSR_THREAD CSR_THREAD
 
typedef struct _CSR_THREADPCSR_THREAD
 
typedef enum _CSR_PROCESS_FLAGS CSR_PROCESS_FLAGS
 
typedef enum _CSR_PROCESS_FLAGSPCSR_PROCESS_FLAGS
 
typedef enum _CSR_THREAD_FLAGS CSR_THREAD_FLAGS
 
typedef enum _CSR_THREAD_FLAGSPCSR_THREAD_FLAGS
 
typedef enum _SHUTDOWN_RESULT SHUTDOWN_RESULT
 
typedef enum _SHUTDOWN_RESULTPSHUTDOWN_RESULT
 
typedef enum _CSR_SHUTDOWN_FLAGS CSR_SHUTDOWN_FLAGS
 
typedef enum _CSR_SHUTDOWN_FLAGSPCSR_SHUTDOWN_FLAGS
 
typedef enum _CSR_DEBUG_FLAGS CSR_PROCESS_DEBUG_FLAGS
 
typedef enum _CSR_DEBUG_FLAGSPCSR_PROCESS_DEBUG_FLAGS
 
typedef enum _CSR_REPLY_CODE CSR_REPLY_CODE
 
typedef enum _CSR_REPLY_CODEPCSR_REPLY_CODE
 
typedef BOOLEAN(NTAPICSR_WAIT_FUNCTION) (IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)
 
typedef struct _CSR_WAIT_BLOCK CSR_WAIT_BLOCK
 
typedef struct _CSR_WAIT_BLOCKPCSR_WAIT_BLOCK
 
typedef NTSTATUS(NTAPIPCSR_API_ROUTINE) (IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
 
typedef NTSTATUS(NTAPIPCSR_CONNECT_CALLBACK) (IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
 
typedef VOID(NTAPIPCSR_DISCONNECT_CALLBACK) (IN PCSR_PROCESS CsrProcess)
 
typedef NTSTATUS(NTAPIPCSR_NEWPROCESS_CALLBACK) (IN PCSR_PROCESS Parent, IN PCSR_PROCESS CsrProcess)
 
typedef VOID(NTAPIPCSR_HARDERROR_CALLBACK) (IN PCSR_THREAD CsrThread, IN PHARDERROR_MSG HardErrorMessage)
 
typedef ULONG(NTAPIPCSR_SHUTDOWNPROCESS_CALLBACK) (IN PCSR_PROCESS CsrProcess, IN ULONG Flags, IN BOOLEAN FirstPhase)
 
typedef struct _CSR_SERVER_DLL CSR_SERVER_DLL
 
typedef struct _CSR_SERVER_DLLPCSR_SERVER_DLL
 
typedef NTSTATUS(NTAPIPCSR_SERVER_DLL_INIT_CALLBACK) (IN PCSR_SERVER_DLL LoadedServerDll)
 

Enumerations

enum  _CSR_PROCESS_FLAGS {
  CsrProcessTerminating = 0x1, CsrProcessSkipShutdown = 0x2, CsrProcessNormalPriority = 0x10, CsrProcessIdlePriority = 0x20,
  CsrProcessHighPriority = 0x40, CsrProcessRealtimePriority = 0x80, CsrProcessCreateNewGroup = 0x100, CsrProcessTerminated = 0x200,
  CsrProcessLastThreadTerminated = 0x400, CsrProcessIsConsoleApp = 0x800
}
 
enum  _CSR_THREAD_FLAGS { CsrThreadAlertable = 0x1, CsrThreadInTermination = 0x2, CsrThreadTerminated = 0x4, CsrThreadIsServerThread = 0x10 }
 
enum  _SHUTDOWN_RESULT { CsrShutdownCsrProcess = 1, CsrShutdownNonCsrProcess, CsrShutdownCancelled }
 
enum  _CSR_SHUTDOWN_FLAGS { CsrShutdownSystem = 4, CsrShutdownOther = 8 }
 
enum  _CSR_DEBUG_FLAGS { CsrDebugOnlyThisProcess = 1, CsrDebugProcessChildren = 2 }
 
enum  _CSR_REPLY_CODE { CsrReplyImmediately = 0, CsrReplyPending = 1, CsrReplyDeadClient = 2, CsrReplyAlreadySent = 3 }
 

Functions

 C_ASSERT (FIELD_OFFSET(CSR_SERVER_DLL, SharedSection)==0x38)
 
NTSTATUS NTAPI CsrServerInitialization (IN ULONG ArgumentCount, IN PCHAR Arguments[])
 
PCSR_THREAD NTAPI CsrAddStaticServerThread (IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
 
NTSTATUS NTAPI CsrCallServerFromServer (IN PCSR_API_MESSAGE ReceiveMsg, IN OUT PCSR_API_MESSAGE ReplyMsg)
 
PCSR_THREAD NTAPI CsrConnectToUser (VOID)
 
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 CsrCreateRemoteThread (IN HANDLE hThread, IN PCLIENT_ID ClientId)
 
NTSTATUS NTAPI CsrCreateThread (IN PCSR_PROCESS CsrProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN BOOLEAN HaveClient)
 
BOOLEAN NTAPI CsrCreateWait (IN PLIST_ENTRY WaitList, IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext)
 
NTSTATUS NTAPI CsrDebugProcess (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrDebugProcessStop (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrDereferenceProcess (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrDereferenceThread (IN PCSR_THREAD CsrThread)
 
VOID NTAPI CsrDereferenceWait (IN PLIST_ENTRY WaitList)
 
NTSTATUS NTAPI CsrDestroyProcess (IN PCLIENT_ID Cid, IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI CsrDestroyThread (IN PCLIENT_ID Cid)
 
NTSTATUS NTAPI CsrExecServerThread (IN PVOID ThreadHandler, IN ULONG Flags)
 
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 OPTIONAL)
 
NTSTATUS NTAPI CsrLockThreadByClientId (IN HANDLE Tid, OUT PCSR_THREAD *CsrThread)
 
VOID NTAPI CsrMoveSatisfiedWait (IN PLIST_ENTRY DestinationList, IN PLIST_ENTRY WaitList)
 
BOOLEAN NTAPI CsrNotifyWait (IN PLIST_ENTRY WaitList, IN BOOLEAN NotifyAll, IN PVOID WaitArgument1, IN PVOID WaitArgument2)
 
VOID NTAPI CsrPopulateDosDevices (VOID)
 
HANDLE NTAPI CsrQueryApiPort (VOID)
 
VOID NTAPI CsrReferenceThread (IN PCSR_THREAD CsrThread)
 
BOOLEAN NTAPI CsrRevertToSelf (VOID)
 
VOID NTAPI CsrSetBackgroundPriority (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrSetCallingSpooler (ULONG Reserved)
 
VOID NTAPI CsrSetForegroundPriority (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrShutdownProcesses (IN PLUID CallerLuid, IN ULONG Flags)
 
EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter (IN PEXCEPTION_POINTERS ExceptionInfo)
 
NTSTATUS NTAPI CsrUnlockProcess (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrUnlockThread (IN PCSR_THREAD CsrThread)
 
BOOLEAN NTAPI CsrValidateMessageBuffer (IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
 
BOOLEAN NTAPI CsrValidateMessageString (IN PCSR_API_MESSAGE ApiMessage, IN PWSTR *MessageString)
 

Macro Definition Documentation

◆ CSR_API

#define CSR_API (   n)
Value:
#define IN
Definition: typedefs.h:39
LONG NTSTATUS
Definition: precomp.h:26
enum _CSR_REPLY_CODE * PCSR_REPLY_CODE
GLdouble n
Definition: glext.h:7729
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define OUT
Definition: typedefs.h:40
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68

Definition at line 176 of file csrsrv.h.

◆ CSR_CSRSS_SECTION_SIZE

#define CSR_CSRSS_SECTION_SIZE   65536

Definition at line 27 of file csrsrv.h.

◆ CSR_SERVER_DLL_INIT

#define CSR_SERVER_DLL_INIT (   n)    NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)

Definition at line 255 of file csrsrv.h.

◆ CsrGetClientThread

#define CsrGetClientThread ( )    ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))

Definition at line 77 of file csrsrv.h.

◆ CsrProcessPriorityFlags

#define CsrProcessPriorityFlags
Value:
CsrProcessIdlePriority | \
CsrProcessHighPriority | \
CsrProcessRealtimePriority)

Definition at line 97 of file csrsrv.h.

Typedef Documentation

◆ CSR_NT_SESSION

◆ CSR_PROCESS

◆ CSR_PROCESS_DEBUG_FLAGS

◆ CSR_PROCESS_FLAGS

◆ CSR_REPLY_CODE

◆ CSR_SERVER_DLL

◆ CSR_SHUTDOWN_FLAGS

◆ CSR_THREAD

◆ CSR_THREAD_FLAGS

◆ CSR_WAIT_BLOCK

◆ CSR_WAIT_FUNCTION

typedef BOOLEAN(NTAPI * CSR_WAIT_FUNCTION) (IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)

Definition at line 145 of file csrsrv.h.

◆ PCSR_API_ROUTINE

typedef NTSTATUS(NTAPI * PCSR_API_ROUTINE) (IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)

Definition at line 171 of file csrsrv.h.

◆ PCSR_CONNECT_CALLBACK

typedef NTSTATUS(NTAPI * PCSR_CONNECT_CALLBACK) (IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)

Definition at line 182 of file csrsrv.h.

◆ PCSR_DISCONNECT_CALLBACK

typedef VOID(NTAPI * PCSR_DISCONNECT_CALLBACK) (IN PCSR_PROCESS CsrProcess)

Definition at line 190 of file csrsrv.h.

◆ PCSR_HARDERROR_CALLBACK

typedef VOID(NTAPI * PCSR_HARDERROR_CALLBACK) (IN PCSR_THREAD CsrThread, IN PHARDERROR_MSG HardErrorMessage)

Definition at line 201 of file csrsrv.h.

◆ PCSR_NEWPROCESS_CALLBACK

typedef NTSTATUS(NTAPI * PCSR_NEWPROCESS_CALLBACK) (IN PCSR_PROCESS Parent, IN PCSR_PROCESS CsrProcess)

Definition at line 194 of file csrsrv.h.

◆ PCSR_NT_SESSION

◆ PCSR_PROCESS

◆ PCSR_PROCESS_DEBUG_FLAGS

◆ PCSR_PROCESS_FLAGS

◆ PCSR_REPLY_CODE

◆ PCSR_SERVER_DLL

◆ PCSR_SERVER_DLL_INIT_CALLBACK

typedef NTSTATUS(NTAPI * PCSR_SERVER_DLL_INIT_CALLBACK) (IN PCSR_SERVER_DLL LoadedServerDll)

Definition at line 253 of file csrsrv.h.

◆ PCSR_SHUTDOWN_FLAGS

◆ PCSR_SHUTDOWNPROCESS_CALLBACK

typedef ULONG(NTAPI * PCSR_SHUTDOWNPROCESS_CALLBACK) (IN PCSR_PROCESS CsrProcess, IN ULONG Flags, IN BOOLEAN FirstPhase)

Definition at line 208 of file csrsrv.h.

◆ PCSR_THREAD

◆ PCSR_THREAD_FLAGS

◆ PCSR_WAIT_BLOCK

◆ PSHUTDOWN_RESULT

◆ SHUTDOWN_RESULT

Enumeration Type Documentation

◆ _CSR_DEBUG_FLAGS

Enumerator
CsrDebugOnlyThisProcess 
CsrDebugProcessChildren 

Definition at line 123 of file csrsrv.h.

124 {
enum _CSR_DEBUG_FLAGS * PCSR_PROCESS_DEBUG_FLAGS
enum _CSR_DEBUG_FLAGS CSR_PROCESS_DEBUG_FLAGS

◆ _CSR_PROCESS_FLAGS

Enumerator
CsrProcessTerminating 
CsrProcessSkipShutdown 
CsrProcessNormalPriority 
CsrProcessIdlePriority 
CsrProcessHighPriority 
CsrProcessRealtimePriority 
CsrProcessCreateNewGroup 
CsrProcessTerminated 
CsrProcessLastThreadTerminated 
CsrProcessIsConsoleApp 

Definition at line 83 of file csrsrv.h.

◆ _CSR_REPLY_CODE

Enumerator
CsrReplyImmediately 
CsrReplyPending 
CsrReplyDeadClient 
CsrReplyAlreadySent 

Definition at line 129 of file csrsrv.h.

130 {
132  CsrReplyPending = 1,
133  CsrReplyDeadClient = 2,
enum _CSR_REPLY_CODE * PCSR_REPLY_CODE
enum _CSR_REPLY_CODE CSR_REPLY_CODE

◆ _CSR_SHUTDOWN_FLAGS

Enumerator
CsrShutdownSystem 
CsrShutdownOther 

Definition at line 117 of file csrsrv.h.

118 {
119  CsrShutdownSystem = 4,
120  CsrShutdownOther = 8
enum _CSR_SHUTDOWN_FLAGS * PCSR_SHUTDOWN_FLAGS
enum _CSR_SHUTDOWN_FLAGS CSR_SHUTDOWN_FLAGS

◆ _CSR_THREAD_FLAGS

Enumerator
CsrThreadAlertable 
CsrThreadInTermination 
CsrThreadTerminated 
CsrThreadIsServerThread 

Definition at line 102 of file csrsrv.h.

103 {
104  CsrThreadAlertable = 0x1,
106  CsrThreadTerminated = 0x4,
enum _CSR_THREAD_FLAGS CSR_THREAD_FLAGS
enum _CSR_THREAD_FLAGS * PCSR_THREAD_FLAGS

◆ _SHUTDOWN_RESULT

Enumerator
CsrShutdownCsrProcess 
CsrShutdownNonCsrProcess 
CsrShutdownCancelled 

Definition at line 110 of file csrsrv.h.

111 {
enum _SHUTDOWN_RESULT SHUTDOWN_RESULT
enum _SHUTDOWN_RESULT * PSHUTDOWN_RESULT

Function Documentation

◆ C_ASSERT()

C_ASSERT ( FIELD_OFFSET(CSR_SERVER_DLL, SharedSection)  = =0x38)

◆ CsrAddStaticServerThread()

PCSR_THREAD NTAPI CsrAddStaticServerThread ( IN HANDLE  hThread,
IN PCLIENT_ID  ClientId,
IN ULONG  ThreadFlags 
)

Definition at line 511 of file thredsup.c.

514 {
515  PCSR_THREAD CsrThread;
516 
517  /* Get the Lock */
519 
520  /* Allocate the Server Thread */
521  CsrThread = CsrAllocateThread(CsrRootProcess);
522  if (CsrThread)
523  {
524  /* Setup the Object */
525  CsrThread->ThreadHandle = hThread;
527  CsrThread->ClientId = *ClientId;
528  CsrThread->Flags = ThreadFlags;
529 
530  /* Insert it into the Thread List */
532 
533  /* Increment the thread count */
535  }
536  else
537  {
538  DPRINT1("CsrAddStaticServerThread: alloc failed for thread 0x%x\n", hThread);
539  }
540 
541  /* Release the Process Lock and return */
543  return CsrThread;
544 }
LIST_ENTRY Link
Definition: csrsrv.h:66
#define InsertTailList(ListHead, Entry)
#define CsrReleaseProcessLock()
Definition: api.h:15
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
ULONG ThreadCount
Definition: csrsrv.h:55
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
ULONG Flags
Definition: csrsrv.h:72
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119

Referenced by CsrApiPortInitialize(), CsrpCheckRequestThreads(), CsrSbApiPortInitialize(), and GuiInit().

◆ CsrCallServerFromServer()

NTSTATUS NTAPI CsrCallServerFromServer ( IN PCSR_API_MESSAGE  ReceiveMsg,
IN OUT PCSR_API_MESSAGE  ReplyMsg 
)

Definition at line 51 of file api.c.

53 {
54  ULONG ServerId;
55  PCSR_SERVER_DLL ServerDll;
56  ULONG ApiId;
58 
59  /* Get the Server ID */
60  ServerId = CSR_API_NUMBER_TO_SERVER_ID(ReceiveMsg->ApiNumber);
61 
62  /* Make sure that the ID is within limits, and the Server DLL loaded */
63  if ((ServerId >= CSR_SERVER_DLL_MAX) ||
64  (!(ServerDll = CsrLoadedServerDll[ServerId])))
65  {
66  /* We are beyond the Maximum Server ID */
67  DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n", ServerId, ServerDll);
68  ReplyMsg->Status = STATUS_ILLEGAL_FUNCTION;
70  }
71  else
72  {
73  /* Get the API ID, normalized with our Base ID */
74  ApiId = CSR_API_NUMBER_TO_API_ID(ReceiveMsg->ApiNumber) - ServerDll->ApiBase;
75 
76  /* Make sure that the ID is within limits, and the entry exists */
77  if ((ApiId >= ServerDll->HighestApiSupported) ||
78  ((ServerDll->ValidTable) && !(ServerDll->ValidTable[ApiId])))
79  {
80  /* We are beyond the Maximum API ID, or it doesn't exist */
81 #ifdef CSR_DBG
82  DPRINT1("API: %d\n", ApiId);
83  DPRINT1("CSRSS: %lx (%s) is invalid ApiTableIndex for %Z or is an "
84  "invalid API to call from the server.\n",
85  ApiId,
86  ((ServerDll->NameTable) && (ServerDll->NameTable[ApiId])) ?
87  ServerDll->NameTable[ApiId] : "*** UNKNOWN ***",
88  &ServerDll->Name);
89  if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
90 #endif
91  ReplyMsg->Status = STATUS_ILLEGAL_FUNCTION;
93  }
94  }
95 
96 #ifdef CSR_DBG
97  if (CsrDebug & 2)
98  {
99  DPRINT1("CSRSS: %s Api Request received from server process\n",
100  ServerDll->NameTable[ApiId]);
101  }
102 #endif
103 
104  /* Validation complete, start SEH */
105  _SEH2_TRY
106  {
107  /* Call the API, get the reply code and return the result */
108  ReplyMsg->Status = ServerDll->DispatchTable[ApiId](ReceiveMsg, &ReplyCode);
109  }
111  {
112  /* If we got an exception, return access violation */
113  ReplyMsg->Status = STATUS_ACCESS_VIOLATION;
114  }
115  _SEH2_END;
116 
117  /* Return success */
118  return STATUS_SUCCESS;
119 }
ULONG HighestApiSupported
Definition: csrsrv.h:223
ULONG CsrDebug
Definition: init.c:23
ANSI_STRING Name
Definition: csrsrv.h:218
void DbgBreakPoint()
Definition: mach.c:553
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define CSR_API_NUMBER_TO_SERVER_ID(ApiNumber)
Definition: csrmsg.h:40
#define CSR_API_NUMBER_TO_API_ID(ApiNumber)
Definition: csrmsg.h:43
ULONG ApiBase
Definition: csrsrv.h:222
_SEH2_END
Definition: create.c:4400
#define NtCurrentPeb()
Definition: FLS.c:20
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
enum _CSR_REPLY_CODE CSR_REPLY_CODE
#define DPRINT1
Definition: precomp.h:8
PCSR_API_ROUTINE * DispatchTable
Definition: csrsrv.h:224
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:411
PBOOLEAN ValidTable
Definition: csrsrv.h:225
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

◆ CsrConnectToUser()

PCSR_THREAD NTAPI CsrConnectToUser ( VOID  )

Definition at line 1017 of file api.c.

1018 {
1019  NTSTATUS Status;
1020  ANSI_STRING DllName;
1021  UNICODE_STRING TempName;
1022  HANDLE hUser32;
1023  STRING StartupName;
1024  PTEB Teb = NtCurrentTeb();
1025  PCSR_THREAD CsrThread;
1026  BOOLEAN Connected;
1027 
1028  /* Check if we didn't already find it */
1029  if (!CsrClientThreadSetup)
1030  {
1031  /* Get the DLL Handle for user32.dll */
1032  RtlInitAnsiString(&DllName, "user32");
1033  RtlAnsiStringToUnicodeString(&TempName, &DllName, TRUE);
1035  NULL,
1036  &TempName,
1037  &hUser32);
1038  RtlFreeUnicodeString(&TempName);
1039 
1040  /* If we got the handle, get the Client Thread Startup Entrypoint */
1041  if (NT_SUCCESS(Status))
1042  {
1043  RtlInitAnsiString(&StartupName,"ClientThreadSetup");
1044  Status = LdrGetProcedureAddress(hUser32,
1045  &StartupName,
1046  0,
1048  }
1049  }
1050 
1051  /* Connect to user32 */
1052  _SEH2_TRY
1053  {
1054  Connected = CsrClientThreadSetup();
1055  }
1057  {
1058  Connected = FALSE;
1059  }
1060  _SEH2_END;
1061 
1062  if (!Connected)
1063  {
1064  DPRINT1("CSRSS: CsrConnectToUser failed\n");
1065  return NULL;
1066  }
1067 
1068  /* Save pointer to this thread in TEB */
1070  CsrThread = CsrLocateThreadInProcess(NULL, &Teb->ClientId);
1072  if (CsrThread) Teb->CsrClientThread = CsrThread;
1073 
1074  /* Return it */
1075  return CsrThread;
1076 }
NTSTATUS NTAPI LdrGetDllHandle(IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle)
Definition: ldrapi.c:805
#define TRUE
Definition: types.h:120
PVOID CsrClientThread
Definition: compat.h:704
BOOLEAN(* CsrClientThreadSetup)(VOID)
Definition: api.c:21
LONG NTSTATUS
Definition: precomp.h:26
#define CsrReleaseProcessLock()
Definition: api.h:15
_SEH2_TRY
Definition: create.c:4226
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
CLIENT_ID ClientId
Definition: compat.h:698
#define FALSE
Definition: types.h:117
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSTATUS NTAPI LdrGetProcedureAddress(IN PVOID BaseAddress, IN PANSI_STRING Name, IN ULONG Ordinal, OUT PVOID *ProcedureAddress)
Definition: ldrapi.c:823
unsigned char BOOLEAN
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
std::wstring STRING
Definition: fontsub.cpp:33
#define CsrAcquireProcessLock()
Definition: api.h:12
PCSR_THREAD NTAPI CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL, IN PCLIENT_ID Cid)
Definition: thredsup.c:248
Definition: compat.h:694
_SEH2_END
Definition: create.c:4400
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by CsrApiRequestThread(), and GuiConsoleInputThread().

◆ 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:684
#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
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
void * PVOID
Definition: retypes.h:9
Status
Definition: gdiplustypes.h:24
ULONG CurrentProcess
Definition: shell.c:125
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
#define ASSERT(a)
Definition: mode.c:45
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:2501
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
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:1107
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
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
HANDLE hThread
Definition: wizard.c:27
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2062
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().

◆ CsrCreateRemoteThread()

NTSTATUS NTAPI CsrCreateRemoteThread ( IN HANDLE  hThread,
IN PCLIENT_ID  ClientId 
)

Definition at line 568 of file thredsup.c.

570 {
572  HANDLE ThreadHandle;
573  PCSR_THREAD CsrThread;
575  KERNEL_USER_TIMES KernelTimes;
576 
577  /* Get the Thread Create Time */
579  ThreadTimes,
580  &KernelTimes,
581  sizeof(KernelTimes),
582  NULL);
583  if (!NT_SUCCESS(Status))
584  {
585  DPRINT1("Failed to query thread times: %lx\n", Status);
586  return Status;
587  }
588 
589  /* Lock the Owner Process */
591  if (!NT_SUCCESS(Status))
592  {
593  DPRINT1("No known process for %lx\n", ClientId->UniqueProcess);
594  return Status;
595  }
596 
597  /* Make sure the thread didn't terminate */
598  if (KernelTimes.ExitTime.QuadPart)
599  {
600  /* Unlock the process and return */
602  DPRINT1("Dead thread: %I64x\n", KernelTimes.ExitTime.QuadPart);
604  }
605 
606  /* Allocate a CSR Thread Structure */
607  CsrThread = CsrAllocateThread(CsrProcess);
608  if (!CsrThread)
609  {
610  DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
612  return STATUS_NO_MEMORY;
613  }
614 
615  /* Duplicate the Thread Handle */
617  hThread,
619  &ThreadHandle,
620  0,
621  0,
623  /* Allow failure */
624  if (!NT_SUCCESS(Status))
625  {
626  DPRINT1("Thread duplication failed: %lx\n", Status);
627  ThreadHandle = hThread;
628  }
629 
630  /* Save the data we have */
631  CsrThread->CreateTime = KernelTimes.CreateTime;
632  CsrThread->ClientId = *ClientId;
633  CsrThread->ThreadHandle = ThreadHandle;
634  ProtectHandle(ThreadHandle);
635  CsrThread->Flags = 0;
636 
637  /* Insert the Thread into the Process */
638  Status = CsrInsertThread(CsrProcess, CsrThread);
639  if (!NT_SUCCESS(Status))
640  {
641  /* Bail out */
642  if (CsrThread->ThreadHandle != hThread) NtClose(CsrThread->ThreadHandle);
644  CsrDeallocateThread(CsrThread);
645  return Status;
646  }
647 
648  /* Release the lock and return */
650  return STATUS_SUCCESS;
651 }
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
LONG NTSTATUS
Definition: precomp.h:26
PKPROCESS CsrProcess
Definition: videoprt.c:39
HANDLE UniqueProcess
Definition: compat.h:684
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
#define DUPLICATE_SAME_ACCESS
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
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
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2501
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3407
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
ULONG Flags
Definition: csrsrv.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __FUNCTION__
Definition: types.h:112
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1409
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by CreateRemoteThread().

◆ CsrCreateThread()

NTSTATUS NTAPI CsrCreateThread ( IN PCSR_PROCESS  CsrProcess,
IN HANDLE  hThread,
IN PCLIENT_ID  ClientId,
IN BOOLEAN  HaveClient 
)

Definition at line 677 of file thredsup.c.

681 {
683  PCSR_THREAD CsrThread, CurrentThread;
685  CLIENT_ID CurrentCid;
686  KERNEL_USER_TIMES KernelTimes;
687 
688  if (HaveClient)
689  {
690  /* Get the current thread and CID */
691  CurrentThread = CsrGetClientThread();
692  CurrentCid = CurrentThread->ClientId;
693 
694  /* Acquire the Process Lock */
696 
697  /* Get the current Process and make sure the Thread is valid with this CID */
698  CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
699 
700  /* Something is wrong if we get an empty thread back */
701  if (!CurrentThread)
702  {
703  DPRINT1("CSRSRV: %s: invalid thread!\n", __FUNCTION__);
706  }
707  }
708  else
709  {
710  /* Acquire the Process Lock */
712  }
713 
714  /* Get the Thread Create Time */
716  ThreadTimes,
717  &KernelTimes,
718  sizeof(KernelTimes),
719  NULL);
720  if (!NT_SUCCESS(Status))
721  {
723  return Status;
724  }
725 
726  /* Allocate a CSR Thread Structure */
727  CsrThread = CsrAllocateThread(CsrProcess);
728  if (!CsrThread)
729  {
730  DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
732  return STATUS_NO_MEMORY;
733  }
734 
735  /* Save the data we have */
736  CsrThread->CreateTime = KernelTimes.CreateTime;
737  CsrThread->ClientId = *ClientId;
738  CsrThread->ThreadHandle = hThread;
740  CsrThread->Flags = 0;
741 
742  /* Insert the Thread into the Process */
743  Status = CsrInsertThread(CsrProcess, CsrThread);
744  if (!NT_SUCCESS(Status))
745  {
746  /* Bail out */
748  CsrDeallocateThread(CsrThread);
749  return Status;
750  }
751 
752  /* Release the lock and return */
754 
755  return STATUS_SUCCESS;
756 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
LONG NTSTATUS
Definition: precomp.h:26
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
Status
Definition: gdiplustypes.h:24
ULONG CurrentProcess
Definition: shell.c:125
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
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
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2501
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
ULONG Flags
Definition: csrsrv.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __FUNCTION__
Definition: types.h:112
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1409
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119

Referenced by CSR_API().

◆ CsrCreateWait()

BOOLEAN NTAPI CsrCreateWait ( IN PLIST_ENTRY  WaitList,
IN CSR_WAIT_FUNCTION  WaitFunction,
IN PCSR_THREAD  CsrWaitThread,
IN OUT PCSR_API_MESSAGE  WaitApiMessage,
IN PVOID  WaitContext 
)

Definition at line 209 of file wait.c.

214 {
215  PCSR_WAIT_BLOCK WaitBlock;
216 
217  /* Initialize the wait */
218  if (!CsrInitializeWait(WaitFunction,
219  CsrWaitThread,
220  WaitApiMessage,
221  WaitContext,
222  &WaitBlock))
223  {
224  return FALSE;
225  }
226 
227  /* Acquire the Wait Lock */
229 
230  /* Make sure the thread wasn't destroyed */
231  if (CsrWaitThread->Flags & CsrThreadTerminated)
232  {
233  /* Fail the wait */
234  RtlFreeHeap(CsrHeap, 0, WaitBlock);
236  return FALSE;
237  }
238 
239  /* Associate the newly created wait to the waiting thread */
240  CsrWaitThread->WaitBlock = WaitBlock;
241 
242  /* Insert the wait in the queue */
243  InsertTailList(WaitList, &WaitBlock->WaitList);
244 
245  /* Return */
247  return TRUE;
248 }
#define TRUE
Definition: types.h:120
LIST_ENTRY WaitList
Definition: csrsrv.h:158
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define InsertTailList(ListHead, Entry)
#define CsrReleaseWaitLock()
Definition: api.h:24
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI CsrInitializeWait(IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, OUT PCSR_WAIT_BLOCK *NewWaitBlock)
Definition: wait.c:50
#define CsrAcquireWaitLock()
Definition: api.h:21
HANDLE CsrHeap
Definition: init.c:25

Referenced by DoWriteConsole(), and WaitBeforeReading().

◆ 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
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119
#define CsrAcquireProcessLock()
Definition: api.h:12

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

◆ CsrDereferenceThread()

VOID NTAPI CsrDereferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 775 of file thredsup.c.

776 {
777  /* Acquire process lock */
779 
780  /* Decrease reference count */
781  ASSERT(CsrThread->ReferenceCount > 0);
782  if ((--CsrThread->ReferenceCount) == 0)
783  {
784  /* Call the generic cleanup code */
785  CsrThreadRefcountZero(CsrThread);
786  }
787  else
788  {
789  /* Just release the lock */
791  }
792 }
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:424
#define ASSERT(a)
Definition: mode.c:45
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by CsrApiRequestThread(), CsrDereferenceWait(), CsrNotifyWaitBlock(), GuiConsoleInputThread(), and NotifyUserProcessForShutdown().

◆ CsrDereferenceWait()

VOID NTAPI CsrDereferenceWait ( IN PLIST_ENTRY  WaitList)

Definition at line 266 of file wait.c.

267 {
268  PLIST_ENTRY NextEntry;
269  PCSR_WAIT_BLOCK WaitBlock;
270 
271  /* Acquire the Process and Wait Locks */
274 
275  /* Set the list pointers */
276  NextEntry = WaitList->Flink;
277 
278  /* Start the loop */
279  while (NextEntry != WaitList)
280  {
281  /* Get the wait block */
282  WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
283 
284  /* Move to the next entry */
285  NextEntry = NextEntry->Flink;
286 
287  /* Check if there's no Wait Routine (satisfied wait) */
288  if (WaitBlock->WaitFunction == NULL)
289  {
290  /* Remove it from the Wait List */
291  if (WaitBlock->WaitList.Flink)
292  {
293  RemoveEntryList(&WaitBlock->WaitList);
294  }
295 
296  /* Dereference the thread waiting on it */
297  CsrDereferenceThread(WaitBlock->WaitThread);
298 
299  /* Free the block */
300  RtlFreeHeap(CsrHeap, 0, WaitBlock);
301  }
302  }
303 
304  /* Release the locks */
307 }
PCSR_THREAD WaitThread
Definition: csrsrv.h:160
LIST_ENTRY WaitList
Definition: csrsrv.h:158
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
VOID NTAPI CsrDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:775
#define CsrReleaseWaitLock()
Definition: api.h:24
#define CsrReleaseProcessLock()
Definition: api.h:15
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
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
#define CsrAcquireProcessLock()
Definition: api.h:12
Definition: typedefs.h:119
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
#define CsrAcquireWaitLock()
Definition: api.h:21
#define NULL
Definition: types.h:112
HANDLE CsrHeap
Definition: init.c:25

Referenced by ConioUnpause(), ConSrvCloseHandle(), and PostprocessInput().

◆ 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
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
#define NULL
Definition: types.h:112
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2062
ULONG Flags
Definition: csrsrv.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by CSR_API(), and CsrApiRequestThread().

◆ CsrDestroyThread()

NTSTATUS NTAPI CsrDestroyThread ( IN PCLIENT_ID  Cid)

Definition at line 813 of file thredsup.c.

814 {
815  CLIENT_ID ClientId = *Cid;
816  PCSR_THREAD CsrThread;
818 
819  /* Acquire lock */
821 
822  /* Find the thread */
824  &ClientId);
825 
826  /* Make sure we got one back, and that it's not already gone */
827  if (!CsrThread || (CsrThread->Flags & CsrThreadTerminated))
828  {
829  /* Release the lock and return failure */
832  }
833 
834  /* Set the terminated flag */
835  CsrThread->Flags |= CsrThreadTerminated;
836 
837  /* Acquire the Wait Lock */
839 
840  /* Do we have an active wait block? */
841  if (CsrThread->WaitBlock)
842  {
843  /* Notify waiters of termination */
844  CsrNotifyWaitBlock(CsrThread->WaitBlock,
845  NULL,
846  NULL,
847  NULL,
849  TRUE);
850  }
851 
852  /* Release the Wait Lock */
854 
855  /* Dereference the thread */
856  CsrLockedDereferenceThread(CsrThread);
857 
858  /* Release the Process Lock and return success */
860  return STATUS_SUCCESS;
861 }
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
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define CsrAcquireProcessLock()
Definition: api.h:12
#define CsrAcquireWaitLock()
Definition: api.h:21
struct _CSR_WAIT_BLOCK * WaitBlock
Definition: csrsrv.h:70
#define NULL
Definition: types.h:112
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
ULONG Flags
Definition: csrsrv.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by CsrApiRequestThread().

◆ CsrExecServerThread()

NTSTATUS NTAPI CsrExecServerThread ( IN PVOID  ThreadHandler,
IN ULONG  Flags 
)

Definition at line 885 of file thredsup.c.

887 {
888  PCSR_THREAD CsrThread;
889  HANDLE hThread;
892 
893  /* Acquire process lock */
895 
896  /* Allocate a CSR Thread in the Root Process */
898  CsrThread = CsrAllocateThread(CsrRootProcess);
899  if (!CsrThread)
900  {
901  /* Fail */
903  return STATUS_NO_MEMORY;
904  }
905 
906  /* Create the Thread */
908  NULL,
909  FALSE,
910  0,
911  0,
912  0,
913  ThreadHandler,
914  NULL,
915  &hThread,
916  &ClientId);
917  if (!NT_SUCCESS(Status))
918  {
919  /* Fail */
920  CsrDeallocateThread(CsrThread);
922  return Status;
923  }
924 
925  /* Setup the Thread Object */
926  CsrThread->ThreadHandle = hThread;
928  CsrThread->ClientId = ClientId;
929  CsrThread->Flags = Flags;
930 
931  /* Insert it into the Thread List */
933 
934  /* Increase the thread count */
936 
937  /* Return */
939  return Status;
940 }
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY Link
Definition: csrsrv.h:66
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
#define FALSE
Definition: types.h:117
ULONG ThreadCount
Definition: csrsrv.h:55
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
HANDLE hThread
Definition: wizard.c:27
ULONG Flags
Definition: csrsrv.h:72
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119

Referenced by CSR_API().

◆ 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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
_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:1834
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
NTSTATUS NTAPI NtOpenThreadToken(IN HANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN BOOLEAN OpenAsSelf, OUT PHANDLE TokenHandle)
Definition: token.c:3853
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
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DPRINT1
Definition: precomp.h:8

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

◆ CsrLockProcessByClientId()

◆ CsrLockThreadByClientId()

NTSTATUS NTAPI CsrLockThreadByClientId ( IN HANDLE  Tid,
OUT PCSR_THREAD CsrThread 
)

Definition at line 964 of file thredsup.c.

966 {
967  PLIST_ENTRY NextEntry;
968  PCSR_THREAD CurrentThread = NULL;
970  ULONG i;
971 
972  /* Acquire the lock */
974 
975  /* Assume failure */
976  ASSERT(CsrThread != NULL);
977  *CsrThread = NULL;
978 
979  /* Convert to Hash */
980  i = CsrHashThread(Tid);
981 
982  /* Setup the List Pointers */
983  NextEntry = CsrThreadHashTable[i].Flink;
984 
985  /* Start Loop */
986  while (NextEntry != &CsrThreadHashTable[i])
987  {
988  /* Get the Thread */
989  CurrentThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
990 
991  /* Check for TID Match */
992  if ((CurrentThread->ClientId.UniqueThread == Tid) &&
993  (CurrentThread->Flags & CsrThreadTerminated) == 0)
994  {
995  /* Get out of here */
996  break;
997  }
998 
999  /* Move to the next entry */
1000  NextEntry = NextEntry->Flink;
1001  }
1002 
1003  /* Nothing found if we got back to the list */
1004  if (NextEntry == &CsrThreadHashTable[i]) CurrentThread = NULL;
1005 
1006  /* Did the loop find something? */
1007  if (CurrentThread)
1008  {
1009  /* Reference the found thread */
1011  CsrLockedReferenceThread(CurrentThread);
1012  *CsrThread = CurrentThread;
1013  }
1014  else
1015  {
1016  /* Nothing found, release the lock */
1019  }
1020 
1021  /* Return the status */
1022  return Status;
1023 }
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154
LONG NTSTATUS
Definition: precomp.h:26
#define CsrReleaseProcessLock()
Definition: api.h:15
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
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
CLIENT_ID ClientId
Definition: csrsrv.h:68
#define CsrHashThread(t)
Definition: thredsup.c:17
HANDLE UniqueThread
Definition: compat.h:685
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CsrAcquireProcessLock()
Definition: api.h:12
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
Definition: typedefs.h:119
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
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:72
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by GetThreadConsoleDesktop().

◆ CsrMoveSatisfiedWait()

VOID NTAPI CsrMoveSatisfiedWait ( IN PLIST_ENTRY  DestinationList,
IN PLIST_ENTRY  WaitList 
)

Definition at line 330 of file wait.c.

332 {
333  PLIST_ENTRY NextEntry;
334  PCSR_WAIT_BLOCK WaitBlock;
335 
336  /* Acquire the Wait Lock */
338 
339  /* Set the List pointers */
340  NextEntry = WaitList->Flink;
341 
342  /* Start looping */
343  while (NextEntry != WaitList)
344  {
345  /* Get the Wait block */
346  WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
347 
348  /* Go to the next entry */
349  NextEntry = NextEntry->Flink;
350 
351  /* Check if there's no Wait Routine (satisfied wait) */
352  if (WaitBlock->WaitFunction == NULL)
353  {
354  /* Remove it from the Wait Block Queue */
355  RemoveEntryList(&WaitBlock->WaitList);
356 
357  /* Insert the wait into the destination list */
358  InsertTailList(DestinationList, &WaitBlock->WaitList);
359  }
360  }
361 
362  /* Release the wait lock */
364 }
LIST_ENTRY WaitList
Definition: csrsrv.h:158
#define InsertTailList(ListHead, Entry)
#define CsrReleaseWaitLock()
Definition: api.h:24
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
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
Definition: typedefs.h:119
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
#define CsrAcquireWaitLock()
Definition: api.h:21
#define NULL
Definition: types.h:112

◆ CsrNotifyWait()

BOOLEAN NTAPI CsrNotifyWait ( IN PLIST_ENTRY  WaitList,
IN BOOLEAN  NotifyAll,
IN PVOID  WaitArgument1,
IN PVOID  WaitArgument2 
)

Definition at line 388 of file wait.c.

392 {
393  PLIST_ENTRY NextEntry;
394  PCSR_WAIT_BLOCK WaitBlock;
395  BOOLEAN NotifySuccess = FALSE;
396 
397  /* Acquire the Wait Lock */
399 
400  /* Set the List pointers */
401  NextEntry = WaitList->Flink;
402 
403  /* Start looping */
404  while (NextEntry != WaitList)
405  {
406  /* Get the Wait block */
407  WaitBlock = CONTAINING_RECORD(NextEntry, CSR_WAIT_BLOCK, WaitList);
408 
409  /* Go to the next entry */
410  NextEntry = NextEntry->Flink;
411 
412  /* Check if there is a Wait Routine */
413  if (WaitBlock->WaitFunction != NULL)
414  {
415  /* Notify the Waiter */
416  NotifySuccess |= CsrNotifyWaitBlock(WaitBlock,
417  WaitList,
418  WaitArgument1,
419  WaitArgument2,
420  0,
421  FALSE);
422 
423  /*
424  * We've already done a wait, so leave unless
425  * we want to notify all the waits...
426  */
427  if (!NotifyAll) break;
428  }
429  }
430 
431  /* Release the wait lock and return */
433  return NotifySuccess;
434 }
#define CsrReleaseWaitLock()
Definition: api.h:24
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
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
Definition: typedefs.h:119
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
#define CsrAcquireWaitLock()
Definition: api.h:21
#define NULL
Definition: types.h:112
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

Referenced by ConioUnpause(), ConSrvCloseHandle(), and PostprocessInput().

◆ CsrPopulateDosDevices()

VOID NTAPI CsrPopulateDosDevices ( VOID  )

Definition at line 1095 of file init.c.

1096 {
1097  DPRINT1("Deprecated API in r55585.\n");
1098  return;
1099 }
#define DPRINT1
Definition: precomp.h:8

◆ CsrQueryApiPort()

HANDLE NTAPI CsrQueryApiPort ( VOID  )

Definition at line 1093 of file api.c.

1094 {
1095  return CsrApiPort;
1096 }
HANDLE CsrApiPort
Definition: connect.c:21

Referenced by CSR_API(), and UserClientConnect().

◆ CsrReferenceThread()

VOID NTAPI CsrReferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 1042 of file thredsup.c.

1043 {
1044  /* Acquire process lock */
1046 
1047  /* Sanity checks */
1048  ASSERT((CsrThread->Flags & CsrThreadTerminated) == 0);
1049  ASSERT(CsrThread->ReferenceCount != 0);
1050 
1051  /* Increment reference count */
1052  CsrThread->ReferenceCount++;
1053 
1054  /* Release the lock */
1056 }
#define CsrReleaseProcessLock()
Definition: api.h:15
#define ASSERT(a)
Definition: mode.c:45
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by NotifyUserProcessForShutdown().

◆ 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
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:2018
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8

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

◆ CsrServerInitialization()

NTSTATUS NTAPI CsrServerInitialization ( IN ULONG  ArgumentCount,
IN PCHAR  Arguments[] 
)

Definition at line 971 of file init.c.

973 {
975 
976  /* Cache System Basic Information so we don't always request it */
978  &CsrNtSysInfo,
979  sizeof(SYSTEM_BASIC_INFORMATION),
980  NULL);
981  if (!NT_SUCCESS(Status))
982  {
983  DPRINT1("CSRSRV:%s: NtQuerySystemInformation failed (Status=0x%08lx)\n",
985  return Status;
986  }
987 
988  /* Save our Heap */
989  CsrHeap = RtlGetProcessHeap();
990 
991  /* Set our Security Descriptor to protect the process */
993  if (!NT_SUCCESS(Status))
994  {
995  DPRINT1("CSRSRV:%s: CsrSetProcessSecurity failed (Status=0x%08lx)\n",
997  return Status;
998  }
999 
1000  /* Set up Session Support */
1002  if (!NT_SUCCESS(Status))
1003  {
1004  DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=0x%08lx)\n",
1005  __FUNCTION__, Status);
1006  return Status;
1007  }
1008 
1009  /* Set up Process Support and allocate the CSR Root Process */
1011  if (!NT_SUCCESS(Status))
1012  {
1013  DPRINT1("CSRSRV:%s: CsrInitializeProcessStructure failed (Status=0x%08lx)\n",
1014  __FUNCTION__, Status);
1015  return Status;
1016  }
1017 
1018  /* Parse the command line */
1019  Status = CsrParseServerCommandLine(ArgumentCount, Arguments);
1020  if (!NT_SUCCESS(Status))
1021  {
1022  DPRINT1("CSRSRV:%s: CsrParseServerCommandLine failed (Status=0x%08lx)\n",
1023  __FUNCTION__, Status);
1024  return Status;
1025  }
1026 
1027  /* Finish to initialize the CSR Root Process */
1029  if (!NT_SUCCESS(Status))
1030  {
1031  DPRINT1("CSRSRV:%s: CsrInitCsrRootProcess failed (Status=0x%08lx)\n",
1032  __FUNCTION__, Status);
1033  return Status;
1034  }
1035 
1036  /* Now initialize our API Port */
1038  if (!NT_SUCCESS(Status))
1039  {
1040  DPRINT1("CSRSRV:%s: CsrApiPortInitialize failed (Status=0x%08lx)\n",
1041  __FUNCTION__, Status);
1042  return Status;
1043  }
1044 
1045  /* Initialize the API Port for SM communication */
1047  if (!NT_SUCCESS(Status))
1048  {
1049  DPRINT1("CSRSRV:%s: CsrSbApiPortInitialize failed (Status=0x%08lx)\n",
1050  __FUNCTION__, Status);
1051  return Status;
1052  }
1053 
1054  /* We're all set! Connect to SM! */
1056  CsrSbApiPort,
1058  &CsrSmApiPort);
1059  if (!NT_SUCCESS(Status))
1060  {
1061  DPRINT1("CSRSRV:%s: SmConnectToSm failed (Status=0x%08lx)\n",
1062  __FUNCTION__, Status);
1063  return Status;
1064  }
1065 
1066  /* Have us handle Hard Errors */
1068  if (!NT_SUCCESS(Status))
1069  {
1070  DPRINT1("CSRSRV:%s: NtSetDefaultHardErrorPort failed (Status=0x%08lx)\n",
1071  __FUNCTION__, Status);
1072  return Status;
1073  }
1074 
1075  /* Return status */
1076  return Status;
1077 }
NTSTATUS NTAPI CsrParseServerCommandLine(IN ULONG ArgumentCount, IN PCHAR Arguments[])
Definition: init.c:550
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
NTSTATUS NTAPI CsrInitializeProcessStructure(VOID)
Definition: procsup.c:254
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI CsrSetProcessSecurity(VOID)
Definition: init.c:62
NTSTATUS NTAPI NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
Definition: harderr.c:742
NTSTATUS NTAPI CsrSbApiPortInitialize(VOID)
Definition: init.c:875
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
Definition: init.c:40
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CsrInitCsrRootProcess(VOID)
Definition: init.c:729
HANDLE CsrSbApiPort
Definition: init.c:29
HANDLE CsrSmApiPort
Definition: init.c:31
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI SmConnectToSm(IN PUNICODE_STRING SbApiPortName, IN HANDLE SbApiPort, IN ULONG ImageType, OUT PHANDLE SmApiPort)
Definition: smclient.c:68
NTSTATUS NTAPI CsrApiPortInitialize(VOID)
Definition: api.c:896
NTSTATUS NTAPI CsrInitializeNtSessionList(VOID)
Definition: session.c:53
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __FUNCTION__
Definition: types.h:112
HANDLE CsrHeap
Definition: init.c:25
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
HANDLE CsrApiPort
Definition: init.c:33

Referenced by _main().

◆ 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:1107

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

◆ CsrSetCallingSpooler()

VOID NTAPI CsrSetCallingSpooler ( ULONG  Reserved)

Definition at line 599 of file server.c.

600 {
601  /* Deprecated */
602  return;
603 }

◆ 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:1107

Referenced by ConSrvSetProcessFocus().

◆ 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
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
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ListLink
Definition: csrsrv.h:39
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
Definition: typedefs.h:119
Definition: copy.c:32
PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
Definition: csrsrv.h:240
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 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:2062
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
#define STATUS_SUCCESS
Definition: shellext.h:65
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by UserExitReactOS().

◆ CsrUnhandledExceptionFilter()

EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter ( IN PEXCEPTION_POINTERS  ExceptionInfo)

Definition at line 622 of file server.c.

623 {
626  BOOLEAN OldValue;
628  UNICODE_STRING ErrorSource;
629  ULONG_PTR ErrorParameters[4];
630  ULONG Response;
631 
632  DPRINT1("CsrUnhandledExceptionFilter called\n");
633 
634  /* Check if a debugger is installed */
636  &DebuggerInfo,
637  sizeof(DebuggerInfo),
638  NULL);
639 
640  /* Check if this is Session 0, and the Debugger is Enabled */
641  if ((NtCurrentPeb()->SessionId != 0) && (NT_SUCCESS(Status)) &&
642  (DebuggerInfo.KernelDebuggerEnabled))
643  {
644  /* Call the Unhandled Exception Filter */
645  Result = RtlUnhandledExceptionFilter(ExceptionInfo);
647  {
648  /* We're going to raise an error. Get Shutdown Privilege first */
650  TRUE,
651  TRUE,
652  &OldValue);
653 
654  /* Use the Process token if that failed */
655  if (Status == STATUS_NO_TOKEN)
656  {
658  TRUE,
659  FALSE,
660  &OldValue);
661  }
662  if (!NT_SUCCESS(Status))
663  {
664  DPRINT1("CsrUnhandledExceptionFilter(): RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE) failed, Status = 0x%08lx\n", Status);
665  goto NoPrivilege;
666  }
667 
668  /* Initialize our Name String */
669  RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
670 
671  /* Set the parameters */
672  ErrorParameters[0] = (ULONG_PTR)&ErrorSource;
673  ErrorParameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
674  ErrorParameters[2] = (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress;
675  ErrorParameters[3] = (ULONG_PTR)ExceptionInfo->ContextRecord;
676 
677  /* Bugcheck */
679  4,
680  1,
681  ErrorParameters,
683  &Response);
684  }
685 
686 NoPrivilege:
687  /* Just terminate us */
689  ExceptionInfo->ExceptionRecord->ExceptionCode);
690  }
691 
692  return Result;
693 }
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
NTSTATUS NTAPI NtRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:553
#define TRUE
Definition: types.h:120
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
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
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
Definition: ncftp.h:89
static const WCHAR L[]
Definition: oid.c:1250
LONG NTAPI RtlUnhandledExceptionFilter(IN struct _EXCEPTION_POINTERS *ExceptionInfo)
Definition: exception.c:306
#define NtCurrentPeb()
Definition: FLS.c:20
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
enum _EXCEPTION_DISPOSITION EXCEPTION_DISPOSITION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct Response Response
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SYSTEM_PROCESS_TERMINATED
Definition: ntstatus.h:670
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87

Referenced by CsrApiRequestThread(), and CsrLoadServerDll().

◆ 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
#define STATUS_SUCCESS
Definition: shellext.h:65

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

◆ CsrUnlockThread()

NTSTATUS NTAPI CsrUnlockThread ( IN PCSR_THREAD  CsrThread)

Definition at line 1074 of file thredsup.c.

1075 {
1076  /* Dereference the Thread */
1078  CsrLockedDereferenceThread(CsrThread);
1079 
1080  /* Release the lock and return */
1082  return STATUS_SUCCESS;
1083 }
#define CsrReleaseProcessLock()
Definition: api.h:15
#define ProcessStructureListLocked()
Definition: api.h:18
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by GetThreadConsoleDesktop().

◆ CsrValidateMessageBuffer()

BOOLEAN NTAPI CsrValidateMessageBuffer ( IN PCSR_API_MESSAGE  ApiMessage,
IN PVOID Buffer,
IN ULONG  ElementCount,
IN ULONG  ElementSize 
)

Definition at line 1426 of file api.c.

1430 {
1431  PCSR_CAPTURE_BUFFER CaptureBuffer = ApiMessage->CsrCaptureData;
1432  SIZE_T BufferDistance = (ULONG_PTR)Buffer - (ULONG_PTR)ApiMessage;
1433  ULONG PointerCount;
1434  PULONG_PTR OffsetPointer;
1435 
1436  /*
1437  * Check whether we have a valid buffer pointer, elements
1438  * of non-trivial size and that we don't overflow.
1439  */
1440  if (!Buffer || ElementSize == 0 ||
1441  (ULONGLONG)ElementCount * ElementSize > (ULONGLONG)MAXULONG)
1442  {
1443  return FALSE;
1444  }
1445 
1446  /* Check if didn't get a buffer and there aren't any arguments to check */
1447  // if (!*Buffer && (ElementCount * ElementSize == 0))
1448  if (!*Buffer && ElementCount == 0) // Here ElementSize != 0 therefore only ElementCount can be == 0
1449  return TRUE;
1450 
1451  /* Check if we have no capture buffer */
1452  if (!CaptureBuffer)
1453  {
1454  /* In this case, succeed only if the caller is CSRSS */
1455  if (NtCurrentTeb()->ClientId.UniqueProcess ==
1456  ApiMessage->Header.ClientId.UniqueProcess)
1457  {
1458  return TRUE;
1459  }
1460  }
1461  else
1462  {
1463  /* Make sure that there is still space left in the capture buffer */
1464  if ((CaptureBuffer->Size - (ULONG_PTR)*Buffer + (ULONG_PTR)CaptureBuffer) >=
1465  (ElementCount * ElementSize))
1466  {
1467  /* Perform the validation test */
1468  PointerCount = CaptureBuffer->PointerCount;
1469  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
1470  while (PointerCount--)
1471  {
1472  /*
1473  * Find in the array, the pointer offset (from the
1474  * API message) that corresponds to the buffer.
1475  */
1476  if (*OffsetPointer == BufferDistance)
1477  {
1478  return TRUE;
1479  }
1480  ++OffsetPointer;
1481  }
1482  }
1483  }
1484 
1485  /* Failure */
1486 #ifdef CSR_DBG
1487  DPRINT1("CSRSRV: Bad message buffer %p\n", ApiMessage);
1488  if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1489 #endif
1490  return FALSE;
1491 }
#define TRUE
Definition: types.h:120
void DbgBreakPoint()
Definition: mach.c:553
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
uint64_t ULONGLONG
Definition: typedefs.h:67
#define MAXULONG
Definition: typedefs.h:251
ULONG_PTR SIZE_T
Definition: typedefs.h:80
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define NtCurrentPeb()
Definition: FLS.c:20
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:65

Referenced by CON_API(), CON_API_NOCONSOLE(), CSR_API(), and CsrValidateMessageString().

◆ CsrValidateMessageString()

BOOLEAN NTAPI CsrValidateMessageString ( IN PCSR_API_MESSAGE  ApiMessage,
IN PWSTR MessageString 
)

Definition at line 1513 of file api.c.

1515 {
1516  if (MessageString)
1517  {
1518  return CsrValidateMessageBuffer(ApiMessage,
1519  (PVOID*)MessageString,
1520  wcslen(*MessageString) + 1,
1521  sizeof(WCHAR));
1522  }
1523  else
1524  {
1525  return FALSE;
1526  }
1527 }
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1426
__wchar_t WCHAR
Definition: xmlstorage.h:180
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)