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.

1049 lines
27 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1993 - 1999 Microsoft Corporation
  3. Module Name :
  4. free.c
  5. Abstract :
  6. This file contains the routines called by MIDL 2.0 stubs and the
  7. interpreter for freeing unmarshalled data on the server.
  8. Author :
  9. David Kays dkays September 1993.
  10. Revision History :
  11. ---------------------------------------------------------------------*/
  12. #include "precomp.hxx"
  13. #include "..\..\ndr20\ndrole.h"
  14. __forceinline void
  15. Ndr64FreeTypeMemory(
  16. PMIDL_STUB_MESSAGE pStubMsg,
  17. uchar * pMemory )
  18. {
  19. if ( !pStubMsg->pPointerQueueState ||
  20. !pStubMsg->pPointerQueueState->GetActiveQueue() )
  21. {
  22. (*pStubMsg->pfnFree)(pMemory);
  23. return;
  24. }
  25. NDR_PFNFREE_POINTER_QUEUE_ELEMENT*pElement =
  26. new(pStubMsg->pPointerQueueState)
  27. NDR_PFNFREE_POINTER_QUEUE_ELEMENT(pStubMsg->pfnFree,
  28. pMemory );
  29. pStubMsg->pPointerQueueState->GetActiveQueue()->Enque( pElement );
  30. }
  31. NDR64_FREE_POINTER_QUEUE_ELEMENT::NDR64_FREE_POINTER_QUEUE_ELEMENT(
  32. MIDL_STUB_MESSAGE *pStubMsg,
  33. uchar * const pMemoryNew,
  34. const PFORMAT_STRING pFormatNew) :
  35. pMemory(pMemoryNew),
  36. pFormat(pFormatNew),
  37. uFlags(pStubMsg->uFlags),
  38. pCorrMemory(pStubMsg->pCorrMemory)
  39. {
  40. }
  41. void
  42. NDR64_FREE_POINTER_QUEUE_ELEMENT::Dispatch(
  43. MIDL_STUB_MESSAGE *pStubMsg)
  44. {
  45. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags, uFlags );
  46. CORRELATION_CONTEXT CorrContext( pStubMsg, pCorrMemory );
  47. Ndr64ToplevelTypeFree( pStubMsg,
  48. pMemory,
  49. pFormat );
  50. }
  51. #if defined(DBG)
  52. void
  53. NDR64_FREE_POINTER_QUEUE_ELEMENT::Print()
  54. {
  55. DbgPrint("NDR_FREE_POINTER_QUEUE_ELEMENT\n");
  56. DbgPrint("pNext: %p\n", pNext );
  57. DbgPrint("pMemory: %p\n", pMemory );
  58. DbgPrint("pFormat: %p\n", pFormat );
  59. DbgPrint("uFlags: %x\n", uFlags );
  60. DbgPrint("pCorrMemory: %p\n", pCorrMemory );
  61. }
  62. #endif
  63. void
  64. Ndr64EnquePointeeFree(
  65. PMIDL_STUB_MESSAGE pStubMsg,
  66. uchar * pMemory,
  67. PNDR64_FORMAT pFormat )
  68. {
  69. NDR64_POINTER_CONTEXT PointerContext( pStubMsg );
  70. RpcTryFinally
  71. {
  72. NDR64_FREE_POINTER_QUEUE_ELEMENT*pElement =
  73. new(PointerContext.GetActiveState())
  74. NDR64_FREE_POINTER_QUEUE_ELEMENT(pStubMsg,
  75. (uchar*)pMemory,
  76. (PFORMAT_STRING)pFormat);
  77. PointerContext.Enque( pElement );
  78. PointerContext.DispatchIfRequired();
  79. }
  80. RpcFinally
  81. {
  82. PointerContext.EndContext();
  83. }
  84. RpcEndFinally
  85. }
  86. __forceinline void
  87. Ndr64PointeeFree(
  88. PMIDL_STUB_MESSAGE pStubMsg,
  89. uchar * pMemory,
  90. PNDR64_FORMAT pFormat )
  91. {
  92. SAVE_CONTEXT<uchar> uFlagsSave( pStubMsg->uFlags );
  93. NDR64_RESET_EMBEDDED_FLAGS_TO_STANDALONE(pStubMsg->uFlags);
  94. if ( !NdrIsLowStack( pStubMsg ) )
  95. {
  96. Ndr64ToplevelTypeFree( pStubMsg,
  97. pMemory,
  98. pFormat );
  99. return;
  100. }
  101. Ndr64EnquePointeeFree(
  102. pStubMsg,
  103. pMemory,
  104. pFormat );
  105. }
  106. void
  107. Ndr64pNoopFree(
  108. PMIDL_STUB_MESSAGE pStubMsg,
  109. uchar * pMemory,
  110. PNDR64_FORMAT pFormat )
  111. {
  112. return;
  113. }
  114. __forceinline void
  115. Ndr64PointerFree(
  116. PMIDL_STUB_MESSAGE pStubMsg,
  117. uchar * pMemory,
  118. PNDR64_FORMAT pFormat )
  119. /*++
  120. Routine Description :
  121. Frees a top level or embedded pointer to anything.
  122. Used for FC64_RP, FC64_UP, FC64_FP, FC64_OP.
  123. Arguments :
  124. pStubMsg - Pointer to the stub message.
  125. pMemory - Pointer to be freed.
  126. pFormat - Pointer's format string description.
  127. Return :
  128. None.
  129. --*/
  130. {
  131. const NDR64_POINTER_FORMAT *pPointerFormat = (NDR64_POINTER_FORMAT*) pFormat;
  132. uchar * pMemoryPointee = pMemory;
  133. if ( ! pMemory )
  134. return;
  135. if ( *(PFORMAT_STRING)pFormat == FC64_IP )
  136. {
  137. ((IUnknown *)pMemory)->Release();
  138. return;
  139. }
  140. if ( *(PFORMAT_STRING)pFormat == FC64_FP )
  141. {
  142. //
  143. // Check if we've already freed this full pointer.
  144. //
  145. if ( ! NdrFullPointerFree( pStubMsg->FullPtrXlatTables,
  146. pMemory ) )
  147. return;
  148. }
  149. if ( 0 == pPointerFormat->Flags )
  150. goto FreeEmbeddedPointers;
  151. //
  152. // Check if this pointer and any possible embedded pointers should not
  153. // be freed.
  154. //
  155. if ( NDR64_DONT_FREE( pPointerFormat->Flags) )
  156. return;
  157. //
  158. // Just go free a pointer to a simple type.
  159. //
  160. if ( NDR64_SIMPLE_POINTER( pPointerFormat->Flags ) )
  161. goto FreeTopPointer;
  162. //
  163. // Check if this is an allocate all nodes pointer.
  164. // IDL symantics say that we only free the top most allocate all nodes
  165. // pointer on the server even in the [out] only case. So jump to the
  166. // check for the pointer free at the end of the routine.
  167. //
  168. if ( NDR64_ALLOCATE_ALL_NODES( pPointerFormat->Flags ) )
  169. goto FreeTopPointer;
  170. if ( NDR64_POINTER_DEREF( pPointerFormat->Flags ) )
  171. pMemoryPointee = *((uchar **)pMemory);
  172. FreeEmbeddedPointers:
  173. Ndr64PointeeFree( pStubMsg,
  174. pMemoryPointee,
  175. pPointerFormat->Pointee );
  176. FreeTopPointer:
  177. //
  178. // Now free the pointer. Pointer guaranteed to be non-null here.
  179. //
  180. // We only free the pointer if it lies outside of the message buffer
  181. // that the server stub received from the RPC runtime. Otherwise we
  182. // used the RPC buffer to hold the pointer's data and should not free it.
  183. //
  184. if ( (pMemory < pStubMsg->BufferStart) || (pMemory > pStubMsg->BufferEnd) )
  185. {
  186. //
  187. // Also check to make sure that the pointer was not allocated on the
  188. // server stub's stack (this may happen for ref pointers).
  189. //
  190. // full pointer can't be allocated on stack
  191. if ( ! NDR64_ALLOCED_ON_STACK( pPointerFormat->Flags ) ||
  192. *(PFORMAT_STRING)pFormat == FC64_FP )
  193. {
  194. Ndr64FreeTypeMemory( pStubMsg, pMemory );
  195. }
  196. }
  197. }
  198. __forceinline void
  199. Ndr64TopLevelPointerFree(
  200. PMIDL_STUB_MESSAGE pStubMsg,
  201. uchar * pMemory,
  202. PNDR64_FORMAT pFormat )
  203. /*++
  204. Routine Description :
  205. Frees a top level or embedded pointer to anything.
  206. Used for FC64_RP, FC64_UP, FC64_FP, FC64_OP.
  207. Arguments :
  208. pStubMsg - Pointer to the stub message.
  209. pMemory - Pointer to be freed.
  210. pFormat - Pointer's format string description.
  211. Return :
  212. None.
  213. --*/
  214. {
  215. Ndr64PointerFree( pStubMsg,
  216. pMemory,
  217. pFormat );
  218. }
  219. __forceinline void
  220. Ndr64EmbeddedPointerFree(
  221. PMIDL_STUB_MESSAGE pStubMsg,
  222. uchar * pMemory,
  223. PNDR64_FORMAT pFormat )
  224. {
  225. Ndr64PointerFree( pStubMsg,
  226. *(uchar**)pMemory,
  227. pFormat );
  228. }
  229. void
  230. Ndr64pRangeFree(
  231. PMIDL_STUB_MESSAGE pStubMsg,
  232. uchar * pMemory,
  233. PNDR64_FORMAT pFormat )
  234. /*++
  235. --*/
  236. {
  237. return;
  238. }
  239. void
  240. Ndr64SimpleStructFree(
  241. PMIDL_STUB_MESSAGE pStubMsg,
  242. uchar * pMemory,
  243. PNDR64_FORMAT pFormat )
  244. /*++
  245. Routine Description :
  246. Frees a simple structure's embedded pointers which were allocated during
  247. a remote call.
  248. Used for FC64_STRUCT and FC64_PSTRUCT.
  249. Arguments :
  250. pStubMsg - Pointer to the stub message.
  251. pMemory - Pointer to be freed.
  252. pFormat - Pointer's format string description.
  253. Return :
  254. None.
  255. --*/
  256. {
  257. const NDR64_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  258. (NDR64_STRUCTURE_HEADER_FORMAT*) pFormat;
  259. if ( !pMemory || !pStructFormat->Flags.HasPointerInfo )
  260. return;
  261. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  262. Ndr64pPointerLayoutFree( pStubMsg,
  263. pStructFormat + 1,
  264. 0,
  265. pMemory );
  266. }
  267. void
  268. Ndr64ConformantStructFree(
  269. PMIDL_STUB_MESSAGE pStubMsg,
  270. uchar * pMemory,
  271. PNDR64_FORMAT pFormat )
  272. /*++
  273. Routine Description :
  274. Frees a conformant structure's embedded pointers which were allocated
  275. during a remote call.
  276. Arguments :
  277. pStubMsg - Pointer to the stub message.
  278. pMemory - Pointer to be freed.
  279. pFormat - Pointer's format string description.
  280. Return :
  281. None.
  282. --*/
  283. {
  284. const NDR64_CONF_STRUCTURE_HEADER_FORMAT * const pStructFormat =
  285. (NDR64_CONF_STRUCTURE_HEADER_FORMAT*) pFormat;
  286. const NDR64_CONF_ARRAY_HEADER_FORMAT * const pArrayFormat =
  287. (NDR64_CONF_ARRAY_HEADER_FORMAT *) pStructFormat->ArrayDescription;
  288. if ( !pMemory || !pStructFormat->Flags.HasPointerInfo )
  289. return;
  290. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  291. NDR64_UINT32 MaxCount = (NDR64_UINT32)
  292. Ndr64EvaluateExpr( pStubMsg,
  293. pArrayFormat->ConfDescriptor,
  294. EXPR_MAXCOUNT );
  295. Ndr64pPointerLayoutFree( pStubMsg,
  296. pStructFormat + 1,
  297. MaxCount,
  298. pMemory );
  299. }
  300. void
  301. Ndr64ComplexStructFree(
  302. PMIDL_STUB_MESSAGE pStubMsg,
  303. uchar * pMemory,
  304. PNDR64_FORMAT pFormat )
  305. /*++
  306. Routine Description :
  307. Frees a complex structure's embedded pointers which were allocated during
  308. a remote call.
  309. Arguments :
  310. pStubMsg - Pointer to the stub message.
  311. pMemory - Pointer to be freed.
  312. pFormat - Pointer's format string description.
  313. Return :
  314. None.
  315. --*/
  316. {
  317. const NDR64_BOGUS_STRUCTURE_HEADER_FORMAT * pStructFormat =
  318. (NDR64_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  319. const NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT * pConfStructFormat =
  320. (NDR64_CONF_BOGUS_STRUCTURE_HEADER_FORMAT*) pFormat;
  321. PFORMAT_STRING pFormatPointers = (PFORMAT_STRING)(pStructFormat->PointerLayout );
  322. PFORMAT_STRING pFormatArray = NULL;
  323. PFORMAT_STRING pMemberLayout = ( *(PFORMAT_STRING)pFormat == FC64_CONF_BOGUS_STRUCT ||
  324. *(PFORMAT_STRING)pFormat == FC64_FORCED_CONF_BOGUS_STRUCT ) ?
  325. (PFORMAT_STRING)( pConfStructFormat + 1) :
  326. (PFORMAT_STRING)( pStructFormat + 1);
  327. if ( !pMemory )
  328. return;
  329. CORRELATION_CONTEXT CorrCtxt( pStubMsg, pMemory );
  330. if ( pStructFormat->Flags.HasConfArray )
  331. {
  332. pFormatArray = (PFORMAT_STRING)pConfStructFormat->ConfArrayDescription;
  333. }
  334. for ( ; ; )
  335. {
  336. switch ( *pMemberLayout )
  337. {
  338. case FC64_STRUCT:
  339. {
  340. const NDR64_SIMPLE_REGION_FORMAT *pRegion =
  341. (NDR64_SIMPLE_REGION_FORMAT*) pMemberLayout;
  342. pMemory += pRegion->RegionSize;
  343. pMemberLayout += sizeof( *pRegion );
  344. break;
  345. }
  346. case FC64_STRUCTPADN :
  347. {
  348. const NDR64_MEMPAD_FORMAT *pMemPad = (NDR64_MEMPAD_FORMAT*)pMemberLayout;
  349. pMemory += pMemPad->MemPad;
  350. pMemberLayout += sizeof(*pMemPad);
  351. break;
  352. }
  353. case FC64_POINTER :
  354. Ndr64EmbeddedPointerFree( pStubMsg,
  355. pMemory,
  356. pFormatPointers );
  357. pMemory += PTR_MEM_SIZE;
  358. pFormatPointers += sizeof(NDR64_POINTER_FORMAT);
  359. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  360. break;
  361. case FC64_EMBEDDED_COMPLEX :
  362. {
  363. const NDR64_EMBEDDED_COMPLEX_FORMAT * pEmbeddedFormat =
  364. (NDR64_EMBEDDED_COMPLEX_FORMAT*) pMemberLayout;
  365. Ndr64EmbeddedTypeFree( pStubMsg,
  366. pMemory,
  367. pEmbeddedFormat->Type );
  368. pMemory = Ndr64pMemoryIncrement( pStubMsg,
  369. pMemory,
  370. pEmbeddedFormat->Type,
  371. FALSE );
  372. pMemberLayout += sizeof( *pEmbeddedFormat );
  373. break;
  374. }
  375. case FC64_BUFFER_ALIGN:
  376. {
  377. const NDR64_BUFFER_ALIGN_FORMAT *pBufAlign =
  378. (NDR64_BUFFER_ALIGN_FORMAT*) pMemberLayout;
  379. pMemberLayout += sizeof( *pBufAlign );
  380. break;
  381. }
  382. case FC64_CHAR :
  383. case FC64_WCHAR :
  384. case FC64_INT8:
  385. case FC64_UINT8:
  386. case FC64_INT16:
  387. case FC64_UINT16:
  388. case FC64_INT32:
  389. case FC64_UINT32:
  390. case FC64_INT64:
  391. case FC64_UINT64:
  392. case FC64_FLOAT32 :
  393. case FC64_FLOAT64 :
  394. case FC64_ERROR_STATUS_T:
  395. pMemory += NDR64_SIMPLE_TYPE_MEMSIZE(*pMemberLayout);
  396. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  397. break;
  398. case FC64_IGNORE :
  399. pMemory += PTR_MEM_SIZE;
  400. pMemberLayout += sizeof(NDR64_SIMPLE_MEMBER_FORMAT);
  401. break;
  402. case FC64_END :
  403. goto ComplexFreeEnd;
  404. default :
  405. NDR_ASSERT(0,"Ndr64ComplexStructFree : bad format char");
  406. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  407. return;
  408. } // switch
  409. } // for
  410. ComplexFreeEnd :
  411. if ( pFormatArray )
  412. {
  413. Ndr64EmbeddedTypeFree( pStubMsg,
  414. pMemory,
  415. pFormatArray );
  416. }
  417. }
  418. void
  419. Ndr64FixedArrayFree(
  420. PMIDL_STUB_MESSAGE pStubMsg,
  421. uchar * pMemory,
  422. PNDR64_FORMAT pFormat )
  423. /*++
  424. Routine Description :
  425. Frees a fixed array's embedded pointers which were allocated during
  426. a remote call.
  427. Arguments :
  428. pStubMsg - Pointer to the stub message.
  429. pMemory - Pointer to be freed.
  430. pFormat - Pointer's format string description.
  431. Return :
  432. None.
  433. --*/
  434. {
  435. const NDR64_FIX_ARRAY_HEADER_FORMAT * pArrayFormat =
  436. (NDR64_FIX_ARRAY_HEADER_FORMAT*) pFormat;
  437. if ( ! pMemory || !pArrayFormat->Flags.HasPointerInfo )
  438. return;
  439. Ndr64pPointerLayoutFree( pStubMsg,
  440. pArrayFormat + 1,
  441. 0,
  442. pMemory );
  443. }
  444. void
  445. Ndr64ConformantArrayFree(
  446. PMIDL_STUB_MESSAGE pStubMsg,
  447. uchar * pMemory,
  448. PNDR64_FORMAT pFormat )
  449. /*++
  450. Routine Description :
  451. Frees a one dimensional conformant array's embedded pointers which were
  452. allocated during a remote call. Called for both top level and embedded
  453. conformant arrays.
  454. Arguments :
  455. pStubMsg - Pointer to the stub message.
  456. pMemory - Pointer to be freed.
  457. pFormat - Pointer's format string description.
  458. Return :
  459. None.
  460. --*/
  461. {
  462. const NDR64_CONF_ARRAY_HEADER_FORMAT *pArrayFormat =
  463. (NDR64_CONF_ARRAY_HEADER_FORMAT*) pFormat;
  464. if ( ! pMemory || !pArrayFormat->Flags.HasPointerInfo )
  465. return;
  466. NDR64_UINT32 MaxCount = (NDR64_UINT32)
  467. Ndr64EvaluateExpr( pStubMsg,
  468. pArrayFormat->ConfDescriptor,
  469. EXPR_MAXCOUNT );
  470. Ndr64pPointerLayoutFree( pStubMsg,
  471. pArrayFormat + 1,
  472. MaxCount,
  473. pMemory );
  474. }
  475. void
  476. Ndr64ConformantVaryingArrayFree(
  477. PMIDL_STUB_MESSAGE pStubMsg,
  478. uchar * pMemory,
  479. PNDR64_FORMAT pFormat )
  480. /*++
  481. Routine Description :
  482. Frees a one dimensional conformant varying array's embedded pointers which
  483. were allocated during a remote call. Called for both top level and
  484. embedded conformant varying arrays.
  485. Arguments :
  486. pStubMsg - Pointer to the stub message.
  487. pMemory - Pointer to be freed.
  488. pFormat - Pointer's format string description.
  489. Return :
  490. None.
  491. --*/
  492. {
  493. const NDR64_CONF_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  494. (NDR64_CONF_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  495. if ( ! pMemory || !pArrayFormat->Flags.HasPointerInfo)
  496. return;
  497. NDR64_UINT32 ActualCount = (NDR64_UINT32)
  498. Ndr64EvaluateExpr( pStubMsg,
  499. pArrayFormat->VarDescriptor,
  500. EXPR_ACTUALCOUNT );
  501. Ndr64pPointerLayoutFree( pStubMsg,
  502. pArrayFormat + 1,
  503. ActualCount,
  504. pMemory );
  505. }
  506. void
  507. Ndr64VaryingArrayFree(
  508. PMIDL_STUB_MESSAGE pStubMsg,
  509. uchar * pMemory,
  510. PNDR64_FORMAT pFormat )
  511. /*++
  512. Routine Description :
  513. Frees a varying array's embedded pointers which were allocated
  514. during a remote call. Called for both top level and embedded varying
  515. arrays.
  516. Arguments :
  517. pStubMsg - Pointer to the stub message.
  518. pMemory - Pointer to be freed.
  519. pFormat - Pointer's format string description.
  520. Return :
  521. None.
  522. --*/
  523. {
  524. const NDR64_VAR_ARRAY_HEADER_FORMAT * pArrayFormat =
  525. (NDR64_VAR_ARRAY_HEADER_FORMAT*) pFormat;
  526. if ( ! pMemory || !pArrayFormat->Flags.HasPointerInfo)
  527. return;
  528. NDR64_UINT32 ActualCount = (NDR64_UINT32)
  529. Ndr64EvaluateExpr( pStubMsg,
  530. pArrayFormat->VarDescriptor,
  531. EXPR_ACTUALCOUNT );
  532. Ndr64pPointerLayoutFree( pStubMsg,
  533. pArrayFormat + 1,
  534. ActualCount,
  535. pMemory );
  536. }
  537. void
  538. Ndr64ComplexArrayFree(
  539. PMIDL_STUB_MESSAGE pStubMsg,
  540. uchar * pMemory,
  541. PNDR64_FORMAT pFormat )
  542. /*++
  543. Routine Description :
  544. Frees a complex array's embedded pointers which were allocated
  545. during a remote call. Called for both top level and embedded complex
  546. arrays.
  547. Arguments :
  548. pStubMsg - Pointer to the stub message.
  549. pMemory - Pointer to be freed.
  550. pFormat - Pointer's format string description.
  551. Return :
  552. None.
  553. --*/
  554. {
  555. const NDR64_BOGUS_ARRAY_HEADER_FORMAT *pArrayFormat =
  556. (NDR64_BOGUS_ARRAY_HEADER_FORMAT *) pFormat;
  557. BOOL IsFixed = ( pArrayFormat->FormatCode == FC64_FIX_BOGUS_ARRAY ) ||
  558. ( pArrayFormat->FormatCode == FC64_FIX_FORCED_BOGUS_ARRAY );
  559. PFORMAT_STRING pElementFormat = (PFORMAT_STRING)pArrayFormat->Element;
  560. //
  561. // We have to check this in case we get an exception before actually
  562. // unmarshalling the array.
  563. //
  564. if ( ! pMemory )
  565. return;
  566. NDR64_WIRE_COUNT_TYPE Elements = pArrayFormat->NumberElements;
  567. NDR64_WIRE_COUNT_TYPE Count = Elements;
  568. NDR64_WIRE_COUNT_TYPE Offset = 0;
  569. if ( !IsFixed )
  570. {
  571. const NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT* pConfVarFormat=
  572. (NDR64_CONF_VAR_BOGUS_ARRAY_HEADER_FORMAT*)pFormat;
  573. //
  574. // Check for conformance description.
  575. //
  576. if ( pConfVarFormat->ConfDescription )
  577. {
  578. Elements = (NDR64_UINT32)Ndr64EvaluateExpr( pStubMsg,
  579. pConfVarFormat->ConfDescription,
  580. EXPR_MAXCOUNT );
  581. Offset = 0;
  582. Count = Elements;
  583. }
  584. //
  585. // Check for variance description.
  586. //
  587. if ( pConfVarFormat->VarDescription )
  588. {
  589. Count = (NDR64_UINT32)
  590. Ndr64EvaluateExpr( pStubMsg,
  591. pConfVarFormat->VarDescription,
  592. EXPR_ACTUALCOUNT );
  593. Offset = (NDR64_UINT32)
  594. Ndr64EvaluateExpr( pStubMsg,
  595. pConfVarFormat->OffsetDescription,
  596. EXPR_OFFSET );
  597. }
  598. }
  599. NDR64_UINT32 ElementMemorySize =
  600. Ndr64pMemorySize( pStubMsg,
  601. pElementFormat,
  602. FALSE );
  603. pMemory += Ndr64pConvertTo2GB((NDR64_UINT64)Offset *
  604. (NDR64_UINT64)ElementMemorySize);
  605. Ndr64pConvertTo2GB( (NDR64_UINT64)Elements *
  606. (NDR64_UINT64)ElementMemorySize );
  607. Ndr64pConvertTo2GB( (NDR64_UINT64)Count *
  608. (NDR64_UINT64)ElementMemorySize );
  609. for ( ; Count--; )
  610. {
  611. Ndr64EmbeddedTypeFree( pStubMsg,
  612. pMemory,
  613. pElementFormat );
  614. pMemory += ElementMemorySize;
  615. }
  616. }
  617. void
  618. Ndr64UnionFree(
  619. PMIDL_STUB_MESSAGE pStubMsg,
  620. uchar * pMemory,
  621. PNDR64_FORMAT pFormat )
  622. /*++
  623. Routine Description :
  624. Frees an encapsulated union's embedded pointers which were allocated
  625. during a remote call.
  626. Arguments :
  627. pStubMsg - Pointer to the stub message.
  628. pMemory - Pointer to be freed.
  629. pFormat - Pointer's format string description.
  630. Return :
  631. None.
  632. --*/
  633. {
  634. const NDR64_UNION_ARM_SELECTOR* pArmSelector;
  635. EXPR_VALUE SwitchIs;
  636. NDR64_FORMAT_CHAR SwitchType;
  637. uchar *pArmMemory;
  638. if ( !pMemory )
  639. return;
  640. switch(*(PFORMAT_STRING)pFormat)
  641. {
  642. case FC64_NON_ENCAPSULATED_UNION:
  643. {
  644. const NDR64_NON_ENCAPSULATED_UNION* pNonEncapUnionFormat =
  645. (const NDR64_NON_ENCAPSULATED_UNION*) pFormat;
  646. SwitchType = pNonEncapUnionFormat->SwitchType;
  647. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pNonEncapUnionFormat + 1);
  648. SwitchIs = Ndr64EvaluateExpr( pStubMsg,
  649. pNonEncapUnionFormat->Switch,
  650. EXPR_SWITCHIS );
  651. pArmMemory = pMemory;
  652. break;
  653. }
  654. case FC64_ENCAPSULATED_UNION:
  655. {
  656. const NDR64_ENCAPSULATED_UNION* pEncapUnionFormat =
  657. (const NDR64_ENCAPSULATED_UNION*)pFormat;
  658. SwitchType = pEncapUnionFormat->SwitchType;
  659. pArmSelector = (NDR64_UNION_ARM_SELECTOR*)(pEncapUnionFormat + 1);
  660. SwitchIs = Ndr64pSimpleTypeToExprValue( SwitchType,
  661. pMemory );
  662. pArmMemory = pMemory + pEncapUnionFormat->MemoryOffset;
  663. break;
  664. }
  665. default:
  666. NDR_ASSERT("Bad union format\n", 0);
  667. return;
  668. }
  669. PNDR64_FORMAT pArmFormat =
  670. Ndr64pFindUnionArm( pStubMsg,
  671. pArmSelector,
  672. SwitchIs );
  673. if ( !pArmFormat )
  674. return;
  675. Ndr64EmbeddedTypeFree( pStubMsg,
  676. pArmMemory,
  677. pArmFormat );
  678. }
  679. void
  680. Ndr64XmitOrRepAsFree(
  681. PMIDL_STUB_MESSAGE pStubMsg,
  682. uchar * pMemory,
  683. PNDR64_FORMAT pFormat )
  684. /*++
  685. Routine Description :
  686. Frees the transmit-as object (actually the presented type instance)
  687. and steps over the object.
  688. There is an exceptional situation where the spec forbids stub to free
  689. the instance. This happens when there is an [in] only parameter with
  690. a [transmit_as()] on a component of the parameter, and the presented
  691. typedef is composed of one or more pointers.
  692. We have a flag in the stub msg that is set when this happens.
  693. See mrshl.c for the description of the FC layout.
  694. Arguments :
  695. pStubMsg - Pointer to the stub message.
  696. pMemory - Pointer to be freed.
  697. pFormat - Pointer's format string description.
  698. Return :
  699. None.
  700. --*/
  701. {
  702. const NDR64_TRANSMIT_AS_FORMAT *pTransFormat =
  703. ( const NDR64_TRANSMIT_AS_FORMAT *) pFormat;
  704. if ( !pMemory )
  705. return;
  706. NDR_ASSERT( pTransFormat->FormatCode == FC64_TRANSMIT_AS || pTransFormat->FormatCode , "invalid format string for user marshal" );
  707. unsigned short QIndex = pTransFormat->RoutineIndex;
  708. const XMIT_ROUTINE_QUINTUPLE * pQuintuple = pStubMsg->StubDesc->aXmitQuintuple;
  709. // Free the presented type instance unless forbidden explicitely.
  710. if ( ! pStubMsg->fDontCallFreeInst )
  711. {
  712. pStubMsg->pPresentedType = pMemory;
  713. pQuintuple[ QIndex ].pfnFreeInst( pStubMsg );
  714. }
  715. }
  716. void
  717. Ndr64UserMarshalFree(
  718. PMIDL_STUB_MESSAGE pStubMsg,
  719. uchar * pMemory,
  720. PNDR64_FORMAT pFormat )
  721. /*++
  722. Routine Description :
  723. Frees the usr_marshal object and steps over the object.
  724. See mrshl.c for the description of the layouts.
  725. Arguments :
  726. pStubMsg - Pointer to the stub message.
  727. pMemory - Pointer to be freed.
  728. pFormat - Pointer's format string description.
  729. Return :
  730. None.
  731. --*/
  732. {
  733. NDR64_USER_MARSHAL_FORMAT * pUserFormat =
  734. ( NDR64_USER_MARSHAL_FORMAT *) pFormat;
  735. NDR_ASSERT( pUserFormat->FormatCode == FC64_USER_MARSHAL, "invalid format string for user marshal" );
  736. unsigned short QIndex = pUserFormat->RoutineIndex;
  737. const USER_MARSHAL_ROUTINE_QUADRUPLE * pQuadruple =
  738. (const USER_MARSHAL_ROUTINE_QUADRUPLE *)( ( NDR_PROC_CONTEXT *)pStubMsg->pContext )->pSyntaxInfo->aUserMarshalQuadruple;
  739. // Call the user to free his stuff.
  740. USER_MARSHAL_CB UserMarshalCB;
  741. Ndr64pInitUserMarshalCB( pStubMsg,
  742. pUserFormat,
  743. USER_MARSHAL_CB_FREE,
  744. & UserMarshalCB);
  745. // The user shouldn't ever free the top level object as we free it.
  746. // He should free only pointees of his top level object.
  747. pQuadruple[ QIndex ].pfnFree( (ulong*) &UserMarshalCB, pMemory );
  748. // Ndr64pMemoryIncrement steps over the memory object.
  749. }
  750. // define the jump table
  751. #define NDR64_BEGIN_TABLE \
  752. PNDR64_FREE_ROUTINE extern const Ndr64FreeRoutinesTable[] = \
  753. {
  754. #define NDR64_TABLE_END \
  755. };
  756. #define NDR64_ZERO_ENTRY NULL
  757. #define NDR64_UNUSED_TABLE_ENTRY( number, tokenname ) ,NULL
  758. #define NDR64_UNUSED_TABLE_ENTRY_NOSYM( number ) ,NULL
  759. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  760. ,free
  761. #define NDR64_SIMPLE_TYPE_TABLE_ENTRY( number, tokenname, buffersize, memorysize) \
  762. ,Ndr64pNoopFree
  763. #include "tokntbl.h"
  764. C_ASSERT( sizeof(Ndr64FreeRoutinesTable)/sizeof(PNDR64_FREE_ROUTINE) == 256 );
  765. #undef NDR64_BEGIN_TABLE
  766. #undef NDR64_TABLE_ENTRY
  767. #define NDR64_BEGIN_TABLE \
  768. PNDR64_FREE_ROUTINE extern const Ndr64EmbeddedFreeRoutinesTable[] = \
  769. {
  770. #define NDR64_TABLE_ENTRY( number, tokenname, marshall, embeddedmarshall, unmarshall, embeddedunmarshall, buffersize, embeddedbuffersize, memsize, embeddedmemsize, free, embeddedfree, typeflags ) \
  771. ,embeddedfree
  772. #include "tokntbl.h"
  773. C_ASSERT( sizeof(Ndr64EmbeddedFreeRoutinesTable) / sizeof(PNDR64_FREE_ROUTINE) == 256 );