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