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)
14 * The CSR_DBG macro is defined for building CSR Servers
15 * with extended debugging information.
24 /* TYPES **********************************************************************/
26 // Used in ntdll/csr/connect.c
27 #define CSR_CSRSS_SECTION_SIZE 65536
29 typedef struct _CSR_NT_SESSION
32 LIST_ENTRY SessionLink
;
34 } CSR_NT_SESSION
, *PCSR_NT_SESSION
;
36 typedef struct _CSR_PROCESS
40 LIST_ENTRY ThreadList
;
41 PCSR_NT_SESSION NtSession
;
42 ULONG ExpectedVersion
;
44 ULONG_PTR ClientViewBase
;
45 ULONG_PTR ClientViewBounds
;
53 ULONG ProcessGroupSequence
;
60 PVOID ServerData
[ANYSIZE_ARRAY
]; // One structure per CSR server.
61 } CSR_PROCESS
, *PCSR_PROCESS
;
63 typedef struct _CSR_THREAD
65 LARGE_INTEGER CreateTime
;
70 struct _CSR_WAIT_BLOCK
*WaitBlock
;
74 ULONG ImpersonationCount
;
75 } CSR_THREAD
, *PCSR_THREAD
;
77 #define CsrGetClientThread() \
78 ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
81 /* ENUMERATIONS ***************************************************************/
83 typedef enum _CSR_PROCESS_FLAGS
85 CsrProcessTerminating
= 0x1,
86 CsrProcessSkipShutdown
= 0x2,
87 CsrProcessNormalPriority
= 0x10,
88 CsrProcessIdlePriority
= 0x20,
89 CsrProcessHighPriority
= 0x40,
90 CsrProcessRealtimePriority
= 0x80,
91 CsrProcessCreateNewGroup
= 0x100,
92 CsrProcessTerminated
= 0x200,
93 CsrProcessLastThreadTerminated
= 0x400,
94 CsrProcessIsConsoleApp
= 0x800
95 } CSR_PROCESS_FLAGS
, *PCSR_PROCESS_FLAGS
;
97 #define CsrProcessPriorityFlags (CsrProcessNormalPriority | \
98 CsrProcessIdlePriority | \
99 CsrProcessHighPriority | \
100 CsrProcessRealtimePriority)
102 typedef enum _CSR_THREAD_FLAGS
104 CsrThreadAlertable
= 0x1,
105 CsrThreadInTermination
= 0x2,
106 CsrThreadTerminated
= 0x4,
107 CsrThreadIsServerThread
= 0x10
108 } CSR_THREAD_FLAGS
, *PCSR_THREAD_FLAGS
;
110 typedef enum _SHUTDOWN_RESULT
112 CsrShutdownCsrProcess
= 1,
113 CsrShutdownNonCsrProcess
,
115 } SHUTDOWN_RESULT
, *PSHUTDOWN_RESULT
;
117 typedef enum _CSR_SHUTDOWN_FLAGS
119 CsrShutdownSystem
= 4,
121 } CSR_SHUTDOWN_FLAGS
, *PCSR_SHUTDOWN_FLAGS
;
123 typedef enum _CSR_DEBUG_FLAGS
125 CsrDebugOnlyThisProcess
= 1,
126 CsrDebugProcessChildren
= 2
127 } CSR_PROCESS_DEBUG_FLAGS
, *PCSR_PROCESS_DEBUG_FLAGS
;
129 typedef enum _CSR_REPLY_CODE
131 CsrReplyImmediately
= 0,
133 CsrReplyDeadClient
= 2,
134 CsrReplyAlreadySent
= 3
135 } CSR_REPLY_CODE
, *PCSR_REPLY_CODE
;
138 /* FUNCTION TYPES AND STRUCTURES **********************************************/
145 (NTAPI
*CSR_WAIT_FUNCTION
)(
146 IN PLIST_ENTRY WaitList
,
147 IN PCSR_THREAD WaitThread
,
148 IN PCSR_API_MESSAGE WaitApiMessage
,
149 IN PVOID WaitContext
,
150 IN PVOID WaitArgument1
,
151 IN PVOID WaitArgument2
,
155 typedef struct _CSR_WAIT_BLOCK
157 ULONG Size
; // Size of the wait block (variable-sized)
160 PCSR_THREAD WaitThread
;
161 CSR_WAIT_FUNCTION WaitFunction
;
162 CSR_API_MESSAGE WaitApiMessage
; // Variable-sized CSR API message
163 } CSR_WAIT_BLOCK
, *PCSR_WAIT_BLOCK
;
167 * Server DLL structure
171 (NTAPI
*PCSR_API_ROUTINE
)(
172 IN OUT PCSR_API_MESSAGE ApiMessage
,
173 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
177 NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
178 IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
182 (NTAPI
*PCSR_CONNECT_CALLBACK
)(
183 IN PCSR_PROCESS CsrProcess
,
184 IN OUT PVOID ConnectionInfo
,
185 IN OUT PULONG ConnectionInfoLength
190 (NTAPI
*PCSR_DISCONNECT_CALLBACK
)(IN PCSR_PROCESS CsrProcess
);
194 (NTAPI
*PCSR_NEWPROCESS_CALLBACK
)(
195 IN PCSR_PROCESS Parent
,
196 IN PCSR_PROCESS CsrProcess
201 (NTAPI
*PCSR_HARDERROR_CALLBACK
)(
202 IN PCSR_THREAD CsrThread
,
203 IN PHARDERROR_MSG HardErrorMessage
208 (NTAPI
*PCSR_SHUTDOWNPROCESS_CALLBACK
)(
209 IN PCSR_PROCESS CsrProcess
,
211 IN BOOLEAN FirstPhase
214 // See http://redplait.blogspot.fr/2011/07/csrserverdll.html
215 typedef struct _CSR_SERVER_DLL
223 ULONG HighestApiSupported
;
224 PCSR_API_ROUTINE
*DispatchTable
;
225 PBOOLEAN ValidTable
; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer.
227 * On Windows Server 2003, CSR Servers contain
228 * the API Names Table only in Debug Builds.
234 ULONG SizeOfProcessData
;
235 PCSR_CONNECT_CALLBACK ConnectCallback
;
236 PCSR_DISCONNECT_CALLBACK DisconnectCallback
;
237 PCSR_HARDERROR_CALLBACK HardErrorCallback
;
239 PCSR_NEWPROCESS_CALLBACK NewProcessCallback
;
240 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback
;
242 } CSR_SERVER_DLL
, *PCSR_SERVER_DLL
;
245 C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL
, SharedSection
) == 0x3C);
247 C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL
, SharedSection
) == 0x38);
253 (NTAPI
*PCSR_SERVER_DLL_INIT_CALLBACK
)(IN PCSR_SERVER_DLL LoadedServerDll
);
255 #define CSR_SERVER_DLL_INIT(n) \
256 NTSTATUS NTAPI n(IN PCSR_SERVER_DLL LoadedServerDll)
259 /* PROTOTYPES ****************************************************************/
263 CsrServerInitialization(IN ULONG ArgumentCount
,
264 IN PCHAR Arguments
[]);
268 CsrAddStaticServerThread(IN HANDLE hThread
,
269 IN PCLIENT_ID ClientId
,
270 IN ULONG ThreadFlags
);
274 CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg
,
275 IN OUT PCSR_API_MESSAGE ReplyMsg
);
279 CsrConnectToUser(VOID
);
283 CsrCreateProcess(IN HANDLE hProcess
,
285 IN PCLIENT_ID ClientId
,
286 IN PCSR_NT_SESSION NtSession
,
288 IN PCLIENT_ID DebugCid
);
292 CsrCreateRemoteThread(IN HANDLE hThread
,
293 IN PCLIENT_ID ClientId
);
297 CsrCreateThread(IN PCSR_PROCESS CsrProcess
,
299 IN PCLIENT_ID ClientId
,
300 IN BOOLEAN HaveClient
);
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
);
312 CsrDebugProcess(IN PCSR_PROCESS CsrProcess
);
316 CsrDebugProcessStop(IN PCSR_PROCESS CsrProcess
);
320 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess
);
324 CsrDereferenceThread(IN PCSR_THREAD CsrThread
);
328 CsrDereferenceWait(IN PLIST_ENTRY WaitList
);
332 CsrDestroyProcess(IN PCLIENT_ID Cid
,
333 IN NTSTATUS ExitStatus
);
337 CsrDestroyThread(IN PCLIENT_ID Cid
);
341 CsrExecServerThread(IN PVOID ThreadHandler
,
346 CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL
,
351 CsrImpersonateClient(IN PCSR_THREAD CsrThread
);
355 CsrLockProcessByClientId(IN HANDLE Pid
,
356 OUT PCSR_PROCESS
*CsrProcess OPTIONAL
);
360 CsrLockThreadByClientId(IN HANDLE Tid
,
361 OUT PCSR_THREAD
*CsrThread
);
365 CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList
,
366 IN PLIST_ENTRY WaitList
);
370 CsrNotifyWait(IN PLIST_ENTRY WaitList
,
371 IN BOOLEAN NotifyAll
,
372 IN PVOID WaitArgument1
,
373 IN PVOID WaitArgument2
);
377 CsrPopulateDosDevices(VOID
);
381 CsrQueryApiPort(VOID
);
385 CsrReferenceThread(IN PCSR_THREAD CsrThread
);
389 CsrRevertToSelf(VOID
);
393 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess
);
397 CsrSetCallingSpooler(ULONG Reserved
);
401 CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess
);
405 CsrShutdownProcesses(IN PLUID CallerLuid
,
408 EXCEPTION_DISPOSITION
410 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo
);
414 CsrUnlockProcess(IN PCSR_PROCESS CsrProcess
);
418 CsrUnlockThread(IN PCSR_THREAD CsrThread
);
422 CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage
,
424 IN ULONG ElementCount
,
425 IN ULONG ElementSize
);
429 CsrValidateMessageString(IN PCSR_API_MESSAGE ApiMessage
,
430 IN PWSTR
*MessageString
);