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.

447 lines
15 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name :
  4. srvcall.c
  5. Abstract :
  6. This file contains multiple transfer syntaxes negotiation related code
  7. Author :
  8. Yong Qu yongqu September 1999.
  9. Revision History :
  10. ---------------------------------------------------------------------*/
  11. #ifndef _MULSYNTX_H
  12. #define _MULSYNTX_H
  13. #include <stddef.h>
  14. typedef struct _NDR_PROC_CONTEXT NDR_PROC_CONTEXT;
  15. typedef struct _NDR_ALLOCA_CONTEXT NDR_ALLOCA_CONTEXT;
  16. #ifdef __cplusplus
  17. extern "C"
  18. {
  19. #endif
  20. typedef void ( RPC_ENTRY * PFNMARSHALLING )( MIDL_STUB_MESSAGE * pStubMsg,
  21. BOOL IsObject
  22. );
  23. typedef void ( RPC_ENTRY * PFNUNMARSHALLING )
  24. ( MIDL_STUB_MESSAGE * pStubMsg,
  25. void * pReturnValue
  26. );
  27. typedef void ( RPC_ENTRY * PFNINIT ) (MIDL_STUB_MESSAGE * pStubMsg,
  28. void * pReturnValue );
  29. typedef void ( RPC_ENTRY * PFNSIZING ) (MIDL_STUB_MESSAGE * pStubMsg,
  30. BOOL IsClient);
  31. typedef unsigned char * ( RPC_ENTRY * PFNCLIENTGETBUFFER ) (MIDL_STUB_MESSAGE * pStubMsg );
  32. typedef void (* PFNGENERICUNBIND ) (
  33. PMIDL_STUB_DESC pStubDesc,
  34. uchar * ArgPtr,
  35. PFORMAT_STRING pFormat,
  36. uint Flags,
  37. handle_t * pGenericHandle
  38. );
  39. typedef unsigned char ( RPC_ENTRY * PFNGETBUFFER ) (
  40. PMIDL_STUB_MESSAGE * pStubMsg,
  41. unsigned long BufferLength );
  42. typedef void ( RPC_ENTRY * PFNSENDRECEIVE ) (
  43. PMIDL_STUB_MESSAGE * pStubMsg );
  44. typedef void ( RPC_ENTRY *PFNCLIENT_EXCEPTION_HANDLING )
  45. ( MIDL_STUB_MESSAGE * pStubMsg,
  46. ulong ProcNum,
  47. RPC_STATUS ExceptionCode,
  48. CLIENT_CALL_RETURN * pReturnValue);
  49. typedef VOID ( RPC_ENTRY *PFNCLIENTFINALLY )
  50. ( MIDL_STUB_MESSAGE * pStubMsg,
  51. void * pThis );
  52. // important! the vtbl sequence should match the fields in NDR_PROC_CONTEXT alwyas.
  53. // we can't do anonymous structure in c++.
  54. typedef struct _SYNTAX_DISPATCH_TABLE
  55. {
  56. PFNINIT pfnInit;
  57. PFNSIZING pfnSizing;
  58. PFNMARSHALLING pfnMarshal;
  59. PFNUNMARSHALLING pfnUnmarshal;
  60. PFNCLIENT_EXCEPTION_HANDLING pfnExceptionHandling;
  61. PFNCLIENTFINALLY pfnFinally;
  62. // PFNGETBUFFER pfnGetBuffer;
  63. // PFNSENDRECEIVE pfnSendReceive;
  64. } SYNTAX_DISPATCH_TABLE;
  65. typedef struct _NDR_PROC_DESC
  66. {
  67. unsigned short ClientBufferSize; // The Oi2 header
  68. unsigned short ServerBufferSize; //
  69. INTERPRETER_OPT_FLAGS Oi2Flags; //
  70. unsigned char NumberParams; //
  71. NDR_PROC_HEADER_EXTS NdrExts;
  72. } NDR_PROC_DESC;
  73. typedef struct _NDR_PROC_INFO
  74. {
  75. INTERPRETER_FLAGS InterpreterFlags;
  76. NDR_PROC_DESC * pProcDesc;
  77. } NDR_PROC_INFO;
  78. #define NDR_ALLOCA_PREALLOCED_BLOCK_SIZE 512
  79. #define NDR_ALLOCA_MIN_BLOCK_SIZE 4096
  80. typedef struct _NDR_ALLOCA_CONTEXT {
  81. PBYTE pBlockPointer;
  82. LIST_ENTRY MemoryList;
  83. ULONG_PTR BytesRemaining;
  84. #if defined(NDR_PROFILE_ALLOCA)
  85. SIZE_T AllocaBytes;
  86. SIZE_T AllocaAllocations;
  87. SIZE_T MemoryBytes;
  88. SIZE_T MemoryAllocations;
  89. #endif
  90. BYTE PreAllocatedBlock[NDR_ALLOCA_PREALLOCED_BLOCK_SIZE];
  91. } NDR_ALLOCA_CONTEXT, *PNDR_ALLOCA_CONTEXT;
  92. // Simulated Alloca
  93. VOID
  94. NdrpAllocaInit(
  95. PNDR_ALLOCA_CONTEXT pAllocaContext
  96. );
  97. VOID
  98. NdrpAllocaDestroy(
  99. PNDR_ALLOCA_CONTEXT pAllocaContext
  100. );
  101. PVOID
  102. NdrpAlloca(
  103. PNDR_ALLOCA_CONTEXT pAllocaContext,
  104. UINT Size
  105. );
  106. class NDR_POINTER_QUEUE_ELEMENT;
  107. typedef struct _NDR_PROC_CONTEXT
  108. {
  109. SYNTAX_TYPE CurrentSyntaxType;
  110. union {
  111. NDR_PROC_INFO NdrInfo;
  112. NDR64_PROC_FORMAT * Ndr64Header;
  113. } ;
  114. PFORMAT_STRING pProcFormat; // proc format string.
  115. ulong NumberParams;
  116. void * Params;
  117. uchar * StartofStack;
  118. uchar HandleType;
  119. handle_t SavedGenericHandle;
  120. PFORMAT_STRING pHandleFormatSave;
  121. PFORMAT_STRING DceTypeFormatString;
  122. ulong IsAsync : 1;
  123. ulong IsObject : 1;
  124. ulong HasPipe : 1;
  125. ulong HasComplexReturn :1;
  126. ulong NeedsResend : 1;
  127. ulong UseLocator : 1;
  128. ulong Reserved7 :1 ;
  129. ulong Reserved8 : 1;
  130. ulong Reservedleft: 8;
  131. ulong FloatDoubleMask;
  132. ulong ResendCount;
  133. ulong RpcFlags;
  134. ulong ExceptionFlag;
  135. ulong StackSize;
  136. MIDL_SYNTAX_INFO * pSyntaxInfo;
  137. PFNINIT pfnInit;
  138. PFNSIZING pfnSizing;
  139. PFNMARSHALLING pfnMarshal;
  140. PFNUNMARSHALLING pfnUnMarshal;
  141. PFNCLIENT_EXCEPTION_HANDLING pfnExceptionHandling;
  142. PFNCLIENTFINALLY pfnClientFinally;
  143. NDR_PIPE_DESC * pPipeDesc;
  144. NDR_POINTER_QUEUE_ELEMENT * pQueueFreeList;
  145. NDR_ALLOCA_CONTEXT AllocateContext;
  146. } NDR_PROC_CONTEXT;
  147. extern uchar Ndr64HandleTypeMap[];
  148. const extern RPC_SYNTAX_IDENTIFIER NDR_TRANSFER_SYNTAX;
  149. const extern RPC_SYNTAX_IDENTIFIER NDR64_TRANSFER_SYNTAX;
  150. const extern RPC_SYNTAX_IDENTIFIER FAKE_NDR64_TRANSFER_SYNTAX;
  151. void
  152. NdrServerSetupNDR64TransferSyntax(
  153. ulong ProcNum,
  154. MIDL_SYNTAX_INFO * pServerInfo,
  155. NDR_PROC_CONTEXT * pContext );
  156. RPC_STATUS RPC_ENTRY
  157. Ndr64ClientNegotiateTransferSyntax(
  158. void * pThis,
  159. MIDL_STUB_MESSAGE *pStubMsg,
  160. MIDL_STUBLESS_PROXY_INFO *pProxyInfo,
  161. NDR_PROC_CONTEXT *pContext );
  162. CLIENT_CALL_RETURN RPC_ENTRY
  163. NdrpClientCall3(
  164. void * pThis,
  165. MIDL_STUBLESS_PROXY_INFO *pProxyInfo,
  166. unsigned long nProcNum,
  167. void *pReturnValue,
  168. NDR_PROC_CONTEXT * pContext,
  169. unsigned char * StartofStack
  170. );
  171. void RPC_ENTRY
  172. NdrpClientUnMarshal ( MIDL_STUB_MESSAGE * pStubMsg,
  173. void * pReturnValue );
  174. void RPC_ENTRY
  175. NdrpServerUnMarshal ( MIDL_STUB_MESSAGE * pStubMsg );
  176. void RPC_ENTRY
  177. NdrpClientMarshal( MIDL_STUB_MESSAGE * pStubMsg,
  178. BOOL IsObject );
  179. void RPC_ENTRY
  180. NdrpServerMarshal( MIDL_STUB_MESSAGE * pStubMsg,
  181. BOOL IsObject );
  182. void RPC_ENTRY
  183. NdrpClientInit( MIDL_STUB_MESSAGE * pStubMsg,
  184. void * pReturnValue );
  185. void RPC_ENTRY
  186. Ndr64pClientUnMarshal ( MIDL_STUB_MESSAGE * pStubMsg,
  187. void * pReturnValue );
  188. void RPC_ENTRY
  189. Ndr64pServerUnMarshal ( MIDL_STUB_MESSAGE * pStubMsg );
  190. void RPC_ENTRY
  191. Ndr64pClientMarshal( MIDL_STUB_MESSAGE * pStubMsg,
  192. BOOL IsObject );
  193. void RPC_ENTRY
  194. Ndr64pServerMarshal( MIDL_STUB_MESSAGE * pStubMsg );
  195. void
  196. Ndr64pServerOutInit( PMIDL_STUB_MESSAGE pStubMsg );
  197. void RPC_ENTRY
  198. Ndr64pClientInit( MIDL_STUB_MESSAGE * pStubMsg,
  199. void * ReturnValue );
  200. void RPC_ENTRY
  201. NdrpClientExceptionHandling( MIDL_STUB_MESSAGE * pStubMsg,
  202. ulong ProcNum,
  203. RPC_STATUS ExceptionCode,
  204. CLIENT_CALL_RETURN * pReturnValue );
  205. void RPC_ENTRY
  206. NdrpAsyncClientExceptionHandling( MIDL_STUB_MESSAGE * pStubMsg,
  207. ulong ProcNum,
  208. RPC_STATUS ExceptionCode,
  209. CLIENT_CALL_RETURN * pReturnValue );
  210. void RPC_ENTRY
  211. NdrpDcomClientExceptionHandling( MIDL_STUB_MESSAGE * pStubMsg,
  212. ulong ProcNum,
  213. RPC_STATUS ExceptionCode,
  214. CLIENT_CALL_RETURN * pReturnValue );
  215. void RPC_ENTRY
  216. NdrpNoopSizing( MIDL_STUB_MESSAGE * pStubMsg,
  217. BOOL IsClient );
  218. void RPC_ENTRY
  219. NdrpSizing( MIDL_STUB_MESSAGE * pStubMsg,
  220. BOOL IsClient );
  221. void RPC_ENTRY
  222. Ndr64pSizing( MIDL_STUB_MESSAGE * pStubMsg,
  223. BOOL IsClient );
  224. void RPC_ENTRY
  225. Ndr64pClientExceptionHandling( MIDL_STUB_MESSAGE * pStubMsg,
  226. ulong ProcNum,
  227. RPC_STATUS ExceptionCode,
  228. CLIENT_CALL_RETURN * pReturnValue );
  229. void RPC_ENTRY
  230. Ndr64pDcomClientExceptionHandling( MIDL_STUB_MESSAGE * pStubMsg,
  231. ulong ProcNum,
  232. RPC_STATUS ExceptionCode,
  233. CLIENT_CALL_RETURN * pReturnValue );
  234. void RPC_ENTRY NdrpClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  235. void * pThis );
  236. void RPC_ENTRY Ndr64pClientFinally( PMIDL_STUB_MESSAGE pStubMsg,
  237. void * pThis );
  238. typedef handle_t (* PFNEXPLICITBINDHANDLEMGR)(PMIDL_STUB_DESC pStubDesc,
  239. uchar * ArgPtr,
  240. PFORMAT_STRING pFormat,
  241. handle_t * pSavedGenericHandle);
  242. typedef handle_t (* PFNIMPLICITBINDHANDLEMGR)(PMIDL_STUB_DESC pStubDesc,
  243. uchar HandleType,
  244. handle_t * pSavedGenericHandle);
  245. void RPC_ENTRY
  246. Ndr64ClientInitializeContext(
  247. SYNTAX_TYPE SyntaxType,
  248. const MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  249. ulong nProcNum,
  250. NDR_PROC_CONTEXT * pContext,
  251. uchar * StartofStack );
  252. RPC_STATUS RPC_ENTRY
  253. Ndr64pClientSetupTransferSyntax( void * pThis,
  254. RPC_MESSAGE * pRpcMsg,
  255. MIDL_STUB_MESSAGE * pStubMsg,
  256. MIDL_STUBLESS_PROXY_INFO * ProxyInfo,
  257. NDR_PROC_CONTEXT * pContext,
  258. ulong nProcNum );
  259. HRESULT
  260. MulNdrpBeginDcomAsyncClientCall(
  261. MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  262. ulong nProcNum,
  263. NDR_PROC_CONTEXT * pContext,
  264. void * StartofStack );
  265. HRESULT
  266. MulNdrpFinishDcomAsyncClientCall(
  267. MIDL_STUBLESS_PROXY_INFO * pProxyInfo,
  268. ulong nProcNum,
  269. NDR_PROC_CONTEXT * pContext,
  270. void * StartofStack );
  271. void Ndr64SetupClientSyntaxVtbl( PRPC_SYNTAX_IDENTIFIER pSyntax,
  272. NDR_PROC_CONTEXT * pContext );
  273. ulong RPC_ENTRY
  274. MulNdrpInitializeContextFromProc (
  275. SYNTAX_TYPE SyntaxType,
  276. PFORMAT_STRING pFormat,
  277. NDR_PROC_CONTEXT * pContext,
  278. uchar * StartofStack,
  279. BOOLEAN IsReset = FALSE );
  280. RPC_STATUS RPC_ENTRY
  281. Ndr64SetupServerContext ( NDR_PROC_CONTEXT * pContext,
  282. PFORMAT_STRING pFormat );
  283. /* rpcndr64.h */
  284. BOOL NdrValidateServerInfo( MIDL_SERVER_INFO *pServerInfo );
  285. void
  286. NdrpServerInit( PMIDL_STUB_MESSAGE pStubMsg,
  287. RPC_MESSAGE * pRpcMsg,
  288. PMIDL_STUB_DESC pStubDesc,
  289. void * pThis,
  290. IRpcChannelBuffer * pChannel,
  291. PNDR_ASYNC_MESSAGE pAsynMsg);
  292. void NdrpServerOutInit( PMIDL_STUB_MESSAGE pStubMsg );
  293. void RPC_ENTRY
  294. Ndr64ProxyInitialize(
  295. IN void * pThis,
  296. IN PRPC_MESSAGE pRpcMsg,
  297. IN PMIDL_STUB_MESSAGE pStubMsg,
  298. IN PMIDL_STUBLESS_PROXY_INFO pProxyInfo,
  299. IN unsigned int ProcNum );
  300. __forceinline
  301. PFORMAT_STRING
  302. NdrpGetProcString( PMIDL_SYNTAX_INFO pSyntaxInfo,
  303. SYNTAX_TYPE SyntaxType,
  304. ulong nProcNum )
  305. {
  306. if ( SyntaxType == XFER_SYNTAX_DCE )
  307. {
  308. unsigned long nFormatOffset;
  309. nFormatOffset = (pSyntaxInfo->FmtStringOffset)[nProcNum];
  310. return (PFORMAT_STRING) &pSyntaxInfo->ProcString[nFormatOffset];
  311. }
  312. else
  313. {
  314. return ((PFORMAT_STRING*)(pSyntaxInfo->FmtStringOffset))[nProcNum];
  315. }
  316. }
  317. __forceinline
  318. SYNTAX_TYPE NdrpGetSyntaxType( PRPC_SYNTAX_IDENTIFIER pSyntaxId )
  319. {
  320. SYNTAX_TYPE SyntaxType = (SYNTAX_TYPE)( * (ulong *)pSyntaxId );
  321. #if !defined( __RPC_WIN64__ )
  322. if ( SyntaxType == XFER_SYNTAX_TEST_NDR64 )
  323. SyntaxType = XFER_SYNTAX_NDR64;
  324. #endif
  325. // NDR_ASSERT( SyntaxType == XFER_SYNTAX_NDR64 || SyntaxType == XFER_SYNTAX_DCE,
  326. // "invliad transfer syntax" );
  327. return SyntaxType ;
  328. }
  329. __forceinline void
  330. NdrpInitializeProcContext( NDR_PROC_CONTEXT * pContext )
  331. {
  332. memset( pContext, 0, offsetof( NDR_PROC_CONTEXT, AllocateContext ) );
  333. NdrpAllocaInit( & pContext->AllocateContext );
  334. }
  335. #define NDR64GETHANDLETYPE(x) ( ((NDR64_PROC_FLAGS *)x)->HandleType )
  336. #define NDR64MAPHANDLETYPE(x) ( Ndr64HandleTypeMap[ x ] )
  337. #define SAMEDIRECTION(flag , Param ) ( flag ? Param.ParamAttr.IsIn : Param.ParamAttr.IsOut )
  338. #define NDR64SAMEDIRECTION( flag, pParamFlags ) ( flag ? pParamFlags->IsIn : pParamFlags->IsOut )
  339. __forceinline
  340. void NdrpGetPreferredSyntax( ulong nCount,
  341. MIDL_SYNTAX_INFO * pSyntaxInfo,
  342. ulong * pPrefer )
  343. {
  344. pSyntaxInfo;
  345. // ndr64 is always the last one.
  346. #if !defined(__RPC_WIN64__)
  347. *pPrefer = nCount - 1;
  348. // *pPrefer = 0; // should be 0 in 32bit.
  349. #else
  350. *pPrefer = nCount -1;
  351. #endif
  352. }
  353. #ifdef __cplusplus
  354. }
  355. #endif
  356. #endif // _MULSYNTX_H