ReactOS  0.4.15-dev-2361-g32428a3
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 512 of file thredsup.c.

515 {
516  PCSR_THREAD CsrThread;
517 
518  /* Get the Lock */
520 
521  /* Allocate the Server Thread */
522  CsrThread = CsrAllocateThread(CsrRootProcess);
523  if (CsrThread)
524  {
525  /* Setup the Object */
526  CsrThread->ThreadHandle = hThread;
528  CsrThread->ClientId = *ClientId;
529  CsrThread->Flags = ThreadFlags;
530 
531  /* Insert it into the Thread List */
533 
534  /* Increment the thread count */
536  }
537  else
538  {
539  DPRINT1("CsrAddStaticServerThread: alloc failed for thread 0x%x\n", hThread);
540  }
541 
542  /* Release the Process Lock and return */
544  return CsrThread;
545 }
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:28
#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 422 of file procsup.c.

428 {
429  PCSR_THREAD CurrentThread = CsrGetClientThread();
430  CLIENT_ID CurrentCid;
432  PCSR_SERVER_DLL ServerDll;
433  PVOID ProcessData;
434  ULONG i;
437  PCSR_THREAD CsrThread;
438  KERNEL_USER_TIMES KernelTimes;
439 
440  /* Get the current CID and lock Processes */
441  CurrentCid = CurrentThread->ClientId;
443 
444  /* Get the current CSR Thread */
445  CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
446  if (!CurrentThread)
447  {
448  /* We've failed to locate the thread */
451  }
452 
453  /* Allocate a new Process Object */
455  if (!CsrProcess)
456  {
457  /* Couldn't allocate Process */
459  return STATUS_NO_MEMORY;
460  }
461 
462  /* Inherit the Process Data */
463  CurrentProcess = CurrentThread->Process;
464  ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
465  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
466  {
467  /* Get the current Server */
468  ServerDll = CsrLoadedServerDll[i];
469 
470  /* Check if the DLL is Loaded and has Per Process Data */
471  if (ServerDll && ServerDll->SizeOfProcessData)
472  {
473  /* Set the pointer */
474  CsrProcess->ServerData[i] = ProcessData;
475 
476  /* Copy the Data */
477  RtlMoveMemory(ProcessData,
478  CurrentProcess->ServerData[i],
479  ServerDll->SizeOfProcessData);
480 
481  /* Update next data pointer */
482  ProcessData = (PVOID)((ULONG_PTR)ProcessData +
483  ServerDll->SizeOfProcessData);
484  }
485  else
486  {
487  /* No data for this Server */
488  CsrProcess->ServerData[i] = NULL;
489  }
490  }
491 
492  /* Set the Exception Port for us */
495  &CsrApiPort,
496  sizeof(CsrApiPort));
497  if (!NT_SUCCESS(Status))
498  {
499  /* Failed */
502  return STATUS_NO_MEMORY;
503  }
504 
505  /* Check if CreateProcess got CREATE_NEW_PROCESS_GROUP */
507  {
508  /*
509  * We create the process group leader of a new process group, therefore
510  * its process group ID and sequence number are its own ones.
511  */
512  CsrProcess->ProcessGroupId = HandleToUlong(ClientId->UniqueProcess);
513  CsrProcess->ProcessGroupSequence = CsrProcess->SequenceNumber;
514  }
515  else
516  {
517  /* Inherit the process group ID and sequence number from the current process */
518  CsrProcess->ProcessGroupId = CurrentProcess->ProcessGroupId;
519  CsrProcess->ProcessGroupSequence = CurrentProcess->ProcessGroupSequence;
520  }
521 
522  /* Check if this is a console process */
524 
525  /* Mask out non-debug flags */
527 
528  /* Check if every process will be debugged */
529  if (!(Flags) && (CurrentProcess->DebugFlags & CsrDebugProcessChildren))
530  {
531  /* Pass it on to the current process */
532  CsrProcess->DebugFlags = CsrDebugProcessChildren;
533  CsrProcess->DebugCid = CurrentProcess->DebugCid;
534  }
535 
536  /* Check if Debugging was used on this process */
537  if ((Flags & (CsrDebugOnlyThisProcess | CsrDebugProcessChildren)) && (DebugCid))
538  {
539  /* Save the debug flag used */
540  CsrProcess->DebugFlags = Flags;
541 
542  /* Save the CID */
543  CsrProcess->DebugCid = *DebugCid;
544  }
545 
546  /* Check if Debugging is enabled */
547  if (CsrProcess->DebugFlags)
548  {
549  /* Set the Debug Port for us */
552  &CsrApiPort,
553  sizeof(CsrApiPort));
555  if (!NT_SUCCESS(Status))
556  {
557  /* Failed */
560  return STATUS_NO_MEMORY;
561  }
562  }
563 
564  /* Get the Thread Create Time */
566  ThreadTimes,
567  &KernelTimes,
568  sizeof(KernelTimes),
569  NULL);
570  if (!NT_SUCCESS(Status))
571  {
572  /* Failed */
575  return STATUS_NO_MEMORY;
576  }
577 
578  /* Allocate a CSR Thread Structure */
579  CsrThread = CsrAllocateThread(CsrProcess);
580  if (!CsrThread)
581  {
582  /* Failed */
585  return STATUS_NO_MEMORY;
586  }
587 
588  /* Save the data we have */
589  CsrThread->CreateTime = KernelTimes.CreateTime;
590  CsrThread->ClientId = *ClientId;
591  CsrThread->ThreadHandle = hThread;
593  CsrThread->Flags = 0;
594 
595  /* Insert the Thread into the Process */
596  Status = CsrInsertThread(CsrProcess, CsrThread);
597  if (!NT_SUCCESS(Status))
598  {
599  /* Bail out */
601  CsrDeallocateThread(CsrThread);
603  return Status;
604  }
605 
606  /* Reference the session */
607  CsrReferenceNtSession(NtSession);
608  CsrProcess->NtSession = NtSession;
609 
610  /* Setup Process Data */
611  CsrProcess->ClientId = *ClientId;
612  CsrProcess->ProcessHandle = hProcess;
613  CsrProcess->ShutdownLevel = 0x280;
614 
615  /* Set the Priority to Background */
617 
618  /* Insert the Process */
620 
621  /* Release lock and return */
623  return Status;
624 }
#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:297
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:1107
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:189
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:28
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:366
#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 569 of file thredsup.c.

