ReactOS  0.4.14-dev-52-g6116262
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 LPWSTR *MessageString)
 

Macro Definition Documentation

◆ CSR_API

#define CSR_API (   n)
Value:
#define IN
Definition: typedefs.h:38
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:39
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:1176
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  DPRINT1("API: %d\n", ApiId);
82 #ifdef CSR_DBG
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 #endif
90  // DbgBreakPoint();
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
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
_SEH2_TRY
Definition: create.c:4250
#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:4424
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
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
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:397
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 1003 of file api.c.

1004 {
1005  NTSTATUS Status;
1006  ANSI_STRING DllName;
1007  UNICODE_STRING TempName;
1008  HANDLE hUser32;
1009  STRING StartupName;
1010  PTEB Teb = NtCurrentTeb();
1011  PCSR_THREAD CsrThread;
1012  BOOLEAN Connected;
1013 
1014  /* Check if we didn't already find it */
1015  if (!CsrClientThreadSetup)
1016  {
1017  /* Get the DLL Handle for user32.dll */
1018  RtlInitAnsiString(&DllName, "user32");
1019  RtlAnsiStringToUnicodeString(&TempName, &DllName, TRUE);
1021  NULL,
1022  &TempName,
1023  &hUser32);
1024  RtlFreeUnicodeString(&TempName);
1025 
1026  /* If we got the handle, get the Client Thread Startup Entrypoint */
1027  if (NT_SUCCESS(Status))
1028  {
1029  RtlInitAnsiString(&StartupName,"ClientThreadSetup");
1030  Status = LdrGetProcedureAddress(hUser32,
1031  &StartupName,
1032  0,
1034  }
1035  }
1036 
1037  /* Connect to user32 */
1038  _SEH2_TRY
1039  {
1040  Connected = CsrClientThreadSetup();
1041  }
1043  {
1044  Connected = FALSE;
1045  } _SEH2_END;
1046 
1047  if (!Connected)
1048  {
1049  DPRINT1("CSRSS: CsrConnectToUser failed\n");
1050  return NULL;
1051  }
1052 
1053  /* Save pointer to this thread in TEB */
1055  CsrThread = CsrLocateThreadInProcess(NULL, &Teb->ClientId);
1057  if (CsrThread) Teb->CsrClientThread = CsrThread;
1058 
1059  /* Return it */
1060  return CsrThread;
1061 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI LdrGetDllHandle(IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle)
Definition: ldrapi.c:805
PVOID CsrClientThread
Definition: compat.h:494
BOOLEAN(* CsrClientThreadSetup)(VOID)
Definition: api.c:21
LONG NTSTATUS
Definition: precomp.h:26
#define CsrReleaseProcessLock()
Definition: api.h:15
_SEH2_TRY
Definition: create.c:4250
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
CLIENT_ID ClientId
Definition: compat.h:488
#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
smooth NULL
Definition: ftsmooth.c:416
#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
Status
Definition: gdiplustypes.h:24
Definition: compat.h:484
_SEH2_END
Definition: create.c:4424
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#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;
434  PCSR_PROCESS CsrProcess;
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 */
453  CsrProcess = CsrAllocateProcess();
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 */
499  CsrDeallocateProcess(CsrProcess);
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  */
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 */
557  CsrDeallocateProcess(CsrProcess);
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 */
572  CsrDeallocateProcess(CsrProcess);
574  return STATUS_NO_MEMORY;
575  }
576 
577  /* Allocate a CSR Thread Structure */
578  CsrThread = CsrAllocateThread(CsrProcess);
579  if (!CsrThread)
580  {
581  /* Failed */
582  CsrDeallocateProcess(CsrProcess);
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 */
599  CsrDeallocateProcess(CsrProcess);
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 */
615  CsrSetBackgroundPriority(CsrProcess);
616 
617  /* Insert the Process */
618  CsrInsertProcess(CurrentProcess, CsrProcess);
619 
620  /* Release lock and return */
622  return Status;
623 }
ULONG DebugFlags
Definition: csrsrv.h:49
#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:297
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:79
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
HANDLE UniqueProcess
Definition: compat.h:474
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:63
PCSR_PROCESS Process
Definition: csrsrv.h:69
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
CLIENT_ID DebugCid
Definition: csrsrv.h:50
HANDLE ProcessHandle
Definition: csrsrv.h:46
smooth NULL
Definition: ftsmooth.c:416
CLIENT_ID ClientId
Definition: csrsrv.h:38
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
void * PVOID
Definition: retypes.h:9
ULONG CurrentProcess
Definition: shell.c:125
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PVOID ServerData[ANYSIZE_ARRAY]
Definition: csrsrv.h:60
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
ULONG SequenceNumber
Definition: csrsrv.h:47
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
ULONG ProcessGroupSequence
Definition: csrsrv.h:53
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:2497
HANDLE ThreadHandle
Definition: csrsrv.h:71
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1098
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
PCSR_NT_SESSION NtSession
Definition: csrsrv.h:41
Status
Definition: gdiplustypes.h:24
HANDLE CsrApiPort
Definition: connect.c:21
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG ProcessGroupId
Definition: csrsrv.h:52
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:48
ULONG Flags
Definition: csrsrv.h:72
VOID NTAPI CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:365
ULONG ShutdownLevel
Definition: csrsrv.h:58
#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;
574  PCSR_PROCESS CsrProcess;
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 */
601  CsrUnlockProcess(CsrProcess);
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__);
611  CsrUnlockProcess(CsrProcess);
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);
643  CsrUnlockProcess(CsrProcess);
644  CsrDeallocateThread(CsrThread);
645  return Status;
646  }
647 
648  /* Release the lock and return */
649  CsrUnlockProcess(CsrProcess);
650  return STATUS_SUCCESS;
651 }
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
LONG NTSTATUS
Definition: precomp.h:26
HANDLE UniqueProcess
Definition: compat.h:474
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
#define DUPLICATE_SAME_ACCESS
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
#define NtCurrentProcess()
Definition: nt_native.h:1657
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
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:2497
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
HANDLE ThreadHandle
Definition: csrsrv.h:71
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define __FUNCTION__
Definition: types.h:112
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1398
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:112

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 */
747  CsrUnlockProcess(CsrProcess);
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:297
LONG NTSTATUS
Definition: precomp.h:26
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
smooth NULL
Definition: ftsmooth.c:416
ULONG CurrentProcess
Definition: shell.c:125
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
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:2497
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define __FUNCTION__
Definition: types.h:112
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1398
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
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 }
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 }
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 */
703  CsrProcessRefcountZero(CsrProcess);
704  }
705  else
706  {
707  /* Just release the lock */
709  }
710 }
#define CsrReleaseProcessLock()
Definition: api.h:15
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

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

