ReactOS  0.4.13-dev-247-g0f29b3f
csrsrv.h
Go to the documentation of this file.
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 /*
14  * The CSR_DBG macro is defined for building CSR Servers
15  * with extended debugging information.
16  */
17 #if DBG
18 #define CSR_DBG
19 #endif
20 
21 #include "csrmsg.h"
22 
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 {
35 
36 typedef struct _CSR_PROCESS
37 {
60  PVOID ServerData[ANYSIZE_ARRAY]; // One structure per CSR server.
62 
63 typedef struct _CSR_THREAD
64 {
76 
77 #define CsrGetClientThread() \
78  ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
79 
80 
81 /* ENUMERATIONS ***************************************************************/
82 
83 typedef enum _CSR_PROCESS_FLAGS
84 {
96 
97 #define CsrProcessPriorityFlags (CsrProcessNormalPriority | \
98  CsrProcessIdlePriority | \
99  CsrProcessHighPriority | \
100  CsrProcessRealtimePriority)
101 
102 typedef enum _CSR_THREAD_FLAGS
103 {
109 
110 typedef enum _SHUTDOWN_RESULT
111 {
116 
118 {
122 
123 typedef enum _CSR_DEBUG_FLAGS
124 {
128 
129 typedef enum _CSR_REPLY_CODE
130 {
136 
137 
138 /* FUNCTION TYPES AND STRUCTURES **********************************************/
139 
140 /*
141  * Wait block
142  */
143 typedef
144 BOOLEAN
150  IN PVOID WaitArgument1,
151  IN PVOID WaitArgument2,
152  IN ULONG WaitFlags
153 );
154 
155 typedef struct _CSR_WAIT_BLOCK
156 {
157  ULONG Size; // Size of the wait block (variable-sized)
162  CSR_API_MESSAGE WaitApiMessage; // Variable-sized CSR API message
164 
165 
166 /*
167  * Server DLL structure
168  */
169 typedef
170 NTSTATUS
172  IN OUT PCSR_API_MESSAGE ApiMessage,
173  IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
174 );
175 
176 #define CSR_API(n) \
177  NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
178  IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
179 
180 typedef
181 NTSTATUS
183  IN PCSR_PROCESS CsrProcess,
184  IN OUT PVOID ConnectionInfo,
185  IN OUT PULONG ConnectionInfoLength
186 );
187 
188 typedef
189 VOID
191 
192 typedef
193 NTSTATUS
196  IN PCSR_PROCESS CsrProcess
197 );
198 
199 typedef
200 VOID
202  IN PCSR_THREAD CsrThread,
203  IN PHARDERROR_MSG HardErrorMessage
204 );
205 
206 typedef
207 ULONG
209  IN PCSR_PROCESS CsrProcess,
210  IN ULONG Flags,
211  IN BOOLEAN FirstPhase
212 );
213 
214 // See http://redplait.blogspot.fr/2011/07/csrserverdll.html
215 typedef struct _CSR_SERVER_DLL
216 {
225  PBOOLEAN ValidTable; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer.
226 /*
227  * On Windows Server 2003, CSR Servers contain
228  * the API Names Table only in Debug Builds.
229  */
230 #ifdef CSR_DBG
231  PCHAR *NameTable;
232 #endif
233 
243 #ifndef _WIN64
244  #ifdef CSR_DBG
245  C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x3C);
246  #else
247  C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x38);
248  #endif
249 #endif
250 
251 typedef
252 NTSTATUS
254 
255 #define CSR_SERVER_DLL_INIT(n) \
256  NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
257 
258 
259 /* PROTOTYPES ****************************************************************/
260 
261 NTSTATUS
262 NTAPI
263 CsrServerInitialization(IN ULONG ArgumentCount,
264  IN PCHAR Arguments[]);
265 
267 NTAPI
270  IN ULONG ThreadFlags);
271 
272 NTSTATUS
273 NTAPI
275  IN OUT PCSR_API_MESSAGE ReplyMsg);
276 
278 NTAPI
280 
281 NTSTATUS
282 NTAPI
284  IN HANDLE hThread,
286  IN PCSR_NT_SESSION NtSession,
287  IN ULONG Flags,
288  IN PCLIENT_ID DebugCid);
289 
290 NTSTATUS
291 NTAPI
294 
295 NTSTATUS
296 NTAPI
297 CsrCreateThread(IN PCSR_PROCESS CsrProcess,
298  IN HANDLE hThread,
300  IN BOOLEAN HaveClient);
301 
302 BOOLEAN
303 NTAPI
304 CsrCreateWait(IN PLIST_ENTRY WaitList,
305  IN CSR_WAIT_FUNCTION WaitFunction,
306  IN PCSR_THREAD CsrWaitThread,
307  IN OUT PCSR_API_MESSAGE WaitApiMessage,
308  IN PVOID WaitContext);
309 
310 NTSTATUS
311 NTAPI
312 CsrDebugProcess(IN PCSR_PROCESS CsrProcess);
313 
314 NTSTATUS
315 NTAPI
317 
318 VOID
319 NTAPI
321 
322 VOID
323 NTAPI
325 
326 VOID
327 NTAPI
329 
330 NTSTATUS
331 NTAPI
334 
335 NTSTATUS
336 NTAPI
338 
339 NTSTATUS
340 NTAPI
341 CsrExecServerThread(IN PVOID ThreadHandler,
342  IN ULONG Flags);
343 
344 NTSTATUS
345 NTAPI
347  OUT PLUID Luid);
348 
349 BOOLEAN
350 NTAPI
352 
353 NTSTATUS
354 NTAPI
356  OUT PCSR_PROCESS *CsrProcess OPTIONAL);
357 
358 NTSTATUS
359 NTAPI
361  OUT PCSR_THREAD *CsrThread);
362 
363 VOID
364 NTAPI
365 CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList,
366  IN PLIST_ENTRY WaitList);
367 
368 BOOLEAN
369 NTAPI
370 CsrNotifyWait(IN PLIST_ENTRY WaitList,
371  IN BOOLEAN NotifyAll,
372  IN PVOID WaitArgument1,
373  IN PVOID WaitArgument2);
374 
375 VOID
376 NTAPI
378 
379 HANDLE
380 NTAPI
382 
383 VOID
384 NTAPI
386 
387 BOOLEAN
388 NTAPI
390 
391 VOID
392 NTAPI
394 
395 VOID
396 NTAPI
398 
399 VOID
400 NTAPI
402 
403 NTSTATUS
404 NTAPI
405 CsrShutdownProcesses(IN PLUID CallerLuid,
406  IN ULONG Flags);
407 
409 NTAPI
411 
412 NTSTATUS
413 NTAPI
414 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
415 
416 NTSTATUS
417 NTAPI
418 CsrUnlockThread(IN PCSR_THREAD CsrThread);
419 
420 BOOLEAN
421 NTAPI
423  IN PVOID *Buffer,
424  IN ULONG ElementCount,
425  IN ULONG ElementSize);
426 
427 BOOLEAN
428 NTAPI
430  IN LPWSTR *MessageString);
431 
432 #endif // _CSRSRV_H
433 
434 /* EOF */
ULONG HighestApiSupported
Definition: csrsrv.h:223
_SHUTDOWN_RESULT
Definition: csrsrv.h:110
ULONG DebugFlags
Definition: csrsrv.h:49
signed char * PCHAR
Definition: retypes.h:7
struct _CSR_NT_SESSION * PCSR_NT_SESSION
#define IN
Definition: typedefs.h:38
ULONG Size
Definition: csrsrv.h:157
enum _SHUTDOWN_RESULT SHUTDOWN_RESULT
PCSR_CONNECT_CALLBACK ConnectCallback
Definition: csrsrv.h:235
enum _CSR_PROCESS_FLAGS CSR_PROCESS_FLAGS
ULONG SizeOfProcessData
Definition: csrsrv.h:234
enum _CSR_THREAD_FLAGS CSR_THREAD_FLAGS
PCSR_THREAD WaitThread
Definition: csrsrv.h:160
enum _CSR_SHUTDOWN_FLAGS * PCSR_SHUTDOWN_FLAGS
#define ANYSIZE_ARRAY
Definition: typedefs.h:45
enum _CSR_THREAD_FLAGS * PCSR_THREAD_FLAGS
ULONG Reserved
Definition: csrsrv.h:57
NTSTATUS NTAPI CsrExecServerThread(IN PVOID ThreadHandler, IN ULONG Flags)
Definition: thredsup.c:885
enum _CSR_PROCESS_FLAGS * PCSR_PROCESS_FLAGS
LIST_ENTRY WaitList
Definition: csrsrv.h:158
LONG NTSTATUS
Definition: precomp.h:26
enum _CSR_DEBUG_FLAGS * PCSR_PROCESS_DEBUG_FLAGS
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1315
enum _CSR_REPLY_CODE * PCSR_REPLY_CODE
BOOLEAN NTAPI CsrRevertToSelf(VOID)
Definition: procsup.c:1048
LIST_ENTRY Link
Definition: csrsrv.h:66
ULONG ShutdownFlags
Definition: csrsrv.h:59
NTSTATUS NTAPI CsrDestroyProcess(IN PCLIENT_ID Cid, IN NTSTATUS ExitStatus)
Definition: procsup.c:734
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
ULONG_PTR ClientViewBounds
Definition: csrsrv.h:45
VOID NTAPI CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:690
ANSI_STRING Name
Definition: csrsrv.h:218
ULONG ReferenceCount
Definition: csrsrv.h:73
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:716
VOID NTAPI CsrDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:775
_CSR_PROCESS_FLAGS
Definition: csrsrv.h:83
_CSR_SHUTDOWN_FLAGS
Definition: csrsrv.h:117
BOOLEAN NTAPI CsrNotifyWait(IN PLIST_ENTRY WaitList, IN BOOLEAN NotifyAll, IN PVOID WaitArgument1, IN PVOID WaitArgument2)
Definition: wait.c:388
struct _CSR_PROCESS CSR_PROCESS
NTSTATUS(NTAPI * PCSR_CONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess, IN OUT PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoLength)
Definition: csrsrv.h:182
uint32_t ULONG_PTR
Definition: typedefs.h:63
EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: server.c:606
PCSR_PROCESS Process
Definition: csrsrv.h:69
NTSTATUS NTAPI CsrServerInitialization(IN ULONG ArgumentCount, IN PCHAR Arguments[])
Definition: init.c:965
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
PCSR_DISCONNECT_CALLBACK DisconnectCallback
Definition: csrsrv.h:236
BOOLEAN NTAPI CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage, IN LPWSTR *MessageString)
Definition: api.c:1403
PCSR_THREAD NTAPI CsrAddStaticServerThread(IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
Definition: thredsup.c:511
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VOID(NTAPI * PCSR_HARDERROR_CALLBACK)(IN PCSR_THREAD CsrThread, IN PHARDERROR_MSG HardErrorMessage)
Definition: csrsrv.h:201
ULONG ReferenceCount
Definition: csrsrv.h:51
NTSTATUS(NTAPI * PCSR_API_ROUTINE)(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
Definition: csrsrv.h:171
ULONG ImpersonationCount
Definition: csrsrv.h:74
NTSTATUS NTAPI CsrShutdownProcesses(IN PLUID CallerLuid, IN ULONG Flags)
Definition: procsup.c:1268
ULONG(NTAPI * PCSR_SHUTDOWNPROCESS_CALLBACK)(IN PCSR_PROCESS CsrProcess, IN ULONG Flags, IN BOOLEAN FirstPhase)
Definition: csrsrv.h:208
CLIENT_ID DebugCid
Definition: csrsrv.h:50
HANDLE ProcessHandle
Definition: csrsrv.h:46
unsigned char BOOLEAN
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
Definition: bufpool.h:45
CLIENT_ID ClientId
Definition: csrsrv.h:38
VOID(NTAPI * PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess)
Definition: csrsrv.h:190
ULONG ThreadCount
Definition: csrsrv.h:55
VOID NTAPI CsrSetCallingSpooler(ULONG Reserved)
Definition: server.c:583
ULONG ServerId
Definition: csrsrv.h:220
ULONG fVDM
Definition: csrsrv.h:54
HANDLE ServerHandle
Definition: csrsrv.h:219
NTSTATUS NTAPI CsrUnlockThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:1074
struct _CSR_WAIT_BLOCK * PCSR_WAIT_BLOCK
LIST_ENTRY ListLink
Definition: csrsrv.h:39
VOID NTAPI CsrReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:1042
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
enum _CSR_DEBUG_FLAGS CSR_PROCESS_DEBUG_FLAGS
PVOID ServerData[ANYSIZE_ARRAY]
Definition: csrsrv.h:60
ULONG Unknown2[3]
Definition: csrsrv.h:241
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
CLIENT_ID ClientId
Definition: csrsrv.h:68
VOID NTAPI CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1129
ULONG SequenceNumber
Definition: csrsrv.h:47
NTSTATUS NTAPI CsrLockThreadByClientId(IN HANDLE Tid, OUT PCSR_THREAD *CsrThread)
Definition: thredsup.c:964
struct _CSR_PROCESS * PCSR_PROCESS
ULONG Unknown
Definition: csrsrv.h:221
VOID NTAPI CsrPopulateDosDevices(VOID)
Definition: init.c:1089
ULONG ProcessGroupSequence
Definition: csrsrv.h:53
enum _SHUTDOWN_RESULT * PSHUTDOWN_RESULT
NTSTATUS NTAPI CsrDebugProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:642
struct _CSR_THREAD CSR_THREAD
VOID NTAPI CsrDereferenceWait(IN PLIST_ENTRY WaitList)
Definition: wait.c:266
NTSTATUS NTAPI CsrCreateThread(IN PCSR_PROCESS CsrProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN BOOLEAN HaveClient)
Definition: thredsup.c:677
HANDLE ThreadHandle
Definition: csrsrv.h:71
PCSR_HARDERROR_CALLBACK HardErrorCallback
Definition: csrsrv.h:237
LIST_ENTRY HashLinks
Definition: csrsrv.h:67
char * PBOOLEAN
Definition: retypes.h:11
NTSTATUS NTAPI CsrCreateRemoteThread(IN HANDLE hThread, IN PCLIENT_ID ClientId)
Definition: thredsup.c:568
VOID NTAPI CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList, IN PLIST_ENTRY WaitList)
Definition: wait.c:330
struct _CSR_WAIT_BLOCK CSR_WAIT_BLOCK
NTSTATUS NTAPI CsrDestroyThread(IN PCLIENT_ID Cid)
Definition: thredsup.c:813
#define NTSTATUS
Definition: precomp.h:20
#define VOID
Definition: acefi.h:82
PVOID SharedSection
Definition: csrsrv.h:238
C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection)==0x38)
ULONG Length
Definition: csrsrv.h:217
_CSR_DEBUG_FLAGS
Definition: csrsrv.h:123
Definition: typedefs.h:117
struct _CSR_SERVER_DLL * PCSR_SERVER_DLL
NTSTATUS(NTAPI * PCSR_NEWPROCESS_CALLBACK)(IN PCSR_PROCESS Parent, IN PCSR_PROCESS CsrProcess)
Definition: csrsrv.h:194
PCSR_NT_SESSION NtSession
Definition: csrsrv.h:41
PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
Definition: csrsrv.h:240
ULONG ApiBase
Definition: csrsrv.h:222
LIST_ENTRY SessionLink
Definition: csrsrv.h:32
struct _CSR_SERVER_DLL CSR_SERVER_DLL
CSR_WAIT_FUNCTION WaitFunction
Definition: csrsrv.h:161
HANDLE ClientPort
Definition: csrsrv.h:43
PVOID WaitContext
Definition: csrsrv.h:159
struct _CSR_THREAD * PCSR_THREAD
PCSR_THREAD NTAPI CsrConnectToUser(VOID)
Definition: api.c:1003
CSR_API_MESSAGE WaitApiMessage
Definition: csrsrv.h:162
NTSTATUS NTAPI CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL, OUT PLUID Luid)
Definition: procsup.c:827
struct _CSR_WAIT_BLOCK * WaitBlock
Definition: csrsrv.h:70
_CSR_REPLY_CODE
Definition: csrsrv.h:129
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
struct _CSR_NT_SESSION CSR_NT_SESSION
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:861
ULONG ProcessGroupId
Definition: csrsrv.h:52
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
enum _CSR_REPLY_CODE CSR_REPLY_CODE
#define OPTIONAL
Definition: typedefs.h:40
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg, IN OUT PCSR_API_MESSAGE ReplyMsg)
Definition: api.c:51
enum _CSR_SHUTDOWN_FLAGS CSR_SHUTDOWN_FLAGS
NTSTATUS NTAPI CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:666
HANDLE hThread
Definition: wizard.c:27
PCSR_API_ROUTINE * DispatchTable
Definition: csrsrv.h:224
ULONG PriorityClass
Definition: csrsrv.h:56
#define BOOLEAN
Definition: pedump.c:73
#define OUT
Definition: typedefs.h:39
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1098
unsigned int ULONG
Definition: retypes.h:1
enum _EXCEPTION_DISPOSITION EXCEPTION_DISPOSITION
BOOLEAN NTAPI CsrImpersonateClient(IN PCSR_THREAD CsrThread)
Definition: procsup.c:925
BOOLEAN(NTAPI * CSR_WAIT_FUNCTION)(IN PLIST_ENTRY WaitList, IN PCSR_THREAD WaitThread, IN PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags)
Definition: csrsrv.h:145
ULONG Flags
Definition: csrsrv.h:48
ULONG Flags
Definition: csrsrv.h:72
ULONG ShutdownLevel
Definition: csrsrv.h:58
NTSTATUS(NTAPI * PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll)
Definition: csrsrv.h:253
PCSR_NEWPROCESS_CALLBACK NewProcessCallback
Definition: csrsrv.h:239
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOLEAN NTAPI CsrCreateWait(IN PLIST_ENTRY WaitList, IN CSR_WAIT_FUNCTION WaitFunction, IN PCSR_THREAD CsrWaitThread, IN OUT PCSR_API_MESSAGE WaitApiMessage, IN PVOID WaitContext)
Definition: wait.c:209
HANDLE NTAPI CsrQueryApiPort(VOID)
Definition: api.c:1078
_CSR_THREAD_FLAGS
Definition: csrsrv.h:102
ULONG SessionId
Definition: csrsrv.h:33
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1398
PBOOLEAN ValidTable
Definition: csrsrv.h:225
ULONG ReferenceCount
Definition: csrsrv.h:31
ULONG ExpectedVersion
Definition: csrsrv.h:42
NTSTATUS NTAPI CsrCreateProcess(IN HANDLE hProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN PCSR_NT_SESSION NtSession, IN ULONG Flags, IN PCLIENT_ID DebugCid)
Definition: procsup.c:421
ULONG_PTR ClientViewBase
Definition: csrsrv.h:44
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68