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