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.

509 lines
13 KiB

  1. /************************************************************************
  2. Copyright (c) 1993-2000 Microsoft Corporation
  3. Module Name :
  4. pipendr.h
  5. Abstract :
  6. NDR Pipe related definitions.
  7. Author :
  8. RyszardK December 1995
  9. Revision History :
  10. ***********************************************************************/
  11. #ifndef _PIPENDR_H_
  12. #define _PIPENDR_H_
  13. #include "interp2.h"
  14. typedef struct _NDR_PIPE_DESC * PNDR_PIPE_DESC;
  15. #define PIPE_PARTIAL_BUFFER_SIZE 5000
  16. #define PIPE_ELEM_BUFFER_SIZE 5000
  17. //
  18. // Signature and version
  19. //
  20. #define NDR_PIPE_SIGNATURE (ushort) 0x5667
  21. #define NDR_PIPE_VERSION (short) 0x3031
  22. //
  23. // Pipe flags
  24. //
  25. #define NDR_IN_PIPE 0x0001
  26. #define NDR_OUT_PIPE 0x0002
  27. #define NDR_LAST_IN_PIPE 0x0004
  28. #define NDR_LAST_OUT_PIPE 0x0008
  29. #define NDR_OUT_ALLOCED 0x0010
  30. #define NDR_REF_PIPE 0x0020
  31. //
  32. // Pipe Status - global state for individual pipes in the pipe message.
  33. //
  34. typedef enum {
  35. NDR_PIPE_NOT_OPENED,
  36. NDR_PIPE_ACTIVE_IN,
  37. NDR_PIPE_ACTIVE_OUT,
  38. NDR_PIPE_DRAINED
  39. } NDR_PIPE_STATUS;
  40. #define PLONG_LV_CAST *(long * *)&
  41. #define PULONG_LV_CAST *(ulong * *)&
  42. #define WIRE_PAD(size, al) ((((ulong)size)&al) ? ((ulong)(al+1)-(((ulong)size)&al)) : 0)
  43. #define REMAINING_BYTES() ((long)pStubMsg->RpcMsg->BufferLength - \
  44. (long)(pStubMsg->Buffer - (uchar*)pStubMsg->RpcMsg->Buffer))
  45. // These are the states of the state machine processing the chunks
  46. // in the marshaling buffer.
  47. typedef enum {
  48. START,
  49. COPY_PIPE_ELEM,
  50. RETURN_PARTIAL_ELEM,
  51. READ_PARTIAL_ELEM,
  52. VERIFY_TAIL_CHUNK
  53. } RECEIVE_STATES;
  54. typedef struct _FC_PIPE_DEF
  55. {
  56. unsigned char Fc;
  57. unsigned char Align : 4; //
  58. unsigned char Unused : 1; // Flag and alignment byte
  59. unsigned char HasRange : 1; //
  60. unsigned char ObjectPipe : 1; //
  61. unsigned char BigPipe : 1; //
  62. short TypeOffset;
  63. union
  64. {
  65. struct
  66. {
  67. unsigned short MemSize;
  68. unsigned short WireSize;
  69. unsigned long LowChunkLimit;
  70. unsigned long HighChunkLimit;
  71. } s;
  72. struct
  73. {
  74. unsigned long MemSize;
  75. unsigned long WireSize;
  76. unsigned long LowChunkLimit;
  77. unsigned long HighChunkLimit;
  78. } Big;
  79. };
  80. } FC_PIPE_DEF;
  81. //
  82. // The NDR_PIPE_*_RTN are templates for the DCE raw runtime routines.
  83. // This should be moved to rpcndr.h when we decide to expose -Os stubs.
  84. //
  85. typedef void
  86. (__RPC_API * NDR_PIPE_PULL_RTN)(
  87. char * state,
  88. void * buf,
  89. unsigned long esize,
  90. unsigned long * ecount );
  91. typedef void
  92. (__RPC_API * NDR_PIPE_PUSH_RTN)(
  93. char * state,
  94. void * buf,
  95. unsigned long ecount );
  96. typedef void
  97. (__RPC_API * NDR_PIPE_ALLOC_RTN)(
  98. char * state,
  99. unsigned long bsize,
  100. void ** buf,
  101. unsigned long * bcount );
  102. //
  103. // The NDR_HR_PIPE_*_RTN are templates abstracting DCOM pipe routines
  104. // and also async raw pipe routine - note that there is an error code returned.
  105. //
  106. typedef RPC_STATUS
  107. (__RPC_API * NDR_HR_PIPE_PULL_RTN)(
  108. char * state,
  109. void * buf,
  110. unsigned long esize,
  111. unsigned long * ecount );
  112. typedef RPC_STATUS
  113. (__RPC_API * NDR_HR_PIPE_PUSH_RTN)(
  114. char * state,
  115. void * buf,
  116. unsigned long ecount );
  117. typedef RPC_STATUS
  118. (__RPC_API * NDR_HR_PIPE_ALLOC_RTN)(
  119. char * state,
  120. unsigned long bsize,
  121. void ** buf,
  122. unsigned long * bcount );
  123. typedef struct _GENERIC_PIPE_TYPE
  124. {
  125. NDR_HR_PIPE_PULL_RTN pfnPull;
  126. NDR_HR_PIPE_PUSH_RTN pfnPush;
  127. NDR_HR_PIPE_ALLOC_RTN pfnAlloc;
  128. char * pState;
  129. } GENERIC_PIPE_TYPE;
  130. #define NDR_DEFAULT_PIPE_HIGH_CHUNK_LIMIT 0x0ffffff /* less than 2GB */
  131. typedef struct {
  132. int CurrentState;
  133. int TotalElemsCount;
  134. int OrigElemsInChunk;
  135. int ElemsInChunk;
  136. int ElemAlign;
  137. int ElemWireSize;
  138. int ElemMemSize;
  139. int PartialBufferSize;
  140. unsigned char * PartialElem;
  141. int PartialElemSize;
  142. int PartialOffset;
  143. int EndOfPipe : 1;
  144. int EndOfPipePending : 1;
  145. int LowChunkLimit;
  146. int HighChunkLimit;
  147. BOOL fBlockCopy;
  148. int ElemPad;
  149. PFORMAT_STRING TypeFormat;
  150. } NDR_PIPE_STATE;
  151. typedef enum _NDR_DCOM_PIPE_STATE
  152. {
  153. NDR_DCOM_NO_PIPES,
  154. NDR_DCOM_IN_PIPE_PROCESSING,
  155. NDR_DCOM_IN_PIPES_DRAINED,
  156. NDR_DCOM_OUT_PIPE_PROCESSING,
  157. NDR_DCOM_OUT_PIPES_DRAINED,
  158. NDR_DCOM_PIPES_DONE,
  159. NDR_DCOM_PIPE_ERROR
  160. } NDR_DCOM_PIPE_STATE;
  161. typedef struct _NDR_PIPE_MESSAGE
  162. {
  163. unsigned short Signature;
  164. unsigned short PipeId;
  165. unsigned short PipeStatus;
  166. unsigned short PipeFlags;
  167. PFORMAT_STRING pTypeFormat;
  168. PMIDL_STUB_MESSAGE pStubMsg;
  169. GENERIC_PIPE_TYPE * pPipeObject;
  170. } NDR_PIPE_MESSAGE, * PNDR_PIPE_MESSAGE;
  171. //
  172. // Flags helping with the buffer management at the server.
  173. // [in] pipes need to be processed within a separate in buffer.
  174. // This buffer needs to be freed after last [in] pipe.
  175. // [out] pipe processing has to start with a partial RpcGetBuffer.
  176. // Nothing needs to be done with that buffer before return to runtime.
  177. //
  178. typedef struct _PIPEDESC_FLAGS
  179. {
  180. unsigned short AuxOutBufferAllocated : 1;
  181. unsigned short NoBufferCallPending : 1;
  182. unsigned short Reserved : 1;
  183. unsigned short NoMoreBuffersToRead : 1;
  184. } PIPEDESC_FLAGS;
  185. #ifdef __cplusplus
  186. class NDR_PIPE_HELPER
  187. {
  188. public:
  189. // Init functions
  190. virtual PNDR_PIPE_DESC GetPipeDesc() = 0;
  191. // Parameter enum functions
  192. virtual bool InitParamEnum() = 0;
  193. virtual bool GotoNextParam() = 0;
  194. virtual unsigned short GetParamPipeFlags() = 0;
  195. virtual PFORMAT_STRING GetParamTypeFormat() = 0;
  196. virtual char *GetParamArgument() = 0;
  197. // Pipe State
  198. virtual void InitPipeStateWithType( PNDR_PIPE_MESSAGE pPipeMsg) = 0;
  199. // Marshall Unmarshall Functions.
  200. virtual void MarshallType( PNDR_PIPE_MESSAGE pPipeMsg,
  201. uchar *pMemory,
  202. unsigned long Elements ) = 0;
  203. virtual void UnmarshallType( PNDR_PIPE_MESSAGE pPipeMsg,
  204. uchar *pMemory,
  205. unsigned long Elements ) = 0;
  206. virtual void BufferSizeType( PNDR_PIPE_MESSAGE pPipeMsg,
  207. uchar *pMemory,
  208. unsigned long Elements ) = 0;
  209. virtual void ConvertType( PNDR_PIPE_MESSAGE pPipeMsg,
  210. unsigned long Elements ) = 0;
  211. virtual void BufferSizeChunkCounter( PNDR_PIPE_MESSAGE pPipeMsg ) = 0;
  212. virtual bool UnmarshallChunkCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  213. ulong *pOut ) = 0;
  214. virtual void MarshallChunkCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  215. ulong Counter ) = 0;
  216. virtual void BufferSizeChunkTailCounter( PNDR_PIPE_MESSAGE pPipeMsg ) = 0;
  217. virtual void MarshallChunkTailCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  218. ulong Counter ) = 0;
  219. virtual bool VerifyChunkTailCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  220. ulong HeaderCounter ) = 0;
  221. virtual bool HasChunkTailCounter() = 0;
  222. };
  223. typedef NDR_PIPE_HELPER *PNDR_PIPE_HELPER;
  224. #else // #ifdef __cplusplus
  225. typedef void *PNDR_PIPE_HELPER;
  226. #endif
  227. typedef struct _NDR_ALLOCA_CONTEXT *PNDR_ALLOCA_CONTEXT;
  228. typedef struct _NDR_PIPE_DESC
  229. {
  230. NDR_PIPE_MESSAGE * pPipeMsg;
  231. short CurrentPipe;
  232. short PrevPipe;
  233. short InPipes;
  234. short OutPipes;
  235. short TotalPipes;
  236. short PipeVersion;
  237. PIPEDESC_FLAGS Flags;
  238. unsigned long PipeException;
  239. unsigned char * DispatchBuffer;
  240. unsigned long DispatchBufferLength;
  241. unsigned char * LastPartialBuffer;
  242. unsigned long LastPartialSize;
  243. unsigned char Leftover[8];
  244. unsigned long LeftoverSize;
  245. unsigned char * BufferSave;
  246. unsigned long LengthSave;
  247. NDR_PIPE_STATE RuntimeState;
  248. void * ChainingBuffer;
  249. unsigned long ChainingBufferSize;
  250. PNDR_PIPE_HELPER pPipeHelper;
  251. PNDR_ALLOCA_CONTEXT pAllocContext;
  252. } NDR_PIPE_DESC, * PNDR_PIPE_DESC;
  253. //
  254. // Most of these prototypes should be exposed when we have -Os stubs.
  255. //
  256. void RPC_ENTRY
  257. NdrPipeAlloc(
  258. char * pState,
  259. unsigned long bsize,
  260. void ** buf,
  261. unsigned long * bcount );
  262. RPC_STATUS RPC_ENTRY
  263. NdrAsyncPipeAlloc(
  264. char * pState,
  265. unsigned long bsize,
  266. void ** buf,
  267. unsigned long * bcount );
  268. RPCRTAPI
  269. RPC_STATUS RPC_ENTRY
  270. NdrAsyncPipePull(
  271. char * pState,
  272. void * buf,
  273. unsigned long esize,
  274. unsigned long * ecount );
  275. RPCRTAPI
  276. RPC_STATUS RPC_ENTRY
  277. NdrAsyncPipePush(
  278. char * pState,
  279. void * buf,
  280. unsigned long ecount );
  281. void
  282. NdrpPipeElementBufferSize(
  283. NDR_PIPE_DESC * pPipeDesc,
  284. PMIDL_STUB_MESSAGE pStubMsg,
  285. uchar * pMemory,
  286. ulong ElemCount
  287. );
  288. void
  289. NdrpPipeElementConvertAndUnmarshal(
  290. NDR_PIPE_DESC * pPipeDesc,
  291. PMIDL_STUB_MESSAGE pStubMsg,
  292. uchar * * ppMemory,
  293. long ElemMemCount,
  294. long * pActCount
  295. );
  296. BOOL
  297. NdrReadPipeElements(
  298. NDR_PIPE_DESC * pPipeDesc,
  299. PMIDL_STUB_MESSAGE pStubMsg,
  300. unsigned char * pTargetBuffer,
  301. long * pElementsRead
  302. );
  303. void
  304. NdrpReadPipeElementsFromBuffer (
  305. NDR_PIPE_DESC * pPipeDesc,
  306. PMIDL_STUB_MESSAGE pStubMsg,
  307. uchar ** TargetBuffer,
  308. long TargetBufferCount,
  309. long * NumCopied
  310. );
  311. RPC_STATUS
  312. NdrpPushPipeForClient(
  313. PMIDL_STUB_MESSAGE pStubMsg,
  314. NDR_PIPE_DESC * pPipeDesc,
  315. BOOL fPushWholePipe,
  316. long * pActElems );
  317. RPC_STATUS
  318. NdrpPullPipeForClient(
  319. PMIDL_STUB_MESSAGE pStubMsg,
  320. NDR_PIPE_DESC * pPipeDesc,
  321. BOOL fPushWholePipe,
  322. long * pActElems,
  323. BOOL * fEndOfPipe );
  324. void
  325. NdrMarkNextActivePipe(
  326. NDR_PIPE_DESC * pPipeDesc );
  327. RPC_STATUS RPC_ENTRY
  328. NdrSend(
  329. NDR_PIPE_DESC * pPipeDesc,
  330. PMIDL_STUB_MESSAGE pStubMsg,
  331. BOOL fPartial );
  332. void RPC_ENTRY
  333. NdrPartialSend(
  334. NDR_PIPE_DESC * pPipeDesc,
  335. PMIDL_STUB_MESSAGE pStubMsg );
  336. void RPC_ENTRY
  337. NdrCompleteSend(
  338. NDR_PIPE_DESC * pPipeDesc,
  339. PMIDL_STUB_MESSAGE pStubMsg );
  340. void RPC_ENTRY
  341. NdrReceive(
  342. NDR_PIPE_DESC * pPipeDesc,
  343. PMIDL_STUB_MESSAGE pStubMsg,
  344. unsigned long Size,
  345. BOOL fPartial );
  346. void RPC_ENTRY
  347. NdrPartialReceive(
  348. NDR_PIPE_DESC * pPipeDesc,
  349. PMIDL_STUB_MESSAGE pStubMsg,
  350. unsigned long Size );
  351. void RPC_ENTRY
  352. NdrPipeSendReceive(
  353. PMIDL_STUB_MESSAGE pStubMsg,
  354. NDR_PIPE_DESC * pPipeDesc
  355. );
  356. void
  357. RPC_ENTRY
  358. NdrIsAppDoneWithPipes(
  359. PNDR_PIPE_DESC pPipeDesc
  360. );
  361. void RPC_ENTRY
  362. NdrPipesInitialize(
  363. PMIDL_STUB_MESSAGE pStubMsg,
  364. PNDR_PIPE_HELPER pPipeHelper,
  365. PNDR_ALLOCA_CONTEXT pAllocContext
  366. );
  367. void
  368. NdrpPipesInitialize32(
  369. PMIDL_STUB_MESSAGE pStubMsg,
  370. PNDR_ALLOCA_CONTEXT pAllocContext,
  371. PFORMAT_STRING Params,
  372. char * pStackTop,
  373. unsigned long NumberParams
  374. );
  375. void
  376. NdrpPipesInitialize64(
  377. PMIDL_STUB_MESSAGE pStubMsg,
  378. PNDR_ALLOCA_CONTEXT pAllocContext,
  379. PFORMAT_STRING Params,
  380. char * pStackTop,
  381. unsigned long NumberParams
  382. );
  383. RPCRTAPI
  384. void
  385. RPC_ENTRY
  386. NdrPipePull(
  387. char * pState,
  388. void * buf,
  389. unsigned long esize,
  390. unsigned long * ecount );
  391. RPCRTAPI
  392. void
  393. RPC_ENTRY
  394. NdrPipePush(
  395. char * pState,
  396. void * buf,
  397. unsigned long ecount );
  398. RPCRTAPI
  399. unsigned char *
  400. RPC_ENTRY
  401. NdrGetPipeBuffer(
  402. PMIDL_STUB_MESSAGE pStubMsg,
  403. unsigned long BufferLength,
  404. RPC_BINDING_HANDLE Handle );
  405. RPCRTAPI
  406. void
  407. RPC_ENTRY
  408. NdrGetPartialBuffer(
  409. PMIDL_STUB_MESSAGE pStubMsg );
  410. void
  411. NdrpRaisePipeException(
  412. NDR_PIPE_DESC * pPipeDesc,
  413. RPC_STATUS Exception );
  414. #endif // PIPENDR