[CSR]: Fix header information ;)
[reactos.git] / reactos / 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.ionescu@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 #ifndef _CSRSRV_H
11 #define _CSRSRV_H
12
13 #include "csrmsg.h"
14
15
16 /* TYPES **********************************************************************/
17
18 // Used in ntdll/csr/connect.c
19 #define CSR_CSRSS_SECTION_SIZE 65536
20
21 typedef struct _CSR_NT_SESSION
22 {
23 ULONG ReferenceCount;
24 LIST_ENTRY SessionLink;
25 ULONG SessionId;
26 } CSR_NT_SESSION, *PCSR_NT_SESSION;
27
28 typedef struct _CSR_PROCESS
29 {
30 CLIENT_ID ClientId;
31 LIST_ENTRY ListLink;
32 LIST_ENTRY ThreadList;
33 PCSR_NT_SESSION NtSession;
34 ULONG ExpectedVersion;
35 HANDLE ClientPort;
36 ULONG_PTR ClientViewBase;
37 ULONG_PTR ClientViewBounds;
38 HANDLE ProcessHandle;
39 ULONG SequenceNumber;
40 ULONG Flags;
41 ULONG DebugFlags;
42 CLIENT_ID DebugCid;
43 ULONG ReferenceCount;
44 ULONG ProcessGroupId;
45 ULONG ProcessGroupSequence;
46 ULONG fVDM;
47 ULONG ThreadCount;
48 ULONG PriorityClass;
49 ULONG Reserved;
50 ULONG ShutdownLevel;
51 ULONG ShutdownFlags;
52 PVOID ServerData[ANYSIZE_ARRAY]; // One structure per CSR server.
53 } CSR_PROCESS, *PCSR_PROCESS;
54
55 typedef struct _CSR_THREAD
56 {
57 LARGE_INTEGER CreateTime;
58 LIST_ENTRY Link;
59 LIST_ENTRY HashLinks;
60 CLIENT_ID ClientId;
61 PCSR_PROCESS Process;
62 struct _CSR_WAIT_BLOCK *WaitBlock;
63 HANDLE ThreadHandle;
64 ULONG Flags;
65 ULONG ReferenceCount;
66 ULONG ImpersonationCount;
67 } CSR_THREAD, *PCSR_THREAD;
68
69 #define CsrGetClientThread() \
70 ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
71
72
73 /* ENUMERATIONS ***************************************************************/
74
75 typedef enum _CSR_PROCESS_FLAGS
76 {
77 CsrProcessTerminating = 0x1,
78 CsrProcessSkipShutdown = 0x2,
79 CsrProcessNormalPriority = 0x10,
80 CsrProcessIdlePriority = 0x20,
81 CsrProcessHighPriority = 0x40,
82 CsrProcessRealtimePriority = 0x80,
83 CsrProcessCreateNewGroup = 0x100,
84 CsrProcessTerminated = 0x200,
85 CsrProcessLastThreadTerminated = 0x400,
86 CsrProcessIsConsoleApp = 0x800
87 } CSR_PROCESS_FLAGS, *PCSR_PROCESS_FLAGS;
88
89 #define CsrProcessPriorityFlags (CsrProcessNormalPriority | \
90 CsrProcessIdlePriority | \
91 CsrProcessHighPriority | \
92 CsrProcessRealtimePriority)
93
94 typedef enum _CSR_THREAD_FLAGS
95 {
96 CsrThreadAlertable = 0x1,
97 CsrThreadInTermination = 0x2,
98 CsrThreadTerminated = 0x4,
99 CsrThreadIsServerThread = 0x10
100 } CSR_THREAD_FLAGS, *PCSR_THREAD_FLAGS;
101
102 typedef enum _SHUTDOWN_RESULT
103 {
104 CsrShutdownCsrProcess = 1,
105 CsrShutdownNonCsrProcess,
106 CsrShutdownCancelled
107 } SHUTDOWN_RESULT, *PSHUTDOWN_RESULT;
108
109 typedef enum _CSR_SHUTDOWN_FLAGS
110 {
111 CsrShutdownSystem = 4,
112 CsrShutdownOther = 8
113 } CSR_SHUTDOWN_FLAGS, *PCSR_SHUTDOWN_FLAGS;
114
115 typedef enum _CSR_DEBUG_FLAGS
116 {
117 CsrDebugOnlyThisProcess = 1,
118 CsrDebugProcessChildren = 2
119 } CSR_PROCESS_DEBUG_FLAGS, *PCSR_PROCESS_DEBUG_FLAGS;
120
121 typedef enum _CSR_REPLY_CODE
122 {
123 CsrReplyImmediately = 0,
124 CsrReplyPending = 1,
125 CsrReplyDeadClient = 2,
126 CsrReplyAlreadySent = 3
127 } CSR_REPLY_CODE, *PCSR_REPLY_CODE;
128
129
130 /* FUNCTION TYPES AND STRUCTURES **********************************************/
131
132 /*
133 * Wait block
134 */
135 typedef
136 BOOLEAN
137 (*CSR_WAIT_FUNCTION)(
138 IN PLIST_ENTRY WaitList,
139 IN PCSR_THREAD WaitThread,
140 IN PCSR_API_MESSAGE WaitApiMessage,
141 IN PVOID WaitContext,
142 IN PVOID WaitArgument1,
143 IN PVOID WaitArgument2,
144 IN ULONG WaitFlags
145 );
146
147 typedef struct _CSR_WAIT_BLOCK
148 {
149 ULONG Size; // Size of the wait block (variable-sized)
150 LIST_ENTRY WaitList;
151 LIST_ENTRY UserWaitList;
152 PVOID WaitContext;
153 PCSR_THREAD WaitThread;
154 CSR_WAIT_FUNCTION WaitFunction;
155 CSR_API_MESSAGE WaitApiMessage; // Variable-sized CSR API message
156 } CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
157
158
159 /*
160 * Server DLL structure
161 */
162 typedef
163 NTSTATUS
164 (NTAPI *PCSR_API_ROUTINE)(
165 IN OUT PCSR_API_MESSAGE ApiMessage,
166 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
167 );
168
169 #define CSR_API(n) \
170 NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
171 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
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 // See http://redplait.blogspot.fr/2011/07/csrserverdll.html
208 typedef struct _CSR_SERVER_DLL
209 {
210 ULONG Length;
211 ANSI_STRING Name;
212 HANDLE ServerHandle;
213 ULONG ServerId;
214 ULONG Unknown;
215 ULONG ApiBase;
216 ULONG HighestApiSupported;
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;
225 PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
226 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
227 ULONG Unknown2[3];
228 } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
229 C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x3C);
230
231 typedef
232 NTSTATUS
233 (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll);
234
235 #define CSR_SERVER_DLL_INIT(n) \
236 NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
237
238
239 /* PROTOTYPES ****************************************************************/
240
241 NTSTATUS
242 NTAPI
243 CsrServerInitialization(IN ULONG ArgumentCount,
244 IN PCHAR Arguments[]);
245
246 PCSR_THREAD
247 NTAPI
248 CsrAddStaticServerThread(IN HANDLE hThread,
249 IN PCLIENT_ID ClientId,
250 IN ULONG ThreadFlags);
251
252 NTSTATUS
253 NTAPI
254 CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
255 IN OUT PCSR_API_MESSAGE ReplyMsg);
256
257 PCSR_THREAD
258 NTAPI
259 CsrConnectToUser(VOID);
260
261 NTSTATUS
262 NTAPI
263 CsrCreateProcess(IN HANDLE hProcess,
264 IN HANDLE hThread,
265 IN PCLIENT_ID ClientId,
266 IN PCSR_NT_SESSION NtSession,
267 IN ULONG Flags,
268 IN PCLIENT_ID DebugCid);
269
270 NTSTATUS
271 NTAPI
272 CsrCreateRemoteThread(IN HANDLE hThread,
273 IN PCLIENT_ID ClientId);
274
275 NTSTATUS
276 NTAPI
277 CsrCreateThread(IN PCSR_PROCESS CsrProcess,
278 IN HANDLE hThread,
279 IN PCLIENT_ID ClientId,
280 IN BOOLEAN HaveClient);
281
282 BOOLEAN
283 NTAPI
284 CsrCreateWait(IN PLIST_ENTRY WaitList,
285 IN CSR_WAIT_FUNCTION WaitFunction,
286 IN PCSR_THREAD CsrWaitThread,
287 IN OUT PCSR_API_MESSAGE WaitApiMessage,
288 IN PVOID WaitContext,
289 IN PLIST_ENTRY UserWaitList OPTIONAL);
290
291 NTSTATUS
292 NTAPI
293 CsrDebugProcess(IN PCSR_PROCESS CsrProcess);
294
295 NTSTATUS
296 NTAPI
297 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess);
298
299 VOID
300 NTAPI
301 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
302
303 VOID
304 NTAPI
305 CsrDereferenceThread(IN PCSR_THREAD CsrThread);
306
307 VOID
308 NTAPI
309 CsrDereferenceWait(IN PLIST_ENTRY WaitList);
310
311 NTSTATUS
312 NTAPI
313 CsrDestroyProcess(IN PCLIENT_ID Cid,
314 IN NTSTATUS ExitStatus);
315
316 NTSTATUS
317 NTAPI
318 CsrDestroyThread(IN PCLIENT_ID Cid);
319
320 NTSTATUS
321 NTAPI
322 CsrExecServerThread(IN PVOID ThreadHandler,
323 IN ULONG Flags);
324
325 NTSTATUS
326 NTAPI
327 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
328 OUT PLUID Luid);
329
330 BOOLEAN
331 NTAPI
332 CsrImpersonateClient(IN PCSR_THREAD CsrThread);
333
334 NTSTATUS
335 NTAPI
336 CsrLockProcessByClientId(IN HANDLE Pid,
337 OUT PCSR_PROCESS *CsrProcess OPTIONAL);
338
339 NTSTATUS
340 NTAPI
341 CsrLockThreadByClientId(IN HANDLE Tid,
342 OUT PCSR_THREAD *CsrThread);
343
344 VOID
345 NTAPI
346 CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry,
347 IN PLIST_ENTRY WaitList);
348
349 BOOLEAN
350 NTAPI
351 CsrNotifyWait(IN PLIST_ENTRY WaitList,
352 IN ULONG WaitType,
353 IN PVOID WaitArgument1,
354 IN PVOID WaitArgument2);
355
356 VOID
357 NTAPI
358 CsrPopulateDosDevices(VOID);
359
360 HANDLE
361 NTAPI
362 CsrQueryApiPort(VOID);
363
364 VOID
365 NTAPI
366 CsrReferenceThread(IN PCSR_THREAD CsrThread);
367
368 BOOLEAN
369 NTAPI
370 CsrRevertToSelf(VOID);
371
372 VOID
373 NTAPI
374 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
375
376 VOID
377 NTAPI
378 CsrSetCallingSpooler(ULONG Reserved);
379
380 VOID
381 NTAPI
382 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess);
383
384 NTSTATUS
385 NTAPI
386 CsrShutdownProcesses(IN PLUID CallerLuid,
387 IN ULONG Flags);
388
389 EXCEPTION_DISPOSITION
390 NTAPI
391 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo);
392
393 NTSTATUS
394 NTAPI
395 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
396
397 NTSTATUS
398 NTAPI
399 CsrUnlockThread(IN PCSR_THREAD CsrThread);
400
401 BOOLEAN
402 NTAPI
403 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
404 IN PVOID *Buffer,
405 IN ULONG ElementCount,
406 IN ULONG ElementSize);
407
408 BOOLEAN
409 NTAPI
410 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage,
411 IN LPWSTR *MessageString);
412
413 #endif // _CSRSRV_H
414
415 /* EOF */