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.

279 lines
7.6 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright <c> 2000 Microsoft Corporation
  3. Module Name :
  4. ndrpall.h
  5. Abtract :
  6. Contains private definitions which are common to both
  7. ndr20 and ndr64
  8. Author :
  9. mzoran May 31, 2000
  10. Revision History :
  11. --------------------------------------------------------------------*/
  12. #if !defined(__NDRPALL_H__)
  13. #define __NDRPALL_H__
  14. //
  15. // The MIDL version is contained in the stub descriptor starting with
  16. // MIDL version 2.00.96 (pre NT 3.51 Beta 2, 2/95) and can be used for a finer
  17. // granularity of compatability checking. The MIDL version was zero before
  18. // MIDL version 2.00.96. The MIDL version number is converted into
  19. // an integer long using the following expression :
  20. // ((Major << 24) | (Minor << 16) | Revision)
  21. //
  22. #define MIDL_NT_3_51 ((2UL << 24) | (0UL << 16) | 102UL)
  23. #define MIDL_VERSION_3_0_39 ((3UL << 24) | (0UL << 16) | 39UL)
  24. #define MIDL_VERSION_3_2_88 ((3UL << 24) | (2UL << 16) | 88UL)
  25. #define MIDL_VERSION_5_0_136 ((5UL << 24) | (0UL << 16) | 136UL)
  26. #define MIDL_VERSION_5_2_202 ((5UL << 24) | (2UL << 16) | 202UL)
  27. // Shortcut typedefs.
  28. typedef unsigned char uchar;
  29. typedef unsigned short ushort;
  30. typedef unsigned long ulong;
  31. typedef unsigned int uint;
  32. typedef unsigned __int64 uint64;
  33. #if defined(NDRFREE_DEBUGPRINT)
  34. // force a debug print and a breakpoint on a free build
  35. #define NDR_ASSERT( exp, S ) \
  36. if (!(exp)) { DbgPrint( "%s(%s)\n", __FILE__, __LINE__ );DbgPrint( S## - Ryszard's private rpcrt4.dll\n", NULL );DebugBreak(); }
  37. #define NDR_CORRUPTION_ASSERT( exp, S ) NDR_ASSERT( exp, S )
  38. #else
  39. // Just use the RPC runtime assert
  40. #define NDR_ASSERT( exp, S ) \
  41. { ASSERT( ( S, (exp) ) ); }
  42. #define NDR_CORRUPTION_ASSERT( exp, S ) \
  43. { CORRUPTION_ASSERT( ( S, (exp) ) ); }
  44. #endif
  45. #define NDR_MEMORY_LIST_SIGNATURE 'MEML'
  46. // work around a HP RPC bug that'll coredump if the value of wire unique pointer marker is some certain value.
  47. // I can't really figure out the exact pattern and finally decide to choose one that works
  48. #define UNIQUE_POINTER_MARK 0x20000
  49. typedef struct _NDR_MEMORY_LIST_TAIL_NODE {
  50. ULONG Signature;
  51. void *pMemoryHead;
  52. struct _NDR_MEMORY_LIST_TAIL_NODE *pNextNode;
  53. } NDR_MEMORY_LIST_TAIL_NODE, *PNDR_MEMORY_LIST_TAIL_NODE;
  54. struct NDR_ALLOC_ALL_NODES_CONTEXT {
  55. unsigned char * AllocAllNodesMemory;
  56. unsigned char * AllocAllNodesMemoryBegin;
  57. unsigned char * AllocAllNodesMemoryEnd;
  58. };
  59. void
  60. NdrpFreeMemoryList(
  61. PMIDL_STUB_MESSAGE pStubMsg
  62. );
  63. void
  64. NdrpGetIIDFromBuffer(
  65. PMIDL_STUB_MESSAGE pStubMsg,
  66. IID ** ppIID
  67. );
  68. void
  69. NDRSContextEmergencyCleanup (
  70. IN RPC_BINDING_HANDLE BindingHandle,
  71. IN OUT NDR_SCONTEXT hContext,
  72. IN NDR_RUNDOWN userRunDownIn,
  73. IN PVOID NewUserContext,
  74. IN BOOL fManagerRoutineException
  75. );
  76. void
  77. NdrpEmergencyContextCleanup(
  78. MIDL_STUB_MESSAGE * pStubMsg,
  79. PNDR_CONTEXT_HANDLE_ARG_DESC pCtxtDesc,
  80. void * pArg,
  81. BOOL fManagerRoutineException );
  82. //
  83. // Alignment macros.
  84. //
  85. #define ALIGN( pStuff, cAlign ) \
  86. pStuff = (uchar *)((LONG_PTR)((pStuff) + (cAlign)) \
  87. & ~ ((LONG_PTR)(cAlign)))
  88. #define LENGTH_ALIGN( Length, cAlign ) \
  89. Length = (((Length) + (cAlign)) & ~ (cAlign))
  90. #if defined(_IA64_)
  91. #include "ia64reg.h"
  92. #ifdef __cplusplus
  93. extern "C" {
  94. #endif
  95. unsigned __int64 __getReg (int);
  96. #pragma intrinsic (__getReg)
  97. #ifdef __cplusplus
  98. } // extern "C"
  99. #endif
  100. #endif
  101. #if defined(_X86_)
  102. __forceinline
  103. void*
  104. NdrGetCurrentStackPointer(void)
  105. {
  106. _asm{ mov eax, esp }
  107. }
  108. __forceinline
  109. void
  110. NdrSetupLowStackMark( PMIDL_STUB_MESSAGE pStubMsg )
  111. {
  112. pStubMsg->LowStackMark = (uchar*)NdrGetCurrentStackPointer() - 0x1000; //4KB
  113. }
  114. __forceinline
  115. BOOL
  116. NdrIsLowStack(MIDL_STUB_MESSAGE *pStubMsg ) {
  117. return (SIZE_T)NdrGetCurrentStackPointer() < (SIZE_T)pStubMsg->LowStackMark;
  118. }
  119. #elif defined(_AMD64_)
  120. __forceinline
  121. void*
  122. NdrGetCurrentStackPointer(void)
  123. {
  124. PVOID TopOfStack;
  125. return (&TopOfStack + 1);
  126. }
  127. __forceinline
  128. void
  129. NdrSetupLowStackMark( PMIDL_STUB_MESSAGE pStubMsg )
  130. {
  131. pStubMsg->LowStackMark = (uchar*)NdrGetCurrentStackPointer() - 0x1000; //4KB
  132. }
  133. __forceinline
  134. BOOL
  135. NdrIsLowStack(MIDL_STUB_MESSAGE *pStubMsg ) {
  136. return (SIZE_T)NdrGetCurrentStackPointer() < (SIZE_T)pStubMsg->LowStackMark;
  137. //return false;
  138. }
  139. #elif defined(_IA64_)
  140. __forceinline
  141. void*
  142. NdrGetCurrentStackPointer(void)
  143. {
  144. return (void*)__getReg(CV_IA64_IntSp);
  145. }
  146. __forceinline
  147. void*
  148. NdrGetCurrentBackingStorePointer(void)
  149. {
  150. return (void*)__getReg(CV_IA64_RsBSP);
  151. }
  152. __forceinline
  153. void
  154. NdrSetupLowStackMark( PMIDL_STUB_MESSAGE pStubMsg )
  155. {
  156. // a backing store pointer which is used to store the stack based registers.
  157. // The normal stack grows downward and the backing store pointer grows upward.
  158. pStubMsg->LowStackMark = (uchar*)NdrGetCurrentStackPointer() - 0x4000;
  159. pStubMsg->BackingStoreLowMark =
  160. (uchar*)NdrGetCurrentBackingStorePointer() + 0x4000; //16KB // IA64 really has 2 stack pointers. The normal stack pointer and
  161. }
  162. __forceinline
  163. BOOL
  164. NdrIsLowStack(MIDL_STUB_MESSAGE *pStubMsg ) {
  165. return ((SIZE_T)NdrGetCurrentBackingStorePointer() > (SIZE_T)pStubMsg->BackingStoreLowMark) ||
  166. ((SIZE_T)NdrGetCurrentStackPointer() < (SIZE_T)pStubMsg->LowStackMark);
  167. //return false;
  168. }
  169. #else
  170. #error Unsupported Architecture
  171. #endif
  172. __forceinline
  173. void
  174. NdrRpcSetNDRSlot( void * pStubMsg )
  175. {
  176. RPC_STATUS rc = I_RpcSetNDRSlot( pStubMsg ) ;
  177. if ( rc!= RPC_S_OK )
  178. RpcRaiseException(rc );
  179. }
  180. BOOL
  181. IsWriteAV (
  182. IN struct _EXCEPTION_POINTERS *ExceptionPointers
  183. );
  184. int RPC_ENTRY
  185. NdrServerUnmarshallExceptionFlag(
  186. IN struct _EXCEPTION_POINTERS *ExceptionPointers
  187. );
  188. #define ZEROOUT_GAP( x ) if ( !((LONG_PTR)x & 3) ) {*( (long *&)(x) ) = 0;}
  189. // zero out 4 bytes if the alignement is 7
  190. void __forceinline
  191. ZeroOutGapAndAlign( PMIDL_STUB_MESSAGE pStubMsg, ulong Alignment )
  192. {
  193. if ( (~((ULONG_PTR)(pStubMsg->Buffer - 1) & 4 )) & (Alignment & 4 ) )
  194. {
  195. ALIGN(pStubMsg->Buffer,3);
  196. *((ulong *)pStubMsg->Buffer) = 0;
  197. };
  198. ALIGN(pStubMsg->Buffer, Alignment );
  199. }
  200. typedef void ( __fastcall * PSIMPLETYPE_MARSHAL_ROUTINE)(
  201. IN PMIDL_STUB_MESSAGE,
  202. IN uchar * );
  203. // memory copy routine used in marshalling to zero out trailing 4 bytes
  204. // if the memcpy doesn't end on 4 byte boundary.
  205. // we are sure the buffer buffer copy size could not be 0. midl will reject
  206. // empty structure and 0 length array.
  207. void __forceinline
  208. RpcpMarshalMemoryCopy(
  209. OUT void * Destination,
  210. IN void * Source,
  211. IN size_t Length
  212. )
  213. {
  214. NDR_ASSERT( Length != 0, "invalid buffer length");
  215. uchar *pEndofData = (uchar *)Destination + Length;
  216. ALIGN(pEndofData, 3 );
  217. // decide to add an IF statement to marshalling memcpy:
  218. // the place where this might have relatively more perf panelty
  219. // is only simple struct (with pointer ). All others we either have to
  220. // check anyhow or the code is complicated enough adding one
  221. // if doesn't really hurt.
  222. if ( pEndofData -4 >= Destination )
  223. *(long *)(pEndofData -4) = 0;
  224. RpcpMemoryCopy(Destination, Source, Length );
  225. }
  226. #endif // __NDRPALL_H__