◆ 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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define CsrAcquireProcessLock()
Definition: api.h:12
Definition: typedefs.h:117
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
#define CsrAcquireWaitLock()
Definition: api.h:21
HANDLE CsrHeap
Definition: init.c:25

Referenced by ConioProcessInputEvent(), ConioUnpause(), ConSrvCloseHandle(), ConSrvCloseHandleEntry(), 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;
738  PCSR_PROCESS CsrProcess;
739  CLIENT_ID ClientId = *Cid;
740  PLIST_ENTRY NextEntry;
741 
742  /* Acquire lock */
744 
745  /* Find the thread */
746  CsrThread = CsrLocateThreadByClientId(&CsrProcess, &ClientId);
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 */
757  CsrProcess->Flags |= CsrProcessTerminating;
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 }
#define TRUE
Definition: types.h:120
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 STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
#define CsrReleaseWaitLock()
Definition: api.h:24
#define CsrReleaseProcessLock()
Definition: api.h:15
static int Link(const char **args)
Definition: vfdcmd.c:2414
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define CsrAcquireProcessLock()
Definition: api.h:12
Definition: typedefs.h:117
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
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
ULONG Flags
Definition: csrsrv.h:48
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:2966

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;
817  PCSR_PROCESS CsrProcess;
818 
819  /* Acquire lock */
821 
822  /* Find the thread */
823  CsrThread = CsrLocateThreadByClientId(&CsrProcess,
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 }
#define TRUE
Definition: types.h:120
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 STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
#define CsrReleaseWaitLock()
Definition: api.h:24
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
smooth NULL
Definition: ftsmooth.c:416
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define CsrAcquireProcessLock()
Definition: api.h:12
#define CsrAcquireWaitLock()
Definition: api.h:21
struct _CSR_WAIT_BLOCK * WaitBlock
Definition: csrsrv.h:70
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:2966

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
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
ULONG ThreadCount
Definition: csrsrv.h:55
#define NtCurrentProcess()
Definition: nt_native.h:1657
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE ThreadHandle
Definition: csrsrv.h:71
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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)
Status
Definition: gdiplustypes.h:24
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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);
876 
877  /* Allocate memory for the Token Info */
878  if (!(TokenStats = RtlAllocateHeap(CsrHeap, 0, Length)))
879  {
880  /* Fail and close the token */
881  NtClose(hToken);
882  return STATUS_NO_MEMORY;
883  }
884 
885  /* Now query the information */
888  TokenStats,
889  Length,
890  &Length);
891 
892  /* Close the handle */
893  NtClose(hToken);
894 
895  /* Check for success */
896  if (NT_SUCCESS(Status))
897  {
898  /* Return the LUID */
899  *Luid = TokenStats->AuthenticationId;
900  }
901 
902  /* Free the query information */
903  RtlFreeHeap(CsrHeap, 0, TokenStats);
904 
905  /* Return the Status */
906  return Status;
907 }
LUID AuthenticationId
Definition: setypes.h:1033
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define NtCurrentThread()
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
NTSTATUS NTAPI NtOpenProcessToken(IN HANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
Definition: security.c:350
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Definition: token.c:1839
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_NO_TOKEN
Definition: ntstatus.h:346
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSTATUS NTAPI NtOpenThreadToken(IN HANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN BOOLEAN OpenAsSelf, OUT PHANDLE TokenHandle)
Definition: token.c:3858
unsigned int ULONG
Definition: retypes.h:1
HANDLE CsrHeap
Definition: init.c:25

Referenced by FindProcessForShutdown(), and UserExitReactOS().

◆ CsrImpersonateClient()

BOOLEAN NTAPI CsrImpersonateClient ( IN PCSR_THREAD  CsrThread)

Definition at line 925 of file procsup.c.

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

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

◆ CsrLockProcessByClientId()

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

◆ 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
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
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
CLIENT_ID ClientId
Definition: csrsrv.h:68
#define CsrHashThread(t)
Definition: thredsup.c:17
HANDLE UniqueThread
Definition: compat.h:475
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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:117
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:2966

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
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
#define CsrAcquireWaitLock()
Definition: api.h:21

◆ 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
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
#define CsrAcquireWaitLock()
Definition: api.h:21
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 ConioProcessInputEvent(), ConioUnpause(), ConSrvCloseHandle(), ConSrvCloseHandleEntry(), and PostprocessInput().

◆ CsrPopulateDosDevices()

VOID NTAPI CsrPopulateDosDevices ( VOID  )

Definition at line 1089 of file init.c.

1090 {
1091  DPRINT1("Deprecated API in r55585.\n");
1092  return;
1093 }
#define DPRINT1
Definition: precomp.h:8

◆ CsrQueryApiPort()

HANDLE NTAPI CsrQueryApiPort ( VOID  )

Definition at line 1078 of file api.c.

1079 {
1080  return CsrApiPort;
1081 }
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by NotifyUserProcessForShutdown().

◆ CsrRevertToSelf()

BOOLEAN NTAPI CsrRevertToSelf ( VOID  )

Definition at line 1048 of file procsup.c.

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

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

◆ CsrServerInitialization()

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

Definition at line 965 of file init.c.

967 {
969 
970  /* Cache System Basic Information so we don't always request it */
972  &CsrNtSysInfo,
973  sizeof(SYSTEM_BASIC_INFORMATION),
974  NULL);
975  if (!NT_SUCCESS(Status))
976  {
977  DPRINT1("CSRSRV:%s: NtQuerySystemInformation failed (Status=0x%08lx)\n",
979  return Status;
980  }
981 
982  /* Save our Heap */
983  CsrHeap = RtlGetProcessHeap();
984 
985  /* Set our Security Descriptor to protect the process */
987  if (!NT_SUCCESS(Status))
988  {
989  DPRINT1("CSRSRV:%s: CsrSetProcessSecurity failed (Status=0x%08lx)\n",
991  return Status;
992  }
993 
994  /* Set up Session Support */
996  if (!NT_SUCCESS(Status))
997  {
998  DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=0x%08lx)\n",
1000  return Status;
1001  }
1002 
1003  /* Set up Process Support and allocate the CSR Root Process */
1005  if (!NT_SUCCESS(Status))
1006  {
1007  DPRINT1("CSRSRV:%s: CsrInitializeProcessStructure failed (Status=0x%08lx)\n",
1008  __FUNCTION__, Status);
1009  return Status;
1010  }
1011 
1012  /* Parse the command line */
1013  Status = CsrParseServerCommandLine(ArgumentCount, Arguments);
1014  if (!NT_SUCCESS(Status))
1015  {
1016  DPRINT1("CSRSRV:%s: CsrParseServerCommandLine failed (Status=0x%08lx)\n",
1017  __FUNCTION__, Status);
1018  return Status;
1019  }
1020 
1021  /* Finish to initialize the CSR Root Process */
1023  if (!NT_SUCCESS(Status))
1024  {
1025  DPRINT1("CSRSRV:%s: CsrInitCsrRootProcess failed (Status=0x%08lx)\n",
1026  __FUNCTION__, Status);
1027  return Status;
1028  }
1029 
1030  /* Now initialize our API Port */
1032  if (!NT_SUCCESS(Status))
1033  {
1034  DPRINT1("CSRSRV:%s: CsrApiPortInitialize failed (Status=0x%08lx)\n",
1035  __FUNCTION__, Status);
1036  return Status;
1037  }
1038 
1039  /* Initialize the API Port for SM communication */
1041  if (!NT_SUCCESS(Status))
1042  {
1043  DPRINT1("CSRSRV:%s: CsrSbApiPortInitialize failed (Status=0x%08lx)\n",
1044  __FUNCTION__, Status);
1045  return Status;
1046  }
1047 
1048  /* We're all set! Connect to SM! */
1050  CsrSbApiPort,
1052  &CsrSmApiPort);
1053  if (!NT_SUCCESS(Status))
1054  {
1055  DPRINT1("CSRSRV:%s: SmConnectToSm failed (Status=0x%08lx)\n",
1056  __FUNCTION__, Status);
1057  return Status;
1058  }
1059 
1060  /* Have us handle Hard Errors */
1062  if (!NT_SUCCESS(Status))
1063  {
1064  DPRINT1("CSRSRV:%s: NtSetDefaultHardErrorPort failed (Status=0x%08lx)\n",
1065  __FUNCTION__, Status);
1066  return Status;
1067  }
1068 
1069  /* Return status */
1070  return Status;
1071 }
NTSTATUS NTAPI CsrParseServerCommandLine(IN ULONG ArgumentCount, IN PCHAR Arguments[])
Definition: init.c:544
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:869
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
smooth NULL
Definition: ftsmooth.c:416
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
Definition: init.c:40
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CsrInitCsrRootProcess(VOID)
Definition: init.c:723
Status
Definition: gdiplustypes.h:24
HANDLE CsrSbApiPort
Definition: init.c:29
HANDLE CsrSmApiPort
Definition: init.c:31
#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:882
NTSTATUS NTAPI CsrInitializeNtSessionList(VOID)
Definition: session.c:53
return STATUS_SUCCESS
Definition: btrfs.c:2966
#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 1098 of file procsup.c.

