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.

209 lines
5.5 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. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifndef _INC_VARARGS
  18. #define _INC_VARARGS
  19. #if !defined(_WIN32)
  20. #error ERROR: Only Win32 target supported!
  21. #endif
  22. #ifdef _MSC_VER
  23. /*
  24. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  25. * alignment.
  26. */
  27. #pragma pack(push,8)
  28. #endif /* _MSC_VER */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #if __STDC__
  33. #error varargs.h incompatible with ANSI (use stdarg.h)
  34. #endif
  35. #if !defined(_W64)
  36. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  37. #define _W64 __w64
  38. #else
  39. #define _W64
  40. #endif
  41. #endif
  42. #ifndef _UINTPTR_T_DEFINED
  43. #ifdef _WIN64
  44. typedef unsigned __int64 uintptr_t;
  45. #else
  46. typedef _W64 unsigned int uintptr_t;
  47. #endif
  48. #define _UINTPTR_T_DEFINED
  49. #endif
  50. #ifndef _VA_LIST_DEFINED
  51. #ifdef _M_ALPHA
  52. typedef struct {
  53. char *a0; /* pointer to first homed integer argument */
  54. int offset; /* byte offset of next parameter */
  55. } va_list;
  56. #else
  57. typedef char *va_list;
  58. #endif
  59. #define _VA_LIST_DEFINED
  60. #endif
  61. #if defined(_M_CEE)
  62. #error varargs.h not supported when targetting _M_CEE (use stdarg.h)
  63. #elif defined(_M_IX86)
  64. /*
  65. * define a macro to compute the size of a type, variable or expression,
  66. * rounded up to the nearest multiple of sizeof(int). This number is its
  67. * size as function argument (Intel architecture). Note that the macro
  68. * depends on sizeof(int) being a power of 2!
  69. */
  70. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  71. #define va_dcl va_list va_alist;
  72. #define va_start(ap) ap = (va_list)&va_alist
  73. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  74. #define va_end(ap) ap = (va_list)0
  75. #elif defined(_M_MRX000) /* _MIPS_ */
  76. #define va_dcl int va_alist;
  77. #define va_start(list) list = (char *) &va_alist
  78. #define va_end(list)
  79. #define va_arg(list, mode) ((mode *)(list =\
  80. (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\
  81. (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1]
  82. /* +++++++++++++++++++++++++++++++++++++++++++
  83. Because of parameter passing conventions in C:
  84. use mode=int for char, and short types
  85. use mode=double for float types
  86. use a pointer for array types
  87. +++++++++++++++++++++++++++++++++++++++++++ */
  88. #elif defined(_M_ALPHA)
  89. /*
  90. * The Alpha compiler supports two builtin functions that are used to
  91. * implement stdarg/varargs. The __builtin_va_start function is used
  92. * by va_start to initialize the data structure that locates the next
  93. * argument. The __builtin_isfloat function is used by va_arg to pick
  94. * which part of the home area a given register argument is stored in.
  95. * The home area is where up to six integer and/or six floating point
  96. * register arguments are stored down (so they can also be referenced
  97. * by a pointer like any arguments passed on the stack).
  98. */
  99. extern void * __builtin_va_start(va_list, ...);
  100. #define va_dcl long va_alist;
  101. #define va_start(list) __builtin_va_start(list, va_alist, 0)
  102. #define va_end(list)
  103. #define va_arg(list, mode) \
  104. ( *( ((list).offset += ((int)sizeof(mode) + 7) & -8) , \
  105. (mode *)((list).a0 + (list).offset - \
  106. ((__builtin_isfloat(mode) && (list).offset <= (6 * 8)) ? \
  107. (6 * 8) + 8 : ((int)sizeof(mode) + 7) & -8) \
  108. ) \
  109. ) \
  110. )
  111. #elif defined(_M_PPC)
  112. /*
  113. * define a macro to compute the size of a type, variable or expression,
  114. * rounded up to the nearest multiple of sizeof(int). This number is its
  115. * size as function argument (PPC architecture). Note that the macro
  116. * depends on sizeof(int) being a power of 2!
  117. */
  118. /* this is for LITTLE-ENDIAN PowerPC */
  119. /* bytes that a type occupies in the argument list */
  120. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  121. /* return 'ap' adjusted for type 't' in arglist */
  122. #define _ALIGNIT(ap,t) \
  123. ((((int)(ap))+(sizeof(t)<8?3:7)) & (sizeof(t)<8?~3:~7))
  124. #define va_dcl va_list va_alist;
  125. #define va_start(ap) ap = (va_list)&va_alist
  126. #define va_arg(ap,t) ( *(t *)((ap = (char *) (_ALIGNIT(ap, t) + _INTSIZEOF(t))) - _INTSIZEOF(t)) )
  127. #define va_end(ap) ap = (va_list)0
  128. #elif defined(_M_IA64)
  129. #ifndef _VA_LIST
  130. #define _VA_LIST char*
  131. #endif
  132. typedef _VA_LIST va_list;
  133. #define _VA_STRUCT_ALIGN 16
  134. #define _VA_ALIGN 8
  135. #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) \
  136. - (ap))
  137. #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
  138. #define _SLOTSIZEOF(t) ( (sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1) )
  139. #define va_dcl __int64 va_alist;
  140. #define va_start(ap) ( ap = (va_list)&va_alist )
  141. #define va_arg(ap,t) (*(t *)((ap += _SLOTSIZEOF(t)+ _APALIGN(t,ap)) \
  142. -_SLOTSIZEOF(t)))
  143. #define va_end(ap) ( ap = (va_list)0 )
  144. #else
  145. /* A guess at the proper definitions for other platforms */
  146. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  147. #define va_dcl va_list va_alist;
  148. #define va_start(ap) ap = (va_list)&va_alist
  149. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  150. #define va_end(ap) ap = (va_list)0
  151. #endif
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #ifdef _MSC_VER
  156. #pragma pack(pop)
  157. #endif /* _MSC_VER */
  158. #endif /* _INC_VARARGS */