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.

217 lines
6.1 KiB

  1. /***
  2. *stdarg.h - defines ANSI-style macros for variable argument functions
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines ANSI-style macros for accessing arguments
  8. * of functions which take a variable number of arguments.
  9. * [ANSI]
  10. *
  11. * [Public]
  12. *
  13. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifndef _INC_STDARG
  18. #define _INC_STDARG
  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 !defined(_W64)
  33. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  34. #define _W64 __w64
  35. #else
  36. #define _W64
  37. #endif
  38. #endif
  39. #ifndef _UINTPTR_T_DEFINED
  40. #ifdef _WIN64
  41. typedef unsigned __int64 uintptr_t;
  42. #else
  43. typedef _W64 unsigned int uintptr_t;
  44. #endif
  45. #define _UINTPTR_T_DEFINED
  46. #endif
  47. #ifndef _VA_LIST_DEFINED
  48. #ifdef _M_ALPHA
  49. typedef struct {
  50. char *a0; /* pointer to first homed integer argument */
  51. int offset; /* byte offset of next parameter */
  52. } va_list;
  53. #else
  54. typedef char * va_list;
  55. #endif
  56. #define _VA_LIST_DEFINED
  57. #endif
  58. #ifdef __cplusplus
  59. #define _ADDRESSOF(v) ( &reinterpret_cast<const char &>(v) )
  60. #else
  61. #define _ADDRESSOF(v) ( &(v) )
  62. #endif
  63. #if defined(_M_CEE)
  64. extern void __cdecl __va_start(va_list*, ...);
  65. extern void * __cdecl __va_arg(va_list*, ...);
  66. extern void __cdecl __va_end(va_list*);
  67. #define va_start(ap,v) ( __va_start(&ap, _ADDRESSOF(v), sizeof(v), \
  68. __builtin_alignof(v), _ADDRESSOF(v)) )
  69. #define va_arg(ap,t) ( *(t *)__va_arg(&ap, sizeof(t), \
  70. __builtin_alignof(t), (t *)0) )
  71. #define va_end(ap) ( __va_end(&ap) )
  72. #elif defined(_M_IX86)
  73. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  74. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  75. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  76. #define va_end(ap) ( ap = (va_list)0 )
  77. #elif defined(_M_MRX000)
  78. /* Use these types and definitions if generating code for MIPS */
  79. #define va_start(ap,v) ap = (va_list)_ADDRESSOF(v) + sizeof(v)
  80. #define va_end(list)
  81. #define va_arg(list, mode) ((mode *)(list =\
  82. (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\
  83. (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1]
  84. /* +++++++++++++++++++++++++++++++++++++++++++
  85. Because of parameter passing conventions in C:
  86. use mode=int for char, and short types
  87. use mode=double for float types
  88. use a pointer for array types
  89. +++++++++++++++++++++++++++++++++++++++++++ */
  90. #elif defined(_M_ALPHA)
  91. /* Use these types and definitions if generating code for ALPHA */
  92. /*
  93. * The Alpha compiler supports two builtin functions that are used to
  94. * implement stdarg/varargs. The __builtin_va_start function is used
  95. * by va_start to initialize the data structure that locates the next
  96. * argument. The __builtin_isfloat function is used by va_arg to pick
  97. * which part of the home area a given register argument is stored in.
  98. * The home area is where up to six integer and/or six floating point
  99. * register arguments are stored down (so they can also be referenced
  100. * by a pointer like any arguments passed on the stack).
  101. */
  102. extern void * __builtin_va_start(va_list, ...);
  103. #ifdef _CFRONT
  104. #define __builtin_isfloat(a) __builtin_alignof(a)
  105. #endif
  106. #define va_start(list, v) __builtin_va_start(list, v, 1)
  107. #define va_end(list)
  108. #define va_arg(list, mode) \
  109. ( *( ((list).offset += ((int)sizeof(mode) + 7) & -8) , \
  110. (mode *)((list).a0 + (list).offset - \
  111. ((__builtin_isfloat(mode) && (list).offset <= (6 * 8)) ? \
  112. (6 * 8) + 8 : ((int)sizeof(mode) + 7) & -8) \
  113. ) \
  114. ) \
  115. )
  116. #elif defined(_M_PPC)
  117. /* Microsoft C8 front end (used in Motorola Merged compiler) */
  118. /* bytes that a type occupies in the argument list */
  119. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  120. /* return 'ap' adjusted for type 't' in arglist */
  121. #define _ALIGNIT(ap,t) \
  122. ((((int)(ap))+(sizeof(t)<8?3:7)) & (sizeof(t)<8?~3:~7))
  123. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  124. #define va_arg(ap,t) ( *(t *)((ap = (char *) (_ALIGNIT(ap, t) + _INTSIZEOF(t))) - _INTSIZEOF(t)) )
  125. #define va_end(ap) ( ap = (va_list)0 )
  126. #elif defined(_M_IA64)
  127. #define _VA_STRUCT_ALIGN 16
  128. #define _VA_ALIGN 8
  129. #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) \
  130. - (ap))
  131. #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
  132. #define _SLOTSIZEOF(t) ( (sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1) )
  133. #ifdef __cplusplus
  134. extern void __cdecl __va_start(va_list*, ...);
  135. #define va_start(ap,v) ( __va_start(&ap, _ADDRESSOF(v), _SLOTSIZEOF(v), \
  136. _ADDRESSOF(v)) )
  137. #else
  138. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _SLOTSIZEOF(v) )
  139. #endif
  140. #define va_arg(ap,t) (*(t *)((ap += _SLOTSIZEOF(t)+ _APALIGN(t,ap)) \
  141. -_SLOTSIZEOF(t)))
  142. #define va_end(ap) ( ap = (va_list)0 )
  143. #elif defined(_M_AMD64)
  144. extern void __cdecl __va_start(va_list *, ...);
  145. #define va_start(ap, x) ( __va_start(&ap, x) )
  146. #define va_arg(ap, t) \
  147. ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \
  148. ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \
  149. : *(t *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )
  150. #define va_end(ap) ( ap = (va_list)0 )
  151. #else
  152. /* A guess at the proper definitions for other platforms */
  153. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  154. #define va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
  155. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  156. #define va_end(ap) ( ap = (va_list)0 )
  157. #endif
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #ifdef _MSC_VER
  162. #pragma pack(pop)
  163. #endif /* _MSC_VER */
  164. #endif /* _INC_STDARG */