571 {
573  HANDLE ThreadHandle;
574  PCSR_THREAD CsrThread;
576  KERNEL_USER_TIMES KernelTimes;
577 
578  /* Get the Thread Create Time */
580  ThreadTimes,
581  &KernelTimes,
582  sizeof(KernelTimes),
583  NULL);
584  if (!NT_SUCCESS(Status))
585  {
586  DPRINT1("Failed to query thread times: %lx\n", Status);
587  return Status;
588  }
589 
590  /* Lock the Owner Process */
592  if (!NT_SUCCESS(Status))
593  {
594  DPRINT1("No known process for %lx\n", ClientId->UniqueProcess);
595  return Status;
596  }
597 
598  /* Make sure the thread didn't terminate */
599  if (KernelTimes.ExitTime.QuadPart)
600  {
601  /* Unlock the process and return */
603  DPRINT1("Dead thread: %I64x\n", KernelTimes.ExitTime.QuadPart);
605  }
606 
607  /* Allocate a CSR Thread Structure */
608  CsrThread = CsrAllocateThread(CsrProcess);
609  if (!CsrThread)
610  {
611  DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
613  return STATUS_NO_MEMORY;
614  }
615 
616  /* Duplicate the Thread Handle */
618  hThread,
620  &ThreadHandle,
621  0,
622  0,
624  /* Allow failure */
625  if (!NT_SUCCESS(Status))
626  {
627  DPRINT1("Thread duplication failed: %lx\n", Status);
628  ThreadHandle = hThread;
629  }
630 
631  /* Save the data we have */
632  CsrThread->CreateTime = KernelTimes.CreateTime;
633  CsrThread->ClientId = *ClientId;
634  CsrThread->ThreadHandle = ThreadHandle;
635  ProtectHandle(ThreadHandle);
636  CsrThread->Flags = 0;
637 
638  /* Insert the Thread into the Process */
639  Status = CsrInsertThread(CsrProcess, CsrThread);
640  if (!NT_SUCCESS(Status))
641  {
642  /* Bail out */
643  if (CsrThread->ThreadHandle != hThread) NtClose(CsrThread->ThreadHandle);
645  CsrDeallocateThread(CsrThread);
646  return Status;
647  }
648 
649  /* Release the lock and return */
651  return STATUS_SUCCESS;
652 }
#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:28
#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:1410
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 678 of file thredsup.c.

