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.

571 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. csrsrv.h
  5. Abstract:
  6. Main include file for Server side of the Client Server Runtime (CSR)
  7. Author:
  8. Steve Wood (stevewo) 8-Oct-1990
  9. Revision History:
  10. --*/
  11. //
  12. // Include definitions common between the Client and Server portions.
  13. //
  14. #include "csr.h"
  15. //
  16. // Include definitions specific to the Server portion.
  17. //
  18. #include "ntcsrsrv.h"
  19. #define NOEXTAPI
  20. #include "wdbgexts.h"
  21. #include "ntdbg.h"
  22. //
  23. // Define debugging flags and macro for testing them. All debug code
  24. // should be contained within a IF_CSR_DEBUG macro call so that when
  25. // the system is compiled with debug code disabled, none of the code
  26. // is generated.
  27. //
  28. #if DBG
  29. #define CSR_DEBUG_INIT 0x00000001
  30. #define CSR_DEBUG_LPC 0x00000002
  31. #define CSR_DEBUG_FLAG3 0x00000004
  32. #define CSR_DEBUG_FLAG4 0x00000008
  33. #define CSR_DEBUG_FLAG5 0x00000010
  34. #define CSR_DEBUG_FLAG6 0x00000020
  35. #define CSR_DEBUG_FLAG7 0x00000040
  36. #define CSR_DEBUG_FLAG8 0x00000080
  37. #define CSR_DEBUG_FLAG9 0x00000100
  38. #define CSR_DEBUG_FLAG10 0x00000200
  39. #define CSR_DEBUG_FLAG11 0x00000400
  40. #define CSR_DEBUG_FLAG12 0x00000800
  41. #define CSR_DEBUG_FLAG13 0x00001000
  42. #define CSR_DEBUG_FLAG14 0x00002000
  43. #define CSR_DEBUG_FLAG15 0x00004000
  44. #define CSR_DEBUG_FLAG16 0x00008000
  45. #define CSR_DEBUG_FLAG17 0x00010000
  46. #define CSR_DEBUG_FLAG18 0x00020000
  47. #define CSR_DEBUG_FLAG19 0x00040000
  48. #define CSR_DEBUG_FLAG20 0x00080000
  49. #define CSR_DEBUG_FLAG21 0x00100000
  50. #define CSR_DEBUG_FLAG22 0x00200000
  51. #define CSR_DEBUG_FLAG23 0x00400000
  52. #define CSR_DEBUG_FLAG24 0x00800000
  53. #define CSR_DEBUG_FLAG25 0x01000000
  54. #define CSR_DEBUG_FLAG26 0x02000000
  55. #define CSR_DEBUG_FLAG27 0x04000000
  56. #define CSR_DEBUG_FLAG28 0x08000000
  57. #define CSR_DEBUG_FLAG29 0x10000000
  58. #define CSR_DEBUG_FLAG30 0x20000000
  59. #define CSR_DEBUG_FLAG31 0x40000000
  60. #define CSR_DEBUG_FLAG32 0x80000000
  61. ULONG CsrDebug;
  62. #define IF_CSR_DEBUG( ComponentFlag ) \
  63. if (CsrDebug & (CSR_DEBUG_ ## ComponentFlag))
  64. #define SafeBreakPoint() \
  65. if (NtCurrentPeb()->BeingDebugged) { \
  66. DbgBreakPoint(); \
  67. }
  68. #else
  69. #define IF_CSR_DEBUG( ComponentFlag ) if (FALSE)
  70. #define SafeBreakPoint()
  71. #endif
  72. #if DBG
  73. #define CSRSS_PROTECT_HANDLES 1
  74. BOOLEAN
  75. ProtectHandle(
  76. HANDLE hObject
  77. );
  78. BOOLEAN
  79. UnProtectHandle(
  80. HANDLE hObject
  81. );
  82. #else
  83. #define CSRSS_PROTECT_HANDLES 0
  84. #define ProtectHandle( hObject )
  85. #define UnProtectHandle( hObject )
  86. #endif
  87. //
  88. // Event indicating the csr server has completed initialization.
  89. //
  90. HANDLE CsrInitializationEvent;
  91. //
  92. // Include NT Session Manager and Debug SubSystem Interfaces
  93. #include <ntsm.h>
  94. typedef BOOLEAN (*PSB_API_ROUTINE)( IN PSBAPIMSG SbApiMsg );
  95. //
  96. // Global data accessed by Client-Server Runtime Server
  97. //
  98. PVOID CsrHeap;
  99. HANDLE CsrObjectDirectory;
  100. #define CSR_SBAPI_PORT_NAME L"SbApiPort"
  101. UNICODE_STRING CsrDirectoryName;
  102. UNICODE_STRING CsrApiPortName;
  103. UNICODE_STRING CsrSbApiPortName;
  104. HANDLE CsrApiPort;
  105. HANDLE CsrSbApiPort;
  106. HANDLE CsrSmApiPort;
  107. ULONG CsrMaxApiRequestThreads;
  108. #define CSR_MAX_THREADS 16
  109. #define CSR_STATIC_API_THREAD 0x00000010
  110. PCSR_THREAD CsrSbApiRequestThreadPtr;
  111. #define FIRST_SEQUENCE_COUNT 5
  112. //
  113. // Routines defined in srvinit.c
  114. //
  115. //
  116. // Hydra Specific Globals and prototypes
  117. //
  118. #define SESSION_ROOT L"\\Sessions"
  119. #define DOSDEVICES L"\\DosDevices"
  120. #define MAX_SESSION_PATH 256
  121. ULONG SessionId;
  122. HANDLE SessionObjectDirectory;
  123. HANDLE DosDevicesDirectory;
  124. HANDLE BNOLinksDirectory;
  125. HANDLE SessionsObjectDirectory;
  126. NTSTATUS
  127. CsrCreateSessionObjectDirectory( ULONG SessionID );
  128. //
  129. // The CsrNtSysInfo global variable contains NT specific constants of
  130. // interest, such as page size, allocation granularity, etc. It is filled
  131. // in once during process initialization.
  132. //
  133. SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
  134. #define ROUND_UP_TO_PAGES(SIZE) (((ULONG)(SIZE) + CsrNtSysInfo.PageSize - 1) & ~(CsrNtSysInfo.PageSize - 1))
  135. #define ROUND_DOWN_TO_PAGES(SIZE) (((ULONG)(SIZE)) & ~(CsrNtSysInfo.PageSize - 1))
  136. #define QUAD_ALIGN(VALUE) ( ((ULONG_PTR)(VALUE) + 7) & ~7 )
  137. NTSTATUS
  138. CsrParseServerCommandLine(
  139. IN ULONG argc,
  140. IN PCH argv[]
  141. );
  142. NTSTATUS
  143. CsrServerDllInitialization(
  144. IN PCSR_SERVER_DLL LoadedServerDll
  145. );
  146. NTSTATUS
  147. CsrSrvUnusedFunction(
  148. IN OUT PCSR_API_MSG m,
  149. IN OUT PCSR_REPLY_STATUS ReplyStatus
  150. );
  151. NTSTATUS
  152. CsrEnablePrivileges(
  153. VOID
  154. );
  155. //
  156. // Routines define in srvdebug.c
  157. //
  158. #if DBG
  159. #else
  160. #endif // DBG
  161. //
  162. // Routines defined in sbinit.c
  163. //
  164. NTSTATUS
  165. CsrSbApiPortInitialize( VOID );
  166. VOID
  167. CsrSbApiPortTerminate(
  168. NTSTATUS Status
  169. );
  170. //
  171. // Routines defined in sbreqst.c
  172. //
  173. NTSTATUS
  174. CsrSbApiRequestThread(
  175. IN PVOID Parameter
  176. );
  177. //
  178. // Routines defined in sbapi.c
  179. //
  180. BOOLEAN
  181. CsrSbCreateSession(
  182. IN PSBAPIMSG Msg
  183. );
  184. BOOLEAN
  185. CsrSbTerminateSession(
  186. IN PSBAPIMSG Msg
  187. );
  188. BOOLEAN
  189. CsrSbForeignSessionComplete(
  190. IN PSBAPIMSG Msg
  191. );
  192. //
  193. // Routines defined in session.c
  194. //
  195. RTL_CRITICAL_SECTION CsrNtSessionLock;
  196. LIST_ENTRY CsrNtSessionList;
  197. #define LockNtSessionList() RtlEnterCriticalSection( &CsrNtSessionLock )
  198. #define UnlockNtSessionList() RtlLeaveCriticalSection( &CsrNtSessionLock )
  199. NTSTATUS
  200. CsrInitializeNtSessionList( VOID );
  201. PCSR_NT_SESSION
  202. CsrAllocateNtSession(
  203. ULONG SessionId
  204. );
  205. VOID
  206. CsrReferenceNtSession(
  207. PCSR_NT_SESSION Session
  208. );
  209. VOID
  210. CsrDereferenceNtSession(
  211. PCSR_NT_SESSION Session,
  212. NTSTATUS ExitStatus
  213. );
  214. //
  215. // Routines defined in apiinit.c
  216. //
  217. NTSTATUS
  218. CsrApiPortInitialize( VOID );
  219. //
  220. // Routines defined in apireqst.c
  221. //
  222. NTSTATUS
  223. CsrApiRequestThread(
  224. IN PVOID Parameter
  225. );
  226. BOOLEAN
  227. CsrCaptureArguments(
  228. IN PCSR_THREAD t,
  229. IN PCSR_API_MSG m
  230. );
  231. VOID
  232. CsrReleaseCapturedArguments(
  233. IN PCSR_API_MSG m
  234. );
  235. ULONG
  236. CsrSrvNullApiCall(
  237. IN OUT PCSR_API_MSG m,
  238. IN OUT PCSR_REPLY_STATUS ReplyStatus
  239. );
  240. //
  241. // Routines and data defined in srvloadr.c
  242. //
  243. #define CSR_MAX_SERVER_DLL 4
  244. PCSR_SERVER_DLL CsrLoadedServerDll[ CSR_MAX_SERVER_DLL ];
  245. ULONG CsrTotalPerProcessDataLength;
  246. HANDLE CsrSrvSharedSection;
  247. ULONG CsrSrvSharedSectionSize;
  248. PVOID CsrSrvSharedSectionBase;
  249. PVOID CsrSrvSharedSectionHeap;
  250. PVOID *CsrSrvSharedStaticServerData;
  251. #define CSR_BASE_PATH L"\\REGISTRY\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Subsystems\\CSRSS"
  252. #define IsTerminalServer() (BOOLEAN)(USER_SHARED_DATA->SuiteMask & (1 << TerminalServer))
  253. NTSTATUS
  254. CsrLoadServerDll(
  255. IN PCH ModuleName,
  256. IN PCH InitRoutineString,
  257. IN ULONG ServerDllIndex
  258. );
  259. ULONG
  260. CsrSrvClientConnect(
  261. IN OUT PCSR_API_MSG m,
  262. IN OUT PCSR_REPLY_STATUS ReplyStatus
  263. );
  264. NTSTATUS
  265. CsrSrvCreateSharedSection(
  266. IN PCH SizeParameter
  267. );
  268. NTSTATUS
  269. CsrSrvAttachSharedSection(
  270. IN PCSR_PROCESS Process OPTIONAL,
  271. OUT PCSR_API_CONNECTINFO p
  272. );
  273. //
  274. // Routines and data defined in process.c
  275. //
  276. //
  277. // The CsrProcessStructureLock critical section protects all of the link
  278. // fields of the Windows Process objects. You must own this lock to examine
  279. // or modify any of the following fields of the CSR_PROCESS structure:
  280. //
  281. // ListLink
  282. //
  283. // It also protects the following variables:
  284. //
  285. // CsrRootProcess
  286. //
  287. RTL_CRITICAL_SECTION CsrProcessStructureLock;
  288. #define AcquireProcessStructureLock() RtlEnterCriticalSection( &CsrProcessStructureLock )
  289. #define ReleaseProcessStructureLock() RtlLeaveCriticalSection( &CsrProcessStructureLock )
  290. #define ProcessStructureListLocked() \
  291. (CsrProcessStructureLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)
  292. //
  293. // The following is a dummy process that acts as the root of the Windows Process
  294. // Structure. It has a ClientId of -1.-1 so it does not conflict with actual
  295. // Windows Processes. All processes created via the session manager are children
  296. // of this process, as are all orphaned processes. The ListLink field of this
  297. // process is the head of a list of all Windows Processes.
  298. //
  299. PCSR_PROCESS CsrRootProcess;
  300. //
  301. // reference/dereference thread are public in ntcsrsrv.h
  302. //
  303. VOID
  304. CsrLockedReferenceProcess(
  305. PCSR_PROCESS p
  306. );
  307. VOID
  308. CsrLockedReferenceThread(
  309. PCSR_THREAD t
  310. );
  311. VOID
  312. CsrLockedDereferenceProcess(
  313. PCSR_PROCESS p
  314. );
  315. VOID
  316. CsrLockedDereferenceThread(
  317. PCSR_THREAD t
  318. );
  319. NTSTATUS
  320. CsrInitializeProcessStructure( VOID );
  321. PCSR_PROCESS
  322. CsrAllocateProcess( VOID );
  323. VOID
  324. CsrDeallocateProcess(
  325. IN PCSR_PROCESS Process
  326. );
  327. VOID
  328. CsrInsertProcess(
  329. IN PCSR_PROCESS ParentProcess,
  330. IN PCSR_PROCESS CallingProcess,
  331. IN PCSR_PROCESS Process
  332. );
  333. VOID
  334. CsrRemoveProcess(
  335. IN PCSR_PROCESS Process
  336. );
  337. PCSR_THREAD
  338. CsrAllocateThread(
  339. IN PCSR_PROCESS Process
  340. );
  341. VOID
  342. CsrDeallocateThread(
  343. IN PCSR_THREAD Thread
  344. );
  345. VOID
  346. CsrInsertThread(
  347. IN PCSR_PROCESS Process,
  348. IN PCSR_THREAD Thread
  349. );
  350. VOID
  351. CsrRemoveThread(
  352. IN PCSR_THREAD Thread
  353. );
  354. PCSR_THREAD
  355. CsrLocateThreadByClientId(
  356. OUT PCSR_PROCESS *Process,
  357. IN PCLIENT_ID ClientId
  358. );
  359. NTSTATUS
  360. CsrUiLookup(
  361. IN PCLIENT_ID AppClientId,
  362. OUT PCLIENT_ID DebugUiClientId
  363. );
  364. NTSTATUS
  365. CsrSrvIdentifyAlertableThread(
  366. IN OUT PCSR_API_MSG m,
  367. IN OUT PCSR_REPLY_STATUS ReplyStatus
  368. );
  369. NTSTATUS
  370. CsrSrvSetPriorityClass(
  371. IN OUT PCSR_API_MSG m,
  372. IN OUT PCSR_REPLY_STATUS ReplyStatus
  373. );
  374. //
  375. // Routines and data defined in csrdebug.c
  376. //
  377. VOID
  378. CsrSuspendProcess(
  379. IN PCSR_PROCESS Process
  380. );
  381. VOID
  382. CsrResumeProcess(
  383. IN PCSR_PROCESS Process
  384. );
  385. //
  386. // Routines and data defined in wait.c
  387. //
  388. #define AcquireWaitListsLock() RtlEnterCriticalSection( &CsrWaitListsLock )
  389. #define ReleaseWaitListsLock() RtlLeaveCriticalSection( &CsrWaitListsLock )
  390. RTL_CRITICAL_SECTION CsrWaitListsLock;
  391. BOOLEAN
  392. CsrInitializeWait(
  393. IN CSR_WAIT_ROUTINE WaitRoutine,
  394. IN PCSR_THREAD WaitingThread,
  395. IN OUT PCSR_API_MSG WaitReplyMessage,
  396. IN PVOID WaitParameter,
  397. OUT PCSR_WAIT_BLOCK *WaitBlockPtr
  398. );
  399. BOOLEAN
  400. CsrNotifyWaitBlock(
  401. IN PCSR_WAIT_BLOCK WaitBlock,
  402. IN PLIST_ENTRY WaitQueue,
  403. IN PVOID SatisfyParameter1,
  404. IN PVOID SatisfyParameter2,
  405. IN ULONG WaitFlags,
  406. IN BOOLEAN DereferenceThread
  407. );
  408. ULONG CsrBaseTag;
  409. ULONG CsrSharedBaseTag;
  410. #define MAKE_TAG( t ) (RTL_HEAP_MAKE_TAG( CsrBaseTag, t ))
  411. #define TMP_TAG 0
  412. #define INIT_TAG 1
  413. #define CAPTURE_TAG 2
  414. #define PROCESS_TAG 3
  415. #define THREAD_TAG 4
  416. #define SECURITY_TAG 5
  417. #define SESSION_TAG 6
  418. #define WAIT_TAG 7
  419. #define MAKE_SHARED_TAG( t ) (RTL_HEAP_MAKE_TAG( CsrSharedBaseTag, t ))
  420. #define SHR_INIT_TAG 0
  421. //
  422. // Routines and data defined in process.c
  423. //
  424. BOOLEAN
  425. CsrSbCreateProcess(
  426. IN OUT PSBAPIMSG m
  427. );