ReactOS 0.4.15-dev-8235-gcd88a97
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:
LONG NTSTATUS
Definition: precomp.h:26
enum _CSR_REPLY_CODE * PCSR_REPLY_CODE
GLdouble n
Definition: glext.h:7729
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40

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:
@ CsrProcessRealtimePriority
Definition: csrsrv.h:90
@ CsrProcessHighPriority
Definition: csrsrv.h:89
@ CsrProcessIdlePriority
Definition: csrsrv.h:88
@ CsrProcessNormalPriority
Definition: csrsrv.h:87

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 144 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 170 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 181 of file csrsrv.h.

◆ PCSR_DISCONNECT_CALLBACK

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

Definition at line 189 of file csrsrv.h.

◆ PCSR_HARDERROR_CALLBACK

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

Definition at line 200 of file csrsrv.h.

◆ PCSR_NEWPROCESS_CALLBACK

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

Definition at line 193 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 252 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 207 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
@ CsrDebugProcessChildren
Definition: csrsrv.h:126
@ CsrDebugOnlyThisProcess
Definition: csrsrv.h:125
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.

84{
enum _CSR_PROCESS_FLAGS CSR_PROCESS_FLAGS
@ CsrProcessTerminated
Definition: csrsrv.h:92
@ CsrProcessLastThreadTerminated
Definition: csrsrv.h:93
@ CsrProcessSkipShutdown
Definition: csrsrv.h:86
@ CsrProcessCreateNewGroup
Definition: csrsrv.h:91
@ CsrProcessIsConsoleApp
Definition: csrsrv.h:94
@ CsrProcessTerminating
Definition: csrsrv.h:85
enum _CSR_PROCESS_FLAGS * PCSR_PROCESS_FLAGS

◆ _CSR_REPLY_CODE

Enumerator
CsrReplyImmediately 
CsrReplyPending 
CsrReplyDeadClient 
CsrReplyAlreadySent 

Definition at line 129 of file csrsrv.h.

130{
132 CsrReplyPending = 1,
enum _CSR_REPLY_CODE CSR_REPLY_CODE
@ CsrReplyAlreadySent
Definition: csrsrv.h:134
@ CsrReplyImmediately
Definition: csrsrv.h:131
@ CsrReplyDeadClient
Definition: csrsrv.h:133
@ CsrReplyPending
Definition: csrsrv.h:132

◆ _CSR_SHUTDOWN_FLAGS

Enumerator
CsrShutdownSystem 
CsrShutdownOther 

Definition at line 117 of file csrsrv.h.

118{
@ CsrShutdownOther
Definition: csrsrv.h:120
@ CsrShutdownSystem
Definition: csrsrv.h:119
enum _CSR_SHUTDOWN_FLAGS CSR_SHUTDOWN_FLAGS
enum _CSR_SHUTDOWN_FLAGS * PCSR_SHUTDOWN_FLAGS

◆ _CSR_THREAD_FLAGS

Enumerator
CsrThreadAlertable 
CsrThreadInTermination 
CsrThreadTerminated 
CsrThreadIsServerThread 

Definition at line 102 of file csrsrv.h.

103{
104 CsrThreadAlertable = 0x1,
enum _CSR_THREAD_FLAGS CSR_THREAD_FLAGS
@ CsrThreadAlertable
Definition: csrsrv.h:104
@ CsrThreadTerminated
Definition: csrsrv.h:106
@ CsrThreadInTermination
Definition: csrsrv.h:105
@ CsrThreadIsServerThread
Definition: csrsrv.h:107
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
@ CsrShutdownNonCsrProcess
Definition: csrsrv.h:113
@ CsrShutdownCsrProcess
Definition: csrsrv.h:112
@ CsrShutdownCancelled
Definition: csrsrv.h:114

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 */
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}
#define DPRINT1
Definition: precomp.h:8
#define InsertTailList(ListHead, Entry)
HANDLE hThread
Definition: wizard.c:28
ULONG ThreadCount
Definition: csrsrv.h:55
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
ULONG Flags
Definition: csrsrv.h:72
HANDLE ThreadHandle
Definition: csrsrv.h:71
CLIENT_ID ClientId
Definition: csrsrv.h:68
LIST_ENTRY Link
Definition: csrsrv.h:66
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
#define CsrAcquireProcessLock()
Definition: api.h:12
#define CsrReleaseProcessLock()
Definition: api.h:15
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

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 = NULL;
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#ifdef CSR_DBG
68 DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n",
69 ServerId, ServerDll);
70 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
71#endif
72 ReplyMsg->Status = STATUS_ILLEGAL_FUNCTION;
74 }
75 else
76 {
77 /* Get the API ID, normalized with our Base ID */
78 ApiId = CSR_API_NUMBER_TO_API_ID(ReceiveMsg->ApiNumber) - ServerDll->ApiBase;
79
80 /* Make sure that the ID is within limits, and the entry exists */
81 if ((ApiId >= ServerDll->HighestApiSupported) ||
82 ((ServerDll->ValidTable) && !(ServerDll->ValidTable[ApiId])))
83 {
84 /* We are beyond the Maximum API ID, or it doesn't exist */
85#ifdef CSR_DBG
86 DPRINT1("API: %d\n", ApiId);
87 DPRINT1("CSRSS: %lx (%s) is invalid ApiTableIndex for %Z or is an "
88 "invalid API to call from the server.\n",
89 ApiId,
90 ((ServerDll->NameTable) && (ServerDll->NameTable[ApiId])) ?
91 ServerDll->NameTable[ApiId] : "*** UNKNOWN ***",
92 &ServerDll->Name);
93 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
94#endif
95 ReplyMsg->Status = STATUS_ILLEGAL_FUNCTION;
97 }
98 }
99
100#ifdef CSR_DBG
101 if (CsrDebug & 2)
102 {
103 DPRINT1("CSRSS: %s Api Request received from server process\n",
104 ServerDll->NameTable[ApiId]);
105 }
106#endif
107
108 /* Validation complete, start SEH */
110 {
111 /* Call the API, get the reply code and return the result */
112 ReplyMsg->Status = ServerDll->DispatchTable[ApiId](ReceiveMsg, &ReplyCode);
113 }
115 {
116 /* If we got an exception, return access violation */
117 ReplyMsg->Status = STATUS_ACCESS_VIOLATION;
118 }
119 _SEH2_END;
120
121 /* Return success */
122 return STATUS_SUCCESS;
123}
#define NtCurrentPeb()
Definition: FLS.c:22
#define CSR_API_NUMBER_TO_API_ID(ApiNumber)
Definition: csrmsg.h:43
#define CSR_API_NUMBER_TO_SERVER_ID(ApiNumber)
Definition: csrmsg.h:40
#define NULL
Definition: types.h:112
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:411
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG HighestApiSupported
Definition: csrsrv.h:223
PBOOLEAN ValidTable
Definition: csrsrv.h:225
ANSI_STRING Name
Definition: csrsrv.h:218
PCSR_API_ROUTINE * DispatchTable
Definition: csrsrv.h:224
ULONG ApiBase
Definition: csrsrv.h:222
ULONG CsrDebug
Definition: init.c:23
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20
uint32_t ULONG
Definition: typedefs.h:59

