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.

2765 lines
82 KiB

  1. /**********************************************************************
  2. Copyright (c) 1993-2000 Microsoft Corporation
  3. Module Name :
  4. unmrshl.cxx
  5. Abstract :
  6. This file contains the unmarshalling 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. Ndr64UDTSimpleTypeUnmarshall1(
  16. PMIDL_STUB_MESSAGE pStubMsg,
  17. uchar ** ppMemory,
  18. PNDR64_FORMAT pFormat,
  19. bool fMustAlloc )
  20. {
  21. //
  22. // Align the buffer.
  23. //
  24. ALIGN( pStubMsg->Buffer, NDR64_SIMPLE_TYPE_BUFALIGN(*(PFORMAT_STRING)pFormat) );
  25. // Initialize the memory pointer if needed.
  26. if ( fMustAlloc )
  27. {
  28. *ppMemory = (uchar *) NdrAllocate( pStubMsg,
  29. NDR64_SIMPLE_TYPE_MEMSIZE(*(PFORMAT_STRING)pFormat) );
  30. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  31. }
  32. else if ( !*ppMemory )
  33. {
  34. // Set pointer into buffer.
  35. *ppMemory = pStubMsg->Buffer;
  36. }
  37. Ndr64SimpleTypeUnmarshall( pStubMsg,
  38. *ppMemory,
  39. *(PFORMAT_STRING)pFormat );
  40. }
  41. void
  42. Ndr64SimpleTypeUnmarshall(
  43. PMIDL_STUB_MESSAGE pStubMsg,
  44. uchar * pMemory,
  45. uchar FormatChar )
  46. /*++
  47. Routine Description :
  48. Unmarshalls a simple type.
  49. Arguments :
  50. pStubMsg - Pointer to the stub message.
  51. pMemory - Memory pointer to unmarshall into.
  52. FormatChar - Simple type format character.
  53. Return :
  54. None.
  55. --*/
  56. {
  57. switch ( FormatChar )
  58. {
  59. case FC64_CHAR :
  60. case FC64_UINT8 :
  61. case FC64_INT8 :
  62. *pMemory = *(pStubMsg->Buffer)++;
  63. break;
  64. case FC64_WCHAR :
  65. case FC64_UINT16 :
  66. case FC64_INT16 :
  67. ALIGN(pStubMsg->Buffer,1);
  68. *((NDR64_UINT16 *)pMemory) = *((NDR64_UINT16 *)pStubMsg->Buffer);
  69. pStubMsg->Buffer += sizeof(NDR64_UINT16);
  70. break;
  71. case FC64_INT32 :
  72. case FC64_UINT32 :
  73. case FC64_FLOAT32 :
  74. case FC64_ERROR_STATUS_T:
  75. ALIGN(pStubMsg->Buffer,3);
  76. *((NDR64_UINT32 *)pMemory) = *((NDR64_UINT32 *)pStubMsg->Buffer);
  77. pStubMsg->Buffer += sizeof(NDR64_UINT32);
  78. break;
  79. case FC64_UINT64 :
  80. case FC64_INT64 :
  81. case FC64_FLOAT64 :
  82. ALIGN(pStubMsg->Buffer,7);
  83. *((NDR64_UINT64 *)pMemory) = *((NDR64_UINT64 *)pStubMsg->Buffer);
  84. pStubMsg->Buffer += sizeof(NDR64_UINT64);
  85. break;
  86. case FC64_IGNORE :
  87. break;
  88. default :
  89. NDR_ASSERT(0,"Ndr64SimpleTypeUnmarshall : bad format char");
  90. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  91. return;
  92. }
  93. }
  94. void
  95. Ndr64RangeUnmarshall(
  96. PMIDL_STUB_MESSAGE pStubMsg,
  97. uchar ** ppMemory,
  98. PNDR64_FORMAT pFormat,
  99. bool fMustAlloc )
  100. /*++
  101. Unmarshals a range FC64_RANGE descriptor.
  102. --*/
  103. {
  104. const NDR64_RANGE_FORMAT * pRangeFormat =
  105. (const NDR64_RANGE_FORMAT*)pFormat;
  106. Ndr64UDTSimpleTypeUnmarshall1( pStubMsg,
  107. ppMemory,
  108. (PNDR64_FORMAT)&pRangeFormat->RangeType,
  109. fMustAlloc );
  110. EXPR_VALUE Value = Ndr64pSimpleTypeToExprValue( pRangeFormat->RangeType, *ppMemory );
  111. if ( Value < (EXPR_VALUE)pRangeFormat->MinValue ||
  112. Value > (EXPR_VALUE)pRangeFormat->MaxValue )
  113. RpcRaiseException( RPC_X_INVALID_BOUND );
  114. }
  115. IUnknown *
  116. Ndr64pInterfacePointerUnmarshall (
  117. PMIDL_STUB_MESSAGE pStubMsg,
  118. PNDR64_FORMAT pFormat)
  119. /*++
  120. Routine Description :
  121. Unmarshalls an interface pointer.
  122. Arguments :
  123. pStubMsg - Pointer to the stub message.
  124. pFormat - Interface pointer's format string description.
  125. Return :
  126. None.
  127. Notes : Here is the data representation.
  128. // wire representation of a marshalled interface pointer
  129. typedef struct tagMInterfacePointer
  130. {
  131. ULONG ulCntData; // size of data
  132. [size_is(ulCntData)] BYTE abData[]; // data (OBJREF)
  133. } MInterfacePointer;
  134. --*/
  135. {
  136. const NDR64_CONSTANT_IID_FORMAT *pConstInterfaceFormat =
  137. (NDR64_CONSTANT_IID_FORMAT*)pFormat;
  138. const NDR64_IID_FORMAT *pInterfaceFormat =
  139. (NDR64_IID_FORMAT*)pFormat;
  140. // Unmarshal the conformant size and the count field.
  141. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  142. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, (sizeof(NDR64_WIRE_COUNT_TYPE)+sizeof(ulong)) );
  143. NDR64_UINT32 MaxCount = Ndr64pConvertTo2GB( *(NDR64_WIRE_COUNT_TYPE *) pStubMsg->Buffer );
  144. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  145. ulong ulCntData = *(ulong *) pStubMsg->Buffer;
  146. pStubMsg->Buffer += sizeof(ulong);
  147. if ( MaxCount != ulCntData )
  148. {
  149. RpcRaiseException( RPC_X_BAD_STUB_DATA );
  150. return NULL;
  151. }
  152. if ( !MaxCount )
  153. {
  154. return NULL;
  155. }
  156. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, MaxCount );
  157. // Get a pointer to the IID hidden in the interface pointer
  158. // representation in the buffer with Rick's IRpcHelper.
  159. //
  160. IID *piidValue;
  161. NdrpGetIIDFromBuffer( pStubMsg, & piidValue );
  162. //
  163. // Validate the IID.
  164. //
  165. if ( ((NDR64_IID_FLAGS*)&pConstInterfaceFormat->Flags)->ConstantIID )
  166. {
  167. if ( memcmp( &pConstInterfaceFormat->Guid,
  168. piidValue,
  169. sizeof(GUID)) != 0)
  170. {
  171. RpcRaiseException( RPC_X_BAD_STUB_DATA );
  172. return NULL;
  173. }
  174. }
  175. else
  176. {
  177. Ndr64pCheckCorrelation(pStubMsg,
  178. (EXPR_VALUE)piidValue,
  179. pInterfaceFormat->IIDDescriptor,
  180. EXPR_IID
  181. );
  182. }
  183. IStream *pStream = (*NdrpCreateStreamOnMemory)(pStubMsg->Buffer, MaxCount);
  184. if(pStream == 0)
  185. {
  186. RpcRaiseException(RPC_S_OUT_OF_MEMORY);
  187. return NULL;
  188. }
  189. IUnknown * punk = NULL;
  190. HRESULT hr = (*pfnCoUnmarshalInterface)(pStream, IID_NULL, (void**)&punk );
  191. pStream->Release();
  192. if(FAILED(hr))
  193. {
  194. RpcRaiseException(hr);
  195. return NULL;
  196. }
  197. pStubMsg->Buffer += MaxCount;
  198. return punk;
  199. }
  200. class FINDONTFREE_CONTEXT
  201. {
  202. PMIDL_STUB_MESSAGE const pStubMsg;
  203. const int fInDontFreeSave;
  204. public:
  205. __forceinline FINDONTFREE_CONTEXT( PMIDL_STUB_MESSAGE pStubMsg ) :
  206. pStubMsg( pStubMsg ),
  207. fInDontFreeSave(pStubMsg->fInDontFree)
  208. {}
  209. __forceinline FINDONTFREE_CONTEXT( PMIDL_STUB_MESSAGE pStubMsg,
  210. int fInDontFree ) :
  211. pStubMsg( pStubMsg ),
  212. fInDontFreeSave(pStubMsg->fInDontFree)
  213. {
  214. pStubMsg->fInDontFree = fInDontFree;
  215. }
  216. __forceinline ~FINDONTFREE_CONTEXT()
  217. {
  218. pStubMsg->fInDontFree = fInDontFreeSave;
  219. }
  220. };
  221. void
  222. Ndr64pFreeOlePointer(
  223. PMIDL_STUB_MESSAGE pStubMsg,
  224. uchar * pMemory,
  225. PNDR64_FORMAT pFormat )
  226. {
  227. NDR_POINTER_QUEUE *pOldQueue = NULL;
  228. if ( pStubMsg->pPointerQueueState )
  229. {
  230. pOldQueue = pStubMsg->pPointerQueueState->GetActiveQueue();
  231. pStubMsg->pPointerQueueState->SetActiveQueue(pOldQueue);
  232. }
  233. RpcTryFinally
  234. {
  235. Ndr64PointerFree( pStubMsg,
  236. pMemory,
  237. pFormat );
  238. }
  239. RpcFinally
  240. {
  241. if ( pStubMsg->pPointerQueueState )
  242. {
  243. pStubMsg->pPointerQueueState->SetActiveQueue( pOldQueue );
  244. }
  245. }
  246. RpcEndFinally
  247. }
  248. NDR_ALLOC_ALL_NODES_CONTEXT *
  249. Ndr64pGetAllocateAllNodesContext(
  250. PMIDL_STUB_MESSAGE pStubMsg,
  251. PNDR64_FORMAT pFormat )
  252. {
  253. uchar *pBuffer = pStubMsg->Buffer;
  254. // Clear memory size before calling mem size routine.
  255. pStubMsg->MemorySize = 0;
  256. //
  257. // Get the allocate all nodes memory size.
  258. //
  259. {
  260. NDR_POINTER_QUEUE *pOldQueue = NULL;
  261. if (pStubMsg->pPointerQueueState)
  262. {
  263. pOldQueue = pStubMsg->pPointerQueueState->GetActiveQueue();
  264. pStubMsg->pPointerQueueState->SetActiveQueue(NULL);
  265. }
  266. RpcTryFinally
  267. {
  268. Ndr64TopLevelTypeMemorySize( pStubMsg,
  269. pFormat );
  270. }
  271. RpcFinally
  272. {
  273. if ( pStubMsg->pPointerQueueState )
  274. {
  275. pStubMsg->pPointerQueueState->SetActiveQueue( pOldQueue );
  276. }
  277. }
  278. RpcEndFinally
  279. }
  280. ulong AllocSize = pStubMsg->MemorySize;
  281. pStubMsg->MemorySize = 0;
  282. LENGTH_ALIGN( AllocSize, __alignof(NDR_ALLOC_ALL_NODES_CONTEXT) - 1);
  283. uchar *pAllocMemory =
  284. (uchar*)NdrAllocate( pStubMsg, AllocSize + sizeof(NDR_ALLOC_ALL_NODES_CONTEXT) );
  285. NDR_ALLOC_ALL_NODES_CONTEXT *pAllocContext =
  286. (NDR_ALLOC_ALL_NODES_CONTEXT*)(pAllocMemory + AllocSize);
  287. pAllocContext->AllocAllNodesMemory = pAllocMemory;
  288. pAllocContext->AllocAllNodesMemoryBegin = pAllocMemory;
  289. pAllocContext->AllocAllNodesMemoryEnd = (uchar*)pAllocContext;
  290. pStubMsg->Buffer = pBuffer;
  291. return pAllocContext;
  292. }
  293. __forceinline void
  294. Ndr64pPointerUnmarshallInternal(
  295. PMIDL_STUB_MESSAGE pStubMsg,
  296. NDR64_PTR_WIRE_TYPE WirePtr,
  297. uchar ** ppMemory,
  298. uchar * pMemory,
  299. PNDR64_FORMAT pFormat )
  300. /*++
  301. Routine Description :
  302. Private routine for unmarshalling a pointer to anything. This is the
  303. entry point for pointers embedded in structures, arrays, and unions.
  304. Used for FC64_RP, FC64_UP, FC64_FP, FC64_OP.
  305. Arguments :
  306. pStubMsg - Pointer to the stub message.
  307. ppBufferPointer - Address of the location in the buffer which holds the
  308. incomming pointer's value and will hold the final
  309. unmarshalled pointer's value.
  310. pMemory - Current memory pointer's value which we want to
  311. unmarshall into. If this value is valid the it will
  312. be copied to *ppBufferPointer and this is where stuff
  313. will get unmarshalled into.
  314. pFormat - Pointer's format string description.
  315. pStubMsg->Buffer - set to the pointee.
  316. Return :
  317. None.
  318. --*/
  319. {
  320. const NDR64_POINTER_FORMAT *pPointerFormat = (NDR64_POINTER_FORMAT*) pFormat;
  321. bool fPointeeAlloc;
  322. bool fNewAllocAllNodes = false;
  323. // make sure we are not out out of bound. We need this check for embedded pointers / pointer
  324. // to pointer cases.
  325. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer );
  326. SAVE_CONTEXT<ulong> FullPtrRefIdSave( pStubMsg->FullPtrRefId );
  327. FINDONTFREE_CONTEXT fInDontFreeSave( pStubMsg );
  328. if ( NDR64_IS_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags) )
  329. {
  330. pMemory = 0;
  331. }
  332. //
  333. // Check the pointer type.
  334. //
  335. switch ( *(PFORMAT_STRING)pFormat )
  336. {
  337. case FC64_RP :
  338. break;
  339. case FC64_OP :
  340. //
  341. // Burn some instructions for OLE unique pointer support.
  342. //
  343. if ( pStubMsg->IsClient )
  344. {
  345. //
  346. // It's ok if this is an [out] unique pointer. It will get
  347. // zeroed before this routine is called and Ndr64PointerFree
  348. // will simply return.
  349. //
  350. Ndr64pFreeOlePointer(
  351. pStubMsg,
  352. pMemory,
  353. pFormat );
  354. // Set the current memory pointer to 0 so that we'll alloc.
  355. pMemory = 0;
  356. }
  357. // Fall through.
  358. case FC64_UP :
  359. //
  360. // Check for a null incomming pointer. Routines which call this
  361. // routine insure that the memory pointer gets nulled.
  362. //
  363. if ( ! WirePtr )
  364. {
  365. *ppMemory = NULL;
  366. return;
  367. }
  368. break;
  369. case FC64_IP:
  370. if ( pStubMsg->IsClient )
  371. {
  372. Ndr64PointerFree( pStubMsg,
  373. pMemory,
  374. pFormat );
  375. pMemory = 0;
  376. }
  377. if ( ! WirePtr )
  378. {
  379. *ppMemory = NULL;
  380. return;
  381. }
  382. *(IUnknown **)ppMemory = (IUnknown*)
  383. Ndr64pInterfacePointerUnmarshall( pStubMsg,
  384. pPointerFormat->Pointee
  385. );
  386. return;
  387. case FC64_FP :
  388. {
  389. //
  390. // We have to remember the incomming ref id because we overwrite
  391. // it during the QueryRefId call.
  392. //
  393. ulong FullPtrRefId =
  394. Ndr64pWirePtrToRefId( WirePtr );
  395. if ( !FullPtrRefId )
  396. {
  397. *ppMemory = NULL;
  398. return;
  399. }
  400. //
  401. // Lookup the ref id.
  402. //
  403. if ( Ndr64pFullPointerQueryRefId( pStubMsg,
  404. FullPtrRefId,
  405. FULL_POINTER_UNMARSHALLED,
  406. (void**)ppMemory ) )
  407. {
  408. return;
  409. }
  410. //
  411. // If our query returned false then check if the returned pointer
  412. // is 0. If so then we have to scribble away the ref id in the
  413. // stub message FullPtrRefId field so that we can insert the
  414. // pointer translation later, after we've allocated the pointer.
  415. // If the returned pointer was non-null then we leave the stub
  416. // message FullPtrRefId field alone so that we don't try to
  417. // re-insert the pointer to ref id translation later.
  418. //
  419. // We also copy the returned pointer value into pMemory. This
  420. // will allow our allocation decision to be made correctly.
  421. //
  422. if ( ! ( pMemory = *ppMemory ) )
  423. {
  424. //
  425. // Put the unmarshalled ref id into the stub message to
  426. // be used later in a call to Ndr64FullPointerInsertRefId.
  427. //
  428. pStubMsg->FullPtrRefId = FullPtrRefId;
  429. }
  430. }
  431. break;
  432. default :
  433. NDR_ASSERT(0,"Ndr64pPointerUnmarshall : bad pointer type");
  434. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  435. return;
  436. }
  437. //
  438. // Make the initial "must allocate" decision.
  439. //
  440. // The fPointeeAlloc flag is set on the client side if the current memory
  441. // pointer is null, and on the server side it is set if the current memory
  442. // pointer has the allocate don't free attribute applied to it.
  443. //
  444. // On the client side we also set the pointer's value in the buffer equal
  445. // to the current memory pointer.
  446. //
  447. // On the server side we explicitly null out the pointer's value in the
  448. // buffer as long as it's not allocated on the stack, otherwise we set it
  449. // equal to the current memory pointer (stack allocated).
  450. //
  451. if ( pStubMsg->IsClient )
  452. {
  453. *ppMemory = pMemory;
  454. fPointeeAlloc = ! pMemory;
  455. }
  456. else
  457. {
  458. if ( ! NDR64_ALLOCED_ON_STACK( pPointerFormat->Flags ) )
  459. *ppMemory = 0;
  460. else
  461. *ppMemory = pMemory;
  462. //
  463. // If this is a don't free pointer or a parent pointer of this pointer
  464. // was a don't free pointer then we set the alloc flag.
  465. //
  466. if ( fPointeeAlloc = (NDR64_DONT_FREE( pPointerFormat->Flags ) ||
  467. pStubMsg->fInDontFree ||
  468. pStubMsg->ReuseBuffer ) )
  469. {
  470. pStubMsg->fInDontFree = TRUE;
  471. }
  472. //
  473. // We also set the alloc flag for object interface pointers.
  474. //
  475. if ( *(PFORMAT_STRING)pFormat == FC64_OP )
  476. fPointeeAlloc = true;
  477. }
  478. //
  479. // Check if this is an allocate all nodes pointer AND that we're
  480. // not already in an allocate all nodes context.
  481. //
  482. if ( NDR64_ALLOCATE_ALL_NODES( pPointerFormat->Flags ) && ! pStubMsg->pAllocAllNodesContext )
  483. {
  484. fNewAllocAllNodes = true;
  485. pStubMsg->pAllocAllNodesContext =
  486. Ndr64pGetAllocateAllNodesContext(
  487. pStubMsg,
  488. pPointerFormat->Pointee );
  489. *ppMemory = 0;
  490. fPointeeAlloc = true;
  491. }
  492. if ( NDR64_POINTER_DEREF( pPointerFormat->Flags ) )
  493. {
  494. //
  495. // Re-align the buffer. This is to cover embedded pointer to
  496. // pointers.
  497. //
  498. ALIGN(pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN );
  499. //
  500. // We can't re-use the buffer for a pointer to a pointer
  501. // because we can't null out the pointee before we've unmarshalled
  502. // it. We need the stubs to alloc pointers to pointers on the
  503. // stack.
  504. //
  505. if ( ! *ppMemory && ! pStubMsg->IsClient )
  506. fPointeeAlloc = true;
  507. if ( fPointeeAlloc )
  508. {
  509. *ppMemory = (uchar*)NdrAllocate( pStubMsg, PTR_MEM_SIZE );
  510. *((void **)*ppMemory) = 0;
  511. }
  512. if ( pStubMsg->FullPtrRefId )
  513. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  514. ppMemory = (uchar **) *ppMemory;
  515. }
  516. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  517. NDR64_RESET_EMBEDDED_FLAGS_TO_STANDALONE(pStubMsg->uFlags);
  518. if ( fPointeeAlloc )
  519. NDR64_SET_SKIP_REF_CHECK( pStubMsg->uFlags );
  520. PNDR64_FORMAT pPointee = pPointerFormat->Pointee;
  521. if ( NDR64_IS_SIMPLE_TYPE( *(PFORMAT_STRING)pPointee) )
  522. {
  523. ALIGN(pStubMsg->Buffer,NDR64_SIMPLE_TYPE_BUFALIGN(*(PFORMAT_STRING)pPointee) );
  524. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer +
  525. NDR64_SIMPLE_TYPE_BUFSIZE( *(PFORMAT_STRING)pPointee ) );
  526. }
  527. // we don't need to check for buffer over run here. For non simple types,
  528. // unmarshal routines have checks available; for pointer to pointer, we have
  529. // the check at the beginning of this routine; and for pointer to simple types,
  530. // we'll unmarshal in place, but that's in current pStubMsg->Buffer, which is
  531. // covered by the above check too.
  532. Ndr64TopLevelTypeUnmarshall(
  533. pStubMsg,
  534. ppMemory,
  535. pPointerFormat->Pointee,
  536. fPointeeAlloc );
  537. // Insert full pointer to ref id translation if needed.
  538. if ( pStubMsg->FullPtrRefId )
  539. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  540. //
  541. // Reset the memory allocator and allocate all nodes flag if this was
  542. // an allocate all nodes case.
  543. //
  544. if ( fNewAllocAllNodes )
  545. {
  546. pStubMsg->pAllocAllNodesContext = 0;
  547. }
  548. }
  549. NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT::NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT(
  550. MIDL_STUB_MESSAGE *pStubMsg,
  551. uchar ** ppMemoryNew,
  552. uchar * pMemoryNew,
  553. NDR64_PTR_WIRE_TYPE WirePtrNew,
  554. PFORMAT_STRING pFormatNew ) :
  555. WirePtr(WirePtrNew),
  556. ppMemory(ppMemoryNew),
  557. pMemory(pMemoryNew),
  558. pFormat(pFormatNew),
  559. pCorrMemory(pStubMsg->pCorrMemory),
  560. pAllocAllNodesContext(pStubMsg->pAllocAllNodesContext),
  561. fInDontFree(pStubMsg->fInDontFree),
  562. uFlags(pStubMsg->uFlags)
  563. {
  564. }
  565. void NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT::Dispatch( PMIDL_STUB_MESSAGE pStubMsg )
  566. {
  567. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pCorrMemory );
  568. SAVE_CONTEXT<NDR_ALLOC_ALL_NODES_CONTEXT*>
  569. AllocNodesSave(pStubMsg->pAllocAllNodesContext,pAllocAllNodesContext );
  570. FINDONTFREE_CONTEXT fInDoneFreeSave( pStubMsg, fInDontFree );
  571. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags, uFlags );
  572. Ndr64pPointerUnmarshallInternal(
  573. pStubMsg,
  574. WirePtr,
  575. ppMemory,
  576. pMemory,
  577. pFormat );
  578. }
  579. #if defined(DBG)
  580. void NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT::Print()
  581. {
  582. DbgPrint("NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT:\n");
  583. DbgPrint("pNext: %p\n", pNext );
  584. DbgPrint("WirePtr: %I64u\n", WirePtr );
  585. DbgPrint("ppMemory: %p\n", ppMemory );
  586. DbgPrint("pMemory: %p\n", pMemory );
  587. DbgPrint("pFormat: %p\n", pFormat );
  588. DbgPrint("pCorrMemory: %p\n", pCorrMemory );
  589. DbgPrint("pAllocAllNodesContext: %p\n", pAllocAllNodesContext );
  590. DbgPrint("fInDontFree: %u\n", fInDontFree );
  591. DbgPrint("uFlags: %u\n", uFlags );
  592. }
  593. #endif
  594. void
  595. Ndr64pEnquePointerUnmarshall(
  596. PMIDL_STUB_MESSAGE pStubMsg,
  597. NDR64_PTR_WIRE_TYPE WirePtr,
  598. uchar ** ppMemory,
  599. uchar * pMemory,
  600. PNDR64_FORMAT pFormat )
  601. {
  602. NDR64_POINTER_CONTEXT PointerContext( pStubMsg );
  603. RpcTryFinally
  604. {
  605. NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT*pElement =
  606. new(pStubMsg->pPointerQueueState)
  607. NDR64_UNMRSHL_POINTER_QUEUE_ELEMENT(pStubMsg,
  608. ppMemory,
  609. pMemory,
  610. WirePtr,
  611. (PFORMAT_STRING)pFormat );
  612. PointerContext.Enque( pElement );
  613. PointerContext.DispatchIfRequired();
  614. }
  615. RpcFinally
  616. {
  617. PointerContext.EndContext();
  618. }
  619. RpcEndFinally
  620. }
  621. void
  622. Ndr64pPointerUnmarshall(
  623. PMIDL_STUB_MESSAGE pStubMsg,
  624. NDR64_PTR_WIRE_TYPE WirePtr,
  625. uchar ** ppMemory,
  626. uchar * pMemory,
  627. PNDR64_FORMAT pFormat )
  628. {
  629. if ( !NdrIsLowStack( pStubMsg ) )
  630. {
  631. Ndr64pPointerUnmarshallInternal(
  632. pStubMsg,
  633. WirePtr,
  634. ppMemory,
  635. pMemory,
  636. pFormat );
  637. return;
  638. }
  639. Ndr64pEnquePointerUnmarshall(
  640. pStubMsg,
  641. WirePtr,
  642. ppMemory,
  643. pMemory,
  644. pFormat );
  645. }
  646. __forceinline void
  647. Ndr64EmbeddedPointerUnmarshall(
  648. PMIDL_STUB_MESSAGE pStubMsg,
  649. uchar ** ppMemory,
  650. PNDR64_FORMAT pFormat,
  651. bool /*fSkipRefCheck*/ )
  652. {
  653. ALIGN( pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN );
  654. NDR64_PTR_WIRE_TYPE WirePtr = *(NDR64_PTR_WIRE_TYPE*) pStubMsg->Buffer;
  655. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  656. POINTER_BUFFER_SWAP_CONTEXT SwapContext(pStubMsg);
  657. Ndr64pPointerUnmarshall( pStubMsg,
  658. WirePtr,
  659. *(uchar***)ppMemory,
  660. **(uchar***)ppMemory,
  661. pFormat );
  662. }
  663. __forceinline void
  664. Ndr64TopLevelPointerUnmarshall(
  665. PMIDL_STUB_MESSAGE pStubMsg,
  666. uchar ** ppMemory,
  667. PNDR64_FORMAT pFormat,
  668. bool /* fSkipRefCheck */)
  669. {
  670. if ( *(PFORMAT_STRING)pFormat != FC64_RP )
  671. {
  672. ALIGN( pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN );
  673. NDR64_PTR_WIRE_TYPE WirePtr = *(NDR64_PTR_WIRE_TYPE*) pStubMsg->Buffer;
  674. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  675. Ndr64pPointerUnmarshall( pStubMsg,
  676. WirePtr,
  677. ppMemory,
  678. *ppMemory,
  679. pFormat );
  680. return;
  681. }
  682. //
  683. // If we're on the client unmarshalling a top level [out] ref pointer,
  684. // we have to make sure that it is non-null.
  685. if ( pStubMsg->IsClient &&
  686. !NDR64_IS_SKIP_REF_CHECK( pStubMsg->uFlags ) &&
  687. ! *ppMemory )
  688. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  689. Ndr64pPointerUnmarshall( pStubMsg,
  690. 0,
  691. ppMemory,
  692. *ppMemory,
  693. pFormat );
  694. }
  695. void
  696. Ndr64SimpleStructUnmarshall(
  697. PMIDL_STUB_MESSAGE pStubMsg,
  698. uchar ** ppMemory,
  699. PNDR64_FORMAT pFormat,
  700. bool fMustAlloc )
  701. /*++
  702. Routine description :
  703. Unmarshalls a simple structure.
  704. Arguments :
  705. pStubMsg - Pointer to the stub message.
  706. ppMemory - Double pointer to the structure being unmarshalled.
  707. pFormat - Structure's format string description.
  708. fMustAlloc - TRUE if the structure must be allocate, FALSE otherwise.
  709. --*/
  710. {
  711. const NDR64_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  712. (NDR64_STRUCTURE_HEADER_FORMAT*) pFormat;
  713. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  714. // Align the buffer.
  715. ALIGN(pStubMsg->Buffer, pStructFormat->Alignment);
  716. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, pStructFormat->MemorySize );
  717. uchar *pBufferSave = pStubMsg->Buffer;
  718. pStubMsg->Buffer += pStructFormat->MemorySize;
  719. if ( fMustAlloc )
  720. {
  721. *ppMemory = (uchar *) NdrAllocate( pStubMsg, pStructFormat->MemorySize );
  722. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  723. }
  724. else if ( !*ppMemory )
  725. {
  726. *ppMemory = pBufferSave;
  727. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  728. }
  729. if ( pStructFormat->Flags.HasPointerInfo )
  730. {
  731. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pBufferSave );
  732. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  733. pStructFormat + 1,
  734. 0,
  735. *ppMemory,
  736. pBufferSave );
  737. }
  738. // Copy the struct if we're not using the rpc buffer.
  739. if ( *ppMemory != pBufferSave )
  740. {
  741. RpcpMemoryCopy( *ppMemory,
  742. pBufferSave,
  743. pStructFormat->MemorySize );
  744. }
  745. }
  746. void
  747. Ndr64ConformantStructUnmarshall(
  748. PMIDL_STUB_MESSAGE pStubMsg,
  749. uchar ** ppMemory,
  750. PNDR64_FORMAT pFormat,
  751. bool fMustAlloc )
  752. /*++
  753. Routine description :
  754. Unmarshalls a conformant structure.
  755. Arguments :
  756. pStubMsg - Pointer to the stub message.
  757. ppMemory - Double pointer to where the structure should be unmarshalled.
  758. pFormat - Structure's format string description.
  759. fMustAlloc - TRUE if the structure must be allocate, FALSE otherwise.
  760. Return :
  761. None.
  762. --*/
  763. {
  764. const NDR64_CONF_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  765. (NDR64_CONF_STRUCTURE_HEADER_FORMAT*) pFormat;
  766. const NDR64_CONF_ARRAY_HEADER_FORMAT * const pArrayFormat =
  767. (NDR64_CONF_ARRAY_HEADER_FORMAT *) pStructFormat->ArrayDescription;
  768. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags );
  769. NDR64_WIRE_COUNT_TYPE MaxCount;
  770. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  771. {
  772. // Align the buffer for unmarshalling the conformance count.
  773. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  774. MaxCount = *((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer);
  775. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  776. }
  777. else
  778. MaxCount = *((NDR64_WIRE_COUNT_TYPE *)pStubMsg->ConformanceMark);
  779. // Re-align the buffer
  780. ALIGN(pStubMsg->Buffer, pStructFormat->Alignment );
  781. uchar *pBufferStart = pStubMsg->Buffer;
  782. CHECK_EOB_RAISE_IB( pBufferStart + pStructFormat->MemorySize );
  783. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pBufferStart );
  784. Ndr64pCheckCorrelation( pStubMsg,
  785. MaxCount,
  786. pArrayFormat->ConfDescriptor,
  787. EXPR_MAXCOUNT );
  788. NDR64_UINT32 StructSize = Ndr64pConvertTo2GB( (NDR64_UINT64)pStructFormat->MemorySize +
  789. ( MaxCount * (NDR64_UINT64)pArrayFormat->ElementSize ) );
  790. CHECK_EOB_WITH_WRAP_RAISE_IB( pBufferStart, StructSize );
  791. pStubMsg->Buffer += StructSize;
  792. if ( fMustAlloc )
  793. {
  794. *ppMemory = (uchar *) NdrAllocate( pStubMsg, StructSize );
  795. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  796. }
  797. else if ( !*ppMemory )
  798. {
  799. *ppMemory = pBufferStart;
  800. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  801. }
  802. if ( pStructFormat->Flags.HasPointerInfo )
  803. {
  804. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  805. pStructFormat + 1,
  806. (NDR64_UINT32)MaxCount,
  807. *ppMemory,
  808. pBufferStart );
  809. }
  810. if ( *ppMemory != pBufferStart )
  811. {
  812. RpcpMemoryCopy( *ppMemory,
  813. pBufferStart,
  814. StructSize );
  815. }
  816. }
  817. void
  818. Ndr64ComplexStructUnmarshall(
  819. PMIDL_STUB_MESSAGE pStubMsg,
  820. uchar ** ppMemory,
  821. PNDR64_FORMAT pFormat,
  822. bool fMustAlloc )
  823. /*++
  824. Routine description :
  825. Unmarshalls a complex structure.
  826. Arguments :
  827. pStubMsg - Pointer to the stub message.
  828. ppMemory - Double pointer to where the structure should be unmarshalled.
  829. pFormat - Structure's format string description.
  830. fMustAlloc - Ignored.
  831. Return :
  832. None.
  833. --*/
  834. {
  835. const NDR64_BOGUS_STRUCTURE_HEADER_FORMAT * pStructFormat =
  836. (NDR64_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  837. const NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT * pConfStructFormat =
  838. (NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  839. bool fSetPointerBufferMark = !pStubMsg->PointerBufferMark;
  840. if ( fSetPointerBufferMark )
  841. {
  842. uchar *pBufferSave = pStubMsg->Buffer;
  843. BOOL fOldIgnore = pStubMsg->IgnoreEmbeddedPointers;
  844. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  845. pStubMsg->MemorySize = 0;
  846. Ndr64ComplexStructMemorySize(
  847. pStubMsg,
  848. pFormat );
  849. // check buffer overrun for flat part of the struct.
  850. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer );
  851. pStubMsg->PointerBufferMark = pStubMsg->Buffer;
  852. pStubMsg->IgnoreEmbeddedPointers = fOldIgnore;
  853. pStubMsg->Buffer = pBufferSave;
  854. }
  855. uchar * pMemory;
  856. PFORMAT_STRING pFormatPointers = (PFORMAT_STRING)pStructFormat->PointerLayout;
  857. PFORMAT_STRING pFormatArray = NULL;
  858. bool fIsFullBogus = ( *(PFORMAT_STRING)pFormat == FC64_BOGUS_STRUCT ||
  859. *(PFORMAT_STRING)pFormat == FC64_CONF_BOGUS_STRUCT );
  860. PFORMAT_STRING pMemberLayout = ( *(PFORMAT_STRING)pFormat == FC64_CONF_BOGUS_STRUCT ||
  861. *(PFORMAT_STRING)pFormat == FC64_FORCED_CONF_BOGUS_STRUCT ) ?
  862. (PFORMAT_STRING)( pConfStructFormat + 1) :
  863. (PFORMAT_STRING)( pStructFormat + 1);
  864. SAVE_CONTEXT<uchar*> ConformanceMarkSave( pStubMsg->ConformanceMark );
  865. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  866. // Get conformant array description.
  867. if ( pStructFormat->Flags.HasConfArray )
  868. {
  869. pFormatArray = (PFORMAT_STRING)pConfStructFormat->ConfArrayDescription;
  870. }
  871. //
  872. // Now check if there is a conformant array and mark where the conformance
  873. // will be unmarshalled from.
  874. //
  875. if ( pFormatArray && !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  876. {
  877. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  878. pStubMsg->ConformanceMark = pStubMsg->Buffer;
  879. //
  880. // Increment the buffer pointer for every dimension in the
  881. // conformant array.
  882. //
  883. pStubMsg->Buffer += pConfStructFormat->Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE);
  884. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  885. }
  886. // Align the buffer on the struct's alignment.
  887. ALIGN( pStubMsg->Buffer, pStructFormat->Alignment );
  888. bool fMustCopy;
  889. if ( fMustAlloc || ( fIsFullBogus && ! *ppMemory ) )
  890. {
  891. NDR64_UINT32 StructSize =
  892. Ndr64pMemorySize( pStubMsg,
  893. pFormat,
  894. TRUE );
  895. *ppMemory = (uchar*)NdrAllocate( pStubMsg, StructSize );
  896. memset( *ppMemory, 0, StructSize );
  897. NDR64_SET_NEW_EMBEDDED_ALLOCATION( pStubMsg->uFlags );
  898. fMustCopy = true;
  899. }
  900. else if ( ! *ppMemory )
  901. {
  902. *ppMemory = pStubMsg->Buffer;
  903. NDR64_SET_NEW_EMBEDDED_ALLOCATION( pStubMsg->uFlags );
  904. fMustCopy = false;
  905. }
  906. else
  907. // reuse the clients memory
  908. fMustCopy = true;
  909. if ( pStubMsg->FullPtrRefId )
  910. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  911. // Get the beginning memory pointer.
  912. pMemory = *ppMemory;
  913. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  914. for ( ; ; )
  915. {
  916. switch ( *pMemberLayout )
  917. {
  918. case FC64_STRUCT:
  919. {
  920. const NDR64_SIMPLE_REGION_FORMAT *pRegion =
  921. (NDR64_SIMPLE_REGION_FORMAT*) pMemberLayout;
  922. ALIGN( pStubMsg->Buffer, pRegion->Alignment );
  923. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + pRegion->RegionSize );
  924. if ( fMustCopy )
  925. RpcpMemoryCopy( pMemory,
  926. pStubMsg->Buffer,
  927. pRegion->RegionSize );
  928. pStubMsg->Buffer += pRegion->RegionSize;
  929. pMemory += pRegion->RegionSize;
  930. pMemberLayout += sizeof( *pRegion );
  931. break;
  932. }
  933. case FC64_STRUCTPADN :
  934. {
  935. const NDR64_MEMPAD_FORMAT *pMemPad = (NDR64_MEMPAD_FORMAT*)pMemberLayout;
  936. pMemory += pMemPad->MemPad;
  937. pMemberLayout += sizeof(*pMemPad);
  938. break;
  939. }
  940. case FC64_POINTER :
  941. {
  942. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  943. &pMemory,
  944. pFormatPointers );
  945. pMemory += PTR_MEM_SIZE;
  946. pFormatPointers += sizeof(NDR64_POINTER_FORMAT);
  947. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  948. break;
  949. }
  950. case FC64_EMBEDDED_COMPLEX :
  951. {
  952. const NDR64_EMBEDDED_COMPLEX_FORMAT * pEmbeddedFormat =
  953. (NDR64_EMBEDDED_COMPLEX_FORMAT*) pMemberLayout;
  954. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  955. &pMemory,
  956. pEmbeddedFormat->Type );
  957. pMemory = Ndr64pMemoryIncrement( pStubMsg,
  958. pMemory,
  959. pEmbeddedFormat->Type,
  960. TRUE );
  961. pMemberLayout += sizeof(*pEmbeddedFormat);
  962. break;
  963. }
  964. case FC64_BUFFER_ALIGN:
  965. {
  966. const NDR64_BUFFER_ALIGN_FORMAT *pBufAlign =
  967. (NDR64_BUFFER_ALIGN_FORMAT*) pMemberLayout;
  968. ALIGN( pStubMsg->Buffer, pBufAlign->Alignment );
  969. pMemberLayout += sizeof( *pBufAlign );
  970. break;
  971. }
  972. case FC64_CHAR :
  973. case FC64_WCHAR :
  974. case FC64_INT8:
  975. case FC64_UINT8:
  976. case FC64_INT16:
  977. case FC64_UINT16:
  978. case FC64_INT32:
  979. case FC64_UINT32:
  980. case FC64_INT64:
  981. case FC64_UINT64:
  982. case FC64_FLOAT32 :
  983. case FC64_FLOAT64 :
  984. case FC64_ERROR_STATUS_T:
  985. Ndr64SimpleTypeUnmarshall( pStubMsg,
  986. pMemory,
  987. *pMemberLayout );
  988. pMemory += NDR64_SIMPLE_TYPE_MEMSIZE(*pMemberLayout);
  989. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  990. break;
  991. case FC64_IGNORE :
  992. ALIGN(pStubMsg->Buffer, NDR64_PTR_WIRE_ALIGN);
  993. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  994. if ( NDR64_IS_NEW_EMBEDDED_ALLOCATION( pStubMsg->uFlags ) )
  995. {
  996. *(char**)pMemory = (char*)0;
  997. }
  998. pMemory += PTR_MEM_SIZE;
  999. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  1000. break;
  1001. case FC64_END :
  1002. goto ComplexUnmarshallEnd;
  1003. default :
  1004. NDR_ASSERT(0,"Ndr64ComplexStructUnmarshall : bad format char");
  1005. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  1006. return;
  1007. }
  1008. }
  1009. ComplexUnmarshallEnd:
  1010. if ( pFormatArray )
  1011. {
  1012. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1013. &pMemory,
  1014. pFormatArray );
  1015. }
  1016. else
  1017. {
  1018. // If the structure doesn't have a conformant array, align it again
  1019. ALIGN( pStubMsg->Buffer, pStructFormat->Alignment );
  1020. }
  1021. if ( fSetPointerBufferMark )
  1022. {
  1023. pStubMsg->Buffer = pStubMsg->PointerBufferMark;
  1024. pStubMsg->PointerBufferMark = 0;
  1025. }
  1026. }
  1027. void
  1028. Ndr64pCommonStringUnmarshall(
  1029. PMIDL_STUB_MESSAGE pStubMsg,
  1030. uchar ** ppMemory,
  1031. const NDR64_STRING_HEADER_FORMAT *pStringFormat,
  1032. bool fMustAlloc,
  1033. NDR64_UINT32 MemorySize )
  1034. {
  1035. ALIGN(pStubMsg->Buffer,NDR64_WIRE_COUNT_ALIGN);
  1036. NDR64_WIRE_COUNT_TYPE Offset = ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[0];
  1037. NDR64_WIRE_COUNT_TYPE Count = ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[1];
  1038. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1039. NDR64_UINT32 TransmittedSize =
  1040. Ndr64pConvertTo2GB( (NDR64_UINT64)pStringFormat->ElementSize *
  1041. Count );
  1042. if ( ( Offset != 0 ) ||
  1043. ( 0 == Count ) ||
  1044. ( TransmittedSize > MemorySize ) )
  1045. RpcRaiseException( RPC_X_INVALID_BOUND );
  1046. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, TransmittedSize );
  1047. // In this code, we check that a terminator is
  1048. // where the marshaller tells us it is. We could check
  1049. // if another terminator exists in addition to the other
  1050. // terminator, but it doesn't make sense to do this
  1051. // since it wouldn't close any attacks.
  1052. switch( pStringFormat->FormatCode )
  1053. {
  1054. case FC64_CHAR_STRING:
  1055. case FC64_CONF_CHAR_STRING:
  1056. {
  1057. char *p = (char *) pStubMsg->Buffer;
  1058. NDR64_WIRE_COUNT_TYPE ActualChars = Count - 1;
  1059. if ( '\0' != p[ActualChars] )
  1060. {
  1061. RpcRaiseException( RPC_X_INVALID_BOUND );
  1062. return;
  1063. }
  1064. break;
  1065. }
  1066. case FC64_WCHAR_STRING:
  1067. case FC64_CONF_WCHAR_STRING:
  1068. {
  1069. wchar_t *p = ( wchar_t* ) pStubMsg->Buffer;
  1070. NDR64_WIRE_COUNT_TYPE ActualChars = Count - 1;
  1071. if ( L'\0' != p[ActualChars] )
  1072. {
  1073. RpcRaiseException( RPC_X_INVALID_BOUND );
  1074. return;
  1075. }
  1076. break;
  1077. }
  1078. case FC64_STRUCT_STRING:
  1079. case FC64_CONF_STRUCT_STRING:
  1080. {
  1081. NDR64_UINT8 *p = (NDR64_UINT8 *) pStubMsg->Buffer;
  1082. NDR64_WIRE_COUNT_TYPE ActualChars = Count - 1;
  1083. NDR64_UINT32 ElementSize = pStringFormat->ElementSize;
  1084. NDR64_UINT8 *t = p + Ndr64pConvertTo2GB( ActualChars * ElementSize );
  1085. if ( !Ndr64pIsStructStringTerminator( t, ElementSize ) )
  1086. {
  1087. RpcRaiseException( RPC_X_INVALID_BOUND );
  1088. return;
  1089. }
  1090. break;
  1091. }
  1092. }
  1093. if ( fMustAlloc )
  1094. {
  1095. *ppMemory = (uchar *) NdrAllocate( pStubMsg, MemorySize );
  1096. }
  1097. else if ( ! *ppMemory )
  1098. {
  1099. *ppMemory = ( TransmittedSize == MemorySize ) ? pStubMsg->Buffer :
  1100. (uchar *) NdrAllocate( pStubMsg, MemorySize );
  1101. }
  1102. if ( *ppMemory != pStubMsg->Buffer )
  1103. {
  1104. RpcpMemoryCopy( *ppMemory,
  1105. pStubMsg->Buffer,
  1106. TransmittedSize );
  1107. }
  1108. pStubMsg->Buffer += TransmittedSize;
  1109. return;
  1110. }
  1111. void
  1112. Ndr64NonConformantStringUnmarshall(
  1113. PMIDL_STUB_MESSAGE pStubMsg,
  1114. uchar ** ppMemory,
  1115. PNDR64_FORMAT pFormat,
  1116. bool fMustAlloc )
  1117. /*++
  1118. Routine description :
  1119. Unmarshalls a non conformant string.
  1120. Arguments :
  1121. pStubMsg - Pointer to the stub message.
  1122. pMemory - Double pointer to the string should be unmarshalled.
  1123. pFormat - String's format string description.
  1124. fMustAlloc - Ignored.
  1125. Return :
  1126. None.
  1127. --*/
  1128. {
  1129. const NDR64_NON_CONFORMANT_STRING_FORMAT * pStringFormat =
  1130. (NDR64_NON_CONFORMANT_STRING_FORMAT*) pFormat;
  1131. Ndr64pCommonStringUnmarshall( pStubMsg,
  1132. ppMemory,
  1133. &pStringFormat->Header,
  1134. fMustAlloc,
  1135. pStringFormat->TotalSize );
  1136. }
  1137. void
  1138. Ndr64ConformantStringUnmarshall(
  1139. PMIDL_STUB_MESSAGE pStubMsg,
  1140. uchar ** ppMemory,
  1141. PNDR64_FORMAT pFormat,
  1142. bool fMustAlloc )
  1143. /*++
  1144. Routine description :
  1145. Unmarshalls a top level conformant string.
  1146. Arguments :
  1147. pStubMsg - Pointer to the stub message.
  1148. ppMemory - Double pointer to where the string should be unmarshalled.
  1149. pFormat - String's format string description.
  1150. fMustAlloc - TRUE if the string must be allocated, FALSE otherwise.
  1151. Return :
  1152. None.
  1153. --*/
  1154. {
  1155. const NDR64_CONFORMANT_STRING_FORMAT * pStringFormat =
  1156. (const NDR64_CONFORMANT_STRING_FORMAT*) pFormat;
  1157. const NDR64_SIZED_CONFORMANT_STRING_FORMAT *pSizedStringFormat =
  1158. (const NDR64_SIZED_CONFORMANT_STRING_FORMAT*) pFormat;
  1159. NDR64_WIRE_COUNT_TYPE MaxCount;
  1160. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1161. {
  1162. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1163. MaxCount = *((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer);
  1164. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  1165. }
  1166. else
  1167. {
  1168. MaxCount = *(NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  1169. }
  1170. NDR64_UINT32 AllocationSize =
  1171. Ndr64pConvertTo2GB( MaxCount *
  1172. (NDR64_UINT64)pStringFormat->Header.ElementSize );
  1173. if ( pStringFormat->Header.Flags.IsSized )
  1174. {
  1175. Ndr64pCheckCorrelation( pStubMsg,
  1176. MaxCount,
  1177. pSizedStringFormat->SizeDescription,
  1178. EXPR_MAXCOUNT );
  1179. }
  1180. return
  1181. Ndr64pCommonStringUnmarshall( pStubMsg,
  1182. ppMemory,
  1183. &pStringFormat->Header,
  1184. fMustAlloc,
  1185. AllocationSize );
  1186. }
  1187. void
  1188. Ndr64FixedArrayUnmarshall(
  1189. PMIDL_STUB_MESSAGE pStubMsg,
  1190. uchar ** ppMemory,
  1191. PNDR64_FORMAT pFormat,
  1192. bool fMustAlloc )
  1193. /*++
  1194. Routine Description :
  1195. Unmarshalls a fixed array of any number of dimensions.
  1196. Arguments :
  1197. pStubMsg - Pointer to the stub message.
  1198. ppMemory - Pointer to the array to unmarshall.
  1199. pFormat - Array's format string description.
  1200. fMustAlloc - TRUE if the array must be allocated, FALSE otherwise.
  1201. Return :
  1202. None.
  1203. --*/
  1204. {
  1205. const NDR64_FIX_ARRAY_HEADER_FORMAT * pArrayFormat =
  1206. (NDR64_FIX_ARRAY_HEADER_FORMAT*) pFormat;
  1207. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1208. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment );
  1209. uchar *pBufferStart = pStubMsg->Buffer;
  1210. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + pArrayFormat->TotalSize );
  1211. pStubMsg->Buffer += pArrayFormat->TotalSize;
  1212. if ( fMustAlloc )
  1213. {
  1214. *ppMemory = (uchar *) NdrAllocate( pStubMsg, pArrayFormat->TotalSize );
  1215. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1216. }
  1217. else if ( !*ppMemory )
  1218. {
  1219. *ppMemory = pBufferStart;
  1220. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1221. }
  1222. if ( pArrayFormat->Flags.HasPointerInfo )
  1223. {
  1224. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1225. pArrayFormat + 1,
  1226. 0,
  1227. *ppMemory,
  1228. pBufferStart );
  1229. }
  1230. if ( *ppMemory != pBufferStart )
  1231. {
  1232. RpcpMemoryCopy( *ppMemory,
  1233. pBufferStart,
  1234. pArrayFormat->TotalSize );
  1235. }
  1236. }
  1237. void
  1238. Ndr64ConformantArrayUnmarshall(
  1239. PMIDL_STUB_MESSAGE pStubMsg,
  1240. uchar ** ppMemory,
  1241. PNDR64_FORMAT pFormat,
  1242. bool fMustAlloc )
  1243. /*++
  1244. Routine Description :
  1245. Unmarshalls a top level one dimensional conformant array.
  1246. Used for FC64_CARRAY.
  1247. Arguments :
  1248. pStubMsg - Pointer to the stub message.
  1249. ppMemory - Pointer to array to be unmarshalled.
  1250. pFormat - Array's format string description.
  1251. Return :
  1252. None.
  1253. --*/
  1254. {
  1255. const NDR64_CONF_ARRAY_HEADER_FORMAT *pArrayFormat =
  1256. (NDR64_CONF_ARRAY_HEADER_FORMAT*) pFormat;
  1257. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1258. NDR64_WIRE_COUNT_TYPE MaxCount;
  1259. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1260. {
  1261. // Align the buffer for conformance marshalling.
  1262. ALIGN(pStubMsg->Buffer,NDR64_WIRE_COUNT_ALIGN);
  1263. MaxCount = *((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer);
  1264. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  1265. }
  1266. else
  1267. {
  1268. MaxCount = *pStubMsg->ConformanceMark;
  1269. }
  1270. NDR64_UINT32 CopySize =
  1271. Ndr64pConvertTo2GB( MaxCount *
  1272. (NDR64_UINT64)pArrayFormat->ElementSize );
  1273. Ndr64pCheckCorrelation( pStubMsg,
  1274. MaxCount,
  1275. pArrayFormat->ConfDescriptor,
  1276. EXPR_MAXCOUNT );
  1277. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  1278. uchar *pBufferStart = pStubMsg->Buffer;
  1279. CHECK_EOB_WITH_WRAP_RAISE_IB( pStubMsg->Buffer, CopySize);
  1280. pStubMsg->Buffer += CopySize; // Unmarshall embedded pointers.
  1281. if ( fMustAlloc )
  1282. {
  1283. *ppMemory = (uchar *) NdrAllocate( pStubMsg, CopySize );
  1284. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1285. }
  1286. else if ( !*ppMemory )
  1287. {
  1288. *ppMemory = pBufferStart;
  1289. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1290. }
  1291. if ( pArrayFormat->Flags.HasPointerInfo )
  1292. {
  1293. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1294. pArrayFormat + 1,
  1295. (NDR64_UINT32)MaxCount,
  1296. *ppMemory,
  1297. pBufferStart );
  1298. }
  1299. if ( *ppMemory != pBufferStart )
  1300. {
  1301. RpcpMemoryCopy( *ppMemory,
  1302. pBufferStart,
  1303. CopySize );
  1304. }
  1305. }
  1306. void
  1307. Ndr64ConformantVaryingArrayUnmarshall(
  1308. PMIDL_STUB_MESSAGE pStubMsg,
  1309. uchar ** ppMemory,
  1310. PNDR64_FORMAT pFormat,
  1311. bool fMustAlloc )
  1312. /*++
  1313. Routine Description :
  1314. Unmarshalls a top level one dimensional conformant varying array.
  1315. Used for FC64_CVARRAY.
  1316. Arguments :
  1317. pStubMsg - Pointer to the stub message.
  1318. ppMemory - Pointer to the array being unmarshalled.
  1319. pFormat - Array's format string description.
  1320. fMustAlloc - Ignored.
  1321. Return :
  1322. None.
  1323. --*/
  1324. {
  1325. const NDR64_CONF_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  1326. (NDR64_CONF_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  1327. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags);
  1328. NDR64_WIRE_COUNT_TYPE MaxCount;
  1329. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1330. {
  1331. // Align the buffer for conformance unmarshalling.
  1332. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1333. MaxCount = *((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer);
  1334. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  1335. }
  1336. else
  1337. {
  1338. MaxCount = *(NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  1339. }
  1340. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1341. NDR64_WIRE_COUNT_TYPE Offset = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[0];
  1342. NDR64_WIRE_COUNT_TYPE ActualCount = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[1];
  1343. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1344. NDR64_UINT32 AllocSize = Ndr64pConvertTo2GB( MaxCount *
  1345. (NDR64_UINT64)pArrayFormat->ElementSize );
  1346. NDR64_UINT32 CopySize = Ndr64pConvertTo2GB( ActualCount *
  1347. (NDR64_UINT64)pArrayFormat->ElementSize );
  1348. if ( ( Offset != 0 ) ||
  1349. ActualCount > MaxCount )
  1350. RpcRaiseException( RPC_X_INVALID_BOUND );
  1351. Ndr64pCheckCorrelation( pStubMsg,
  1352. MaxCount,
  1353. pArrayFormat->ConfDescriptor,
  1354. EXPR_MAXCOUNT );
  1355. Ndr64pCheckCorrelation( pStubMsg,
  1356. ActualCount,
  1357. pArrayFormat->VarDescriptor,
  1358. EXPR_ACTUALCOUNT );
  1359. //
  1360. // For a conformant varying array, we can't reuse the buffer
  1361. // because it doesn't hold the total size of the array.
  1362. if ( fMustAlloc || !*ppMemory )
  1363. {
  1364. *ppMemory = (uchar *) NdrAllocate( pStubMsg, AllocSize );
  1365. memset( *ppMemory, 0, AllocSize );
  1366. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1367. }
  1368. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  1369. CHECK_EOB_WITH_WRAP_RAISE_IB( pStubMsg->Buffer, CopySize);
  1370. uchar *pBufferStart = pStubMsg->Buffer;
  1371. pStubMsg->Buffer += CopySize;
  1372. if ( pArrayFormat->Flags.HasPointerInfo )
  1373. {
  1374. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1375. pArrayFormat + 1,
  1376. (NDR64_UINT32)ActualCount,
  1377. *ppMemory,
  1378. pBufferStart );
  1379. }
  1380. RpcpMemoryCopy( *ppMemory,
  1381. pBufferStart,
  1382. CopySize );
  1383. }
  1384. void
  1385. Ndr64VaryingArrayUnmarshall(
  1386. PMIDL_STUB_MESSAGE pStubMsg,
  1387. uchar ** ppMemory,
  1388. PNDR64_FORMAT pFormat,
  1389. bool fMustAlloc )
  1390. /*++
  1391. Routine Description :
  1392. Unmarshalls top level or embedded a one dimensional varying array.
  1393. Arguments :
  1394. pStubMsg - Pointer to the stub message.
  1395. pMemory - Array being unmarshalled.
  1396. pFormat - Array's format string description.
  1397. fMustAlloc - Ignored.
  1398. --*/
  1399. {
  1400. const NDR64_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  1401. (NDR64_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  1402. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1403. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1404. NDR64_WIRE_COUNT_TYPE Offset = ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[0];
  1405. NDR64_WIRE_COUNT_TYPE ActualCount = ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[1];
  1406. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1407. NDR64_UINT32 CopySize
  1408. = Ndr64pConvertTo2GB( ActualCount *
  1409. (NDR64_UINT64)pArrayFormat->ElementSize );
  1410. if ( ( Offset != 0 ) ||
  1411. ( CopySize > pArrayFormat->TotalSize ) )
  1412. RpcRaiseException( RPC_X_INVALID_BOUND );
  1413. Ndr64pCheckCorrelation( pStubMsg,
  1414. ActualCount,
  1415. pArrayFormat->VarDescriptor,
  1416. EXPR_ACTUALCOUNT );
  1417. if ( fMustAlloc || !*ppMemory )
  1418. {
  1419. *ppMemory = (uchar *) NdrAllocate( pStubMsg, pArrayFormat->TotalSize );
  1420. memset( *ppMemory, 0, pArrayFormat->TotalSize );
  1421. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1422. }
  1423. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment );
  1424. CHECK_EOB_WITH_WRAP_RAISE_IB( pStubMsg->Buffer, CopySize );
  1425. uchar *pBufferStart = pStubMsg->Buffer;
  1426. pStubMsg->Buffer += CopySize;
  1427. if ( pArrayFormat->Flags.HasPointerInfo )
  1428. {
  1429. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1430. pArrayFormat + 1,
  1431. (NDR64_UINT32)ActualCount,
  1432. *ppMemory,
  1433. pBufferStart );
  1434. }
  1435. RpcpMemoryCopy( *ppMemory,
  1436. pBufferStart,
  1437. CopySize );
  1438. }
  1439. void
  1440. Ndr64ComplexArrayUnmarshall(
  1441. PMIDL_STUB_MESSAGE pStubMsg,
  1442. uchar ** ppMemory,
  1443. PNDR64_FORMAT pFormat,
  1444. bool fMustAlloc )
  1445. /*++
  1446. Routine Description :
  1447. Unmarshalls a top level complex array.
  1448. Arguments :
  1449. pStubMsg - Pointer to the stub message.
  1450. ppMemory - Pointer to the array being unmarshalled.
  1451. pFormat - Array's format string description.
  1452. fMustAlloc - Ignored.
  1453. Return :
  1454. None.
  1455. --*/
  1456. {
  1457. const NDR64_BOGUS_ARRAY_HEADER_FORMAT *pArrayFormat =
  1458. (NDR64_BOGUS_ARRAY_HEADER_FORMAT *) pFormat;
  1459. bool fSetPointerBufferMark = ! pStubMsg->PointerBufferMark;
  1460. if ( fSetPointerBufferMark )
  1461. {
  1462. uchar *pBuffer = pStubMsg->Buffer;
  1463. BOOL fOldIgnore = pStubMsg->IgnoreEmbeddedPointers;
  1464. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  1465. pStubMsg->MemorySize = 0;
  1466. Ndr64ComplexArrayMemorySize(
  1467. pStubMsg,
  1468. pFormat );
  1469. // make sure we haven't overflow for the flat part.
  1470. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer );
  1471. pStubMsg->PointerBufferMark = pStubMsg->Buffer;
  1472. pStubMsg->IgnoreEmbeddedPointers = fOldIgnore;
  1473. pStubMsg->Buffer = pBuffer;
  1474. }
  1475. BOOL IsFixed = ( pArrayFormat->FormatCode == FC64_FIX_BOGUS_ARRAY ) ||
  1476. ( pArrayFormat->FormatCode == FC64_FIX_FORCED_BOGUS_ARRAY );
  1477. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags);
  1478. SAVE_CONTEXT<uchar*> ConformanceMarkSave( pStubMsg->ConformanceMark );
  1479. SAVE_CONTEXT<uchar*> VarianceMarkSave( pStubMsg->VarianceMark );
  1480. PFORMAT_STRING pElementFormat = (PFORMAT_STRING)pArrayFormat->Element;
  1481. NDR64_WIRE_COUNT_TYPE Elements = pArrayFormat->NumberElements;
  1482. NDR64_WIRE_COUNT_TYPE Count = Elements;
  1483. NDR64_WIRE_COUNT_TYPE Offset = 0;
  1484. if ( !IsFixed )
  1485. {
  1486. const NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT* pConfVarFormat=
  1487. (NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT*)pFormat;
  1488. //
  1489. // Check for conformance description.
  1490. //
  1491. if ( pConfVarFormat->ConfDescription )
  1492. {
  1493. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1494. {
  1495. //
  1496. // Outer most dimension sets the conformance marker.
  1497. //
  1498. // Align the buffer for conformance marshalling.
  1499. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  1500. // Mark where the conformance count(s) will be marshalled.
  1501. pStubMsg->ConformanceMark = pStubMsg->Buffer;
  1502. // Increment past where the conformance will go.
  1503. pStubMsg->Buffer += pArrayFormat->NumberDims * sizeof(NDR64_WIRE_COUNT_TYPE);
  1504. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  1505. }
  1506. Elements = *(NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  1507. pStubMsg->ConformanceMark += sizeof(NDR64_WIRE_COUNT_TYPE);
  1508. Ndr64pCheckCorrelation( pStubMsg,
  1509. Elements,
  1510. pConfVarFormat->ConfDescription,
  1511. EXPR_MAXCOUNT );
  1512. Offset = 0;
  1513. Count = Elements;
  1514. }
  1515. //
  1516. // Check for variance description.
  1517. //
  1518. if ( pConfVarFormat->VarDescription )
  1519. {
  1520. if ( ! NDR64_IS_VAR_MARK_VALID( pStubMsg->uFlags ) )
  1521. {
  1522. NDR64_UINT32 Dimensions;
  1523. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1524. Dimensions = ( pArrayFormat->Flags.IsArrayofStrings ) ? ( pArrayFormat->NumberDims - 1) :
  1525. ( pArrayFormat->NumberDims );
  1526. pStubMsg->VarianceMark = pStubMsg->Buffer;
  1527. pStubMsg->Buffer += Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1528. if ( NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  1529. NDR64_SET_VAR_MARK_VALID( pStubMsg->uFlags );
  1530. }
  1531. else if ( !NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  1532. NDR64_RESET_VAR_MARK_VALID( pStubMsg->uFlags );
  1533. Offset = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->VarianceMark)[0];
  1534. Count = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->VarianceMark)[1];
  1535. pStubMsg->VarianceMark += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1536. Ndr64pCheckCorrelation( pStubMsg,
  1537. Count,
  1538. pConfVarFormat->VarDescription,
  1539. EXPR_ACTUALCOUNT );
  1540. Ndr64pCheckCorrelation( pStubMsg,
  1541. Offset,
  1542. pConfVarFormat->OffsetDescription,
  1543. EXPR_OFFSET );
  1544. }
  1545. }
  1546. NDR64_UINT32 ElementMemorySize =
  1547. Ndr64pMemorySize( pStubMsg,
  1548. pElementFormat,
  1549. TRUE );
  1550. NDR64_UINT32 ArraySize = Ndr64pConvertTo2GB( Elements *
  1551. (NDR64_UINT64)ElementMemorySize );
  1552. Ndr64pConvertTo2GB( Count *
  1553. (NDR64_UINT64)ElementMemorySize );
  1554. if ( fMustAlloc || ! *ppMemory )
  1555. {
  1556. *ppMemory = (uchar*)NdrAllocate( pStubMsg, (uint) ArraySize );
  1557. memset( *ppMemory, 0, ArraySize );
  1558. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1559. }
  1560. if ( pStubMsg->FullPtrRefId )
  1561. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  1562. uchar *pMemory = *ppMemory;
  1563. pMemory += Ndr64pConvertTo2GB(Offset *
  1564. (NDR64_UINT64)ElementMemorySize);
  1565. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment);
  1566. for( ; Count--; )
  1567. {
  1568. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1569. &pMemory,
  1570. pElementFormat );
  1571. pMemory += ElementMemorySize;
  1572. }
  1573. if ( fSetPointerBufferMark )
  1574. {
  1575. pStubMsg->Buffer = pStubMsg->PointerBufferMark;
  1576. pStubMsg->PointerBufferMark = 0;
  1577. }
  1578. }
  1579. void
  1580. Ndr64UnionUnmarshall (
  1581. PMIDL_STUB_MESSAGE pStubMsg,
  1582. uchar ** ppMemory,
  1583. PNDR64_FORMAT pFormat,
  1584. bool fMustAlloc )
  1585. /*++
  1586. Routine Description :
  1587. Unmarshalls an encapsulated array.
  1588. Arguments :
  1589. pStubMsg - Pointer to the stub message.
  1590. ppMemory - Double pointer to where the union should be unmarshalled.
  1591. pFormat - Union's format string description.
  1592. fMustAlloc - Ignored.
  1593. Return :
  1594. None.
  1595. --*/
  1596. {
  1597. const NDR64_UNION_ARM_SELECTOR* pArmSelector;
  1598. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1599. EXPR_VALUE SwitchIs;
  1600. uchar* pArmMemory;
  1601. switch(*(PFORMAT_STRING)pFormat)
  1602. {
  1603. case FC64_NON_ENCAPSULATED_UNION:
  1604. {
  1605. const NDR64_NON_ENCAPSULATED_UNION* pNonEncapUnionFormat =
  1606. (const NDR64_NON_ENCAPSULATED_UNION*) pFormat;
  1607. ALIGN(pStubMsg->Buffer, pNonEncapUnionFormat->Alignment);
  1608. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pNonEncapUnionFormat + 1);
  1609. if ( fMustAlloc || ! *ppMemory )
  1610. {
  1611. *ppMemory = (uchar*)NdrAllocate( pStubMsg, pNonEncapUnionFormat->MemorySize );
  1612. //
  1613. // We must zero out all of the new memory in case there are pointers
  1614. // in any of the arms.
  1615. //
  1616. MIDL_memset( *ppMemory, 0, pNonEncapUnionFormat->MemorySize );
  1617. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1618. }
  1619. SwitchIs = Ndr64pSimpleTypeToExprValue( pNonEncapUnionFormat->SwitchType,
  1620. pStubMsg->Buffer );
  1621. pStubMsg->Buffer += NDR64_SIMPLE_TYPE_BUFSIZE( pNonEncapUnionFormat->SwitchType );
  1622. Ndr64pCheckCorrelation( pStubMsg,
  1623. SwitchIs,
  1624. pNonEncapUnionFormat->Switch,
  1625. EXPR_SWITCHIS );
  1626. pArmMemory = *ppMemory;
  1627. break;
  1628. }
  1629. case FC64_ENCAPSULATED_UNION:
  1630. {
  1631. const NDR64_ENCAPSULATED_UNION* pEncapUnionFormat =
  1632. (const NDR64_ENCAPSULATED_UNION*)pFormat;
  1633. ALIGN(pStubMsg->Buffer, pEncapUnionFormat->Alignment);
  1634. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pEncapUnionFormat + 1);
  1635. if ( fMustAlloc || ! *ppMemory )
  1636. {
  1637. *ppMemory = (uchar*)NdrAllocate( pStubMsg, pEncapUnionFormat->MemorySize );
  1638. //
  1639. // We must zero out all of the new memory in case there are pointers
  1640. // in any of the arms.
  1641. //
  1642. MIDL_memset( *ppMemory, 0, pEncapUnionFormat->MemorySize );
  1643. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1644. }
  1645. SwitchIs = Ndr64pSimpleTypeToExprValue( pEncapUnionFormat->SwitchType,
  1646. pStubMsg->Buffer );
  1647. Ndr64SimpleTypeUnmarshall( pStubMsg,
  1648. *ppMemory,
  1649. pEncapUnionFormat->SwitchType );
  1650. pArmMemory = *ppMemory + pEncapUnionFormat->MemoryOffset;
  1651. break;
  1652. }
  1653. default:
  1654. NDR_ASSERT("Bad union format\n", 0);
  1655. return;
  1656. }
  1657. if ( pStubMsg->FullPtrRefId )
  1658. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  1659. ALIGN(pStubMsg->Buffer, pArmSelector->Alignment);
  1660. PNDR64_FORMAT pArmFormat =
  1661. Ndr64pFindUnionArm( pStubMsg,
  1662. pArmSelector,
  1663. SwitchIs );
  1664. // check we aren't EOB after unmarshalling arm selector
  1665. // we won't corrupt memory as there is no in place unmarshall here.
  1666. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer );
  1667. if ( pArmFormat )
  1668. {
  1669. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1670. &pArmMemory,
  1671. pArmFormat );
  1672. }
  1673. }
  1674. void
  1675. Ndr64XmitOrRepAsUnmarshall (
  1676. PMIDL_STUB_MESSAGE pStubMsg,
  1677. uchar ** ppMemory,
  1678. PNDR64_FORMAT pFormat,
  1679. bool /*fMustAlloc*/,
  1680. bool bIsEmbedded )
  1681. /*++
  1682. Routine Description :
  1683. Unmarshalls a transmit as (or represent as)object.
  1684. Means: allocate the transmitted object,
  1685. unmarshall transmitted object,
  1686. translate the transmitted into presented
  1687. free the transmitted.
  1688. See mrshl.c for the description of the FC layout.
  1689. Arguments :
  1690. pStubMsg - a pointer to the stub message
  1691. ppMemory - pointer to the presented type where to put data
  1692. pFormat - format string description
  1693. fMustAlloc - allocate flag
  1694. Note.
  1695. fMustAlloc is ignored as we always allocate outside of the buffer.
  1696. --*/
  1697. {
  1698. unsigned char * pPresentedType = *ppMemory;
  1699. const XMIT_ROUTINE_QUINTUPLE * pQuintuple = pStubMsg->StubDesc->aXmitQuintuple;
  1700. NDR64_TRANSMIT_AS_FORMAT *pTransFormat =
  1701. ( NDR64_TRANSMIT_AS_FORMAT *) pFormat;
  1702. NDR_ASSERT( pTransFormat->FormatCode == FC64_TRANSMIT_AS || pTransFormat->FormatCode , "invalid format string for user marshal" );
  1703. unsigned short QIndex = pTransFormat->RoutineIndex;
  1704. unsigned long PresentedTypeSize = pTransFormat->PresentedTypeMemorySize;
  1705. if ( ! pPresentedType )
  1706. {
  1707. pPresentedType = (uchar*)NdrAllocate( pStubMsg, (uint) PresentedTypeSize );
  1708. MIDL_memset( pPresentedType, 0, (uint) PresentedTypeSize );
  1709. }
  1710. // Allocate the transmitted object outside of the buffer
  1711. // and unmarshall into it
  1712. if ( NDR64_IS_SIMPLE_TYPE( *(PFORMAT_STRING)pTransFormat->TransmittedType ))
  1713. {
  1714. __int64 SimpleTypeValueBuffer[2];
  1715. unsigned char * pTransmittedType = (unsigned char *)SimpleTypeValueBuffer;
  1716. Ndr64SimpleTypeUnmarshall( pStubMsg,
  1717. pTransmittedType,
  1718. *(PFORMAT_STRING)pTransFormat->TransmittedType );
  1719. // Translate from the transmitted type into the presented type.
  1720. pStubMsg->pTransmitType = pTransmittedType;
  1721. pStubMsg->pPresentedType = pPresentedType;
  1722. pQuintuple[ QIndex ].pfnTranslateFromXmit( pStubMsg );
  1723. *ppMemory = pStubMsg->pPresentedType;
  1724. }
  1725. else
  1726. {
  1727. // Save the current state of the memory list so that the temporary
  1728. // memory allocated for the transmitted type can be easily removed
  1729. // from the list. This assumes that the memory allocated here
  1730. // will not have any linkes to other blocks of memory. This is true
  1731. // as long as full pointers are not used. Fortunatly, full pointers
  1732. // do not work correctly in the current code.
  1733. void *pMemoryListSave = pStubMsg->pMemoryList;
  1734. unsigned char *pTransmittedType = NULL; // asking the engine to allocate
  1735. // In NDR64, Xmit/Rep cannot be a pointer or contain a pointer.
  1736. // So we don't need to worry about the pointer queue here.
  1737. if ( bIsEmbedded )
  1738. {
  1739. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1740. &pTransmittedType,
  1741. pTransFormat->TransmittedType );
  1742. }
  1743. else
  1744. {
  1745. Ndr64TopLevelTypeUnmarshall( pStubMsg,
  1746. &pTransmittedType,
  1747. pTransFormat->TransmittedType,
  1748. TRUE );
  1749. }
  1750. // Translate from the transmitted type into the presented type.
  1751. pStubMsg->pTransmitType = pTransmittedType;
  1752. pStubMsg->pPresentedType = pPresentedType;
  1753. pQuintuple[ QIndex ].pfnTranslateFromXmit( pStubMsg );
  1754. *ppMemory = pStubMsg->pPresentedType;
  1755. // Free the transmitted object (it was allocated by the engine)
  1756. // and its pointees. The call through the table frees the pointees
  1757. // only (plus it'd free the object itself if it were a pointer).
  1758. // As the transmitted type is not a pointer here, we need to free it
  1759. // explicitely later.
  1760. // Remove the memory that will be freed from the allocated memory
  1761. // list by restoring the memory list pointer.
  1762. // If an exception occures during one of these free routines, we
  1763. // are in trouble anyway.
  1764. pStubMsg->pMemoryList = pMemoryListSave;
  1765. if ( bIsEmbedded )
  1766. {
  1767. Ndr64EmbeddedTypeFree( pStubMsg,
  1768. pTransmittedType,
  1769. pTransFormat->TransmittedType );
  1770. }
  1771. else
  1772. {
  1773. Ndr64ToplevelTypeFree( pStubMsg,
  1774. pTransmittedType,
  1775. pTransFormat->TransmittedType );
  1776. }
  1777. // The buffer reusage check.
  1778. if ( pTransmittedType < pStubMsg->BufferStart ||
  1779. pTransmittedType > pStubMsg->BufferEnd )
  1780. (*pStubMsg->pfnFree)( pTransmittedType );
  1781. }
  1782. }
  1783. void
  1784. Ndr64TopLevelXmitOrRepAsUnmarshall (
  1785. PMIDL_STUB_MESSAGE pStubMsg,
  1786. uchar ** ppMemory,
  1787. PNDR64_FORMAT pFormat,
  1788. bool fMustAlloc )
  1789. {
  1790. Ndr64XmitOrRepAsUnmarshall( pStubMsg,
  1791. ppMemory,
  1792. pFormat,
  1793. fMustAlloc,
  1794. false );
  1795. }
  1796. void
  1797. Ndr64EmbeddedXmitOrRepAsUnmarshall (
  1798. PMIDL_STUB_MESSAGE pStubMsg,
  1799. uchar ** ppMemory,
  1800. PNDR64_FORMAT pFormat,
  1801. bool fMustAlloc )
  1802. {
  1803. Ndr64XmitOrRepAsUnmarshall( pStubMsg,
  1804. ppMemory,
  1805. pFormat,
  1806. fMustAlloc,
  1807. true );
  1808. }
  1809. void
  1810. Ndr64UserMarshallUnmarshallInternal(
  1811. PMIDL_STUB_MESSAGE pStubMsg,
  1812. uchar * pMemory,
  1813. PNDR64_FORMAT pFormat )
  1814. {
  1815. NDR64_USER_MARSHAL_FORMAT *pUserFormat =
  1816. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1817. unsigned char * pUserBuffer = pStubMsg->Buffer;
  1818. unsigned char * pUserBufferSaved = pUserBuffer;
  1819. USER_MARSHAL_CB UserMarshalCB;
  1820. Ndr64pInitUserMarshalCB( pStubMsg,
  1821. pUserFormat,
  1822. USER_MARSHAL_CB_UNMARSHALL,
  1823. & UserMarshalCB );
  1824. unsigned short QIndex = pUserFormat->RoutineIndex;
  1825. const USER_MARSHAL_ROUTINE_QUADRUPLE * pQuadruple = (const USER_MARSHAL_ROUTINE_QUADRUPLE * )
  1826. ( ( NDR_PROC_CONTEXT *)pStubMsg->pContext )->pSyntaxInfo->aUserMarshalQuadruple;
  1827. if ((pUserBufferSaved < (uchar *) pStubMsg->RpcMsg->Buffer) ||
  1828. ((unsigned long) (pUserBufferSaved - (uchar *) pStubMsg->RpcMsg->Buffer)
  1829. > pStubMsg->RpcMsg->BufferLength))
  1830. {
  1831. RpcRaiseException( RPC_X_INVALID_BUFFER );
  1832. }
  1833. pUserBuffer = pQuadruple[ QIndex ].pfnUnmarshall( (ulong*) &UserMarshalCB,
  1834. pUserBuffer,
  1835. pMemory );
  1836. if ((pUserBufferSaved > pUserBuffer) ||
  1837. ((unsigned long) (pUserBuffer - (uchar *) pStubMsg->RpcMsg->Buffer)
  1838. > pStubMsg->RpcMsg->BufferLength ))
  1839. {
  1840. RpcRaiseException( RPC_X_INVALID_BUFFER );
  1841. }
  1842. // Step over the pointee.
  1843. pStubMsg->Buffer = pUserBuffer;
  1844. }
  1845. void
  1846. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT::Dispatch(MIDL_STUB_MESSAGE *pStubMsg)
  1847. {
  1848. Ndr64UserMarshallUnmarshallInternal( pStubMsg,
  1849. pMemory,
  1850. pFormat );
  1851. }
  1852. #if defined(DBG)
  1853. void
  1854. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT::Print()
  1855. {
  1856. DbgPrint("NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT\n");
  1857. DbgPrint("pMemory: %p\n", pMemory );
  1858. DbgPrint("pFormat: %p\n", pFormat );
  1859. }
  1860. #endif
  1861. void
  1862. Ndr64UserMarshallPointeeUnmarshall(
  1863. PMIDL_STUB_MESSAGE pStubMsg,
  1864. uchar * pMemory,
  1865. PNDR64_FORMAT pFormat )
  1866. {
  1867. if ( !pStubMsg->pPointerQueueState ||
  1868. !pStubMsg->pPointerQueueState->GetActiveQueue() )
  1869. {
  1870. POINTER_BUFFER_SWAP_CONTEXT SwapContext(pStubMsg);
  1871. Ndr64UserMarshallUnmarshallInternal(
  1872. pStubMsg,
  1873. pMemory,
  1874. pFormat );
  1875. return;
  1876. }
  1877. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT*pElement =
  1878. new(pStubMsg->pPointerQueueState)
  1879. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT(pMemory,
  1880. (PFORMAT_STRING)pFormat );
  1881. pStubMsg->pPointerQueueState->GetActiveQueue()->Enque( pElement );
  1882. }
  1883. void
  1884. Ndr64UserMarshalUnmarshall (
  1885. PMIDL_STUB_MESSAGE pStubMsg,
  1886. uchar ** ppMemory,
  1887. PNDR64_FORMAT pFormat,
  1888. bool fMustAlloc,
  1889. bool bIsEmbedded )
  1890. /*++
  1891. Routine Description :
  1892. Unmarshals a user_marshal object.
  1893. The layout is described in marshalling.
  1894. Arguments :
  1895. pStubMsg - Pointer to the stub message.
  1896. ppMemory - Pointer to pointer to the usr_marshall object to unmarshall.
  1897. pFormat - Object's format string description.
  1898. Return :
  1899. None.
  1900. --*/
  1901. {
  1902. NDR64_USER_MARSHAL_FORMAT *pUserFormat =
  1903. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1904. NDR_ASSERT( pUserFormat->FormatCode == FC64_USER_MARSHAL, "invalid format string for user marshal" );
  1905. // Align for the object or a pointer to it.
  1906. ALIGN( pStubMsg->Buffer, pUserFormat->TransmittedTypeWireAlignment );
  1907. // Take care of the pointer, if any.
  1908. NDR64_PTR_WIRE_TYPE PointerMarker;
  1909. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE) ||
  1910. (( pUserFormat->Flags & USER_MARSHAL_REF) && bIsEmbedded) )
  1911. {
  1912. PointerMarker = *((NDR64_PTR_WIRE_TYPE *)pStubMsg->Buffer);
  1913. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  1914. }
  1915. // We always call user's routine to unmarshall the user object.
  1916. // However, the top level object is allocated by the engine.
  1917. // Thus, the behavior is exactly the same as for represent_as(),
  1918. // with regard to the top level presented type.
  1919. if ( *ppMemory == NULL )
  1920. {
  1921. // Allocate a presented type object first.
  1922. uint MemSize = pUserFormat->UserTypeMemorySize;
  1923. *ppMemory = (uchar *) NdrAllocate( pStubMsg, MemSize );
  1924. MIDL_memset( *ppMemory, 0, MemSize );
  1925. }
  1926. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE) && (0 == PointerMarker ))
  1927. {
  1928. // The user type is a unique pointer, and it is 0. So, we are done.
  1929. return;
  1930. }
  1931. if ( pUserFormat->Flags & USER_MARSHAL_POINTER )
  1932. {
  1933. Ndr64UserMarshallPointeeUnmarshall( pStubMsg,
  1934. *ppMemory,
  1935. pFormat );
  1936. return;
  1937. }
  1938. Ndr64UserMarshallUnmarshallInternal( pStubMsg,
  1939. *ppMemory,
  1940. pFormat );
  1941. }
  1942. void
  1943. Ndr64TopLevelUserMarshalUnmarshall (
  1944. PMIDL_STUB_MESSAGE pStubMsg,
  1945. uchar ** ppMemory,
  1946. PNDR64_FORMAT pFormat,
  1947. bool fMustAlloc )
  1948. {
  1949. Ndr64UserMarshalUnmarshall( pStubMsg,
  1950. ppMemory,
  1951. pFormat,
  1952. fMustAlloc,
  1953. false );
  1954. }
  1955. void
  1956. Ndr64EmbeddedUserMarshalUnmarshall (
  1957. PMIDL_STUB_MESSAGE pStubMsg,
  1958. uchar ** ppMemory,
  1959. PNDR64_FORMAT pFormat,
  1960. bool fMustAlloc )
  1961. {
  1962. Ndr64UserMarshalUnmarshall( pStubMsg,
  1963. ppMemory,
  1964. pFormat,
  1965. fMustAlloc,
  1966. true );
  1967. }
  1968. void
  1969. Ndr64ClientContextUnmarshall(
  1970. PMIDL_STUB_MESSAGE pStubMsg,
  1971. NDR_CCONTEXT * pContextHandle,
  1972. RPC_BINDING_HANDLE BindHandle )
  1973. /*++
  1974. Routine Description :
  1975. Unmarshalls a context handle on the client side.
  1976. Arguments :
  1977. pStubMsg - Pointer to stub message.
  1978. pContextHandle - Pointer to context handle to unmarshall.
  1979. BindHandle - The handle value used by the client for binding.
  1980. Return :
  1981. None.
  1982. --*/
  1983. {
  1984. // Note, this is a routine called directly from -Os stubs.
  1985. // The routine called by interpreter is called Ndr64UnmarshallHandle
  1986. // and can be found in hndl.c
  1987. ALIGN(pStubMsg->Buffer,3);
  1988. // All 20 bytes of the buffer are touched so a check is not needed here.
  1989. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + CONTEXT_HANDLE_WIRE_SIZE );
  1990. NDRCContextUnmarshall( pContextHandle,
  1991. BindHandle,
  1992. pStubMsg->Buffer,
  1993. pStubMsg->RpcMsg->DataRepresentation );
  1994. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  1995. }
  1996. NDR_SCONTEXT
  1997. Ndr64ServerContextUnmarshall(
  1998. PMIDL_STUB_MESSAGE pStubMsg )
  1999. /*++
  2000. Routine Description :
  2001. Unmarshalls a context handle on the server side.
  2002. Arguments :
  2003. pStubMsg - Pointer to stub message.
  2004. Return :
  2005. The unmarshalled context handle.
  2006. --*/
  2007. {
  2008. // Note, this is a routine called directly from -Os stubs.
  2009. // The routine called by interpreter is called Ndr64UnmarshallHandle
  2010. // and can be found in hndl.c
  2011. NDR_SCONTEXT Context;
  2012. ALIGN(pStubMsg->Buffer,3);
  2013. // All 20 bytes of the buffer are touched so a check is not needed here.
  2014. // we could corrupt memory if it's out of bound
  2015. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + CONTEXT_HANDLE_WIRE_SIZE );
  2016. Context = NDRSContextUnmarshall2(pStubMsg->RpcMsg->Handle,
  2017. pStubMsg->Buffer,
  2018. pStubMsg->RpcMsg->DataRepresentation,
  2019. RPC_CONTEXT_HANDLE_DEFAULT_GUARD,
  2020. RPC_CONTEXT_HANDLE_DEFAULT_FLAGS );
  2021. if ( ! Context )
  2022. RpcRaiseException( RPC_X_SS_CONTEXT_MISMATCH );
  2023. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  2024. return Context;
  2025. }
  2026. NDR_SCONTEXT
  2027. Ndr64ContextHandleInitialize (
  2028. PMIDL_STUB_MESSAGE pStubMsg,
  2029. PFORMAT_STRING pFormat )
  2030. /*
  2031. This routine is to initialize a context handle with a new NT5 flavor.
  2032. It is used in conjunction with Ndr64ContextHandleUnmarshal.
  2033. */
  2034. {
  2035. NDR_SCONTEXT SContext;
  2036. void * pGuard = RPC_CONTEXT_HANDLE_DEFAULT_GUARD;
  2037. DWORD Flags = RPC_CONTEXT_HANDLE_DEFAULT_FLAGS;
  2038. NDR64_CONTEXT_HANDLE_FORMAT * pContextFormat;
  2039. pContextFormat = ( NDR64_CONTEXT_HANDLE_FORMAT * )pFormat;
  2040. NDR_ASSERT( pContextFormat->FormatCode == FC64_BIND_CONTEXT, "invalid format char " );
  2041. // NT5 beta2 features: strict context handle, serialize and noserialize.
  2042. if ( pContextFormat->ContextFlags & NDR_STRICT_CONTEXT_HANDLE )
  2043. {
  2044. pGuard = pStubMsg->StubDesc->RpcInterfaceInformation;
  2045. pGuard = & ((PRPC_SERVER_INTERFACE)pGuard)->InterfaceId;
  2046. }
  2047. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_NOSERIALIZE )
  2048. {
  2049. Flags = RPC_CONTEXT_HANDLE_DONT_SERIALIZE;
  2050. }
  2051. else if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_SERIALIZE )
  2052. {
  2053. Flags = RPC_CONTEXT_HANDLE_SERIALIZE;
  2054. }
  2055. SContext = NDRSContextUnmarshall2(
  2056. pStubMsg->RpcMsg->Handle,
  2057. (void *)0, // buffer
  2058. pStubMsg->RpcMsg->DataRepresentation,
  2059. pGuard,
  2060. Flags );
  2061. return SContext;
  2062. }
  2063. NDR_SCONTEXT
  2064. Ndr64ServerContextNewUnmarshall(
  2065. PMIDL_STUB_MESSAGE pStubMsg,
  2066. PFORMAT_STRING pFormat )
  2067. /*
  2068. This routine to unmarshal a context handle with a new NT5 flavor.
  2069. For the old style handles, we call an optimized routine
  2070. Ndr64ServerContextUnmarshall below.
  2071. Interpreter calls Ndr64UnmarshallHandle from hndl.c
  2072. ppMemory - note, this is not a pointer to user's context handle but
  2073. a pointer to NDR_SCONTEXT pointer to the runtime internal object.
  2074. User's handle is a field of that object.
  2075. */
  2076. {
  2077. void * pGuard = RPC_CONTEXT_HANDLE_DEFAULT_GUARD;
  2078. DWORD Flags = RPC_CONTEXT_HANDLE_DEFAULT_FLAGS;
  2079. NDR64_CONTEXT_HANDLE_FORMAT *pContextFormat = ( NDR64_CONTEXT_HANDLE_FORMAT * )pFormat;
  2080. NDR_ASSERT( pContextFormat->FormatCode == FC64_BIND_CONTEXT, "invalid format char " );
  2081. // Anti-attack defense for servers, NT5 beta3 feature.
  2082. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL )
  2083. {
  2084. // Check the incoming context handle on the server.
  2085. // Context handle wire layout: ulong with version (always 0), then a uuid.
  2086. //
  2087. if ( !pStubMsg->IsClient && 0 == memcmp( pStubMsg->Buffer + 4,
  2088. &GUID_NULL,
  2089. sizeof(GUID) ) )
  2090. RpcRaiseException( RPC_X_BAD_STUB_DATA );
  2091. }
  2092. // NT5 beta2 features: strict context handle, serialize and noserialize.
  2093. if ( pContextFormat->ContextFlags & NDR_STRICT_CONTEXT_HANDLE )
  2094. {
  2095. pGuard = pStubMsg->StubDesc->RpcInterfaceInformation;
  2096. pGuard = & ((PRPC_SERVER_INTERFACE)pGuard)->InterfaceId;
  2097. }
  2098. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_NOSERIALIZE )
  2099. {
  2100. Flags = RPC_CONTEXT_HANDLE_DONT_SERIALIZE;
  2101. }
  2102. else if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_SERIALIZE )
  2103. {
  2104. Flags = RPC_CONTEXT_HANDLE_SERIALIZE;
  2105. }
  2106. ALIGN( pStubMsg->Buffer, 0x3 );
  2107. // All 20 bytes of the buffer are touched so a check is not needed here.
  2108. NDR_SCONTEXT SContext =
  2109. NDRSContextUnmarshall2(
  2110. pStubMsg->RpcMsg->Handle,
  2111. pStubMsg->Buffer,
  2112. pStubMsg->RpcMsg->DataRepresentation,
  2113. pGuard,
  2114. Flags );
  2115. if ( ! SContext )
  2116. RpcRaiseException( RPC_X_SS_CONTEXT_MISMATCH );
  2117. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  2118. return SContext;
  2119. }
  2120. // define the jump table
  2121. #define NDR64_BEGIN_TABLE \
  2122. PNDR64_UNMARSHALL_ROUTINE extern const Ndr64UnmarshallRoutinesTable[] = \
  2123. {
  2124. #define NDR64_TABLE_END \
  2125. };
  2126. #define NDR64_ZERO_ENTRY NULL
  2127. #define NDR64_UNUSED_TABLE_ENTRY( number, tokenname ) ,NULL
  2128. #define NDR64_UNUSED_TABLE_ENTRY_NOSYM( number ) ,NULL
  2129. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  2130. ,unmarshall
  2131. #define NDR64_SIMPLE_TYPE_TABLE_ENTRY( number, tokenname, buffersize, memorysize) \
  2132. ,Ndr64UDTSimpleTypeUnmarshall1
  2133. #include "tokntbl.h"
  2134. C_ASSERT( sizeof(Ndr64UnmarshallRoutinesTable)/sizeof(PNDR64_UNMARSHALL_ROUTINE) == 256 );
  2135. #undef NDR64_BEGIN_TABLE
  2136. #undef NDR64_TABLE_ENTRY
  2137. #define NDR64_BEGIN_TABLE \
  2138. PNDR64_UNMARSHALL_ROUTINE extern const Ndr64EmbeddedUnmarshallRoutinesTable[] = \
  2139. {
  2140. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  2141. ,embeddedunmarshall
  2142. #include "tokntbl.h"
  2143. C_ASSERT( sizeof(Ndr64EmbeddedUnmarshallRoutinesTable)/sizeof(PNDR64_UNMARSHALL_ROUTINE) == 256 );