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.

148 lines
3.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. typedef char *va_list;
  52. #define _VA_LIST_DEFINED
  53. #endif
  54. #if defined(_M_CEE)
  55. #error varargs.h not supported when targetting _M_CEE (use stdarg.h)
  56. #elif defined(_M_IX86)
  57. /*
  58. * define a macro to compute the size of a type, variable or expression,
  59. * rounded up to the nearest multiple of sizeof(int). This number is its
  60. * size as function argument (Intel architecture). Note that the macro
  61. * depends on sizeof(int) being a power of 2!
  62. */
  63. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  64. #define va_dcl va_list va_alist;
  65. #define va_start(ap) ap = (va_list)&va_alist
  66. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  67. #define va_end(ap) ap = (va_list)0
  68. #elif defined(_M_IA64)
  69. #ifndef _VA_LIST
  70. #define _VA_LIST char*
  71. #endif
  72. typedef _VA_LIST va_list;
  73. #define _VA_STRUCT_ALIGN 16
  74. #define _VA_ALIGN 8
  75. #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) \
  76. - (ap))
  77. #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
  78. #define _SLOTSIZEOF(t) ( (sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1) )
  79. #define va_dcl __int64 va_alist;
  80. #define va_start(ap) ( ap = (va_list)&va_alist )
  81. #define va_arg(ap,t) (*(t *)((ap += _SLOTSIZEOF(t)+ _APALIGN(t,ap)) \
  82. -_SLOTSIZEOF(t)))
  83. #define va_end(ap) ( ap = (va_list)0 )
  84. #elif defined(_M_AMD64)
  85. extern void __cdecl __va_start(va_list *, ...);
  86. #define va_dcl va_list va_alist;
  87. #define va_start(ap, x) ( __va_start(&ap, x) )
  88. #define va_arg(ap, t) \
  89. ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \
  90. ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \
  91. : *(t *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )
  92. #define va_end(ap) ( ap = (va_list)0 )
  93. #else
  94. /* A guess at the proper definitions for other platforms */
  95. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  96. #define va_dcl va_list va_alist;
  97. #define va_start(ap) ap = (va_list)&va_alist
  98. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  99. #define va_end(ap) ap = (va_list)0
  100. #endif
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #ifdef _MSC_VER
  105. #pragma pack(pop)
  106. #endif /* _MSC_VER */
  107. #endif /* _INC_VARARGS */