[REACTOS]
[reactos.git] / reactos / deprecated / csrsrv / include / api.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: subsys/csrss/include/api.h
5 * PURPOSE: CSRSS API interface
6 */
7
8 #pragma once
9
10 #define NTOS_MODE_USER
11 #include <ndk/psfuncs.h>
12 #include <ndk/rtlfuncs.h>
13
14 #include <csrss/csrss.h>
15
16 #define CSR_SRV_SERVER 0
17 #define CSR_SERVER_DLL_MAX 4
18 #define LOCK RtlEnterCriticalSection(&ProcessDataLock)
19 #define UNLOCK RtlLeaveCriticalSection(&ProcessDataLock)
20 #define CsrAcquireProcessLock() LOCK
21 #define CsrReleaseProcessLock() UNLOCK
22 #define ProcessStructureListLocked() \
23 (ProcessDataLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)
24
25 #define CsrAcquireWaitLock() \
26 RtlEnterCriticalSection(&CsrWaitListsLock);
27
28 #define CsrReleaseWaitLock() \
29 RtlLeaveCriticalSection(&CsrWaitListsLock);
30
31 #define CsrAcquireNtSessionLock() \
32 RtlEnterCriticalSection(&CsrNtSessionLock);
33
34 #define CsrReleaseNtSessionLock() \
35 RtlLeaveCriticalSection(&CsrNtSessionLock);
36
37 typedef enum _CSR_THREAD_FLAGS
38 {
39 CsrThreadAltertable = 0x1,
40 CsrThreadInTermination = 0x2,
41 CsrThreadTerminated = 0x4,
42 CsrThreadIsServerThread = 0x10
43 } CSR_THREAD_FLAGS, *PCSR_THREAD_FLAGS;
44
45 typedef enum _SHUTDOWN_RESULT
46 {
47 CsrShutdownCsrProcess = 1,
48 CsrShutdownNonCsrProcess,
49 CsrShutdownCancelled
50 } SHUTDOWN_RESULT, *PSHUTDOWN_RESULT;
51
52 typedef enum _CSR_SHUTDOWN_FLAGS
53 {
54 CsrShutdownSystem = 4,
55 CsrShutdownOther = 8
56 } CSR_SHUTDOWN_FLAGS, *PCSR_SHUTDOWN_FLAGS;
57
58 typedef enum _CSR_DEBUG_FLAGS
59 {
60 CsrDebugOnlyThisProcess = 1,
61 CsrDebugProcessChildren = 2
62 } CSR_PROCESS_DEBUG_FLAGS, *PCSR_PROCESS_DEBUG_FLAGS;
63
64 typedef enum _CSR_PROCESS_FLAGS
65 {
66 CsrProcessTerminating = 0x1,
67 CsrProcessSkipShutdown = 0x2,
68 CsrProcessNormalPriority = 0x10,
69 CsrProcessIdlePriority = 0x20,
70 CsrProcessHighPriority = 0x40,
71 CsrProcessRealtimePriority = 0x80,
72 CsrProcessCreateNewGroup = 0x100,
73 CsrProcessTerminated = 0x200,
74 CsrProcessLastThreadTerminated = 0x400,
75 CsrProcessIsConsoleApp = 0x800
76 } CSR_PROCESS_FLAGS, *PCSR_PROCESS_FLAGS;
77
78 #define CsrProcessPriorityFlags (CsrProcessNormalPriority | \
79 CsrProcessIdlePriority | \
80 CsrProcessHighPriority | \
81 CsrProcessRealtimePriority)
82
83 typedef struct _CSRSS_CON_PROCESS_DATA
84 {
85 HANDLE ConsoleEvent;
86 struct tagCSRSS_CONSOLE *Console;
87 struct tagCSRSS_CONSOLE *ParentConsole;
88 BOOL bInheritHandles;
89 RTL_CRITICAL_SECTION HandleTableLock;
90 ULONG HandleTableSize;
91 struct _CSRSS_HANDLE *HandleTable;
92 PCONTROLDISPATCHER CtrlDispatcher;
93 LIST_ENTRY ConsoleLink;
94 } CSRSS_CON_PROCESS_DATA, *PCSRSS_CON_PROCESS_DATA;
95
96 typedef struct _CSR_NT_SESSION
97 {
98 ULONG ReferenceCount;
99 LIST_ENTRY SessionLink;
100 ULONG SessionId;
101 } CSR_NT_SESSION, *PCSR_NT_SESSION;
102
103 typedef struct _CSR_PROCESS
104 {
105 CLIENT_ID ClientId;
106 LIST_ENTRY ListLink;
107 LIST_ENTRY ThreadList;
108 struct _CSR_PROCESS *Parent;
109 PCSR_NT_SESSION NtSession;
110 ULONG ExpectedVersion;
111 HANDLE ClientPort;
112 ULONG_PTR ClientViewBase;
113 ULONG_PTR ClientViewBounds;
114 HANDLE ProcessHandle;
115 ULONG SequenceNumber;
116 ULONG Flags;
117 ULONG DebugFlags;
118 CLIENT_ID DebugCid;
119 ULONG ReferenceCount;
120 ULONG ProcessGroupId;
121 ULONG ProcessGroupSequence;
122 ULONG fVDM;
123 ULONG ThreadCount;
124 ULONG PriorityClass;
125 ULONG Reserved;
126 ULONG ShutdownLevel;
127 ULONG ShutdownFlags;
128 // PVOID ServerData[ANYSIZE_ARRAY];
129 CSRSS_CON_PROCESS_DATA;
130 } CSR_PROCESS, *PCSR_PROCESS;
131
132 typedef struct _CSR_THREAD
133 {
134 LARGE_INTEGER CreateTime;
135 LIST_ENTRY Link;
136 LIST_ENTRY HashLinks;
137 CLIENT_ID ClientId;
138 PCSR_PROCESS Process;
139 struct _CSR_WAIT_BLOCK *WaitBlock;
140 HANDLE ThreadHandle;
141 ULONG Flags;
142 ULONG ReferenceCount;
143 ULONG ImpersonationCount;
144 } CSR_THREAD, *PCSR_THREAD;
145
146 typedef
147 BOOLEAN
148 (*CSR_WAIT_FUNCTION)(
149 IN PLIST_ENTRY WaitList,
150 IN PCSR_THREAD WaitThread,
151 IN PCSR_API_MESSAGE WaitApiMessage,
152 IN PVOID WaitContext,
153 IN PVOID WaitArgument1,
154 IN PVOID WaitArgument2,
155 IN ULONG WaitFlags
156 );
157
158 typedef struct _CSR_WAIT_BLOCK
159 {
160 ULONG Size;
161 LIST_ENTRY WaitList;
162 LIST_ENTRY UserWaitList;
163 PVOID WaitContext;
164 PCSR_THREAD WaitThread;
165 CSR_WAIT_FUNCTION WaitFunction;
166 CSR_API_MESSAGE WaitApiMessage;
167 } CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
168
169 typedef
170 NTSTATUS
171 (NTAPI *PCSR_CONNECT_CALLBACK)(
172 IN PCSR_PROCESS CsrProcess,
173 IN OUT PVOID ConnectionInfo,
174 IN OUT PULONG ConnectionInfoLength
175 );
176
177 typedef
178 VOID
179 (NTAPI *PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess);
180
181 typedef
182 NTSTATUS
183 (NTAPI *PCSR_NEWPROCESS_CALLBACK)(
184 IN PCSR_PROCESS Parent,
185 IN PCSR_PROCESS CsrProcess
186 );
187
188 typedef
189 VOID
190 (NTAPI *PCSR_HARDERROR_CALLBACK)(
191 IN PCSR_THREAD CsrThread,
192 IN PHARDERROR_MSG HardErrorMessage
193 );
194
195 typedef
196 ULONG
197 (NTAPI *PCSR_SHUTDOWNPROCESS_CALLBACK)(
198 IN PCSR_PROCESS CsrProcess,
199 IN ULONG Flags,
200 IN BOOLEAN FirstPhase
201 );
202
203 typedef
204 NTSTATUS
205 (NTAPI *PCSR_API_ROUTINE)(
206 IN OUT PCSR_API_MESSAGE ApiMessage,
207 IN OUT PULONG Reply
208 );
209
210 typedef struct _CSR_SERVER_DLL
211 {
212 ULONG Length;
213 HANDLE Event;
214 ANSI_STRING Name;
215 HANDLE ServerHandle;
216 ULONG ServerId;
217 ULONG Unknown;
218 ULONG ApiBase;
219 ULONG HighestApiSupported;
220 PCSR_API_ROUTINE *DispatchTable;
221 PBOOLEAN ValidTable;
222 PCHAR *NameTable;
223 ULONG SizeOfProcessData;
224 PCSR_CONNECT_CALLBACK ConnectCallback;
225 PCSR_DISCONNECT_CALLBACK DisconnectCallback;
226 PCSR_HARDERROR_CALLBACK HardErrorCallback;
227 PVOID SharedSection;
228 PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
229 PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
230 ULONG Unknown2[3];
231 } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
232
233 typedef
234 NTSTATUS
235 (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL ServerDll);
236
237
238 typedef NTSTATUS (WINAPI *CSRSS_API_PROC)(PCSR_PROCESS ProcessData,
239 PCSR_API_MESSAGE Request);
240
241 typedef struct _CSRSS_API_DEFINITION
242 {
243 ULONG Type;
244 ULONG MinRequestSize;
245 CSRSS_API_PROC Handler;
246 } CSRSS_API_DEFINITION, *PCSRSS_API_DEFINITION;
247
248 #define CSRSS_DEFINE_API(Func, Handler) \
249 { Func, sizeof(CSRSS_##Func), Handler }
250
251 typedef struct _CSRSS_LISTEN_DATA
252 {
253 HANDLE ApiPortHandle;
254 ULONG ApiDefinitionsCount;
255 PCSRSS_API_DEFINITION *ApiDefinitions;
256 } CSRSS_LISTEN_DATA, *PCSRSS_LISTEN_DATA;
257
258 #define CSR_API(n) NTSTATUS WINAPI n ( \
259 PCSR_PROCESS ProcessData, \
260 PCSR_API_MESSAGE Request)
261
262 /* init.c */
263 extern HANDLE hBootstrapOk;
264 NTSTATUS NTAPI CsrServerInitialization(ULONG ArgumentCount, PCHAR Arguments[]);
265
266 /* api/process.c */
267 CSR_API(CsrConnectProcess);
268 CSR_API(CsrSrvCreateProcess);
269 CSR_API(CsrTerminateProcess);
270 CSR_API(CsrSrvCreateThread);
271 CSR_API(CsrGetShutdownParameters);
272 CSR_API(CsrSetShutdownParameters);
273
274 VOID
275 NTAPI
276 CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess);
277
278 PCSR_THREAD
279 NTAPI
280 CsrAllocateThread(IN PCSR_PROCESS CsrProcess);
281
282 PCSR_PROCESS
283 NTAPI
284 CsrAllocateProcess(VOID);
285
286 VOID
287 NTAPI
288 CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess);
289
290 VOID
291 NTAPI
292 CsrRemoveProcess(IN PCSR_PROCESS CsrProcess);
293
294 VOID
295 NTAPI
296 CsrDereferenceThread(IN PCSR_THREAD CsrThread);
297
298 VOID
299 NTAPI
300 CsrInsertProcess(IN PCSR_PROCESS Parent OPTIONAL,
301 IN PCSR_PROCESS CurrentProcess OPTIONAL,
302 IN PCSR_PROCESS CsrProcess);
303
304
305 /* api/wapi.c */
306 NTSTATUS FASTCALL CsrApiRegisterDefinitions(PCSRSS_API_DEFINITION NewDefinitions);
307 VOID FASTCALL CsrApiCallHandler(PCSR_PROCESS ProcessData,
308 PCSR_API_MESSAGE Request);
309 VOID WINAPI CsrSbApiRequestThread (PVOID PortHandle);
310 VOID NTAPI ClientConnectionThread(HANDLE ServerPort);
311
312 VOID
313 NTAPI
314 CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
315
316 extern HANDLE CsrApiPort;
317 extern HANDLE CsrSmApiPort;
318 extern HANDLE CsrSbApiPort;
319 extern LIST_ENTRY CsrThreadHashTable[256];
320 extern PCSR_PROCESS CsrRootProcess;
321 extern RTL_CRITICAL_SECTION ProcessDataLock, CsrWaitListsLock;
322 extern UNICODE_STRING CsrDirectoryName;
323 extern ULONG CsrDebug;
324 extern ULONG CsrTotalPerProcessDataLength;
325 extern SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
326 extern PVOID CsrSrvSharedSectionHeap;
327 extern PVOID *CsrSrvSharedStaticServerData;
328 extern HANDLE CsrInitializationEvent;
329 extern PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX];
330 extern ULONG CsrMaxApiRequestThreads;
331
332 NTSTATUS
333 NTAPI
334 CsrApiPortInitialize(VOID);
335
336 NTSTATUS
337 NTAPI
338 CsrCreateProcess(IN HANDLE hProcess,
339 IN HANDLE hThread,
340 IN PCLIENT_ID ClientId,
341 IN PCSR_NT_SESSION NtSession,
342 IN ULONG Flags,
343 IN PCLIENT_ID DebugCid);
344
345 BOOLEAN
346 NTAPI
347 ProtectHandle(IN HANDLE ObjectHandle);
348
349 VOID
350 NTAPI
351 CsrInsertThread(IN PCSR_PROCESS Process,
352 IN PCSR_THREAD Thread);
353
354 VOID
355 NTAPI
356 CsrLockedReferenceThread(IN PCSR_THREAD CsrThread);
357
358 /* api/process.c */
359 typedef NTSTATUS (WINAPI *CSRSS_ENUM_PROCESS_PROC)(PCSR_PROCESS ProcessData,
360 PVOID Context);
361 NTSTATUS WINAPI CsrInitializeProcessStructure(VOID);
362
363 NTSTATUS WINAPI CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc, PVOID Context);
364 PCSR_THREAD NTAPI CsrAddStaticServerThread(IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags);
365 PCSR_THREAD NTAPI CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL, IN PCLIENT_ID Cid);
366 PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId);
367 NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL);
368 NTSTATUS NTAPI CsrCreateThread(IN PCSR_PROCESS CsrProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId);
369 NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess);
370
371 //hack
372 VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread);
373
374 NTSTATUS
375 NTAPI
376 CsrInitializeNtSessionList(VOID);
377
378 NTSTATUS
379 NTAPI
380 CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
381 OUT PCSR_CONNECTION_INFO ConnectInfo);
382
383 NTSTATUS
384 NTAPI
385 CsrSrvCreateSharedSection(IN PCHAR ParameterValue);
386
387 NTSTATUS
388 NTAPI
389 CsrSrvClientConnect(
390 IN OUT PCSR_API_MESSAGE ApiMessage,
391 IN OUT PULONG Reply
392 );
393
394 NTSTATUS
395 NTAPI
396 CsrSrvUnusedFunction(
397 IN OUT PCSR_API_MESSAGE ApiMessage,
398 IN OUT PULONG Reply
399 );
400
401 NTSTATUS
402 NTAPI
403 CsrSrvIdentifyAlertableThread(
404 IN OUT PCSR_API_MESSAGE ApiMessage,
405 IN OUT PULONG Reply
406 );
407
408 NTSTATUS
409 NTAPI
410 CsrSrvSetPriorityClass(
411 IN OUT PCSR_API_MESSAGE ApiMessage,
412 IN OUT PULONG Reply
413 );
414
415 NTSTATUS
416 NTAPI
417 CsrDestroyProcess(IN PCLIENT_ID Cid,
418 IN NTSTATUS ExitStatus);
419
420 NTSTATUS
421 NTAPI
422 CsrDestroyThread(IN PCLIENT_ID Cid);
423
424 VOID
425 NTAPI
426 CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread);
427
428 BOOLEAN
429 NTAPI
430 CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock,
431 IN PLIST_ENTRY WaitList,
432 IN PVOID WaitArgument1,
433 IN PVOID WaitArgument2,
434 IN ULONG WaitFlags,
435 IN BOOLEAN DereferenceThread);
436
437 VOID
438 NTAPI
439 CsrReferenceNtSession(IN PCSR_NT_SESSION Session);
440
441 LONG
442 NTAPI
443 CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo);
444
445 VOID
446 NTAPI
447 CsrDereferenceNtSession(IN PCSR_NT_SESSION Session,
448 IN NTSTATUS ExitStatus);
449
450 VOID
451 NTAPI
452 CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess);
453
454 VOID
455 NTAPI
456 CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess);
457
458 NTSTATUS
459 NTAPI
460 CsrLoadServerDll(IN PCHAR DllString,
461 IN PCHAR EntryPoint OPTIONAL,
462 IN ULONG ServerId);
463
464 /* api/user.c */
465 CSR_API(CsrRegisterServicesProcess);
466
467 /* EOF */