682 {
684  PCSR_THREAD CsrThread, CurrentThread;
686  CLIENT_ID CurrentCid;
687  KERNEL_USER_TIMES KernelTimes;
688 
689  if (HaveClient)
690  {
691  /* Get the current thread and CID */
692  CurrentThread = CsrGetClientThread();
693  CurrentCid = CurrentThread->ClientId;
694 
695  /* Acquire the Process Lock */
697 
698  /* Get the current Process and make sure the Thread is valid with this CID */
699  CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
700 
701  /* Something is wrong if we get an empty thread back */
702  if (!CurrentThread)
703  {
704  DPRINT1("CSRSRV: %s: invalid thread!\n", __FUNCTION__);
707  }
708  }
709  else
710  {
711  /* Acquire the Process Lock */
713  }
714 
715  /* Get the Thread Create Time */
717  ThreadTimes,
718  &KernelTimes,
719  sizeof(KernelTimes),
720  NULL);
721  if (!NT_SUCCESS(Status))
722  {
724  return Status;
725  }
726 
727  /* Allocate a CSR Thread Structure */
728  CsrThread = CsrAllocateThread(CsrProcess);
729  if (!CsrThread)
730  {
731  DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
733  return STATUS_NO_MEMORY;
734  }
735 
736  /* Save the data we have */
737  CsrThread->CreateTime = KernelTimes.CreateTime;
738  CsrThread->ClientId = *ClientId;
739  CsrThread->ThreadHandle = hThread;
741  CsrThread->Flags = 0;
742 
743  /* Insert the Thread into the Process */
744  Status = CsrInsertThread(CsrProcess, CsrThread);
745  if (!NT_SUCCESS(Status))
746  {
747  /* Bail out */
749  CsrDeallocateThread(CsrThread);
750  return Status;
751  }
752 
753  /* Release the lock and return */
755 
756  return STATUS_SUCCESS;
757 }
#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:28
#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:1410
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 643 of file procsup.c.

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

◆ CsrDebugProcessStop()

NTSTATUS NTAPI CsrDebugProcessStop ( IN PCSR_PROCESS  CsrProcess)

Definition at line 667 of file procsup.c.

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

◆ CsrDereferenceProcess()

VOID NTAPI CsrDereferenceProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 691 of file procsup.c.

692 {
693  LONG LockCount;
694 
695  /* Acquire process lock */
697 
698  /* Decrease reference count */
699  LockCount = --CsrProcess->ReferenceCount;
700  ASSERT(LockCount >= 0);
701  if (LockCount == 0)
702  {
703  /* Call the generic cleanup code */
705  }
706  else
707  {
708  /* Just release the lock */
710  }
711 }
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 776 of file thredsup.c.

777 {
778  /* Acquire process lock */
780 
781  /* Decrease reference count */
782  ASSERT(CsrThread->ReferenceCount > 0);
783  if ((--CsrThread->ReferenceCount) == 0)
784  {
785  /* Call the generic cleanup code */
786  CsrThreadRefcountZero(CsrThread);
787  }
788  else
789  {
790  /* Just release the lock */
792  }
793 }
#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:776
#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 735 of file procsup.c.

737 {
738  PCSR_THREAD CsrThread;
740  CLIENT_ID ClientId = *Cid;
741  PLIST_ENTRY NextEntry;
742 
743  /* Acquire lock */
745 
746  /* Find the thread */
748 
749  /* Make sure we got one back, and that it's not already gone */
750  if (!(CsrThread) || (CsrProcess->Flags & CsrProcessTerminating))
751  {
752  /* Release the lock and return failure */
755  }
756 
757  /* Set the terminated flag */
759 
760  /* Get the List Pointers */
761  NextEntry = CsrProcess->ThreadList.Flink;
762  while (NextEntry != &CsrProcess->ThreadList)
763  {
764  /* Get the current thread entry */
765  CsrThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
766 
767  /* Move to the next entry */
768  NextEntry = NextEntry->Flink;
769 
770  /* Make sure the thread isn't already dead */
771  if (CsrThread->Flags & CsrThreadTerminated)
772  {
773  /* Go the the next thread */
774  continue;
775  }
776 
777  /* Set the Terminated flag */
778  CsrThread->Flags |= CsrThreadTerminated;
779 
780  /* Acquire the Wait Lock */
782 
783  /* Do we have an active wait block? */
784  if (CsrThread->WaitBlock)
785  {
786  /* Notify waiters of termination */
787  CsrNotifyWaitBlock(CsrThread->WaitBlock,
788  NULL,
789  NULL,
790  NULL,
792  TRUE);
793  }
794 
795  /* Release the Wait Lock */
797 
798  /* Dereference the thread */
799  CsrLockedDereferenceThread(CsrThread);
800  }
801 
802  /* Release the Process Lock and return success */
804  return STATUS_SUCCESS;
805 }
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 814 of file thredsup.c.

