6c89d146e76b6affdf8cf98a35aa176e5401c629
[reactos.git] / reactos / include / reactos / subsys / csr / csrsrv.h
1 /*
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)
8 */
9
10 #ifndef _CSRSRV_H
11 #define _CSRSRV_H
12
13 #include "csrmsg.h"
14
15
16 /* TYPES **********************************************************************/
17
18 // Used in ntdll/csr/connect.c
19 #define CSR_CSRSS_SECTION_SIZE 65536
20
21 typedef struct _CSR_NT_SESSION
22 {
23 ULONG ReferenceCount;
24 LIST_ENTRY SessionLink;
25 ULONG SessionId;
26 } CSR_NT_SESSION, *PCSR_NT_SESSION;
27
28 typedef struct _CSR_PROCESS
29 {
30 CLIENT_ID ClientId;
31 LIST_ENTRY ListLink;
32 LIST_ENTRY ThreadList;
33 PCSR_NT_SESSION NtSession;
34 ULONG ExpectedVersion;
35 HANDLE ClientPort;
36 ULONG_PTR ClientViewBase;
37 ULONG_PTR ClientViewBounds;
38 HANDLE ProcessHandle;
39 ULONG SequenceNumber;
40 ULONG Flags;
41 ULONG DebugFlags;
42 CLIENT_ID DebugCid;
43 ULONG ReferenceCount;
44 ULONG ProcessGroupId;
45 ULONG ProcessGroupSequence;
46 ULONG fVDM;
47 ULONG ThreadCount;
48 ULONG PriorityClass;
49 ULONG Reserved;
50 ULONG ShutdownLevel;
51 ULONG ShutdownFlags;
52 PVOID ServerData[ANYSIZE_ARRAY]; // One structure per CSR server.
53 } CSR_PROCESS, *PCSR_PROCESS;
54
55 typedef struct _CSR_THREAD
56 {
57 LARGE_INTEGER CreateTime;
58 LIST_ENTRY Link;
59 LIST_ENTRY HashLinks;
60 CLIENT_ID ClientId;
61 PCSR_PROCESS Process;
62 struct _CSR_WAIT_BLOCK *WaitBlock;
63 HANDLE ThreadHandle;
64 ULONG Flags;
65 ULONG ReferenceCount;
66 ULONG ImpersonationCount;
67 } CSR_THREAD, *PCSR_THREAD;
68
69 #define CsrGetClientThread() \
70 ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
71
72
73 /* ENUMERATIONS ***************************************************************/
74
75 typedef enum _CSR_PROCESS_FLAGS
76 {
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;
88
89 #define CsrProcessPriorityFlags (CsrProcessNormalPriority | \
90 CsrProcessIdlePriority | \
91 CsrProcessHighPriority | \
92 CsrProcessRealtimePriority)
93
94 typedef enum _CSR_THREAD_FLAGS
95 {
96 CsrThreadAlertable = 0x1,
97 CsrThreadInTermination = 0x2,
98 CsrThreadTerminated = 0x4,
99 CsrThreadIsServerThread = 0x10
100 } CSR_THREAD_FLAGS, *PCSR_THREAD_FLAGS;
101
102 typedef enum _SHUTDOWN_RESULT
103 {
104 CsrShutdownCsrProcess = 1,
105 CsrShutdownNonCsrProcess,
106 CsrShutdownCancelled
107 } SHUTDOWN_RESULT, *PSHUTDOWN_RESULT;
108
109 typedef enum _CSR_SHUTDOWN_FLAGS
110 {
111 CsrShutdownSystem = 4,
112 CsrShutdownOther = 8
113 } CSR_SHUTDOWN_FLAGS, *PCSR_SHUTDOWN_FLAGS;
114
115 typedef enum _CSR_DEBUG_FLAGS
116 {
117 CsrDebugOnlyThisProcess = 1,
118 CsrDebugProcessChildren = 2
119 } CSR_PROCESS_DEBUG_FLAGS, *PCSR_PROCESS_DEBUG_FLAGS;
120
121 typedef enum _CSR_REPLY_CODE
122 {
123 CsrReplyImmediately = 0,
124 CsrReplyPending = 1,
125 CsrReplyDeadClient = 2,
126 CsrReplyAlreadySent = 3
127 } CSR_REPLY_CODE, *PCSR_REPLY_CODE;
128
129
130 /* FUNCTION TYPES AND STRUCTURES **********************************************/
131
132 /*
133 * Wait block
134 */
135 typedef
136 BOOLEAN
137 (NTAPI *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,
144 IN ULONG WaitFlags
145 );
146
147 typedef struct _CSR_WAIT_BLOCK
148 {
149 ULONG Size; // Size of the wait block (variable-sized)
150 LIST_ENTRY WaitList;
151 PVOID WaitContext;
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;
156
157
158 /*
159 * Server DLL structure
160 */
161 typedef
162 NTSTATUS
163 (NTAPI *PCSR_API_ROUTINE)(
164 IN OUT PCSR_API_MESSAGE ApiMessage,
165 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
166 );
167
168 #define CSR_API(n) \
169 NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
170 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
171
172 typedef
173 NTSTATUS
174 (NTAPI *PCSR_CONNECT_CALLBACK)(
175 IN PCSR_PROCESS CsrProcess,
176 IN OUT PVOID ConnectionInfo,
177 IN OUT PULONG ConnectionInfoLength
178 );
179
180 typedef
181 VOID
182 (NTAPI *PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess);
183
184 typedef
185 NTSTATUS
186 (NTAPI *PCSR_NEWPROCESS_CALLBACK)(
187 IN PCSR_PROCESS Parent,
188 IN PCSR_PROCESS CsrProcess
189 );
190
191 typedef
192 VOID
193 (NTAPI *PCSR_HARDERROR_CALLBACK)(
194 IN PCSR_THREAD CsrThread,
195 IN PHARDERROR_MSG HardErrorMessage
196 );
197
198 typedef
199 ULONG
200 (NTAPI *PCSR_SHUTDOWNPROCESS_CALLBACK)(
201 IN PCSR_PROCESS CsrProcess,
202 IN ULONG Flags,
203 IN BOOLEAN FirstPhase
204 );
205
206 // See http://redplait.blogspot.fr/2011/07/csrserverdll.html
207 typedef struct _CSR_SERVER_DLL
208 {
209 ULONG Length;
210 ANSI_STRING Name;
211 HANDLE ServerHandle;
212 ULONG ServerId;
213 ULONG Unknown;
214 ULONG ApiBase;
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.
218 PCHAR *NameTable;
219 ULONG SizeOfProcessData;
220 PCSR_CONNECT_CALLBACK ConnectCallback;
221 PCSR_DISCONNECT_CALLBACK DisconnectCallback;
222 PCSR_HARDERROR_CALLBACK HardErrorCallback;
223 PVOID SharedSection;
224 PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
225 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
226 ULONG Unknown2[3];
227 } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
228 #ifndef _WIN64
229 C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x3C);
230 #endif
231
232 typedef
233 NTSTATUS
234 (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll);
235
236 #define CSR_SERVER_DLL_INIT(n) \
237 NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
238
239
240 /* PROTOTYPES ****************************************************************/
241
242 NTSTATUS
243 NTAPI
244 CsrServerInitialization(IN ULONG ArgumentCount,
245 IN PCHAR Arguments[]);
246
247 PCSR_THREAD
248 NTAPI
249 CsrAddStaticServerThread(IN HANDLE hThread,
250 IN PCLIENT_ID ClientId,
251 IN ULONG ThreadFlags);
252
253 NTSTATUS
254 NTAPI
255 CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
256 IN OUT PCSR_API_MESSAGE ReplyMsg);
257
258 PCSR_THREAD
259 NTAPI
260 CsrConnectToUser(VOID);
261
262 NTSTATUS
263 NTAPI
264 CsrCreateProcess(IN HANDLE hProcess,
265 IN HANDLE hThread,
266 IN PCLIENT_ID ClientId,
267 IN PCSR_NT_SESSION NtSession,
268 IN ULONG Flags,
269 IN PCLIENT_ID DebugCid);
270
271 NTSTATUS
272 NTAPI
273 CsrCreateRemoteThread(IN HANDLE hThread,
274 IN PCLIENT_ID ClientId);
275
276 NTSTATUS
277 NTAPI
278 CsrCreateThread(IN PCSR_PROCESS CsrProcess,
279 IN HANDLE hThread,
280 IN PCLIENT_ID ClientId,
281 IN BOOLEAN HaveClient);
282
283 BOOLEAN
284 NTAPI
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);
290
291 NTSTATUS
292 NTAPI
293 CsrDebugProcess(IN PCSR_PROCESS CsrProcess);
294
295 NTSTATUS
296 NTAPI
297 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess);
298
299 VOID
300 NTAPI
301 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
302
303 VOID
304 NTAPI
305 CsrDereferenceThread(IN PCSR_THREAD CsrThread);
306
307 VOID
308 NTAPI
309 CsrDereferenceWait(IN PLIST_ENTRY WaitList);
310
311 NTSTATUS
312 NTAPI
313 CsrDestroyProcess(IN PCLIENT_ID Cid,
314 IN NTSTATUS ExitStatus);
315
316 NTSTATUS
317 NTAPI
318 CsrDestroyThread(IN PCLIENT_ID Cid);
319
320 NTSTATUS
321 NTAPI
322 CsrExecServerThread(IN PVOID ThreadHandler,
323 IN ULONG Flags);
324
325 NTSTATUS
326 NTAPI
327 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
328 OUT PLUID Luid);
329
330 BOOLEAN
331 NTAPI
332 CsrImpersonateClient(IN PCSR_THREAD CsrThread);
333
334 NTSTATUS
335 NTAPI
336 CsrLockProcessByClientId(IN HANDLE Pid,
337 OUT PCSR_PROCESS *CsrProcess OPTIONAL);
338
339 NTSTATUS
340 NTAPI
341 CsrLockThreadByClientId(IN HANDLE Tid,
342 OUT PCSR_THREAD *CsrThread);
343
344 VOID
345 NTAPI
346 CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList,
347 IN PLIST_ENTRY WaitList);
348
349 BOOLEAN
350 NTAPI
351 CsrNotifyWait(IN PLIST_ENTRY WaitList,
352 IN BOOLEAN NotifyAll,
353 IN PVOID WaitArgument1,
354 IN PVOID WaitArgument2);
355
356 VOID
357 NTAPI
358 CsrPopulateDosDevices(VOID);
359
360 HANDLE
361 NTAPI
362 CsrQueryApiPort(VOID);
363
364 VOID
365 NTAPI
366 CsrReferenceThread(IN PCSR_THREAD CsrThread);
367
368 BOOLEAN
369 NTAPI
370 CsrRevertToSelf(VOID);
371
372 VOID
373 NTAPI
374 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
375
376 VOID
377 NTAPI
378 CsrSetCallingSpooler(ULONG Reserved);
379
380 VOID
381 NTAPI
382 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess);
383
384 NTSTATUS
385 NTAPI
386 CsrShutdownProcesses(IN PLUID CallerLuid,
387 IN ULONG Flags);
388
389 EXCEPTION_DISPOSITION
390 NTAPI
391 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo);
392
393 NTSTATUS
394 NTAPI
395 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
396
397 NTSTATUS
398 NTAPI
399 CsrUnlockThread(IN PCSR_THREAD CsrThread);
400
401 BOOLEAN
402 NTAPI
403 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
404 IN PVOID *Buffer,
405 IN ULONG ElementCount,
406 IN ULONG ElementSize);
407
408 BOOLEAN
409 NTAPI
410 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage,
411 IN LPWSTR *MessageString);
412
413 #endif // _CSRSRV_H
414
415 /* EOF */