1099 {
1100  PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
1101 
1102  /* Set the Foreground bit off */
1103  ProcessPriority.Foreground = FALSE;
1104 
1105  /* Set the new priority */
1106  NtSetInformationProcess(CsrProcess->ProcessHandle,
1108  &ProcessPriority,
1109  sizeof(ProcessPriority));
1110 }
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

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

◆ CsrSetCallingSpooler()

VOID NTAPI CsrSetCallingSpooler ( ULONG  Reserved)

Definition at line 583 of file server.c.

584 {
585  /* Deprecated */
586  return;
587 }

◆ CsrSetForegroundPriority()

VOID NTAPI CsrSetForegroundPriority ( IN PCSR_PROCESS  CsrProcess)

Definition at line 1129 of file procsup.c.

1130 {
1131  PROCESS_FOREGROUND_BACKGROUND ProcessPriority;
1132 
1133  /* Set the Foreground bit on */
1134  ProcessPriority.Foreground = TRUE;
1135 
1136  /* Set the new priority */
1137  NtSetInformationProcess(CsrProcess->ProcessHandle,
1139  &ProcessPriority,
1140  sizeof(ProcessPriority));
1141 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

Referenced by ConSrvSetProcessFocus().

◆ CsrShutdownProcesses()

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

Definition at line 1268 of file procsup.c.

1270 {
1271  PLIST_ENTRY NextEntry;
1272  PCSR_PROCESS CsrProcess;
1273  NTSTATUS Status;
1274  BOOLEAN FirstTry;
1275  ULONG i;
1276  PCSR_SERVER_DLL ServerDll;
1277  ULONG Result = 0;
1278 
1279  /* Acquire process lock */
1281 
1282  /* Add shutdown flag */
1284 
1285  /* Get the list pointers */
1286  NextEntry = CsrRootProcess->ListLink.Flink;
1287  while (NextEntry != &CsrRootProcess->ListLink)
1288  {
1289  /* Get the Process */
1290  CsrProcess = CONTAINING_RECORD(NextEntry, CSR_PROCESS, ListLink);
1291 
1292  /* Move to the next entry */
1293  NextEntry = NextEntry->Flink;
1294 
1295  /* Remove the skip flag, set shutdown flags to 0 */
1296  CsrProcess->Flags &= ~CsrProcessSkipShutdown;
1297  CsrProcess->ShutdownFlags = 0;
1298  }
1299 
1300  /* Set shutdown Priority */
1302 
1303  /* Start looping */
1304  while (TRUE)
1305  {
1306  /* Find the next process to shutdown */
1307  CsrProcess = FindProcessForShutdown(CallerLuid);
1308  if (!CsrProcess) break;
1309 
1310  /* Increase reference to process */
1311  CsrLockedReferenceProcess(CsrProcess);
1312 
1313  FirstTry = TRUE;
1314  while (TRUE)
1315  {
1316  /* Loop all the servers */
1317  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
1318  {
1319  /* Get the current server */
1320  ServerDll = CsrLoadedServerDll[i];
1321 
1322  /* Check if it's valid and if it has a Shutdown Process Callback */
1323  if (ServerDll && ServerDll->ShutdownProcessCallback)
1324  {
1325  /* Release the lock, make the callback, and acquire it back */
1327  Result = ServerDll->ShutdownProcessCallback(CsrProcess,
1328  Flags,
1329  FirstTry);
1331 
1332  /* Check the result */
1334  {
1335  /* The callback unlocked the process */
1336  break;
1337  }
1338  else if (Result == CsrShutdownCancelled)
1339  {
1340  /* Check if this was a forced shutdown */
1341  if (Flags & EWX_FORCE)
1342  {
1343  DPRINT1("Process %x cancelled forced shutdown (Dll = %d)\n",
1344  CsrProcess->ClientId.UniqueProcess, i);
1345  DbgBreakPoint();
1346  }
1347 
1348  /* Shutdown was cancelled, unlock and exit */
1351  goto Quickie;
1352  }
1353  }
1354  }
1355 
1356  /* No matches during the first try, so loop again */
1358  {
1359  FirstTry = FALSE;
1360  continue;
1361  }
1362 
1363  /* Second try, break out */
1364  break;
1365  }
1366 
1367  /* We've reached the final loop here, so dereference */
1368  if (i == CSR_SERVER_DLL_MAX) CsrLockedDereferenceProcess(CsrProcess);
1369  }
1370 
1371  /* Success path */
1374 
1375 Quickie:
1376  /* Return to normal priority */
1378 
1379  return Status;
1380 }
#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
HANDLE UniqueProcess
Definition: compat.h:474
void DbgBreakPoint()
Definition: mach.c:553
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
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
CLIENT_ID ClientId
Definition: csrsrv.h:38
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY ListLink
Definition: csrsrv.h:39
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
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:1159
#define CsrAcquireProcessLock()
Definition: api.h:12
Definition: typedefs.h:117
Definition: copy.c:32
PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
Definition: csrsrv.h:240
Status
Definition: gdiplustypes.h:24
VOID NTAPI CsrSetToNormalPriority(VOID)
Definition: procsup.c:52
VOID NTAPI CsrSetToShutdownPriority(VOID)
Definition: procsup.c:80
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:48
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 606 of file server.c.

607 {
610  BOOLEAN OldValue;
612  UNICODE_STRING ErrorSource;
613  ULONG_PTR ErrorParameters[4];
614  ULONG Response;
615 
616  DPRINT1("CsrUnhandledExceptionFilter called\n");
617 
618  /* Check if a debugger is installed */
620  &DebuggerInfo,
621  sizeof(DebuggerInfo),
622  NULL);
623 
624  /* Check if this is Session 0, and the Debugger is Enabled */
625  if ((NtCurrentPeb()->SessionId != 0) && (NT_SUCCESS(Status)) &&
626  (DebuggerInfo.KernelDebuggerEnabled))
627  {
628  /* Call the Unhandled Exception Filter */
629  Result = RtlUnhandledExceptionFilter(ExceptionInfo);
631  {
632  /* We're going to raise an error. Get Shutdown Privilege first */
634  TRUE,
635  TRUE,
636  &OldValue);
637 
638  /* Use the Process token if that failed */
639  if (Status == STATUS_NO_TOKEN)
640  {
642  TRUE,
643  FALSE,
644  &OldValue);
645  }
646 
647  /* Initialize our Name String */
648  RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
649 
650  /* Set the parameters */
651  ErrorParameters[0] = (ULONG_PTR)&ErrorSource;
652  ErrorParameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
653  ErrorParameters[2] = (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress;
654  ErrorParameters[3] = (ULONG_PTR)ExceptionInfo->ContextRecord;
655 
656  /* Bugcheck */
658  4,
659  1,
660  ErrorParameters,
662  &Response);
663  }
664 
665  /* Just terminate us */
667  ExceptionInfo->ExceptionRecord->ExceptionCode);
668  }
669 
670  return Result;
671 }
#define TRUE
Definition: types.h:120
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
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:63
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_TOKEN
Definition: ntstatus.h:346
Definition: ncftp.h:89
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
LONG NTAPI RtlUnhandledExceptionFilter(IN struct _EXCEPTION_POINTERS *ExceptionInfo)
Definition: exception.c:306
#define NtCurrentPeb()
Definition: FLS.c:20
#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:656
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87

