Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

562 lines
9.8 KiB

  1. /*++ BUILD Version: 0002 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntcsrsrv.h
  5. Abstract:
  6. This module defines the public interfaces of the Server portion of
  7. the Client-Server Runtime (Csr) Subsystem.
  8. Author:
  9. Steve Wood (stevewo) 09-Oct-1990
  10. Revision History:
  11. --*/
  12. #ifndef _NTCSRSRVAPI_
  13. #define _NTCSRSRVAPI_
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. //
  18. // Define API decoration for direct importing system DLL references.
  19. //
  20. #if !defined(_CSRSRV_)
  21. #define NTCSRAPI DECLSPEC_IMPORT
  22. #else
  23. #define NTCSRAPI
  24. #endif
  25. #include "ntcsrmsg.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. //
  30. // NT Session structure allocated in the server context for each new NT
  31. // session that is a client of the server.
  32. //
  33. typedef struct _CSR_NT_SESSION {
  34. LIST_ENTRY SessionLink;
  35. ULONG SessionId;
  36. ULONG ReferenceCount;
  37. STRING RootDirectory;
  38. } CSR_NT_SESSION, *PCSR_NT_SESSION;
  39. //
  40. // Per Thread data structure allocated in the server context for each new
  41. // client thread that is allowed to communicate with the server.
  42. //
  43. #define CSR_ALERTABLE_THREAD 0x00000001
  44. #define CSR_THREAD_TERMINATING 0x00000002
  45. #define CSR_THREAD_DESTROYED 0x00000004
  46. typedef struct _CSR_THREAD {
  47. LARGE_INTEGER CreateTime;
  48. LIST_ENTRY Link;
  49. LIST_ENTRY HashLinks;
  50. CLIENT_ID ClientId;
  51. struct _CSR_PROCESS *Process;
  52. struct _CSR_WAIT_BLOCK *WaitBlock;
  53. HANDLE ThreadHandle;
  54. ULONG Flags;
  55. ULONG ReferenceCount;
  56. ULONG ImpersonateCount;
  57. } CSR_THREAD, *PCSR_THREAD;
  58. //
  59. // Per Process data structure allocated in the server context for each new
  60. // client process that successfully connects to the server.
  61. //
  62. //
  63. // 0x00000010 -> 0x000000x0 are used in ntcsrmsg.h
  64. //
  65. #define CSR_DEBUG_THIS_PROCESS 0x00000001
  66. #define CSR_DEBUG_PROCESS_TREE 0x00000002
  67. #define CSR_DEBUG_WIN32SERVER 0x00000004
  68. #define CSR_CREATE_PROCESS_GROUP 0x00000100
  69. #define CSR_PROCESS_DESTROYED 0x00000200
  70. #define CSR_PROCESS_LASTTHREADOK 0x00000400
  71. #define CSR_PROCESS_CONSOLEAPP 0x00000800
  72. #define CSR_PROCESS_TERMINATED 0x00001000
  73. //
  74. // Flags defines
  75. //
  76. #define CSR_PROCESS_TERMINATING 1
  77. #define CSR_PROCESS_SHUTDOWNSKIP 2
  78. typedef struct _CSR_PROCESS {
  79. CLIENT_ID ClientId;
  80. LIST_ENTRY ListLink;
  81. LIST_ENTRY ThreadList;
  82. struct _CSR_PROCESS *Parent;
  83. PCSR_NT_SESSION NtSession;
  84. ULONG ExpectedVersion;
  85. HANDLE ClientPort;
  86. PCH ClientViewBase;
  87. PCH ClientViewBounds;
  88. HANDLE ProcessHandle;
  89. ULONG SequenceNumber;
  90. ULONG Flags;
  91. ULONG DebugFlags;
  92. CLIENT_ID DebugUserInterface;
  93. ULONG ReferenceCount;
  94. ULONG ProcessGroupId;
  95. ULONG ProcessGroupSequence;
  96. ULONG fVDM;
  97. ULONG ThreadCount;
  98. UCHAR PriorityClass;
  99. UCHAR Spare0;
  100. UCHAR Spare1;
  101. UCHAR Spare2;
  102. ULONG Spare3;
  103. ULONG ShutdownLevel;
  104. ULONG ShutdownFlags;
  105. PVOID ServerDllPerProcessData[ 1 ]; // Variable length array
  106. } CSR_PROCESS, *PCSR_PROCESS;
  107. //
  108. // All exported API calls define the same interface to the Server Request
  109. // loop. The return value is any arbritrary 32-bit value, which will be
  110. // be returned in the ReturnValue field of the reply message.
  111. //
  112. typedef enum _CSR_REPLY_STATUS {
  113. CsrReplyImmediate,
  114. CsrReplyPending,
  115. CsrClientDied,
  116. CsrServerReplied
  117. } CSR_REPLY_STATUS, *PCSR_REPLY_STATUS;
  118. typedef
  119. ULONG
  120. (*PCSR_API_ROUTINE)(
  121. IN OUT PCSR_API_MSG ReplyMsg,
  122. OUT PCSR_REPLY_STATUS ReplyStatus
  123. );
  124. #define CSR_SERVER_QUERYCLIENTTHREAD() \
  125. ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
  126. //
  127. // Server data structure allocated for each Server DLL loaded into the
  128. // context of the server process.
  129. //
  130. typedef
  131. NTSTATUS
  132. (*PCSR_SERVER_CONNECT_ROUTINE)(
  133. IN PCSR_PROCESS Process,
  134. IN OUT PVOID ConnectionInformation,
  135. IN OUT PULONG ConnectionInformationLength
  136. );
  137. typedef
  138. VOID
  139. (*PCSR_SERVER_DISCONNECT_ROUTINE)(
  140. IN PCSR_PROCESS Process
  141. );
  142. typedef
  143. NTSTATUS
  144. (*PCSR_SERVER_ADDPROCESS_ROUTINE)(
  145. IN PCSR_PROCESS ParentProcess,
  146. IN PCSR_PROCESS Process
  147. );
  148. typedef
  149. VOID
  150. (*PCSR_SERVER_HARDERROR_ROUTINE)(
  151. IN PCSR_THREAD Thread,
  152. IN PHARDERROR_MSG HardErrorMsg
  153. );
  154. NTCSRAPI
  155. NTSTATUS
  156. NTAPI
  157. CsrServerInitialization(
  158. IN ULONG argc,
  159. IN PCH argv[]
  160. );
  161. NTCSRAPI
  162. NTSTATUS
  163. NTAPI
  164. CsrCallServerFromServer(
  165. PCSR_API_MSG ReceiveMsg,
  166. PCSR_API_MSG ReplyMsg
  167. );
  168. //
  169. // ShutdownProcessRoutine return values
  170. //
  171. #define SHUTDOWN_KNOWN_PROCESS 1
  172. #define SHUTDOWN_UNKNOWN_PROCESS 2
  173. #define SHUTDOWN_CANCEL 3
  174. //
  175. // Private ShutdownFlags flag
  176. //
  177. #define SHUTDOWN_SYSTEMCONTEXT 0x00000004
  178. #define SHUTDOWN_OTHERCONTEXT 0x00000008
  179. typedef
  180. ULONG
  181. (*PCSR_SERVER_SHUTDOWNPROCESS_ROUTINE)(
  182. IN PCSR_PROCESS Process,
  183. IN ULONG Flags,
  184. IN BOOLEAN fFirstPass
  185. );
  186. NTCSRAPI
  187. ULONG
  188. NTAPI
  189. CsrComputePriorityClass(
  190. IN PCSR_PROCESS Process
  191. );
  192. NTCSRAPI
  193. NTSTATUS
  194. NTAPI
  195. CsrShutdownProcesses(
  196. PLUID LuidCaller,
  197. ULONG Flags
  198. );
  199. NTCSRAPI
  200. NTSTATUS
  201. NTAPI
  202. CsrGetProcessLuid(
  203. HANDLE ProcessHandle,
  204. PLUID LuidProcess
  205. );
  206. typedef struct _CSR_SERVER_DLL {
  207. ULONG Length;
  208. HANDLE CsrInitializationEvent;
  209. STRING ModuleName;
  210. HANDLE ModuleHandle;
  211. ULONG ServerDllIndex;
  212. ULONG ServerDllConnectInfoLength;
  213. ULONG ApiNumberBase;
  214. ULONG MaxApiNumber;
  215. PCSR_API_ROUTINE *ApiDispatchTable;
  216. PBOOLEAN ApiServerValidTable;
  217. PSZ *ApiNameTable;
  218. ULONG PerProcessDataLength;
  219. PCSR_SERVER_CONNECT_ROUTINE ConnectRoutine;
  220. PCSR_SERVER_DISCONNECT_ROUTINE DisconnectRoutine;
  221. PCSR_SERVER_HARDERROR_ROUTINE HardErrorRoutine;
  222. PVOID SharedStaticServerData;
  223. PCSR_SERVER_ADDPROCESS_ROUTINE AddProcessRoutine;
  224. PCSR_SERVER_SHUTDOWNPROCESS_ROUTINE ShutdownProcessRoutine;
  225. } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
  226. typedef
  227. NTSTATUS
  228. (*PCSR_SERVER_DLL_INIT_ROUTINE)(
  229. IN PCSR_SERVER_DLL LoadedServerDll
  230. );
  231. typedef
  232. VOID
  233. (*PCSR_ATTACH_COMPLETE_ROUTINE)(
  234. VOID
  235. );
  236. NTCSRAPI
  237. VOID
  238. NTAPI
  239. CsrReferenceThread(
  240. PCSR_THREAD t
  241. );
  242. NTCSRAPI
  243. VOID
  244. NTAPI
  245. CsrDereferenceThread(
  246. PCSR_THREAD t
  247. );
  248. NTCSRAPI
  249. NTSTATUS
  250. NTAPI
  251. CsrCreateProcess(
  252. IN HANDLE ProcessHandle,
  253. IN HANDLE ThreadHandle,
  254. IN PCLIENT_ID ClientId,
  255. IN PCSR_NT_SESSION Session,
  256. IN ULONG DebugFlags,
  257. IN PCLIENT_ID DebugUserInterface OPTIONAL
  258. );
  259. NTCSRAPI
  260. NTSTATUS
  261. NTAPI
  262. CsrDebugProcess(
  263. IN ULONG TargetProcessId,
  264. IN PCLIENT_ID DebugUserInterface,
  265. IN PCSR_ATTACH_COMPLETE_ROUTINE AttachCompleteRoutine
  266. );
  267. NTCSRAPI
  268. NTSTATUS
  269. NTAPI
  270. CsrDebugProcessStop(
  271. IN ULONG TargetProcessId,
  272. IN PCLIENT_ID DebugUserInterface
  273. );
  274. NTCSRAPI
  275. VOID
  276. NTAPI
  277. CsrDereferenceProcess(
  278. PCSR_PROCESS p
  279. );
  280. NTCSRAPI
  281. NTSTATUS
  282. NTAPI
  283. CsrDestroyProcess(
  284. IN PCLIENT_ID ClientId,
  285. IN NTSTATUS ExitStatus
  286. );
  287. NTCSRAPI
  288. NTSTATUS
  289. NTAPI
  290. CsrLockProcessByClientId(
  291. IN HANDLE UniqueProcessId,
  292. OUT PCSR_PROCESS *Process
  293. );
  294. NTCSRAPI
  295. NTSTATUS
  296. NTAPI
  297. CsrUnlockProcess(
  298. IN PCSR_PROCESS Process
  299. );
  300. NTCSRAPI
  301. NTSTATUS
  302. NTAPI
  303. CsrLockThreadByClientId(
  304. IN HANDLE UniqueThreadId,
  305. OUT PCSR_THREAD *Thread
  306. );
  307. NTCSRAPI
  308. NTSTATUS
  309. NTAPI
  310. CsrUnlockThread(
  311. IN PCSR_THREAD Thread
  312. );
  313. NTCSRAPI
  314. NTSTATUS
  315. NTAPI
  316. CsrCreateThread(
  317. IN PCSR_PROCESS Process,
  318. IN HANDLE ThreadHandle,
  319. IN PCLIENT_ID ClientId,
  320. BOOLEAN ValidateCallingThread
  321. );
  322. NTCSRAPI
  323. PCSR_THREAD
  324. NTAPI
  325. CsrLocateThreadInProcess(
  326. IN PCSR_PROCESS Process,
  327. IN PCLIENT_ID ClientId
  328. );
  329. NTCSRAPI
  330. NTSTATUS
  331. NTAPI
  332. CsrCreateRemoteThread(
  333. IN HANDLE ThreadHandle,
  334. IN PCLIENT_ID ClientId
  335. );
  336. NTCSRAPI
  337. NTSTATUS
  338. NTAPI
  339. CsrDestroyThread(
  340. IN PCLIENT_ID ClientId
  341. );
  342. //
  343. // WaitFlags
  344. //
  345. typedef
  346. BOOLEAN
  347. (*CSR_WAIT_ROUTINE)(
  348. IN PLIST_ENTRY WaitQueue,
  349. IN PCSR_THREAD WaitingThread,
  350. IN PCSR_API_MSG WaitReplyMessage,
  351. IN PVOID WaitParameter,
  352. IN PVOID SatisfyParameter1,
  353. IN PVOID SatisfyParameter2,
  354. IN ULONG WaitFlags
  355. );
  356. typedef struct _CSR_WAIT_BLOCK {
  357. ULONG Length;
  358. LIST_ENTRY Link;
  359. LIST_ENTRY UserLink;
  360. PVOID WaitParameter;
  361. PCSR_THREAD WaitingThread;
  362. CSR_WAIT_ROUTINE WaitRoutine;
  363. CSR_API_MSG WaitReplyMessage;
  364. } CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
  365. NTCSRAPI
  366. BOOLEAN
  367. NTAPI
  368. CsrCreateWait(
  369. IN PLIST_ENTRY WaitQueue,
  370. IN CSR_WAIT_ROUTINE WaitRoutine,
  371. IN PCSR_THREAD WaitingThread,
  372. IN OUT PCSR_API_MSG WaitReplyMessage,
  373. IN PVOID WaitParameter,
  374. IN PLIST_ENTRY UserLinkListHead OPTIONAL
  375. );
  376. NTCSRAPI
  377. VOID
  378. NTAPI
  379. CsrDereferenceWait(
  380. IN PLIST_ENTRY WaitQueue
  381. );
  382. NTCSRAPI
  383. BOOLEAN
  384. NTAPI
  385. CsrNotifyWait(
  386. IN PLIST_ENTRY WaitQueue,
  387. IN BOOLEAN SatisfyAll,
  388. IN PVOID SatisfyParameter1,
  389. IN PVOID SatisfyParameter2
  390. );
  391. NTCSRAPI
  392. VOID
  393. NTAPI
  394. CsrMoveSatisfiedWait(
  395. IN PLIST_ENTRY DstWaitQueue,
  396. IN PLIST_ENTRY SrcWaitQueue
  397. );
  398. NTCSRAPI
  399. PVOID
  400. NTAPI
  401. CsrAddStaticServerThread(
  402. IN HANDLE ThreadHandle,
  403. IN PCLIENT_ID ClientId,
  404. IN ULONG Flags
  405. );
  406. NTCSRAPI
  407. NTSTATUS
  408. NTAPI
  409. CsrExecServerThread(
  410. IN PUSER_THREAD_START_ROUTINE StartAddress,
  411. IN ULONG Flags
  412. );
  413. NTCSRAPI
  414. PCSR_THREAD
  415. NTAPI
  416. CsrConnectToUser(
  417. VOID
  418. );
  419. NTCSRAPI
  420. BOOLEAN
  421. NTAPI
  422. CsrImpersonateClient(
  423. IN PCSR_THREAD Thread
  424. );
  425. NTCSRAPI
  426. BOOLEAN
  427. NTAPI
  428. CsrRevertToSelf(
  429. VOID
  430. );
  431. NTCSRAPI
  432. VOID
  433. NTAPI
  434. CsrSetForegroundPriority(
  435. IN PCSR_PROCESS Process
  436. );
  437. NTCSRAPI
  438. VOID
  439. NTAPI
  440. CsrSetBackgroundPriority(
  441. IN PCSR_PROCESS Process
  442. );
  443. NTCSRAPI
  444. EXCEPTION_DISPOSITION
  445. NTAPI
  446. CsrUnhandledExceptionFilter(
  447. IN PEXCEPTION_POINTERS ExceptionInfo
  448. );
  449. NTCSRAPI
  450. BOOLEAN
  451. NTAPI
  452. CsrValidateMessageBuffer(
  453. IN CONST CSR_API_MSG *m,
  454. IN VOID CONST * CONST * Buffer,
  455. IN ULONG Count,
  456. IN ULONG Size
  457. );
  458. NTCSRAPI
  459. BOOLEAN
  460. NTAPI
  461. CsrValidateMessageString(
  462. IN CONST CSR_API_MSG *m,
  463. IN CONST PCWSTR *Buffer
  464. );
  465. typedef struct _CSR_FAST_ANSI_OEM_TABLES {
  466. char OemToAnsiTable[256];
  467. char AnsiToOemTable[256];
  468. } CSR_FAST_ANSI_OEM_TABLES, *PCSR_FAST_ANSI_OEM_TABLES;
  469. #ifdef __cplusplus
  470. }
  471. #endif
  472. #endif // _NTCSRSRVAPI_