815 {
816  CLIENT_ID ClientId = *Cid;
817  PCSR_THREAD CsrThread;
819 
820  /* Acquire lock */
822 
823  /* Find the thread */
825  &ClientId);
826 
827  /* Make sure we got one back, and that it's not already gone */
828  if (!CsrThread || (CsrThread->Flags & CsrThreadTerminated))
829  {
830  /* Release the lock and return failure */
833  }
834 
835  /* Set the terminated flag */
836  CsrThread->Flags |= CsrThreadTerminated;
837 
838  /* Acquire the Wait Lock */
840 
841  /* Do we have an active wait block? */
842  if (CsrThread->WaitBlock)
843  {
844  /* Notify waiters of termination */
845  CsrNotifyWaitBlock(CsrThread->WaitBlock,
846  NULL,
847  NULL,
848  NULL,
850  TRUE);
851  }
852 
853  /* Release the Wait Lock */
855 
856  /* Dereference the thread */
857  CsrLockedDereferenceThread(CsrThread);
858 
859  /* Release the Process Lock and return success */
861  return STATUS_SUCCESS;
862 }
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 886 of file thredsup.c.

888 {
889  PCSR_THREAD CsrThread;
890  HANDLE hThread;
893 
894  /* Acquire process lock */
896 
897  /* Allocate a CSR Thread in the Root Process */
899  CsrThread = CsrAllocateThread(CsrRootProcess);
900  if (!CsrThread)
901  {
902  /* Fail */
904  return STATUS_NO_MEMORY;
905  }
906 
907  /* Create the Thread */
909  NULL,
910  FALSE,
911  0,
912  0,
913  0,
914  ThreadHandler,
915  NULL,
916  &hThread,
917  &ClientId);
918  if (!NT_SUCCESS(Status))
919  {
920  /* Fail */
921  CsrDeallocateThread(CsrThread);
923  return Status;
924  }
925 
926  /* Setup the Thread Object */
927  CsrThread->ThreadHandle = hThread;
929  CsrThread->ClientId = ClientId;
930  CsrThread->Flags = Flags;
931 
932  /* Insert it into the Thread List */
934 
935  /* Increase the thread count */
937 
938  /* Return */
940  return Status;
941 }
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:28
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 828 of file procsup.c.

830 {
831  HANDLE hToken = NULL;
833  ULONG Length;
834  PTOKEN_STATISTICS TokenStats;
835 
836  /* Check if we have a handle to a CSR Process */
837  if (!hProcess)
838  {
839  /* We don't, so try opening the Thread's Token */
841  TOKEN_QUERY,
842  FALSE,
843  &hToken);
844 
845  /* Check for success */
846  if (!NT_SUCCESS(Status))
847  {
848  /* If we got some other failure, then return and quit */
849  if (Status != STATUS_NO_TOKEN) return Status;
850 
851  /* We don't have a Thread Token, use a Process Token */
853  hToken = NULL;
854  }
855  }
856 
857  /* Check if we have a token by now */
858  if (!hToken)
859  {
860  /* No token yet, so open the Process Token */
862  TOKEN_QUERY,
863  &hToken);
864  if (!NT_SUCCESS(Status))
865  {
866  /* Still no token, return the error */
867  return Status;
868  }
869  }
870 
871  /* Now get the size we'll need for the Token Information */
874  NULL,
875  0,
876  &Length);
878  {
879  /* Close the token and fail */
880  NtClose(hToken);
881  return Status;
882  }
883 
884  /* Allocate memory for the Token Info */
885  if (!(TokenStats = RtlAllocateHeap(CsrHeap, 0, Length)))
886  {
887  /* Fail and close the token */
888  NtClose(hToken);
889  return STATUS_NO_MEMORY;
890  }
891 
892  /* Now query the information */
895  TokenStats,
896  Length,
897  &Length);
898 
899  /* Close the handle */
900  NtClose(hToken);
901 
902  /* Check for success */
903  if (NT_SUCCESS(Status))
904  {
905  /* Return the LUID */
906  *Luid = TokenStats->AuthenticationId;
907  }
908 
909  /* Free the query information */
910  RtlFreeHeap(CsrHeap, 0, TokenStats);
911 
912  /* Return the Status */
913  return Status;
914 }
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:2164
#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:4183
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 932 of file procsup.c.

