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.

345 lines
10 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. long
  38. NdrpArrayDimensions(
  39. PMIDL_STUB_MESSAGE pStubMsg,
  40. PFORMAT_STRING pFormat,
  41. BOOL fIgnoreStringArrays
  42. );
  43. long
  44. NdrpArrayElements(
  45. PMIDL_STUB_MESSAGE pStubMsg,
  46. uchar * pMemory,
  47. PFORMAT_STRING pFormat
  48. );
  49. void
  50. NdrpArrayVariance(
  51. PMIDL_STUB_MESSAGE pStubMsg,
  52. uchar * pMemory,
  53. PFORMAT_STRING pFormat,
  54. long * pOffset,
  55. long * pLength
  56. );
  57. PFORMAT_STRING
  58. NdrpSkipPointerLayout(
  59. PFORMAT_STRING pFormat
  60. );
  61. long
  62. NdrpStringStructLen(
  63. uchar * pMemory,
  64. long ElementSize
  65. );
  66. void
  67. NdrpCheckBound(
  68. ulong Bound,
  69. int Type
  70. );
  71. RPCRTAPI
  72. void
  73. RPC_ENTRY
  74. NdrpRangeBufferSize(
  75. PMIDL_STUB_MESSAGE pStubMsg,
  76. unsigned char * pMemory,
  77. PFORMAT_STRING pFormat
  78. );
  79. void
  80. NdrpRangeConvert(
  81. PMIDL_STUB_MESSAGE pStubMsg,
  82. PFORMAT_STRING pFormat,
  83. uchar fEmbeddedPointerPass
  84. );
  85. void RPC_ENTRY
  86. NdrpRangeFree(
  87. PMIDL_STUB_MESSAGE pStubMsg,
  88. uchar * pMemory,
  89. PFORMAT_STRING pFormat
  90. );
  91. unsigned long RPC_ENTRY
  92. NdrpRangeMemorySize(
  93. PMIDL_STUB_MESSAGE pStubMsg,
  94. PFORMAT_STRING pFormat );
  95. unsigned char * RPC_ENTRY
  96. NdrpRangeMarshall(
  97. PMIDL_STUB_MESSAGE pStubMsg,
  98. uchar * pMemory,
  99. PFORMAT_STRING pFormat );
  100. unsigned long
  101. FixWireRepForDComVerGTE54(
  102. PMIDL_STUB_MESSAGE pStubMsg );
  103. RPC_STATUS
  104. NdrpPerformRpcInitialization (
  105. void
  106. );
  107. PVOID
  108. NdrpPrivateAllocate(
  109. PNDR_ALLOCA_CONTEXT pAllocaContext,
  110. UINT Size
  111. );
  112. void
  113. NdrpPrivateFree(
  114. PNDR_ALLOCA_CONTEXT pAllocaContext,
  115. void *pMemory
  116. );
  117. void
  118. NdrpInitUserMarshalCB(
  119. MIDL_STUB_MESSAGE *pStubMsg,
  120. PFORMAT_STRING pFormat,
  121. USER_MARSHAL_CB_TYPE CBType,
  122. USER_MARSHAL_CB *pUserMarshalCB
  123. );
  124. void
  125. NdrpCleanupServerContextHandles(
  126. MIDL_STUB_MESSAGE * pStubMsg,
  127. uchar * pStartOfStack,
  128. BOOL fManagerRoutineException
  129. );
  130. // Checking bounds etc.
  131. // The bound value check below is independent of anything.
  132. #define CHECK_BOUND( Bound, Type ) NdrpCheckBound( Bound, (int)(Type) )
  133. // check for overflow when calculating the total size.
  134. ULONG MultiplyWithOverflowCheck( ULONG_PTR Count, ULONG_PTR ElemSize );
  135. // These end of buffer checks can be performed on a receiving side only.
  136. // The necessary setup is there for memorysize, unmarshal and convert walks.
  137. // This also includes pickling walk.
  138. // Don't use this on the sending side.
  139. // Checks if the pointer is past the end of the buffer. Do not check for wraparound.
  140. #define CHECK_EOB_RAISE_BSD( p ) \
  141. { \
  142. if( (uchar *)(p) > pStubMsg->BufferEnd ) \
  143. { \
  144. RpcRaiseException( RPC_X_BAD_STUB_DATA ); \
  145. } \
  146. }
  147. #define CHECK_EOB_RAISE_IB( p ) \
  148. { \
  149. if( (uchar *)(p) > pStubMsg->BufferEnd ) \
  150. { \
  151. RpcRaiseException( RPC_X_INVALID_BOUND ); \
  152. } \
  153. }
  154. // Checks if p + incsize is past the end of the bufffer.
  155. // Correctly handle wraparound.
  156. #define CHECK_EOB_WITH_WRAP_RAISE_BSD( p, incsize ) \
  157. { \
  158. unsigned char *NewBuffer = ((uchar *)(p)) + (SIZE_T)(incsize);\
  159. if( (NewBuffer > pStubMsg->BufferEnd) || (NewBuffer < (p)) ) \
  160. { \
  161. RpcRaiseException( RPC_X_BAD_STUB_DATA ); \
  162. } \
  163. }
  164. #define CHECK_EOB_WITH_WRAP_RAISE_IB( p, incsize ) \
  165. { \
  166. unsigned char *NewBuffer = ((uchar *)(p)) + (SIZE_T)(incsize);\
  167. if( (NewBuffer > pStubMsg->BufferEnd) || (NewBuffer < (p)) ) \
  168. { \
  169. RpcRaiseException( RPC_X_INVALID_BOUND ); \
  170. } \
  171. }
  172. #define CHECK_ULONG_BOUND( v ) if ( 0x80000000 & (unsigned long)(v) ) \
  173. RpcRaiseException( RPC_X_INVALID_BOUND );
  174. #define REUSE_BUFFER(pStubMsg) (! pStubMsg->IsClient)
  175. // This would be appropriate on the sending side for marshaling.
  176. #define CHECK_SEND_EOB_RAISE_BSD( p ) \
  177. if ( pStubMsg->RpcMsg->Buffer + pStubMsg->RpcMsg->BufferLength < p ) \
  178. RpcRaiseException( RPC_X_BAD_STUB_DATA )
  179. #define NdrpComputeSwitchIs( pStubMsg, pMemory, pFormat ) \
  180. NdrpComputeConformance( pStubMsg, \
  181. pMemory, \
  182. pFormat )
  183. #define NdrpComputeIIDPointer( pStubMsg, pMemory, pFormat ) \
  184. NdrpComputeConformance( pStubMsg, \
  185. pMemory, \
  186. pFormat )
  187. //
  188. // Defined in global.c
  189. //
  190. IMPORTSPEC extern const unsigned char SimpleTypeAlignment[];
  191. IMPORTSPEC extern const unsigned char SimpleTypeBufferSize[];
  192. IMPORTSPEC extern const unsigned char SimpleTypeMemorySize[];
  193. IMPORTSPEC extern const unsigned long NdrTypeFlags[];
  194. #if defined(__RPC_WIN64__)
  195. #define PTR_WIRE_REP(p) (ulong)(p ? ( PtrToUlong( p ) | 0x80000000) : 0)
  196. #else
  197. #define PTR_WIRE_REP(p) (ulong)p
  198. #endif
  199. //
  200. // Proc info flags macros.
  201. //
  202. #define IS_OLE_INTERFACE(Flags) ((Flags) & Oi_OBJECT_PROC)
  203. #define HAS_RPCFLAGS(Flags) ((Flags) & Oi_HAS_RPCFLAGS)
  204. #define DONT_HANDLE_EXCEPTION(Flags) \
  205. ((Flags) & Oi_IGNORE_OBJECT_EXCEPTION_HANDLING)
  206. //
  207. // Routine index macro.
  208. //
  209. #define ROUTINE_INDEX(FC) ((FC) & 0x3F)
  210. #include <ndrmisc.h>
  211. //
  212. // Union hack helper. (used to be MAGIC_UNION_BYTE 0x80)
  213. //
  214. #define IS_MAGIC_UNION_BYTE(pFmt) \
  215. ((*(unsigned short *)pFmt & (unsigned short)0xff00) == MAGIC_UNION_SHORT)
  216. // User marshal marker on wire.
  217. #define USER_MARSHAL_MARKER 0x72657355
  218. #define BOGUS_EMBED_CONF_STRUCT_FLAG ( ( unsigned char ) 0x01 )
  219. // compute buffer size for the pointees of a complex struct or complex array
  220. // specifically excluding the flat parts.
  221. #define POINTEE_BUFFER_LENGTH_ONLY_FLAG ( ( unsigned char ) 0x02 )
  222. #define TOPMOST_CONF_STRUCT_FLAG ( ( unsigned char ) 0x04 )
  223. #define REVERSE_ARRAY_MARSHALING_FLAG ( ( unsigned char ) 0x08 )
  224. #define WALKIP_FLAG ( ( unsigned char ) 0x10 )
  225. #define BROKEN_INTERFACE_POINTER_FLAG ( ( unsigned char ) 0x20 )
  226. #define SKIP_REF_CHECK_FLAG ( ( unsigned char ) 0x40 )
  227. #define IS_EMBED_CONF_STRUCT( f ) ( ( f ) & BOGUS_EMBED_CONF_STRUCT_FLAG )
  228. #define SET_EMBED_CONF_STRUCT( f ) ( f ) |= BOGUS_EMBED_CONF_STRUCT_FLAG
  229. #define RESET_EMBED_CONF_STRUCT( f ) ( f ) &= ~BOGUS_EMBED_CONF_STRUCT_FLAG
  230. #define COMPUTE_POINTEE_BUFFER_LENGTH_ONLY( Flags ) ( ( Flags ) & POINTEE_BUFFER_LENGTH_ONLY_FLAG )
  231. #define SET_COMPUTE_POINTEE_BUFFER_LENGTH_ONLY( Flags ) ( ( Flags ) |= POINTEE_BUFFER_LENGTH_ONLY_FLAG )
  232. #define RESET_COMPUTE_POINTEE_BUFFER_LENGTH_ONLY( Flags ) ( ( Flags ) &= ~POINTEE_BUFFER_LENGTH_ONLY_FLAG )
  233. #define IS_TOPMOST_CONF_STRUCT( f ) ( ( f ) & TOPMOST_CONF_STRUCT_FLAG )
  234. #define SET_TOPMOST_CONF_STRUCT( f ) ( ( f ) |= TOPMOST_CONF_STRUCT_FLAG )
  235. #define RESET_TOPMOST_CONF_STRUCT( f ) ( ( f ) &= ~TOPMOST_CONF_STRUCT_FLAG )
  236. #define IS_CONF_ARRAY_DONE( f ) ( ( f ) & REVERSE_ARRAY_MARSHALING_FLAG )
  237. #define SET_CONF_ARRAY_DONE( f ) ( ( f ) |= REVERSE_ARRAY_MARSHALING_FLAG )
  238. #define RESET_CONF_ARRAY_DONE( f ) ( ( f ) &= ~REVERSE_ARRAY_MARSHALING_FLAG )
  239. #define IS_WALKIP( f ) ( ( f ) & WALKIP_FLAG )
  240. #define SET_WALKIP( f ) ( ( f ) |= WALKIP_FLAG )
  241. #define RESET_WALKIP( f ) ( ( f ) &= ~WALKIP_FLAG )
  242. #define IS_SKIP_REF_CHECK( f ) ( ( f ) & SKIP_REF_CHECK_FLAG )
  243. #define SET_SKIP_REF_CHECK( f ) ( ( f ) |= SKIP_REF_CHECK_FLAG )
  244. #define RESET_SKIP_REF_CHECK( f ) ( ( f ) &= ~SKIP_REF_CHECK_FLAG )
  245. #define IS_BROKEN_INTERFACE_POINTER( f ) ( ( f ) & BROKEN_INTERFACE_POINTER_FLAG )
  246. #define SET_BROKEN_INTERFACE_POINTER( f ) ( ( f ) |= BROKEN_INTERFACE_POINTER_FLAG )
  247. #define RESET_BROKEN_INTERFACE_POINTER( f ) ( ( f ) &= ~BROKEN_INTERFACE_POINTER_FLAG )
  248. #define RESET_CONF_FLAGS_TO_STANDALONE( f ) (f) &= ~( BOGUS_EMBED_CONF_STRUCT_FLAG | \
  249. TOPMOST_CONF_STRUCT_FLAG | \
  250. REVERSE_ARRAY_MARSHALING_FLAG )
  251. //
  252. // Environment dependent macros
  253. //
  254. #define SIMPLE_TYPE_BUF_INCREMENT(Len, FC) Len += 16
  255. #define EXCEPTION_FLAG \
  256. ( (!(RpcFlags & RPCFLG_ASYNCHRONOUS)) && \
  257. (!InterpreterFlags.IgnoreObjectException) && \
  258. (StubMsg.dwStubPhase != PROXY_SENDRECEIVE) )
  259. #endif // _NDRP_