◆ CsrConnectToUser()

PCSR_THREAD NTAPI CsrConnectToUser ( VOID  )

Definition at line 1021 of file api.c.

1022{
1024 ANSI_STRING DllName;
1025 UNICODE_STRING TempName;
1026 HANDLE hUser32;
1027 STRING StartupName;
1028 PTEB Teb = NtCurrentTeb();
1029 PCSR_THREAD CsrThread;
1030 BOOLEAN Connected;
1031
1032 /* Check if we didn't already find it */
1034 {
1035 /* Get the DLL Handle for user32.dll */
1036 RtlInitAnsiString(&DllName, "user32");
1037 RtlAnsiStringToUnicodeString(&TempName, &DllName, TRUE);
1039 NULL,
1040 &TempName,
1041 &hUser32);
1042 RtlFreeUnicodeString(&TempName);
1043
1044 /* If we got the handle, get the Client Thread Startup Entrypoint */
1045 if (NT_SUCCESS(Status))
1046 {
1047 RtlInitAnsiString(&StartupName,"ClientThreadSetup");
1049 &StartupName,
1050 0,
1052 }
1053 }
1054
1055 /* Connect to user32 */
1056 _SEH2_TRY
1057 {
1058 Connected = CsrClientThreadSetup();
1059 }
1061 {
1062 Connected = FALSE;
1063 }
1064 _SEH2_END;
1065
1066 if (!Connected)
1067 {
1068 DPRINT1("CSRSS: CsrConnectToUser failed\n");
1069 return NULL;
1070 }
1071
1072 /* Save pointer to this thread in TEB */
1074 CsrThread = CsrLocateThreadInProcess(NULL, &Teb->ClientId);
1076 if (CsrThread) Teb->CsrClientThread = CsrThread;
1077
1078 /* Return it */
1079 return CsrThread;
1080}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
std::wstring STRING
Definition: fontsub.cpp:33
Status
Definition: gdiplustypes.h:25
#define NtCurrentTeb
NTSTATUS NTAPI LdrGetDllHandle(_In_opt_ PWSTR DllPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *DllHandle)
Definition: ldrapi.c:770
NTSTATUS NTAPI LdrGetProcedureAddress(_In_ PVOID BaseAddress, _In_opt_ _When_(Ordinal==0, _Notnull_) PANSI_STRING Name, _In_opt_ _When_(Name==NULL, _In_range_(>, 0)) ULONG Ordinal, _Out_ PVOID *ProcedureAddress)
Definition: ldrapi.c:789
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
Definition: compat.h:836
CLIENT_ID ClientId
Definition: compat.h:839
PVOID CsrClientThread
Definition: compat.h:845
BOOLEAN(* CsrClientThreadSetup)(VOID)
Definition: api.c:21
PCSR_THREAD NTAPI CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL, IN PCLIENT_ID Cid)
Definition: thredsup.c:248

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;
431 PCSR_PROCESS CurrentProcess;
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 */
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 */
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 */
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 */
619 CsrInsertProcess(CurrentProcess, CsrProcess);
620
621 /* Release lock and return */
623 return Status;
624}
#define HandleToUlong(h)
Definition: basetsd.h:79
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define CsrProcessPriorityFlags
Definition: csrsrv.h:97
@ ThreadTimes
Definition: compat.h:936
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
@ ProcessDebugPort
Definition: winternl.h:395
@ ProcessExceptionPort
Definition: winternl.h:864
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2624
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
HANDLE UniqueProcess
Definition: compat.h:825
ULONG DebugFlags
Definition: csrsrv.h:49
ULONG ProcessGroupId
Definition: csrsrv.h:52
ULONG ProcessGroupSequence
Definition: csrsrv.h:53
PVOID ServerData[ANYSIZE_ARRAY]
Definition: csrsrv.h:60
CLIENT_ID DebugCid
Definition: csrsrv.h:50
ULONG SizeOfProcessData
Definition: csrsrv.h:234
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
PCSR_PROCESS Process
Definition: csrsrv.h:69
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
KEXECUTE_OPTIONS Flags
Definition: ketypes.h:2130
HANDLE CsrApiPort
Definition: connect.c:27
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
VOID NTAPI CsrReferenceNtSession(IN PCSR_NT_SESSION Session)
Definition: session.c:118
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:189
VOID NTAPI CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:366
VOID NTAPI CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:297
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1107
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
PKPROCESS CsrProcess
Definition: videoprt.c:39
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

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 */
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}
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1410
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
#define __FUNCTION__
Definition: types.h:116
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
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:3410
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
LONGLONG QuadPart
Definition: typedefs.h:114
#define DUPLICATE_SAME_ACCESS

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;
685 PCSR_PROCESS CurrentProcess;
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 */
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}
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182

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}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
LIST_ENTRY WaitList
Definition: csrsrv.h:158
#define CsrAcquireWaitLock()
Definition: api.h:21
HANDLE CsrHeap
Definition: init.c:25
#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

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}
#define DPRINT
Definition: sndvol32.h:73
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ 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}

