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.

336 lines
10 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1995 - 2000 Microsoft Corporation
  3. Module Name :
  4. pipes.cxx
  5. Abstract :
  6. This file contains the 64bit specified pipe code.
  7. Author :
  8. Mike Zoran (mzoran) Feb 2000
  9. Revision History :
  10. ---------------------------------------------------------------------*/
  11. #include "precomp.hxx"
  12. #include "..\ndr20\pipendr.h"
  13. class NDR_PIPE_HELPER64 : public NDR_PIPE_HELPER
  14. {
  15. private:
  16. PMIDL_STUB_MESSAGE pStubMsg;
  17. char *pStackTop;
  18. unsigned long NumberParameters;
  19. NDR64_PARAM_FORMAT* pFirstParameter;
  20. NDR64_PARAM_FORMAT* pCurrentParameter;
  21. unsigned long CurrentParamNumber;
  22. NDR_PIPE_DESC PipeDesc;
  23. public:
  24. void *operator new( size_t stAllocateBlock, PNDR_ALLOCA_CONTEXT pAllocContext )
  25. {
  26. return NdrpAlloca( pAllocContext, (UINT)stAllocateBlock );
  27. }
  28. // Do nothing since the memory will be deleted automatically
  29. void operator delete(void *pMemory) {}
  30. NDR_PIPE_HELPER64( PMIDL_STUB_MESSAGE pStubMsg,
  31. PFORMAT_STRING Params,
  32. char * pStackTop,
  33. unsigned long NumberParams )
  34. {
  35. NDR_PIPE_HELPER64::pStubMsg = pStubMsg;
  36. NDR_PIPE_HELPER64::pStackTop = pStackTop;
  37. pFirstParameter = (NDR64_PARAM_FORMAT*)Params;
  38. NumberParameters = NumberParams;
  39. }
  40. virtual PNDR_PIPE_DESC GetPipeDesc()
  41. {
  42. return &PipeDesc;
  43. }
  44. virtual bool InitParamEnum()
  45. {
  46. pCurrentParameter = pFirstParameter;
  47. CurrentParamNumber = 0;
  48. return NumberParameters > 0;
  49. }
  50. virtual bool GotoNextParam()
  51. {
  52. if ( CurrentParamNumber + 1 >= NumberParameters )
  53. {
  54. return false;
  55. }
  56. CurrentParamNumber++;
  57. pCurrentParameter = pFirstParameter + CurrentParamNumber;
  58. return true;
  59. }
  60. virtual unsigned short GetParamPipeFlags()
  61. {
  62. NDR64_PARAM_FLAGS *pParamFlags = (NDR64_PARAM_FLAGS *)&pCurrentParameter->Attributes;
  63. if ( !pParamFlags->IsPipe )
  64. return 0;
  65. unsigned short Flags = 0;
  66. if ( pParamFlags->IsIn )
  67. Flags |= NDR_IN_PIPE;
  68. if ( pParamFlags->IsOut )
  69. Flags |= NDR_OUT_PIPE;
  70. if ( pParamFlags->IsSimpleRef )
  71. Flags |= NDR_REF_PIPE;
  72. return Flags;
  73. }
  74. virtual PFORMAT_STRING GetParamTypeFormat()
  75. {
  76. return (PFORMAT_STRING)pCurrentParameter->Type;
  77. }
  78. virtual char *GetParamArgument()
  79. {
  80. return pStackTop + pCurrentParameter->StackOffset;
  81. }
  82. virtual void InitPipeStateWithType( PNDR_PIPE_MESSAGE pPipeMsg )
  83. {
  84. NDR64_PIPE_FORMAT* pPipeFc = (NDR64_PIPE_FORMAT *) pPipeMsg->pTypeFormat;
  85. NDR_PIPE_STATE *pState = & PipeDesc.RuntimeState;
  86. NDR64_PIPE_FLAGS *pPipeFlags = (NDR64_PIPE_FLAGS*)&pPipeFc->Flags;
  87. NDR64_RANGE_PIPE_FORMAT *pRangePipeFc = (NDR64_RANGE_PIPE_FORMAT*)pPipeFc;
  88. pState->LowChunkLimit = 0;
  89. pState->HighChunkLimit = NDR_DEFAULT_PIPE_HIGH_CHUNK_LIMIT;
  90. pState->ElemAlign = pPipeFc->Alignment;
  91. pState->ElemMemSize = pPipeFc->MemorySize;
  92. pState->ElemWireSize = pPipeFc->BufferSize;
  93. if ( pPipeFlags->HasRange )
  94. {
  95. pState->LowChunkLimit = pRangePipeFc->MinValue;
  96. pState->HighChunkLimit = pRangePipeFc->MaxValue;
  97. }
  98. pState->ElemPad = WIRE_PAD( pState->ElemWireSize, pState->ElemAlign );
  99. pState->fBlockCopy = pPipeFlags->BlockCopy;
  100. }
  101. virtual void MarshallType( PNDR_PIPE_MESSAGE pPipeMsg,
  102. uchar *pMemory,
  103. unsigned long Elements )
  104. {
  105. unsigned long ElemMemSize = PipeDesc.RuntimeState.ElemMemSize;
  106. NDR64_PIPE_FORMAT* pPipeFc = (NDR64_PIPE_FORMAT *) pPipeMsg->pTypeFormat;
  107. while( Elements-- )
  108. {
  109. Ndr64TopLevelTypeMarshall( pPipeMsg->pStubMsg,
  110. pMemory,
  111. pPipeFc->Type );
  112. pMemory += ElemMemSize;
  113. }
  114. }
  115. virtual void UnmarshallType( PNDR_PIPE_MESSAGE pPipeMsg,
  116. uchar *pMemory,
  117. unsigned long Elements )
  118. {
  119. unsigned long ElemMemSize = PipeDesc.RuntimeState.ElemMemSize;
  120. NDR64_PIPE_FORMAT* pPipeFc = (NDR64_PIPE_FORMAT *) pPipeMsg->pTypeFormat;
  121. while( Elements-- )
  122. {
  123. Ndr64TopLevelTypeUnmarshall( pPipeMsg->pStubMsg,
  124. &pMemory,
  125. pPipeFc->Type,
  126. false );
  127. pMemory += ElemMemSize;
  128. }
  129. }
  130. virtual void BufferSizeType( PNDR_PIPE_MESSAGE pPipeMsg,
  131. uchar *pMemory,
  132. unsigned long Elements )
  133. {
  134. unsigned long ElemMemSize = PipeDesc.RuntimeState.ElemMemSize;
  135. NDR64_PIPE_FORMAT* pPipeFc = (NDR64_PIPE_FORMAT *) pPipeMsg->pTypeFormat;
  136. while( Elements-- )
  137. {
  138. Ndr64TopLevelTypeSize( pPipeMsg->pStubMsg,
  139. pMemory,
  140. pPipeFc->Type );
  141. pMemory += ElemMemSize;
  142. }
  143. }
  144. virtual void ConvertType( PNDR_PIPE_MESSAGE /* pPipeMsg */,
  145. unsigned long /* Elements */ )
  146. {
  147. }
  148. virtual void BufferSizeChunkCounter( PNDR_PIPE_MESSAGE pPipeMsg )
  149. {
  150. PMIDL_STUB_MESSAGE pStubMsg = pPipeMsg->pStubMsg;
  151. LENGTH_ALIGN( pStubMsg->BufferLength, sizeof(NDR64_UINT64)-1 );
  152. pStubMsg->BufferLength += sizeof(NDR64_UINT64);
  153. }
  154. virtual bool UnmarshallChunkCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  155. ulong *pOut )
  156. {
  157. PMIDL_STUB_MESSAGE pStubMsg = pPipeMsg->pStubMsg;
  158. ALIGN( pStubMsg->Buffer, sizeof(NDR64_UINT64)-1);
  159. if ( 0 == REMAINING_BYTES() )
  160. {
  161. return false;
  162. }
  163. // transition: end of src
  164. if (REMAINING_BYTES() < sizeof(NDR64_UINT64))
  165. {
  166. // with packet sizes being a multiple of 8,
  167. // this cannot happen.
  168. NDR_ASSERT( 0, "Chunk counter split is not possible.");
  169. NdrpRaisePipeException( &PipeDesc, RPC_S_INTERNAL_ERROR );
  170. return false;
  171. }
  172. NDR64_UINT64 Counter = *(NDR64_UINT64*)pStubMsg->Buffer;
  173. pStubMsg->Buffer += sizeof(NDR64_UINT64);
  174. *pOut = Ndr64pConvertTo2GB( Counter );
  175. return true;
  176. }
  177. virtual void MarshallChunkCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  178. ulong Counter )
  179. {
  180. PMIDL_STUB_MESSAGE pStubMsg = pPipeMsg->pStubMsg;
  181. ALIGN( pStubMsg->Buffer, sizeof(NDR64_UINT64)-1);
  182. Ndr64pConvertTo2GB( Counter );
  183. *(NDR64_UINT64*)pStubMsg->Buffer = (NDR64_UINT64)Counter;
  184. pStubMsg->Buffer += sizeof(NDR64_UINT64);
  185. }
  186. virtual void BufferSizeChunkTailCounter( PNDR_PIPE_MESSAGE pPipeMsg )
  187. {
  188. BufferSizeChunkCounter( pPipeMsg );
  189. }
  190. virtual void MarshallChunkTailCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  191. ulong Counter )
  192. {
  193. PMIDL_STUB_MESSAGE pStubMsg = pPipeMsg->pStubMsg;
  194. ALIGN( pStubMsg->Buffer, sizeof(NDR64_UINT64)-1);
  195. Ndr64pConvertTo2GB( Counter );
  196. NDR64_UINT64 TailCounter = (NDR64_UINT64)-(NDR64_INT64)(NDR64_UINT64)Counter;
  197. *(NDR64_UINT64*)pStubMsg->Buffer = TailCounter;
  198. pStubMsg->Buffer += sizeof(NDR64_UINT64);
  199. }
  200. virtual bool VerifyChunkTailCounter( PNDR_PIPE_MESSAGE pPipeMsg,
  201. ulong HeaderCounter )
  202. {
  203. PMIDL_STUB_MESSAGE pStubMsg = pPipeMsg->pStubMsg;
  204. ALIGN( pStubMsg->Buffer, sizeof(NDR64_UINT64)-1);
  205. if ( 0 == REMAINING_BYTES() )
  206. {
  207. return false;
  208. }
  209. // transition: end of src
  210. if (REMAINING_BYTES() < sizeof(NDR64_UINT64))
  211. {
  212. // with packet sizes being a multiple of 8,
  213. // this cannot happen.
  214. NDR_ASSERT( 0, "Chunk counter split is not possible.");
  215. NdrpRaisePipeException( &PipeDesc, RPC_S_INTERNAL_ERROR );
  216. return false;
  217. }
  218. NDR64_UINT64 TailCounter = *(NDR64_UINT64*)pStubMsg->Buffer;
  219. pStubMsg->Buffer += sizeof(NDR64_UINT64);
  220. Ndr64pConvertTo2GB( HeaderCounter );
  221. NDR64_UINT64 TailCounterChk = (NDR64_UINT64)-(NDR64_INT64)(NDR64_UINT64)HeaderCounter;
  222. if ( TailCounterChk != TailCounter )
  223. {
  224. RpcRaiseException( RPC_X_INVALID_BOUND );
  225. }
  226. return true;
  227. }
  228. virtual bool HasChunkTailCounter() { return TRUE; }
  229. };
  230. void
  231. NdrpPipesInitialize64(
  232. PMIDL_STUB_MESSAGE pStubMsg,
  233. PNDR_ALLOCA_CONTEXT pAllocContext,
  234. PFORMAT_STRING Params,
  235. char * pStackTop,
  236. unsigned long NumberParams
  237. )
  238. {
  239. /* C wrapper to initialize the 32 pipe helper and call NdrPipesInitialize*/
  240. NDR_PIPE_HELPER64 *pPipeHelper =
  241. new( pAllocContext ) NDR_PIPE_HELPER64( pStubMsg,
  242. Params,
  243. pStackTop,
  244. NumberParams );
  245. NdrPipesInitialize( pStubMsg,
  246. pPipeHelper,
  247. pAllocContext );
  248. }