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.

336 lines
8.4 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name :
  4. ndrmisc.h
  5. Abtract :
  6. Contains misc. function prototypes, flags, and macros, mainly from
  7. rpc\ndr20\ndrp.h.
  8. Revision History :
  9. John Doty johndoty May 2000 (Assembled from other ndr headers)
  10. --------------------------------------------------------------------*/
  11. #ifndef __NDRMISC_H__
  12. #define __NDRMISC_H__
  13. //
  14. // Type marshalling and buffer manipulation
  15. //
  16. EXTERN_C uchar *
  17. NdrpMemoryIncrement(
  18. PMIDL_STUB_MESSAGE pStubMsg,
  19. uchar * pMemory,
  20. PFORMAT_STRING pFormat
  21. );
  22. EXTERN_C void
  23. NdrUnmarshallBasetypeInline(
  24. PMIDL_STUB_MESSAGE pStubMsg,
  25. uchar * pArg,
  26. uchar Format
  27. );
  28. EXTERN_C
  29. unsigned char
  30. RPC_ENTRY
  31. NdrGetSimpleTypeBufferAlignment(
  32. unsigned char FormatChar
  33. );
  34. EXTERN_C
  35. unsigned char
  36. RPC_ENTRY
  37. NdrGetSimpleTypeBufferSize(
  38. unsigned char FormatChar
  39. );
  40. EXTERN_C
  41. unsigned char
  42. RPC_ENTRY
  43. NdrGetSimpleTypeMemorySize(
  44. unsigned char FormatChar
  45. );
  46. EXTERN_C
  47. unsigned long
  48. RPC_ENTRY
  49. NdrGetTypeFlags(
  50. unsigned char FormatChar
  51. );
  52. EXTERN_C
  53. void
  54. RPC_ENTRY
  55. NdrTypeSize(
  56. PMIDL_STUB_MESSAGE pStubMsg,
  57. unsigned char __RPC_FAR * pMemory,
  58. PFORMAT_STRING pFormat
  59. );
  60. EXTERN_C
  61. unsigned char *
  62. RPC_ENTRY
  63. NdrTypeMarshall(
  64. PMIDL_STUB_MESSAGE pStubMsg,
  65. unsigned char __RPC_FAR * pMemory,
  66. PFORMAT_STRING pFormat
  67. );
  68. EXTERN_C
  69. unsigned char *
  70. RPC_ENTRY
  71. NdrTypeUnmarshall(
  72. PMIDL_STUB_MESSAGE pStubMsg,
  73. unsigned char __RPC_FAR ** ppMemory,
  74. PFORMAT_STRING pFormat,
  75. unsigned char fSkipRefCheck
  76. );
  77. EXTERN_C
  78. void
  79. RPC_ENTRY
  80. NdrTypeFree(
  81. PMIDL_STUB_MESSAGE pStubMsg,
  82. unsigned char __RPC_FAR * pMemory,
  83. PFORMAT_STRING pFormat
  84. );
  85. // used by callframe guys
  86. EXTERN_C void
  87. NdrOutInit(
  88. PMIDL_STUB_MESSAGE pStubMsg,
  89. PFORMAT_STRING pFormat,
  90. uchar ** ppArg
  91. );
  92. // This definition is adjusted for a native platform.
  93. // The wire size is fixed for DCE NDR regardless of platform.
  94. #define PTR_MEM_SIZE sizeof(void *)
  95. #define PTR_MEM_ALIGN (sizeof(void *)-1)
  96. #define PTR_WIRE_SIZE (4)
  97. #define NDR_MAX_BUFFER_ALIGNMENT (16)
  98. #define CONTEXT_HANDLE_WIRE_SIZE 20
  99. #define IGNORED(Param)
  100. //
  101. // Alignment macros.
  102. //
  103. #define ALIGN( pStuff, cAlign ) \
  104. pStuff = (uchar *)((LONG_PTR)((pStuff) + (cAlign)) \
  105. & ~ ((LONG_PTR)(cAlign)))
  106. #define LENGTH_ALIGN( Length, cAlign ) \
  107. Length = (((Length) + (cAlign)) & ~ (cAlign))
  108. //
  109. // Simple type alignment and size lookup macros.
  110. //
  111. #ifdef _RPCRT4_
  112. #define SIMPLE_TYPE_ALIGNMENT(FormatChar) SimpleTypeAlignment[FormatChar]
  113. #define SIMPLE_TYPE_BUFSIZE(FormatChar) SimpleTypeBufferSize[FormatChar]
  114. #define SIMPLE_TYPE_MEMSIZE(FormatChar) SimpleTypeMemorySize[FormatChar]
  115. #else
  116. #define SIMPLE_TYPE_ALIGNMENT(FormatChar) NdrGetSimpleTypeBufferAlignment(FormatChar)
  117. #define SIMPLE_TYPE_BUFSIZE(FormatChar) NdrGetSimpleTypeBufferSize(FormatChar)
  118. #define SIMPLE_TYPE_MEMSIZE(FormatChar) NdrGetSimpleTypeMemorySize(FormatChar)
  119. #endif
  120. //
  121. // Format character attribute bits used in global NdrTypesFlags defined in
  122. // global.c.
  123. //
  124. #define _SIMPLE_TYPE_ 0x0001L
  125. #define _POINTER_ 0x0002L
  126. #define _STRUCT_ 0x0004L
  127. #define _ARRAY_ 0x0008L
  128. #define _STRING_ 0x0010L
  129. #define _UNION_ 0x0020L
  130. #define _XMIT_AS_ 0x0040L
  131. #define _BY_VALUE_ 0x0080L
  132. #define _HANDLE_ 0x0100L
  133. #define _BASIC_POINTER_ 0x0200L
  134. //
  135. // Format character query macros.
  136. //
  137. #ifdef __RPCRT4__
  138. #define _FC_FLAGS(FC) NdrTypeFlags[(FC)]
  139. #else
  140. #define _FC_FLAGS(FC) NdrGetTypeFlags(FC)
  141. #endif
  142. #define IS_SIMPLE_TYPE(FC) (_FC_FLAGS(FC) & _SIMPLE_TYPE_)
  143. #define IS_POINTER_TYPE(FC) (_FC_FLAGS(FC) & _POINTER_)
  144. #define IS_BASIC_POINTER(FC) (_FC_FLAGS(FC) & _BASIC_POINTER_)
  145. #define IS_ARRAY(FC) (_FC_FLAGS(FC) & _ARRAY_)
  146. #define IS_STRUCT(FC) (_FC_FLAGS(FC) & _STRUCT_)
  147. #define IS_UNION(FC) (_FC_FLAGS(FC) & _UNION_)
  148. #define IS_STRING(FC) (_FC_FLAGS(FC) & _STRING_)
  149. #define IS_ARRAY_OR_STRING(FC) (_FC_FLAGS(FC) & (_STRING_ | _ARRAY_))
  150. #define IS_XMIT_AS(FC) (_FC_FLAGS(FC) & _XMIT_AS_)
  151. #define IS_BY_VALUE(FC) (_FC_FLAGS(FC) & _BY_VALUE_)
  152. #define IS_HANDLE(FC) (NdrTypeFlags[(FC)] & _HANDLE_)
  153. //
  154. // Pointer attribute extraction and querying macros.
  155. //
  156. #define ALLOCATE_ALL_NODES( FC ) ((FC) & FC_ALLOCATE_ALL_NODES)
  157. #define DONT_FREE( FC ) ((FC) & FC_DONT_FREE)
  158. #define ALLOCED_ON_STACK( FC ) ((FC) & FC_ALLOCED_ON_STACK)
  159. #define SIMPLE_POINTER( FC ) ((FC) & FC_SIMPLE_POINTER)
  160. #define POINTER_DEREF( FC ) ((FC) & FC_POINTER_DEREF)
  161. //
  162. // Handle query macros.
  163. //
  164. #define IS_HANDLE_PTR( FC ) ((FC) & HANDLE_PARAM_IS_VIA_PTR)
  165. #define IS_HANDLE_IN( FC ) ((FC) & HANDLE_PARAM_IS_IN)
  166. #define IS_HANDLE_OUT( FC ) ((FC) & HANDLE_PARAM_IS_OUT)
  167. #define IS_HANDLE_RETURN( FC ) ((FC) & HANDLE_PARAM_IS_RETURN)
  168. //
  169. // Stack and argument defines.
  170. //
  171. #if defined(_AMD64_) || defined(_IA64_)
  172. #define REGISTER_TYPE _int64
  173. #else
  174. #define REGISTER_TYPE int
  175. #endif
  176. #define RETURN_SIZE 8
  177. //
  178. // Argument retrieval macros.
  179. //
  180. #define INIT_ARG(argptr,arg0) va_start(argptr, arg0)
  181. #ifndef _ALPHA_
  182. //
  183. // Both MIPS and x86 are 4 byte aligned stacks, with MIPS supporting 8byte
  184. // alignment on the stack as well. Their va_list is essentially an
  185. // unsigned char *.
  186. //
  187. #if defined(_IA64_)
  188. #define GET_FIRST_IN_ARG(argptr)
  189. #define GET_FIRST_OUT_ARG(argptr)
  190. #elif defined(_AMD64_)
  191. #define GET_FIRST_IN_ARG(argptr)
  192. #define GET_FIRST_OUT_ARG(argptr)
  193. #else
  194. #define GET_FIRST_IN_ARG(argptr) argptr = *(va_list *)argptr
  195. #define GET_FIRST_OUT_ARG(argptr) argptr = *(va_list *)argptr
  196. #endif
  197. #define GET_NEXT_C_ARG(argptr,type) va_arg(argptr,type)
  198. #define SKIP_STRUCT_ON_STACK(ArgPtr, Size) ArgPtr += Size
  199. #define GET_STACK_START(ArgPtr) ArgPtr
  200. #define GET_STACK_POINTER(ArgPtr, mode) ArgPtr
  201. #else // _ALPHA_
  202. //
  203. // The Alpha has an 8byte aligned stack, with its va_list being a structure
  204. // consisting of an unsigned char *, a0 and an int offset. See stdarg.h for
  205. // the gory details.
  206. //
  207. #define GET_FIRST_IN_ARG(argptr) \
  208. argptr.a0 = va_arg(argptr, char *); \
  209. argptr.offset = 0
  210. #define GET_FIRST_OUT_ARG(argptr) \
  211. argptr.a0 = va_arg(argptr, char *); \
  212. argptr.offset = 0
  213. //
  214. // Note that this macro does nothing for the Alpha. The stack incrementing is
  215. // folded into the GET_STACK_POINTER below.
  216. //
  217. #define GET_NEXT_C_ARG(argptr,type)
  218. #define SKIP_STRUCT_ON_STACK(ArgPtr, Size) \
  219. Size += 7; Size &= ~7; \
  220. for(Size /= sizeof(_int64);Size;--Size){va_arg(ArgPtr, _int64);}
  221. #define GET_STACK_START(ArgPtr) ArgPtr.a0
  222. //
  223. // Ok, this ugly mess is just a trimmed dowm version of the va_arg macro for
  224. // the alpha. What is missing is the dereference operator (*) and the test for
  225. // a float (__builtin_isfloat()).
  226. //
  227. #define GET_STACK_POINTER(ArgPtr, mode) \
  228. ( \
  229. ((ArgPtr).offset += ((int)sizeof(mode) + 7) & -8) , \
  230. (mode *)((ArgPtr).a0 + \
  231. (ArgPtr).offset - \
  232. (((int)sizeof(mode) + 7) & -8)) \
  233. )
  234. #endif // _ALPHA_
  235. //
  236. // Use the following macro _after_ argptr has been saved or processed
  237. //
  238. #define SKIP_PROCESSED_ARG(argptr, type) \
  239. GET_NEXT_C_ARG(argptr, type); \
  240. GET_STACK_POINTER(argptr,type)
  241. #define GET_NEXT_S_ARG(argptr,type) argptr += sizeof(type)
  242. #endif