◆ CsrDereferenceProcess()

VOID NTAPI CsrDereferenceProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 691 of file procsup.c.

692{
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}
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119

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}
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:424

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 */
298
299 /* Free the block */
300 RtlFreeHeap(CsrHeap, 0, WaitBlock);
301 }
302 }
303
304 /* Release the locks */
307}
VOID NTAPI CsrDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:776
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
PCSR_THREAD WaitThread
Definition: csrsrv.h:160
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

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 */
800 }
801
802 /* Release the Process Lock and return success */
804 return STATUS_SUCCESS;
805}
struct _CSR_WAIT_BLOCK * WaitBlock
Definition: csrsrv.h:70
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
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
static int Link(const char **args)
Definition: vfdcmd.c:2414

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 */
858
859 /* Release the Process Lock and return success */
861 return STATUS_SUCCESS;
862}
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467

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;
893
894 /* Acquire process lock */
896
897 /* Allocate a CSR Thread in the Root Process */
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}
#define InsertHeadList(ListHead, Entry)
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)

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;
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 */
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 */
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}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI NtOpenProcessToken(IN HANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
Definition: security.c:350
NTSTATUS NTAPI NtOpenThreadToken(_In_ HANDLE ThreadHandle, _In_ ACCESS_MASK DesiredAccess, _In_ BOOLEAN OpenAsSelf, _Out_ PHANDLE TokenHandle)
Opens a token that is tied to a thread handle.
Definition: token.c:2474
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
LUID AuthenticationId
Definition: setypes.h:1087
_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)
Queries a specific type of information in regard of an access token based upon the information class....
Definition: tokencls.c:473
#define TOKEN_QUERY
Definition: setypes.h:928
@ TokenStatistics
Definition: setypes.h:975
#define NtCurrentThread()

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,
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:1036
ULONG ImpersonationCount
Definition: csrsrv.h:74
SECURITY_QUALITY_OF_SERVICE CsrSecurityQos
Definition: procsup.c:23

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}
HANDLE UniqueThread
Definition: compat.h:826
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154
#define CsrHashThread(t)
Definition: thredsup.c:17
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21

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}

