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.

1629 lines
47 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1993 - 2000 Microsoft Corporation
  3. Module Name :
  4. bufsize.c
  5. Abstract :
  6. This file contains the routines called by MIDL 2.0 stubs and the
  7. interpreter for computing the buffer size needed for a parameter.
  8. Author :
  9. David Kays dkays September 1993.
  10. Revision History :
  11. ---------------------------------------------------------------------*/
  12. #include "precomp.hxx"
  13. #include "..\..\ndr20\ndrole.h"
  14. void
  15. Ndr64UDTSimpleTypeSize(
  16. PMIDL_STUB_MESSAGE pStubMsg,
  17. uchar * pMemory,
  18. PNDR64_FORMAT pFormat )
  19. /*++
  20. Routine Description :
  21. Get the size a top level or embedded simple type.
  22. Arguments :
  23. pStubMsg - Pointer to the stub message.
  24. pMemory - Pointer to the data being sized.
  25. pFormat - Pointer's format string description.
  26. Return :
  27. None.
  28. --*/
  29. {
  30. LENGTH_ALIGN( pStubMsg->BufferLength,
  31. NDR64_SIMPLE_TYPE_BUFALIGN(*(PFORMAT_STRING)pFormat) );
  32. pStubMsg->BufferLength += NDR64_SIMPLE_TYPE_BUFSIZE(*(PFORMAT_STRING)pFormat);
  33. pMemory += NDR64_SIMPLE_TYPE_MEMSIZE(*(PFORMAT_STRING)pFormat);
  34. }
  35. void
  36. Ndr64pInterfacePointerBufferSize (
  37. PMIDL_STUB_MESSAGE pStubMsg,
  38. uchar * pMemory,
  39. PNDR64_FORMAT pFormat )
  40. /*++
  41. Routine Description :
  42. Computes the buffer size needed for an interface pointer.
  43. Arguments :
  44. pStubMsg - Pointer to the stub message.
  45. pMemory - The interface pointer being sized.
  46. pFormat - Interface pointer's format string description.
  47. Return :
  48. None.
  49. // wire representation of a marshalled interface pointer
  50. typedef struct tagMInterfacePointer
  51. {
  52. ULONG ulCntData; // size of data
  53. [size_is(ulCntData)] BYTE abData[]; // data (OBJREF)
  54. } MInterfacePointer;
  55. --*/
  56. {
  57. const NDR64_CONSTANT_IID_FORMAT *pConstInterfaceFormat =
  58. (NDR64_CONSTANT_IID_FORMAT*)pFormat;
  59. const NDR64_IID_FORMAT *pInterfaceFormat =
  60. (NDR64_IID_FORMAT*)pFormat;
  61. //
  62. // Get an IID pointer.
  63. //
  64. IID *piid;
  65. if ( ((NDR64_IID_FLAGS*)&pInterfaceFormat->Flags)->ConstantIID )
  66. {
  67. piid = (IID*)&pConstInterfaceFormat->Guid;
  68. }
  69. else
  70. {
  71. piid = (IID *) Ndr64EvaluateExpr( pStubMsg,
  72. pInterfaceFormat->IIDDescriptor,
  73. EXPR_IID );
  74. if(piid == 0)
  75. {
  76. RpcRaiseException( RPC_S_INVALID_ARG );
  77. }
  78. }
  79. // Allocate space for the length and array bounds.
  80. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  81. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE);
  82. pStubMsg->BufferLength += sizeof(ulong);
  83. unsigned long size;
  84. HRESULT hr = (*pfnCoGetMarshalSizeMax)(&size, *piid, (IUnknown *)pMemory,
  85. pStubMsg->dwDestContext, pStubMsg->pvDestContext, 0);
  86. if(FAILED(hr))
  87. {
  88. RpcRaiseException(hr);
  89. }
  90. pStubMsg->BufferLength += size;
  91. }
  92. __forceinline void
  93. Ndr64pPointerBufferSizeInternal(
  94. PMIDL_STUB_MESSAGE pStubMsg,
  95. uchar * pMemory,
  96. PNDR64_FORMAT pFormat )
  97. /*++
  98. Routine Description :
  99. Private routine for sizing a pointee. This is the entry
  100. point for pointers embedded in structures, arrays, or unions.
  101. Used for FC64_RP, FC64_UP, FC64_FP, FC64_OP.
  102. Arguments :
  103. pStubMsg - Pointer to the stub message.
  104. pMemory - Pointer to the data being sized.
  105. pFormat - Pointer's format string description.
  106. pStubMsg->BufferLength - ready for the pointee.
  107. Return :
  108. None.
  109. --*/
  110. { const NDR64_POINTER_FORMAT *pPointerFormat = (NDR64_POINTER_FORMAT*) pFormat;
  111. PFORMAT_STRING pPointeeFormat = (PFORMAT_STRING)pPointerFormat->Pointee;
  112. if ( ! pMemory )
  113. return;
  114. switch( pPointerFormat->FormatCode )
  115. {
  116. case FC64_IP:
  117. Ndr64pInterfacePointerBufferSize( pStubMsg,
  118. pMemory,
  119. pPointeeFormat
  120. );
  121. return;
  122. case FC64_FP:
  123. //
  124. // Check if we have already sized this full pointer.
  125. //
  126. if ( Ndr64pFullPointerQueryPointer( pStubMsg,
  127. pMemory,
  128. FULL_POINTER_BUF_SIZED,
  129. 0 ) )
  130. return;
  131. break;
  132. default:
  133. break;
  134. }
  135. if ( NDR64_SIMPLE_POINTER( pPointerFormat->Flags ) )
  136. {
  137. // Pointer to simple type.
  138. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_SIMPLE_TYPE_BUFALIGN(*pPointeeFormat));
  139. pStubMsg->BufferLength += NDR64_SIMPLE_TYPE_BUFSIZE(*pPointeeFormat);
  140. return;
  141. }
  142. //
  143. // Pointer to complex type.
  144. //
  145. if ( NDR64_POINTER_DEREF( pPointerFormat->Flags ) )
  146. pMemory = *((uchar **)pMemory);
  147. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  148. NDR64_RESET_EMBEDDED_FLAGS_TO_STANDALONE(pStubMsg->uFlags);
  149. Ndr64TopLevelTypeSize( pStubMsg,
  150. pMemory,
  151. pPointeeFormat );
  152. }
  153. NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT::NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT(
  154. MIDL_STUB_MESSAGE *pStubMsg,
  155. uchar * const pMemoryNew,
  156. const PFORMAT_STRING pFormatNew) :
  157. pMemory(pMemoryNew),
  158. pFormat(pFormatNew),
  159. uFlags(pStubMsg->uFlags),
  160. pCorrMemory(pStubMsg->pCorrMemory)
  161. {
  162. }
  163. void
  164. NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT::Dispatch(
  165. MIDL_STUB_MESSAGE *pStubMsg)
  166. {
  167. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags, uFlags );
  168. CORRELATION_CONTEXT CorrCtxt(pStubMsg, pCorrMemory);
  169. Ndr64pPointerBufferSizeInternal( pStubMsg,
  170. pMemory,
  171. pFormat);
  172. }
  173. #if defined(DBG)
  174. void
  175. NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT::Print()
  176. {
  177. DbgPrint("NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT\n");
  178. DbgPrint("pNext: %p\n", pNext );
  179. DbgPrint("pMemory: %p\n", pMemory );
  180. DbgPrint("pFormat: %p\n", pFormat );
  181. DbgPrint("uFlags: %x\n", uFlags );
  182. DbgPrint("pCorrMemory: %p\n", pCorrMemory );
  183. }
  184. #endif
  185. void
  186. Ndr64pEnquePointerBufferSize(
  187. PMIDL_STUB_MESSAGE pStubMsg,
  188. uchar * pMemory,
  189. PNDR64_FORMAT pFormat )
  190. {
  191. NDR64_POINTER_CONTEXT PointerContext( pStubMsg );
  192. RpcTryFinally
  193. {
  194. NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT *pElement =
  195. new(PointerContext.GetActiveState())
  196. NDR64_BUFSIZE_POINTER_QUEUE_ELEMENT(pStubMsg,
  197. pMemory,
  198. (PFORMAT_STRING)pFormat);
  199. PointerContext.Enque( pElement );
  200. PointerContext.DispatchIfRequired();
  201. }
  202. RpcFinally
  203. {
  204. PointerContext.EndContext();
  205. }
  206. RpcEndFinally
  207. }
  208. void
  209. Ndr64pPointerBufferSize(
  210. PMIDL_STUB_MESSAGE pStubMsg,
  211. uchar * pMemory,
  212. PNDR64_FORMAT pFormat )
  213. {
  214. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  215. if (!NdrIsLowStack(pStubMsg))
  216. {
  217. Ndr64pPointerBufferSizeInternal(
  218. pStubMsg,
  219. pMemory,
  220. pFormat );
  221. return;
  222. }
  223. Ndr64pEnquePointerBufferSize(
  224. pStubMsg,
  225. pMemory,
  226. pFormat );
  227. }
  228. __forceinline void
  229. Ndr64TopLevelPointerBufferSize(
  230. PMIDL_STUB_MESSAGE pStubMsg,
  231. uchar * pMemory,
  232. PNDR64_FORMAT pFormat )
  233. {
  234. if ( *(PFORMAT_STRING)pFormat != FC64_RP )
  235. {
  236. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_PTR_WIRE_ALIGN );
  237. pStubMsg->BufferLength += sizeof(NDR64_PTR_WIRE_TYPE);
  238. }
  239. Ndr64pPointerBufferSize( pStubMsg,
  240. pMemory,
  241. pFormat );
  242. }
  243. __forceinline void
  244. Ndr64EmbeddedPointerBufferSize(
  245. PMIDL_STUB_MESSAGE pStubMsg,
  246. uchar * pMemory,
  247. PNDR64_FORMAT pFormat )
  248. {
  249. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_PTR_WIRE_ALIGN );
  250. pStubMsg->BufferLength += sizeof(NDR64_PTR_WIRE_TYPE);
  251. if ( pStubMsg->IgnoreEmbeddedPointers )
  252. return;
  253. POINTER_BUFFERLENGTH_SWAP_CONTEXT SwapContext( pStubMsg );
  254. Ndr64pPointerBufferSize( pStubMsg,
  255. *(uchar**)pMemory,
  256. pFormat );
  257. }
  258. void
  259. Ndr64pRangeBufferSize(
  260. PMIDL_STUB_MESSAGE pStubMsg,
  261. uchar * pMemory,
  262. PNDR64_FORMAT pFormat )
  263. /*++
  264. Routine Description :
  265. Computes the buffer size needed for a simple type with range on it.
  266. Used for FC64_RANGE.
  267. Arguments :
  268. pStubMsg - Pointer to the stub message.
  269. pMemory - Pointer to the structure being sized.
  270. pFormat - Structure's format string description.
  271. Return :
  272. None.
  273. --*/
  274. {
  275. const NDR64_RANGE_FORMAT * pRangeFormat =
  276. (const NDR64_RANGE_FORMAT*)pFormat;
  277. LENGTH_ALIGN( pStubMsg->BufferLength, NDR64_SIMPLE_TYPE_BUFALIGN(pRangeFormat->RangeType) );
  278. pStubMsg->BufferLength += NDR64_SIMPLE_TYPE_BUFSIZE(pRangeFormat->RangeType);
  279. }
  280. void
  281. Ndr64SimpleStructBufferSize(
  282. PMIDL_STUB_MESSAGE pStubMsg,
  283. uchar * pMemory,
  284. PNDR64_FORMAT pFormat )
  285. /*++
  286. Routine Description :
  287. Computes the buffer size needed for a simple structure.
  288. Arguments :
  289. pStubMsg - Pointer to the stub message.
  290. pMemory - Pointer to the structure being sized.
  291. pFormat - Structure's format string description.
  292. Return :
  293. None.
  294. --*/
  295. {
  296. const NDR64_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  297. (NDR64_STRUCTURE_HEADER_FORMAT*) pFormat;
  298. LENGTH_ALIGN( pStubMsg->BufferLength, pStructFormat->Alignment );
  299. pStubMsg->BufferLength += pStructFormat->MemorySize;
  300. if ( pStructFormat->Flags.HasPointerInfo )
  301. {
  302. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  303. Ndr64pPointerLayoutBufferSize( pStubMsg,
  304. pStructFormat + 1,
  305. 0,
  306. pMemory );
  307. }
  308. }
  309. void
  310. Ndr64ConformantStructBufferSize(
  311. PMIDL_STUB_MESSAGE pStubMsg,
  312. uchar * pMemory,
  313. PNDR64_FORMAT pFormat )
  314. /*++
  315. Routine Description :
  316. Computes the buffer size needed for a conformant structure.
  317. Used for FC64_CSTRUCT and FC64_CPSTRUCT.
  318. Arguments :
  319. pStubMsg - Pointer to the stub message.
  320. pMemory - Pointer to the structure being sized.
  321. pFormat - Structure's format string description.
  322. Return :
  323. None.
  324. --*/
  325. {
  326. const NDR64_CONF_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  327. (NDR64_CONF_STRUCTURE_HEADER_FORMAT*) pFormat;
  328. const NDR64_CONF_ARRAY_HEADER_FORMAT * const pArrayFormat =
  329. (NDR64_CONF_ARRAY_HEADER_FORMAT *)pStructFormat->ArrayDescription;
  330. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  331. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  332. {
  333. // Align and add size for conformance count.
  334. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN);
  335. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE);
  336. }
  337. // Align
  338. LENGTH_ALIGN(pStubMsg->BufferLength, pStructFormat->Alignment );
  339. NDR64_WIRE_COUNT_TYPE MaxCount =
  340. Ndr64EvaluateExpr( pStubMsg,
  341. pArrayFormat->ConfDescriptor,
  342. EXPR_MAXCOUNT );
  343. pStubMsg->BufferLength += pStructFormat->MemorySize +
  344. Ndr64pConvertTo2GB(MaxCount *
  345. (NDR64_UINT64)pArrayFormat->ElementSize );
  346. if ( pStructFormat->Flags.HasPointerInfo )
  347. {
  348. Ndr64pPointerLayoutBufferSize( pStubMsg,
  349. pStructFormat + 1,
  350. (NDR64_UINT32)MaxCount,
  351. pMemory );
  352. }
  353. }
  354. void
  355. Ndr64ComplexStructBufferSize(
  356. PMIDL_STUB_MESSAGE pStubMsg,
  357. uchar * pMemory,
  358. PNDR64_FORMAT pFormat )
  359. /*++
  360. Routine Description :
  361. Computes the buffer size needed for a complex structure.
  362. Arguments :
  363. pStubMsg - Pointer to the stub message.
  364. pMemory - Pointer to the structure being sized.
  365. pFormat - Structure's format string description.
  366. Return :
  367. None.
  368. --*/
  369. {
  370. const NDR64_BOGUS_STRUCTURE_HEADER_FORMAT * pStructFormat =
  371. (NDR64_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  372. const NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT * pConfStructFormat =
  373. (NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  374. bool fSetPointerBufferMark = !pStubMsg->IgnoreEmbeddedPointers &&
  375. !pStubMsg->PointerBufferMark;
  376. if ( fSetPointerBufferMark )
  377. {
  378. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  379. ulong BufferLengthSave = pStubMsg->BufferLength;
  380. Ndr64ComplexStructBufferSize(
  381. pStubMsg,
  382. pMemory,
  383. pFormat );
  384. // complex struct may not have a zero length
  385. NDR_ASSERT( pStubMsg->BufferLength, "Flat part of struct had a zero length!" );
  386. pStubMsg->IgnoreEmbeddedPointers = FALSE;
  387. pStubMsg->PointerBufferMark = (uchar*) ULongToPtr(pStubMsg->BufferLength);
  388. pStubMsg->BufferLength = BufferLengthSave;
  389. }
  390. PFORMAT_STRING pFormatPointers = (PFORMAT_STRING) pStructFormat->PointerLayout;
  391. PFORMAT_STRING pFormatArray = NULL;
  392. PFORMAT_STRING pMemberLayout = ( *(PFORMAT_STRING)pFormat == FC64_CONF_BOGUS_STRUCT ||
  393. *(PFORMAT_STRING)pFormat == FC64_FORCED_CONF_BOGUS_STRUCT ) ?
  394. (PFORMAT_STRING)( pConfStructFormat + 1) :
  395. (PFORMAT_STRING)( pStructFormat + 1);
  396. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  397. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  398. // Get conformant array description.
  399. if ( pStructFormat->Flags.HasConfArray )
  400. {
  401. pFormatArray = (PFORMAT_STRING)pConfStructFormat->ConfArrayDescription;
  402. // accounted for by the outermost embedding complex struct
  403. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  404. {
  405. //
  406. // Align and add size of conformance count(s).
  407. //
  408. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  409. pStubMsg->BufferLength += pConfStructFormat->Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE);
  410. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  411. }
  412. }
  413. else
  414. pFormatArray = 0;
  415. LENGTH_ALIGN(pStubMsg->BufferLength, pStructFormat->Alignment);
  416. //
  417. // Shallow size the structure member by member.
  418. //
  419. for ( ; ; )
  420. {
  421. switch ( *pMemberLayout )
  422. {
  423. case FC64_STRUCT:
  424. {
  425. const NDR64_SIMPLE_REGION_FORMAT *pRegion =
  426. (NDR64_SIMPLE_REGION_FORMAT*) pMemberLayout;
  427. LENGTH_ALIGN(pStubMsg->BufferLength, pRegion->Alignment );
  428. pStubMsg->BufferLength += pRegion->RegionSize;
  429. pMemory += pRegion->RegionSize;
  430. pMemberLayout += sizeof( *pRegion );
  431. break;
  432. }
  433. case FC64_STRUCTPADN :
  434. {
  435. const NDR64_MEMPAD_FORMAT *pMemPad = (NDR64_MEMPAD_FORMAT*)pMemberLayout;
  436. pMemory += pMemPad->MemPad;
  437. pMemberLayout += sizeof(*pMemPad);
  438. break;
  439. }
  440. case FC64_POINTER :
  441. {
  442. Ndr64EmbeddedPointerBufferSize(
  443. pStubMsg,
  444. pMemory,
  445. pFormatPointers );
  446. pMemory += PTR_MEM_SIZE;
  447. pFormatPointers += sizeof(NDR64_POINTER_FORMAT);
  448. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  449. break;
  450. }
  451. //
  452. // Embedded complex types.
  453. //
  454. case FC64_EMBEDDED_COMPLEX :
  455. {
  456. const NDR64_EMBEDDED_COMPLEX_FORMAT * pEmbeddedFormat =
  457. (NDR64_EMBEDDED_COMPLEX_FORMAT*) pMemberLayout;
  458. PFORMAT_STRING pTypeFormat = (PFORMAT_STRING)pEmbeddedFormat->Type;
  459. Ndr64EmbeddedTypeSize( pStubMsg,
  460. pMemory,
  461. pTypeFormat );
  462. pMemory = Ndr64pMemoryIncrement( pStubMsg,
  463. pMemory,
  464. pTypeFormat,
  465. FALSE );
  466. pMemberLayout += sizeof( *pEmbeddedFormat );
  467. break;
  468. }
  469. case FC64_BUFFER_ALIGN:
  470. {
  471. const NDR64_BUFFER_ALIGN_FORMAT *pBufAlign =
  472. (NDR64_BUFFER_ALIGN_FORMAT*) pMemberLayout;
  473. LENGTH_ALIGN(pStubMsg->BufferLength, pBufAlign->Alignment);
  474. pMemberLayout += sizeof( *pBufAlign );
  475. break;
  476. }
  477. //
  478. // simple types
  479. //
  480. case FC64_CHAR :
  481. case FC64_WCHAR :
  482. case FC64_INT8:
  483. case FC64_UINT8:
  484. case FC64_INT16:
  485. case FC64_UINT16:
  486. case FC64_INT32:
  487. case FC64_UINT32:
  488. case FC64_INT64:
  489. case FC64_UINT64:
  490. case FC64_FLOAT32 :
  491. case FC64_FLOAT64 :
  492. case FC64_ERROR_STATUS_T:
  493. LENGTH_ALIGN( pStubMsg->BufferLength,
  494. NDR64_SIMPLE_TYPE_BUFALIGN(*pMemberLayout) );
  495. pStubMsg->BufferLength += NDR64_SIMPLE_TYPE_BUFSIZE(*pMemberLayout);
  496. pMemory += NDR64_SIMPLE_TYPE_MEMSIZE(*pMemberLayout);
  497. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  498. break;
  499. case FC64_IGNORE :
  500. LENGTH_ALIGN( pStubMsg->BufferLength, NDR64_PTR_WIRE_ALIGN );
  501. pStubMsg->BufferLength += sizeof(NDR64_PTR_WIRE_TYPE);
  502. pMemory += PTR_MEM_SIZE;
  503. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  504. break;
  505. //
  506. // Done with layout.
  507. //
  508. case FC64_END :
  509. goto ComplexStructBufferSizeEnd;
  510. default :
  511. NDR_ASSERT(0,"Ndr64ComplexStructBufferSize : bad format char");
  512. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  513. return;
  514. } // switch
  515. } // for
  516. ComplexStructBufferSizeEnd:
  517. //
  518. // Size any conformant array.
  519. //
  520. if ( pFormatArray )
  521. {
  522. Ndr64EmbeddedTypeSize( pStubMsg,
  523. pMemory,
  524. pFormatArray );
  525. }
  526. else
  527. {
  528. // If the structure doesn't have a conformant array, align it again
  529. LENGTH_ALIGN( pStubMsg->BufferLength, pStructFormat->Alignment );
  530. }
  531. if ( fSetPointerBufferMark )
  532. {
  533. pStubMsg->BufferLength = PtrToUlong(pStubMsg->PointerBufferMark);
  534. pStubMsg->PointerBufferMark = NULL;
  535. }
  536. }
  537. void
  538. Ndr64FixedArrayBufferSize(
  539. PMIDL_STUB_MESSAGE pStubMsg,
  540. uchar * pMemory,
  541. PNDR64_FORMAT pFormat )
  542. /*++
  543. Routine Description :
  544. Computes the buffer size needed for a fixed array of any number of
  545. dimensions.
  546. Used for FC64_SMFARRAY and FC64_LGFARRAY.
  547. Arguments :
  548. pStubMsg - Pointer to the stub message.
  549. pMemory - Pointer to the array being sized.
  550. pFormat - Array's format string description.
  551. Return :
  552. None.
  553. --*/
  554. {
  555. const NDR64_FIX_ARRAY_HEADER_FORMAT * pArrayFormat =
  556. (NDR64_FIX_ARRAY_HEADER_FORMAT*) pFormat;
  557. LENGTH_ALIGN(pStubMsg->BufferLength, pArrayFormat->Alignment );
  558. pStubMsg->BufferLength += pArrayFormat->TotalSize;
  559. if ( pArrayFormat->Flags.HasPointerInfo )
  560. {
  561. Ndr64pPointerLayoutBufferSize( pStubMsg,
  562. pArrayFormat + 1,
  563. 0,
  564. pMemory );
  565. }
  566. }
  567. void
  568. Ndr64ConformantArrayBufferSize(
  569. PMIDL_STUB_MESSAGE pStubMsg,
  570. uchar * pMemory,
  571. PNDR64_FORMAT pFormat )
  572. /*++
  573. Routine Description :
  574. Computes the buffer size needed for a top level one dimensional conformant
  575. array.
  576. Used for FC64_CARRAY.
  577. Arguments :
  578. pStubMsg - Pointer to the stub message.
  579. pMemory - Pointer to the array being sized.
  580. pFormat - Array's format string description.
  581. Return :
  582. None.
  583. --*/
  584. {
  585. const NDR64_CONF_ARRAY_HEADER_FORMAT *pArrayFormat =
  586. (NDR64_CONF_ARRAY_HEADER_FORMAT*) pFormat;
  587. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  588. {
  589. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN);
  590. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE);
  591. }
  592. NDR64_WIRE_COUNT_TYPE ConformanceCount =
  593. Ndr64EvaluateExpr( pStubMsg,
  594. pArrayFormat->ConfDescriptor,
  595. EXPR_MAXCOUNT );
  596. NDR64_UINT32 BufferSize = Ndr64pConvertTo2GB( (NDR64_UINT64)pArrayFormat->ElementSize *
  597. ConformanceCount );
  598. LENGTH_ALIGN(pStubMsg->BufferLength,pArrayFormat->Alignment);
  599. pStubMsg->BufferLength += BufferSize;
  600. if ( pArrayFormat->Flags.HasPointerInfo )
  601. {
  602. Ndr64pPointerLayoutBufferSize( pStubMsg,
  603. pArrayFormat + 1,
  604. (NDR64_UINT32)ConformanceCount,
  605. pMemory );
  606. }
  607. }
  608. void
  609. Ndr64ConformantVaryingArrayBufferSize(
  610. PMIDL_STUB_MESSAGE pStubMsg,
  611. uchar * pMemory,
  612. PNDR64_FORMAT pFormat )
  613. /*++
  614. Routine Description :
  615. Computes the buffer size needed for a top level one dimensional conformant
  616. varying array.
  617. Arguments :
  618. pStubMsg - Pointer to the stub message.
  619. pMemory - Pointer to the array being sized.
  620. pFormat - Array's format string description.
  621. Return :
  622. None.
  623. --*/
  624. {
  625. const NDR64_CONF_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  626. (NDR64_CONF_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  627. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  628. {
  629. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  630. pStubMsg->BufferLength += sizeof( NDR64_WIRE_COUNT_TYPE );
  631. }
  632. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  633. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  634. NDR64_WIRE_COUNT_TYPE ActualCount =
  635. Ndr64EvaluateExpr( pStubMsg,
  636. pArrayFormat->VarDescriptor,
  637. EXPR_ACTUALCOUNT );
  638. NDR64_UINT32 CopySize = Ndr64pConvertTo2GB( ActualCount *
  639. (NDR64_UINT64)pArrayFormat->ElementSize );
  640. LENGTH_ALIGN(pStubMsg->BufferLength, pArrayFormat->Alignment );
  641. pStubMsg->BufferLength += CopySize;
  642. if ( pArrayFormat->Flags.HasPointerInfo )
  643. {
  644. Ndr64pPointerLayoutBufferSize( pStubMsg,
  645. pArrayFormat + 1,
  646. (NDR64_UINT32)ActualCount,
  647. pMemory );
  648. }
  649. }
  650. void
  651. Ndr64VaryingArrayBufferSize(
  652. PMIDL_STUB_MESSAGE pStubMsg,
  653. uchar * pMemory,
  654. PNDR64_FORMAT pFormat )
  655. /*++
  656. Routine Description :
  657. Computes the buffer size needed for a top level or embedded one
  658. dimensional varying array.
  659. Arguments :
  660. pStubMsg - Pointer to the stub message.
  661. pMemory - Pointer to the array being sized.
  662. pFormat - Array's format string description.
  663. Return :
  664. None.
  665. Arguments :
  666. pMemory - pointer to the parameter to size
  667. pFormat - pointer to the format string description of the parameter
  668. --*/
  669. {
  670. const NDR64_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  671. (NDR64_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  672. //
  673. // Align and add size for offset and actual count.
  674. //
  675. LENGTH_ALIGN( pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN);
  676. pStubMsg->BufferLength += (sizeof(NDR64_WIRE_COUNT_TYPE) * 2);
  677. NDR64_WIRE_COUNT_TYPE ActualCount =
  678. Ndr64EvaluateExpr( pStubMsg,
  679. pArrayFormat->VarDescriptor,
  680. EXPR_ACTUALCOUNT );
  681. // Check if the bounds are valid
  682. NDR64_UINT32 BufferSize = Ndr64pConvertTo2GB( ActualCount *
  683. (NDR64_UINT64)pArrayFormat->ElementSize );
  684. if ( BufferSize > pArrayFormat->TotalSize )
  685. RpcRaiseException( RPC_X_INVALID_BOUND );
  686. LENGTH_ALIGN(pStubMsg->BufferLength, pArrayFormat->Alignment );
  687. pStubMsg->BufferLength += BufferSize;
  688. if ( pArrayFormat->Flags.HasPointerInfo )
  689. {
  690. Ndr64pPointerLayoutBufferSize( pStubMsg,
  691. pArrayFormat + 1,
  692. (NDR64_UINT32)ActualCount,
  693. pMemory );
  694. }
  695. }
  696. void
  697. Ndr64ComplexArrayBufferSize(
  698. PMIDL_STUB_MESSAGE pStubMsg,
  699. uchar * pMemory,
  700. PNDR64_FORMAT pFormat )
  701. /*++
  702. Routine Description :
  703. Computes the buffer size needed for a top level complex array.
  704. Used for FC64_BOGUS_STRUCT.
  705. Arguments :
  706. pStubMsg - Pointer to the stub message.
  707. pMemory - Pointer to the array being sized.
  708. pFormat - Array's format string description.
  709. Return :
  710. None.
  711. --*/
  712. {
  713. const NDR64_BOGUS_ARRAY_HEADER_FORMAT *pArrayFormat =
  714. (NDR64_BOGUS_ARRAY_HEADER_FORMAT *) pFormat;
  715. bool fSetPointerBufferMark = !pStubMsg->IgnoreEmbeddedPointers &&
  716. (! pStubMsg->PointerBufferMark );
  717. if ( fSetPointerBufferMark )
  718. {
  719. ulong BufferLengthSave = pStubMsg->BufferLength;
  720. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  721. Ndr64ComplexArrayBufferSize(
  722. pStubMsg,
  723. pMemory,
  724. pFormat );
  725. // In NDR64 the flat part of a array may not have a zero length.
  726. NDR_ASSERT( pStubMsg->BufferLength, "Flat part of array had a zero length!" );
  727. pStubMsg->PointerBufferMark = (uchar*)ULongToPtr(pStubMsg->BufferLength);
  728. pStubMsg->IgnoreEmbeddedPointers = FALSE;
  729. pStubMsg->BufferLength = BufferLengthSave;
  730. }
  731. BOOL IsFixed = ( pArrayFormat->FormatCode == FC64_FIX_BOGUS_ARRAY ) ||
  732. ( pArrayFormat->FormatCode == FC64_FIX_FORCED_BOGUS_ARRAY );
  733. PFORMAT_STRING pElementFormat = (PFORMAT_STRING) pArrayFormat->Element;
  734. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  735. NDR64_WIRE_COUNT_TYPE Elements = pArrayFormat->NumberElements;
  736. NDR64_WIRE_COUNT_TYPE Count = Elements;
  737. NDR64_WIRE_COUNT_TYPE Offset = 0;
  738. if ( !IsFixed )
  739. {
  740. const NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT* pConfVarFormat =
  741. (NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT*)pFormat;
  742. if ( pConfVarFormat->ConfDescription )
  743. {
  744. Elements = Ndr64EvaluateExpr( pStubMsg,
  745. pConfVarFormat->ConfDescription,
  746. EXPR_MAXCOUNT );
  747. Count = Elements;
  748. Offset = 0;
  749. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  750. {
  751. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN);
  752. pStubMsg->BufferLength += pArrayFormat->NumberDims *
  753. sizeof(NDR64_WIRE_COUNT_TYPE);
  754. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  755. }
  756. }
  757. if ( pConfVarFormat->VarDescription )
  758. {
  759. Count =
  760. Ndr64EvaluateExpr( pStubMsg,
  761. pConfVarFormat->VarDescription,
  762. EXPR_ACTUALCOUNT );
  763. Offset =
  764. Ndr64EvaluateExpr( pStubMsg,
  765. pConfVarFormat->OffsetDescription,
  766. EXPR_OFFSET);
  767. if ( ! NDR64_IS_VAR_MARK_VALID( pStubMsg->uFlags ) )
  768. {
  769. NDR64_UINT32 Dimensions;
  770. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  771. Dimensions = ( pArrayFormat->Flags.IsArrayofStrings ) ? ( pArrayFormat->NumberDims - 1 ) :
  772. ( pArrayFormat->NumberDims );
  773. pStubMsg->BufferLength += Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  774. if ( NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  775. NDR64_SET_VAR_MARK_VALID( pStubMsg->uFlags );
  776. }
  777. else if ( !NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  778. NDR64_RESET_VAR_MARK_VALID( pStubMsg->uFlags );
  779. }
  780. }
  781. NDR64_UINT32 ElementMemorySize =
  782. Ndr64pMemorySize( pStubMsg,
  783. pElementFormat,
  784. FALSE );
  785. pMemory += Ndr64pConvertTo2GB(Offset *
  786. (NDR64_UINT64)ElementMemorySize);
  787. Ndr64pConvertTo2GB( Elements *
  788. (NDR64_UINT64)ElementMemorySize );
  789. Ndr64pConvertTo2GB( Count *
  790. (NDR64_UINT64)ElementMemorySize );
  791. if ( (Offset + Count) > Elements )
  792. RpcRaiseException( RPC_X_INVALID_BOUND );
  793. LENGTH_ALIGN( pStubMsg->BufferLength, pArrayFormat->Alignment );
  794. for ( ; Count--; )
  795. {
  796. Ndr64EmbeddedTypeSize( pStubMsg,
  797. pMemory,
  798. pElementFormat );
  799. pMemory += ElementMemorySize;
  800. }
  801. if ( fSetPointerBufferMark )
  802. {
  803. pStubMsg->BufferLength = PtrToUlong(pStubMsg->PointerBufferMark);
  804. pStubMsg->PointerBufferMark = NULL;
  805. }
  806. }
  807. void
  808. Ndr64NonConformantStringBufferSize(
  809. PMIDL_STUB_MESSAGE pStubMsg,
  810. uchar * pMemory,
  811. PNDR64_FORMAT pFormat )
  812. /*++
  813. Routine Description :
  814. Computes the buffer size needed for a non conformant string.
  815. Arguments :
  816. pStubMsg - Pointer to the stub message.
  817. pMemory - Pointer to the array being sized.
  818. pFormat - Array's format string description.
  819. Return :
  820. None.
  821. --*/
  822. {
  823. const NDR64_NON_CONFORMANT_STRING_FORMAT * pStringFormat =
  824. (NDR64_NON_CONFORMANT_STRING_FORMAT*) pFormat;
  825. NDR64_UINT32 CopySize =
  826. Ndr64pCommonStringSize(pStubMsg,
  827. pMemory,
  828. &pStringFormat->Header);
  829. if ( CopySize > pStringFormat->TotalSize )
  830. RpcRaiseException( RPC_X_INVALID_BOUND );
  831. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  832. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  833. pStubMsg->BufferLength += CopySize;
  834. }
  835. void
  836. Ndr64ConformantStringBufferSize(
  837. PMIDL_STUB_MESSAGE pStubMsg,
  838. uchar * pMemory,
  839. PNDR64_FORMAT pFormat )
  840. /*++
  841. Routine Description :
  842. Routine for computing the buffer size needed for a conformant
  843. string.
  844. Arguments :
  845. pStubMsg - Pointer to the stub message.
  846. pMemory - Pointer to the array being sized.
  847. pFormat - Array's format string description.
  848. Return :
  849. None.
  850. --*/
  851. {
  852. const NDR64_CONFORMANT_STRING_FORMAT * pStringFormat =
  853. (NDR64_CONFORMANT_STRING_FORMAT*) pFormat;
  854. const NDR64_SIZED_CONFORMANT_STRING_FORMAT * pSizedStringFormat =
  855. (NDR64_SIZED_CONFORMANT_STRING_FORMAT*) pFormat;
  856. NDR64_UINT32 CopySize =
  857. Ndr64pCommonStringSize(pStubMsg,
  858. pMemory,
  859. &pStringFormat->Header);
  860. if ( pStringFormat->Header.Flags.IsSized )
  861. {
  862. Ndr64EvaluateExpr( pStubMsg,
  863. pSizedStringFormat->SizeDescription,
  864. EXPR_MAXCOUNT );
  865. if ( pStubMsg->ActualCount > pStubMsg->MaxCount )
  866. RpcRaiseException(RPC_X_INVALID_BOUND);
  867. }
  868. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  869. {
  870. LENGTH_ALIGN( pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN );
  871. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE);
  872. }
  873. // Align and add size for variance.
  874. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_WIRE_COUNT_ALIGN);
  875. pStubMsg->BufferLength += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  876. pStubMsg->BufferLength += CopySize;
  877. }
  878. void
  879. Ndr64UnionBufferSize(
  880. PMIDL_STUB_MESSAGE pStubMsg,
  881. uchar * pMemory,
  882. PNDR64_FORMAT pFormat )
  883. /*++
  884. Routine Description :
  885. Computes the buffer size needed for an encapsulated union.
  886. Used for FC64_ENCAPSULATED_UNION.
  887. Arguments :
  888. pStubMsg - Pointer to the stub message.
  889. pMemory - Pointer to the union being sized.
  890. pFormat - Union's format string description.
  891. Return :
  892. None.
  893. --*/
  894. {
  895. const NDR64_UNION_ARM_SELECTOR* pArmSelector;
  896. EXPR_VALUE SwitchIs;
  897. NDR64_FORMAT_CHAR SwitchType;
  898. uchar *pArmMemory;
  899. switch(*(PFORMAT_STRING)pFormat)
  900. {
  901. case FC64_NON_ENCAPSULATED_UNION:
  902. {
  903. const NDR64_NON_ENCAPSULATED_UNION* pNonEncapUnionFormat =
  904. (const NDR64_NON_ENCAPSULATED_UNION*) pFormat;
  905. LENGTH_ALIGN(pStubMsg->BufferLength, pNonEncapUnionFormat->Alignment);
  906. SwitchType = pNonEncapUnionFormat->SwitchType;
  907. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pNonEncapUnionFormat + 1);
  908. SwitchIs = Ndr64EvaluateExpr( pStubMsg,
  909. pNonEncapUnionFormat->Switch,
  910. EXPR_SWITCHIS );
  911. pArmMemory = pMemory;
  912. break;
  913. }
  914. case FC64_ENCAPSULATED_UNION:
  915. {
  916. const NDR64_ENCAPSULATED_UNION* pEncapUnionFormat =
  917. (const NDR64_ENCAPSULATED_UNION*)pFormat;
  918. LENGTH_ALIGN(pStubMsg->BufferLength, pEncapUnionFormat->Alignment);
  919. SwitchType = pEncapUnionFormat->SwitchType;
  920. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pEncapUnionFormat + 1);
  921. SwitchIs = Ndr64pSimpleTypeToExprValue(SwitchType,
  922. pMemory);
  923. pArmMemory = pMemory + pEncapUnionFormat->MemoryOffset;
  924. break;
  925. }
  926. default:
  927. NDR_ASSERT("Bad union format\n", 0);
  928. return;
  929. }
  930. //
  931. // Size the switch_is.
  932. //
  933. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_SIMPLE_TYPE_BUFALIGN(SwitchType));
  934. pStubMsg->BufferLength += NDR64_SIMPLE_TYPE_BUFSIZE(SwitchType);
  935. LENGTH_ALIGN( pStubMsg->BufferLength, pArmSelector->Alignment);
  936. PNDR64_FORMAT pArmFormat =
  937. Ndr64pFindUnionArm( pStubMsg,
  938. pArmSelector,
  939. SwitchIs );
  940. if ( ! pArmFormat )
  941. return;
  942. Ndr64EmbeddedTypeSize( pStubMsg,
  943. pArmMemory,
  944. pArmFormat );
  945. }
  946. void
  947. Ndr64XmitOrRepAsBufferSize(
  948. PMIDL_STUB_MESSAGE pStubMsg,
  949. uchar * pMemory,
  950. PNDR64_FORMAT pFormat,
  951. bool IsEmbedded )
  952. /*++
  953. Routine Description :
  954. Computes the buffer size needed for a transmit as or represent as object.
  955. See mrshl.c for the description of the FC layout.
  956. Arguments :
  957. pStubMsg - Pointer to the stub message.
  958. pMemory - Pointer to the transmit/represent as object being sized.
  959. pFormat - Object's format string description.
  960. Return :
  961. None.
  962. --*/
  963. {
  964. NDR64_TRANSMIT_AS_FORMAT *pTransFormat = ( NDR64_TRANSMIT_AS_FORMAT *) pFormat;
  965. NDR_ASSERT( pTransFormat->FormatCode == FC64_TRANSMIT_AS || pTransFormat->FormatCode , "invalid format string for user marshal" );
  966. unsigned short QIndex = pTransFormat->RoutineIndex;
  967. NDR64_UINT32 XmitTypeSize = pTransFormat->TransmittedTypeBufferSize;
  968. const XMIT_ROUTINE_QUINTUPLE * pQuintuple = pStubMsg->StubDesc->aXmitQuintuple;
  969. if ( XmitTypeSize )
  970. {
  971. LENGTH_ALIGN( pStubMsg->BufferLength, pTransFormat->TransmittedTypeWireAlignment );
  972. pStubMsg->BufferLength += XmitTypeSize;
  973. }
  974. else
  975. {
  976. // We have to create an object to size it.
  977. // First translate the presented type into the transmitted type.
  978. // This includes an allocation of a transmitted type object.
  979. pStubMsg->pPresentedType = pMemory;
  980. pStubMsg->pTransmitType = NULL;
  981. pQuintuple[ QIndex ].pfnTranslateToXmit( pStubMsg );
  982. // bufsize the transmitted type.
  983. unsigned char * pTransmittedType = pStubMsg->pTransmitType;
  984. // In NDR64, Xmit/Rep cannot be a pointer or contain a pointer.
  985. // So we don't need to worry about the pointer queue here.
  986. if ( IsEmbedded )
  987. {
  988. Ndr64EmbeddedTypeSize( pStubMsg,
  989. pTransmittedType,
  990. pTransFormat->TransmittedType );
  991. }
  992. else
  993. {
  994. Ndr64TopLevelTypeSize( pStubMsg,
  995. pTransmittedType,
  996. pTransFormat->TransmittedType );
  997. }
  998. pStubMsg->pTransmitType = pTransmittedType;
  999. // Free the temporary transmitted object (it was alloc'ed by the user).
  1000. pQuintuple[ QIndex ].pfnFreeXmit( pStubMsg );
  1001. }
  1002. }
  1003. void
  1004. Ndr64TopLevelXmitOrRepAsBufferSize(
  1005. PMIDL_STUB_MESSAGE pStubMsg,
  1006. uchar * pMemory,
  1007. PNDR64_FORMAT pFormat )
  1008. {
  1009. Ndr64XmitOrRepAsBufferSize( pStubMsg,
  1010. pMemory,
  1011. pFormat,
  1012. false );
  1013. }
  1014. void
  1015. Ndr64EmbeddedXmitOrRepAsBufferSize(
  1016. PMIDL_STUB_MESSAGE pStubMsg,
  1017. uchar * pMemory,
  1018. PNDR64_FORMAT pFormat )
  1019. {
  1020. Ndr64XmitOrRepAsBufferSize( pStubMsg,
  1021. pMemory,
  1022. pFormat,
  1023. true );
  1024. }
  1025. void
  1026. Ndr64UserMarshallBufferSizeInternal(
  1027. PMIDL_STUB_MESSAGE pStubMsg,
  1028. uchar * pMemory,
  1029. PNDR64_FORMAT pFormat )
  1030. {
  1031. NDR64_USER_MARSHAL_FORMAT *pUserFormat = ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1032. // We are here to size a flat object or a pointee object.
  1033. // Optimization: if we know the wire size, don't call the user to size it.
  1034. if ( pUserFormat->TransmittedTypeBufferSize != 0 )
  1035. {
  1036. pStubMsg->BufferLength += pUserFormat->TransmittedTypeBufferSize;
  1037. }
  1038. else
  1039. {
  1040. // Unknown wire size: Call the user to size his stuff.
  1041. USER_MARSHAL_CB UserMarshalCB;
  1042. Ndr64pInitUserMarshalCB( pStubMsg,
  1043. pUserFormat,
  1044. USER_MARSHAL_CB_BUFFER_SIZE,
  1045. & UserMarshalCB);
  1046. unsigned long UserOffset = pStubMsg->BufferLength;
  1047. unsigned short QIndex = pUserFormat->RoutineIndex;
  1048. const USER_MARSHAL_ROUTINE_QUADRUPLE * pQuadruple =
  1049. (const USER_MARSHAL_ROUTINE_QUADRUPLE *)( ( NDR_PROC_CONTEXT *)pStubMsg->pContext )->pSyntaxInfo->aUserMarshalQuadruple;
  1050. UserOffset = pQuadruple[ QIndex ].pfnBufferSize( (ulong*) &UserMarshalCB,
  1051. UserOffset,
  1052. pMemory );
  1053. pStubMsg->BufferLength = UserOffset;
  1054. }
  1055. }
  1056. void
  1057. NDR64_USR_MRSHL_BUFSIZE_POINTER_QUEUE_ELEMENT::Dispatch(MIDL_STUB_MESSAGE *pStubMsg)
  1058. {
  1059. Ndr64UserMarshallBufferSizeInternal( pStubMsg,
  1060. pMemory,
  1061. pFormat );
  1062. }
  1063. #if defined(DBG)
  1064. void
  1065. NDR64_USR_MRSHL_BUFSIZE_POINTER_QUEUE_ELEMENT::Print()
  1066. {
  1067. DbgPrint("NDR_USR_MRSHL_BUFSIZE_POINTER_QUEUE_ELEMENT\n");
  1068. DbgPrint("pMemory: %p\n", pMemory );
  1069. DbgPrint("pFormat: %p\n", pFormat );
  1070. }
  1071. #endif
  1072. void
  1073. Ndr64UserMarshallPointeeBufferSize(
  1074. PMIDL_STUB_MESSAGE pStubMsg,
  1075. uchar * pMemory,
  1076. PNDR64_FORMAT pFormat )
  1077. {
  1078. if ( pStubMsg->IgnoreEmbeddedPointers )
  1079. return;
  1080. if ( !pStubMsg->pPointerQueueState ||
  1081. !pStubMsg->pPointerQueueState->GetActiveQueue() )
  1082. {
  1083. POINTER_BUFFERLENGTH_SWAP_CONTEXT SwapContext( pStubMsg );
  1084. Ndr64UserMarshallBufferSizeInternal( pStubMsg,
  1085. pMemory,
  1086. pFormat );
  1087. return;
  1088. }
  1089. NDR64_USR_MRSHL_BUFSIZE_POINTER_QUEUE_ELEMENT*pElement =
  1090. new(pStubMsg->pPointerQueueState)
  1091. NDR64_USR_MRSHL_BUFSIZE_POINTER_QUEUE_ELEMENT(pMemory,
  1092. (PFORMAT_STRING)pFormat );
  1093. pStubMsg->pPointerQueueState->GetActiveQueue()->Enque( pElement );
  1094. }
  1095. void
  1096. Ndr64UserMarshalBufferSize(
  1097. PMIDL_STUB_MESSAGE pStubMsg,
  1098. uchar * pMemory,
  1099. PNDR64_FORMAT pFormat,
  1100. bool bIsEmbedded )
  1101. /*++
  1102. Routine Description :
  1103. Computes the buffer size needed for a usr_marshall object.
  1104. Arguments :
  1105. pStubMsg - Pointer to the stub message.
  1106. pMemory - Pointer to the usr_marshall object to buffer size.
  1107. pFormat - Object's format string description.
  1108. Return :
  1109. None.
  1110. --*/
  1111. {
  1112. NDR64_USER_MARSHAL_FORMAT *pUserFormat = ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1113. NDR_ASSERT( pUserFormat->FormatCode == FC64_USER_MARSHAL, "invalid format string for user marshal" );
  1114. // Align for the flat object or a pointer to the user object.
  1115. LENGTH_ALIGN( pStubMsg->BufferLength, pUserFormat->TransmittedTypeWireAlignment );
  1116. if ( pUserFormat->Flags & USER_MARSHAL_POINTER )
  1117. {
  1118. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE) ||
  1119. ( ( pUserFormat->Flags & USER_MARSHAL_REF) && bIsEmbedded ) )
  1120. {
  1121. LENGTH_ALIGN(pStubMsg->BufferLength, NDR64_PTR_WIRE_ALIGN );
  1122. pStubMsg->BufferLength += sizeof( NDR64_PTR_WIRE_TYPE );
  1123. }
  1124. Ndr64UserMarshallPointeeBufferSize( pStubMsg,
  1125. pMemory,
  1126. pFormat );
  1127. return;
  1128. }
  1129. Ndr64UserMarshallBufferSizeInternal( pStubMsg,
  1130. pMemory,
  1131. pFormat );
  1132. }
  1133. void
  1134. Ndr64TopLevelUserMarshalBufferSize(
  1135. PMIDL_STUB_MESSAGE pStubMsg,
  1136. uchar * pMemory,
  1137. PNDR64_FORMAT pFormat )
  1138. {
  1139. Ndr64UserMarshalBufferSize(
  1140. pStubMsg,
  1141. pMemory,
  1142. pFormat,
  1143. false );
  1144. }
  1145. void
  1146. Ndr64EmbeddedUserMarshallBufferSize(
  1147. PMIDL_STUB_MESSAGE pStubMsg,
  1148. uchar * pMemory,
  1149. PNDR64_FORMAT pFormat )
  1150. {
  1151. Ndr64UserMarshalBufferSize(
  1152. pStubMsg,
  1153. pMemory,
  1154. pFormat,
  1155. true );
  1156. }
  1157. void
  1158. Ndr64ContextHandleSize(
  1159. PMIDL_STUB_MESSAGE pStubMsg,
  1160. uchar * pMemory,
  1161. PNDR64_FORMAT pFormat )
  1162. /*++
  1163. Routine Description :
  1164. Computes the buffer size needed for a context handle.
  1165. Arguments :
  1166. pStubMsg - Pointer to the stub message.
  1167. pMemory - Ignored.
  1168. pFormat - Ignored.
  1169. Return :
  1170. None.
  1171. --*/
  1172. {
  1173. LENGTH_ALIGN(pStubMsg->BufferLength,0x3);
  1174. pStubMsg->BufferLength += CONTEXT_HANDLE_WIRE_SIZE;
  1175. }
  1176. // define the jump table
  1177. #define NDR64_BEGIN_TABLE \
  1178. PNDR64_SIZE_ROUTINE extern const Ndr64SizeRoutinesTable[] = \
  1179. {
  1180. #define NDR64_TABLE_END \
  1181. };
  1182. #define NDR64_ZERO_ENTRY NULL
  1183. #define NDR64_UNUSED_TABLE_ENTRY( number, tokenname ) ,NULL
  1184. #define NDR64_UNUSED_TABLE_ENTRY_NOSYM( number ) ,NULL
  1185. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  1186. ,buffersize
  1187. #define NDR64_SIMPLE_TYPE_TABLE_ENTRY( number, tokenname, buffersize, memorysize ) \
  1188. ,Ndr64UDTSimpleTypeSize
  1189. #include "tokntbl.h"
  1190. C_ASSERT( sizeof(Ndr64SizeRoutinesTable)/sizeof(PNDR64_SIZE_ROUTINE) == 256 );
  1191. #undef NDR64_BEGIN_TABLE
  1192. #undef NDR64_TABLE_ENTRY
  1193. #define NDR64_BEGIN_TABLE \
  1194. PNDR64_SIZE_ROUTINE extern const Ndr64EmbeddedSizeRoutinesTable[] = \
  1195. {
  1196. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  1197. ,embeddedbuffersize
  1198. #include "tokntbl.h"
  1199. C_ASSERT( sizeof(Ndr64EmbeddedSizeRoutinesTable) / sizeof(PNDR64_SIZE_ROUTINE) == 256 );