Leaked source code of windows server 2003
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.

551 lines
10 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. PCSR_NT_SESSION NtSession;
  83. ULONG ExpectedVersion;
  84. HANDLE ClientPort;
  85. PCH ClientViewBase;
  86. PCH ClientViewBounds;
  87. HANDLE ProcessHandle;
  88. ULONG SequenceNumber;
  89. ULONG Flags;
  90. ULONG DebugFlags;
  91. CLIENT_ID DebugUserInterface;
  92. ULONG ReferenceCount;
  93. ULONG ProcessGroupId;
  94. ULONG ProcessGroupSequence;
  95. ULONG fVDM;
  96. ULONG ThreadCount;
  97. UCHAR PriorityClass;
  98. UCHAR Spare0;
  99. UCHAR Spare1;
  100. UCHAR Spare2;
  101. ULONG Spare3;
  102. ULONG ShutdownLevel;
  103. ULONG ShutdownFlags;
  104. PVOID ServerDllPerProcessData[ 1 ]; // Variable length array
  105. } CSR_PROCESS, *PCSR_PROCESS;
  106. //
  107. // All exported API calls define the same interface to the Server Request
  108. // loop. The return value is any arbritrary 32-bit value, which will be
  109. // be returned in the ReturnValue field of the reply message.
  110. //
  111. typedef enum _CSR_REPLY_STATUS {
  112. CsrReplyImmediate,
  113. CsrReplyPending,
  114. CsrClientDied,
  115. CsrServerReplied
  116. } CSR_REPLY_STATUS, *PCSR_REPLY_STATUS;
  117. typedef
  118. ULONG
  119. (*PCSR_API_ROUTINE)(
  120. IN OUT PCSR_API_MSG ReplyMsg,
  121. OUT PCSR_REPLY_STATUS ReplyStatus
  122. );
  123. #define CSR_SERVER_QUERYCLIENTTHREAD() \
  124. ((PCSR_THREAD)(NtCurrentTeb()->CsrClientThread))
  125. //
  126. // Server data structure allocated for each Server DLL loaded into the
  127. // context of the server process.
  128. //
  129. typedef
  130. NTSTATUS
  131. (*PCSR_SERVER_CONNECT_ROUTINE)(
  132. IN PCSR_PROCESS Process,
  133. IN OUT PVOID ConnectionInformation,
  134. IN OUT PULONG ConnectionInformationLength
  135. );
  136. typedef
  137. VOID
  138. (*PCSR_SERVER_DISCONNECT_ROUTINE)(
  139. IN PCSR_PROCESS Process
  140. );
  141. typedef
  142. NTSTATUS
  143. (*PCSR_SERVER_ADDPROCESS_ROUTINE)(
  144. IN PCSR_PROCESS ParentProcess,
  145. IN PCSR_PROCESS Process
  146. );
  147. typedef
  148. VOID
  149. (*PCSR_SERVER_HARDERROR_ROUTINE)(
  150. IN PCSR_THREAD Thread,
  151. IN PHARDERROR_MSG HardErrorMsg
  152. );
  153. NTCSRAPI
  154. NTSTATUS
  155. NTAPI
  156. CsrServerInitialization(
  157. IN ULONG argc,
  158. IN PCH argv[]
  159. );
  160. NTCSRAPI
  161. NTSTATUS
  162. NTAPI
  163. CsrCallServerFromServer(
  164. PCSR_API_MSG ReceiveMsg,
  165. PCSR_API_MSG ReplyMsg
  166. );
  167. //
  168. // ShutdownProcessRoutine return values
  169. //
  170. #define SHUTDOWN_KNOWN_PROCESS 1
  171. #define SHUTDOWN_UNKNOWN_PROCESS 2
  172. #define SHUTDOWN_CANCEL 3
  173. //
  174. // Private ShutdownFlags flag
  175. //
  176. #define SHUTDOWN_SYSTEMCONTEXT 0x00000004
  177. #define SHUTDOWN_OTHERCONTEXT 0x00000008
  178. typedef
  179. ULONG
  180. (*PCSR_SERVER_SHUTDOWNPROCESS_ROUTINE)(
  181. IN PCSR_PROCESS Process,
  182. IN ULONG Flags,
  183. IN BOOLEAN fFirstPass
  184. );
  185. NTCSRAPI
  186. ULONG
  187. NTAPI
  188. CsrComputePriorityClass(
  189. IN PCSR_PROCESS Process
  190. );
  191. NTCSRAPI
  192. NTSTATUS
  193. NTAPI
  194. CsrShutdownProcesses(
  195. PLUID LuidCaller,
  196. ULONG Flags
  197. );
  198. NTCSRAPI
  199. NTSTATUS
  200. NTAPI
  201. CsrGetProcessLuid(
  202. HANDLE ProcessHandle,
  203. PLUID LuidProcess
  204. );
  205. typedef struct _CSR_SERVER_DLL {
  206. ULONG Length;
  207. STRING ModuleName;
  208. HANDLE ModuleHandle;
  209. ULONG ServerDllIndex;
  210. ULONG ServerDllConnectInfoLength;
  211. ULONG ApiNumberBase;
  212. ULONG MaxApiNumber;
  213. CONST PCSR_API_ROUTINE *ApiDispatchTable;
  214. PBOOLEAN ApiServerValidTable;
  215. #if DBG
  216. CONST PSZ *ApiNameTable;
  217. #endif
  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. ULONG
  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. NTSTATUS
  324. NTAPI
  325. CsrCreateRemoteThread(
  326. IN HANDLE ThreadHandle,
  327. IN PCLIENT_ID ClientId
  328. );
  329. NTCSRAPI
  330. NTSTATUS
  331. NTAPI
  332. CsrDestroyThread(
  333. IN PCLIENT_ID ClientId
  334. );
  335. //
  336. // WaitFlags
  337. //
  338. typedef
  339. BOOLEAN
  340. (*CSR_WAIT_ROUTINE)(
  341. IN PLIST_ENTRY WaitQueue,
  342. IN PCSR_THREAD WaitingThread,
  343. IN PCSR_API_MSG WaitReplyMessage,
  344. IN PVOID WaitParameter,
  345. IN PVOID SatisfyParameter1,
  346. IN PVOID SatisfyParameter2,
  347. IN ULONG WaitFlags
  348. );
  349. typedef struct _CSR_WAIT_BLOCK {
  350. ULONG Length;
  351. LIST_ENTRY Link;
  352. PVOID WaitParameter;
  353. PCSR_THREAD WaitingThread;
  354. CSR_WAIT_ROUTINE WaitRoutine;
  355. CSR_API_MSG WaitReplyMessage;
  356. } CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
  357. NTCSRAPI
  358. BOOLEAN
  359. NTAPI
  360. CsrCreateWait(
  361. IN PLIST_ENTRY WaitQueue,
  362. IN CSR_WAIT_ROUTINE WaitRoutine,
  363. IN PCSR_THREAD WaitingThread,
  364. IN OUT PCSR_API_MSG WaitReplyMessage,
  365. IN PVOID WaitParameter);
  366. NTCSRAPI
  367. VOID
  368. NTAPI
  369. CsrDereferenceWait(
  370. IN PLIST_ENTRY WaitQueue
  371. );
  372. NTCSRAPI
  373. BOOLEAN
  374. NTAPI
  375. CsrNotifyWait(
  376. IN PLIST_ENTRY WaitQueue,
  377. IN BOOLEAN SatisfyAll,
  378. IN PVOID SatisfyParameter1,
  379. IN PVOID SatisfyParameter2
  380. );
  381. NTCSRAPI
  382. VOID
  383. NTAPI
  384. CsrMoveSatisfiedWait(
  385. IN PLIST_ENTRY DstWaitQueue,
  386. IN PLIST_ENTRY SrcWaitQueue
  387. );
  388. NTCSRAPI
  389. PVOID
  390. NTAPI
  391. CsrAddStaticServerThread(
  392. IN HANDLE ThreadHandle,
  393. IN PCLIENT_ID ClientId,
  394. IN ULONG Flags
  395. );
  396. NTCSRAPI
  397. NTSTATUS
  398. NTAPI
  399. CsrExecServerThread(
  400. IN PUSER_THREAD_START_ROUTINE StartAddress,
  401. IN ULONG Flags
  402. );
  403. NTCSRAPI
  404. PCSR_THREAD
  405. NTAPI
  406. CsrConnectToUser(
  407. VOID
  408. );
  409. NTCSRAPI
  410. BOOLEAN
  411. NTAPI
  412. CsrImpersonateClient(
  413. IN PCSR_THREAD Thread
  414. );
  415. NTCSRAPI
  416. BOOLEAN
  417. NTAPI
  418. CsrRevertToSelf(
  419. VOID
  420. );
  421. NTCSRAPI
  422. VOID
  423. NTAPI
  424. CsrSetForegroundPriority(
  425. IN PCSR_PROCESS Process
  426. );
  427. NTCSRAPI
  428. VOID
  429. NTAPI
  430. CsrSetBackgroundPriority(
  431. IN PCSR_PROCESS Process
  432. );
  433. NTCSRAPI
  434. EXCEPTION_DISPOSITION
  435. NTAPI
  436. CsrUnhandledExceptionFilter(
  437. IN PEXCEPTION_POINTERS ExceptionInfo
  438. );
  439. NTCSRAPI
  440. BOOLEAN
  441. NTAPI
  442. CsrValidateMessageBuffer(
  443. IN CONST CSR_API_MSG *m,
  444. IN VOID CONST * CONST * Buffer,
  445. IN ULONG Count,
  446. IN ULONG Size
  447. );
  448. NTCSRAPI
  449. BOOLEAN
  450. NTAPI
  451. CsrValidateMessageString(
  452. IN CONST CSR_API_MSG *m,
  453. IN CONST PCWSTR *Buffer
  454. );
  455. typedef struct _CSR_FAST_ANSI_OEM_TABLES {
  456. char OemToAnsiTable[256];
  457. char AnsiToOemTable[256];
  458. } CSR_FAST_ANSI_OEM_TABLES, *PCSR_FAST_ANSI_OEM_TABLES;
  459. #ifdef __cplusplus
  460. }
  461. #endif
  462. #endif // _NTCSRSRVAPI_