◆ 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}
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 1146 of file init.c.

1147{
1148 DPRINT1("Deprecated API in r55585.\n");
1149 return;
1150}

◆ CsrQueryApiPort()

HANDLE NTAPI CsrQueryApiPort ( VOID  )

Definition at line 1097 of file api.c.

1098{
1099 return CsrApiPort;
1100}

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}

Referenced by NotifyUserProcessForShutdown().

◆ CsrRevertToSelf()

BOOLEAN NTAPI CsrRevertToSelf ( VOID  )

Definition at line 1057 of file procsup.c.

1058{
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}
@ ThreadImpersonationToken
Definition: compat.h:940
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:2018

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 1011 of file init.c.

1013{
1015
1016 /* Cache System Basic Information so we don't always request it */
1018 &CsrNtSysInfo,
1020 NULL);
1021 if (!NT_SUCCESS(Status))
1022 {
1023 DPRINT1("CSRSRV:%s: NtQuerySystemInformation failed (Status=0x%08lx)\n",
1025 return Status;
1026 }
1027
1028 /* Save our Heap */
1029 CsrHeap = RtlGetProcessHeap();
1030
1031 /* Set our Security Descriptor to protect the process */
1033 if (!NT_SUCCESS(Status))
1034 {
1035 DPRINT1("CSRSRV:%s: CsrSetProcessSecurity failed (Status=0x%08lx)\n",
1037 return Status;
1038 }
1039
1040 /* Set up Session Support */
1042 if (!NT_SUCCESS(Status))
1043 {
1044 DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=0x%08lx)\n",
1046 return Status;
1047 }
1048
1049 /* Set up Process Support and allocate the CSR Root Process */
1051 if (!NT_SUCCESS(Status))
1052 {
1053 DPRINT1("CSRSRV:%s: CsrInitializeProcessStructure failed (Status=0x%08lx)\n",
1055 return Status;
1056 }
1057
1058 /* Parse the command line */
1059 Status = CsrParseServerCommandLine(ArgumentCount, Arguments);
1060 if (!NT_SUCCESS(Status))
1061 {
1062 DPRINT1("CSRSRV:%s: CsrParseServerCommandLine failed (Status=0x%08lx)\n",
1064 return Status;
1065 }
1066
1067 /* Finish to initialize the CSR Root Process */
1069 if (!NT_SUCCESS(Status))
1070 {
1071 DPRINT1("CSRSRV:%s: CsrInitCsrRootProcess failed (Status=0x%08lx)\n",
1073 return Status;
1074 }
1075
1076 /* Now initialize our API Port */
1078 if (!NT_SUCCESS(Status))
1079 {
1080 DPRINT1("CSRSRV:%s: CsrApiPortInitialize failed (Status=0x%08lx)\n",
1082 return Status;
1083 }
1084
1085#ifdef __REACTOS__
1086 if (CsrSubSystemType != IMAGE_SUBSYSTEM_UNKNOWN)
1087 {
1088#endif
1089 /* Initialize the API Port for SM communication */
1091 if (!NT_SUCCESS(Status))
1092 {
1093 DPRINT1("CSRSRV:%s: CsrSbApiPortInitialize failed (Status=0x%08lx)\n",
1095 return Status;
1096 }
1097
1098 /* We're all set! Connect to SM! */
1101#ifdef __REACTOS__
1102 CsrSubSystemType,
1103#else
1105#endif
1106 &CsrSmApiPort);
1107 if (!NT_SUCCESS(Status))
1108 {
1109 DPRINT1("CSRSRV:%s: SmConnectToSm failed (Status=0x%08lx)\n",
1111 return Status;
1112 }
1113#ifdef __REACTOS__
1114 }
1115#endif
1116
1117 /* Have us handle Hard Errors */
1119 if (!NT_SUCCESS(Status))
1120 {
1121 DPRINT1("CSRSRV:%s: NtSetDefaultHardErrorPort failed (Status=0x%08lx)\n",
1123 return Status;
1124 }
1125
1126 /* Return status */
1127 return Status;
1128}
@ SystemBasicInformation
Definition: ntddk_ex.h:11
NTSTATUS NTAPI NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
Definition: harderr.c:740
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
#define IMAGE_SUBSYSTEM_UNKNOWN
Definition: ntimage.h:435
NTSTATUS NTAPI SmConnectToSm(_In_opt_ PUNICODE_STRING SbApiPortName, _In_opt_ HANDLE SbApiPort, _In_opt_ ULONG ImageType, _Out_ PHANDLE SmApiPort)
Connects to the SM API port for registering a session callback port (Sb) associated to a subsystem,...
Definition: smclient.c:57
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
NTSTATUS NTAPI CsrApiPortInitialize(VOID)
Definition: api.c:900
NTSTATUS NTAPI CsrInitializeNtSessionList(VOID)
Definition: session.c:53
NTSTATUS NTAPI CsrInitializeProcessStructure(VOID)
Definition: procsup.c:255
NTSTATUS NTAPI CsrSbApiPortInitialize(VOID)
Definition: init.c:915
NTSTATUS NTAPI CsrParseServerCommandLine(IN ULONG ArgumentCount, IN PCHAR Arguments[])
Definition: init.c:554
NTSTATUS NTAPI CsrSetProcessSecurity(VOID)
Definition: init.c:66
HANDLE CsrSbApiPort
Definition: init.c:29
HANDLE CsrSmApiPort
Definition: init.c:31
HANDLE CsrApiPort
Definition: init.c:33
HANDLE CsrHeap
Definition: init.c:25
NTSTATUS NTAPI CsrInitCsrRootProcess(VOID)
Definition: init.c:769
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
Definition: init.c:44

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}
@ ProcessForegroundInformation
Definition: winternl.h:881

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

◆ CsrSetCallingSpooler()

VOID NTAPI CsrSetCallingSpooler ( ULONG  Reserved)

Definition at line 620 of file server.c.

621{
622 /* Deprecated */
623 return;
624}

◆ 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}

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;
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 */
1305 CsrProcess->Flags &= ~CsrProcessSkipShutdown;
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
1387Quickie:
1388 /* Return to normal priority */
1390
1391 return Status;
1392}
@ FirstTry
Definition: copy.c:25
ULONG ShutdownFlags
Definition: csrsrv.h:59
LIST_ENTRY ListLink
Definition: csrsrv.h:39
PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
Definition: csrsrv.h:240
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
VOID NTAPI CsrSetToShutdownPriority(VOID)
Definition: procsup.c:80
VOID NTAPI CsrSetToNormalPriority(VOID)
Definition: procsup.c:52
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:233
PCSR_PROCESS NTAPI FindProcessForShutdown(IN PLUID CallerLuid)
Definition: procsup.c:1168
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define EWX_FORCE
Definition: winuser.h:635
_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:409

Referenced by UserExitReactOS().

◆ CsrUnhandledExceptionFilter()

EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter ( IN PEXCEPTION_POINTERS  ExceptionInfo)

Definition at line 643 of file server.c.

644{
647 BOOLEAN OldValue;
649 UNICODE_STRING ErrorSource;
650 ULONG_PTR ErrorParameters[4];
652
653 DPRINT1("CsrUnhandledExceptionFilter called\n");
654
655 /* Check if a debugger is installed */
657 &DebuggerInfo,
658 sizeof(DebuggerInfo),
659 NULL);
660
661 /* Check if this is Session 0, and the Debugger is Enabled */
662 if ((NtCurrentPeb()->SessionId != 0) && (NT_SUCCESS(Status)) &&
663 (DebuggerInfo.KernelDebuggerEnabled))
664 {
665 /* Call the Unhandled Exception Filter */
666 Result = RtlUnhandledExceptionFilter(ExceptionInfo);
668 {
669 /* We're going to raise an error. Get Shutdown Privilege first */
671 TRUE,
672 TRUE,
673 &OldValue);
674
675 /* Use the Process token if that failed */
676 if (Status == STATUS_NO_TOKEN)
677 {
679 TRUE,
680 FALSE,
681 &OldValue);
682 }
683 if (!NT_SUCCESS(Status))
684 {
685 DPRINT1("CsrUnhandledExceptionFilter(): RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE) failed, Status = 0x%08lx\n", Status);
686 goto NoPrivilege;
687 }
688
689 /* Initialize our Name String */
690 RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
691
692 /* Set the parameters */
693 ErrorParameters[0] = (ULONG_PTR)&ErrorSource;
694 ErrorParameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
695 ErrorParameters[2] = (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress;
696 ErrorParameters[3] = (ULONG_PTR)ExceptionInfo->ContextRecord;
697
698 /* Bugcheck */
700 4,
701 1,
702 ErrorParameters,
704 &Response);
705 }
706
707NoPrivilege:
708 /* Just terminate us */
710 ExceptionInfo->ExceptionRecord->ExceptionCode);
711 }
712
713 return Result;
714}
enum _EXCEPTION_DISPOSITION EXCEPTION_DISPOSITION
ULONG SessionId
Definition: dllmain.c:28
#define ULONG_PTR
Definition: config.h:101
@ SystemKernelDebuggerInformation
Definition: ntddk_ex.h:46
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:551
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
@ OptionShutdownSystem
Definition: extypes.h:192
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define STATUS_SYSTEM_PROCESS_TERMINATED
Definition: ntstatus.h:670
#define L(x)
Definition: ntvdm.h:50
LONG NTAPI RtlUnhandledExceptionFilter(IN struct _EXCEPTION_POINTERS *ExceptionInfo)
Definition: exception.c:313
Definition: ncftp.h:89

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}

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 ProcessStructureListLocked()
Definition: api.h:18

Referenced by GetThreadConsoleDesktop().

◆ CsrValidateMessageBuffer()

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

Definition at line 1430 of file api.c.

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

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 1517 of file api.c.

1519{
1520 if (MessageString)
1521 {
1522 return CsrValidateMessageBuffer(ApiMessage,
1523 (PVOID*)MessageString,
1524 wcslen(*MessageString) + 1,
1525 sizeof(WCHAR));
1526 }
1527 else
1528 {
1529 return FALSE;
1530 }
1531}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1430
__wchar_t WCHAR
Definition: xmlstorage.h:180