[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 /* 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 NTSTATUS
251 NTAPI
252 CsrServerInitialization(IN ULONG ArgumentCount,
253 IN PCHAR Arguments[]);
254
255 PCSR_THREAD
256 NTAPI
257 CsrAddStaticServerThread(IN HANDLE hThread,
258 IN PCLIENT_ID ClientId,
259 IN ULONG ThreadFlags);
260
261 NTSTATUS
262 NTAPI
263 CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
264 IN OUT PCSR_API_MESSAGE ReplyMsg);
265
266 PCSR_THREAD
267 NTAPI
268 CsrConnectToUser(VOID);
269
270 NTSTATUS
271 NTAPI
272 CsrCreateProcess(IN HANDLE hProcess,
273 IN HANDLE hThread,
274 IN PCLIENT_ID ClientId,
275 IN PCSR_NT_SESSION NtSession,
276 IN ULONG Flags,
277 IN PCLIENT_ID DebugCid);
278
279 NTSTATUS
280 NTAPI
281 CsrCreateRemoteThread(IN HANDLE hThread,
282 IN PCLIENT_ID ClientId);
283
284 NTSTATUS
285 NTAPI
286 CsrCreateThread(IN PCSR_PROCESS CsrProcess,
287 IN HANDLE hThread,
288 IN PCLIENT_ID ClientId,
289 IN BOOLEAN HaveClient);
290
291 BOOLEAN
292 NTAPI
293 CsrCreateWait(IN PLIST_ENTRY WaitList,
294 IN CSR_WAIT_FUNCTION WaitFunction,
295 IN PCSR_THREAD CsrWaitThread,
296 IN OUT PCSR_API_MESSAGE WaitApiMessage,
297 IN PVOID WaitContext,
298 IN PLIST_ENTRY UserWaitList OPTIONAL);
299
300 NTSTATUS
301 NTAPI
302 CsrDebugProcess(IN PCSR_PROCESS CsrProcess);
303
304 NTSTATUS
305 NTAPI
306 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess);
307
308 VOID
309 NTAPI
310 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
311
312 VOID
313 NTAPI
314 CsrDereferenceThread(IN PCSR_THREAD CsrThread);
315
316 VOID
317 NTAPI
318 CsrDereferenceWait(IN PLIST_ENTRY WaitList);
319
320 NTSTATUS
321 NTAPI
322 CsrDestroyProcess(IN PCLIENT_ID Cid,
323 IN NTSTATUS ExitStatus);
324
325 NTSTATUS
326 NTAPI
327 CsrDestroyThread(IN PCLIENT_ID Cid);
328
329 NTSTATUS
330 NTAPI
331 CsrExecServerThread(IN PVOID ThreadHandler,
332 IN ULONG Flags);
333
334 NTSTATUS
335 NTAPI
336 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
337 OUT PLUID Luid);
338
339 BOOLEAN
340 NTAPI
341 CsrImpersonateClient(IN PCSR_THREAD CsrThread);
342
343 NTSTATUS
344 NTAPI
345 CsrLockProcessByClientId(IN HANDLE Pid,
346 OUT PCSR_PROCESS *CsrProcess OPTIONAL);
347
348 NTSTATUS
349 NTAPI
350 CsrLockThreadByClientId(IN HANDLE Tid,
351 OUT PCSR_THREAD *CsrThread);
352
353 VOID
354 NTAPI
355 CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry,
356 IN PLIST_ENTRY WaitList);
357
358 BOOLEAN
359 NTAPI
360 CsrNotifyWait(IN PLIST_ENTRY WaitList,
361 IN ULONG WaitType,
362 IN PVOID WaitArgument1,
363 IN PVOID WaitArgument2);
364
365 VOID
366 NTAPI
367 CsrPopulateDosDevices(VOID);
368
369 HANDLE
370 NTAPI
371 CsrQueryApiPort(VOID);
372
373 VOID
374 NTAPI
375 CsrReferenceThread(IN PCSR_THREAD CsrThread);
376
377 BOOLEAN
378 NTAPI
379 CsrRevertToSelf(VOID);
380
381 VOID
382 NTAPI
383 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
384
385 VOID
386 NTAPI
387 CsrSetCallingSpooler(ULONG Reserved);
388
389 VOID
390 NTAPI
391 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess);
392
393 NTSTATUS
394 NTAPI
395 CsrShutdownProcesses(IN PLUID CallerLuid,
396 IN ULONG Flags);
397
398 EXCEPTION_DISPOSITION
399 NTAPI
400 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo);
401
402 NTSTATUS
403 NTAPI
404 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
405
406 NTSTATUS
407 NTAPI
408 CsrUnlockThread(IN PCSR_THREAD CsrThread);
409
410 BOOLEAN
411 NTAPI
412 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
413 IN PVOID *Buffer,
414 IN ULONG ElementCount,
415 IN ULONG ElementSize);
416
417 BOOLEAN
418 NTAPI
419 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage,
420 IN LPWSTR *MessageString);
421
422 /*
423 #ifdef _MSC_VER
424 #pragma warning(pop)
425 #endif
426 */
427
428 #endif // _CSRSRV_H
429
430 /* EOF */