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.

259 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. MRxProxyAsyncEng.h
  5. Abstract:
  6. This module defines the types and functions related to the SMB protocol
  7. selection engine: the component that translates minirdr calldowns into
  8. SMBs.
  9. Revision History:
  10. --*/
  11. #ifndef _ASYNCENG_H_
  12. #define _ASYNCENG_H_
  13. #include "innerio.h"
  14. IMPORTANT_STRUCTURE(MRXPROXY_ASYNCENGINE_CONTEXT);
  15. #define MRXPROXY_ASYNCENGINE_ARGUMENT_SIGNATURE \
  16. PMRXPROXY_ASYNCENGINE_CONTEXT AsyncEngineContext, \
  17. PRX_CONTEXT RxContext
  18. #define MRXPROXY_ASYNCENGINE_ARGUMENTS \
  19. AsyncEngineContext,RxContext
  20. #if DBG
  21. #define OECHKLINKAGE_FLAG_NO_REQPCKT_CHECK 0x00000001
  22. VOID
  23. __MRxProxyAsyncEngOEAssertConsistentLinkage(
  24. PSZ MsgPrefix,
  25. PSZ File,
  26. unsigned Line,
  27. PRX_CONTEXT RxContext,
  28. PMRXPROXY_ASYNCENGINE_CONTEXT AsyncEngineContext,
  29. ULONG Flags
  30. );
  31. #define MRxProxyAsyncEngOEAssertConsistentLinkage(a) {\
  32. __MRxProxyAsyncEngOEAssertConsistentLinkage(a,__FILE__,__LINE__,RxContext,AsyncEngineContext,0);\
  33. }
  34. #define MRxProxyAsyncEngOEAssertConsistentLinkageFromOE(a) {\
  35. ASSERT_ASYNCENG_CONTEXT(AsyncEngineContext); \
  36. __MRxProxyAsyncEngOEAssertConsistentLinkage(a,__FILE__,__LINE__, \
  37. AsyncEngineContext->RxContext, \
  38. AsyncEngineContext,0); \
  39. }
  40. #define MRxProxyAsyncEngOEAssertConsistentLinkageFromOEwithFlags(a,FLAGS) {\
  41. ASSERT_ASYNCENG_CONTEXT(AsyncEngineContext); \
  42. __MRxProxyAsyncEngOEAssertConsistentLinkage(a,__FILE__,__LINE__, \
  43. AsyncEngineContext->RxContext, \
  44. AsyncEngineContext,FLAGS); \
  45. }
  46. #else
  47. #define MRxProxyAsyncEngOEAssertConsistentLinkage(a) {NOTHING;}
  48. #define MRxProxyAsyncEngOEAssertConsistentLinkageFromOE(a) {NOTHING;}
  49. #define MRxProxyAsyncEngOEAssertConsistentLinkageFromOEwithFlags(a,b) {NOTHING;}
  50. #endif
  51. typedef
  52. NTSTATUS
  53. (*PMRXPROXY_ASYNCENG_CONTINUE_ROUTINE) (
  54. MRXPROXY_ASYNCENGINE_ARGUMENT_SIGNATURE
  55. );
  56. //typedef
  57. //NTSTATUS
  58. //(*PMRXPROXY_ASYNCENG_FINISH_ROUTINE) (
  59. // PMRXPROXY_ASYNCENGINE_CONTEXT
  60. // );
  61. #define MRXPROXY_ASYNCENG_OE_HISTORY_SIZE 32
  62. typedef struct _ASYNCENG_HISTORY {
  63. ULONG Next;
  64. ULONG Submits; //could be shortened....
  65. struct {
  66. ULONG Longs[2];
  67. } Markers[MRXPROXY_ASYNCENG_OE_HISTORY_SIZE];
  68. } ASYNCENG_HISTORY;
  69. #if DBG
  70. VOID MRxProxyAsyncEngUpdateOEHistory(
  71. PMRXPROXY_ASYNCENGINE_CONTEXT AsyncEngineContext,
  72. ULONG Tag1,
  73. ULONG Tag2
  74. );
  75. #define UPDATE_OE_HISTORY_LONG(a) {MRxProxyAsyncEngUpdateOEHistory(AsyncEngineContext,a,0);}
  76. #define UPDATE_OE_HISTORY_2SHORTS(a,b) {MRxProxyAsyncEngUpdateOEHistory(AsyncEngineContext,a,b);}
  77. #else
  78. #define UPDATE_OE_HISTORY_LONG(a)
  79. #define UPDATE_OE_HISTORY_2SHORTS(a,b)
  80. #endif //if DBG
  81. //these are used by the continuation routines to specify what kind of
  82. //async submit is being done
  83. typedef enum _MRXPROXY_ASYNCENGINE_CONTEXT_TYPE {
  84. //MRXPROXY_ASYNCENG_AECTXTYPE_CREATE,
  85. MRXPROXY_ASYNCENG_AECTXTYPE_READ,
  86. MRXPROXY_ASYNCENG_AECTXTYPE_WRITE,
  87. MRXPROXY_ASYNCENG_AECTXTYPE_QUERYDIR,
  88. MRXPROXY_ASYNCENG_AECTXTYPE_LOCKS,
  89. MRXPROXY_ASYNCENG_AECTXTYPE_FLUSH,
  90. MRXPROXY_ASYNCENG_AECTXTYPE_CLOSE,
  91. //MRXPROXY_ASYNCENG_AECTXTYPE_SEARCH,
  92. MRXPROXY_ASYNCENG_AECTXTYPE_MAXIMUM
  93. } MRXPROXY_ASYNCENGINE_CONTEXT_TYPE;
  94. //these are used by the entry point routines to specify what entrypoint was
  95. //called....this facilitates common continuation routines
  96. typedef enum _MRXPROXY_ASYNCENGINE_CONTEXT_ENTRYPOINTS {
  97. MRXPROXY_ASYNCENG_CTX_FROM_LOCKS,
  98. MRXPROXY_ASYNCENG_CTX_FROM_FLUSH,
  99. MRXPROXY_ASYNCENG_CTX_FROM_CLEANUPFOBX,
  100. MRXPROXY_ASYNCENG_CTX_FROM_CLOSESRVCALL,
  101. MRXPROXY_ASYNCENG_CTX_FROM_CREATE,
  102. MRXPROXY_ASYNCENG_CTX_FROM_RENAME,
  103. MRXPROXY_ASYNCENG_CTX_FROM_READ,
  104. MRXPROXY_ASYNCENG_CTX_FROM_WRITE,
  105. MRXPROXY_ASYNCENG_CTX_FROM_QUERYDIR,
  106. MRXPROXY_ASYNCENG_CTX_FROM_FAKESETDELETEDISPOSITION,
  107. MRXPROXY_ASYNCENG_CTX_FROM_MAXIMUM
  108. } MRXPROXY_ASYNCENGINE_CONTEXT_ENTRYPOINTS;
  109. #define MRXPROXY_ASYNCENG_DEFINE_CTX_FLAG(a,c) RX_DEFINE_FLAG(MRXPROXY_ASYNCENG_CTX_FLAG_##a,c,0xffff)
  110. typedef enum {
  111. MRXPROXY_ASYNCENG_DEFINE_CTX_FLAG(MUST_SUCCEED_ALLOCATED, 0)
  112. MRXPROXY_ASYNCENG_DEFINE_CTX_FLAG(AWAITING_DISPATCH, 1)
  113. MRXPROXY_ASYNCENG_DEFINE_CTX_FLAG(ASYNC_OPERATION, 2)
  114. MRXPROXY_ASYNCENG_DEFINE_CTX_FLAG(POSTED_RESUME, 3)
  115. //MRXPROXY_ASYNCENG_DEFINE_CTX_FLAG(NETROOT_GOOD, 15)
  116. } RX_CONTEXT_CREATE_FLAGS;
  117. typedef enum _MRXPROXY_ASYNCENG_OE_INNERIO_STATE {
  118. MRxProxyAsyncEngOEInnerIoStates_Initial = 0,
  119. MRxProxyAsyncEngOEInnerIoStates_ReadyToSend,
  120. MRxProxyAsyncEngOEInnerIoStates_OperationOutstanding
  121. } MRXPROXY_ASYNCENG_OE_INNERIO_STATE;
  122. typedef struct _MRXPROXY_ASYNCENGINE_CONTEXT{
  123. MRX_NORMAL_NODE_HEADER;
  124. PRX_CONTEXT RxContext;
  125. PIRP CalldownIrp;
  126. union {
  127. IO_STATUS_BLOCK;
  128. IO_STATUS_BLOCK IoStatusBlock;
  129. };
  130. RX_WORK_QUEUE_ITEM WorkQueueItem;
  131. MRXPROXY_ASYNCENGINE_CONTEXT_TYPE AECTXType;
  132. MRXPROXY_ASYNCENGINE_CONTEXT_ENTRYPOINTS EntryPoint;
  133. ULONG ContinueEntryCount;
  134. USHORT Flags;
  135. UCHAR OpSpecificFlags;
  136. UCHAR OpSpecificState;
  137. PMRXPROXY_ASYNCENG_CONTINUE_ROUTINE Continuation;
  138. //PMRXPROXY_ASYNCENG_FINISH_ROUTINE FinishRoutine;
  139. union {
  140. struct {
  141. PUCHAR PtrToLockType; //this must be here because the beginning of the
  142. //lockstart code sets the locklist to zero which will be this
  143. //CODE.IMPROVEMENT.ASHAMED fix this up so that assert locks uses readwrite
  144. PMRX_SRV_OPEN SrvOpen;
  145. PRX_LOCK_ENUMERATOR LockEnumerator;
  146. PVOID ContinuationHandle;
  147. ULONG NumberOfLocksPlaced;
  148. LARGE_INTEGER NextLockOffset;
  149. LARGE_INTEGER NextLockRange;
  150. BOOLEAN NextLockIsExclusive;
  151. BOOLEAN LockAreaNonEmpty;
  152. BOOLEAN EndOfListReached;
  153. } AssertLocks;
  154. } ;
  155. //#if DBG CODE.IMPROVEMENT we should get rid of what we don't really, really need
  156. ULONG SerialNumber;
  157. ASYNCENG_HISTORY History;
  158. PIRP RxContextCapturedRequestPacket;
  159. PMDL SaveDataMdlForDebug;
  160. ULONG SaveLengthForDebug;
  161. PMDL SaveIrpMdlForDebug;
  162. //#endif
  163. } MRXPROXY_ASYNCENGINE_CONTEXT, *PMRXPROXY_ASYNCENGINE_CONTEXT;
  164. NTSTATUS
  165. MRxProxySubmitAsyncEngRequest(
  166. MRXPROXY_ASYNCENGINE_ARGUMENT_SIGNATURE,
  167. IN MRXPROXY_ASYNCENGINE_CONTEXT_TYPE AECTXType
  168. );
  169. NTSTATUS
  170. MRxProxyResumeAsyncEngineContext(
  171. IN OUT PRX_CONTEXT RxContext
  172. );
  173. #define ASSERT_ASYNCENG_CONTEXT(__p) ASSERT(NodeType(__p)==PROXY_NTC_ASYNCENGINE_CONTEXT)
  174. NTSTATUS
  175. __MRxProxyAsyncEngineOuterWrapper (
  176. IN PRX_CONTEXT RxContext,
  177. IN MRXPROXY_ASYNCENGINE_CONTEXT_ENTRYPOINTS EntryPoint,
  178. IN PMRXPROXY_ASYNCENG_CONTINUE_ROUTINE Continuation
  179. #if DBG
  180. ,IN PSZ RoutineName,
  181. IN BOOLEAN LoudProcessing,
  182. IN BOOLEAN StopOnLoud
  183. #endif
  184. );
  185. #if DBG
  186. #define MRxProxyAsyncEngineOuterWrapper(r,e,c,x1,x2,x3) \
  187. __MRxProxyAsyncEngineOuterWrapper(r,e,c,x1,x2,x3)
  188. #else
  189. #define MRxProxyAsyncEngineOuterWrapper(r,e,c,x1,x2,x3) \
  190. __MRxProxyAsyncEngineOuterWrapper(r,e,c)
  191. #endif
  192. PMRXPROXY_ASYNCENGINE_CONTEXT
  193. MRxProxyCreateAsyncEngineContext (
  194. IN PRX_CONTEXT RxContext,
  195. IN MRXPROXY_ASYNCENGINE_CONTEXT_ENTRYPOINTS EntryPoint
  196. );
  197. #define MRxProxyReferenceAsyncEngineContext(AsyncEngineContext) {\
  198. ULONG result = InterlockedIncrement(&(AsyncEngineContext)->NodeReferenceCount); \
  199. RxDbgTrace(0, (DEBUG_TRACE_MRXPROXY_ASYNCENG), \
  200. ("ReferenceAsyncEngineContext result=%08lx\n", result )); \
  201. }
  202. BOOLEAN
  203. MRxProxyFinalizeAsyncEngineContext (
  204. IN OUT PMRXPROXY_ASYNCENGINE_CONTEXT AsyncEngineContext
  205. );
  206. // this macro is used to do the async completion for read/write/locks. Note that the call to lowiocompletion
  207. // will try to complete the irp thereby freeing the user's mdl.
  208. // we use this macro so that there will be only one version of this code. when we combine start routines,
  209. // this will be un macroed
  210. #define MRxProxyAsyncEngAsyncCompletionIfNecessary(AECTX,RXCONTEXT) { \
  211. if (ContinueEntryCount>1) { \
  212. BOOLEAN FinalizationComplete; \
  213. if (FALSE) {DbgBreakPoint(); } \
  214. (RXCONTEXT)->StoredStatus = Status; \
  215. RxLowIoCompletion((RXCONTEXT)); \
  216. FinalizationComplete = MRxProxyFinalizeAsyncEngineContext((AECTX)); \
  217. ASSERT(!FinalizationComplete); \
  218. }}
  219. NTSTATUS
  220. MRxProxyAsyncEngineCalldownIrpCompletion (
  221. IN PDEVICE_OBJECT DeviceObject,
  222. IN PIRP CalldownIrp,
  223. IN OUT PVOID Context
  224. );
  225. #endif // _ASYNCENG_H_
  226.