933 {
935  PCSR_THREAD CurrentThread = CsrGetClientThread();
936 
937  /* Use the current thread if none given */
938  if (!CsrThread) CsrThread = CurrentThread;
939 
940  /* Still no thread, something is wrong */
941  if (!CsrThread)
942  {
943  /* Failure */
944  return FALSE;
945  }
946 
947  /* Make the call */
949  CsrThread->ThreadHandle,
950  &CsrSecurityQos);
951 
952  if (!NT_SUCCESS(Status))
953  {
954  /* Failure */
955 #ifdef CSR_DBG
956  DPRINT1("CSRSS: Can't impersonate client thread - Status = %lx\n", Status);
957  // if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
958 #endif
959  return FALSE;
960  }
961 
962  /* Increase the impersonation count for the current thread */
963  if (CurrentThread) ++CurrentThread->ImpersonationCount;
964 
965  /* Return Success */
966  return TRUE;
967 }
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 965 of file thredsup.c.

967 {
968  PLIST_ENTRY NextEntry;
969  PCSR_THREAD CurrentThread = NULL;
971  ULONG i;
972 
973  /* Acquire the lock */
975 
976  /* Assume failure */
977  ASSERT(CsrThread != NULL);
978  *CsrThread = NULL;
979 
980  /* Convert to Hash */
981  i = CsrHashThread(Tid);
982 
983  /* Setup the List Pointers */
984  NextEntry = CsrThreadHashTable[i].Flink;
985 
986  /* Start Loop */
987  while (NextEntry != &CsrThreadHashTable[i])
988  {
989  /* Get the Thread */
990  CurrentThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
991 
992  /* Check for TID Match */
993  if ((CurrentThread->ClientId.UniqueThread == Tid) &&
994  (CurrentThread->Flags & CsrThreadTerminated) == 0)
995  {
996  /* Get out of here */
997  break;
998  }
999 
1000  /* Move to the next entry */
1001  NextEntry = NextEntry->Flink;
1002  }
1003 
1004  /* Nothing found if we got back to the list */
1005  if (NextEntry == &CsrThreadHashTable[i]) CurrentThread = NULL;
1006 
1007  /* Did the loop find something? */
1008  if (CurrentThread)
1009  {
1010  /* Reference the found thread */
1012  CsrLockedReferenceThread(CurrentThread);
1013  *CsrThread = CurrentThread;
1014  }
1015  else
1016  {
1017  /* Nothing found, release the lock */
1020  }
1021 
1022  /* Return the status */
1023  return Status;
1024 }
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 1043 of file thredsup.c.

1044 {
1045  /* Acquire process lock */
1047 
1048  /* Sanity checks */
1049  ASSERT((CsrThread->Flags & CsrThreadTerminated) == 0);
1050  ASSERT(CsrThread->ReferenceCount != 0);
1051 
1052  /* Increment reference count */
1053  CsrThread->ReferenceCount++;
1054 
1055  /* Release the lock */
1057 }
#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 1057 of file procsup.c.

1058 {
1059  NTSTATUS Status;
1060  PCSR_THREAD CurrentThread = CsrGetClientThread();
1061  HANDLE ImpersonationToken = NULL;
1062 
1063  /* Check if we have a Current Thread */
1064  if (CurrentThread)
1065  {
1066  /* Make sure impersonation is on */
1067  if (!CurrentThread->ImpersonationCount)
1068  {
1069  DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
1070  // DbgBreakPoint();
1071  return FALSE;
1072  }
1073  else if ((--CurrentThread->ImpersonationCount) > 0)
1074  {
1075  /* Success; impersonation count decreased but still not zero */
1076  return TRUE;
1077  }
1078  }
1079 
1080  /* Impersonation has been totally removed, revert to ourselves */
1083  &ImpersonationToken,
1084  sizeof(ImpersonationToken));
1085 
1086  /* Return TRUE or FALSE */
1087  return NT_SUCCESS(Status);
1088 }
#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:255
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 1107 of file procsup.c.

