[NTDLL]
[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 typedef struct _CSR_PROCESS
37 {
38 CLIENT_ID ClientId;
39 LIST_ENTRY ListLink;
40 LIST_ENTRY ThreadList;
41 struct _CSR_PROCESS *Parent;
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 CsrThreadAltertable = 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
131 /*
132 * Wait block
133 */
134 typedef
135 BOOLEAN
136 (*CSR_WAIT_FUNCTION)(
137 IN PLIST_ENTRY WaitList,
138 IN PCSR_THREAD WaitThread,
139 IN PCSR_API_MESSAGE WaitApiMessage,
140 IN PVOID WaitContext,
141 IN PVOID WaitArgument1,
142 IN PVOID WaitArgument2,
143 IN ULONG WaitFlags
144 );
145
146 typedef struct _CSR_WAIT_BLOCK
147 {
148 ULONG Size;
149 LIST_ENTRY WaitList;
150 LIST_ENTRY UserWaitList;
151 PVOID WaitContext;
152 PCSR_THREAD WaitThread;
153 CSR_WAIT_FUNCTION WaitFunction;
154 CSR_API_MESSAGE WaitApiMessage;
155 } CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
156
157
158 /*
159 * Server DLL structure
160 */
161 typedef
162 NTSTATUS
163 (NTAPI *PCSR_API_ROUTINE)(
164 IN OUT PCSR_API_MESSAGE ApiMessage,
165 OUT PULONG Reply
166 );
167
168 #define CSR_API(n) \
169 NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
170 OUT PULONG Reply)
171 // IN OUT PCSR_REPLY_STATUS ReplyStatus)
172
173 typedef
174 NTSTATUS
175 (NTAPI *PCSR_CONNECT_CALLBACK)(
176 IN PCSR_PROCESS CsrProcess,
177 IN OUT PVOID ConnectionInfo,
178 IN OUT PULONG ConnectionInfoLength
179 );
180
181 typedef
182 VOID
183 (NTAPI *PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess);
184
185 typedef
186 NTSTATUS
187 (NTAPI *PCSR_NEWPROCESS_CALLBACK)(
188 IN PCSR_PROCESS Parent,
189 IN PCSR_PROCESS CsrProcess
190 );
191
192 typedef
193 VOID
194 (NTAPI *PCSR_HARDERROR_CALLBACK)(
195 IN PCSR_THREAD CsrThread,
196 IN PHARDERROR_MSG HardErrorMessage
197 );
198
199 typedef
200 ULONG
201 (NTAPI *PCSR_SHUTDOWNPROCESS_CALLBACK)(
202 IN PCSR_PROCESS CsrProcess,
203 IN ULONG Flags,
204 IN BOOLEAN FirstPhase
205 );
206
207 typedef struct _CSR_SERVER_DLL
208 {
209 ULONG Length;
210 HANDLE Event;
211 ANSI_STRING Name;
212 HANDLE ServerHandle;
213 ULONG ServerId;
214 ULONG Unknown;
215 ULONG ApiBase; // ApiNumberBase
216 ULONG HighestApiSupported; // MaxApiNumber
217 PCSR_API_ROUTINE *DispatchTable;
218 PBOOLEAN ValidTable; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer.
219 PCHAR *NameTable;
220 ULONG SizeOfProcessData;
221 PCSR_CONNECT_CALLBACK ConnectCallback;
222 PCSR_DISCONNECT_CALLBACK DisconnectCallback;
223 PCSR_HARDERROR_CALLBACK HardErrorCallback;
224 PVOID SharedSection; // SharedStaticServerData
225 PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
226 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
227 ULONG Unknown2[3];
228 } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
229
230
231 /* FUNCTION TYPES *************************************************************/
232
233 typedef
234 NTSTATUS
235 (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll);
236
237 #define CSR_SERVER_DLL_INIT(n) \
238 NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
239
240
241 /* PROTOTYPES ****************************************************************/
242
243 ///////////
244 BOOLEAN
245 NTAPI
246 CsrCaptureArguments(IN PCSR_THREAD CsrThread,
247 IN PCSR_API_MESSAGE ApiMessage);
248
249 VOID
250 NTAPI
251 CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
252 //////////
253
254
255
256 NTSTATUS
257 NTAPI
258 CsrServerInitialization(IN ULONG ArgumentCount,
259 IN PCHAR Arguments[]);
260
261 PCSR_THREAD
262 NTAPI
263 CsrAddStaticServerThread(IN HANDLE hThread,
264 IN PCLIENT_ID ClientId,
265 IN ULONG ThreadFlags);
266
267 NTSTATUS
268 NTAPI
269 CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
270 IN OUT PCSR_API_MESSAGE ReplyMsg);
271
272 PCSR_THREAD
273 NTAPI
274 CsrConnectToUser(VOID);
275
276 NTSTATUS
277 NTAPI
278 CsrCreateProcess(IN HANDLE hProcess,
279 IN HANDLE hThread,
280 IN PCLIENT_ID ClientId,
281 IN PCSR_NT_SESSION NtSession,
282 IN ULONG Flags,
283 IN PCLIENT_ID DebugCid);
284
285 NTSTATUS
286 NTAPI
287 CsrCreateRemoteThread(IN HANDLE hThread,
288 IN PCLIENT_ID ClientId);
289
290 NTSTATUS
291 NTAPI
292 CsrCreateThread(IN PCSR_PROCESS CsrProcess,
293 IN HANDLE hThread,
294 IN PCLIENT_ID ClientId,
295 IN BOOLEAN HaveClient);
296
297 BOOLEAN
298 NTAPI
299 CsrCreateWait(IN PLIST_ENTRY WaitList,
300 IN CSR_WAIT_FUNCTION WaitFunction,
301 IN PCSR_THREAD CsrWaitThread,
302 IN OUT PCSR_API_MESSAGE WaitApiMessage,
303 IN PVOID WaitContext,
304 IN PLIST_ENTRY UserWaitList OPTIONAL);
305
306 NTSTATUS
307 NTAPI
308 CsrDebugProcess(IN PCSR_PROCESS CsrProcess);
309
310 NTSTATUS
311 NTAPI
312 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess);
313
314 VOID
315 NTAPI
316 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
317
318 VOID
319 NTAPI
320 CsrDereferenceThread(IN PCSR_THREAD CsrThread);
321
322 VOID
323 NTAPI
324 CsrDereferenceWait(IN PLIST_ENTRY WaitList);
325
326 NTSTATUS
327 NTAPI
328 CsrDestroyProcess(IN PCLIENT_ID Cid,
329 IN NTSTATUS ExitStatus);
330
331 NTSTATUS
332 NTAPI
333 CsrDestroyThread(IN PCLIENT_ID Cid);
334
335 NTSTATUS
336 NTAPI
337 CsrExecServerThread(IN PVOID ThreadHandler,
338 IN ULONG Flags);
339
340 NTSTATUS
341 NTAPI
342 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
343 OUT PLUID Luid);
344
345 BOOLEAN
346 NTAPI
347 CsrImpersonateClient(IN PCSR_THREAD CsrThread);
348
349 NTSTATUS
350 NTAPI
351 CsrLockProcessByClientId(IN HANDLE Pid,
352 OUT PCSR_PROCESS *CsrProcess OPTIONAL);
353
354 NTSTATUS
355 NTAPI
356 CsrLockThreadByClientId(IN HANDLE Tid,
357 OUT PCSR_THREAD *CsrThread);
358
359 VOID
360 NTAPI
361 CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry,
362 IN PLIST_ENTRY WaitList);
363
364 BOOLEAN
365 NTAPI
366 CsrNotifyWait(IN PLIST_ENTRY WaitList,
367 IN ULONG WaitType,
368 IN PVOID WaitArgument1,
369 IN PVOID WaitArgument2);
370
371 VOID
372 NTAPI
373 CsrPopulateDosDevices(VOID);
374
375 HANDLE
376 NTAPI
377 CsrQueryApiPort(VOID);
378
379 VOID
380 NTAPI
381 CsrReferenceThread(IN PCSR_THREAD CsrThread);
382
383 BOOLEAN
384 NTAPI
385 CsrRevertToSelf(VOID);
386
387 VOID
388 NTAPI
389 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
390
391 VOID
392 NTAPI
393 CsrSetCallingSpooler(ULONG Reserved);
394
395 VOID
396 NTAPI
397 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess);
398
399 NTSTATUS
400 NTAPI
401 CsrShutdownProcesses(IN PLUID CallerLuid,
402 IN ULONG Flags);
403
404 EXCEPTION_DISPOSITION
405 NTAPI
406 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo);
407
408 NTSTATUS
409 NTAPI
410 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
411
412 NTSTATUS
413 NTAPI
414 CsrUnlockThread(IN PCSR_THREAD CsrThread);
415
416 BOOLEAN
417 NTAPI
418 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
419 IN PVOID *Buffer,
420 IN ULONG ElementCount,
421 IN ULONG ElementSize);
422
423 BOOLEAN
424 NTAPI
425 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage,
426 IN LPWSTR *MessageString);
427
428 /*
429 #ifdef _MSC_VER
430 #pragma warning(pop)
431 #endif
432 */
433
434 #endif // _CSRSRV_H
435
436 /* EOF */