2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Client/Server Runtime SubSystem
4 * FILE: include/reactos/subsys/csr/csrsrv.h
5 * PURPOSE: Public definitions for CSR Servers
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
16 /* TYPES **********************************************************************/
18 // Used in ntdll/csr/connect.c
19 #define CSR_CSRSS_SECTION_SIZE 65536
21 typedef struct _CSR_NT_SESSION
24 LIST_ENTRY SessionLink
;
26 } CSR_NT_SESSION
, *PCSR_NT_SESSION
;
28 typedef struct _CSR_PROCESS
32 LIST_ENTRY ThreadList
;
33 PCSR_NT_SESSION NtSession
;
34 ULONG ExpectedVersion
;
36 ULONG_PTR ClientViewBase
;
37 ULONG_PTR ClientViewBounds
;
45 ULONG ProcessGroupSequence
;
52 PVOID ServerData
[ANYSIZE_ARRAY
]; // One structure per CSR server.
53 } CSR_PROCESS
, *PCSR_PROCESS
;
55 typedef struct _CSR_THREAD
57 LARGE_INTEGER CreateTime
;
62 struct _CSR_WAIT_BLOCK
*WaitBlock
;
66 ULONG ImpersonationCount
;
67 } CSR_THREAD
, *PCSR_THREAD
;
69 #define CsrGetClientThread() \
70 ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
73 /* ENUMERATIONS ***************************************************************/
75 typedef enum _CSR_PROCESS_FLAGS
77 CsrProcessTerminating
= 0x1,
78 CsrProcessSkipShutdown
= 0x2,
79 CsrProcessNormalPriority
= 0x10,
80 CsrProcessIdlePriority
= 0x20,
81 CsrProcessHighPriority
= 0x40,
82 CsrProcessRealtimePriority
= 0x80,
83 CsrProcessCreateNewGroup
= 0x100,
84 CsrProcessTerminated
= 0x200,
85 CsrProcessLastThreadTerminated
= 0x400,
86 CsrProcessIsConsoleApp
= 0x800
87 } CSR_PROCESS_FLAGS
, *PCSR_PROCESS_FLAGS
;
89 #define CsrProcessPriorityFlags (CsrProcessNormalPriority | \
90 CsrProcessIdlePriority | \
91 CsrProcessHighPriority | \
92 CsrProcessRealtimePriority)
94 typedef enum _CSR_THREAD_FLAGS
96 CsrThreadAlertable
= 0x1,
97 CsrThreadInTermination
= 0x2,
98 CsrThreadTerminated
= 0x4,
99 CsrThreadIsServerThread
= 0x10
100 } CSR_THREAD_FLAGS
, *PCSR_THREAD_FLAGS
;
102 typedef enum _SHUTDOWN_RESULT
104 CsrShutdownCsrProcess
= 1,
105 CsrShutdownNonCsrProcess
,
107 } SHUTDOWN_RESULT
, *PSHUTDOWN_RESULT
;
109 typedef enum _CSR_SHUTDOWN_FLAGS
111 CsrShutdownSystem
= 4,
113 } CSR_SHUTDOWN_FLAGS
, *PCSR_SHUTDOWN_FLAGS
;
115 typedef enum _CSR_DEBUG_FLAGS
117 CsrDebugOnlyThisProcess
= 1,
118 CsrDebugProcessChildren
= 2
119 } CSR_PROCESS_DEBUG_FLAGS
, *PCSR_PROCESS_DEBUG_FLAGS
;
121 typedef enum _CSR_REPLY_CODE
123 CsrReplyImmediately
= 0,
125 CsrReplyDeadClient
= 2,
126 CsrReplyAlreadySent
= 3
127 } CSR_REPLY_CODE
, *PCSR_REPLY_CODE
;
130 /* FUNCTION TYPES AND STRUCTURES **********************************************/
137 (*CSR_WAIT_FUNCTION
)(
138 IN PLIST_ENTRY WaitList
,
139 IN PCSR_THREAD WaitThread
,
140 IN PCSR_API_MESSAGE WaitApiMessage
,
141 IN PVOID WaitContext
,
142 IN PVOID WaitArgument1
,
143 IN PVOID WaitArgument2
,
147 typedef struct _CSR_WAIT_BLOCK
149 ULONG Size
; // Size of the wait block (variable-sized)
152 PCSR_THREAD WaitThread
;
153 CSR_WAIT_FUNCTION WaitFunction
;
154 CSR_API_MESSAGE WaitApiMessage
; // Variable-sized CSR API message
155 } CSR_WAIT_BLOCK
, *PCSR_WAIT_BLOCK
;
159 * Server DLL structure
163 (NTAPI
*PCSR_API_ROUTINE
)(
164 IN OUT PCSR_API_MESSAGE ApiMessage
,
165 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
169 NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
170 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
174 (NTAPI
*PCSR_CONNECT_CALLBACK
)(
175 IN PCSR_PROCESS CsrProcess
,
176 IN OUT PVOID ConnectionInfo
,
177 IN OUT PULONG ConnectionInfoLength
182 (NTAPI
*PCSR_DISCONNECT_CALLBACK
)(IN PCSR_PROCESS CsrProcess
);
186 (NTAPI
*PCSR_NEWPROCESS_CALLBACK
)(
187 IN PCSR_PROCESS Parent
,
188 IN PCSR_PROCESS CsrProcess
193 (NTAPI
*PCSR_HARDERROR_CALLBACK
)(
194 IN PCSR_THREAD CsrThread
,
195 IN PHARDERROR_MSG HardErrorMessage
200 (NTAPI
*PCSR_SHUTDOWNPROCESS_CALLBACK
)(
201 IN PCSR_PROCESS CsrProcess
,
203 IN BOOLEAN FirstPhase
206 // See http://redplait.blogspot.fr/2011/07/csrserverdll.html
207 typedef struct _CSR_SERVER_DLL
215 ULONG HighestApiSupported
;
216 PCSR_API_ROUTINE
*DispatchTable
;
217 PBOOLEAN ValidTable
; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer.
219 ULONG SizeOfProcessData
;
220 PCSR_CONNECT_CALLBACK ConnectCallback
;
221 PCSR_DISCONNECT_CALLBACK DisconnectCallback
;
222 PCSR_HARDERROR_CALLBACK HardErrorCallback
;
224 PCSR_NEWPROCESS_CALLBACK NewProcessCallback
;
225 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
;
227 } CSR_SERVER_DLL
, *PCSR_SERVER_DLL
;
229 C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL
, SharedSection
) == 0x3C);
234 (NTAPI
*PCSR_SERVER_DLL_INIT_CALLBACK
)(IN PCSR_SERVER_DLL LoadedServerDll
);
236 #define CSR_SERVER_DLL_INIT(n) \
237 NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
240 /* PROTOTYPES ****************************************************************/
244 CsrServerInitialization(IN ULONG ArgumentCount
,
245 IN PCHAR Arguments
[]);
249 CsrAddStaticServerThread(IN HANDLE hThread
,
250 IN PCLIENT_ID ClientId
,
251 IN ULONG ThreadFlags
);
255 CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg
,
256 IN OUT PCSR_API_MESSAGE ReplyMsg
);
260 CsrConnectToUser(VOID
);
264 CsrCreateProcess(IN HANDLE hProcess
,
266 IN PCLIENT_ID ClientId
,
267 IN PCSR_NT_SESSION NtSession
,
269 IN PCLIENT_ID DebugCid
);
273 CsrCreateRemoteThread(IN HANDLE hThread
,
274 IN PCLIENT_ID ClientId
);
278 CsrCreateThread(IN PCSR_PROCESS CsrProcess
,
280 IN PCLIENT_ID ClientId
,
281 IN BOOLEAN HaveClient
);
285 CsrCreateWait(IN PLIST_ENTRY WaitList
,
286 IN CSR_WAIT_FUNCTION WaitFunction
,
287 IN PCSR_THREAD CsrWaitThread
,
288 IN OUT PCSR_API_MESSAGE WaitApiMessage
,
289 IN PVOID WaitContext
);
293 CsrDebugProcess(IN PCSR_PROCESS CsrProcess
);
297 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess
);
301 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess
);
305 CsrDereferenceThread(IN PCSR_THREAD CsrThread
);
309 CsrDereferenceWait(IN PLIST_ENTRY WaitList
);
313 CsrDestroyProcess(IN PCLIENT_ID Cid
,
314 IN NTSTATUS ExitStatus
);
318 CsrDestroyThread(IN PCLIENT_ID Cid
);
322 CsrExecServerThread(IN PVOID ThreadHandler
,
327 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL
,
332 CsrImpersonateClient(IN PCSR_THREAD CsrThread
);
336 CsrLockProcessByClientId(IN HANDLE Pid
,
337 OUT PCSR_PROCESS
*CsrProcess OPTIONAL
);
341 CsrLockThreadByClientId(IN HANDLE Tid
,
342 OUT PCSR_THREAD
*CsrThread
);
346 CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList
,
347 IN PLIST_ENTRY WaitList
);
351 CsrNotifyWait(IN PLIST_ENTRY WaitList
,
352 IN BOOLEAN NotifyAll
,
353 IN PVOID WaitArgument1
,
354 IN PVOID WaitArgument2
);
358 CsrPopulateDosDevices(VOID
);
362 CsrQueryApiPort(VOID
);
366 CsrReferenceThread(IN PCSR_THREAD CsrThread
);
370 CsrRevertToSelf(VOID
);
374 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess
);
378 CsrSetCallingSpooler(ULONG Reserved
);
382 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess
);
386 CsrShutdownProcesses(IN PLUID CallerLuid
,
389 EXCEPTION_DISPOSITION
391 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo
);
395 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess
);
399 CsrUnlockThread(IN PCSR_THREAD CsrThread
);
403 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage
,
405 IN ULONG ElementCount
,
406 IN ULONG ElementSize
);
410 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage
,
411 IN LPWSTR
*MessageString
);