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