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.

387 lines
13 KiB

  1. /****************************************************************************/
  2. // icap.h
  3. //
  4. // TermDD private header.
  5. //
  6. // Copyright (C) 1998-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #define ICA_POOL_TAG ' acI'
  9. /*
  10. * Enumerated ICA object types
  11. */
  12. typedef enum _ICA_TYPE {
  13. IcaType_Connection,
  14. IcaType_Stack,
  15. IcaType_Channel
  16. } ICA_TYPE;
  17. /*
  18. * ICA dispatch prototype
  19. */
  20. typedef NTSTATUS (*PICA_DISPATCH) (
  21. IN PVOID IcaObject,
  22. IN PIRP Irp,
  23. IN PIO_STACK_LOCATION IrpSp);
  24. /*
  25. * Deferred trace structure
  26. */
  27. #pragma warning(disable : 4200) // for Buffer[] nonstandard extension.
  28. typedef struct _DEFERRED_TRACE {
  29. struct _DEFERRED_TRACE *Next;
  30. ULONG Length;
  31. WCHAR Buffer[];
  32. } DEFERRED_TRACE, *PDEFERRED_TRACE;
  33. #pragma warning(default : 4200)
  34. /*
  35. * Trace Information structure
  36. */
  37. typedef struct _ICA_TRACE_INFO {
  38. ULONG TraceClass; // trace - enabled trace classes (TC_?)
  39. ULONG TraceEnable; // trace - enabled trace types (TT_?)
  40. BOOLEAN fTraceDebugger; // trace - send trace messages to the debugger
  41. BOOLEAN fTraceTimestamp; // trace - time stamp trace messages
  42. PWCHAR pTraceFileName;
  43. PFILE_OBJECT pTraceFileObject;
  44. PDEFERRED_TRACE pDeferredTrace;
  45. } ICA_TRACE_INFO, *PICA_TRACE_INFO;
  46. /*
  47. * Common header for all ICA objects
  48. */
  49. typedef struct _ICA_HEADER {
  50. ICA_TYPE Type;
  51. PICA_DISPATCH *pDispatchTable;
  52. } ICA_HEADER, *PICA_HEADER;
  53. /*
  54. * ICA connection object
  55. */
  56. typedef struct _ICA_CONNECTION {
  57. ICA_HEADER Header; // WARNING: This field MUST ALWAYS be first
  58. LONG RefCount; // Reference count for this connection
  59. ERESOURCE Resource; // Resource protecting access to this object
  60. BOOLEAN fPassthruEnabled;
  61. LIST_ENTRY StackHead; // List of stack objects for this connection
  62. LIST_ENTRY ChannelHead; // List of channel objects for this connection
  63. LIST_ENTRY VcBindHead; // List of vcbind objects for this connection
  64. ICA_TRACE_INFO TraceInfo; // trace information
  65. /*
  66. * Channel pointers array. This array should be indexed using the
  67. * channel number plus the virtual channel number. This allows a
  68. * fast lookup of any bound channel given the channel/virtual number.
  69. */
  70. struct _ICA_CHANNEL *pChannel[CHANNEL_COUNT+VIRTUAL_MAXIMUM];
  71. ERESOURCE ChannelTableLock;
  72. } ICA_CONNECTION, *PICA_CONNECTION;
  73. //
  74. // define the Maximum Low Water Mark setting to resume transmission
  75. //
  76. #define MAX_LOW_WATERMARK ((ULONG)((ULONG_PTR)-1))
  77. /*
  78. * ICA stack object
  79. */
  80. typedef struct _ICA_STACK {
  81. ICA_HEADER Header; // WARNING: This field MUST ALWAYS be first
  82. LONG RefCount; // Reference count for this stack
  83. ERESOURCE Resource; // Resource protecting access to this object
  84. STACKCLASS StackClass; // Stack type (primary/shadow)
  85. LIST_ENTRY StackEntry; // Links for connection object stack list
  86. LIST_ENTRY SdLinkHead; // Head of SDLINK list for this stack
  87. struct _ICA_STACK *pPassthru; // Pointer to passthru stack
  88. BOOLEAN fIoDisabled;
  89. BOOLEAN fClosing;
  90. BOOLEAN fDoingInput;
  91. BOOLEAN fDisablingIo;
  92. KEVENT IoEndEvent;
  93. LARGE_INTEGER LastInputTime; // last time of keyboard/mouse input
  94. PVOID pBrokenEventObject;
  95. /*
  96. * Pointer to connection object.
  97. * Note this is typed as PUCHAR instead of PICA_CONNECTION to prevent use
  98. * of it directly. All references to the connection object a stack is
  99. * attached to should be made by calling IcaGetConnectionForStack() if
  100. * the stack is already locked, or IcaLockConnectionForStack() otherwise.
  101. * This is required because this is a dynamic pointer, which can be
  102. * modified during stack reconnect.
  103. */
  104. PUCHAR pConnect; // Pointer to connection object
  105. BOOLEAN fWaitForOutBuf; // outbuf - did we hit the high watermark
  106. ULONG OutBufLength; // outbuf - length of output buffer
  107. ULONG OutBufCount; // outbuf - maximum number of outbufs
  108. ULONG OutBufAllocCount; // outbuf - number of outbufs allocated
  109. KEVENT OutBufEvent; // outbuf - allocate event
  110. ULONG SdOutBufHeader; // reserved output buffer header bytes
  111. ULONG SdOutBufTrailer; // reserved output buffer trailer bytes
  112. CLIENTMODULES ClientModules; // stack driver client module data
  113. PROTOCOLSTATUS ProtocolStatus; // stack driver protocol status
  114. LIST_ENTRY StackNode; // for linking all stacks together
  115. LARGE_INTEGER LastKeepAliveTime; // Time last keepalive packet sent
  116. ULONG OutBufLowWaterMark; // low water mark to resume transmission
  117. } ICA_STACK, *PICA_STACK;
  118. /*
  119. * Channel Filter Input/Output procedure prototype
  120. */
  121. typedef NTSTATUS
  122. (_stdcall * PFILTERPROC)( PVOID, PCHAR, ULONG, PINBUF * );
  123. /*
  124. * ICA channel filter object
  125. */
  126. typedef struct _ICA_FILTER {
  127. PFILTERPROC InputFilter; // Input filter procedure
  128. PFILTERPROC OutputFilter; // Output filter procedure
  129. } ICA_FILTER, *PICA_FILTER;
  130. /*
  131. * ICA virtual class bind structure
  132. */
  133. typedef struct _ICA_VCBIND {
  134. VIRTUALCHANNELNAME VirtualName; // Virtual channel name
  135. VIRTUALCHANNELCLASS VirtualClass; // Virtual channel number (0-31, -1 unbound)
  136. ULONG Flags;
  137. LIST_ENTRY Links; // Links for vcbind structure list
  138. } ICA_VCBIND, *PICA_VCBIND;
  139. /*
  140. * ICA channel object
  141. */
  142. typedef struct _ICA_CHANNEL {
  143. ICA_HEADER Header; // WARNING: This field MUST ALWAYS be first
  144. LONG RefCount; // Reference count for this channel
  145. ERESOURCE Resource; // Resource protecting access to this object
  146. ULONG Flags; // Channel flags (see CHANNEL_xxx below)
  147. LONG OpenCount; // Count of opens on this object
  148. PICA_CONNECTION pConnect; // Pointer to connection object
  149. PICA_FILTER pFilter; // Pointer to filter object for this channel
  150. CHANNELCLASS ChannelClass; // Channel type
  151. VIRTUALCHANNELNAME VirtualName; // Virtual channel name
  152. VIRTUALCHANNELCLASS VirtualClass; // Virtual channel number (0-31, -1 unbound)
  153. LIST_ENTRY Links; // Links for channel structure list
  154. LIST_ENTRY InputIrpHead; // Head of pending IRP list
  155. LIST_ENTRY InputBufHead; // Head of input buffer list
  156. unsigned InputBufCurSize; // Bytes held in input buffers.
  157. unsigned InputBufMaxSize; // High watermark for input buffers.
  158. PERESOURCE pChannelTableLock;
  159. ULONG CompletionRoutineCount;
  160. } ICA_CHANNEL, *PICA_CHANNEL;
  161. /*
  162. * VirtualClass - virtual channel is not yet bound to a virtual class number
  163. */
  164. #define UNBOUND_CHANNEL -1
  165. /*
  166. * Channel Flags
  167. */
  168. #define CHANNEL_MESSAGE_MODE 0x00000001 // This is a message mode channel
  169. #define CHANNEL_SHADOW_IO 0x00000002 // Pass shadow data
  170. #define CHANNEL_SCREENDATA 0x00000004 // This is a screen data channel
  171. #define CHANNEL_CLOSING 0x00000008 // This channel is being closed
  172. #define CHANNEL_SHADOW_PERSISTENT 0x00000010 // Used for virtual channels: still up during shadow
  173. #define CHANNEL_SESSION_DISABLEIO 0x00000020 // Used disable IO for help session while not in shadow mode
  174. #define CHANNEL_CANCEL_READS 0x00000040 // To cancel reads to CommandChannel on Winstation termination
  175. /*
  176. * Stack Driver load structure
  177. * There exists exactly one of these structures for
  178. * each Stack Driver (WD/PD/TD) loaded in the system.
  179. */
  180. typedef struct _SDLOAD {
  181. WDNAMEW SdName; // Name of this SD
  182. LONG RefCount; // Reference count
  183. LIST_ENTRY Links; // Links for SDLOAD list
  184. PVOID ImageHandle; // Image handle for this driver
  185. PVOID ImageBase; // Image base for this driver
  186. PSDLOADPROC DriverLoad; // Pointer to driver load routine
  187. PFILE_OBJECT FileObject; // Reference to underlying driver
  188. PVOID pUnloadWorkItem;// Pointer to workitem for delayed unload
  189. PDEVICE_OBJECT DeviceObject;// Pointer device object to use the unload safe completion routine
  190. } SDLOAD, *PSDLOAD;
  191. /*
  192. * Stack Driver link structure
  193. * There exists one of these structures for each WD/PD/TD in a stack.
  194. */
  195. typedef struct _SDLINK {
  196. PICA_STACK pStack; // Pointer to ICA_STACK object for this driver
  197. PSDLOAD pSdLoad; // Pointer to SDLOAD object for this driver
  198. LIST_ENTRY Links; // Links for SDLINK list
  199. LONG RefCount;
  200. SDCONTEXT SdContext; // Contains SD proc table, context value, callup table
  201. ERESOURCE Resource;
  202. } SDLINK, * PSDLINK;
  203. /*
  204. * Lock/Unlock macros
  205. */
  206. #if DBG
  207. /*
  208. *
  209. * NOTE: Under DBG builds, the following routines will validate
  210. * that the correct locking order is not violated.
  211. * The correct order is:
  212. * 1) Connection
  213. * 2) Stack
  214. * 3) Channel
  215. */
  216. BOOLEAN IcaLockConnection(PICA_CONNECTION);
  217. void IcaUnlockConnection(PICA_CONNECTION);
  218. BOOLEAN IcaLockStack(PICA_STACK);
  219. void IcaUnlockStack(PICA_STACK);
  220. BOOLEAN IcaLockChannel(PICA_CHANNEL);
  221. void IcaUnlockChannel(PICA_CHANNEL);
  222. #else // DBG
  223. #define IcaLockConnection(p) { \
  224. IcaReferenceConnection( p ); \
  225. KeEnterCriticalRegion(); /* Disable APC calls */ \
  226. ExAcquireResourceExclusiveLite( &p->Resource, TRUE ); \
  227. }
  228. #define IcaUnlockConnection(p) { \
  229. ExReleaseResourceLite( &p->Resource ); \
  230. KeLeaveCriticalRegion(); /* Re-enable APC calls */ \
  231. IcaDereferenceConnection( p ); \
  232. }
  233. #define IcaLockStack(p) { \
  234. IcaReferenceStack( p ); \
  235. KeEnterCriticalRegion(); /* Disable APC calls */ \
  236. ExAcquireResourceExclusiveLite( &p->Resource, TRUE ); \
  237. }
  238. #define IcaUnlockStack(p) { \
  239. ExReleaseResourceLite( &p->Resource ); \
  240. KeLeaveCriticalRegion(); /* Re-enable APC calls */ \
  241. IcaDereferenceStack( p ); \
  242. }
  243. #define IcaLockChannel(p) { \
  244. IcaReferenceChannel( p ); \
  245. KeEnterCriticalRegion(); /* Disable APC calls */ \
  246. ExAcquireResourceExclusiveLite( &p->Resource, TRUE ); \
  247. }
  248. #define IcaUnlockChannel(p) { \
  249. ExReleaseResourceLite( &p->Resource ); \
  250. KeLeaveCriticalRegion(); /* Re-enable APC calls */ \
  251. IcaDereferenceChannel(p); \
  252. }
  253. #endif // DBG
  254. PICA_CONNECTION IcaGetConnectionForStack(PICA_STACK);
  255. PICA_CONNECTION IcaLockConnectionForStack(PICA_STACK);
  256. void IcaUnlockConnectionForStack(PICA_STACK);
  257. /*
  258. * Memory alloc/free macros
  259. */
  260. #if DBG
  261. PVOID IcaAllocatePool(IN POOL_TYPE, IN ULONG, PCHAR, ULONG, BOOLEAN);
  262. #define ICA_ALLOCATE_POOL(a,b) IcaAllocatePool(a, b, __FILE__, __LINE__, FALSE)
  263. #define ICA_ALLOCATE_POOL_WITH_QUOTA(a,b) IcaAllocatePool(a, b, __FILE__, __LINE__, TRUE)
  264. void IcaFreePool (IN PVOID);
  265. #define ICA_FREE_POOL(a) IcaFreePool(a)
  266. #else // DBG
  267. #define ICA_ALLOCATE_POOL(a,b) ExAllocatePoolWithTag(a,b,ICA_POOL_TAG)
  268. #define ICA_ALLOCATE_POOL_WITH_QUOTA(a,b) ExAllocatePoolWithQuotaTag(a,b,ICA_POOL_TAG)
  269. #define ICA_FREE_POOL(a) ExFreePool(a)
  270. #endif // DBG
  271. /*
  272. * Spinlock acquire/release macros
  273. */
  274. #if DBG
  275. extern ULONG IcaLocksAcquired;
  276. #define IcaAcquireSpinLock(a,b) KeAcquireSpinLock((a),(b)); IcaLocksAcquired++
  277. #define IcaReleaseSpinLock(a,b) IcaLocksAcquired--; KeReleaseSpinLock((a),(b))
  278. void IcaInitializeDebugData(void);
  279. #else // DBG
  280. #define IcaAcquireSpinLock(a,b) KeAcquireSpinLock((a),(b))
  281. #define IcaReleaseSpinLock(a,b) KeReleaseSpinLock((a),(b))
  282. #endif // DBG
  283. /*
  284. * Trace
  285. */
  286. extern ICA_TRACE_INFO G_TraceInfo;
  287. #undef TRACE
  288. #undef TRACESTACK
  289. #undef TRACESTACKBUF
  290. #undef TRACECHANNEL
  291. #if DBG
  292. VOID _cdecl _IcaTrace( PICA_CONNECTION, ULONG, ULONG, CHAR *, ... );
  293. VOID _cdecl _IcaStackTrace( PICA_STACK, ULONG, ULONG, CHAR *, ... );
  294. VOID _IcaStackTraceBuffer( PICA_STACK, ULONG, ULONG, PVOID, ULONG );
  295. VOID _cdecl _IcaChannelTrace( PICA_CHANNEL, ULONG, ULONG, CHAR *, ... );
  296. #define TRACE(_arg) _IcaTrace _arg
  297. #define TRACESTACK(_arg) _IcaStackTrace _arg
  298. #define TRACESTACKBUF(_arg) _IcaStackTraceBuffer _arg
  299. #define TRACECHANNEL(_arg) _IcaChannelTrace _arg
  300. #else
  301. #define TRACE(_arg)
  302. #define TRACESTACK(_arg)
  303. #define TRACESTACKBUF(_arg)
  304. #define TRACECHANNEL(_arg)
  305. #endif
  306. /*
  307. * Need to define these to have MP save driver ( proper locked operation will generated for x86)-Bug# 209464
  308. */
  309. #define _NTSRV_
  310. #define _NTDDK_