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.

2762 lines
85 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(NULL);
  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 = pStructFormat->MemorySize + Ndr64pMultiplyUpTo2GB(
  789. MaxCount , 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_WITH_WRAP_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. Ndr64pMultiplyUpTo2GB( Count, pStringFormat->ElementSize );
  1041. if ( ( Offset != 0 ) ||
  1042. ( 0 == Count ) ||
  1043. ( TransmittedSize > MemorySize ) )
  1044. RpcRaiseException( RPC_X_INVALID_BOUND );
  1045. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, TransmittedSize );
  1046. // In this code, we check that a terminator is
  1047. // where the marshaller tells us it is. We could check
  1048. // if another terminator exists in addition to the other
  1049. // terminator, but it doesn't make sense to do this
  1050. // since it wouldn't close any attacks.
  1051. switch( pStringFormat->FormatCode )
  1052. {
  1053. case FC64_CHAR_STRING:
  1054. case FC64_CONF_CHAR_STRING:
  1055. {
  1056. char *p = (char *) pStubMsg->Buffer;
  1057. NDR64_WIRE_COUNT_TYPE ActualChars = Count - 1;
  1058. if ( '\0' != p[ActualChars] )
  1059. {
  1060. RpcRaiseException( RPC_X_INVALID_BOUND );
  1061. return;
  1062. }
  1063. break;
  1064. }
  1065. case FC64_WCHAR_STRING:
  1066. case FC64_CONF_WCHAR_STRING:
  1067. {
  1068. wchar_t *p = ( wchar_t* ) pStubMsg->Buffer;
  1069. NDR64_WIRE_COUNT_TYPE ActualChars = Count - 1;
  1070. if ( L'\0' != p[ActualChars] )
  1071. {
  1072. RpcRaiseException( RPC_X_INVALID_BOUND );
  1073. return;
  1074. }
  1075. break;
  1076. }
  1077. case FC64_STRUCT_STRING:
  1078. case FC64_CONF_STRUCT_STRING:
  1079. {
  1080. NDR64_UINT8 *p = (NDR64_UINT8 *) pStubMsg->Buffer;
  1081. NDR64_WIRE_COUNT_TYPE ActualChars = Count - 1;
  1082. NDR64_UINT32 ElementSize = pStringFormat->ElementSize;
  1083. NDR64_UINT8 *t = p + Ndr64pMultiplyUpTo2GB( ActualChars , ElementSize );
  1084. if ( !Ndr64pIsStructStringTerminator( t, ElementSize ) )
  1085. {
  1086. RpcRaiseException( RPC_X_INVALID_BOUND );
  1087. return;
  1088. }
  1089. break;
  1090. }
  1091. }
  1092. if ( fMustAlloc )
  1093. {
  1094. *ppMemory = (uchar *) NdrAllocate( pStubMsg, MemorySize );
  1095. }
  1096. else if ( ! *ppMemory )
  1097. {
  1098. *ppMemory = ( TransmittedSize == MemorySize ) ? pStubMsg->Buffer :
  1099. (uchar *) NdrAllocate( pStubMsg, MemorySize );
  1100. }
  1101. if ( *ppMemory != pStubMsg->Buffer )
  1102. {
  1103. RpcpMemoryCopy( *ppMemory,
  1104. pStubMsg->Buffer,
  1105. TransmittedSize );
  1106. }
  1107. pStubMsg->Buffer += TransmittedSize;
  1108. return;
  1109. }
  1110. void
  1111. Ndr64NonConformantStringUnmarshall(
  1112. PMIDL_STUB_MESSAGE pStubMsg,
  1113. uchar ** ppMemory,
  1114. PNDR64_FORMAT pFormat,
  1115. bool fMustAlloc )
  1116. /*++
  1117. Routine description :
  1118. Unmarshalls a non conformant string.
  1119. Arguments :
  1120. pStubMsg - Pointer to the stub message.
  1121. pMemory - Double pointer to the string should be unmarshalled.
  1122. pFormat - String's format string description.
  1123. fMustAlloc - Ignored.
  1124. Return :
  1125. None.
  1126. --*/
  1127. {
  1128. const NDR64_NON_CONFORMANT_STRING_FORMAT * pStringFormat =
  1129. (NDR64_NON_CONFORMANT_STRING_FORMAT*) pFormat;
  1130. Ndr64pCommonStringUnmarshall( pStubMsg,
  1131. ppMemory,
  1132. &pStringFormat->Header,
  1133. fMustAlloc,
  1134. pStringFormat->TotalSize );
  1135. }
  1136. void
  1137. Ndr64ConformantStringUnmarshall(
  1138. PMIDL_STUB_MESSAGE pStubMsg,
  1139. uchar ** ppMemory,
  1140. PNDR64_FORMAT pFormat,
  1141. bool fMustAlloc )
  1142. /*++
  1143. Routine description :
  1144. Unmarshalls a top level conformant string.
  1145. Arguments :
  1146. pStubMsg - Pointer to the stub message.
  1147. ppMemory - Double pointer to where the string should be unmarshalled.
  1148. pFormat - String's format string description.
  1149. fMustAlloc - TRUE if the string must be allocated, FALSE otherwise.
  1150. Return :
  1151. None.
  1152. --*/
  1153. {
  1154. const NDR64_CONFORMANT_STRING_FORMAT * pStringFormat =
  1155. (const NDR64_CONFORMANT_STRING_FORMAT*) pFormat;
  1156. const NDR64_SIZED_CONFORMANT_STRING_FORMAT *pSizedStringFormat =
  1157. (const NDR64_SIZED_CONFORMANT_STRING_FORMAT*) pFormat;
  1158. NDR64_WIRE_COUNT_TYPE MaxCount;
  1159. if ( !NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1160. {
  1161. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1162. MaxCount = *((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer);
  1163. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  1164. }
  1165. else
  1166. {
  1167. MaxCount = *(NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  1168. }
  1169. NDR64_UINT32 AllocationSize =
  1170. Ndr64pMultiplyUpTo2GB( MaxCount ,
  1171. pStringFormat->Header.ElementSize );
  1172. if ( pStringFormat->Header.Flags.IsSized )
  1173. {
  1174. Ndr64pCheckCorrelation( pStubMsg,
  1175. MaxCount,
  1176. pSizedStringFormat->SizeDescription,
  1177. EXPR_MAXCOUNT );
  1178. }
  1179. return
  1180. Ndr64pCommonStringUnmarshall( pStubMsg,
  1181. ppMemory,
  1182. &pStringFormat->Header,
  1183. fMustAlloc,
  1184. AllocationSize );
  1185. }
  1186. void
  1187. Ndr64FixedArrayUnmarshall(
  1188. PMIDL_STUB_MESSAGE pStubMsg,
  1189. uchar ** ppMemory,
  1190. PNDR64_FORMAT pFormat,
  1191. bool fMustAlloc )
  1192. /*++
  1193. Routine Description :
  1194. Unmarshalls a fixed array of any number of dimensions.
  1195. Arguments :
  1196. pStubMsg - Pointer to the stub message.
  1197. ppMemory - Pointer to the array to unmarshall.
  1198. pFormat - Array's format string description.
  1199. fMustAlloc - TRUE if the array must be allocated, FALSE otherwise.
  1200. Return :
  1201. None.
  1202. --*/
  1203. {
  1204. const NDR64_FIX_ARRAY_HEADER_FORMAT * pArrayFormat =
  1205. (NDR64_FIX_ARRAY_HEADER_FORMAT*) pFormat;
  1206. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1207. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment );
  1208. uchar *pBufferStart = pStubMsg->Buffer;
  1209. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer , pArrayFormat->TotalSize );
  1210. pStubMsg->Buffer += pArrayFormat->TotalSize;
  1211. if ( fMustAlloc )
  1212. {
  1213. *ppMemory = (uchar *) NdrAllocate( pStubMsg, pArrayFormat->TotalSize );
  1214. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1215. }
  1216. else if ( !*ppMemory )
  1217. {
  1218. *ppMemory = pBufferStart;
  1219. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1220. }
  1221. if ( pArrayFormat->Flags.HasPointerInfo )
  1222. {
  1223. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1224. pArrayFormat + 1,
  1225. 0,
  1226. *ppMemory,
  1227. pBufferStart );
  1228. }
  1229. if ( *ppMemory != pBufferStart )
  1230. {
  1231. RpcpMemoryCopy( *ppMemory,
  1232. pBufferStart,
  1233. pArrayFormat->TotalSize );
  1234. }
  1235. }
  1236. void
  1237. Ndr64ConformantArrayUnmarshall(
  1238. PMIDL_STUB_MESSAGE pStubMsg,
  1239. uchar ** ppMemory,
  1240. PNDR64_FORMAT pFormat,
  1241. bool fMustAlloc )
  1242. /*++
  1243. Routine Description :
  1244. Unmarshalls a top level one dimensional conformant array.
  1245. Used for FC64_CARRAY.
  1246. Arguments :
  1247. pStubMsg - Pointer to the stub message.
  1248. ppMemory - Pointer to array to be unmarshalled.
  1249. pFormat - Array's format string description.
  1250. Return :
  1251. None.
  1252. --*/
  1253. {
  1254. const NDR64_CONF_ARRAY_HEADER_FORMAT *pArrayFormat =
  1255. (NDR64_CONF_ARRAY_HEADER_FORMAT*) pFormat;
  1256. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1257. NDR64_WIRE_COUNT_TYPE MaxCount;
  1258. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1259. {
  1260. // Align the buffer for conformance marshalling.
  1261. ALIGN(pStubMsg->Buffer,NDR64_WIRE_COUNT_ALIGN);
  1262. MaxCount = *((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer);
  1263. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  1264. }
  1265. else
  1266. {
  1267. MaxCount = *pStubMsg->ConformanceMark;
  1268. }
  1269. NDR64_UINT32 CopySize =
  1270. Ndr64pMultiplyUpTo2GB( MaxCount , pArrayFormat->ElementSize );
  1271. Ndr64pCheckCorrelation( pStubMsg,
  1272. MaxCount,
  1273. pArrayFormat->ConfDescriptor,
  1274. EXPR_MAXCOUNT );
  1275. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  1276. uchar *pBufferStart = pStubMsg->Buffer;
  1277. CHECK_EOB_WITH_WRAP_RAISE_IB( pStubMsg->Buffer, CopySize);
  1278. pStubMsg->Buffer += CopySize; // Unmarshall embedded pointers.
  1279. if ( fMustAlloc )
  1280. {
  1281. *ppMemory = (uchar *) NdrAllocate( pStubMsg, CopySize );
  1282. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1283. }
  1284. else if ( !*ppMemory )
  1285. {
  1286. *ppMemory = pBufferStart;
  1287. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1288. }
  1289. if ( pArrayFormat->Flags.HasPointerInfo )
  1290. {
  1291. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1292. pArrayFormat + 1,
  1293. (NDR64_UINT32)MaxCount,
  1294. *ppMemory,
  1295. pBufferStart );
  1296. }
  1297. if ( *ppMemory != pBufferStart )
  1298. {
  1299. RpcpMemoryCopy( *ppMemory,
  1300. pBufferStart,
  1301. CopySize );
  1302. }
  1303. }
  1304. void
  1305. Ndr64ConformantVaryingArrayUnmarshall(
  1306. PMIDL_STUB_MESSAGE pStubMsg,
  1307. uchar ** ppMemory,
  1308. PNDR64_FORMAT pFormat,
  1309. bool fMustAlloc )
  1310. /*++
  1311. Routine Description :
  1312. Unmarshalls a top level one dimensional conformant varying array.
  1313. Used for FC64_CVARRAY.
  1314. Arguments :
  1315. pStubMsg - Pointer to the stub message.
  1316. ppMemory - Pointer to the array being unmarshalled.
  1317. pFormat - Array's format string description.
  1318. fMustAlloc - Ignored.
  1319. Return :
  1320. None.
  1321. --*/
  1322. {
  1323. const NDR64_CONF_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  1324. (NDR64_CONF_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  1325. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags);
  1326. NDR64_WIRE_COUNT_TYPE MaxCount;
  1327. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1328. {
  1329. // Align the buffer for conformance unmarshalling.
  1330. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1331. MaxCount = *((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer);
  1332. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE);
  1333. }
  1334. else
  1335. {
  1336. MaxCount = *(NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  1337. }
  1338. ALIGN( pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1339. NDR64_WIRE_COUNT_TYPE Offset = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[0];
  1340. NDR64_WIRE_COUNT_TYPE ActualCount = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->Buffer)[1];
  1341. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1342. NDR64_UINT32 AllocSize = Ndr64pMultiplyUpTo2GB( MaxCount , pArrayFormat->ElementSize );
  1343. NDR64_UINT32 CopySize = Ndr64pMultiplyUpTo2GB( ActualCount , pArrayFormat->ElementSize );
  1344. if ( ( Offset != 0 ) ||
  1345. ActualCount > MaxCount )
  1346. RpcRaiseException( RPC_X_INVALID_BOUND );
  1347. Ndr64pCheckCorrelation( pStubMsg,
  1348. MaxCount,
  1349. pArrayFormat->ConfDescriptor,
  1350. EXPR_MAXCOUNT );
  1351. Ndr64pCheckCorrelation( pStubMsg,
  1352. ActualCount,
  1353. pArrayFormat->VarDescriptor,
  1354. EXPR_ACTUALCOUNT );
  1355. //
  1356. // For a conformant varying array, we can't reuse the buffer
  1357. // because it doesn't hold the total size of the array.
  1358. if ( fMustAlloc || !*ppMemory )
  1359. {
  1360. *ppMemory = (uchar *) NdrAllocate( pStubMsg, AllocSize );
  1361. memset( *ppMemory, 0, AllocSize );
  1362. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1363. }
  1364. ALIGN( pStubMsg->Buffer, pArrayFormat->Alignment );
  1365. CHECK_EOB_WITH_WRAP_RAISE_IB( pStubMsg->Buffer, CopySize);
  1366. uchar *pBufferStart = pStubMsg->Buffer;
  1367. pStubMsg->Buffer += CopySize;
  1368. if ( pArrayFormat->Flags.HasPointerInfo )
  1369. {
  1370. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1371. pArrayFormat + 1,
  1372. (NDR64_UINT32)ActualCount,
  1373. *ppMemory,
  1374. pBufferStart );
  1375. }
  1376. RpcpMemoryCopy( *ppMemory,
  1377. pBufferStart,
  1378. CopySize );
  1379. }
  1380. void
  1381. Ndr64VaryingArrayUnmarshall(
  1382. PMIDL_STUB_MESSAGE pStubMsg,
  1383. uchar ** ppMemory,
  1384. PNDR64_FORMAT pFormat,
  1385. bool fMustAlloc )
  1386. /*++
  1387. Routine Description :
  1388. Unmarshalls top level or embedded a one dimensional varying array.
  1389. Arguments :
  1390. pStubMsg - Pointer to the stub message.
  1391. pMemory - Array being unmarshalled.
  1392. pFormat - Array's format string description.
  1393. fMustAlloc - Ignored.
  1394. --*/
  1395. {
  1396. const NDR64_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  1397. (NDR64_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  1398. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1399. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1400. NDR64_WIRE_COUNT_TYPE Offset = ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[0];
  1401. NDR64_WIRE_COUNT_TYPE ActualCount = ((NDR64_WIRE_COUNT_TYPE *)pStubMsg->Buffer)[1];
  1402. pStubMsg->Buffer += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1403. NDR64_UINT32 CopySize
  1404. = Ndr64pMultiplyUpTo2GB( ActualCount , pArrayFormat->ElementSize );
  1405. if ( ( Offset != 0 ) ||
  1406. ( CopySize > pArrayFormat->TotalSize ) )
  1407. RpcRaiseException( RPC_X_INVALID_BOUND );
  1408. Ndr64pCheckCorrelation( pStubMsg,
  1409. ActualCount,
  1410. pArrayFormat->VarDescriptor,
  1411. EXPR_ACTUALCOUNT );
  1412. if ( fMustAlloc || !*ppMemory )
  1413. {
  1414. *ppMemory = (uchar *) NdrAllocate( pStubMsg, pArrayFormat->TotalSize );
  1415. memset( *ppMemory, 0, pArrayFormat->TotalSize );
  1416. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1417. }
  1418. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment );
  1419. CHECK_EOB_WITH_WRAP_RAISE_IB( pStubMsg->Buffer, CopySize );
  1420. uchar *pBufferStart = pStubMsg->Buffer;
  1421. pStubMsg->Buffer += CopySize;
  1422. if ( pArrayFormat->Flags.HasPointerInfo )
  1423. {
  1424. Ndr64pPointerLayoutUnmarshall( pStubMsg,
  1425. pArrayFormat + 1,
  1426. (NDR64_UINT32)ActualCount,
  1427. *ppMemory,
  1428. pBufferStart );
  1429. }
  1430. RpcpMemoryCopy( *ppMemory,
  1431. pBufferStart,
  1432. CopySize );
  1433. }
  1434. void
  1435. Ndr64ComplexArrayUnmarshall(
  1436. PMIDL_STUB_MESSAGE pStubMsg,
  1437. uchar ** ppMemory,
  1438. PNDR64_FORMAT pFormat,
  1439. bool fMustAlloc )
  1440. /*++
  1441. Routine Description :
  1442. Unmarshalls a top level complex array.
  1443. Arguments :
  1444. pStubMsg - Pointer to the stub message.
  1445. ppMemory - Pointer to the array being unmarshalled.
  1446. pFormat - Array's format string description.
  1447. fMustAlloc - Ignored.
  1448. Return :
  1449. None.
  1450. --*/
  1451. {
  1452. const NDR64_BOGUS_ARRAY_HEADER_FORMAT *pArrayFormat =
  1453. (NDR64_BOGUS_ARRAY_HEADER_FORMAT *) pFormat;
  1454. bool fSetPointerBufferMark = ! pStubMsg->PointerBufferMark;
  1455. if ( fSetPointerBufferMark )
  1456. {
  1457. uchar *pBuffer = pStubMsg->Buffer;
  1458. BOOL fOldIgnore = pStubMsg->IgnoreEmbeddedPointers;
  1459. pStubMsg->IgnoreEmbeddedPointers = TRUE;
  1460. pStubMsg->MemorySize = 0;
  1461. Ndr64ComplexArrayMemorySize(
  1462. pStubMsg,
  1463. pFormat );
  1464. // make sure we haven't overflow for the flat part.
  1465. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer );
  1466. pStubMsg->PointerBufferMark = pStubMsg->Buffer;
  1467. pStubMsg->IgnoreEmbeddedPointers = fOldIgnore;
  1468. pStubMsg->Buffer = pBuffer;
  1469. }
  1470. BOOL IsFixed = ( pArrayFormat->FormatCode == FC64_FIX_BOGUS_ARRAY ) ||
  1471. ( pArrayFormat->FormatCode == FC64_FIX_FORCED_BOGUS_ARRAY );
  1472. SAVE_CONTEXT<uchar> uFlagsSave(pStubMsg->uFlags);
  1473. SAVE_CONTEXT<uchar*> ConformanceMarkSave( pStubMsg->ConformanceMark );
  1474. SAVE_CONTEXT<uchar*> VarianceMarkSave( pStubMsg->VarianceMark );
  1475. PFORMAT_STRING pElementFormat = (PFORMAT_STRING)pArrayFormat->Element;
  1476. NDR64_WIRE_COUNT_TYPE Elements = pArrayFormat->NumberElements;
  1477. NDR64_WIRE_COUNT_TYPE Count = Elements;
  1478. NDR64_WIRE_COUNT_TYPE Offset = 0;
  1479. if ( !IsFixed )
  1480. {
  1481. const NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT* pConfVarFormat=
  1482. (NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT*)pFormat;
  1483. //
  1484. // Check for conformance description.
  1485. //
  1486. if ( pConfVarFormat->ConfDescription )
  1487. {
  1488. if ( ! NDR64_IS_CONF_MARK_VALID( pStubMsg->uFlags ) )
  1489. {
  1490. //
  1491. // Outer most dimension sets the conformance marker.
  1492. //
  1493. // Align the buffer for conformance marshalling.
  1494. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN);
  1495. // Mark where the conformance count(s) will be marshalled.
  1496. pStubMsg->ConformanceMark = pStubMsg->Buffer;
  1497. // Increment past where the conformance will go.
  1498. NDR64_UINT32 ConfSize = pArrayFormat->NumberDims*sizeof(NDR64_WIRE_COUNT_TYPE) ;
  1499. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, ConfSize);
  1500. pStubMsg->Buffer += ConfSize;
  1501. NDR64_SET_CONF_MARK_VALID( pStubMsg->uFlags );
  1502. }
  1503. Elements = *(NDR64_WIRE_COUNT_TYPE*)pStubMsg->ConformanceMark;
  1504. pStubMsg->ConformanceMark += sizeof(NDR64_WIRE_COUNT_TYPE);
  1505. Ndr64pCheckCorrelation( pStubMsg,
  1506. Elements,
  1507. pConfVarFormat->ConfDescription,
  1508. EXPR_MAXCOUNT );
  1509. Offset = 0;
  1510. Count = Elements;
  1511. }
  1512. //
  1513. // Check for variance description.
  1514. //
  1515. if ( pConfVarFormat->VarDescription )
  1516. {
  1517. if ( ! NDR64_IS_VAR_MARK_VALID( pStubMsg->uFlags ) )
  1518. {
  1519. NDR64_UINT32 Dimensions;
  1520. ALIGN(pStubMsg->Buffer, NDR64_WIRE_COUNT_ALIGN );
  1521. Dimensions = ( pArrayFormat->Flags.IsArrayofStrings ) ? ( pArrayFormat->NumberDims - 1) :
  1522. ( pArrayFormat->NumberDims );
  1523. pStubMsg->VarianceMark = pStubMsg->Buffer;
  1524. NDR64_UINT32 VaryingSize = Dimensions * sizeof(NDR64_WIRE_COUNT_TYPE) * 2 ;
  1525. CHECK_EOB_WITH_WRAP_RAISE_BSD( pStubMsg->Buffer, VaryingSize);
  1526. pStubMsg->Buffer += VaryingSize;
  1527. if ( NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  1528. NDR64_SET_VAR_MARK_VALID( pStubMsg->uFlags );
  1529. }
  1530. else if ( !NDR64_IS_ARRAY_OR_STRING( *pElementFormat ) )
  1531. NDR64_RESET_VAR_MARK_VALID( pStubMsg->uFlags );
  1532. Offset = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->VarianceMark)[0];
  1533. Count = ((NDR64_WIRE_COUNT_TYPE*)pStubMsg->VarianceMark)[1];
  1534. pStubMsg->VarianceMark += sizeof(NDR64_WIRE_COUNT_TYPE) * 2;
  1535. Ndr64pCheckCorrelation( pStubMsg,
  1536. Count,
  1537. pConfVarFormat->VarDescription,
  1538. EXPR_ACTUALCOUNT );
  1539. Ndr64pCheckCorrelation( pStubMsg,
  1540. Offset,
  1541. pConfVarFormat->OffsetDescription,
  1542. EXPR_OFFSET );
  1543. }
  1544. }
  1545. NDR64_UINT32 ElementMemorySize =
  1546. Ndr64pMemorySize( pStubMsg,
  1547. pElementFormat,
  1548. TRUE );
  1549. NDR64_UINT32 ArraySize = Ndr64pMultiplyUpTo2GB( Elements , ElementMemorySize );
  1550. Ndr64pMultiplyUpTo2GB( Count , ElementMemorySize );
  1551. if ( fMustAlloc || ! *ppMemory )
  1552. {
  1553. *ppMemory = (uchar*)NdrAllocate( pStubMsg, (uint) ArraySize );
  1554. memset( *ppMemory, 0, ArraySize );
  1555. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1556. }
  1557. if ( pStubMsg->FullPtrRefId )
  1558. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  1559. uchar *pMemory = *ppMemory;
  1560. pMemory += Ndr64pMultiplyUpTo2GB(Offset , ElementMemorySize);
  1561. ALIGN(pStubMsg->Buffer, pArrayFormat->Alignment);
  1562. for( ; Count--; )
  1563. {
  1564. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1565. &pMemory,
  1566. pElementFormat );
  1567. pMemory += ElementMemorySize;
  1568. }
  1569. if ( fSetPointerBufferMark )
  1570. {
  1571. pStubMsg->Buffer = pStubMsg->PointerBufferMark;
  1572. pStubMsg->PointerBufferMark = 0;
  1573. }
  1574. }
  1575. void
  1576. Ndr64UnionUnmarshall (
  1577. PMIDL_STUB_MESSAGE pStubMsg,
  1578. uchar ** ppMemory,
  1579. PNDR64_FORMAT pFormat,
  1580. bool fMustAlloc )
  1581. /*++
  1582. Routine Description :
  1583. Unmarshalls an encapsulated array.
  1584. Arguments :
  1585. pStubMsg - Pointer to the stub message.
  1586. ppMemory - Double pointer to where the union should be unmarshalled.
  1587. pFormat - Union's format string description.
  1588. fMustAlloc - Ignored.
  1589. Return :
  1590. None.
  1591. --*/
  1592. {
  1593. const NDR64_UNION_ARM_SELECTOR* pArmSelector;
  1594. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  1595. EXPR_VALUE SwitchIs;
  1596. uchar* pArmMemory;
  1597. switch(*(PFORMAT_STRING)pFormat)
  1598. {
  1599. case FC64_NON_ENCAPSULATED_UNION:
  1600. {
  1601. const NDR64_NON_ENCAPSULATED_UNION* pNonEncapUnionFormat =
  1602. (const NDR64_NON_ENCAPSULATED_UNION*) pFormat;
  1603. ALIGN(pStubMsg->Buffer, pNonEncapUnionFormat->Alignment);
  1604. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pNonEncapUnionFormat + 1);
  1605. if ( fMustAlloc || ! *ppMemory )
  1606. {
  1607. *ppMemory = (uchar*)NdrAllocate( pStubMsg, pNonEncapUnionFormat->MemorySize );
  1608. //
  1609. // We must zero out all of the new memory in case there are pointers
  1610. // in any of the arms.
  1611. //
  1612. MIDL_memset( *ppMemory, 0, pNonEncapUnionFormat->MemorySize );
  1613. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1614. }
  1615. SwitchIs = Ndr64pSimpleTypeToExprValue( pNonEncapUnionFormat->SwitchType,
  1616. pStubMsg->Buffer );
  1617. pStubMsg->Buffer += NDR64_SIMPLE_TYPE_BUFSIZE( pNonEncapUnionFormat->SwitchType );
  1618. Ndr64pCheckCorrelation( pStubMsg,
  1619. SwitchIs,
  1620. pNonEncapUnionFormat->Switch,
  1621. EXPR_SWITCHIS );
  1622. pArmMemory = *ppMemory;
  1623. break;
  1624. }
  1625. case FC64_ENCAPSULATED_UNION:
  1626. {
  1627. const NDR64_ENCAPSULATED_UNION* pEncapUnionFormat =
  1628. (const NDR64_ENCAPSULATED_UNION*)pFormat;
  1629. ALIGN(pStubMsg->Buffer, pEncapUnionFormat->Alignment);
  1630. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pEncapUnionFormat + 1);
  1631. if ( fMustAlloc || ! *ppMemory )
  1632. {
  1633. *ppMemory = (uchar*)NdrAllocate( pStubMsg, pEncapUnionFormat->MemorySize );
  1634. //
  1635. // We must zero out all of the new memory in case there are pointers
  1636. // in any of the arms.
  1637. //
  1638. MIDL_memset( *ppMemory, 0, pEncapUnionFormat->MemorySize );
  1639. NDR64_SET_NEW_EMBEDDED_ALLOCATION(pStubMsg->uFlags);
  1640. }
  1641. SwitchIs = Ndr64pSimpleTypeToExprValue( pEncapUnionFormat->SwitchType,
  1642. pStubMsg->Buffer );
  1643. Ndr64SimpleTypeUnmarshall( pStubMsg,
  1644. *ppMemory,
  1645. pEncapUnionFormat->SwitchType );
  1646. pArmMemory = *ppMemory + pEncapUnionFormat->MemoryOffset;
  1647. break;
  1648. }
  1649. default:
  1650. NDR_ASSERT("Bad union format\n", 0);
  1651. return;
  1652. }
  1653. if ( pStubMsg->FullPtrRefId )
  1654. FULL_POINTER_INSERT( pStubMsg, *ppMemory );
  1655. ALIGN(pStubMsg->Buffer, pArmSelector->Alignment);
  1656. PNDR64_FORMAT pArmFormat =
  1657. Ndr64pFindUnionArm( pStubMsg,
  1658. pArmSelector,
  1659. SwitchIs );
  1660. // check we aren't EOB after unmarshalling arm selector
  1661. // we won't corrupt memory as there is no in place unmarshall here.
  1662. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer );
  1663. if ( pArmFormat )
  1664. {
  1665. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1666. &pArmMemory,
  1667. pArmFormat );
  1668. }
  1669. }
  1670. void
  1671. Ndr64XmitOrRepAsUnmarshall (
  1672. PMIDL_STUB_MESSAGE pStubMsg,
  1673. uchar ** ppMemory,
  1674. PNDR64_FORMAT pFormat,
  1675. bool /*fMustAlloc*/,
  1676. bool bIsEmbedded )
  1677. /*++
  1678. Routine Description :
  1679. Unmarshalls a transmit as (or represent as)object.
  1680. Means: allocate the transmitted object,
  1681. unmarshall transmitted object,
  1682. translate the transmitted into presented
  1683. free the transmitted.
  1684. See mrshl.c for the description of the FC layout.
  1685. Arguments :
  1686. pStubMsg - a pointer to the stub message
  1687. ppMemory - pointer to the presented type where to put data
  1688. pFormat - format string description
  1689. fMustAlloc - allocate flag
  1690. Note.
  1691. fMustAlloc is ignored as we always allocate outside of the buffer.
  1692. --*/
  1693. {
  1694. unsigned char * pPresentedType = *ppMemory;
  1695. const XMIT_ROUTINE_QUINTUPLE * pQuintuple = pStubMsg->StubDesc->aXmitQuintuple;
  1696. NDR64_TRANSMIT_AS_FORMAT *pTransFormat =
  1697. ( NDR64_TRANSMIT_AS_FORMAT *) pFormat;
  1698. NDR_ASSERT( pTransFormat->FormatCode == FC64_TRANSMIT_AS || pTransFormat->FormatCode , "invalid format string for user marshal" );
  1699. unsigned short QIndex = pTransFormat->RoutineIndex;
  1700. unsigned long PresentedTypeSize = pTransFormat->PresentedTypeMemorySize;
  1701. if ( ! pPresentedType )
  1702. {
  1703. pPresentedType = (uchar*)NdrAllocate( pStubMsg, (uint) PresentedTypeSize );
  1704. MIDL_memset( pPresentedType, 0, (uint) PresentedTypeSize );
  1705. }
  1706. // Allocate the transmitted object outside of the buffer
  1707. // and unmarshall into it
  1708. if ( NDR64_IS_SIMPLE_TYPE( *(PFORMAT_STRING)pTransFormat->TransmittedType ))
  1709. {
  1710. __int64 SimpleTypeValueBuffer[2];
  1711. unsigned char * pTransmittedType = (unsigned char *)SimpleTypeValueBuffer;
  1712. Ndr64SimpleTypeUnmarshall( pStubMsg,
  1713. pTransmittedType,
  1714. *(PFORMAT_STRING)pTransFormat->TransmittedType );
  1715. // Translate from the transmitted type into the presented type.
  1716. pStubMsg->pTransmitType = pTransmittedType;
  1717. pStubMsg->pPresentedType = pPresentedType;
  1718. pQuintuple[ QIndex ].pfnTranslateFromXmit( pStubMsg );
  1719. *ppMemory = pStubMsg->pPresentedType;
  1720. }
  1721. else
  1722. {
  1723. // Save the current state of the memory list so that the temporary
  1724. // memory allocated for the transmitted type can be easily removed
  1725. // from the list. This assumes that the memory allocated here
  1726. // will not have any linkes to other blocks of memory. This is true
  1727. // as long as full pointers are not used. Fortunatly, full pointers
  1728. // do not work correctly in the current code.
  1729. void *pMemoryListSave = pStubMsg->pMemoryList;
  1730. unsigned char *pTransmittedType = NULL; // asking the engine to allocate
  1731. // In NDR64, Xmit/Rep cannot be a pointer or contain a pointer.
  1732. // So we don't need to worry about the pointer queue here.
  1733. if ( bIsEmbedded )
  1734. {
  1735. Ndr64EmbeddedTypeUnmarshall( pStubMsg,
  1736. &pTransmittedType,
  1737. pTransFormat->TransmittedType );
  1738. }
  1739. else
  1740. {
  1741. Ndr64TopLevelTypeUnmarshall( pStubMsg,
  1742. &pTransmittedType,
  1743. pTransFormat->TransmittedType,
  1744. TRUE );
  1745. }
  1746. // Translate from the transmitted type into the presented type.
  1747. pStubMsg->pTransmitType = pTransmittedType;
  1748. pStubMsg->pPresentedType = pPresentedType;
  1749. pQuintuple[ QIndex ].pfnTranslateFromXmit( pStubMsg );
  1750. *ppMemory = pStubMsg->pPresentedType;
  1751. // Free the transmitted object (it was allocated by the engine)
  1752. // and its pointees. The call through the table frees the pointees
  1753. // only (plus it'd free the object itself if it were a pointer).
  1754. // As the transmitted type is not a pointer here, we need to free it
  1755. // explicitely later.
  1756. // Remove the memory that will be freed from the allocated memory
  1757. // list by restoring the memory list pointer.
  1758. // If an exception occures during one of these free routines, we
  1759. // are in trouble anyway.
  1760. pStubMsg->pMemoryList = pMemoryListSave;
  1761. if ( bIsEmbedded )
  1762. {
  1763. Ndr64EmbeddedTypeFree( pStubMsg,
  1764. pTransmittedType,
  1765. pTransFormat->TransmittedType );
  1766. }
  1767. else
  1768. {
  1769. Ndr64ToplevelTypeFree( pStubMsg,
  1770. pTransmittedType,
  1771. pTransFormat->TransmittedType );
  1772. }
  1773. // The buffer reusage check.
  1774. if ( pTransmittedType < pStubMsg->BufferStart ||
  1775. pTransmittedType > pStubMsg->BufferEnd )
  1776. (*pStubMsg->pfnFree)( pTransmittedType );
  1777. }
  1778. }
  1779. void
  1780. Ndr64TopLevelXmitOrRepAsUnmarshall (
  1781. PMIDL_STUB_MESSAGE pStubMsg,
  1782. uchar ** ppMemory,
  1783. PNDR64_FORMAT pFormat,
  1784. bool fMustAlloc )
  1785. {
  1786. Ndr64XmitOrRepAsUnmarshall( pStubMsg,
  1787. ppMemory,
  1788. pFormat,
  1789. fMustAlloc,
  1790. false );
  1791. }
  1792. void
  1793. Ndr64EmbeddedXmitOrRepAsUnmarshall (
  1794. PMIDL_STUB_MESSAGE pStubMsg,
  1795. uchar ** ppMemory,
  1796. PNDR64_FORMAT pFormat,
  1797. bool fMustAlloc )
  1798. {
  1799. Ndr64XmitOrRepAsUnmarshall( pStubMsg,
  1800. ppMemory,
  1801. pFormat,
  1802. fMustAlloc,
  1803. true );
  1804. }
  1805. void
  1806. Ndr64UserMarshallUnmarshallInternal(
  1807. PMIDL_STUB_MESSAGE pStubMsg,
  1808. uchar * pMemory,
  1809. PNDR64_FORMAT pFormat )
  1810. {
  1811. NDR64_USER_MARSHAL_FORMAT *pUserFormat =
  1812. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1813. unsigned char * pUserBuffer = pStubMsg->Buffer;
  1814. unsigned char * pUserBufferSaved = pUserBuffer;
  1815. USER_MARSHAL_CB UserMarshalCB;
  1816. Ndr64pInitUserMarshalCB( pStubMsg,
  1817. pUserFormat,
  1818. USER_MARSHAL_CB_UNMARSHALL,
  1819. & UserMarshalCB );
  1820. unsigned short QIndex = pUserFormat->RoutineIndex;
  1821. const USER_MARSHAL_ROUTINE_QUADRUPLE * pQuadruple = (const USER_MARSHAL_ROUTINE_QUADRUPLE * )
  1822. ( ( NDR_PROC_CONTEXT *)pStubMsg->pContext )->pSyntaxInfo->aUserMarshalQuadruple;
  1823. if ((pUserBufferSaved < (uchar *) pStubMsg->RpcMsg->Buffer) ||
  1824. ((unsigned long) (pUserBufferSaved - (uchar *) pStubMsg->RpcMsg->Buffer)
  1825. > pStubMsg->RpcMsg->BufferLength))
  1826. {
  1827. RpcRaiseException( RPC_X_INVALID_BUFFER );
  1828. }
  1829. pUserBuffer = pQuadruple[ QIndex ].pfnUnmarshall( (ulong*) &UserMarshalCB,
  1830. pUserBuffer,
  1831. pMemory );
  1832. if ((pUserBufferSaved > pUserBuffer) ||
  1833. ((unsigned long) (pUserBuffer - (uchar *) pStubMsg->RpcMsg->Buffer)
  1834. > pStubMsg->RpcMsg->BufferLength ))
  1835. {
  1836. RpcRaiseException( RPC_X_INVALID_BUFFER );
  1837. }
  1838. // Step over the pointee.
  1839. pStubMsg->Buffer = pUserBuffer;
  1840. }
  1841. void
  1842. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT::Dispatch(MIDL_STUB_MESSAGE *pStubMsg)
  1843. {
  1844. Ndr64UserMarshallUnmarshallInternal( pStubMsg,
  1845. pMemory,
  1846. pFormat );
  1847. }
  1848. #if defined(DBG)
  1849. void
  1850. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT::Print()
  1851. {
  1852. DbgPrint("NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT\n");
  1853. DbgPrint("pMemory: %p\n", pMemory );
  1854. DbgPrint("pFormat: %p\n", pFormat );
  1855. }
  1856. #endif
  1857. void
  1858. Ndr64UserMarshallPointeeUnmarshall(
  1859. PMIDL_STUB_MESSAGE pStubMsg,
  1860. uchar * pMemory,
  1861. PNDR64_FORMAT pFormat )
  1862. {
  1863. if ( !pStubMsg->pPointerQueueState ||
  1864. !pStubMsg->pPointerQueueState->GetActiveQueue() )
  1865. {
  1866. POINTER_BUFFER_SWAP_CONTEXT SwapContext(pStubMsg);
  1867. Ndr64UserMarshallUnmarshallInternal(
  1868. pStubMsg,
  1869. pMemory,
  1870. pFormat );
  1871. return;
  1872. }
  1873. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT*pElement =
  1874. new(pStubMsg->pPointerQueueState)
  1875. NDR64_USR_MRSHL_UNMRSHL_POINTER_QUEUE_ELEMENT(pMemory,
  1876. (PFORMAT_STRING)pFormat );
  1877. pStubMsg->pPointerQueueState->GetActiveQueue()->Enque( pElement );
  1878. }
  1879. void
  1880. Ndr64UserMarshalUnmarshall (
  1881. PMIDL_STUB_MESSAGE pStubMsg,
  1882. uchar ** ppMemory,
  1883. PNDR64_FORMAT pFormat,
  1884. bool fMustAlloc,
  1885. bool bIsEmbedded )
  1886. /*++
  1887. Routine Description :
  1888. Unmarshals a user_marshal object.
  1889. The layout is described in marshalling.
  1890. Arguments :
  1891. pStubMsg - Pointer to the stub message.
  1892. ppMemory - Pointer to pointer to the usr_marshall object to unmarshall.
  1893. pFormat - Object's format string description.
  1894. Return :
  1895. None.
  1896. --*/
  1897. {
  1898. NDR64_USER_MARSHAL_FORMAT *pUserFormat =
  1899. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  1900. NDR_ASSERT( pUserFormat->FormatCode == FC64_USER_MARSHAL, "invalid format string for user marshal" );
  1901. // Align for the object or a pointer to it.
  1902. ALIGN( pStubMsg->Buffer, pUserFormat->TransmittedTypeWireAlignment );
  1903. // Take care of the pointer, if any.
  1904. NDR64_PTR_WIRE_TYPE PointerMarker;
  1905. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE) ||
  1906. (( pUserFormat->Flags & USER_MARSHAL_REF) && bIsEmbedded) )
  1907. {
  1908. PointerMarker = *((NDR64_PTR_WIRE_TYPE *)pStubMsg->Buffer);
  1909. pStubMsg->Buffer += sizeof(NDR64_PTR_WIRE_TYPE);
  1910. }
  1911. // We always call user's routine to unmarshall the user object.
  1912. // However, the top level object is allocated by the engine.
  1913. // Thus, the behavior is exactly the same as for represent_as(),
  1914. // with regard to the top level presented type.
  1915. if ( *ppMemory == NULL )
  1916. {
  1917. // Allocate a presented type object first.
  1918. uint MemSize = pUserFormat->UserTypeMemorySize;
  1919. *ppMemory = (uchar *) NdrAllocate( pStubMsg, MemSize );
  1920. MIDL_memset( *ppMemory, 0, MemSize );
  1921. }
  1922. if ( ( pUserFormat->Flags & USER_MARSHAL_UNIQUE) && (0 == PointerMarker ))
  1923. {
  1924. // The user type is a unique pointer, and it is 0. So, we are done.
  1925. return;
  1926. }
  1927. if ( pUserFormat->Flags & USER_MARSHAL_POINTER )
  1928. {
  1929. Ndr64UserMarshallPointeeUnmarshall( pStubMsg,
  1930. *ppMemory,
  1931. pFormat );
  1932. return;
  1933. }
  1934. Ndr64UserMarshallUnmarshallInternal( pStubMsg,
  1935. *ppMemory,
  1936. pFormat );
  1937. }
  1938. void
  1939. Ndr64TopLevelUserMarshalUnmarshall (
  1940. PMIDL_STUB_MESSAGE pStubMsg,
  1941. uchar ** ppMemory,
  1942. PNDR64_FORMAT pFormat,
  1943. bool fMustAlloc )
  1944. {
  1945. Ndr64UserMarshalUnmarshall( pStubMsg,
  1946. ppMemory,
  1947. pFormat,
  1948. fMustAlloc,
  1949. false );
  1950. }
  1951. void
  1952. Ndr64EmbeddedUserMarshalUnmarshall (
  1953. PMIDL_STUB_MESSAGE pStubMsg,
  1954. uchar ** ppMemory,
  1955. PNDR64_FORMAT pFormat,
  1956. bool fMustAlloc )
  1957. {
  1958. Ndr64UserMarshalUnmarshall( pStubMsg,
  1959. ppMemory,
  1960. pFormat,
  1961. fMustAlloc,
  1962. true );
  1963. }
  1964. void
  1965. Ndr64ClientContextUnmarshall(
  1966. PMIDL_STUB_MESSAGE pStubMsg,
  1967. NDR_CCONTEXT * pContextHandle,
  1968. RPC_BINDING_HANDLE BindHandle )
  1969. /*++
  1970. Routine Description :
  1971. Unmarshalls a context handle on the client side.
  1972. Arguments :
  1973. pStubMsg - Pointer to stub message.
  1974. pContextHandle - Pointer to context handle to unmarshall.
  1975. BindHandle - The handle value used by the client for binding.
  1976. Return :
  1977. None.
  1978. --*/
  1979. {
  1980. // Note, this is a routine called directly from -Os stubs.
  1981. // The routine called by interpreter is called Ndr64UnmarshallHandle
  1982. // and can be found in hndl.c
  1983. ALIGN(pStubMsg->Buffer,3);
  1984. // All 20 bytes of the buffer are touched so a check is not needed here.
  1985. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + CONTEXT_HANDLE_WIRE_SIZE );
  1986. NDRCContextUnmarshall( pContextHandle,
  1987. BindHandle,
  1988. pStubMsg->Buffer,
  1989. pStubMsg->RpcMsg->DataRepresentation );
  1990. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  1991. }
  1992. NDR_SCONTEXT
  1993. Ndr64ServerContextUnmarshall(
  1994. PMIDL_STUB_MESSAGE pStubMsg )
  1995. /*++
  1996. Routine Description :
  1997. Unmarshalls a context handle on the server side.
  1998. Arguments :
  1999. pStubMsg - Pointer to stub message.
  2000. Return :
  2001. The unmarshalled context handle.
  2002. --*/
  2003. {
  2004. // Note, this is a routine called directly from -Os stubs.
  2005. // The routine called by interpreter is called Ndr64UnmarshallHandle
  2006. // and can be found in hndl.c
  2007. NDR_SCONTEXT Context;
  2008. ALIGN(pStubMsg->Buffer,3);
  2009. // we could corrupt memory if it's out of bound
  2010. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + CONTEXT_HANDLE_WIRE_SIZE );
  2011. Context = NDRSContextUnmarshall2(pStubMsg->RpcMsg->Handle,
  2012. pStubMsg->Buffer,
  2013. pStubMsg->RpcMsg->DataRepresentation,
  2014. RPC_CONTEXT_HANDLE_DEFAULT_GUARD,
  2015. RPC_CONTEXT_HANDLE_DEFAULT_FLAGS );
  2016. if ( ! Context )
  2017. RpcRaiseException( RPC_X_SS_CONTEXT_MISMATCH );
  2018. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  2019. return Context;
  2020. }
  2021. NDR_SCONTEXT
  2022. Ndr64ContextHandleInitialize (
  2023. PMIDL_STUB_MESSAGE pStubMsg,
  2024. PFORMAT_STRING pFormat )
  2025. /*
  2026. This routine is to initialize a context handle with a new NT5 flavor.
  2027. It is used in conjunction with Ndr64ContextHandleUnmarshal.
  2028. */
  2029. {
  2030. NDR_SCONTEXT SContext;
  2031. void * pGuard = RPC_CONTEXT_HANDLE_DEFAULT_GUARD;
  2032. DWORD Flags = RPC_CONTEXT_HANDLE_DEFAULT_FLAGS;
  2033. NDR64_CONTEXT_HANDLE_FORMAT * pContextFormat;
  2034. pContextFormat = ( NDR64_CONTEXT_HANDLE_FORMAT * )pFormat;
  2035. NDR_ASSERT( pContextFormat->FormatCode == FC64_BIND_CONTEXT, "invalid format char " );
  2036. // NT5 beta2 features: strict context handle, serialize and noserialize.
  2037. if ( pContextFormat->ContextFlags & NDR_STRICT_CONTEXT_HANDLE )
  2038. {
  2039. pGuard = pStubMsg->StubDesc->RpcInterfaceInformation;
  2040. pGuard = & ((PRPC_SERVER_INTERFACE)pGuard)->InterfaceId;
  2041. }
  2042. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_NOSERIALIZE )
  2043. {
  2044. Flags = RPC_CONTEXT_HANDLE_DONT_SERIALIZE;
  2045. }
  2046. else if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_SERIALIZE )
  2047. {
  2048. Flags = RPC_CONTEXT_HANDLE_SERIALIZE;
  2049. }
  2050. SContext = NDRSContextUnmarshall2(
  2051. pStubMsg->RpcMsg->Handle,
  2052. (void *)0, // buffer
  2053. pStubMsg->RpcMsg->DataRepresentation,
  2054. pGuard,
  2055. Flags );
  2056. return SContext;
  2057. }
  2058. NDR_SCONTEXT
  2059. Ndr64ServerContextNewUnmarshall(
  2060. PMIDL_STUB_MESSAGE pStubMsg,
  2061. PFORMAT_STRING pFormat )
  2062. /*
  2063. This routine to unmarshal a context handle with a new NT5 flavor.
  2064. For the old style handles, we call an optimized routine
  2065. Ndr64ServerContextUnmarshall below.
  2066. Interpreter calls Ndr64UnmarshallHandle from hndl.c
  2067. ppMemory - note, this is not a pointer to user's context handle but
  2068. a pointer to NDR_SCONTEXT pointer to the runtime internal object.
  2069. User's handle is a field of that object.
  2070. */
  2071. {
  2072. void * pGuard = RPC_CONTEXT_HANDLE_DEFAULT_GUARD;
  2073. DWORD Flags = RPC_CONTEXT_HANDLE_DEFAULT_FLAGS;
  2074. ALIGN( pStubMsg->Buffer, 0x3 );
  2075. // we might corrupt the memory during the byte swap
  2076. CHECK_EOB_RAISE_BSD( pStubMsg->Buffer + CONTEXT_HANDLE_WIRE_SIZE );
  2077. NDR64_CONTEXT_HANDLE_FORMAT *pContextFormat = ( NDR64_CONTEXT_HANDLE_FORMAT * )pFormat;
  2078. NDR_ASSERT( pContextFormat->FormatCode == FC64_BIND_CONTEXT, "invalid format char " );
  2079. // Anti-attack defense for servers, NT5 beta3 feature.
  2080. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL )
  2081. {
  2082. // Check the incoming context handle on the server.
  2083. // Context handle wire layout: ulong with version (always 0), then a uuid.
  2084. //
  2085. if ( !pStubMsg->IsClient && 0 == memcmp( pStubMsg->Buffer + 4,
  2086. &GUID_NULL,
  2087. sizeof(GUID) ) )
  2088. RpcRaiseException( RPC_X_BAD_STUB_DATA );
  2089. }
  2090. // NT5 beta2 features: strict context handle, serialize and noserialize.
  2091. if ( pContextFormat->ContextFlags & NDR_STRICT_CONTEXT_HANDLE )
  2092. {
  2093. pGuard = pStubMsg->StubDesc->RpcInterfaceInformation;
  2094. pGuard = & ((PRPC_SERVER_INTERFACE)pGuard)->InterfaceId;
  2095. }
  2096. if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_NOSERIALIZE )
  2097. {
  2098. Flags = RPC_CONTEXT_HANDLE_DONT_SERIALIZE;
  2099. }
  2100. else if ( pContextFormat->ContextFlags & NDR_CONTEXT_HANDLE_SERIALIZE )
  2101. {
  2102. Flags = RPC_CONTEXT_HANDLE_SERIALIZE;
  2103. }
  2104. NDR_SCONTEXT SContext =
  2105. NDRSContextUnmarshall2(
  2106. pStubMsg->RpcMsg->Handle,
  2107. pStubMsg->Buffer,
  2108. pStubMsg->RpcMsg->DataRepresentation,
  2109. pGuard,
  2110. Flags );
  2111. if ( ! SContext )
  2112. RpcRaiseException( RPC_X_SS_CONTEXT_MISMATCH );
  2113. pStubMsg->Buffer += CONTEXT_HANDLE_WIRE_SIZE;
  2114. return SContext;
  2115. }
  2116. // define the jump table
  2117. #define NDR64_BEGIN_TABLE \
  2118. PNDR64_UNMARSHALL_ROUTINE extern const Ndr64UnmarshallRoutinesTable[] = \
  2119. {
  2120. #define NDR64_TABLE_END \
  2121. };
  2122. #define NDR64_ZERO_ENTRY NULL
  2123. #define NDR64_UNUSED_TABLE_ENTRY( number, tokenname ) ,NULL
  2124. #define NDR64_UNUSED_TABLE_ENTRY_NOSYM( number ) ,NULL
  2125. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  2126. ,unmarshall
  2127. #define NDR64_SIMPLE_TYPE_TABLE_ENTRY( number, tokenname, buffersize, memorysize) \
  2128. ,Ndr64UDTSimpleTypeUnmarshall1
  2129. #include "tokntbl.h"
  2130. C_ASSERT( sizeof(Ndr64UnmarshallRoutinesTable)/sizeof(PNDR64_UNMARSHALL_ROUTINE) == 256 );
  2131. #undef NDR64_BEGIN_TABLE
  2132. #undef NDR64_TABLE_ENTRY
  2133. #define NDR64_BEGIN_TABLE \
  2134. PNDR64_UNMARSHALL_ROUTINE extern const Ndr64EmbeddedUnmarshallRoutinesTable[] = \
  2135. {
  2136. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  2137. ,embeddedunmarshall
  2138. #include "tokntbl.h"
  2139. C_ASSERT( sizeof(Ndr64EmbeddedUnmarshallRoutinesTable)/sizeof(PNDR64_UNMARSHALL_ROUTINE) == 256 );