1108 {
1109  PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
1110 
1111  /* Set the Foreground bit off */
1112  ProcessPriority.Foreground = FALSE;
1113 
1114  /* Set the new priority */
1115  NtSetInformationProcess(CsrProcess->ProcessHandle,
1117  &ProcessPriority,
1118  sizeof(ProcessPriority));
1119 }
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 1138 of file procsup.c.

1139 {
1140  PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
1141 
1142  /* Set the Foreground bit on */
1143  ProcessPriority.Foreground = TRUE;
1144 
1145  /* Set the new priority */
1146  NtSetInformationProcess(CsrProcess->ProcessHandle,
1148  &ProcessPriority,
1149  sizeof(ProcessPriority));
1150 }
#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 1277 of file procsup.c.

1279 {
1280  PLIST_ENTRY NextEntry;
1282  NTSTATUS Status;
1283  BOOLEAN FirstTry;
1284  ULONG i;
1285  PCSR_SERVER_DLL ServerDll;
1286  ULONG Result = 0;
1287 
1288  /* Acquire process lock */
1290 
1291  /* Add shutdown flag */
1293 
1294  /* Get the list pointers */
1295  NextEntry = CsrRootProcess->ListLink.Flink;
1296  while (NextEntry != &CsrRootProcess->ListLink)
1297  {
1298  /* Get the Process */
1299  CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
1300 
1301  /* Move to the next entry */
1302  NextEntry = NextEntry->Flink;
1303 
1304  /* Remove the skip flag, set shutdown flags to 0 */
1306  CsrProcess->ShutdownFlags = 0;
1307  }
1308 
1309  /* Set shutdown Priority */
1311 
1312  /* Start looping */
1313  while (TRUE)
1314  {
1315  /* Find the next process to shutdown */
1316  CsrProcess = FindProcessForShutdown(CallerLuid);
1317  if (!CsrProcess) break;
1318 
1319  /* Increase reference to process */
1321 
1322  FirstTry = TRUE;
1323  while (TRUE)
1324  {
1325  /* Loop all the servers */
1326  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
1327  {
1328  /* Get the current server */
1329  ServerDll = CsrLoadedServerDll[i];
1330 
1331  /* Check if it's valid and if it has a Shutdown Process Callback */
1332  if (ServerDll && ServerDll->ShutdownProcessCallback)
1333  {
1334  /* Release the lock, make the callback, and acquire it back */
1337  Flags,
1338  FirstTry);
1340 
1341  /* Check the result */
1343  {
1344  /* The callback unlocked the process */
1345  break;
1346  }
1347  else if (Result == CsrShutdownCancelled)
1348  {
1349 #ifdef CSR_DBG
1350  /* Check if this was a forced shutdown */
1351  if (Flags & EWX_FORCE)
1352  {
1353  DPRINT1("Process %x cancelled forced shutdown (Dll = %d)\n",
1354  CsrProcess->ClientId.UniqueProcess, i);
1355  DbgBreakPoint();
1356  }
1357 #endif
1358 
1359  /* Shutdown was cancelled, unlock and exit */
1362  goto Quickie;
1363  }
1364  }
1365  }
1366 
1367  /* No matches during the first try, so loop again */
1369  {
1370  FirstTry = FALSE;
1371  continue;
1372  }
1373 
1374  /* Second try, break out */
1375  break;
1376  }
1377 
1378  /* We've reached the final loop here, so dereference */
1379  if (i == CSR_SERVER_DLL_MAX)
1381  }
1382 
1383  /* Success path */
1386 
1387 Quickie:
1388  /* Return to normal priority */
1390 
1391  return Status;
1392 }
#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:233
#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:1168
#define CsrAcquireProcessLock()
Definition: api.h:12
Definition: typedefs.h:119
Definition: copy.c:25
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 1410 of file procsup.c.

1411 {
1412  /* Dereference the process */
1414 
1415  /* Release the lock and return */
1417  return STATUS_SUCCESS;
1418 }
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 1075 of file thredsup.c.

1076 {
1077  /* Dereference the Thread */
1079  CsrLockedDereferenceThread(CsrThread);
1080 
1081  /* Release the lock and return */
1083  return STATUS_SUCCESS;
1084 }
#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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)