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.

159 lines
4.4 KiB

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