Referenced by CsrApiRequestThread().

◆ CsrUnlockProcess()

NTSTATUS NTAPI CsrUnlockProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 1398 of file procsup.c.

1399 {
1400  /* Dereference the process */
1401  CsrLockedDereferenceProcess(CsrProcess);
1402 
1403  /* Release the lock and return */
1405  return STATUS_SUCCESS;
1406 }
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by 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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by GetThreadConsoleDesktop().

◆ CsrValidateMessageBuffer()

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

Definition at line 1315 of file api.c.

1319 {
1320  PCSR_CAPTURE_BUFFER CaptureBuffer = ApiMessage->CsrCaptureData;
1321  SIZE_T BufferDistance = (ULONG_PTR)Buffer - (ULONG_PTR)ApiMessage;
1322  ULONG PointerCount;
1323  PULONG_PTR OffsetPointer;
1324 
1325  /*
1326  * Check whether we have a valid buffer pointer, elements
1327  * of non-trivial size and that we don't overflow.
1328  */
1329  if (!Buffer || ElementSize == 0 ||
1330  (ULONGLONG)ElementCount * ElementSize > (ULONGLONG)0xFFFFFFFF)
1331  {
1332  return FALSE;
1333  }
1334 
1335  /* Check if didn't get a buffer and there aren't any arguments to check */
1336  // if (!*Buffer && (ElementCount * ElementSize == 0))
1337  if (!*Buffer && ElementCount == 0) // Here ElementSize != 0 therefore only ElementCount can be == 0
1338  return TRUE;
1339 
1340  /* Check if we have no capture buffer */
1341  if (!CaptureBuffer)
1342  {
1343  /*
1344  * In this case, check only the Process ID
1345  * and if there is a match, we succeed.
1346  */
1347  if (NtCurrentTeb()->ClientId.UniqueProcess ==
1348  ApiMessage->Header.ClientId.UniqueProcess)
1349  {
1350  return TRUE;
1351  }
1352  }
1353  else
1354  {
1355  /* Make sure that there is still space left in the buffer */
1356  if ((CaptureBuffer->Size - (ULONG_PTR)*Buffer + (ULONG_PTR)CaptureBuffer) >=
1357  (ElementCount * ElementSize))
1358  {
1359  /* Perform the validation test */
1360  PointerCount = CaptureBuffer->PointerCount;
1361  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
1362  while (PointerCount--)
1363  {
1364  /*
1365  * The pointer offset must be equal to the delta between
1366  * the addresses of the buffer and of the API message.
1367  */
1368  if (*OffsetPointer == BufferDistance)
1369  {
1370  return TRUE;
1371  }
1372  ++OffsetPointer;
1373  }
1374  }
1375  }
1376 
1377  /* Failure */
1378  DPRINT1("CSRSRV: Bad message buffer %p\n", ApiMessage);
1379  DbgBreakPoint();
1380  return FALSE;
1381 }
#define TRUE
Definition: types.h:120
void DbgBreakPoint()
Definition: mach.c:553
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: bufpool.h:45
uint64_t ULONGLONG
Definition: typedefs.h:65
ULONG_PTR SIZE_T
Definition: typedefs.h:78
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#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:63

Referenced by CSR_API(), and CsrValidateMessageString().

◆ CsrValidateMessageString()

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

Definition at line 1403 of file api.c.

1405 {
1406  if (MessageString)
1407  {
1408  return CsrValidateMessageBuffer(ApiMessage,
1409  (PVOID*)MessageString,
1410  wcslen(*MessageString) + 1,
1411  sizeof(WCHAR));
1412  }
1413  else
1414  {
1415  return FALSE;
1416  }
1417 }
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
__wchar_t WCHAR
Definition: xmlstorage.h:180
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)