[REACTOS]
[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@relsoft.net)
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 (*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 LIST_ENTRY UserWaitList;
152 PVOID WaitContext;
153 PCSR_THREAD WaitThread;
154 CSR_WAIT_FUNCTION WaitFunction;
155 CSR_API_MESSAGE WaitApiMessage; // Variable-sized CSR API message
156 } CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
157
158
159 /*
160 * Server DLL structure
161 */
162 typedef
163 NTSTATUS
164 (NTAPI *PCSR_API_ROUTINE)(
165 IN OUT PCSR_API_MESSAGE ApiMessage,
166 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
167 );
168
169 #define CSR_API(n) \
170 NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
171 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
172
173 typedef
174 NTSTATUS
175 (NTAPI *PCSR_CONNECT_CALLBACK)(
176 IN PCSR_PROCESS CsrProcess,
177 IN OUT PVOID ConnectionInfo,
178 IN OUT PULONG ConnectionInfoLength
179 );
180
181 typedef
182 VOID
183 (NTAPI *PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess);
184
185 typedef
186 NTSTATUS
187 (NTAPI *PCSR_NEWPROCESS_CALLBACK)(
188 IN PCSR_PROCESS Parent,
189 IN PCSR_PROCESS CsrProcess
190 );
191
192 typedef
193 VOID
194 (NTAPI *PCSR_HARDERROR_CALLBACK)(
195 IN PCSR_THREAD CsrThread,
196 IN PHARDERROR_MSG HardErrorMessage
197 );
198
199 typedef
200 ULONG
201 (NTAPI *PCSR_SHUTDOWNPROCESS_CALLBACK)(
202 IN PCSR_PROCESS CsrProcess,
203 IN ULONG Flags,
204 IN BOOLEAN FirstPhase
205 );
206
207 // See http://redplait.blogspot.fr/2011/07/csrserverdll.html
208 typedef struct _CSR_SERVER_DLL
209 {
210 ULONG Length;
211 HANDLE Event;
212 ANSI_STRING Name;
213 HANDLE ServerHandle;
214 ULONG ServerId;
215 ULONG Unknown;
216 ULONG ApiBase;
217 ULONG HighestApiSupported;
218 PCSR_API_ROUTINE *DispatchTable;
219 PBOOLEAN ValidTable; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer.
220 PCHAR *NameTable;
221 ULONG SizeOfProcessData;
222 PCSR_CONNECT_CALLBACK ConnectCallback;
223 PCSR_DISCONNECT_CALLBACK DisconnectCallback;
224 PCSR_HARDERROR_CALLBACK HardErrorCallback;
225 PVOID SharedSection;
226 PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
227 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
228 ULONG Unknown2[3];
229 } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
230
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 IN PLIST_ENTRY UserWaitList OPTIONAL);
291
292 NTSTATUS
293 NTAPI
294 CsrDebugProcess(IN PCSR_PROCESS CsrProcess);
295
296 NTSTATUS
297 NTAPI
298 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess);
299
300 VOID
301 NTAPI
302 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
303
304 VOID
305 NTAPI
306 CsrDereferenceThread(IN PCSR_THREAD CsrThread);
307
308 VOID
309 NTAPI
310 CsrDereferenceWait(IN PLIST_ENTRY WaitList);
311
312 NTSTATUS
313 NTAPI
314 CsrDestroyProcess(IN PCLIENT_ID Cid,
315 IN NTSTATUS ExitStatus);
316
317 NTSTATUS
318 NTAPI
319 CsrDestroyThread(IN PCLIENT_ID Cid);
320
321 NTSTATUS
322 NTAPI
323 CsrExecServerThread(IN PVOID ThreadHandler,
324 IN ULONG Flags);
325
326 NTSTATUS
327 NTAPI
328 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
329 OUT PLUID Luid);
330
331 BOOLEAN
332 NTAPI
333 CsrImpersonateClient(IN PCSR_THREAD CsrThread);
334
335 NTSTATUS
336 NTAPI
337 CsrLockProcessByClientId(IN HANDLE Pid,
338 OUT PCSR_PROCESS *CsrProcess OPTIONAL);
339
340 NTSTATUS
341 NTAPI
342 CsrLockThreadByClientId(IN HANDLE Tid,
343 OUT PCSR_THREAD *CsrThread);
344
345 VOID
346 NTAPI
347 CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry,
348 IN PLIST_ENTRY WaitList);
349
350 BOOLEAN
351 NTAPI
352 CsrNotifyWait(IN PLIST_ENTRY WaitList,
353 IN ULONG WaitType,
354 IN PVOID WaitArgument1,
355 IN PVOID WaitArgument2);
356
357 VOID
358 NTAPI
359 CsrPopulateDosDevices(VOID);
360
361 HANDLE
362 NTAPI
363 CsrQueryApiPort(VOID);
364
365 VOID
366 NTAPI
367 CsrReferenceThread(IN PCSR_THREAD CsrThread);
368
369 BOOLEAN
370 NTAPI
371 CsrRevertToSelf(VOID);
372
373 VOID
374 NTAPI
375 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
376
377 VOID
378 NTAPI
379 CsrSetCallingSpooler(ULONG Reserved);
380
381 VOID
382 NTAPI
383 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess);
384
385 NTSTATUS
386 NTAPI
387 CsrShutdownProcesses(IN PLUID CallerLuid,
388 IN ULONG Flags);
389
390 EXCEPTION_DISPOSITION
391 NTAPI
392 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo);
393
394 NTSTATUS
395 NTAPI
396 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
397
398 NTSTATUS
399 NTAPI
400 CsrUnlockThread(IN PCSR_THREAD CsrThread);
401
402 BOOLEAN
403 NTAPI
404 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
405 IN PVOID *Buffer,
406 IN ULONG ElementCount,
407 IN ULONG ElementSize);
408
409 BOOLEAN
410 NTAPI
411 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage,
412 IN LPWSTR *MessageString);
413
414 #endif // _CSRSRV_H
415
416 /* EOF */