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.

1319 lines
41 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. pickle64.cxx
  5. Abstract:
  6. This module contains ndr64 related pickling ndr library routines.
  7. Notes:
  8. Author:
  9. Yong Qu Nov, 1993
  10. Revision History:
  11. ------------------------------------------------------------------------*/
  12. #include "precomp.hxx"
  13. #include <midles.h>
  14. #include "endianp.h"
  15. #include "picklep.hxx"
  16. extern "C"
  17. {
  18. void RPC_ENTRY
  19. NdrpPicklingClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  20. void * pThis );
  21. void RPC_ENTRY
  22. Ndr64pPicklingClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  23. void * pThis );
  24. }
  25. const SYNTAX_DISPATCH_TABLE SyncDcePicklingClient =
  26. {
  27. NdrpClientInit,
  28. NdrpSizing,
  29. NdrpClientMarshal,
  30. NdrpClientUnMarshal,
  31. NdrpClientExceptionHandling,
  32. NdrpPicklingClientFinally
  33. };
  34. const SYNTAX_DISPATCH_TABLE SyncNdr64PicklingClient =
  35. {
  36. Ndr64pClientInit,
  37. Ndr64pSizing,
  38. Ndr64pClientMarshal,
  39. Ndr64pClientUnMarshal,
  40. Ndr64pClientExceptionHandling,
  41. Ndr64pPicklingClientFinally
  42. };
  43. extern const MIDL_FORMAT_STRING __MIDLFormatString;
  44. __inline
  45. void Ndr64pMesTypeInit( PMIDL_STUB_MESSAGE pStubMsg,
  46. NDR_PROC_CONTEXT * pContext,
  47. PMIDL_STUB_DESC pStubDesc )
  48. {
  49. // we need this for correlation cache.
  50. NdrpInitializeProcContext( pContext );
  51. pStubMsg->pContext = pContext;
  52. pStubMsg->fHasExtensions = 1;
  53. pStubMsg->StubDesc = pStubDesc;
  54. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  55. pStubMsg->pfnFree = pStubDesc->pfnFree;
  56. pStubMsg->pCorrInfo = NULL;
  57. }
  58. #define NdrpSetupMesTypeCommon( pfnName, pfnDCE, pfnNDR64 ) \
  59. \
  60. if ( pMesMsg->Operation == MES_ENCODE || pMesMsg->Operation == MES_DECODE ) \
  61. { \
  62. SyntaxType = XFER_SYNTAX_DCE; \
  63. pfnName = &pfnDCE; \
  64. } \
  65. else \
  66. { \
  67. SyntaxType = XFER_SYNTAX_NDR64; \
  68. pfnName = &pfnNDR64; \
  69. } \
  70. \
  71. for ( long i = 0; i < (long) pProxyInfo->nCount; i ++ ) \
  72. if ( NdrpGetSyntaxType( &pProxyInfo->pSyntaxInfo[i].TransferSyntax ) == SyntaxType ) \
  73. { \
  74. pSyntaxInfo = &pProxyInfo->pSyntaxInfo[i]; \
  75. break; \
  76. } \
  77. \
  78. if (NULL == pSyntaxInfo ) \
  79. RpcRaiseException( RPC_S_UNSUPPORTED_TRANS_SYN ); \
  80. \
  81. if ( XFER_SYNTAX_DCE == SyntaxType ) \
  82. { \
  83. ulong nFormatOffset = ArrTypeOffset[i][nTypeIndex]; \
  84. pTypeFormat = &pSyntaxInfo->TypeString[nFormatOffset]; \
  85. } \
  86. else \
  87. { \
  88. if ( SyntaxType == XFER_SYNTAX_NDR64 ) \
  89. Ndr64pMesTypeInit( &pMesMsg->StubMsg, &ProcContext, pProxyInfo->pStubDesc ); \
  90. \
  91. pTypeFormat = (PFORMAT_STRING)(((const FormatInfoRef **) ArrTypeOffset)[i][nTypeIndex]); \
  92. } \
  93. \
  94. ProcContext.pSyntaxInfo = pSyntaxInfo;
  95. void
  96. Ndr64pValidateMesHandle(
  97. PMIDL_ES_MESSAGE_EX pMesMsgEx )
  98. {
  99. RpcTryExcept
  100. {
  101. if ( pMesMsgEx == 0 ||
  102. pMesMsgEx->Signature != MIDL_ES_SIGNATURE ||
  103. ( pMesMsgEx->MesMsg.MesVersion != MIDL_NDR64_ES_VERSION &&
  104. pMesMsgEx->MesMsg.MesVersion != MIDL_ES_VERSION ) )
  105. RpcRaiseException( RPC_S_INVALID_ARG );
  106. }
  107. RpcExcept( 1 )
  108. {
  109. RpcRaiseException( RPC_S_INVALID_ARG );
  110. }
  111. RpcEndExcept
  112. }
  113. RPC_STATUS
  114. Ndr64pValidateMesHandleReturnStatus(
  115. PMIDL_ES_MESSAGE_EX pMesMsgEx )
  116. {
  117. RPC_STATUS Status = RPC_S_OK;
  118. RpcTryExcept
  119. {
  120. if ( pMesMsgEx == 0 || pMesMsgEx->Signature != MIDL_NDR64_ES_SIGNATURE ||
  121. pMesMsgEx->MesMsg.MesVersion != MIDL_NDR64_ES_VERSION )
  122. Status = RPC_S_INVALID_ARG;
  123. }
  124. RpcExcept( 1 )
  125. {
  126. Status = RPC_S_INVALID_ARG;
  127. }
  128. RpcEndExcept
  129. return Status;
  130. }
  131. void
  132. Ndr64pCommonTypeHeaderSize(
  133. PMIDL_ES_MESSAGE pMesMsg
  134. )
  135. {
  136. // This check is to prevent a decoding handle from being used
  137. // for both encoding and sizing of types.
  138. if ( pMesMsg->Operation != MES_ENCODE_NDR64 )
  139. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  140. if ( ! GET_COMMON_TYPE_HEADER_SIZED( pMesMsg ) )
  141. {
  142. pMesMsg->StubMsg.BufferLength += MES_NDR64_CTYPE_HEADER_SIZE;
  143. SET_COMMON_TYPE_HEADER_SIZED( pMesMsg );
  144. }
  145. }
  146. size_t RPC_ENTRY
  147. Ndr64MesTypeAlignSize(
  148. handle_t Handle,
  149. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  150. const MIDL_STUB_DESC * pStubDesc,
  151. PFORMAT_STRING pFormat,
  152. const void __RPC_FAR * pObject
  153. )
  154. {
  155. PMIDL_ES_MESSAGE pMesMsg = ( PMIDL_ES_MESSAGE )Handle;
  156. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  157. size_t OldLength = pStubMsg->BufferLength;
  158. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  159. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  160. if ( ! pObject )
  161. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  162. if( (long)pStubMsg->BufferLength & 0xf )
  163. RpcRaiseException( RPC_X_INVALID_BUFFER );
  164. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  165. NDR_ASSERT( pPicklingInfo->Flags.Oicf, "Oicf should always be on" );
  166. // See if we need to size the common type header.
  167. Ndr64pCommonTypeHeaderSize( (PMIDL_ES_MESSAGE)Handle );
  168. // Now the individual type object.
  169. pStubMsg->BufferLength += MES_NDR64_HEADER_SIZE;
  170. if ( NDR64_IS_POINTER_TYPE(*pFormat) )
  171. {
  172. // We have to dereference the pointer once.
  173. pObject = *(void __RPC_FAR * __RPC_FAR *)pObject;
  174. }
  175. (Ndr64SizeRoutinesTable[ NDR64_ROUTINE_INDEX(*pFormat) ])
  176. ( pStubMsg,
  177. (uchar __RPC_FAR *)pObject,
  178. pFormat );
  179. LENGTH_ALIGN( pStubMsg->BufferLength, 0xf );
  180. Ndr64pPicklingClientFinally( pStubMsg, NULL ); // object
  181. return( pStubMsg->BufferLength - OldLength );
  182. }
  183. // ndr64 entries.
  184. size_t RPC_ENTRY
  185. NdrMesTypeAlignSize3(
  186. handle_t Handle,
  187. const MIDL_TYPE_PICKLING_INFO * pPicklingInfo,
  188. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  189. const unsigned long ** ArrTypeOffset,
  190. unsigned long nTypeIndex,
  191. const void __RPC_FAR * pObject )
  192. {
  193. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  194. PFORMAT_STRING pTypeFormat;
  195. MIDL_SYNTAX_INFO * pSyntaxInfo = NULL;
  196. PFNMESTYPEALIGNSIZE pfnSize;
  197. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  198. SYNTAX_TYPE SyntaxType;
  199. NDR_PROC_CONTEXT ProcContext;
  200. if ( (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE &&
  201. (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE_NDR64 )
  202. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  203. NdrpSetupMesTypeCommon( pfnSize, NdrMesTypeAlignSize2, Ndr64MesTypeAlignSize );
  204. return
  205. ( *pfnSize )( Handle, pPicklingInfo, pProxyInfo->pStubDesc, pTypeFormat, pObject );
  206. }
  207. // common type header for type pickling is longer than before:
  208. // if version is 1, the header size is 8,
  209. // if version is higher than 1, the header size is 24+2*sizeof(RPC_SYNTAX_IDENTIFIER)
  210. // starting 8 bytes is still the same as old one:
  211. // <version:1><endian:1><header_size:2><endian info: 4>
  212. // addtional header:
  213. // <reserved: 16> <transfer_syntax><iid>
  214. //
  215. size_t
  216. Ndr64pCommonTypeHeaderMarshall(
  217. PMIDL_ES_MESSAGE pMesMsg
  218. )
  219. /*++
  220. Returns the space used by the common header.
  221. --*/
  222. {
  223. if ( ! GET_COMMON_TYPE_HEADER_IN( pMesMsg ) )
  224. {
  225. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  226. if ( (ULONG_PTR)pStubMsg->Buffer & 15 )
  227. RpcRaiseException( RPC_X_INVALID_BUFFER );
  228. MIDL_memset( pStubMsg->Buffer, 0xcc, MES_NDR64_CTYPE_HEADER_SIZE );
  229. *pStubMsg->Buffer++ = MIDL_NDR64_ES_VERSION;
  230. *pStubMsg->Buffer++ = NDR_LOCAL_ENDIAN;
  231. * PSHORT_CAST pStubMsg->Buffer = MES_NDR64_CTYPE_HEADER_SIZE;
  232. pStubMsg->Buffer += MES_CTYPE_HEADER_SIZE + 16 -2 ; // skip over reserved, make header size 64bytes
  233. RpcpMemoryCopy( pStubMsg->Buffer,
  234. & NDR64_TRANSFER_SYNTAX,
  235. sizeof(RPC_SYNTAX_IDENTIFIER) );
  236. pStubMsg->Buffer += sizeof( RPC_SYNTAX_IDENTIFIER );
  237. RpcpMemoryCopy( pStubMsg->Buffer ,
  238. & pMesMsg->InterfaceId,
  239. sizeof(RPC_SYNTAX_IDENTIFIER) + sizeof(long) );
  240. pStubMsg->Buffer += sizeof( RPC_SYNTAX_IDENTIFIER );
  241. SET_COMMON_TYPE_HEADER_IN( pMesMsg );
  242. return( MES_NDR64_CTYPE_HEADER_SIZE );
  243. }
  244. return( 0 );
  245. }
  246. void RPC_ENTRY
  247. Ndr64MesTypeEncode(
  248. handle_t Handle,
  249. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  250. const MIDL_STUB_DESC * pStubDesc,
  251. PFORMAT_STRING pFormat,
  252. const void __RPC_FAR * pObject
  253. )
  254. {
  255. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  256. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  257. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  258. uchar __RPC_FAR * pBufferSaved, *pTypeHeader;
  259. size_t RequiredLen, CommonHeaderSize, LengthSaved;
  260. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  261. NDR_ASSERT( pPicklingInfo->Flags.Oicf, "Oicf should always be on" )
  262. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  263. if ( ! pObject )
  264. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  265. if( (LONG_PTR)pStubMsg->Buffer & 0xf )
  266. RpcRaiseException( RPC_X_INVALID_BUFFER );
  267. pStubMsg->BufferLength = 0xf & PtrToUlong( pStubMsg->Buffer );
  268. RequiredLen = Ndr64MesTypeAlignSize( Handle,
  269. pxPicklingInfo,
  270. pStubDesc,
  271. pFormat,
  272. pObject );
  273. NdrpAllocPicklingBuffer( pMesMsg, RequiredLen );
  274. pBufferSaved = pStubMsg->Buffer;
  275. LengthSaved = RequiredLen;
  276. // See if we need to marshall the common type header
  277. CommonHeaderSize = Ndr64pCommonTypeHeaderMarshall( pMesMsg );
  278. // Marshall the header and the object.
  279. memset( pStubMsg->Buffer, 0, MES_NDR64_HEADER_SIZE );
  280. pStubMsg->Buffer += MES_NDR64_HEADER_SIZE;
  281. if ( NDR64_IS_POINTER_TYPE(*pFormat) )
  282. {
  283. // We have to dereference the pointer once.
  284. pObject = *(void __RPC_FAR * __RPC_FAR *)pObject;
  285. }
  286. RpcTryFinally
  287. {
  288. ALIGN( pStubMsg->Buffer, 0xf );
  289. (Ndr64MarshallRoutinesTable[ NDR64_ROUTINE_INDEX(*pFormat) ])
  290. ( pStubMsg,
  291. (uchar __RPC_FAR *)pObject,
  292. pFormat );
  293. // We adjust the buffer to the next align by 16 and
  294. // so, we tell the user that we've written out till next mod 16.
  295. // cleanup possible leaks before raising exception.
  296. }
  297. RpcFinally
  298. {
  299. Ndr64pPicklingClientFinally( pStubMsg, NULL ); // object
  300. }
  301. RpcEndFinally
  302. ALIGN( pStubMsg->Buffer, 0xf );
  303. size_t WriteLength = (size_t)(pStubMsg->Buffer - pBufferSaved);
  304. // We always save the rounded up object length in the type header.
  305. *(unsigned long __RPC_FAR *)(pBufferSaved + CommonHeaderSize) =
  306. WriteLength - CommonHeaderSize - MES_NDR64_HEADER_SIZE;
  307. if ( LengthSaved < WriteLength )
  308. {
  309. NDR_ASSERT( 0, "NdrMesTypeEncode: encode buffer overflow" );
  310. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  311. }
  312. NdrpWritePicklingBuffer( pMesMsg, pBufferSaved, WriteLength );
  313. }
  314. void RPC_ENTRY
  315. NdrMesTypeEncode3(
  316. handle_t Handle,
  317. const MIDL_TYPE_PICKLING_INFO * pPicklingInfo,
  318. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  319. const unsigned long ** ArrTypeOffset,
  320. unsigned long nTypeIndex,
  321. const void __RPC_FAR * pObject )
  322. {
  323. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  324. PFORMAT_STRING pTypeFormat;
  325. MIDL_SYNTAX_INFO * pSyntaxInfo = NULL;
  326. PFNMESTYPEENCODE pfnEncode;
  327. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  328. SYNTAX_TYPE SyntaxType;
  329. NDR_PROC_CONTEXT ProcContext;
  330. if ( (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE &&
  331. (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE_NDR64 )
  332. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  333. NdrpSetupMesTypeCommon( pfnEncode, NdrMesTypeEncode2, Ndr64MesTypeEncode );
  334. ( *pfnEncode )( Handle, pPicklingInfo, pProxyInfo->pStubDesc, pTypeFormat, pObject );
  335. }
  336. // read the type header, and determine if the buffer is marshalled
  337. // using ndr or ndr64
  338. // for future extension, we can allow other transfer syntaxes.
  339. void RPC_ENTRY
  340. Ndr64pCommonTypeHeaderUnmarshall(
  341. PMIDL_ES_MESSAGE pMesMsg
  342. )
  343. {
  344. BOOL IsNewPickling = FALSE;
  345. if ( pMesMsg->Operation != MES_DECODE &&
  346. pMesMsg->Operation != MES_DECODE_NDR64 )
  347. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  348. if ( ! GET_COMMON_TYPE_HEADER_IN( pMesMsg ) )
  349. {
  350. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  351. // read the common header first.
  352. NdrpReadPicklingBuffer( pMesMsg, MES_CTYPE_HEADER_SIZE );
  353. // Check the version number, endianness.
  354. if ( *pStubMsg->Buffer == MIDL_ES_VERSION )
  355. {
  356. IsNewPickling = FALSE;
  357. pMesMsg->Operation = MES_DECODE;
  358. }
  359. else
  360. {
  361. IsNewPickling = TRUE;
  362. }
  363. if ( pStubMsg->Buffer[1] == NDR_LOCAL_ENDIAN )
  364. {
  365. // Read the note about endianess at NdrMesTypeDecode.
  366. //
  367. pMesMsg->AlienDataRep = NDR_LOCAL_DATA_REPRESENTATION;
  368. }
  369. else
  370. {
  371. NDR_ASSERT( pMesMsg->Operation != MES_DECODE_NDR64,
  372. "endian convertion is not supported in ndr64" );
  373. unsigned char temp = pStubMsg->Buffer[2];
  374. pStubMsg->Buffer[2] = pStubMsg->Buffer[3];
  375. pStubMsg->Buffer[3] = temp;
  376. pMesMsg->AlienDataRep = ( NDR_ASCII_CHAR | // chars
  377. pStubMsg->Buffer[1] | // endianness
  378. NDR_IEEE_FLOAT ); // float
  379. }
  380. pStubMsg->Buffer += MES_CTYPE_HEADER_SIZE;
  381. if ( IsNewPickling )
  382. {
  383. SYNTAX_TYPE SyntaxType;
  384. // read the remaining header.
  385. NdrpReadPicklingBuffer( pMesMsg, MES_NDR64_CTYPE_HEADER_SIZE - MES_CTYPE_HEADER_SIZE );
  386. pStubMsg->Buffer += 16; // skip over Reserved;
  387. SyntaxType = NdrpGetSyntaxType( (RPC_SYNTAX_IDENTIFIER *)pStubMsg->Buffer );
  388. if ( SyntaxType == XFER_SYNTAX_DCE )
  389. {
  390. pMesMsg->Operation = MES_DECODE;
  391. }
  392. else if ( SyntaxType = XFER_SYNTAX_NDR64 )
  393. {
  394. pMesMsg->Operation = ( MIDL_ES_CODE )MES_DECODE_NDR64;
  395. }
  396. else
  397. {
  398. RpcRaiseException( RPC_S_UNSUPPORTED_TRANS_SYN );
  399. }
  400. // skip over iid: we don't need it for now. might be used for verification.
  401. pStubMsg->Buffer += 2*sizeof( RPC_SYNTAX_IDENTIFIER );
  402. }
  403. SET_COMMON_TYPE_HEADER_IN( pMesMsg );
  404. }
  405. }
  406. void RPC_ENTRY
  407. Ndr64MesTypeDecode(
  408. handle_t Handle,
  409. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  410. const MIDL_STUB_DESC * pStubDesc,
  411. PFORMAT_STRING pFormat,
  412. void __RPC_FAR * pObject
  413. )
  414. {
  415. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  416. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  417. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  418. uchar __RPC_FAR * pBufferSaved, pTypeHeader;
  419. size_t RequiredLen, CommonHeaderSize, LengthSaved;
  420. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  421. NDR_ASSERT( pPicklingInfo->Flags.Oicf, "Oicf should always be on" )
  422. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  423. if( (LONG_PTR)pStubMsg->Buffer & 0xf )
  424. RpcRaiseException( RPC_X_INVALID_BUFFER );
  425. pStubMsg->BufferLength = 0xf & PtrToUlong( pStubMsg->Buffer );
  426. NdrpReadPicklingBuffer( pMesMsg, MES_NDR64_HEADER_SIZE );
  427. RequiredLen = (size_t) *(unsigned long __RPC_FAR *)pStubMsg->Buffer;
  428. pStubMsg->Buffer += MES_NDR64_HEADER_SIZE;
  429. NdrpReadPicklingBuffer( pMesMsg, RequiredLen );
  430. void * pArg = pObject;
  431. if ( NDR64_IS_POINTER_TYPE(*pFormat) )
  432. {
  433. // We have to dereference the pointer once.
  434. //
  435. pArg = *(void **)pArg;
  436. }
  437. RpcTryFinally
  438. {
  439. (Ndr64UnmarshallRoutinesTable[ NDR64_ROUTINE_INDEX( *pFormat )])
  440. ( pStubMsg,
  441. (uchar __RPC_FAR * __RPC_FAR *)&pArg,
  442. pFormat,
  443. FALSE );
  444. if ( NDR64_IS_POINTER_TYPE(*pFormat) )
  445. {
  446. // Don't drop the pointee, if it was allocated.
  447. *(void **)pObject = pArg;
  448. }
  449. // Next decoding needs to start at aligned to 8.
  450. ALIGN( pStubMsg->Buffer, 15 );
  451. }
  452. RpcFinally
  453. {
  454. Ndr64pPicklingClientFinally( pStubMsg, NULL ); // object
  455. }
  456. RpcEndFinally
  457. }
  458. void RPC_ENTRY
  459. NdrMesTypeDecode3(
  460. handle_t Handle,
  461. const MIDL_TYPE_PICKLING_INFO * pPicklingInfo,
  462. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  463. const unsigned long ** ArrTypeOffset,
  464. unsigned long nTypeIndex,
  465. void __RPC_FAR * pObject )
  466. {
  467. size_t RequiredLen;
  468. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  469. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  470. uchar * BufferSaved;
  471. PFNMESDECODE pfnDecode;
  472. MIDL_SYNTAX_INFO * pSyntaxInfo;
  473. PFORMAT_STRING pTypeFormat;
  474. SYNTAX_TYPE SyntaxType;
  475. NDR_PROC_CONTEXT ProcContext;
  476. if ( ! pObject )
  477. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  478. Ndr64pCommonTypeHeaderUnmarshall( pMesMsg );
  479. NdrpSetupMesTypeCommon( pfnDecode, NdrMesTypeDecode2, Ndr64MesTypeDecode );
  480. (* pfnDecode )( Handle, pPicklingInfo, pProxyInfo->pStubDesc, pTypeFormat, pObject );
  481. }
  482. void RPC_ENTRY
  483. Ndr64MesTypeFree(
  484. handle_t Handle,
  485. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  486. const MIDL_STUB_DESC * pStubDesc,
  487. PFORMAT_STRING pFormat,
  488. void __RPC_FAR * pObject
  489. )
  490. /*++
  491. Routine description:
  492. Free the object.
  493. Arguments:
  494. Handle - a pickling handle,
  495. pStubDesc - a pointer to the stub descriptor,
  496. pFormat - a pointer to the format code describing the object type
  497. pObject - a pointer to the object being freed.
  498. Returns:
  499. Note:
  500. The pickling header is included in the sizing.
  501. --*/
  502. {
  503. NDR_PROC_CONTEXT ProcContext;
  504. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  505. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  506. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  507. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  508. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  509. NDR_ASSERT( pPicklingInfo->Flags.Oicf, "Oicf should always be on" )
  510. if ( ! pObject )
  511. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  512. if( (LONG_PTR)pStubMsg->Buffer & 0xf )
  513. RpcRaiseException( RPC_X_INVALID_BUFFER );
  514. // Now the individual type object.
  515. if ( NDR64_IS_POINTER_TYPE(*pFormat) )
  516. {
  517. // We have to dereference the pointer once.
  518. pObject = *(void __RPC_FAR * __RPC_FAR *)pObject;
  519. }
  520. (Ndr64FreeRoutinesTable[ NDR64_ROUTINE_INDEX(*pFormat) ])
  521. ( pStubMsg,
  522. (uchar __RPC_FAR *)pObject,
  523. pFormat );
  524. Ndr64pPicklingClientFinally( pStubMsg, NULL ); // object
  525. }
  526. void RPC_ENTRY
  527. NdrMesTypeFree3(
  528. handle_t Handle,
  529. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  530. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  531. const unsigned long ** ArrTypeOffset,
  532. unsigned long nTypeIndex,
  533. void __RPC_FAR * pObject )
  534. {
  535. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  536. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  537. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  538. PFNMESFREE pfnFree;
  539. MIDL_SYNTAX_INFO * pSyntaxInfo;
  540. PFORMAT_STRING pTypeFormat;
  541. SYNTAX_TYPE SyntaxType;
  542. NDR_PROC_CONTEXT ProcContext;
  543. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  544. NdrpSetupMesTypeCommon( pfnFree, NdrMesTypeFree2, Ndr64MesTypeFree );
  545. (*pfnFree)(Handle, pxPicklingInfo, pProxyInfo->pStubDesc, pTypeFormat, pObject );
  546. }
  547. void
  548. Ndr64pMesProcEncodeInit( PMIDL_ES_MESSAGE pMesMsg,
  549. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  550. unsigned long nProcNum,
  551. MIDL_ES_CODE Operation,
  552. NDR_PROC_CONTEXT * pContext,
  553. uchar * StartofStack)
  554. {
  555. PMIDL_STUB_DESC pStubDesc = pProxyInfo->pStubDesc;
  556. SYNTAX_TYPE syntaxType;
  557. BOOL fUseEncode, fIsSupported = FALSE;
  558. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  559. RPC_STATUS res;
  560. // TODO: verify stub version.
  561. if ( Operation == MES_ENCODE )
  562. {
  563. syntaxType = XFER_SYNTAX_DCE;
  564. memcpy( &( (PMIDL_ES_MESSAGE_EX)pMesMsg )->TransferSyntax,
  565. &NDR_TRANSFER_SYNTAX ,
  566. sizeof( RPC_SYNTAX_IDENTIFIER ) );
  567. }
  568. else
  569. {
  570. syntaxType = XFER_SYNTAX_NDR64;
  571. memcpy( &( (PMIDL_ES_MESSAGE_EX)pMesMsg )->TransferSyntax,
  572. &NDR64_TRANSFER_SYNTAX ,
  573. sizeof( RPC_SYNTAX_IDENTIFIER ) );
  574. }
  575. Ndr64ClientInitializeContext( syntaxType, pProxyInfo, nProcNum, pContext, StartofStack );
  576. pStubMsg->pContext = pContext;
  577. pStubMsg->StubDesc = pStubDesc;
  578. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  579. pStubMsg->pfnFree = pStubDesc->pfnFree;
  580. // varify proc header
  581. if ( syntaxType == XFER_SYNTAX_DCE )
  582. {
  583. uchar InterpreterFlag = * ((uchar *)&pContext->NdrInfo.InterpreterFlags );
  584. fUseEncode = InterpreterFlag & ENCODE_IS_USED;
  585. memcpy( & (pContext->pfnInit), &SyncDcePicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  586. }
  587. else
  588. {
  589. fUseEncode = ( ( (NDR64_PROC_FLAGS *) & pContext->Ndr64Header->Flags)->IsEncode );
  590. memcpy( & (pContext->pfnInit), &SyncNdr64PicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  591. }
  592. if (!fUseEncode )
  593. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  594. }
  595. CLIENT_CALL_RETURN RPC_VAR_ENTRY
  596. NdrMesProcEncode3(
  597. PMIDL_ES_MESSAGE pMesMsg,
  598. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  599. unsigned long nProcNum,
  600. uchar * StartofStack )
  601. {
  602. PMIDL_STUB_MESSAGE pStubMsg = & pMesMsg->StubMsg;
  603. NDR_PROC_CONTEXT ProcContext;
  604. unsigned long ulAlignment;
  605. unsigned char * BufferSaved;
  606. size_t WriteLength;
  607. CLIENT_CALL_RETURN Ret;
  608. Ret.Simple = NULL;
  609. pMesMsg->ProcNumber = nProcNum;
  610. Ndr64pMesProcEncodeInit( pMesMsg,
  611. pProxyInfo,
  612. nProcNum,
  613. pMesMsg->Operation,
  614. &ProcContext,
  615. StartofStack );
  616. RpcTryFinally
  617. {
  618. ProcContext.pfnInit( pStubMsg,
  619. NULL ); // return value
  620. ProcContext.pfnSizing( pStubMsg,
  621. TRUE );
  622. if ( pMesMsg->Operation == MES_ENCODE )
  623. ulAlignment = 0x7;
  624. else
  625. ulAlignment = 0xf;
  626. // we are not changing the proc header, but we need to overestimate because
  627. // proc header is marshalled first.
  628. LENGTH_ALIGN( pStubMsg->BufferLength, ulAlignment );
  629. pStubMsg->BufferLength += MES_PROC_HEADER_SIZE ;
  630. LENGTH_ALIGN( pStubMsg->BufferLength, ulAlignment );
  631. size_t LengthSaved;
  632. NdrpAllocPicklingBuffer( pMesMsg, pStubMsg->BufferLength );
  633. BufferSaved = pStubMsg->Buffer;
  634. LengthSaved = pStubMsg->BufferLength;
  635. NDR_ASSERT( ( (ULONG_PTR)pStubMsg->Buffer & ulAlignment ) == 0, "pickling buffer is not aligned" );
  636. NdrpProcHeaderMarshallAll( pMesMsg );
  637. ALIGN( pStubMsg->Buffer, ulAlignment );
  638. ProcContext.pfnMarshal( pStubMsg,
  639. FALSE );
  640. ALIGN( pStubMsg->Buffer, ulAlignment );
  641. WriteLength = (size_t)(pStubMsg->Buffer - BufferSaved);
  642. * (unsigned long __RPC_FAR *)
  643. ( BufferSaved + MES_PROC_HEADER_SIZE - 4) =
  644. WriteLength - MES_PROC_HEADER_SIZE;
  645. if ( LengthSaved < WriteLength )
  646. {
  647. NDR_ASSERT( 0, "NdrMesProcEncodeDecode: encode buffer overflow" );
  648. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  649. }
  650. NdrpWritePicklingBuffer( pMesMsg, BufferSaved, WriteLength );
  651. }
  652. RpcFinally
  653. {
  654. ( *ProcContext.pfnClientFinally)( pStubMsg, NULL ); // not object
  655. }
  656. RpcEndFinally
  657. return Ret;
  658. }
  659. // both encode and decode acts like the client side.
  660. void
  661. Ndr64pMesProcDecodeInit( PMIDL_ES_MESSAGE pMesMsg,
  662. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  663. SYNTAX_TYPE SyntaxType,
  664. unsigned long nProcNum,
  665. NDR_PROC_CONTEXT * pContext,
  666. uchar * StartofStack )
  667. {
  668. RPC_STATUS res;
  669. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  670. unsigned long nFormatOffset;
  671. PMIDL_STUB_DESC pStubDesc = pProxyInfo->pStubDesc;
  672. BOOL fUseDecode;
  673. // REVIEW: Calling the "Client" init for decode seems weird but it does
  674. // the right thing and NdrServerSetupMultipleTransferSyntax assumes
  675. // ndr64.
  676. Ndr64ClientInitializeContext(
  677. SyntaxType,
  678. pProxyInfo,
  679. nProcNum,
  680. pContext,
  681. StartofStack );
  682. pStubMsg->pContext = pContext;
  683. pStubMsg->StubDesc = pStubDesc;
  684. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  685. pStubMsg->pfnFree = pStubDesc->pfnFree;
  686. NdrpDataBufferInit( pMesMsg, pContext->pProcFormat );
  687. if ( SyntaxType == XFER_SYNTAX_DCE )
  688. {
  689. uchar InterpreterFlag = * ((uchar *)&pContext->NdrInfo.InterpreterFlags );
  690. fUseDecode = InterpreterFlag & DECODE_IS_USED;
  691. memcpy( & (pContext->pfnInit), &SyncDcePicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  692. }
  693. else
  694. {
  695. fUseDecode = ( ( (NDR64_PROC_FLAGS *) & pContext->Ndr64Header->Flags)->IsDecode );
  696. memcpy( & (pContext->pfnInit), &SyncNdr64PicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  697. }
  698. if (!fUseDecode )
  699. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  700. }
  701. CLIENT_CALL_RETURN RPC_VAR_ENTRY
  702. NdrMesProcDecode3(
  703. PMIDL_ES_MESSAGE pMesMsg,
  704. const MIDL_STUBLESS_PROXY_INFO *pProxyInfo,
  705. unsigned long nProcNum,
  706. uchar * StartofStack,
  707. void * pReturnValue )
  708. {
  709. CLIENT_CALL_RETURN RetVal;
  710. NDR_PROC_CONTEXT ProcContext;
  711. SYNTAX_TYPE SyntaxType;
  712. PMIDL_STUB_MESSAGE pStubMsg = & pMesMsg->StubMsg;
  713. NDR64_PROC_FLAGS *ProcFlags;
  714. unsigned long ulAlign;
  715. long HasComplexReturn;
  716. RetVal.Simple = NULL;
  717. if (NULL == pReturnValue )
  718. pReturnValue = &RetVal;
  719. if ( GET_MES_HEADER_PEEKED( pMesMsg ) )
  720. {
  721. // This makes it possible to encode/decode several procs one after
  722. // another with the same pickling handle (using the same buffer).
  723. CLEAR_MES_HEADER_PEEKED( pMesMsg );
  724. }
  725. else
  726. NdrpProcHeaderUnmarshallAll( pMesMsg );
  727. SyntaxType = NdrpGetSyntaxType( &((PMIDL_ES_MESSAGE_EX)pMesMsg)->TransferSyntax );
  728. if ( SyntaxType == XFER_SYNTAX_DCE )
  729. {
  730. pMesMsg->Operation = MES_DECODE;
  731. ulAlign = 0x7;
  732. }
  733. else if ( SyntaxType == XFER_SYNTAX_NDR64 )
  734. {
  735. pMesMsg->Operation = ( MIDL_ES_CODE )MES_DECODE_NDR64;
  736. ulAlign = 0xf;
  737. }
  738. else
  739. RpcRaiseException( RPC_S_UNSUPPORTED_TRANS_SYN );
  740. if ( (LONG_PTR)pStubMsg->BufferStart & ulAlign )
  741. RpcRaiseException( RPC_X_INVALID_BUFFER );
  742. Ndr64pMesProcDecodeInit( pMesMsg,
  743. pProxyInfo,
  744. SyntaxType,
  745. nProcNum,
  746. &ProcContext,
  747. StartofStack );
  748. RpcTryFinally
  749. {
  750. ProcContext.pfnInit( pStubMsg,
  751. NULL ); // return value
  752. ALIGN( pStubMsg->Buffer, ulAlign );
  753. ProcContext.pfnUnMarshal( pStubMsg,
  754. ProcContext.HasComplexReturn
  755. ? &pReturnValue
  756. : pReturnValue );
  757. // prepare for new decoding.
  758. ALIGN( pStubMsg->Buffer, ulAlign );
  759. }
  760. RpcFinally
  761. {
  762. ( *ProcContext.pfnClientFinally)( pStubMsg, NULL ); // object
  763. }
  764. RpcEndFinally
  765. return *(CLIENT_CALL_RETURN *)pReturnValue;
  766. }
  767. CLIENT_CALL_RETURN RPC_VAR_ENTRY
  768. NdrMesProcEncodeDecode3(
  769. handle_t Handle,
  770. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  771. unsigned long nProcNum,
  772. void *pReturnValue,
  773. ... )
  774. {
  775. BOOL fMoreParams;
  776. PFORMAT_STRING pProcFormat;
  777. void __RPC_FAR * pArg;
  778. va_list ArgList;
  779. unsigned char * BufferSaved;
  780. size_t WriteLength;
  781. uchar * StartofStack;
  782. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  783. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  784. INIT_ARG( ArgList, pReturnValue );
  785. GET_FIRST_IN_ARG(ArgList);
  786. StartofStack = (uchar *)GET_STACK_START(ArgList);
  787. if ( pMesMsg->Operation == MES_ENCODE ||
  788. pMesMsg->Operation == MES_ENCODE_NDR64 )
  789. return NdrMesProcEncode3( (PMIDL_ES_MESSAGE)Handle, pProxyInfo, nProcNum, StartofStack );
  790. else
  791. return NdrMesProcDecode3( (PMIDL_ES_MESSAGE)Handle, pProxyInfo, nProcNum, StartofStack, pReturnValue );
  792. }
  793. void RPC_ENTRY
  794. NdrpPicklingClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  795. void * pThis )
  796. {
  797. NDR_PROC_CONTEXT * pContext = (NDR_PROC_CONTEXT *) pStubMsg->pContext;
  798. PMIDL_STUB_DESC pStubDesc = pStubMsg->StubDesc;
  799. NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
  800. NdrCorrelationFree( pStubMsg );
  801. NdrpAllocaDestroy( & pContext->AllocateContext );
  802. }
  803. void RPC_ENTRY
  804. Ndr64pPicklingClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  805. void * pThis )
  806. {
  807. NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
  808. NdrpAllocaDestroy( & ( (NDR_PROC_CONTEXT *)pStubMsg->pContext )->AllocateContext );
  809. }
  810. // =======================================================================
  811. //
  812. // Ready to use AlignSize routines for simple types
  813. //
  814. // =======================================================================
  815. void ValidateMesSimpleTypeAll( const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  816. MIDL_ES_CODE Operation )
  817. {
  818. ulong i;
  819. SYNTAX_TYPE SyntaxType;
  820. if ( Operation == MES_ENCODE ||
  821. Operation == MES_DECODE )
  822. SyntaxType = XFER_SYNTAX_DCE;
  823. else
  824. SyntaxType = XFER_SYNTAX_NDR64;
  825. for ( i = 0; i < ( ulong )pProxyInfo->nCount; i++ )
  826. {
  827. if ( NdrpGetSyntaxType( &pProxyInfo->pSyntaxInfo[i].TransferSyntax ) == SyntaxType )
  828. break;
  829. }
  830. // Raise exception if we didn't find the supported syntax in proxyinfo.
  831. if ( i >= pProxyInfo->nCount )
  832. RpcRaiseException( RPC_S_UNSUPPORTED_TRANS_SYN );
  833. }
  834. size_t RPC_ENTRY
  835. NdrMesSimpleTypeAlignSizeAll(
  836. handle_t Handle,
  837. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo
  838. )
  839. /*++
  840. Size is always 8 bytes for data and there is no header here per data.
  841. However, the common header gets included for the first object.
  842. --*/
  843. {
  844. if ( (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE &&
  845. (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE_NDR64 )
  846. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  847. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  848. PMIDL_STUB_MESSAGE pStubMsg = &((PMIDL_ES_MESSAGE) Handle)->StubMsg;
  849. ValidateMesSimpleTypeAll( pProxyInfo, ((PMIDL_ES_MESSAGE)Handle)->Operation );
  850. unsigned long OldLength = pStubMsg->BufferLength;
  851. if ( ((PMIDL_ES_MESSAGE)Handle)->Operation == MES_ENCODE )
  852. {
  853. if( (long)( pStubMsg->BufferLength & 0x7 ) )
  854. RpcRaiseException( RPC_X_INVALID_BUFFER );
  855. NdrpCommonTypeHeaderSize( (PMIDL_ES_MESSAGE)Handle );
  856. pStubMsg->BufferLength += 8;
  857. }
  858. else
  859. {
  860. if( (long)( pStubMsg->BufferLength & 0xf ) )
  861. RpcRaiseException( RPC_X_INVALID_BUFFER );
  862. Ndr64pCommonTypeHeaderSize( (PMIDL_ES_MESSAGE)Handle );
  863. LENGTH_ALIGN( pStubMsg->BufferLength, 0xf );
  864. pStubMsg->BufferLength += 16;
  865. }
  866. return( (size_t)(pStubMsg->BufferLength - OldLength) );
  867. }
  868. // =======================================================================
  869. //
  870. // Ready to use Encode routines for simple types
  871. //
  872. // =======================================================================
  873. void RPC_ENTRY
  874. NdrMesSimpleTypeEncodeAll(
  875. handle_t Handle,
  876. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  877. const void __RPC_FAR * pData,
  878. short Size )
  879. /*++
  880. Marshall a simple type entity. There is no header here per data.
  881. However, the common header gets included for the first object.
  882. --*/
  883. {
  884. if ( (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE &&
  885. (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE_NDR64 )
  886. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  887. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  888. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  889. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  890. PMIDL_STUB_DESC pStubDesc = pProxyInfo->pStubDesc;
  891. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  892. pStubMsg->pfnFree = pStubDesc->pfnFree;
  893. unsigned long ulAlignment;
  894. size_t RequiredLen;
  895. // Size and allocate the buffer.
  896. // The req len includes: (the common header) and the data
  897. // Take the pointer alignment to come up with the right size.
  898. pStubMsg->BufferLength = 0xf & PtrToUlong( pStubMsg->Buffer );
  899. RequiredLen = NdrMesSimpleTypeAlignSizeAll( Handle, pProxyInfo );
  900. NdrpAllocPicklingBuffer( pMesMsg, RequiredLen );
  901. // See if we need to marshall the common type header
  902. uchar __RPC_FAR * pBufferSaved = pStubMsg->Buffer;
  903. if ( pMesMsg->Operation == MES_ENCODE )
  904. {
  905. NdrpCommonTypeHeaderMarshall( pMesMsg );
  906. ulAlignment = 0x7;
  907. }
  908. else if ( pMesMsg->Operation == MES_ENCODE_NDR64 )
  909. {
  910. Ndr64pCommonTypeHeaderMarshall( pMesMsg );
  911. ulAlignment = 0xf;
  912. }
  913. else
  914. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  915. ALIGN( pStubMsg->Buffer, ulAlignment );
  916. switch ( Size )
  917. {
  918. case 1:
  919. * PCHAR_CAST pStubMsg->Buffer = * PCHAR_CAST pData;
  920. break;
  921. case 2:
  922. * PSHORT_CAST pStubMsg->Buffer = * PSHORT_CAST pData;
  923. break;
  924. case 4:
  925. * PLONG_CAST pStubMsg->Buffer = * PLONG_CAST pData;
  926. break;
  927. case 8:
  928. * PHYPER_CAST pStubMsg->Buffer = * PHYPER_CAST pData;
  929. break;
  930. default:
  931. NDR_ASSERT( 0, " Size generation problem" );
  932. }
  933. pStubMsg->Buffer += ulAlignment+1;
  934. NdrpWritePicklingBuffer( pMesMsg, pBufferSaved, RequiredLen );
  935. }
  936. // =======================================================================
  937. //
  938. // Ready to use Decode routines for simple types
  939. //
  940. // =======================================================================
  941. void RPC_ENTRY
  942. NdrMesSimpleTypeDecodeAll(
  943. handle_t Handle,
  944. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  945. void __RPC_FAR * pData,
  946. short FormatChar )
  947. /*++
  948. Does not include the header for the data.
  949. However, the common header gets included for the first object.
  950. Note. Endianness and other conversions for decode.
  951. This has been deemed as not worthy doing in the Daytona time frame.
  952. However, to be able to add it in future without backward compatibility
  953. problems, we have the last argument to be the format character as
  954. opposed to the size.
  955. This makes it possible to call NdrSimpleTypeConvert, if needed.
  956. Note that the compiler uses the 32bit tokens for this since this routine
  957. is common to both formats.
  958. --*/
  959. {
  960. if ( ( (PMIDL_ES_MESSAGE)Handle )->Operation != MES_DECODE &&
  961. ( (PMIDL_ES_MESSAGE)Handle )->Operation != MES_DECODE_NDR64 )
  962. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  963. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  964. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  965. PMIDL_STUB_MESSAGE pStubMsg = &((PMIDL_ES_MESSAGE)Handle)->StubMsg;
  966. uchar * BufferSaved;
  967. unsigned long ulAlignment;
  968. // See if we need to unmarshall the common type header.
  969. Ndr64pCommonTypeHeaderUnmarshall( pMesMsg );
  970. // Now the data.
  971. if ( pMesMsg->Operation == MES_DECODE )
  972. {
  973. NdrpReadPicklingBuffer( (PMIDL_ES_MESSAGE) Handle, 8);
  974. ulAlignment = 0x7;
  975. }
  976. else
  977. {
  978. NdrpReadPicklingBuffer( (PMIDL_ES_MESSAGE) Handle, 16);
  979. ulAlignment = 0xf;
  980. }
  981. NDR_ASSERT( ( (ULONG_PTR)pStubMsg->Buffer & ulAlignment ) == 0, "invalid buffer alignment in simple type pickling" );
  982. ValidateMesSimpleTypeAll( pProxyInfo, ((PMIDL_ES_MESSAGE)Handle)->Operation );
  983. if ( pMesMsg->AlienDataRep != NDR_LOCAL_DATA_REPRESENTATION )
  984. {
  985. pStubMsg->RpcMsg->DataRepresentation = pMesMsg->AlienDataRep;
  986. BufferSaved = pStubMsg->Buffer;
  987. NdrSimpleTypeConvert( pStubMsg, (unsigned char)FormatChar );
  988. pStubMsg->Buffer = BufferSaved;
  989. }
  990. switch ( FormatChar )
  991. {
  992. case FC_BYTE:
  993. case FC_CHAR:
  994. case FC_SMALL:
  995. case FC_USMALL:
  996. * PCHAR_CAST pData = * PCHAR_CAST pStubMsg->Buffer;
  997. break;
  998. case FC_WCHAR:
  999. case FC_SHORT:
  1000. case FC_USHORT:
  1001. * PSHORT_CAST pData = * PSHORT_CAST pStubMsg->Buffer;
  1002. break;
  1003. case FC_LONG:
  1004. case FC_ULONG:
  1005. case FC_FLOAT:
  1006. case FC_ENUM32:
  1007. case FC_ERROR_STATUS_T:
  1008. * PLONG_CAST pData = * PLONG_CAST pStubMsg->Buffer;
  1009. break;
  1010. case FC_HYPER:
  1011. case FC_DOUBLE:
  1012. * PHYPER_CAST pData = * PHYPER_CAST pStubMsg->Buffer;
  1013. break;
  1014. #if defined(__RPC_WIN64__)
  1015. case FC_INT3264:
  1016. if (pMesMsg->Operation == MES_DECODE )
  1017. *((INT64 *)pData) = *((long *) pStubMsg->Buffer);
  1018. else
  1019. *((INT64 *)pData) = *((INT64 *) pStubMsg->Buffer);
  1020. break;
  1021. case FC_UINT3264:
  1022. if (pMesMsg->Operation == MES_DECODE )
  1023. *((UINT64 *)pData) = *((ulong *)pStubMsg->Buffer);
  1024. else
  1025. *((UINT64 *)pData) = *((UINT64 *)pStubMsg->Buffer);
  1026. break;
  1027. #endif
  1028. default:
  1029. NDR_ASSERT( 0, " Size generation problem for simple types" );
  1030. }
  1031. pStubMsg->Buffer += ulAlignment+1;
  1032. }