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.

1321 lines
43 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( NdrServerUnmarshallExceptionFlag(GetExceptionInformation()) )
  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( NdrServerUnmarshallExceptionFlag(GetExceptionInformation()) )
  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. if ( pStubMsg->pCorrInfo )
  450. Ndr64CorrelationPass( pStubMsg );
  451. // Next decoding needs to start at aligned to 16.
  452. ALIGN( pStubMsg->Buffer, 15 );
  453. }
  454. RpcFinally
  455. {
  456. Ndr64pPicklingClientFinally( pStubMsg, NULL ); // object
  457. }
  458. RpcEndFinally
  459. }
  460. void RPC_ENTRY
  461. NdrMesTypeDecode3(
  462. handle_t Handle,
  463. const MIDL_TYPE_PICKLING_INFO * pPicklingInfo,
  464. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  465. const unsigned long ** ArrTypeOffset,
  466. unsigned long nTypeIndex,
  467. void __RPC_FAR * pObject )
  468. {
  469. size_t RequiredLen;
  470. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  471. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  472. uchar * BufferSaved;
  473. PFNMESDECODE pfnDecode;
  474. MIDL_SYNTAX_INFO * pSyntaxInfo;
  475. PFORMAT_STRING pTypeFormat;
  476. SYNTAX_TYPE SyntaxType;
  477. NDR_PROC_CONTEXT ProcContext;
  478. if ( ! pObject )
  479. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  480. Ndr64pCommonTypeHeaderUnmarshall( pMesMsg );
  481. NdrpSetupMesTypeCommon( pfnDecode, NdrMesTypeDecode2, Ndr64MesTypeDecode );
  482. (* pfnDecode )( Handle, pPicklingInfo, pProxyInfo->pStubDesc, pTypeFormat, pObject );
  483. }
  484. void RPC_ENTRY
  485. Ndr64MesTypeFree(
  486. handle_t Handle,
  487. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  488. const MIDL_STUB_DESC * pStubDesc,
  489. PFORMAT_STRING pFormat,
  490. void __RPC_FAR * pObject
  491. )
  492. /*++
  493. Routine description:
  494. Free the object.
  495. Arguments:
  496. Handle - a pickling handle,
  497. pStubDesc - a pointer to the stub descriptor,
  498. pFormat - a pointer to the format code describing the object type
  499. pObject - a pointer to the object being freed.
  500. Returns:
  501. Note:
  502. The pickling header is included in the sizing.
  503. --*/
  504. {
  505. NDR_PROC_CONTEXT ProcContext;
  506. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  507. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  508. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  509. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  510. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  511. NDR_ASSERT( pPicklingInfo->Flags.Oicf, "Oicf should always be on" )
  512. if ( ! pObject )
  513. RpcRaiseException( RPC_X_NULL_REF_POINTER );
  514. if( (LONG_PTR)pStubMsg->Buffer & 0xf )
  515. RpcRaiseException( RPC_X_INVALID_BUFFER );
  516. // Now the individual type object.
  517. if ( NDR64_IS_POINTER_TYPE(*pFormat) )
  518. {
  519. // We have to dereference the pointer once.
  520. pObject = *(void __RPC_FAR * __RPC_FAR *)pObject;
  521. }
  522. (Ndr64FreeRoutinesTable[ NDR64_ROUTINE_INDEX(*pFormat) ])
  523. ( pStubMsg,
  524. (uchar __RPC_FAR *)pObject,
  525. pFormat );
  526. Ndr64pPicklingClientFinally( pStubMsg, NULL ); // object
  527. }
  528. void RPC_ENTRY
  529. NdrMesTypeFree3(
  530. handle_t Handle,
  531. const MIDL_TYPE_PICKLING_INFO * pxPicklingInfo,
  532. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  533. const unsigned long ** ArrTypeOffset,
  534. unsigned long nTypeIndex,
  535. void __RPC_FAR * pObject )
  536. {
  537. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  538. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  539. PMIDL_TYPE_PICKLING_INFOp pPicklingInfo;
  540. PFNMESFREE pfnFree;
  541. MIDL_SYNTAX_INFO * pSyntaxInfo;
  542. PFORMAT_STRING pTypeFormat;
  543. SYNTAX_TYPE SyntaxType;
  544. NDR_PROC_CONTEXT ProcContext;
  545. pPicklingInfo = (PMIDL_TYPE_PICKLING_INFOp) pxPicklingInfo;
  546. NdrpSetupMesTypeCommon( pfnFree, NdrMesTypeFree2, Ndr64MesTypeFree );
  547. (*pfnFree)(Handle, pxPicklingInfo, pProxyInfo->pStubDesc, pTypeFormat, pObject );
  548. }
  549. void
  550. Ndr64pMesProcEncodeInit( PMIDL_ES_MESSAGE pMesMsg,
  551. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  552. unsigned long nProcNum,
  553. MIDL_ES_CODE Operation,
  554. NDR_PROC_CONTEXT * pContext,
  555. uchar * StartofStack)
  556. {
  557. PMIDL_STUB_DESC pStubDesc = pProxyInfo->pStubDesc;
  558. SYNTAX_TYPE syntaxType;
  559. BOOL fUseEncode, fIsSupported = FALSE;
  560. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  561. RPC_STATUS res;
  562. // TODO: verify stub version.
  563. if ( Operation == MES_ENCODE )
  564. {
  565. syntaxType = XFER_SYNTAX_DCE;
  566. memcpy( &( (PMIDL_ES_MESSAGE_EX)pMesMsg )->TransferSyntax,
  567. &NDR_TRANSFER_SYNTAX ,
  568. sizeof( RPC_SYNTAX_IDENTIFIER ) );
  569. }
  570. else
  571. {
  572. syntaxType = XFER_SYNTAX_NDR64;
  573. memcpy( &( (PMIDL_ES_MESSAGE_EX)pMesMsg )->TransferSyntax,
  574. &NDR64_TRANSFER_SYNTAX ,
  575. sizeof( RPC_SYNTAX_IDENTIFIER ) );
  576. }
  577. Ndr64ClientInitializeContext( syntaxType, pProxyInfo, nProcNum, pContext, StartofStack );
  578. pStubMsg->pContext = pContext;
  579. pStubMsg->StubDesc = pStubDesc;
  580. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  581. pStubMsg->pfnFree = pStubDesc->pfnFree;
  582. // varify proc header
  583. if ( syntaxType == XFER_SYNTAX_DCE )
  584. {
  585. uchar InterpreterFlag = * ((uchar *)&pContext->NdrInfo.InterpreterFlags );
  586. fUseEncode = InterpreterFlag & ENCODE_IS_USED;
  587. memcpy( & (pContext->pfnInit), &SyncDcePicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  588. }
  589. else
  590. {
  591. fUseEncode = ( ( (NDR64_PROC_FLAGS *) & pContext->Ndr64Header->Flags)->IsEncode );
  592. memcpy( & (pContext->pfnInit), &SyncNdr64PicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  593. }
  594. if (!fUseEncode )
  595. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  596. }
  597. CLIENT_CALL_RETURN RPC_VAR_ENTRY
  598. NdrMesProcEncode3(
  599. PMIDL_ES_MESSAGE pMesMsg,
  600. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  601. unsigned long nProcNum,
  602. uchar * StartofStack )
  603. {
  604. PMIDL_STUB_MESSAGE pStubMsg = & pMesMsg->StubMsg;
  605. NDR_PROC_CONTEXT ProcContext;
  606. unsigned long ulAlignment;
  607. unsigned char * BufferSaved;
  608. size_t WriteLength;
  609. CLIENT_CALL_RETURN Ret;
  610. Ret.Simple = NULL;
  611. pMesMsg->ProcNumber = nProcNum;
  612. Ndr64pMesProcEncodeInit( pMesMsg,
  613. pProxyInfo,
  614. nProcNum,
  615. pMesMsg->Operation,
  616. &ProcContext,
  617. StartofStack );
  618. RpcTryFinally
  619. {
  620. ProcContext.pfnInit( pStubMsg,
  621. NULL ); // return value
  622. ProcContext.pfnSizing( pStubMsg,
  623. TRUE );
  624. if ( pMesMsg->Operation == MES_ENCODE )
  625. ulAlignment = 0x7;
  626. else
  627. ulAlignment = 0xf;
  628. // we are not changing the proc header, but we need to overestimate because
  629. // proc header is marshalled first.
  630. LENGTH_ALIGN( pStubMsg->BufferLength, ulAlignment );
  631. pStubMsg->BufferLength += MES_PROC_HEADER_SIZE ;
  632. LENGTH_ALIGN( pStubMsg->BufferLength, ulAlignment );
  633. size_t LengthSaved;
  634. NdrpAllocPicklingBuffer( pMesMsg, pStubMsg->BufferLength );
  635. BufferSaved = pStubMsg->Buffer;
  636. LengthSaved = pStubMsg->BufferLength;
  637. NDR_ASSERT( ( (ULONG_PTR)pStubMsg->Buffer & ulAlignment ) == 0, "pickling buffer is not aligned" );
  638. NdrpProcHeaderMarshallAll( pMesMsg );
  639. ALIGN( pStubMsg->Buffer, ulAlignment );
  640. ProcContext.pfnMarshal( pStubMsg,
  641. FALSE );
  642. ALIGN( pStubMsg->Buffer, ulAlignment );
  643. WriteLength = (size_t)(pStubMsg->Buffer - BufferSaved);
  644. * (unsigned long __RPC_FAR *)
  645. ( BufferSaved + MES_PROC_HEADER_SIZE - 4) =
  646. WriteLength - MES_PROC_HEADER_SIZE;
  647. if ( LengthSaved < WriteLength )
  648. {
  649. NDR_ASSERT( 0, "NdrMesProcEncodeDecode: encode buffer overflow" );
  650. RpcRaiseException( RPC_S_INTERNAL_ERROR );
  651. }
  652. NdrpWritePicklingBuffer( pMesMsg, BufferSaved, WriteLength );
  653. }
  654. RpcFinally
  655. {
  656. ( *ProcContext.pfnClientFinally)( pStubMsg, NULL ); // not object
  657. }
  658. RpcEndFinally
  659. return Ret;
  660. }
  661. // both encode and decode acts like the client side.
  662. void
  663. Ndr64pMesProcDecodeInit( PMIDL_ES_MESSAGE pMesMsg,
  664. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  665. SYNTAX_TYPE SyntaxType,
  666. unsigned long nProcNum,
  667. NDR_PROC_CONTEXT * pContext,
  668. uchar * StartofStack )
  669. {
  670. RPC_STATUS res;
  671. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  672. unsigned long nFormatOffset;
  673. PMIDL_STUB_DESC pStubDesc = pProxyInfo->pStubDesc;
  674. BOOL fUseDecode;
  675. // REVIEW: Calling the "Client" init for decode seems weird but it does
  676. // the right thing and NdrServerSetupMultipleTransferSyntax assumes
  677. // ndr64.
  678. Ndr64ClientInitializeContext(
  679. SyntaxType,
  680. pProxyInfo,
  681. nProcNum,
  682. pContext,
  683. StartofStack );
  684. pStubMsg->pContext = pContext;
  685. pStubMsg->StubDesc = pStubDesc;
  686. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  687. pStubMsg->pfnFree = pStubDesc->pfnFree;
  688. NdrpDataBufferInit( pMesMsg, pContext->pProcFormat );
  689. if ( SyntaxType == XFER_SYNTAX_DCE )
  690. {
  691. uchar InterpreterFlag = * ((uchar *)&pContext->NdrInfo.InterpreterFlags );
  692. fUseDecode = InterpreterFlag & DECODE_IS_USED;
  693. memcpy( & (pContext->pfnInit), &SyncDcePicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  694. }
  695. else
  696. {
  697. fUseDecode = ( ( (NDR64_PROC_FLAGS *) & pContext->Ndr64Header->Flags)->IsDecode );
  698. memcpy( & (pContext->pfnInit), &SyncNdr64PicklingClient, sizeof( SYNTAX_DISPATCH_TABLE ) );
  699. }
  700. if (!fUseDecode )
  701. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  702. }
  703. CLIENT_CALL_RETURN RPC_VAR_ENTRY
  704. NdrMesProcDecode3(
  705. PMIDL_ES_MESSAGE pMesMsg,
  706. const MIDL_STUBLESS_PROXY_INFO *pProxyInfo,
  707. unsigned long nProcNum,
  708. uchar * StartofStack,
  709. void * pReturnValue )
  710. {
  711. CLIENT_CALL_RETURN RetVal;
  712. NDR_PROC_CONTEXT ProcContext;
  713. SYNTAX_TYPE SyntaxType;
  714. PMIDL_STUB_MESSAGE pStubMsg = & pMesMsg->StubMsg;
  715. NDR64_PROC_FLAGS *ProcFlags;
  716. unsigned long ulAlign;
  717. long HasComplexReturn;
  718. RetVal.Simple = NULL;
  719. if (NULL == pReturnValue )
  720. pReturnValue = &RetVal;
  721. if ( GET_MES_HEADER_PEEKED( pMesMsg ) )
  722. {
  723. // This makes it possible to encode/decode several procs one after
  724. // another with the same pickling handle (using the same buffer).
  725. CLEAR_MES_HEADER_PEEKED( pMesMsg );
  726. }
  727. else
  728. NdrpProcHeaderUnmarshallAll( pMesMsg );
  729. SyntaxType = NdrpGetSyntaxType( &((PMIDL_ES_MESSAGE_EX)pMesMsg)->TransferSyntax );
  730. if ( SyntaxType == XFER_SYNTAX_DCE )
  731. {
  732. pMesMsg->Operation = MES_DECODE;
  733. ulAlign = 0x7;
  734. }
  735. else if ( SyntaxType == XFER_SYNTAX_NDR64 )
  736. {
  737. pMesMsg->Operation = ( MIDL_ES_CODE )MES_DECODE_NDR64;
  738. ulAlign = 0xf;
  739. }
  740. else
  741. RpcRaiseException( RPC_S_UNSUPPORTED_TRANS_SYN );
  742. if ( (LONG_PTR)pStubMsg->BufferStart & ulAlign )
  743. RpcRaiseException( RPC_X_INVALID_BUFFER );
  744. Ndr64pMesProcDecodeInit( pMesMsg,
  745. pProxyInfo,
  746. SyntaxType,
  747. nProcNum,
  748. &ProcContext,
  749. StartofStack );
  750. RpcTryFinally
  751. {
  752. ProcContext.pfnInit( pStubMsg,
  753. NULL ); // return value
  754. ALIGN( pStubMsg->Buffer, ulAlign );
  755. ProcContext.pfnUnMarshal( pStubMsg,
  756. ProcContext.HasComplexReturn
  757. ? &pReturnValue
  758. : pReturnValue );
  759. // prepare for new decoding.
  760. ALIGN( pStubMsg->Buffer, ulAlign );
  761. }
  762. RpcFinally
  763. {
  764. ( *ProcContext.pfnClientFinally)( pStubMsg, NULL ); // object
  765. }
  766. RpcEndFinally
  767. return *(CLIENT_CALL_RETURN *)pReturnValue;
  768. }
  769. CLIENT_CALL_RETURN RPC_VAR_ENTRY
  770. NdrMesProcEncodeDecode3(
  771. handle_t Handle,
  772. const MIDL_STUBLESS_PROXY_INFO* pProxyInfo,
  773. unsigned long nProcNum,
  774. void *pReturnValue,
  775. ... )
  776. {
  777. BOOL fMoreParams;
  778. PFORMAT_STRING pProcFormat;
  779. void __RPC_FAR * pArg;
  780. va_list ArgList;
  781. unsigned char * BufferSaved;
  782. size_t WriteLength;
  783. uchar * StartofStack;
  784. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  785. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  786. INIT_ARG( ArgList, pReturnValue );
  787. GET_FIRST_IN_ARG(ArgList);
  788. StartofStack = (uchar *)GET_STACK_START(ArgList);
  789. if ( pMesMsg->Operation == MES_ENCODE ||
  790. pMesMsg->Operation == MES_ENCODE_NDR64 )
  791. return NdrMesProcEncode3( (PMIDL_ES_MESSAGE)Handle, pProxyInfo, nProcNum, StartofStack );
  792. else
  793. return NdrMesProcDecode3( (PMIDL_ES_MESSAGE)Handle, pProxyInfo, nProcNum, StartofStack, pReturnValue );
  794. }
  795. void RPC_ENTRY
  796. NdrpPicklingClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  797. void * pThis )
  798. {
  799. NDR_PROC_CONTEXT * pContext = (NDR_PROC_CONTEXT *) pStubMsg->pContext;
  800. PMIDL_STUB_DESC pStubDesc = pStubMsg->StubDesc;
  801. NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
  802. NdrCorrelationFree( pStubMsg );
  803. NdrpAllocaDestroy( & pContext->AllocateContext );
  804. }
  805. void RPC_ENTRY
  806. Ndr64pPicklingClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  807. void * pThis )
  808. {
  809. NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
  810. NdrpAllocaDestroy( & ( (NDR_PROC_CONTEXT *)pStubMsg->pContext )->AllocateContext );
  811. }
  812. // =======================================================================
  813. //
  814. // Ready to use AlignSize routines for simple types
  815. //
  816. // =======================================================================
  817. void ValidateMesSimpleTypeAll( const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  818. MIDL_ES_CODE Operation )
  819. {
  820. ulong i;
  821. SYNTAX_TYPE SyntaxType;
  822. if ( Operation == MES_ENCODE ||
  823. Operation == MES_DECODE )
  824. SyntaxType = XFER_SYNTAX_DCE;
  825. else
  826. SyntaxType = XFER_SYNTAX_NDR64;
  827. for ( i = 0; i < ( ulong )pProxyInfo->nCount; i++ )
  828. {
  829. if ( NdrpGetSyntaxType( &pProxyInfo->pSyntaxInfo[i].TransferSyntax ) == SyntaxType )
  830. break;
  831. }
  832. // Raise exception if we didn't find the supported syntax in proxyinfo.
  833. if ( i >= pProxyInfo->nCount )
  834. RpcRaiseException( RPC_S_UNSUPPORTED_TRANS_SYN );
  835. }
  836. size_t RPC_ENTRY
  837. NdrMesSimpleTypeAlignSizeAll(
  838. handle_t Handle,
  839. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo
  840. )
  841. /*++
  842. Size is always 8 bytes for data and there is no header here per data.
  843. However, the common header gets included for the first object.
  844. --*/
  845. {
  846. if ( (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE &&
  847. (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE_NDR64 )
  848. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  849. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  850. PMIDL_STUB_MESSAGE pStubMsg = &((PMIDL_ES_MESSAGE) Handle)->StubMsg;
  851. ValidateMesSimpleTypeAll( pProxyInfo, ((PMIDL_ES_MESSAGE)Handle)->Operation );
  852. unsigned long OldLength = pStubMsg->BufferLength;
  853. if ( ((PMIDL_ES_MESSAGE)Handle)->Operation == MES_ENCODE )
  854. {
  855. if( (long)( pStubMsg->BufferLength & 0x7 ) )
  856. RpcRaiseException( RPC_X_INVALID_BUFFER );
  857. NdrpCommonTypeHeaderSize( (PMIDL_ES_MESSAGE)Handle );
  858. pStubMsg->BufferLength += 8;
  859. }
  860. else
  861. {
  862. if( (long)( pStubMsg->BufferLength & 0xf ) )
  863. RpcRaiseException( RPC_X_INVALID_BUFFER );
  864. Ndr64pCommonTypeHeaderSize( (PMIDL_ES_MESSAGE)Handle );
  865. LENGTH_ALIGN( pStubMsg->BufferLength, 0xf );
  866. pStubMsg->BufferLength += 16;
  867. }
  868. return( (size_t)(pStubMsg->BufferLength - OldLength) );
  869. }
  870. // =======================================================================
  871. //
  872. // Ready to use Encode routines for simple types
  873. //
  874. // =======================================================================
  875. void RPC_ENTRY
  876. NdrMesSimpleTypeEncodeAll(
  877. handle_t Handle,
  878. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  879. const void __RPC_FAR * pData,
  880. short Size )
  881. /*++
  882. Marshall a simple type entity. There is no header here per data.
  883. However, the common header gets included for the first object.
  884. --*/
  885. {
  886. if ( (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE &&
  887. (( PMIDL_ES_MESSAGE)Handle )->Operation != MES_ENCODE_NDR64 )
  888. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  889. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  890. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  891. PMIDL_STUB_MESSAGE pStubMsg = &pMesMsg->StubMsg;
  892. PMIDL_STUB_DESC pStubDesc = pProxyInfo->pStubDesc;
  893. pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
  894. pStubMsg->pfnFree = pStubDesc->pfnFree;
  895. unsigned long ulAlignment;
  896. size_t RequiredLen;
  897. // Size and allocate the buffer.
  898. // The req len includes: (the common header) and the data
  899. // Take the pointer alignment to come up with the right size.
  900. pStubMsg->BufferLength = 0xf & PtrToUlong( pStubMsg->Buffer );
  901. RequiredLen = NdrMesSimpleTypeAlignSizeAll( Handle, pProxyInfo );
  902. NdrpAllocPicklingBuffer( pMesMsg, RequiredLen );
  903. // See if we need to marshall the common type header
  904. uchar __RPC_FAR * pBufferSaved = pStubMsg->Buffer;
  905. if ( pMesMsg->Operation == MES_ENCODE )
  906. {
  907. NdrpCommonTypeHeaderMarshall( pMesMsg );
  908. ulAlignment = 0x7;
  909. }
  910. else if ( pMesMsg->Operation == MES_ENCODE_NDR64 )
  911. {
  912. Ndr64pCommonTypeHeaderMarshall( pMesMsg );
  913. ulAlignment = 0xf;
  914. }
  915. else
  916. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  917. ALIGN( pStubMsg->Buffer, ulAlignment );
  918. switch ( Size )
  919. {
  920. case 1:
  921. * PCHAR_CAST pStubMsg->Buffer = * PCHAR_CAST pData;
  922. break;
  923. case 2:
  924. * PSHORT_CAST pStubMsg->Buffer = * PSHORT_CAST pData;
  925. break;
  926. case 4:
  927. * PLONG_CAST pStubMsg->Buffer = * PLONG_CAST pData;
  928. break;
  929. case 8:
  930. * PHYPER_CAST pStubMsg->Buffer = * PHYPER_CAST pData;
  931. break;
  932. default:
  933. NDR_ASSERT( 0, " Size generation problem" );
  934. }
  935. pStubMsg->Buffer += ulAlignment+1;
  936. NdrpWritePicklingBuffer( pMesMsg, pBufferSaved, RequiredLen );
  937. }
  938. // =======================================================================
  939. //
  940. // Ready to use Decode routines for simple types
  941. //
  942. // =======================================================================
  943. void RPC_ENTRY
  944. NdrMesSimpleTypeDecodeAll(
  945. handle_t Handle,
  946. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  947. void __RPC_FAR * pData,
  948. short FormatChar )
  949. /*++
  950. Does not include the header for the data.
  951. However, the common header gets included for the first object.
  952. Note. Endianness and other conversions for decode.
  953. This has been deemed as not worthy doing in the Daytona time frame.
  954. However, to be able to add it in future without backward compatibility
  955. problems, we have the last argument to be the format character as
  956. opposed to the size.
  957. This makes it possible to call NdrSimpleTypeConvert, if needed.
  958. Note that the compiler uses the 32bit tokens for this since this routine
  959. is common to both formats.
  960. --*/
  961. {
  962. if ( ( (PMIDL_ES_MESSAGE)Handle )->Operation != MES_DECODE &&
  963. ( (PMIDL_ES_MESSAGE)Handle )->Operation != MES_DECODE_NDR64 )
  964. RpcRaiseException( RPC_X_INVALID_ES_ACTION );
  965. Ndr64pValidateMesHandle( (PMIDL_ES_MESSAGE_EX)Handle );
  966. PMIDL_ES_MESSAGE pMesMsg = (PMIDL_ES_MESSAGE) Handle;
  967. PMIDL_STUB_MESSAGE pStubMsg = &((PMIDL_ES_MESSAGE)Handle)->StubMsg;
  968. uchar * BufferSaved;
  969. unsigned long ulAlignment;
  970. // See if we need to unmarshall the common type header.
  971. Ndr64pCommonTypeHeaderUnmarshall( pMesMsg );
  972. // Now the data.
  973. if ( pMesMsg->Operation == MES_DECODE )
  974. {
  975. NdrpReadPicklingBuffer( (PMIDL_ES_MESSAGE) Handle, 8);
  976. ulAlignment = 0x7;
  977. }
  978. else
  979. {
  980. NdrpReadPicklingBuffer( (PMIDL_ES_MESSAGE) Handle, 16);
  981. ulAlignment = 0xf;
  982. }
  983. NDR_ASSERT( ( (ULONG_PTR)pStubMsg->Buffer & ulAlignment ) == 0, "invalid buffer alignment in simple type pickling" );
  984. ValidateMesSimpleTypeAll( pProxyInfo, ((PMIDL_ES_MESSAGE)Handle)->Operation );
  985. if ( pMesMsg->AlienDataRep != NDR_LOCAL_DATA_REPRESENTATION )
  986. {
  987. pStubMsg->RpcMsg->DataRepresentation = pMesMsg->AlienDataRep;
  988. BufferSaved = pStubMsg->Buffer;
  989. NdrSimpleTypeConvert( pStubMsg, (unsigned char)FormatChar );
  990. pStubMsg->Buffer = BufferSaved;
  991. }
  992. switch ( FormatChar )
  993. {
  994. case FC_BYTE:
  995. case FC_CHAR:
  996. case FC_SMALL:
  997. case FC_USMALL:
  998. * PCHAR_CAST pData = * PCHAR_CAST pStubMsg->Buffer;
  999. break;
  1000. case FC_WCHAR:
  1001. case FC_SHORT:
  1002. case FC_USHORT:
  1003. * PSHORT_CAST pData = * PSHORT_CAST pStubMsg->Buffer;
  1004. break;
  1005. case FC_LONG:
  1006. case FC_ULONG:
  1007. case FC_FLOAT:
  1008. case FC_ENUM32:
  1009. case FC_ERROR_STATUS_T:
  1010. * PLONG_CAST pData = * PLONG_CAST pStubMsg->Buffer;
  1011. break;
  1012. case FC_HYPER:
  1013. case FC_DOUBLE:
  1014. * PHYPER_CAST pData = * PHYPER_CAST pStubMsg->Buffer;
  1015. break;
  1016. #if defined(__RPC_WIN64__)
  1017. case FC_INT3264:
  1018. if (pMesMsg->Operation == MES_DECODE )
  1019. *((INT64 *)pData) = *((long *) pStubMsg->Buffer);
  1020. else
  1021. *((INT64 *)pData) = *((INT64 *) pStubMsg->Buffer);
  1022. break;
  1023. case FC_UINT3264:
  1024. if (pMesMsg->Operation == MES_DECODE )
  1025. *((UINT64 *)pData) = *((ulong *)pStubMsg->Buffer);
  1026. else
  1027. *((UINT64 *)pData) = *((UINT64 *)pStubMsg->Buffer);
  1028. break;
  1029. #endif
  1030. default:
  1031. NDR_ASSERT( 0, " Size generation problem for simple types" );
  1032. }
  1033. pStubMsg->Buffer += ulAlignment+1;
  1034. }