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.

359 lines
11 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright <c> 1993-2000 Microsoft Corporation
  3. Module Name :
  4. ndrp.h
  5. Abtract :
  6. Contains private definitions for Ndr files in this directory. This
  7. file is included by all source files in this directory.
  8. Author :
  9. David Kays dkays October 1993
  10. Revision History :
  11. --------------------------------------------------------------------*/
  12. #ifndef _NDRP_
  13. #define _NDRP_
  14. #include <sysinc.h>
  15. #include "rpc.h"
  16. #include "rpcndr.h"
  17. // Get new token definitions for 64b.
  18. #define RPC_NDR_64
  19. #include "ndrtypes.h"
  20. #include "ndr64types.h"
  21. #include "ndrpall.h"
  22. #ifdef NDR_IMPORT_NDRP
  23. #define IMPORTSPEC EXTERN_C DECLSPEC_IMPORT
  24. #else
  25. #define IMPORTSPEC EXTERN_C
  26. #endif
  27. #include "ndr64types.h"
  28. #include "mrshlp.h"
  29. #include "unmrshlp.h"
  30. #include "bufsizep.h"
  31. #include "memsizep.h"
  32. #include "freep.h"
  33. #include "endianp.h"
  34. #include "fullptr.h"
  35. #include "pipendr.h"
  36. #include "mulsyntx.h"
  37. #include "util.hxx"
  38. long
  39. NdrpArrayDimensions(
  40. PMIDL_STUB_MESSAGE pStubMsg,
  41. PFORMAT_STRING pFormat,
  42. BOOL fIgnoreStringArrays
  43. );
  44. long
  45. NdrpArrayElements(
  46. PMIDL_STUB_MESSAGE pStubMsg,
  47. uchar * pMemory,
  48. PFORMAT_STRING pFormat
  49. );
  50. void
  51. NdrpArrayVariance(
  52. PMIDL_STUB_MESSAGE pStubMsg,
  53. uchar * pMemory,
  54. PFORMAT_STRING pFormat,
  55. long * pOffset,
  56. long * pLength
  57. );
  58. PFORMAT_STRING
  59. NdrpSkipPointerLayout(
  60. PFORMAT_STRING pFormat
  61. );
  62. long
  63. NdrpStringStructLen(
  64. uchar * pMemory,
  65. long ElementSize
  66. );
  67. void
  68. NdrpCheckBound(
  69. ulong Bound,
  70. int Type
  71. );
  72. RPCRTAPI
  73. void
  74. RPC_ENTRY
  75. NdrpRangeBufferSize(
  76. PMIDL_STUB_MESSAGE pStubMsg,
  77. unsigned char * pMemory,
  78. PFORMAT_STRING pFormat
  79. );
  80. void
  81. NdrpRangeConvert(
  82. PMIDL_STUB_MESSAGE pStubMsg,
  83. PFORMAT_STRING pFormat,
  84. uchar fEmbeddedPointerPass
  85. );
  86. void RPC_ENTRY
  87. NdrpRangeFree(
  88. PMIDL_STUB_MESSAGE pStubMsg,
  89. uchar * pMemory,
  90. PFORMAT_STRING pFormat
  91. );
  92. unsigned long RPC_ENTRY
  93. NdrpRangeMemorySize(
  94. PMIDL_STUB_MESSAGE pStubMsg,
  95. PFORMAT_STRING pFormat );
  96. unsigned char * RPC_ENTRY
  97. NdrpRangeMarshall(
  98. PMIDL_STUB_MESSAGE pStubMsg,
  99. uchar * pMemory,
  100. PFORMAT_STRING pFormat );
  101. unsigned long
  102. FixWireRepForDComVerGTE54(
  103. PMIDL_STUB_MESSAGE pStubMsg );
  104. RPC_STATUS
  105. NdrpPerformRpcInitialization (
  106. void
  107. );
  108. PVOID
  109. NdrpPrivateAllocate(
  110. PNDR_ALLOCA_CONTEXT pAllocaContext,
  111. UINT Size
  112. );
  113. void
  114. NdrpPrivateFree(
  115. PNDR_ALLOCA_CONTEXT pAllocaContext,
  116. void *pMemory
  117. );
  118. void
  119. NdrpInitUserMarshalCB(
  120. MIDL_STUB_MESSAGE *pStubMsg,
  121. PFORMAT_STRING pFormat,
  122. USER_MARSHAL_CB_TYPE CBType,
  123. USER_MARSHAL_CB *pUserMarshalCB
  124. );
  125. void
  126. NdrpCleanupServerContextHandles(
  127. MIDL_STUB_MESSAGE * pStubMsg,
  128. uchar * pStartOfStack,
  129. BOOL fManagerRoutineException
  130. );
  131. RPC_STATUS
  132. CheckForRobust (
  133. RPC_SERVER_INTERFACE * pRpcServerIf );
  134. DWORD
  135. NdrpCheckMIDLRobust( IN const MIDL_SERVER_INFO * pMServerInfo, ulong ProcCount , BOOL IsObjectIntf );
  136. EXTERN_C
  137. void
  138. NdrpInitArrayInfo( PMIDL_STUB_MESSAGE pStubMsg, ARRAY_INFO * pArrayInfo );
  139. // Checking bounds etc.
  140. // The bound value check below is independent of anything.
  141. #define CHECK_BOUND( Bound, Type ) NdrpCheckBound( Bound, (int)(Type) )
  142. // check for overflow when calculating the total size.
  143. ULONG MultiplyWithOverflowCheck( ULONG_PTR Count, ULONG_PTR ElemSize );
  144. // These end of buffer checks can be performed on a receiving side only.
  145. // The necessary setup is there for memorysize, unmarshal and convert walks.
  146. // This also includes pickling walk.
  147. // Don't use this on the sending side.
  148. // Checks if the pointer is past the end of the buffer. Do not check for wraparound.
  149. #define CHECK_EOB_RAISE_BSD( p ) \
  150. { \
  151. if( (uchar *)(p) > pStubMsg->BufferEnd ) \
  152. { \
  153. RpcRaiseException( RPC_X_BAD_STUB_DATA ); \
  154. } \
  155. }
  156. #define CHECK_EOB_RAISE_IB( p ) \
  157. { \
  158. if( (uchar *)(p) > pStubMsg->BufferEnd ) \
  159. { \
  160. RpcRaiseException( RPC_X_INVALID_BOUND ); \
  161. } \
  162. }
  163. // Checks if p + incsize is past the end of the bufffer.
  164. // Correctly handle wraparound.
  165. #define CHECK_EOB_WITH_WRAP_RAISE_BSD( p, incsize ) \
  166. { \
  167. unsigned char *NewBuffer = ((uchar *)(p)) + (SIZE_T)(incsize);\
  168. if( (NewBuffer > pStubMsg->BufferEnd) || (NewBuffer < (p)) ) \
  169. { \
  170. RpcRaiseException( RPC_X_BAD_STUB_DATA ); \
  171. } \
  172. }
  173. #define CHECK_EOB_WITH_WRAP_RAISE_IB( p, incsize ) \
  174. { \
  175. unsigned char *NewBuffer = ((uchar *)(p)) + (SIZE_T)(incsize);\
  176. if( (NewBuffer > pStubMsg->BufferEnd) || (NewBuffer < (p)) ) \
  177. { \
  178. RpcRaiseException( RPC_X_INVALID_BOUND ); \
  179. } \
  180. }
  181. #define CHECK_ULONG_BOUND( v ) if ( 0x80000000 & (unsigned long)(v) ) \
  182. RpcRaiseException( RPC_X_INVALID_BOUND );
  183. #define REUSE_BUFFER(pStubMsg) (! pStubMsg->IsClient)
  184. // This would be appropriate on the sending side for marshaling.
  185. #define CHECK_SEND_EOB_RAISE_BSD( p ) \
  186. if ( pStubMsg->RpcMsg->Buffer + pStubMsg->RpcMsg->BufferLength < p ) \
  187. RpcRaiseException( RPC_X_BAD_STUB_DATA )
  188. #define NdrpComputeSwitchIs( pStubMsg, pMemory, pFormat ) \
  189. NdrpComputeConformance( pStubMsg, \
  190. pMemory, \
  191. pFormat )
  192. #define NdrpComputeIIDPointer( pStubMsg, pMemory, pFormat ) \
  193. NdrpComputeConformance( pStubMsg, \
  194. pMemory, \
  195. pFormat )
  196. //
  197. // Defined in global.c
  198. //
  199. IMPORTSPEC extern const unsigned char SimpleTypeAlignment[];
  200. IMPORTSPEC extern const unsigned char SimpleTypeBufferSize[];
  201. IMPORTSPEC extern const unsigned char SimpleTypeMemorySize[];
  202. IMPORTSPEC extern const unsigned long NdrTypeFlags[];
  203. #define UNIQUE_POINTER_SHIFT 2
  204. // Add a incremental count for unique pointers to work around HP interop issue
  205. #define PTR_WIRE_REP(p, pStubMsg) (ulong)(p ? UNIQUE_POINTER_MARK + ( (pStubMsg->UniquePtrCount++) << UNIQUE_POINTER_SHIFT ): 0)
  206. //#define PTR_WIRE_REP(p, pStubMsg) (ulong)(p ? UNIQUE_POINTER_MARK + (pStubMsg->UniquePtrCount++): 0)
  207. #if defined(__RPC_WIN64__)
  208. #define UNMARSHAL_PTR_WIRE_REP(p) (ulong)(p ? PtrToUlong( p ) : 0)
  209. #else
  210. #define UNMARSHAL_PTR_WIRE_REP(p) (ulong)p
  211. #endif
  212. //
  213. // Proc info flags macros.
  214. //
  215. #define IS_OLE_INTERFACE(Flags) ((Flags) & Oi_OBJECT_PROC)
  216. #define HAS_RPCFLAGS(Flags) ((Flags) & Oi_HAS_RPCFLAGS)
  217. #define DONT_HANDLE_EXCEPTION(Flags) \
  218. ((Flags) & Oi_IGNORE_OBJECT_EXCEPTION_HANDLING)
  219. //
  220. // Routine index macro.
  221. //
  222. #define ROUTINE_INDEX(FC) ((FC) & 0x3F)
  223. #include <ndrmisc.h>
  224. //
  225. // Union hack helper. (used to be MAGIC_UNION_BYTE 0x80)
  226. //
  227. #define IS_MAGIC_UNION_BYTE(pFmt) \
  228. ((*(unsigned short *)pFmt & (unsigned short)0xff00) == MAGIC_UNION_SHORT)
  229. // User marshal marker on wire.
  230. #define USER_MARSHAL_MARKER 0x72657355
  231. #define BOGUS_EMBED_CONF_STRUCT_FLAG ( ( unsigned char ) 0x01 )
  232. // compute buffer size for the pointees of a complex struct or complex array
  233. // specifically excluding the flat parts.
  234. #define POINTEE_BUFFER_LENGTH_ONLY_FLAG ( ( unsigned char ) 0x02 )
  235. #define TOPMOST_CONF_STRUCT_FLAG ( ( unsigned char ) 0x04 )
  236. #define REVERSE_ARRAY_MARSHALING_FLAG ( ( unsigned char ) 0x08 )
  237. #define WALKIP_FLAG ( ( unsigned char ) 0x10 )
  238. #define BROKEN_INTERFACE_POINTER_FLAG ( ( unsigned char ) 0x20 )
  239. #define SKIP_REF_CHECK_FLAG ( ( unsigned char ) 0x40 )
  240. #define IS_EMBED_CONF_STRUCT( f ) ( ( f ) & BOGUS_EMBED_CONF_STRUCT_FLAG )
  241. #define SET_EMBED_CONF_STRUCT( f ) ( f ) |= BOGUS_EMBED_CONF_STRUCT_FLAG
  242. #define RESET_EMBED_CONF_STRUCT( f ) ( f ) &= ~BOGUS_EMBED_CONF_STRUCT_FLAG
  243. #define COMPUTE_POINTEE_BUFFER_LENGTH_ONLY( Flags ) ( ( Flags ) & POINTEE_BUFFER_LENGTH_ONLY_FLAG )
  244. #define SET_COMPUTE_POINTEE_BUFFER_LENGTH_ONLY( Flags ) ( ( Flags ) |= POINTEE_BUFFER_LENGTH_ONLY_FLAG )
  245. #define RESET_COMPUTE_POINTEE_BUFFER_LENGTH_ONLY( Flags ) ( ( Flags ) &= ~POINTEE_BUFFER_LENGTH_ONLY_FLAG )
  246. #define IS_TOPMOST_CONF_STRUCT( f ) ( ( f ) & TOPMOST_CONF_STRUCT_FLAG )
  247. #define SET_TOPMOST_CONF_STRUCT( f ) ( ( f ) |= TOPMOST_CONF_STRUCT_FLAG )
  248. #define RESET_TOPMOST_CONF_STRUCT( f ) ( ( f ) &= ~TOPMOST_CONF_STRUCT_FLAG )
  249. #define IS_CONF_ARRAY_DONE( f ) ( ( f ) & REVERSE_ARRAY_MARSHALING_FLAG )
  250. #define SET_CONF_ARRAY_DONE( f ) ( ( f ) |= REVERSE_ARRAY_MARSHALING_FLAG )
  251. #define RESET_CONF_ARRAY_DONE( f ) ( ( f ) &= ~REVERSE_ARRAY_MARSHALING_FLAG )
  252. #define IS_WALKIP( f ) ( ( f ) & WALKIP_FLAG )
  253. #define SET_WALKIP( f ) ( ( f ) |= WALKIP_FLAG )
  254. #define RESET_WALKIP( f ) ( ( f ) &= ~WALKIP_FLAG )
  255. #define IS_SKIP_REF_CHECK( f ) ( ( f ) & SKIP_REF_CHECK_FLAG )
  256. #define SET_SKIP_REF_CHECK( f ) ( ( f ) |= SKIP_REF_CHECK_FLAG )
  257. #define RESET_SKIP_REF_CHECK( f ) ( ( f ) &= ~SKIP_REF_CHECK_FLAG )
  258. #define IS_BROKEN_INTERFACE_POINTER( f ) ( ( f ) & BROKEN_INTERFACE_POINTER_FLAG )
  259. #define SET_BROKEN_INTERFACE_POINTER( f ) ( ( f ) |= BROKEN_INTERFACE_POINTER_FLAG )
  260. #define RESET_BROKEN_INTERFACE_POINTER( f ) ( ( f ) &= ~BROKEN_INTERFACE_POINTER_FLAG )
  261. #define RESET_CONF_FLAGS_TO_STANDALONE( f ) (f) &= ~( BOGUS_EMBED_CONF_STRUCT_FLAG | \
  262. TOPMOST_CONF_STRUCT_FLAG | \
  263. REVERSE_ARRAY_MARSHALING_FLAG )
  264. //
  265. // Environment dependent macros
  266. //
  267. #define SIMPLE_TYPE_BUF_INCREMENT(Len, FC) Len += 16
  268. #define EXCEPTION_FLAG \
  269. ( (!(RpcFlags & RPCFLG_ASYNCHRONOUS)) && \
  270. (!InterpreterFlags.IgnoreObjectException) && \
  271. (StubMsg.dwStubPhase != PROXY_SENDRECEIVE) )
  272. #endif // _NDRP_