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