[NDK]
[reactos.git] / reactos / include / crt / vadefs.h
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the w64 mingw-runtime package.
4 * No warranty is given; refer to the file DISCLAIMER within this package.
5 */
6 #ifndef _INC_VADEFS
7 #define _INC_VADEFS
8
9 #ifndef _WIN32
10 #error Only Win32 target is supported!
11 #endif
12
13 #include <crtdefs.h>
14
15 #undef _CRT_PACKING
16 #define _CRT_PACKING 8
17 #pragma pack(push,_CRT_PACKING)
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #ifndef _UINTPTR_T_DEFINED
24 #define _UINTPTR_T_DEFINED
25 #ifndef __uintptr_t_defined
26 #define __uintptr_t_defined
27 #undef uintptr_t
28 #ifdef _WIN64
29 #if defined(__GNUC__) && defined(__STRICT_ANSI__)
30 typedef unsigned int uintptr_t __attribute__ ((mode (DI)));
31 #else
32 __MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
33 #endif
34 #else
35 typedef unsigned long uintptr_t;
36 #endif
37 #endif
38 #endif
39
40 #ifdef __GNUC__
41 #ifndef __GNUC_VA_LIST
42 #define __GNUC_VA_LIST
43 typedef __builtin_va_list __gnuc_va_list;
44 #endif
45 #endif
46
47 #ifndef _VA_LIST_DEFINED
48 #define _VA_LIST_DEFINED
49 #if defined(__GNUC__)
50 typedef __gnuc_va_list va_list;
51 #elif defined(_MSC_VER)
52 typedef char * va_list;
53 #endif
54 #endif
55
56 #ifdef __cplusplus
57 #define _ADDRESSOF(v) (&reinterpret_cast<const char &>(v))
58 #else
59 #define _ADDRESSOF(v) (&(v))
60 #endif
61
62 #if defined(__ia64__)
63 #define _VA_ALIGN 8
64 #define _SLOTSIZEOF(t) ((sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1))
65
66 #define _VA_STRUCT_ALIGN 16
67
68 #define _ALIGNOF(ap) ((((ap)+_VA_STRUCT_ALIGN - 1) & ~(_VA_STRUCT_ALIGN -1)) - (ap))
69 #define _APALIGN(t,ap) (__alignof(t) > 8 ? _ALIGNOF((uintptr_t) ap) : 0)
70 #else
71 #define _SLOTSIZEOF(t) (sizeof(t))
72 #define _APALIGN(t,ap) (__alignof(t))
73 #endif
74
75 #define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
76
77 #if defined(__GNUC__)
78 #define _crt_va_start(v,l) __builtin_va_start(v,l)
79 #define _crt_va_arg(v,l) __builtin_va_arg(v,l)
80 #define _crt_va_end(v) __builtin_va_end(v)
81 #define __va_copy(d,s) __builtin_va_copy(d,s)
82 #elif defined(_MSC_VER)
83
84 #if defined(_M_IX86)
85 #define _crt_va_start(v,l) ((void)((v) = (va_list)_ADDRESSOF(l) + _INTSIZEOF(l)))
86 #define _crt_va_arg(v,l) (*(l *)(((v) += _INTSIZEOF(l)) - _INTSIZEOF(l)))
87 #define _crt_va_end(v) ((void)((v) = (va_list)0))
88 #define __va_copy(d,s) ((void)((d) = (s)))
89 #elif defined(_M_AMD64)
90 #define _PTRSIZEOF(n) ((sizeof(n) + sizeof(void*) - 1) & ~(sizeof(void*) - 1))
91 #define _ISSTRUCT(t) ((sizeof(t) > sizeof(void*)) || (sizeof(t) & (sizeof(t)-1)) != 0)
92 #define _crt_va_start(v,l) ((void)((v) = (va_list)_ADDRESSOF(l) + _PTRSIZEOF(l)))
93 #define _crt_va_arg(v,t) (_ISSTRUCT(t) ? \
94 (**(t**)(((v) += sizeof(void*)) - sizeof(void*))) : \
95 (*(t*)(((v) += sizeof(void*)) - sizeof(void*))))
96 #define _crt_va_end(v) ((void)((v) = (va_list)0))
97 #define __va_copy(d,s) ((void)((d) = (s)))
98 #else //if defined(_M_IA64) || defined(_M_CEE)
99 #error Please implement me
100 #endif
101
102 #endif
103
104 #if !defined(va_copy) && (!defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L)
105 #define va_copy(d,s) __va_copy((d),(s))
106 #endif
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #pragma pack(pop)
113 #endif