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.

1978 lines
56 KiB

  1. /************************************************************************
  2. Copyright (c) 1993 - 1999 Microsoft Corporation
  3. Module Name :
  4. mrshl.c
  5. Abstract :
  6. This file contains the marshalling routines called by MIDL generated
  7. stubs and the interpreter.
  8. Author :
  9. David Kays dkays September 1993.
  10. Revision History :
  11. ***********************************************************************/
  12. #include "precomp.hxx"
  13. #include "..\..\ndr20\ndrole.h"
  14. void
  15. Ndr64SimpleTypeMarshall(
  16. PMIDL_STUB_MESSAGE pStubMsg,
  17. uchar * pMemory,
  18. uchar FormatChar )
  19. /*++
  20. Routine Description :
  21. Marshalls a simple type.
  22. Arguments :
  23. pStubMsg - Pointer to the stub message.
  24. pMemory - Pointer to the data to be marshalled.
  25. FormatChar - Simple type format character.
  26. Return :
  27. None.
  28. --*/
  29. {
  30. switch ( FormatChar )
  31. {
  32. case FC64_CHAR :
  33. case FC64_UINT8:
  34. case FC64_INT8:
  35. *(pStubMsg->Buffer)++ = *pMemory;
  36. break;
  37. case FC64_WCHAR :
  38. case FC64_UINT16:
  39. case FC64_INT16:
  40. ALIGN(pStubMsg->Buffer,1);
  41. *((NDR64_UINT16 *)pStubMsg->Buffer) = *((NDR64_UINT16 *)pMemory);
  42. pStubMsg->Buffer += sizeof(NDR64_UINT16);
  43. break;
  44. case FC64_UINT32:
  45. case FC64_INT32:
  46. case FC64_ERROR_STATUS_T:
  47. case FC64_FLOAT32:
  48. ALIGN(pStubMsg->Buffer,3);
  49. *((NDR64_UINT32 *)pStubMsg->Buffer) = *((NDR64_UINT32 *)pMemory);
  50. pStubMsg->Buffer += sizeof(NDR64_UINT32);
  51. break;
  52. case FC64_UINT64:
  53. case FC64_INT64:
  54. case FC64_FLOAT64:
  55. ALIGN(pStubMsg->Buffer,7);
  56. *((NDR64_UINT64 *)pStubMsg->Buffer) = *((NDR64_UINT64 *)pMemory);
  57. pStubMsg->Buffer += sizeof(NDR64_UINT64);
  58. break;
  59. case FC64_IGNORE:
  60. break;
  61. default :
  62. NDR_ASSERT(0,"Ndr64SimpleTypeMarshall : bad format char");
  63. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  64. return;
  65. }
  66. }
  67. void
  68. Ndr64UDTSimpleTypeMarshall1(
  69. PMIDL_STUB_MESSAGE pStubMsg,
  70. uchar * pMemory,
  71. PNDR64_FORMAT FormatString )
  72. {
  73. Ndr64SimpleTypeMarshall(pStubMsg,pMemory,*(PFORMAT_STRING)FormatString);
  74. }
  75. void
  76. Ndr64pRangeMarshall(
  77. PMIDL_STUB_MESSAGE pStubMsg,
  78. uchar * pMemory,
  79. PNDR64_FORMAT pFormat )
  80. /*++
  81. --*/
  82. {
  83. const NDR64_RANGE_FORMAT * pRangeFormat =
  84. (const NDR64_RANGE_FORMAT*)pFormat;
  85. Ndr64SimpleTypeMarshall( pStubMsg, pMemory, pRangeFormat->RangeType );
  86. }
  87. void
  88. Ndr64pInterfacePointerMarshall (
  89. PMIDL_STUB_MESSAGE pStubMsg,
  90. uchar * pMemory,
  91. PNDR64_FORMAT pFormat )
  92. /*++
  93. Routine Description :
  94. Marshalls an interface pointer.
  95. Arguments :
  96. pStubMsg - Pointer to the stub message.
  97. pMemory - Pointer to the interface pointer being marshalled.
  98. pFormat - Interface pointer's format string description.
  99. Return :
  100. None.
  101. Notes : There is now one representation of a marshalled interface pointer.
  102. // wire representation of a marshalled interface pointer
  103. typedef struct tagMInterfacePointer
  104. {
  105. ULONG ulCntData; // size of data
  106. [size_is(ulCntData)] BYTE abData[]; // data (OBJREF)
  107. } MInterfacePointer;
  108. --*/
  109. {
  110. const NDR64_CONSTANT_IID_FORMAT *pConstInterfaceFormat =
  111. (NDR64_CONSTANT_IID_FORMAT*)pFormat;
  112. const NDR64_IID_FORMAT *pInterfaceFormat =
  113. (NDR64_IID_FORMAT*)pFormat;
  114. //
  115. // Get an IID pointer.
  116. //
  117. IID *piid;
  118. if ( ((NDR64_IID_FLAGS*)&pInterfaceFormat->Flags)->ConstantIID )
  119. {
  120. piid = (IID*)&pConstInterfaceFormat->Guid;
  121. }
  122. else
  123. {
  124. piid = (IID *) Ndr64EvaluateExpr( pStubMsg,
  125. pInterfaceFormat->IIDDescriptor,
  126. EXPR_IID );
  127. if(piid == 0)
  128. {
  129. RpcRaiseException( RPC_S_INVALID_ARG );
  130. return;
  131. }
  132. }
  133. // Leave space in the buffer for the conformant size.
  134. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  135. NDR64_WIRE_COUNT_TYPE * pMaxCount = (NDR64_WIRE_COUNT_TYPE *) pStubMsg->Buffer;
  136. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  137. ulong *pulCntData = (ulong *) pStubMsg->Buffer;
  138. pStubMsg->Buffer += sizeof(ulong);
  139. //Calculate the maximum size of the stream.
  140. ulong position = (ulong)( pStubMsg->Buffer - (uchar *)pStubMsg->RpcMsg->Buffer);
  141. ulong cbMax = pStubMsg->RpcMsg->BufferLength - position;
  142. //Create a stream on memory.
  143. #if defined(DEBUG_WALKIP)
  144. {
  145. CHAR AppName[MAX_PATH];
  146. memset(AppName, 0, sizeof(AppName ) );
  147. GetModuleFileNameA( NULL, AppName, sizeof(AppName ) );
  148. DbgPrint("MRSHL64 %s %p\n", AppName, pStubMsg->Buffer );
  149. }
  150. #endif
  151. IStream *pStream = NdrpCreateStreamOnMemory(pStubMsg->Buffer, cbMax);
  152. if(pStream == 0)
  153. {
  154. RpcRaiseException(RPC_S_OUT_OF_MEMORY);
  155. return;
  156. }
  157. RpcTryFinally
  158. {
  159. HRESULT hr = (*pfnCoMarshalInterface)(pStream, *piid, (IUnknown *)pMemory,
  160. pStubMsg->dwDestContext, pStubMsg->pvDestContext, 0);
  161. if(FAILED(hr))
  162. {
  163. RpcRaiseException(hr);
  164. return;
  165. }
  166. ULARGE_INTEGER libPosition;
  167. LARGE_INTEGER libMove;
  168. libMove.QuadPart = 0;
  169. pStream->Seek(libMove, STREAM_SEEK_CUR, &libPosition);
  170. //Update the array bounds.
  171. *pMaxCount = libPosition.QuadPart;
  172. //Advance the stub message buffer pointer.
  173. pStubMsg->Buffer += (*pulCntData = Ndr64pConvertTo2GB(libPosition.QuadPart));
  174. }
  175. RpcFinally
  176. {
  177. pStream->Release();
  178. }
  179. RpcEndFinally
  180. }
  181. __forceinline void
  182. Ndr64pPointerMarshallInternal(
  183. PMIDL_STUB_MESSAGE pStubMsg,
  184. NDR64_PTR_WIRE_TYPE *pBufferMark,
  185. uchar * pMemory,
  186. PNDR64_FORMAT pFormat )
  187. /*++
  188. Routine Description :
  189. Private routine for marshalling a pointer and its pointee. This is the
  190. entry point for pointers embedded in structures, arrays, and unions.
  191. Used for FC64_RP, FC64_UP, FC64_FP, FC64_OP.
  192. Arguments :
  193. pStubMsg - Pointer to the stub message.
  194. pBufferMark - Pointer to the pointer in the wire buffer.
  195. pMemory - Pointer to the data to be marshalled.
  196. pFormat - Pointer format string description.
  197. pStubMsg->Buffer - the place for the pointee.
  198. Return :
  199. None.
  200. --*/
  201. {
  202. const NDR64_POINTER_FORMAT *pPointerFormat = (NDR64_POINTER_FORMAT*) pFormat;
  203. //
  204. // Check the pointer type.
  205. //
  206. switch ( pPointerFormat->FormatCode )
  207. {
  208. case FC64_RP :
  209. if ( pBufferMark )
  210. {
  211. // Put the pointer in the buffer.
  212. *((NDR64_PTR_WIRE_TYPE*)pBufferMark) = PTR_WIRE_REP(pMemory);
  213. }
  214. if ( !pMemory )
  215. {
  216. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  217. }
  218. break;
  219. case FC64_UP :
  220. case FC64_OP :
  221. // Put the pointer in the buffer.
  222. *((NDR64_PTR_WIRE_TYPE*)pBufferMark) = PTR_WIRE_REP(pMemory);
  223. if ( ! pMemory )
  224. {
  225. return;
  226. }
  227. break;
  228. case FC64_IP :
  229. // Put the pointer in the buffer
  230. *((NDR64_PTR_WIRE_TYPE*)pBufferMark) = PTR_WIRE_REP(pMemory);
  231. if ( ! pMemory )
  232. {
  233. return;
  234. }
  235. Ndr64pInterfacePointerMarshall (pStubMsg,
  236. pMemory,
  237. pPointerFormat->Pointee
  238. );
  239. return;
  240. case FC64_FP :
  241. //
  242. // Marshall the pointer's ref id and see if we've already
  243. // marshalled the pointer's data.
  244. //
  245. {
  246. ulong RefId;
  247. BOOL Result =
  248. Ndr64pFullPointerQueryPointer( pStubMsg,
  249. pMemory,
  250. FULL_POINTER_MARSHALLED,
  251. &RefId );
  252. *(NDR64_PTR_WIRE_TYPE*)pBufferMark = Ndr64pRefIdToWirePtr( RefId );
  253. if ( Result )
  254. return;
  255. }
  256. break;
  257. default :
  258. NDR_ASSERT(0,"Ndr64pPointerMarshall : bad pointer type");
  259. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  260. return;
  261. }
  262. if ( NDR64_SIMPLE_POINTER( pPointerFormat->Flags ) )
  263. {
  264. Ndr64SimpleTypeMarshall( pStubMsg,
  265. pMemory,
  266. *(PFORMAT_STRING)pPointerFormat->Pointee );
  267. return;
  268. }
  269. if ( NDR64_POINTER_DEREF( pPointerFormat->Flags ) )
  270. pMemory = *((uchar **)pMemory);
  271. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  272. NDR64_RESET_EMBEDDED_FLAGS_TO_STANDALONE(pStubMsg->uFlags);
  273. Ndr64TopLevelTypeMarshall(
  274. pStubMsg,
  275. pMemory,
  276. pPointerFormat->Pointee );
  277. }
  278. NDR64_MRSHL_POINTER_QUEUE_ELEMENT::NDR64_MRSHL_POINTER_QUEUE_ELEMENT(
  279. MIDL_STUB_MESSAGE *pStubMsg,
  280. NDR64_PTR_WIRE_TYPE * pBufferMarkNew,
  281. uchar * const pMemoryNew,
  282. const PFORMAT_STRING pFormatNew) :
  283. pBufferMark(pBufferMarkNew),
  284. pMemory(pMemoryNew),
  285. pFormat(pFormatNew),
  286. uFlags(pStubMsg->uFlags),
  287. pCorrMemory(pStubMsg->pCorrMemory)
  288. {
  289. }
  290. void
  291. NDR64_MRSHL_POINTER_QUEUE_ELEMENT::Dispatch(
  292. MIDL_STUB_MESSAGE *pStubMsg)
  293. {
  294. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags, uFlags );
  295. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pCorrMemory );
  296. Ndr64pPointerMarshallInternal( pStubMsg,
  297. pBufferMark,
  298. pMemory,
  299. (PNDR64_FORMAT)pFormat );
  300. }
  301. #if defined(DBG)
  302. void
  303. NDR64_MRSHL_POINTER_QUEUE_ELEMENT::Print()
  304. {
  305. DbgPrint("NDR_MRSHL_POINTER_QUEUE_ELEMENT\n");
  306. DbgPrint("pNext: %p\n", pNext );
  307. DbgPrint("pBufferMark: %p\n", pBufferMark );
  308. DbgPrint("pMemory: %p\n", pMemory );
  309. DbgPrint("pFormat: %p\n", pFormat );
  310. DbgPrint("pCorrMemory: %p\n", pCorrMemory );
  311. DbgPrint("uFlags: %x\n", uFlags );
  312. }
  313. #endif
  314. void
  315. Ndr64pEnquePointerMarshall(
  316. PMIDL_STUB_MESSAGE pStubMsg,
  317. NDR64_PTR_WIRE_TYPE *pBufferMark,
  318. uchar * pMemory,
  319. PNDR64_FORMAT pFormat )
  320. {
  321. NDR64_POINTER_CONTEXT PointerContext( pStubMsg );
  322. RpcTryFinally
  323. {
  324. NDR64_MRSHL_POINTER_QUEUE_ELEMENT*pElement =
  325. new(PointerContext.GetActiveState())
  326. NDR64_MRSHL_POINTER_QUEUE_ELEMENT(pStubMsg,
  327. pBufferMark,
  328. pMemory,
  329. (PFORMAT_STRING)pFormat);
  330. PointerContext.Enque( pElement );
  331. PointerContext.DispatchIfRequired();
  332. }
  333. RpcFinally
  334. {
  335. PointerContext.EndContext();
  336. }
  337. RpcEndFinally
  338. }
  339. void
  340. Ndr64pPointerMarshall(
  341. PMIDL_STUB_MESSAGE pStubMsg,
  342. NDR64_PTR_WIRE_TYPE *pBufferMark,
  343. uchar * pMemory,
  344. PNDR64_FORMAT pFormat )
  345. {
  346. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags);
  347. if ( !NdrIsLowStack(pStubMsg) )
  348. {
  349. Ndr64pPointerMarshallInternal( pStubMsg,
  350. pBufferMark,
  351. pMemory,
  352. pFormat );
  353. return;
  354. }
  355. Ndr64pEnquePointerMarshall(
  356. pStubMsg,
  357. pBufferMark,
  358. pMemory,
  359. pFormat );
  360. }
  361. __forceinline void
  362. Ndr64TopLevelPointerMarshall(
  363. PMIDL_STUB_MESSAGE pStubMsg,
  364. uchar * pMemory,
  365. PNDR64_FORMAT pFormat )
  366. {
  367. NDR64_PTR_WIRE_TYPE *pBufferMark = NULL;
  368. // Non embedded ref pointers do not have a wire representation
  369. if ( *(PFORMAT_STRING)pFormat != FC64_RP )
  370. {
  371. ALIGN( pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN );
  372. pBufferMark = (NDR64_PTR_WIRE_TYPE*)pStubMsg->Buffer;
  373. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  374. }
  375. Ndr64pPointerMarshall( pStubMsg,
  376. pBufferMark,
  377. pMemory,
  378. pFormat );
  379. }
  380. __forceinline void
  381. Ndr64EmbeddedPointerMarshall(
  382. PMIDL_STUB_MESSAGE pStubMsg,
  383. uchar * pMemory,
  384. PNDR64_FORMAT pFormat )
  385. {
  386. ALIGN( pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN );
  387. NDR64_PTR_WIRE_TYPE* pBufferMark = (NDR64_PTR_WIRE_TYPE*)pStubMsg->Buffer;
  388. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  389. POINTER_BUFFER_SWAP_CONTEXT SwapContext(pStubMsg);
  390. Ndr64pPointerMarshall( pStubMsg,
  391. pBufferMark,
  392. *(uchar**)pMemory,
  393. pFormat );
  394. }
  395. void
  396. Ndr64SimpleStructMarshall(
  397. PMIDL_STUB_MESSAGE pStubMsg,
  398. uchar * pMemory,
  399. PNDR64_FORMAT pFormat )
  400. /*++
  401. Routine description :
  402. Marshalls a simple structure.
  403. Used for FC64_STRUCT and FC64_PSTRUCT.
  404. Arguments :
  405. pStubMsg - Pointer to the stub message.
  406. pMemory - Pointer to the structure to be marshalled.
  407. pFormat - Structure's format string description.
  408. Return :
  409. None.
  410. --*/
  411. {
  412. const NDR64_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  413. (NDR64_STRUCTURE_HEADER_FORMAT*) pFormat;
  414. const NDR64_UINT32 StructSize = pStructFormat->MemorySize;
  415. ALIGN(pStubMsg->Buffer, pStructFormat->Alignment);
  416. uchar *pBufferSave = pStubMsg->Buffer;
  417. RpcpMemoryCopy( pBufferSave,
  418. pMemory,
  419. pStructFormat->MemorySize );
  420. pStubMsg->Buffer += pStructFormat->MemorySize;
  421. // Marshall embedded pointers.
  422. if ( pStructFormat->Flags.HasPointerInfo )
  423. {
  424. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory);
  425. Ndr64pPointerLayoutMarshall( pStubMsg,
  426. pStructFormat + 1,
  427. 0,
  428. pMemory,
  429. pBufferSave );
  430. }
  431. }
  432. void
  433. Ndr64ConformantStructMarshall(
  434. PMIDL_STUB_MESSAGE pStubMsg,
  435. uchar * pMemory,
  436. PNDR64_FORMAT pFormat )
  437. /*++
  438. Routine description :
  439. Marshalls a conformant structure.
  440. Arguments :
  441. pStubMsg - Pointer to the stub message.
  442. pMemory - Pointer to the structure to be marshalled.
  443. pFormat - Structure's format string description.
  444. Return :
  445. None.
  446. Note
  447. --*/
  448. {
  449. const NDR64_CONF_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  450. (NDR64_CONF_STRUCTURE_HEADER_FORMAT*) pFormat;
  451. const NDR64_CONF_ARRAY_HEADER_FORMAT * const pArrayFormat =
  452. (NDR64_CONF_ARRAY_HEADER_FORMAT *) pStructFormat->ArrayDescription;
  453. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  454. NDR64_WIRE_COUNT_TYPE MaxCount =
  455. Ndr64EvaluateExpr( pStubMsg,
  456. pArrayFormat->ConfDescriptor,
  457. EXPR_MAXCOUNT );
  458. if ( NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  459. *(NDR64_WIRE_COUNT_TYPE *)pStubMsg->ConformanceMark = MaxCount;
  460. else
  461. {
  462. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  463. *((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer) = MaxCount;
  464. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  465. }
  466. ALIGN(pStubMsg->Buffer, pStructFormat->Alignment);
  467. uchar *pBufferStart = pStubMsg->Buffer;
  468. NDR64_UINT32 StructSize = Ndr64pConvertTo2GB( (NDR64_UINT64)pStructFormat->MemorySize +
  469. ( MaxCount * (NDR64_UINT64)pArrayFormat->ElementSize ) );
  470. RpcpMemoryCopy( pBufferStart,
  471. pMemory,
  472. StructSize );
  473. pStubMsg->Buffer += StructSize;
  474. if ( pStructFormat->Flags.HasPointerInfo )
  475. {
  476. Ndr64pPointerLayoutMarshall( pStubMsg,
  477. pStructFormat + 1,
  478. (NDR64_UINT32)MaxCount,
  479. pMemory,
  480. pBufferStart );
  481. }
  482. }
  483. void
  484. Ndr64ComplexStructMarshall(
  485. PMIDL_STUB_MESSAGE pStubMsg,
  486. uchar * pMemory,
  487. PNDR64_FORMAT pFormat )
  488. /*++
  489. Routine description :
  490. Marshalls a complex structure.
  491. Used for FC64_BOGUS_STRUCT.
  492. Arguments :
  493. pStubMsg - Pointer to the stub message.
  494. pMemory - Pointer to the structure being marshalled.
  495. pFormat - Structure's format string description.
  496. Return :
  497. None.
  498. Notes :
  499. --*/
  500. {
  501. const NDR64_BOGUS_STRUCTURE_HEADER_FORMAT * pStructFormat =
  502. (NDR64_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  503. const NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT * pConfStructFormat =
  504. (NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  505. uchar * pBufferSave = pStubMsg->Buffer;
  506. bool fSetPointerBufferMark = ! pStubMsg->PointerBufferMark;
  507. // Compute where the pointees should be unmarshalled to.
  508. if ( fSetPointerBufferMark )
  509. {
  510. BOOL fOldIgnore = pStubMsg->IgnoreEmbeddedPointers;
  511. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  512. //
  513. // Set BufferLength equal to the current buffer pointer, and then
  514. // when we return from NdrComplexStructBufferSize it will pointer to
  515. // the location in the buffer where the pointees should be marshalled.
  516. // pStubMsg->BufferLength = pBufferSave;
  517. // Instead of pointer, we now calculate pointer increment explicitly.
  518. // Set the pointer alignment as a base.
  519. // We use pBufferSave as the sizing routine accounts for the conf sizes.
  520. //
  521. ulong BufferLenOffset = 0xf & PtrToUlong( pBufferSave );
  522. ulong BufferLengthSave = pStubMsg->BufferLength;
  523. pStubMsg->BufferLength = BufferLenOffset;
  524. Ndr64ComplexStructBufferSize(
  525. pStubMsg,
  526. pMemory,
  527. pFormat );
  528. // Pointer increment including alignments.
  529. BufferLenOffset = pStubMsg->BufferLength - BufferLenOffset;
  530. // Set the location in the buffer where pointees will be marshalled.
  531. pStubMsg->PointerBufferMark = pStubMsg->Buffer + BufferLenOffset;
  532. pStubMsg->BufferLength = BufferLengthSave;
  533. pStubMsg->IgnoreEmbeddedPointers = fOldIgnore;
  534. }
  535. PFORMAT_STRING pFormatPointers = (PFORMAT_STRING)pStructFormat->PointerLayout;
  536. PFORMAT_STRING pFormatArray = NULL;
  537. BOOL fIsFullBogus = ( *(PFORMAT_STRING)pFormat == FC64_BOGUS_STRUCT ||
  538. *(PFORMAT_STRING)pFormat == FC64_CONF_BOGUS_STRUCT );
  539. PFORMAT_STRING pMemberLayout = ( *(PFORMAT_STRING)pFormat == FC64_CONF_BOGUS_STRUCT ||
  540. *(PFORMAT_STRING)pFormat == FC64_FORCED_CONF_BOGUS_STRUCT ) ?
  541. (PFORMAT_STRING)( pConfStructFormat + 1) :
  542. (PFORMAT_STRING)( pStructFormat + 1);
  543. SAVE_CONTEXT<uchar*> ConformanceMarkSave(pStubMsg->ConformanceMark);
  544. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  545. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  546. // Get conformant array description.
  547. if ( pStructFormat->Flags.HasConfArray )
  548. {
  549. pFormatArray = (PFORMAT_STRING)pConfStructFormat->ConfArrayDescription;
  550. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  551. {
  552. // Align for conformance marshalling.
  553. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  554. // Remember where the conformance count(s) will be marshalled.
  555. pStubMsg->ConformanceMark = pStubMsg->Buffer;
  556. // Increment the buffer pointer for every array dimension.
  557. pStubMsg->Buffer += pConfStructFormat->Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE);
  558. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  559. }
  560. }
  561. else
  562. pFormatArray = 0;
  563. // Align buffer on struct's alignment.
  564. ALIGN(pStubMsg->Buffer, pStructFormat->Alignment);
  565. //
  566. // Marshall the structure member by member.
  567. //
  568. for ( ; ; )
  569. {
  570. switch ( *pMemberLayout )
  571. {
  572. case FC64_STRUCT:
  573. {
  574. const NDR64_SIMPLE_REGION_FORMAT *pRegion =
  575. (NDR64_SIMPLE_REGION_FORMAT*) pMemberLayout;
  576. ALIGN( pStubMsg->Buffer, pRegion->Alignment );
  577. RpcpMemoryCopy( pStubMsg->Buffer,
  578. pMemory,
  579. pRegion->RegionSize );
  580. pStubMsg->Buffer += pRegion->RegionSize;
  581. pMemory += pRegion->RegionSize;
  582. pMemberLayout += sizeof( *pRegion );
  583. break;
  584. }
  585. case FC64_STRUCTPADN :
  586. {
  587. const NDR64_MEMPAD_FORMAT *pMemPad = (NDR64_MEMPAD_FORMAT*)pMemberLayout;
  588. pMemory += pMemPad->MemPad;
  589. pMemberLayout += sizeof(*pMemPad);
  590. break;
  591. }
  592. case FC64_POINTER :
  593. {
  594. NDR_ASSERT(pFormatPointers, "Ndr64ComplexStructMarshall: pointer field but no pointer layout");
  595. Ndr64EmbeddedPointerMarshall(
  596. pStubMsg,
  597. pMemory,
  598. pFormatPointers );
  599. pMemory += PTR_MEM_SIZE;
  600. pFormatPointers += sizeof(NDR64_POINTER_FORMAT);
  601. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  602. break;
  603. }
  604. case FC64_EMBEDDED_COMPLEX :
  605. {
  606. const NDR64_EMBEDDED_COMPLEX_FORMAT * pEmbeddedFormat =
  607. (NDR64_EMBEDDED_COMPLEX_FORMAT*) pMemberLayout;
  608. Ndr64EmbeddedTypeMarshall( pStubMsg,
  609. pMemory,
  610. pEmbeddedFormat->Type );
  611. pMemory = Ndr64pMemoryIncrement( pStubMsg,
  612. pMemory,
  613. pEmbeddedFormat->Type,
  614. FALSE );
  615. pMemberLayout += sizeof(*pEmbeddedFormat);
  616. break;
  617. }
  618. case FC64_BUFFER_ALIGN:
  619. {
  620. const NDR64_BUFFER_ALIGN_FORMAT *pBufAlign =
  621. (NDR64_BUFFER_ALIGN_FORMAT*) pMemberLayout;
  622. ALIGN(pStubMsg->Buffer, pBufAlign->Alignment);
  623. pMemberLayout += sizeof( *pBufAlign );
  624. break;
  625. }
  626. case FC64_CHAR :
  627. case FC64_WCHAR :
  628. case FC64_INT8:
  629. case FC64_UINT8:
  630. case FC64_INT16:
  631. case FC64_UINT16:
  632. case FC64_INT32:
  633. case FC64_UINT32:
  634. case FC64_INT64:
  635. case FC64_UINT64:
  636. case FC64_FLOAT32 :
  637. case FC64_FLOAT64 :
  638. case FC64_ERROR_STATUS_T:
  639. Ndr64SimpleTypeMarshall( pStubMsg,
  640. pMemory,
  641. *pMemberLayout );
  642. pMemory += NDR64_SIMPLE_TYPE_MEMSIZE(*pMemberLayout);
  643. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  644. break;
  645. case FC64_IGNORE :
  646. ALIGN(pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN );
  647. pMemory += PTR_MEM_SIZE;
  648. *(NDR64_PTR_WIRE_TYPE*)pStubMsg->Buffer = 0;
  649. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  650. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  651. break;
  652. case FC64_END :
  653. goto ComplexMarshallEnd;
  654. default :
  655. NDR_ASSERT(0,"Ndr64ComplexStructMarshall : bad format char");
  656. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  657. return;
  658. } // switch
  659. } // for
  660. ComplexMarshallEnd:
  661. //
  662. // Marshall conformant array if we have one.
  663. if ( pFormatArray )
  664. {
  665. Ndr64EmbeddedTypeMarshall( pStubMsg,
  666. pMemory,
  667. pFormatArray );
  668. }
  669. else
  670. {
  671. // If the structure doesn't have a conformant array, align it again
  672. ALIGN( pStubMsg->Buffer, pStructFormat->Alignment );
  673. }
  674. if ( fSetPointerBufferMark )
  675. {
  676. pStubMsg->Buffer = pStubMsg->PointerBufferMark;
  677. pStubMsg->PointerBufferMark = 0;
  678. }
  679. }
  680. void
  681. Ndr64NonConformantStringMarshall(
  682. PMIDL_STUB_MESSAGE pStubMsg,
  683. uchar * pMemory,
  684. PNDR64_FORMAT pFormat )
  685. /*++
  686. Routine description :
  687. Marshalls a non conformant string.
  688. Arguments :
  689. pStubMsg - Pointer to the stub message.
  690. pMemory - Pointer to the string to be marshalled.
  691. pFormat - String's format string description.
  692. Return :
  693. None.
  694. --*/
  695. {
  696. const NDR64_NON_CONFORMANT_STRING_FORMAT * pStringFormat =
  697. (NDR64_NON_CONFORMANT_STRING_FORMAT*) pFormat;
  698. NDR64_UINT32 CopySize =
  699. Ndr64pCommonStringSize( pStubMsg,
  700. pMemory,
  701. &pStringFormat->Header );
  702. if ( CopySize > pStringFormat->TotalSize )
  703. RpcRaiseException(RPC_X_INVALID_BOUND);
  704. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  705. ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[0] = pStubMsg->Offset;
  706. ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[1] = pStubMsg->ActualCount;
  707. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  708. // Copy the string.
  709. RpcpMemoryCopy( pStubMsg->Buffer,
  710. pMemory,
  711. CopySize );
  712. pStubMsg->Buffer += CopySize;
  713. }
  714. void
  715. Ndr64ConformantStringMarshall(
  716. PMIDL_STUB_MESSAGE pStubMsg,
  717. uchar * pMemory,
  718. PNDR64_FORMAT pFormat )
  719. /*++
  720. Routine description :
  721. Marshalls a conformant string.
  722. Arguments :
  723. pStubMsg - Pointer to the stub message.
  724. pMemory - Pointer to the string to be marshalled.
  725. pFormat - String's format string description.
  726. Return :
  727. None.
  728. --*/
  729. {
  730. const NDR64_CONFORMANT_STRING_FORMAT * pStringFormat =
  731. (const NDR64_CONFORMANT_STRING_FORMAT*) pFormat;
  732. const NDR64_SIZED_CONFORMANT_STRING_FORMAT * pSizedStringFormat =
  733. (const NDR64_SIZED_CONFORMANT_STRING_FORMAT*) pFormat;
  734. NDR64_WIRE_COUNT_TYPE *pMaxCountMark;
  735. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  736. {
  737. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  738. pMaxCountMark = (NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer;
  739. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  740. }
  741. else
  742. {
  743. pMaxCountMark = (NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  744. }
  745. NDR64_UINT32 CopySize =
  746. Ndr64pCommonStringSize( pStubMsg,
  747. pMemory,
  748. &pStringFormat->Header );
  749. //
  750. // If the string is sized then compute the max count, otherwise the
  751. // max count is equal to the actual count.
  752. //
  753. NDR64_WIRE_COUNT_TYPE MaxCount = pStubMsg->ActualCount;
  754. if ( pStringFormat->Header.Flags.IsSized )
  755. {
  756. MaxCount =
  757. Ndr64EvaluateExpr( pStubMsg,
  758. pSizedStringFormat->SizeDescription,
  759. EXPR_MAXCOUNT );
  760. if ( pStubMsg->ActualCount > MaxCount )
  761. RpcRaiseException(RPC_X_INVALID_BOUND);
  762. }
  763. // Marshall the max count.
  764. *pMaxCountMark = MaxCount;
  765. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  766. ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[0] = pStubMsg->Offset;
  767. ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[1] = pStubMsg->ActualCount;
  768. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  769. RpcpMemoryCopy( pStubMsg->Buffer,
  770. pMemory,
  771. CopySize );
  772. // Update the Buffer pointer.
  773. pStubMsg->Buffer += CopySize;
  774. }
  775. void
  776. Ndr64FixedArrayMarshall(
  777. PMIDL_STUB_MESSAGE pStubMsg,
  778. uchar * pMemory,
  779. PNDR64_FORMAT pFormat )
  780. /*++
  781. Routine Description :
  782. Marshalls a fixed array of any number of dimensions.
  783. Arguments :
  784. pStubMsg - Pointer to the stub message.
  785. pMemory - Pointer to the array to be marshalled.
  786. pFormat - Array's format string description.
  787. Return :
  788. None.
  789. --*/
  790. {
  791. const NDR64_FIX_ARRAY_HEADER_FORMAT * pArrayFormat =
  792. (NDR64_FIX_ARRAY_HEADER_FORMAT*) pFormat;
  793. // Align the buffer.
  794. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  795. uchar *pBufferStart = pStubMsg->Buffer;
  796. // Copy the array.
  797. RpcpMemoryCopy( pBufferStart,
  798. pMemory,
  799. pArrayFormat->TotalSize );
  800. // Increment stub message buffer pointer.
  801. pStubMsg->Buffer += pArrayFormat->TotalSize;
  802. // Marshall embedded pointers.
  803. if ( pArrayFormat->Flags.HasPointerInfo )
  804. {
  805. Ndr64pPointerLayoutMarshall( pStubMsg,
  806. pArrayFormat + 1,
  807. 0,
  808. pMemory,
  809. pBufferStart );
  810. }
  811. }
  812. void
  813. Ndr64ConformantArrayMarshall(
  814. PMIDL_STUB_MESSAGE pStubMsg,
  815. uchar * pMemory,
  816. PNDR64_FORMAT pFormat )
  817. /*++
  818. Routine Description :
  819. Marshalls a top level one dimensional conformant array.
  820. Arguments :
  821. pStubMsg - Pointer to the stub message.
  822. pMemory - Pointer to the array being marshalled.
  823. pFormat - Array's format string description.
  824. Return :
  825. None.
  826. --*/
  827. {
  828. const NDR64_CONF_ARRAY_HEADER_FORMAT *pArrayFormat =
  829. (NDR64_CONF_ARRAY_HEADER_FORMAT*) pFormat;
  830. uchar *pConformanceMark;
  831. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  832. {
  833. // Align the buffer for conformance marshalling.
  834. ALIGN(pStubMsg->Buffer,NDR64_WIRE_COUNT_ALIGN);
  835. pConformanceMark = pStubMsg->Buffer;
  836. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  837. }
  838. else
  839. {
  840. pConformanceMark = pStubMsg->ConformanceMark;
  841. }
  842. NDR64_WIRE_COUNT_TYPE MaxCount =
  843. Ndr64EvaluateExpr( pStubMsg,
  844. pArrayFormat->ConfDescriptor,
  845. EXPR_MAXCOUNT );
  846. *(NDR64_WIRE_COUNT_TYPE*)pConformanceMark = MaxCount;
  847. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  848. // Compute the total array size in bytes.
  849. NDR64_UINT32 CopySize =
  850. Ndr64pConvertTo2GB(MaxCount * (NDR64_UINT64)pArrayFormat->ElementSize);
  851. RpcpMemoryCopy( pStubMsg->Buffer,
  852. pMemory,
  853. CopySize );
  854. // Update buffer pointer.
  855. uchar *pBufferStart = pStubMsg->Buffer;
  856. pStubMsg->Buffer += CopySize;
  857. // Marshall embedded pointers.
  858. if ( pArrayFormat->Flags.HasPointerInfo )
  859. {
  860. Ndr64pPointerLayoutMarshall( pStubMsg,
  861. pArrayFormat + 1,
  862. (NDR64_UINT32)MaxCount,
  863. pMemory,
  864. pBufferStart );
  865. }
  866. }
  867. void
  868. Ndr64ConformantVaryingArrayMarshall(
  869. PMIDL_STUB_MESSAGE pStubMsg,
  870. uchar * pMemory,
  871. PNDR64_FORMAT pFormat )
  872. /*++
  873. Routine Description :
  874. Marshalls a top level one dimensional conformant varying array.
  875. Used for FC64_CVARRAY.
  876. Arguments :
  877. pStubMsg - Pointer to the stub message.
  878. pMemory - Pointer to the array being marshalled.
  879. pFormat - Array's format string description.
  880. Return :
  881. None.
  882. --*/
  883. {
  884. const NDR64_CONF_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  885. (NDR64_CONF_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  886. uchar *pConformanceMark;
  887. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  888. {
  889. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  890. pConformanceMark = pStubMsg->Buffer;
  891. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  892. }
  893. else
  894. {
  895. pConformanceMark = pStubMsg->ConformanceMark;
  896. }
  897. NDR64_WIRE_COUNT_TYPE MaxCount =
  898. Ndr64EvaluateExpr( pStubMsg,
  899. pArrayFormat->ConfDescriptor,
  900. EXPR_MAXCOUNT );
  901. NDR64_WIRE_COUNT_TYPE ActualCount =
  902. Ndr64EvaluateExpr( pStubMsg,
  903. pArrayFormat->VarDescriptor,
  904. EXPR_ACTUALCOUNT );
  905. if ( ActualCount > MaxCount )
  906. RpcRaiseException( RPC_X_INVALID_BOUND );
  907. *(NDR64_WIRE_COUNT_TYPE*)pConformanceMark = MaxCount;
  908. // Align the buffer for variance marshalling.
  909. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  910. // Marshall variance.
  911. ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[0] = 0;
  912. ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[1] = ActualCount;
  913. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  914. NDR64_UINT32 CopySize =
  915. Ndr64pConvertTo2GB( ActualCount *
  916. (NDR64_UINT64)pArrayFormat->ElementSize );
  917. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  918. RpcpMemoryCopy( pStubMsg->Buffer,
  919. pMemory,
  920. CopySize );
  921. uchar *pBufferStart = pStubMsg->Buffer;
  922. pStubMsg->Buffer += CopySize;
  923. // Marshall embedded pointers.
  924. if ( pArrayFormat->Flags.HasPointerInfo )
  925. {
  926. Ndr64pPointerLayoutMarshall( pStubMsg,
  927. pArrayFormat + 1,
  928. (NDR64_UINT32)ActualCount,
  929. pMemory,
  930. pBufferStart );
  931. }
  932. }
  933. void
  934. Ndr64VaryingArrayMarshall(
  935. PMIDL_STUB_MESSAGE pStubMsg,
  936. uchar * pMemory,
  937. PNDR64_FORMAT pFormat )
  938. /*++
  939. Routine Description :
  940. Marshalls a top level or embedded one dimensional varying array.
  941. Arguments :
  942. pStubMsg - Pointer to the stub message.
  943. pMemory - Pointer to the array being marshalled.
  944. pFormat - Array's format string description.
  945. Return :
  946. None.
  947. --*/
  948. {
  949. const NDR64_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  950. (NDR64_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  951. // Compute the variance offset and count.
  952. NDR64_WIRE_COUNT_TYPE ActualCount =
  953. Ndr64EvaluateExpr( pStubMsg,
  954. pArrayFormat->VarDescriptor,
  955. EXPR_ACTUALCOUNT );
  956. NDR64_UINT32 CopySize =
  957. Ndr64pConvertTo2GB( ActualCount * (NDR64_UINT64)pArrayFormat->ElementSize );
  958. // Align the buffer for variance marshalling.
  959. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  960. // Marshall variance.
  961. ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[0] = 0;
  962. ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[1] = ActualCount;
  963. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  964. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment);
  965. // Copy the array.
  966. RpcpMemoryCopy( pStubMsg->Buffer,
  967. pMemory,
  968. CopySize );
  969. // Update buffer pointer.
  970. uchar *pBufferStart = pStubMsg->Buffer;
  971. pStubMsg->Buffer += CopySize;
  972. // Marshall embedded pointers.
  973. if ( pArrayFormat->Flags.HasPointerInfo )
  974. {
  975. Ndr64pPointerLayoutMarshall( pStubMsg,
  976. pArrayFormat + 1,
  977. (NDR64_UINT32)ActualCount,
  978. pMemory,
  979. pBufferStart );
  980. }
  981. }
  982. void
  983. Ndr64ComplexArrayMarshall(
  984. PMIDL_STUB_MESSAGE pStubMsg,
  985. uchar * pMemory,
  986. PNDR64_FORMAT pFormat )
  987. /*++
  988. Routine Description :
  989. Marshalls a top level complex array.
  990. Arguments :
  991. pStubMsg - Pointer to the stub message.
  992. pMemory - Pointer to the array being marshalled.
  993. pFormat - Array's format string description.
  994. Return :
  995. None.
  996. --*/
  997. {
  998. const NDR64_BOGUS_ARRAY_HEADER_FORMAT *pArrayFormat =
  999. (NDR64_BOGUS_ARRAY_HEADER_FORMAT *) pFormat;
  1000. bool fSetPointerBufferMark = ! pStubMsg->PointerBufferMark;
  1001. if ( fSetPointerBufferMark )
  1002. {
  1003. BOOL fOldIgnore = pStubMsg->IgnoreEmbeddedPointers;
  1004. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  1005. ulong BufferLenOffset = 0xf & PtrToUlong( pStubMsg->Buffer );
  1006. ulong BufferLengthSave = pStubMsg->BufferLength;
  1007. pStubMsg->BufferLength = BufferLenOffset;
  1008. Ndr64ComplexArrayBufferSize( pStubMsg,
  1009. pMemory,
  1010. pFormat );
  1011. // Pointer increment including alignments.
  1012. BufferLenOffset = pStubMsg->BufferLength - BufferLenOffset;
  1013. //
  1014. // This is the buffer pointer to the position where embedded pointers
  1015. // will be marshalled.
  1016. //
  1017. pStubMsg->PointerBufferMark = pStubMsg->Buffer + BufferLenOffset;
  1018. pStubMsg->BufferLength = BufferLengthSave;
  1019. pStubMsg->IgnoreEmbeddedPointers = fOldIgnore;
  1020. }
  1021. BOOL IsFixed = ( pArrayFormat->FormatCode == FC64_FIX_BOGUS_ARRAY ) ||
  1022. ( pArrayFormat->FormatCode == FC64_FIX_FORCED_BOGUS_ARRAY );
  1023. PFORMAT_STRING pElementFormat = (PFORMAT_STRING)pArrayFormat->Element;
  1024. NDR64_WIRE_COUNT_TYPE Elements = pArrayFormat->NumberElements;
  1025. NDR64_WIRE_COUNT_TYPE Count = Elements;
  1026. NDR64_WIRE_COUNT_TYPE Offset = 0;
  1027. SAVE_CONTEXT<uchar*> ConformanceMarkSave( pStubMsg->ConformanceMark );
  1028. SAVE_CONTEXT<uchar*> VarianceMarkSave( pStubMsg->VarianceMark );
  1029. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1030. if ( !IsFixed )
  1031. {
  1032. const NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT* pConfVarFormat=
  1033. (NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT*)pFormat;
  1034. if ( pConfVarFormat->ConfDescription != 0 )
  1035. {
  1036. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1037. {
  1038. //
  1039. // Outer most dimension sets the conformance marker.
  1040. //
  1041. // Align the buffer for conformance marshalling.
  1042. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  1043. // Mark where the conformance count(s) will be marshalled.
  1044. pStubMsg->ConformanceMark = pStubMsg->Buffer;
  1045. // Increment past where the conformance will go.
  1046. pStubMsg->Buffer += pArrayFormat->NumberDims * sizeof(NDR64_WIRE_COUNT_TYPE);
  1047. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  1048. }
  1049. Elements = Ndr64EvaluateExpr( pStubMsg,
  1050. pConfVarFormat->ConfDescription,
  1051. EXPR_MAXCOUNT );
  1052. *(NDR64_WIRE_COUNT_TYPE*) pStubMsg->ConformanceMark = Elements;
  1053. pStubMsg->ConformanceMark += sizeof(NDR64_WIRE_COUNT_TYPE);
  1054. Offset = 0;
  1055. Count = Elements;
  1056. }
  1057. //
  1058. // Check for variance description.
  1059. //
  1060. if ( pConfVarFormat->VarDescription != 0 )
  1061. {
  1062. if ( ! NDR64_IS_VAR_MARK_VALID( pStubMsg->uFlags ) )
  1063. {
  1064. NDR64_UINT32 Dimensions;
  1065. //
  1066. // Set the variance marker.
  1067. //
  1068. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1069. Dimensions = ( pArrayFormat->Flags.IsArrayofStrings ) ? ( pArrayFormat->NumberDims - 1) :
  1070. ( pArrayFormat->NumberDims );
  1071. // Increment past where the variance will go.
  1072. pStubMsg->VarianceMark = pStubMsg->Buffer;
  1073. pStubMsg->Buffer += Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1074. if ( NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  1075. NDR64_SET_VAR_MARK_VALID( pStubMsg->uFlags );
  1076. }
  1077. else if ( !NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  1078. NDR64_RESET_VAR_MARK_VALID( pStubMsg->uFlags );
  1079. Count =
  1080. Ndr64EvaluateExpr( pStubMsg,
  1081. pConfVarFormat->VarDescription,
  1082. EXPR_ACTUALCOUNT );
  1083. Offset =
  1084. Ndr64EvaluateExpr( pStubMsg,
  1085. pConfVarFormat->OffsetDescription,
  1086. EXPR_OFFSET );
  1087. if ( Count + Offset > Elements )
  1088. RpcRaiseException( RPC_X_INVALID_BOUND );
  1089. ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->VarianceMark)[0] = Offset;
  1090. ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->VarianceMark)[1] = Count;
  1091. pStubMsg->VarianceMark += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1092. }
  1093. }
  1094. NDR64_UINT32 ElementMemorySize =
  1095. Ndr64pMemorySize( pStubMsg,
  1096. pElementFormat,
  1097. FALSE );
  1098. pMemory += Ndr64pConvertTo2GB( Offset *
  1099. (NDR64_UINT64)ElementMemorySize);
  1100. Ndr64pConvertTo2GB( Elements *
  1101. (NDR64_UINT64)ElementMemorySize );
  1102. Ndr64pConvertTo2GB( Count *
  1103. (NDR64_UINT64)ElementMemorySize );
  1104. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment);
  1105. for ( ; Count--; )
  1106. {
  1107. Ndr64EmbeddedTypeMarshall( pStubMsg,
  1108. pMemory,
  1109. pElementFormat );
  1110. pMemory += ElementMemorySize;
  1111. }
  1112. if ( fSetPointerBufferMark )
  1113. {
  1114. pStubMsg->Buffer = pStubMsg->PointerBufferMark;
  1115. pStubMsg->PointerBufferMark = 0;
  1116. }
  1117. }
  1118. void
  1119. Ndr64UnionMarshall (
  1120. PMIDL_STUB_MESSAGE pStubMsg,
  1121. uchar * pMemory,
  1122. PNDR64_FORMAT pFormat )
  1123. /*++
  1124. Routine Description :
  1125. Marshalls an encapsulated union.
  1126. Used for FC64_ENCAPSULATED_UNION.
  1127. Arguments :
  1128. pStubMsg - Pointer to the stub message.
  1129. pMemory - Pointer to the union being marshalled.
  1130. pFormat - Union's format string description.
  1131. Return :
  1132. None.
  1133. --*/
  1134. {
  1135. const NDR64_UNION_ARM_SELECTOR* pArmSelector;
  1136. EXPR_VALUE SwitchIs;
  1137. NDR64_FORMAT_CHAR SwitchType;
  1138. uchar *pArmMemory;
  1139. switch(*(PFORMAT_STRING)pFormat)
  1140. {
  1141. case FC64_NON_ENCAPSULATED_UNION:
  1142. {
  1143. const NDR64_NON_ENCAPSULATED_UNION* pNonEncapUnionFormat =
  1144. (const NDR64_NON_ENCAPSULATED_UNION*) pFormat;
  1145. ALIGN(pStubMsg->Buffer, pNonEncapUnionFormat->Alignment);
  1146. SwitchType = pNonEncapUnionFormat->SwitchType;
  1147. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pNonEncapUnionFormat + 1);
  1148. SwitchIs = Ndr64EvaluateExpr( pStubMsg,
  1149. pNonEncapUnionFormat->Switch,
  1150. EXPR_SWITCHIS );
  1151. pArmMemory = pMemory;
  1152. break;
  1153. }
  1154. case FC64_ENCAPSULATED_UNION:
  1155. {
  1156. const NDR64_ENCAPSULATED_UNION* pEncapUnionFormat =
  1157. (const NDR64_ENCAPSULATED_UNION*)pFormat;
  1158. ALIGN(pStubMsg->Buffer, pEncapUnionFormat->Alignment);
  1159. SwitchType = pEncapUnionFormat->SwitchType;
  1160. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pEncapUnionFormat + 1);
  1161. SwitchIs = Ndr64pSimpleTypeToExprValue(SwitchType,
  1162. pMemory);
  1163. pArmMemory = pMemory + pEncapUnionFormat->MemoryOffset;
  1164. break;
  1165. }
  1166. default:
  1167. NDR_ASSERT(0, "Bad union format\n");
  1168. }
  1169. Ndr64SimpleTypeMarshall( pStubMsg,
  1170. (uchar *)&SwitchIs,
  1171. SwitchType );
  1172. ALIGN(pStubMsg->Buffer, pArmSelector->Alignment);
  1173. PNDR64_FORMAT pArmFormat =
  1174. Ndr64pFindUnionArm( pStubMsg,
  1175. pArmSelector,
  1176. SwitchIs );
  1177. if ( !pArmFormat )
  1178. return;
  1179. Ndr64EmbeddedTypeMarshall( pStubMsg,
  1180. pArmMemory,
  1181. pArmFormat );
  1182. }
  1183. void
  1184. Ndr64XmitOrRepAsMarshall (
  1185. PMIDL_STUB_MESSAGE pStubMsg,
  1186. uchar * pMemory,
  1187. PNDR64_FORMAT pFormat,
  1188. bool bIsEmbedded )
  1189. /*++
  1190. Routine Description :
  1191. Marshalls a transmit as or represent as argument:
  1192. - translate the presented object into a transmitted object
  1193. - marshall the transmitted object
  1194. - free the transmitted object
  1195. Format string layout:
  1196. check out ndr64types.h
  1197. Arguments :
  1198. pStubMsg - a pointer to the stub message
  1199. pMemory - presented type translated into transmitted type
  1200. and than to be marshalled
  1201. pFormat - format string description
  1202. --*/
  1203. {
  1204. // Skip the token itself and Oi flag. Fetch the QuintupleIndex.
  1205. NDR64_TRANSMIT_AS_FORMAT * pTransFormat =
  1206. ( NDR64_TRANSMIT_AS_FORMAT *) pFormat;
  1207. NDR_ASSERT( pTransFormat->FormatCode == FC64_TRANSMIT_AS || pTransFormat->FormatCode , "invalid format string for user marshal" );
  1208. unsigned short QIndex = pTransFormat->RoutineIndex;
  1209. // First translate the presented type into the transmitted type.
  1210. // This includes an allocation of a transmitted type object.
  1211. pStubMsg->pPresentedType = pMemory;
  1212. pStubMsg->pTransmitType = NULL;
  1213. const XMIT_ROUTINE_QUINTUPLE * pQuintuple =
  1214. pStubMsg->StubDesc->aXmitQuintuple;
  1215. pQuintuple[ QIndex ].pfnTranslateToXmit( pStubMsg );
  1216. unsigned char * pTransmittedType = pStubMsg->pTransmitType;
  1217. // In NDR64, Xmit/Rep cannot be a pointer or contain a pointer.
  1218. // So we don't need to worry about the pointer queue here.
  1219. if ( bIsEmbedded )
  1220. {
  1221. Ndr64EmbeddedTypeMarshall( pStubMsg,
  1222. pTransmittedType,
  1223. pTransFormat->TransmittedType );
  1224. }
  1225. else
  1226. {
  1227. Ndr64TopLevelTypeMarshall( pStubMsg,
  1228. pTransmittedType,
  1229. pTransFormat->TransmittedType );
  1230. }
  1231. pStubMsg->pTransmitType = pTransmittedType;
  1232. // Free the temporary transmitted object (it was allocated by the user).
  1233. pQuintuple[ QIndex ].pfnFreeXmit( pStubMsg );
  1234. }
  1235. void
  1236. Ndr64TopLevelXmitOrRepAsMarshall (
  1237. PMIDL_STUB_MESSAGE pStubMsg,
  1238. uchar * pMemory,
  1239. PNDR64_FORMAT pFormat )
  1240. {
  1241. Ndr64XmitOrRepAsMarshall( pStubMsg,
  1242. pMemory,
  1243. pFormat,
  1244. false );
  1245. }
  1246. void
  1247. Ndr64EmbeddedXmitOrRepAsMarshall (
  1248. PMIDL_STUB_MESSAGE pStubMsg,
  1249. uchar * pMemory,
  1250. PNDR64_FORMAT pFormat )
  1251. {
  1252. Ndr64XmitOrRepAsMarshall( pStubMsg,
  1253. pMemory,
  1254. pFormat,
  1255. true );
  1256. }
  1257. void
  1258. Ndr64UserMarshallMarshallInternal(
  1259. PMIDL_STUB_MESSAGE pStubMsg,
  1260. uchar * pMemory,
  1261. PNDR64_FORMAT pFormat,
  1262. NDR64_PTR_WIRE_TYPE *pWirePtr )
  1263. {
  1264. NDR64_USER_MARSHAL_FORMAT * pUserFormat =
  1265. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1266. unsigned char * pUserBuffer = pStubMsg->Buffer;
  1267. unsigned char * pUserBufferSaved = pUserBuffer;
  1268. // We always call user's routine to marshall.
  1269. USER_MARSHAL_CB UserMarshalCB;
  1270. Ndr64pInitUserMarshalCB( pStubMsg,
  1271. pUserFormat,
  1272. USER_MARSHAL_CB_MARSHALL,
  1273. & UserMarshalCB );
  1274. unsigned short QIndex = pUserFormat->RoutineIndex;
  1275. const USER_MARSHAL_ROUTINE_QUADRUPLE * pQuadruple =
  1276. (const USER_MARSHAL_ROUTINE_QUADRUPLE *)( ( NDR_PROC_CONTEXT *)pStubMsg->pContext )->pSyntaxInfo->aUserMarshalQuadruple;
  1277. if ((pUserBufferSaved < (uchar *) pStubMsg->RpcMsg->Buffer) ||
  1278. ((unsigned long) (pUserBufferSaved - (uchar *) pStubMsg->RpcMsg->Buffer)
  1279. > pStubMsg->RpcMsg->BufferLength))
  1280. {
  1281. RpcRaiseException( RPC_X_INVALID_BUFFER );
  1282. }
  1283. pUserBuffer = pQuadruple[ QIndex ].pfnMarshall( (ulong*) &UserMarshalCB,
  1284. pUserBuffer,
  1285. pMemory );
  1286. if ((pUserBufferSaved > pUserBuffer) ||
  1287. ((unsigned long) (pUserBuffer - (uchar *) pStubMsg->RpcMsg->Buffer)
  1288. > pStubMsg->RpcMsg->BufferLength ))
  1289. {
  1290. RpcRaiseException( RPC_X_INVALID_BUFFER );
  1291. }
  1292. if ( pUserBuffer == pUserBufferSaved )
  1293. {
  1294. // This is valid only if the wire type was a unique type.
  1295. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE) )
  1296. {
  1297. *pWirePtr = 0;
  1298. return;
  1299. }
  1300. else
  1301. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  1302. }
  1303. pStubMsg->Buffer = pUserBuffer;
  1304. }
  1305. void
  1306. NDR64_USR_MRSHL_MRSHL_POINTER_QUEUE_ELEMENT::Dispatch(MIDL_STUB_MESSAGE *pStubMsg)
  1307. {
  1308. Ndr64UserMarshallMarshallInternal( pStubMsg,
  1309. pMemory,
  1310. pFormat,
  1311. pWireMarkerPtr );
  1312. }
  1313. #if defined(DBG)
  1314. void
  1315. NDR64_USR_MRSHL_MRSHL_POINTER_QUEUE_ELEMENT::Print()
  1316. {
  1317. DbgPrint("NDR_USR_MRSHL_MRSHL_POINTER_QUEUE_ELEMENT\n");
  1318. DbgPrint("pMemory: %p\n", pMemory );
  1319. DbgPrint("pFormat: %p\n", pFormat );
  1320. DbgPrint("pWireMarkerPtr: %p\n", pWireMarkerPtr );
  1321. }
  1322. #endif
  1323. void
  1324. Ndr64UserMarshallPointeeMarshall(
  1325. PMIDL_STUB_MESSAGE pStubMsg,
  1326. uchar * pMemory,
  1327. PNDR64_FORMAT pFormat,
  1328. NDR64_PTR_WIRE_TYPE *pWirePtr )
  1329. {
  1330. if ( !pStubMsg->pPointerQueueState ||
  1331. !pStubMsg->pPointerQueueState->GetActiveQueue() )
  1332. {
  1333. POINTER_BUFFER_SWAP_CONTEXT SwapContext( pStubMsg );
  1334. Ndr64UserMarshallMarshallInternal(
  1335. pStubMsg,
  1336. pMemory,
  1337. pFormat,
  1338. pWirePtr );
  1339. return;
  1340. }
  1341. NDR64_USR_MRSHL_MRSHL_POINTER_QUEUE_ELEMENT*pElement =
  1342. new(pStubMsg->pPointerQueueState)
  1343. NDR64_USR_MRSHL_MRSHL_POINTER_QUEUE_ELEMENT(pMemory,
  1344. (PFORMAT_STRING)pFormat,
  1345. pWirePtr);
  1346. pStubMsg->pPointerQueueState->GetActiveQueue()->Enque( pElement );
  1347. }
  1348. void
  1349. Ndr64UserMarshalMarshall(
  1350. PMIDL_STUB_MESSAGE pStubMsg,
  1351. uchar * pMemory,
  1352. PNDR64_FORMAT pFormat,
  1353. bool bIsEmbedded )
  1354. /*++
  1355. Routine Description :
  1356. Marshals a usr_marshall object.
  1357. Arguments :
  1358. pStubMsg - Pointer to the stub message.
  1359. pMemory - Pointer to the usr_marshall object to marshall.
  1360. pFormat - Object's format string description.
  1361. Return :
  1362. None.
  1363. --*/
  1364. {
  1365. NDR64_USER_MARSHAL_FORMAT * pUserFormat =
  1366. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1367. NDR_ASSERT( pUserFormat->FormatCode == FC64_USER_MARSHAL, "invalid format string for user marshal" );
  1368. ALIGN( pStubMsg->Buffer, pUserFormat->TransmittedTypeWireAlignment );
  1369. if ( pUserFormat->Flags & USER_MARSHAL_POINTER )
  1370. {
  1371. NDR64_PTR_WIRE_TYPE *pWireMarkerPtr = NULL;
  1372. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE ) ||
  1373. (( pUserFormat->Flags & USER_MARSHAL_REF ) && bIsEmbedded) )
  1374. {
  1375. pWireMarkerPtr = (NDR64_PTR_WIRE_TYPE *) pStubMsg->Buffer;
  1376. *((NDR64_PTR_WIRE_TYPE *)pStubMsg->Buffer) = NDR64_USER_MARSHAL_MARKER;
  1377. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  1378. }
  1379. Ndr64UserMarshallPointeeMarshall( pStubMsg,
  1380. pMemory,
  1381. pFormat,
  1382. pWireMarkerPtr );
  1383. return;
  1384. }
  1385. Ndr64UserMarshallMarshallInternal(
  1386. pStubMsg,
  1387. pMemory,
  1388. pFormat,
  1389. NULL );
  1390. }
  1391. void
  1392. Ndr64TopLevelUserMarshalMarshall(
  1393. PMIDL_STUB_MESSAGE pStubMsg,
  1394. uchar * pMemory,
  1395. PNDR64_FORMAT pFormat )
  1396. {
  1397. Ndr64UserMarshalMarshall( pStubMsg,
  1398. pMemory,
  1399. pFormat,
  1400. false );
  1401. }
  1402. void
  1403. Ndr64EmbeddedUserMarshalMarshall(
  1404. PMIDL_STUB_MESSAGE pStubMsg,
  1405. uchar * pMemory,
  1406. PNDR64_FORMAT pFormat )
  1407. {
  1408. Ndr64UserMarshalMarshall( pStubMsg,
  1409. pMemory,
  1410. pFormat,
  1411. true );
  1412. }
  1413. void
  1414. Ndr64ServerContextNewMarshall(
  1415. PMIDL_STUB_MESSAGE pStubMsg,
  1416. NDR_SCONTEXT ContextHandle,
  1417. NDR_RUNDOWN RundownRoutine,
  1418. PFORMAT_STRING pFormat )
  1419. /*
  1420. This is a non-optimized NDR engine entry for context handle marshaling.
  1421. In particular it is able to handle all the new NT5 context handle flavors.
  1422. The optimized routine follows below.
  1423. ContextHandle - note, this is not the user's handle but a
  1424. NDR_SCONTEXT pointer from the stub local stack.
  1425. User's handle is a field in that object.
  1426. Note that intepreter calls Ndr64MarshallHandle. However, we can't use it
  1427. as it assumes a helper array of saved context handles that we don't need.
  1428. */
  1429. {
  1430. void * pGuard = RPC_CONTEXT_HANDLE_DEFAULT_GUARD;
  1431. DWORD Flags = RPC_CONTEXT_HANDLE_DEFAULT_FLAGS;
  1432. NDR64_CONTEXT_HANDLE_FORMAT * pContextFormat;
  1433. pContextFormat = ( NDR64_CONTEXT_HANDLE_FORMAT * )pFormat;
  1434. NDR_ASSERT( pContextFormat->FormatCode == FC64_BIND_CONTEXT, "invalid format char " );
  1435. // NT5 beta2 features: strict context handle, serialize and noserialize.
  1436. if ( pContextFormat->ContextFlags & NDR_STRICT_CONTEXT_HANDLE )
  1437. {
  1438. pGuard = pStubMsg->StubDesc->RpcInterfaceInformation;
  1439. pGuard = & ((PRPC_SERVER_INTERFACE)pGuard)->InterfaceId;
  1440. }
  1441. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_NOSERIALIZE )
  1442. {
  1443. Flags = RPC_CONTEXT_HANDLE_DONT_SERIALIZE;
  1444. }
  1445. else if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_SERIALIZE )
  1446. {
  1447. Flags = RPC_CONTEXT_HANDLE_SERIALIZE;
  1448. }
  1449. ALIGN( pStubMsg->Buffer, 0x3 );
  1450. NDRSContextMarshall2(
  1451. pStubMsg->RpcMsg->Handle,
  1452. ContextHandle,
  1453. pStubMsg->Buffer,
  1454. RundownRoutine,
  1455. pGuard,
  1456. Flags );
  1457. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  1458. }
  1459. // define the jump table
  1460. #define NDR64_BEGIN_TABLE \
  1461. PNDR64_MARSHALL_ROUTINE extern const Ndr64MarshallRoutinesTable[] = \
  1462. {
  1463. #define NDR64_TABLE_END \
  1464. };
  1465. #define NDR64_ZERO_ENTRY NULL
  1466. #define NDR64_UNUSED_TABLE_ENTRY( number, tokenname ) ,NULL
  1467. #define NDR64_UNUSED_TABLE_ENTRY_NOSYM( number ) ,NULL
  1468. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  1469. ,marshall
  1470. #define NDR64_SIMPLE_TYPE_TABLE_ENTRY( number, tokenname, typebuffersize, memorysize) \
  1471. ,Ndr64UDTSimpleTypeMarshall1
  1472. #include "tokntbl.h"
  1473. C_ASSERT( sizeof(Ndr64MarshallRoutinesTable)/sizeof(PNDR64_MARSHALL_ROUTINE) == 256 );
  1474. #undef NDR64_BEGIN_TABLE
  1475. #undef NDR64_TABLE_ENTRY
  1476. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  1477. ,embeddedmarshall
  1478. #define NDR64_BEGIN_TABLE \
  1479. PNDR64_MARSHALL_ROUTINE extern const Ndr64EmbeddedMarshallRoutinesTable[] = \
  1480. {
  1481. #include "tokntbl.h"
  1482. C_ASSERT( sizeof(Ndr64EmbeddedMarshallRoutinesTable) / sizeof(PNDR64_MARSHALL_ROUTINE) == 256 );