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.

265 lines
8.3 KiB

  1. /***
  2. *varargs.h - XENIX style macros for variable argument functions
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines XENIX style macros for accessing arguments of a
  8. * function which takes a variable number of arguments.
  9. * [System V]
  10. *
  11. * [Public]
  12. *
  13. *Revision History:
  14. * 08-22-88 GJF Modified to also work for the 386 (small model only)
  15. * 05-03-89 JCR Added _INTERNAL_IFSTRIP for relinc usage
  16. * 08-15-89 GJF Cleanup, now specific to OS/2 2.0 (i.e., 386 flat model)
  17. * 10-30-89 GJF Fixed copyright
  18. * 11-02-89 JCR Changed "DLL" to "_DLL"
  19. * 01-05-90 JCR Added NULL definition
  20. * 03-02-90 GJF Added #ifndef _INC_VARARGS stuff. Also, removed some
  21. * (now) useless preprocessor directives.
  22. * 05-29-90 GJF Replaced sizeof() with _INTSIZEOF() and revised the
  23. * va_arg() macro (fixes PTM 60)
  24. * 05-31-90 GJF Revised va_end() macro (propagated 5-25-90 change to
  25. * crt7 version by WAJ)
  26. * 01-24-91 JCR Generate an error on ANSI compilations
  27. * 08-20-91 JCR C++ and ANSI naming
  28. * 11-01-91 GDP MIPS Compiler support
  29. * 10-16-92 SKS Replaced "#ifdef i386" with "#ifdef _M_IX86".
  30. * 11-03-92 GJF Fixed several conditionals, dropped _DOSX32_ support.
  31. * 01-09-93 SRW Remove usage of MIPS and ALPHA to conform to ANSI
  32. * Use _MIPS_ and _ALPHA_ instead.
  33. * 10-04-93 SRW Fix ifdefs for MIPS and ALPHA to only check for _M_?????? defines
  34. * 10-13-93 GJF Merged NT and Cuda versions.
  35. * 04-05-94 SKS Add prototype of __builtin_va_start for ALPHA
  36. * 10-02-94 BWT PPC merge
  37. * 11-03-94 GJF Ensure 8 byte alignment.
  38. * 02-11-95 CFW Add _CRTBLD to avoid users getting wrong headers.
  39. * 02-14-95 CFW Clean up Mac merge.
  40. * 12-14-95 JWM Add "#pragma once".
  41. * 02-24-97 GJF Detab-ed.
  42. * 10-07-97 RDL Added IA64.
  43. * 11-07-97 RDL Soft23 varargs.
  44. * 05-17-99 PML Remove all Macintosh support.
  45. * 10-25-99 PML Fix IA64 _APALIGN macro (VS7#51838).
  46. * 10-25-99 PML Add support for _M_CEE (VS7#54572).
  47. * 01-20-00 PML Remove __epcg__.
  48. * 05-17-00 PML Use __alignof in _APALIGN macro for IA64.
  49. * 03-26-01 GB Added va_args for AMD64
  50. *
  51. ****/
  52. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  53. #pragma once
  54. #endif
  55. #ifndef _INC_VARARGS
  56. #define _INC_VARARGS
  57. #if !defined(_WIN32)
  58. #error ERROR: Only Win32 target supported!
  59. #endif
  60. #ifndef _CRTBLD
  61. /* This version of the header files is NOT for user programs.
  62. * It is intended for use when building the C runtimes ONLY.
  63. * The version intended for public use will not have this message.
  64. */
  65. #error ERROR: Use of C runtime library internal header file.
  66. #endif /* _CRTBLD */
  67. #ifdef _MSC_VER
  68. /*
  69. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  70. * alignment.
  71. */
  72. #pragma pack(push,8)
  73. #endif /* _MSC_VER */
  74. #ifdef __cplusplus
  75. extern "C" {
  76. #endif
  77. #if __STDC__
  78. #error varargs.h incompatible with ANSI (use stdarg.h)
  79. #endif
  80. #if !defined(_W64)
  81. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 /*IFSTRIP=IGN*/
  82. #define _W64 __w64
  83. #else
  84. #define _W64
  85. #endif
  86. #endif
  87. #ifndef _UINTPTR_T_DEFINED
  88. #ifdef _WIN64
  89. typedef unsigned __int64 uintptr_t;
  90. #else
  91. typedef _W64 unsigned int uintptr_t;
  92. #endif
  93. #define _UINTPTR_T_DEFINED
  94. #endif
  95. #ifndef _VA_LIST_DEFINED
  96. #ifdef _M_ALPHA
  97. typedef struct {
  98. char *a0; /* pointer to first homed integer argument */
  99. int offset; /* byte offset of next parameter */
  100. } va_list;
  101. #else
  102. typedef char *va_list;
  103. #endif
  104. #define _VA_LIST_DEFINED
  105. #endif
  106. #if defined(_M_CEE)
  107. #error varargs.h not supported when targetting _M_CEE (use stdarg.h)
  108. #elif defined(_M_IX86)
  109. /*
  110. * define a macro to compute the size of a type, variable or expression,
  111. * rounded up to the nearest multiple of sizeof(int). This number is its
  112. * size as function argument (Intel architecture). Note that the macro
  113. * depends on sizeof(int) being a power of 2!
  114. */
  115. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  116. #define va_dcl va_list va_alist;
  117. #define va_start(ap) ap = (va_list)&va_alist
  118. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  119. #define va_end(ap) ap = (va_list)0
  120. #elif defined(_M_MRX000) /* _MIPS_ */
  121. #define va_dcl int va_alist;
  122. #define va_start(list) list = (char *) &va_alist
  123. #define va_end(list)
  124. #define va_arg(list, mode) ((mode *)(list =\
  125. (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\
  126. (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1]
  127. /* +++++++++++++++++++++++++++++++++++++++++++
  128. Because of parameter passing conventions in C:
  129. use mode=int for char, and short types
  130. use mode=double for float types
  131. use a pointer for array types
  132. +++++++++++++++++++++++++++++++++++++++++++ */
  133. #elif defined(_M_ALPHA)
  134. /*
  135. * The Alpha compiler supports two builtin functions that are used to
  136. * implement stdarg/varargs. The __builtin_va_start function is used
  137. * by va_start to initialize the data structure that locates the next
  138. * argument. The __builtin_isfloat function is used by va_arg to pick
  139. * which part of the home area a given register argument is stored in.
  140. * The home area is where up to six integer and/or six floating point
  141. * register arguments are stored down (so they can also be referenced
  142. * by a pointer like any arguments passed on the stack).
  143. */
  144. extern void * __builtin_va_start(va_list, ...);
  145. #define va_dcl long va_alist;
  146. #define va_start(list) __builtin_va_start(list, va_alist, 0)
  147. #define va_end(list)
  148. #define va_arg(list, mode) \
  149. ( *( ((list).offset += ((int)sizeof(mode) + 7) & -8) , \
  150. (mode *)((list).a0 + (list).offset - \
  151. ((__builtin_isfloat(mode) && (list).offset <= (6 * 8)) ? \
  152. (6 * 8) + 8 : ((int)sizeof(mode) + 7) & -8) \
  153. ) \
  154. ) \
  155. )
  156. #elif defined(_M_PPC)
  157. /*
  158. * define a macro to compute the size of a type, variable or expression,
  159. * rounded up to the nearest multiple of sizeof(int). This number is its
  160. * size as function argument (PPC architecture). Note that the macro
  161. * depends on sizeof(int) being a power of 2!
  162. */
  163. /* this is for LITTLE-ENDIAN PowerPC */
  164. /* bytes that a type occupies in the argument list */
  165. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  166. /* return 'ap' adjusted for type 't' in arglist */
  167. #define _ALIGNIT(ap,t) \
  168. ((((int)(ap))+(sizeof(t)<8?3:7)) & (sizeof(t)<8?~3:~7))
  169. #define va_dcl va_list va_alist;
  170. #define va_start(ap) ap = (va_list)&va_alist
  171. #define va_arg(ap,t) ( *(t *)((ap = (char *) (_ALIGNIT(ap, t) + _INTSIZEOF(t))) - _INTSIZEOF(t)) )
  172. #define va_end(ap) ap = (va_list)0
  173. #elif defined(_M_IA64)
  174. #ifndef _VA_LIST
  175. #define _VA_LIST char*
  176. #endif
  177. typedef _VA_LIST va_list;
  178. #define _VA_STRUCT_ALIGN 16
  179. #define _VA_ALIGN 8
  180. #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) \
  181. - (ap))
  182. #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
  183. #define _SLOTSIZEOF(t) ( (sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1) )
  184. #define va_dcl __int64 va_alist;
  185. #define va_start(ap) ( ap = (va_list)&va_alist )
  186. #define va_arg(ap,t) (*(t *)((ap += _SLOTSIZEOF(t)+ _APALIGN(t,ap)) \
  187. -_SLOTSIZEOF(t)))
  188. #define va_end(ap) ( ap = (va_list)0 )
  189. #elif defined(_M_AMD64)
  190. extern void __cdecl __va_start(va_list *, ...);
  191. #define va_start(ap, x) ( __va_start(&ap, x) )
  192. #define va_arg(ap, t) \
  193. ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \
  194. ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \
  195. : *(t *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )
  196. #define va_end(ap) ( ap = (va_list)0 )
  197. #else
  198. /* A guess at the proper definitions for other platforms */
  199. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  200. #define va_dcl va_list va_alist;
  201. #define va_start(ap) ap = (va_list)&va_alist
  202. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  203. #define va_end(ap) ap = (va_list)0
  204. #endif
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208. #ifdef _MSC_VER
  209. #pragma pack(pop)
  210. #endif /* _MSC_VER */
  211. #endif /* _INC_VARARGS */