Mercurial > pub > dyncall > dyncall
comparison dyncall/dyncall_macros.h @ 616:5d999f5c13d1
- fixed mingw and cygwin env detection (was always shadowed by _WIN32 macro detection, and __MINGW__ macro check was wrong to begin with)
- cosmetic cleanups for consistency
- added runtime detection to dyncall_macros.h to handle some edge cases
- fixed detection of native thiscall callconv for builds not using MSVC but using (or adhering to) the MSVC runtime (e.g. ReactOS' MinGW based RosBE)
author | Tassilo Philipp |
---|---|
date | Sun, 02 Oct 2022 13:58:33 +0200 |
parents | dfc2e6ee8782 |
children | 6a8aac9b2bcf |
comparison
equal
deleted
inserted
replaced
615:516d72e98253 | 616:5d999f5c13d1 |
---|---|
48 | 48 |
49 /* -- Platform specific #defines ------------------------------------ */ | 49 /* -- Platform specific #defines ------------------------------------ */ |
50 | 50 |
51 /* MS Windows XP x64/Vista64 or later. */ | 51 /* MS Windows XP x64/Vista64 or later. */ |
52 #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) | 52 #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) |
53 #define DC__OS_Win64 | 53 # define DC__OS_Win64 |
54 | 54 |
55 /* MS Windows NT/95/98/ME/2000/XP/Vista32. */ | 55 /* MS Windows NT/95/98/ME/2000/XP/Vista32. */ |
56 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__WINDOWS__) || defined(_WINDOWS) | 56 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__WINDOWS__) || defined(_WINDOWS) |
57 #define DC__OS_Win32 | 57 # define DC__OS_Win32 |
58 | 58 |
59 /* All the OS' based on Darwin OS (MacOS X, OpenDarwin). Note that '__APPLE__' may be defined for classic MacOS, too. */ | 59 /* All the OS' based on Darwin OS (MacOS X, OpenDarwin). Note that '__APPLE__' may be defined for classic MacOS, too. */ |
60 /* __MACOSX__ is not defined in gcc assembler mode (switch: -S) */ | 60 /* __MACOSX__ is not defined in gcc assembler mode (switch: -S) */ |
61 /* @@@ TODO: Check for Classic OS */ | |
62 | |
63 #elif defined(__APPLE__) || defined(__Darwin__) | 61 #elif defined(__APPLE__) || defined(__Darwin__) |
64 # define DC__OS_Darwin | 62 # define DC__OS_Darwin |
65 # if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) | 63 # if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) |
66 # define DC__OS_IPhone | 64 # define DC__OS_IPhone |
67 # else /* defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) */ | 65 # else /* defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) */ |
68 # define DC__OS_MacOSX | 66 # define DC__OS_MacOSX |
69 # endif | 67 # endif |
70 | 68 |
71 /* The most popular open source Unix-like OS - Linux. */ | 69 /* The most popular open source Unix-like OS - Linux. */ |
72 #elif defined(__linux__) || defined(__linux) || defined(__gnu_linux__) | 70 #elif defined(__linux__) || defined(__linux) || defined(__gnu_linux__) |
73 #define DC__OS_Linux | 71 # define DC__OS_Linux |
74 | 72 |
75 /* The most powerful open source Unix-like OS - FreeBSD. */ | 73 /* The most powerful open source Unix-like OS - FreeBSD. */ |
76 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* latter is (also) used by systems using FreeBSD kernel, e.g. Debian/kFreeBSD, which could be detected specifically by also checking for __GLIBC__ */ | 74 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* latter is (also) used by systems using FreeBSD kernel, e.g. Debian/kFreeBSD, which could be detected specifically by also checking for __GLIBC__ */ |
77 #define DC__OS_FreeBSD | 75 # define DC__OS_FreeBSD |
78 | 76 |
79 /* The most secure open source Unix-like OS - OpenBSD. */ | 77 /* The most secure open source Unix-like OS - OpenBSD. */ |
80 #elif defined(__OpenBSD__) | 78 #elif defined(__OpenBSD__) |
81 #define DC__OS_OpenBSD | 79 # define DC__OS_OpenBSD |
82 | 80 |
83 /* The most portable open source Unix-like OS - NetBSD. */ | 81 /* The most portable open source Unix-like OS - NetBSD. */ |
84 #elif defined(__NetBSD__) | 82 #elif defined(__NetBSD__) |
85 #define DC__OS_NetBSD | 83 # define DC__OS_NetBSD |
86 | 84 |
87 /* The FreeBSD fork having heavy clusterization in mind - DragonFlyBSD. */ | 85 /* The FreeBSD fork having heavy clusterization in mind - DragonFlyBSD. */ |
88 #elif defined(__DragonFly__) | 86 #elif defined(__DragonFly__) |
89 #define DC__OS_DragonFlyBSD | 87 # define DC__OS_DragonFlyBSD |
90 | 88 |
91 /* Sun's Unix-like OS - SunOS / Solaris. */ | 89 /* Sun's Unix-like OS - SunOS / Solaris. */ |
92 #elif defined(__sun__) || defined(__sun) || defined(sun) | 90 #elif defined(__sun__) || defined(__sun) || defined(sun) |
93 #define DC__OS_SunOS | 91 # define DC__OS_SunOS |
94 | |
95 /* The "Linux-like environment for Windows" - Cygwin. */ | |
96 #elif defined(__CYGWIN__) | |
97 #define DC__OS_Cygwin | |
98 | |
99 /* The "Minimalist GNU for Windows" - MinGW. */ | |
100 #elif defined(__MINGW__)/*@@@*/ | |
101 #define DC__OS_MinGW | |
102 | 92 |
103 /* The Nintendo DS (homebrew) using devkitpro. */ | 93 /* The Nintendo DS (homebrew) using devkitpro. */ |
104 #elif defined(__nds__) | 94 #elif defined(__nds__) |
105 #define DC__OS_NDS | 95 # define DC__OS_NDS |
106 | 96 |
107 /* The PlayStation Portable (homebrew) SDK. */ | 97 /* The PlayStation Portable (homebrew) SDK. */ |
108 #elif defined(__psp__) || defined(PSP) | 98 #elif defined(__psp__) || defined(PSP) |
109 #define DC__OS_PSP | 99 # define DC__OS_PSP |
110 | 100 |
111 /* Haiku (BeOS alike). */ | 101 /* Haiku (BeOS alike). */ |
112 #elif defined(__HAIKU__) | 102 #elif defined(__HAIKU__) |
113 #define DC__OS_BeOS | 103 # define DC__OS_BeOS |
114 | 104 |
115 /* The Unix successor - Plan9 from Bell Labs */ | 105 /* The Unix successor - Plan9 from Bell Labs */ |
116 #elif defined(Plan9) || defined(__Plan9__) | 106 #elif defined(Plan9) || defined(__Plan9__) |
117 #define DC__OS_Plan9 | 107 # define DC__OS_Plan9 |
118 | 108 |
119 /* Digital's Unix-like OS - VMS */ | 109 /* Digital's Unix-like OS - VMS */ |
120 #elif defined(__vms) | 110 #elif defined(__vms) |
121 #define DC__OS_VMS | 111 # define DC__OS_VMS |
122 | 112 |
113 /* Tanenbaum's Microkernel OS - Minix */ | |
123 #elif defined(__minix) | 114 #elif defined(__minix) |
124 #define DC__OS_Minix | 115 # define DC__OS_Minix |
125 | 116 |
117 /* Unable to determine OS, which is probably ok (e.g. baremetal stuff, etc.). */ | |
126 #else | 118 #else |
127 | 119 # define DC__OS_UNKNOWN |
128 /* Unable to determine OS, which is probably ok (e.g. baremetal stuff, etc.). */ | 120 |
129 #define DC__OS_UNKNOWN | 121 #endif |
122 | |
123 | |
124 /* windows sub envs */ | |
125 #if defined(DC__OS_Win32) || defined(DC__OS_Win64) | |
126 | |
127 /* The "Linux-like environment for Windows" - Cygwin. */ | |
128 # if defined(__CYGWIN__) | |
129 # define DC__OS_Cygwin | |
130 | |
131 /* The "Minimalist GNU for Windows" - MinGW. */ | |
132 # elif defined(__MINGW32__) || defined(__MINGW64__) | |
133 # define DC__OS_MinGW | |
134 # endif | |
135 | |
130 #endif | 136 #endif |
131 | 137 |
132 | 138 |
133 | 139 |
134 /* -- Compiler specific #defines ------------------------------------ */ | 140 /* -- Compiler specific #defines ------------------------------------ */ |
135 | 141 |
136 /* Don't change the order, b/c some compilers use same #defines compatibility */ | 142 /* Don't change the order, b/c some compilers use same #defines compatibility */ |
137 | 143 |
138 /* Intel's C/C++ compiler. */ | 144 /* Intel's C/C++ compiler. */ |
139 #if defined(__INTEL_COMPILER) | 145 #if defined(__INTEL_COMPILER) |
140 #define DC__C_Intel | 146 # define DC__C_Intel |
141 | 147 |
142 /* MS C/C++ compiler. */ | 148 /* MS C/C++ compiler. */ |
143 #elif defined(_MSC_VER) | 149 #elif defined(_MSC_VER) |
144 #define DC__C_MSVC | 150 # define DC__C_MSVC |
145 | 151 |
146 /* LLVM clang. */ | 152 /* LLVM clang. */ |
147 #elif defined(__clang__) || defined(__llvm__) | 153 #elif defined(__clang__) || defined(__llvm__) |
148 #define DC__C_CLANG | 154 # define DC__C_CLANG |
149 | 155 |
150 /* The GNU Compiler Collection - GCC. */ | 156 /* The GNU Compiler Collection - GCC. */ |
151 #elif defined(__GNUC__) | 157 #elif defined(__GNUC__) |
152 #define DC__C_GNU | 158 # define DC__C_GNU |
153 | 159 |
154 /* Watcom compiler. */ | 160 /* Watcom compiler. */ |
155 #elif defined(__WATCOMC__) | 161 #elif defined(__WATCOMC__) |
156 #define DC__C_WATCOM | 162 # define DC__C_WATCOM |
157 | 163 |
158 /* Portable C Compiler. */ | 164 /* Portable C Compiler. */ |
159 #elif defined(__PCC__) | 165 #elif defined(__PCC__) |
160 #define DC__C_PCC | 166 # define DC__C_PCC |
161 | 167 |
162 /* Sun Pro C. */ | 168 /* Sun Pro C. */ |
163 #elif defined(__SUNPRO_C) | 169 #elif defined(__SUNPRO_C) |
164 #define DC__C_SUNPRO | 170 # define DC__C_SUNPRO |
165 | 171 |
166 /* Undetected C Compiler. */ | 172 /* Undetected C Compiler. */ |
167 #else | 173 #else |
168 #define DC__C_UNKNOWN | 174 # define DC__C_UNKNOWN |
169 #endif | 175 #endif |
170 | 176 |
171 | 177 |
172 | 178 |
173 /* -- Architecture -------------------------------------------------- */ | 179 /* -- Architecture -------------------------------------------------- */ |
179 # define DC__Arch_Intel_x86 | 185 # define DC__Arch_Intel_x86 |
180 #elif defined(_M_IA64) || defined(__ia64__) | 186 #elif defined(_M_IA64) || defined(__ia64__) |
181 # define DC__Arch_Itanium | 187 # define DC__Arch_Itanium |
182 #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__) | 188 #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__) |
183 # if defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__) || defined(__powerpc64__) | 189 # if defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__) || defined(__powerpc64__) |
184 # define DC__Arch_PPC64 | 190 # define DC__Arch_PPC64 |
185 # else | 191 # else |
186 # define DC__Arch_PPC32 | 192 # define DC__Arch_PPC32 |
187 # endif | 193 # endif |
188 #elif defined(__mips64__) || defined(__mips64) | 194 #elif defined(__mips64__) || defined(__mips64) |
189 # define DC__Arch_MIPS64 | 195 # define DC__Arch_MIPS64 |
190 #elif defined(_M_MRX000) || defined(__mips__) || defined(__mips) || defined(_mips) | 196 #elif defined(_M_MRX000) || defined(__mips__) || defined(__mips) || defined(_mips) |
191 # define DC__Arch_MIPS | 197 # define DC__Arch_MIPS |
203 # endif | 209 # endif |
204 #endif | 210 #endif |
205 | 211 |
206 | 212 |
207 | 213 |
214 /* -- Runtime ------------------------------------------------------- */ | |
215 | |
216 #if defined(__MSVCRT__) | |
217 # define DC__RT_MSVCRT | |
218 #endif | |
219 | |
220 | |
208 /* -- Rough OS classification --------------------------------------- */ | 221 /* -- Rough OS classification --------------------------------------- */ |
209 | 222 |
210 #if defined(DC__OS_Win32) || defined(DC__OS_Win64) | 223 #if defined(DC__OS_Win32) || defined(DC__OS_Win64) |
211 # define DC_WINDOWS | 224 # define DC_WINDOWS |
212 #elif defined(DC__OS_Plan9) | 225 #elif defined(DC__OS_Plan9) |
228 #endif | 241 #endif |
229 | 242 |
230 #if defined(DC__Arch_ARM_ARM) || defined(DC__Arch_ARM_THUMB) | 243 #if defined(DC__Arch_ARM_ARM) || defined(DC__Arch_ARM_THUMB) |
231 # if defined(__ARM_EABI__) || defined(DC__OS_NDS) | 244 # if defined(__ARM_EABI__) || defined(DC__OS_NDS) |
232 # if defined (__ARM_PCS_VFP) && (__ARM_PCS_VFP == 1) | 245 # if defined (__ARM_PCS_VFP) && (__ARM_PCS_VFP == 1) |
233 # define DC__ABI_ARM_HF | 246 # define DC__ABI_ARM_HF |
234 # else | 247 # else |
235 # define DC__ABI_ARM_EABI | 248 # define DC__ABI_ARM_EABI |
236 # endif | 249 # endif |
237 # elif defined(__APCS_32__) | 250 # elif defined(__APCS_32__) |
238 # define DC__ABI_ARM_OABI | 251 # define DC__ABI_ARM_OABI |
239 # endif | 252 # endif |
240 #endif /* ARM */ | 253 #endif /* ARM */ |
283 # if (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 1)) || defined(MIPSEB) || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || defined(__ARMEB__) || defined(__AARCH64EB__) | 296 # if (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 1)) || defined(MIPSEB) || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || defined(__ARMEB__) || defined(__AARCH64EB__) |
284 # define DC__Endian_BIG | 297 # define DC__Endian_BIG |
285 # elif (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 2)) || defined(MIPSEL) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__ARMEL__) || defined(__AARCH64EL__) | 298 # elif (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 2)) || defined(MIPSEL) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__ARMEL__) || defined(__AARCH64EL__) |
286 # define DC__Endian_LITTLE | 299 # define DC__Endian_LITTLE |
287 # elif defined(DC__Arch_Sparc64) && !defined(__BYTE_ORDER__) /* Sparc64 default is big-endian, except if explicitly defined */ | 300 # elif defined(DC__Arch_Sparc64) && !defined(__BYTE_ORDER__) /* Sparc64 default is big-endian, except if explicitly defined */ |
288 # define DC__Endian_BIG | 301 # define DC__Endian_BIG |
289 # elif defined(BYTE_ORDER) || defined(_BYTE_ORDER) || defined(__BYTE_ORDER__) /* explicitly set byte order, either through compiler or platform specific endian.h */ | 302 # elif defined(BYTE_ORDER) || defined(_BYTE_ORDER) || defined(__BYTE_ORDER__) /* explicitly set byte order, either through compiler or platform specific endian.h */ |
290 # if (defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || (defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN)) || (defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) | 303 # if (defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || (defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN)) || (defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) |
291 # define DC__Endian_BIG | 304 # define DC__Endian_BIG |
292 # elif (defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) || (defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN)) || (defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) | 305 # elif (defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) || (defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN)) || (defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) |
293 # define DC__Endian_LITTLE | 306 # define DC__Endian_LITTLE |
294 # endif | 307 # endif |
295 # elif (defined(_BIG_ENDIAN) && (_BIG_ENDIAN == 1)) || (defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ == 1)) /* explicitly set as on/off */ | 308 # elif (defined(_BIG_ENDIAN) && (_BIG_ENDIAN == 1)) || (defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ == 1)) /* explicitly set as on/off */ |
296 # define DC__Endian_BIG | 309 # define DC__Endian_BIG |
297 # elif (defined(_LITTLE_ENDIAN) && (_LITTLE_ENDIAN == 1)) || (defined(__LITTLE_ENDIAN__) && (__LITTLE_ENDIAN__ == 1)) /* explicitly set as on/off */ | 310 # elif (defined(_LITTLE_ENDIAN) && (_LITTLE_ENDIAN == 1)) || (defined(__LITTLE_ENDIAN__) && (__LITTLE_ENDIAN__ == 1)) /* explicitly set as on/off */ |
298 # define DC__Endian_LITTLE | 311 # define DC__Endian_LITTLE |
315 call and callback support are required for a platform implementation */ | 328 call and callback support are required for a platform implementation */ |
316 | 329 |
317 /* syscalls */ | 330 /* syscalls */ |
318 #if (defined(DC__Arch_Intel_x86) || (defined(DC__Arch_AMD64) && defined(DC_UNIX)) || defined(DC__Arch_PPC32) || defined(DC__Arch_PPC64)) && \ | 331 #if (defined(DC__Arch_Intel_x86) || (defined(DC__Arch_AMD64) && defined(DC_UNIX)) || defined(DC__Arch_PPC32) || defined(DC__Arch_PPC64)) && \ |
319 !defined(DC__OS_MacOSX) && !defined(DC__OS_Plan9) && !defined(DC__OS_NDS) && !defined(DC__OS_PSP) && !defined(DC__OS_Minix) && !defined(DC__OS_SunOS) && !defined(DC__OS_BeOS) | 332 !defined(DC__OS_MacOSX) && !defined(DC__OS_Plan9) && !defined(DC__OS_NDS) && !defined(DC__OS_PSP) && !defined(DC__OS_Minix) && !defined(DC__OS_SunOS) && !defined(DC__OS_BeOS) |
320 # define DC__Feature_Syscall | 333 # define DC__Feature_Syscall |
321 #endif | 334 #endif |
322 | 335 |
323 /* aggregate (struct, union) by value */ | 336 /* aggregate (struct, union) by value */ |
324 #if defined(DC__Arch_AMD64) | 337 #if defined(DC__Arch_AMD64) |
325 # define DC__Feature_AggrByVal | 338 # define DC__Feature_AggrByVal |
326 #endif | 339 #endif |
327 | 340 |
328 | 341 |
329 #endif /* DYNCALL_MACROS_H */ | 342 #endif /* DYNCALL_MACROS_H */ |
330 | 343 |