1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7 #ifndef _INC__MINGW_H
8 #define _INC__MINGW_H
9
10 #define MINGW_HAS_SECURE_API 1
11
12 #include "_mingw_mac.h"
13 #include "_mingw_secapi.h"
14
15 /* Include _cygwin.h if we're building a Cygwin application. */
16 #ifdef __CYGWIN__
17 #include "_cygwin.h"
18 #endif
19
20 /* Target specific macro replacement for type "long". In the Windows API,
21 the type long is always 32 bit, even if the target is 64 bit (LLP64).
22 On 64 bit Cygwin, the type long is 64 bit (LP64). So, to get the right
23 sized definitions and declarations, all usage of type long in the Windows
24 headers have to be replaced by the below defined macro __LONG32. */
25 #ifndef __LP64__ /* 32 bit target, 64 bit Mingw target */
26 #define __LONG32 long
27 #else /* 64 bit Cygwin target */
28 #define __LONG32 int
29 #endif
30
31 /* C/C++ specific language defines. */
32 #ifdef _WIN64
33 #ifdef __stdcall
34 #undef __stdcall
35 #endif
36 #define __stdcall
37 #endif
38
39 #ifndef __GNUC__
40 # ifndef __MINGW_IMPORT
41 # define __MINGW_IMPORT __declspec(dllimport)
42 # endif
43 # ifndef _CRTIMP
44 # define _CRTIMP __declspec(dllimport)
45 # endif
46 # define __DECLSPEC_SUPPORTED
47 # define __attribute__(x) /* nothing */
48 #else /* __GNUC__ */
49 # ifdef __declspec
50 # ifndef __MINGW_IMPORT
51 /* Note the extern. This is needed to work around GCC's
52 limitations in handling dllimport attribute. */
53 # define __MINGW_IMPORT extern __attribute__ ((__dllimport__))
54 # endif
55 # ifndef _CRTIMP
56 # undef __USE_CRTIMP
57 # if !defined (_CRTBLD) && !defined (_SYSCRT)
58 # define __USE_CRTIMP 1
59 # endif
60 # ifdef __USE_CRTIMP
61 # define _CRTIMP __attribute__ ((__dllimport__))
62 # else
63 # define _CRTIMP
64 # endif
65 # endif
66 # define __DECLSPEC_SUPPORTED
67 # else /* __declspec */
68 # undef __DECLSPEC_SUPPORTED
69 # undef __MINGW_IMPORT
70 # ifndef _CRTIMP
71 # define _CRTIMP
72 # endif
73 # endif /* __declspec */
74 #endif /* __GNUC__ */
75
76 #ifdef _MSC_VER
77 #define USE___UUIDOF 1
78 #else
79 #define USE___UUIDOF 0
80 #endif
81
82 #if !defined(_MSC_VER) && !defined(_inline)
83 #define _inline __inline
84 #endif
85
86 #ifdef __cplusplus
87 # define __CRT_INLINE inline
88 #elif defined(_MSC_VER)
89 # define __CRT_INLINE __inline
90 #else
91 # if ( __MINGW_GNUC_PREREQ(4, 3) && __STDC_VERSION__ >= 199901L) \
92 || (defined (__clang__))
93 # define __CRT_INLINE extern inline __attribute__((__gnu_inline__))
94 # else
95 # define __CRT_INLINE extern __inline__
96 # endif
97 #endif
98
99 #if !defined(__MINGW_INTRIN_INLINE) && defined(__GNUC__)
100 #define __MINGW_INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__))
101 #endif
102
103 #ifndef __CYGWIN__
104 #ifdef __NO_INLINE__
105 #undef __CRT__NO_INLINE
106 #define __CRT__NO_INLINE 1
107 #endif
108 #endif
109
110 #ifdef __cplusplus
111 # define __UNUSED_PARAM(x)
112 #else
113 # ifdef __GNUC__
114 # define __UNUSED_PARAM(x) x __attribute__ ((__unused__))
115 # else
116 # define __UNUSED_PARAM(x) x
117 # endif
118 #endif
119
120 #ifndef __GNUC__
121 # ifdef _MSC_VER
122 # define __restrict__ __restrict
123 # else
124 # define __restrict__ /* nothing */
125 # endif
126 #endif /* !__GNUC__ */
127
128 #if __MINGW_GNUC_PREREQ (3,1) && !defined __GNUG__
129 # define __restrict_arr __restrict
130 #elif defined(_MSC_VER)
131 # define __restrict_arr __restrict
132 #else
133 # ifdef __GNUC__
134 # define __restrict_arr /* Not supported in old GCC. */
135 # else
136 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
137 # define __restrict_arr restrict
138 # else
139 # define __restrict_arr /* Not supported. */
140 # endif
141 # endif
142 #endif
143
144 #ifdef __GNUC__
145 #define __MINGW_ATTRIB_NORETURN __attribute__ ((__noreturn__))
146 #define __MINGW_ATTRIB_CONST __attribute__ ((__const__))
147 #elif __MINGW_MSC_PREREQ(12, 0)
148 #define __MINGW_ATTRIB_NORETURN __declspec(noreturn)
149 #define __MINGW_ATTRIB_CONST
150 #else
151 #define __MINGW_ATTRIB_NORETURN
152 #define __MINGW_ATTRIB_CONST
153 #endif
154
155 #if __MINGW_GNUC_PREREQ (3, 0)
156 #define __MINGW_ATTRIB_MALLOC __attribute__ ((__malloc__))
157 #define __MINGW_ATTRIB_PURE __attribute__ ((__pure__))
158 #elif __MINGW_MSC_PREREQ(14, 0)
159 #define __MINGW_ATTRIB_MALLOC __declspec(noalias) __declspec(restrict)
160 #define __MINGW_ATTRIB_PURE
161 #else
162 #define __MINGW_ATTRIB_MALLOC
163 #define __MINGW_ATTRIB_PURE
164 #endif
165
166 /* Attribute `nonnull' was valid as of gcc 3.3. We don't use GCC's
167 variadiac macro facility, because variadic macros cause syntax
168 errors with --traditional-cpp. */
169 #if __MINGW_GNUC_PREREQ (3, 3)
170 #define __MINGW_ATTRIB_NONNULL(arg) __attribute__ ((__nonnull__ (arg)))
171 #else
172 #define __MINGW_ATTRIB_NONNULL(arg)
173 #endif /* GNUC >= 3.3 */
174
175 #ifdef __GNUC__
176 #define __MINGW_ATTRIB_UNUSED __attribute__ ((__unused__))
177 #else
178 #define __MINGW_ATTRIB_UNUSED
179 #endif /* ATTRIBUTE_UNUSED */
180
181 #if __MINGW_GNUC_PREREQ (3, 1)
182 #define __MINGW_ATTRIB_USED __attribute__ ((__used__))
183 #define __MINGW_ATTRIB_DEPRECATED __attribute__ ((__deprecated__))
184 #if __MINGW_GNUC_PREREQ (4, 5) || defined (__clang__)
185 #define __MINGW_ATTRIB_DEPRECATED_MSG(x) __attribute__ ((__deprecated__(x)))
186 #endif
187 #elif __MINGW_MSC_PREREQ(12, 0)
188 #define __MINGW_ATTRIB_USED
189 #define __MINGW_ATTRIB_DEPRECATED __declspec(deprecated)
190 #else
191 #define __MINGW_ATTRIB_USED __MINGW_ATTRIB_UNUSED
192 #define __MINGW_ATTRIB_DEPRECATED
193 #endif /* GNUC >= 3.1 */
194
195 #ifndef __MINGW_ATTRIB_DEPRECATED_MSG
196 #define __MINGW_ATTRIB_DEPRECATED_MSG(x) __MINGW_ATTRIB_DEPRECATED
197 #endif
198
199 #if __MINGW_GNUC_PREREQ (3, 3)
200 #define __MINGW_NOTHROW __attribute__ ((__nothrow__))
201 #elif __MINGW_MSC_PREREQ(12, 0) && defined (__cplusplus)
202 #define __MINGW_NOTHROW __declspec(nothrow)
203 #else
204 #define __MINGW_NOTHROW
205 #endif
206
207 #if __MINGW_GNUC_PREREQ (4, 4)
208 #define __MINGW_ATTRIB_NO_OPTIMIZE __attribute__((__optimize__ ("0")))
209 #else
210 #define __MINGW_ATTRIB_NO_OPTIMIZE
211 #endif
212
213 #if __MINGW_GNUC_PREREQ (4, 4)
214 #define __MINGW_PRAGMA_PARAM(x) _Pragma (#x)
215 #elif __MINGW_MSC_PREREQ (13, 1)
216 #define __MINGW_PRAGMA_PARAM(x) __pragma (x)
217 #else
218 #define __MINGW_PRAGMA_PARAM(x)
219 #endif
220
221 #define __MINGW_BROKEN_INTERFACE(x) \
222 __MINGW_PRAGMA_PARAM(message ("Interface " _CRT_STRINGIZE(x) \
223 " has unverified layout."))
224
225 #ifndef __MSVCRT_VERSION__
226 /* High byte is the major version, low byte is the minor. */
227 # define __MSVCRT_VERSION__ 0x1400
228 #endif
229
230
231 #ifndef _WIN32_WINNT
232 #define _WIN32_WINNT 0x502
233 #endif
234
235 #ifndef _INT128_DEFINED
236 #define _INT128_DEFINED
237 #ifdef __GNUC__
238 #define __int8 char
239 #define __int16 short
240 #define __int32 int
241 #define __int64 long long
242 #ifdef _WIN64
243 #if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) && \
244 !defined(__SIZEOF_INT128__) /* clang >= 3.1 has __int128 but no size macro */
245 #define __SIZEOF_INT128__ 16
246 #endif
247 #ifndef __SIZEOF_INT128__
248 typedef int __int128 __attribute__ ((__mode__ (TI)));
249 #endif
250 #endif
251 #endif /* __GNUC__ */
252 #endif /* _INT128_DEFINED */
253
254 #ifdef __GNUC__
255 #define __ptr32
256 #define __ptr64
257 #ifndef __unaligned
258 #define __unaligned
259 #endif
260 #ifndef __w64
261 #define __w64
262 #endif
263 #ifdef __cplusplus
264 #define __forceinline inline __attribute__((__always_inline__))
265 #else
266 #define __forceinline extern __inline__ __attribute__((__always_inline__,__gnu_inline__))
267 #endif /* __cplusplus */
268 #endif /* __GNUC__ */
269
270 #if !defined(_WIN32) && !defined(__CYGWIN__)
271 #error Only Win32 target is supported!
272 #endif
273
274 #ifndef __nothrow
275 #ifdef __cplusplus
276 #define __nothrow __MINGW_NOTHROW
277 #else
278 #define __nothrow
279 #endif
280 #endif /* __nothrow */
281
282 #include <vadefs.h> /* other headers depend on this include */
283
284 #ifndef _CRT_STRINGIZE
285 #define __CRT_STRINGIZE(_Value) #_Value
286 #define _CRT_STRINGIZE(_Value) __CRT_STRINGIZE(_Value)
287 #endif /* _CRT_STRINGIZE */
288
289 #ifndef _CRT_WIDE
290 #define __CRT_WIDE(_String) L ## _String
291 #define _CRT_WIDE(_String) __CRT_WIDE(_String)
292 #endif /* _CRT_WIDE */
293
294 #ifndef _W64
295 #define _W64
296 #endif
297
298 #ifndef _CRTIMP_NOIA64
299 #ifdef __ia64__
300 #define _CRTIMP_NOIA64
301 #else
302 #define _CRTIMP_NOIA64 _CRTIMP
303 #endif
304 #endif /* _CRTIMP_NOIA64 */
305
306 #ifndef _CRTIMP2
307 #define _CRTIMP2 _CRTIMP
308 #endif
309
310 #ifndef _CRTIMP_ALTERNATIVE
311 #define _CRTIMP_ALTERNATIVE _CRTIMP
312 #define _CRT_ALTERNATIVE_IMPORTED
313 #endif /* _CRTIMP_ALTERNATIVE */
314
315 #ifndef _MRTIMP2
316 #define _MRTIMP2 _CRTIMP
317 #endif
318
319 /* We have to define _DLL for gcc based mingw version. This define is set
320 by VC, when DLL-based runtime is used. So, gcc based runtime just have
321 DLL-base runtime, therefore this define has to be set.
322 As our headers are possibly used by windows compiler having a static
323 C-runtime, we make this definition gnu compiler specific here. */
324 #if !defined (_DLL) && defined (__GNUC__)
325 #define _DLL
326 #endif
327
328 #ifndef _MT
329 #define _MT
330 #endif
331
332 #ifndef _MCRTIMP
333 #define _MCRTIMP _CRTIMP
334 #endif
335
336 #ifndef _CRTIMP_PURE
337 #define _CRTIMP_PURE _CRTIMP
338 #endif
339
340 #ifndef _PGLOBAL
341 #define _PGLOBAL
342 #endif
343
344 #ifndef _AGLOBAL
345 #define _AGLOBAL
346 #endif
347
348 #define _SECURECRT_FILL_BUFFER_PATTERN 0xFD
349 #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated)
350
351 #ifndef _CRT_INSECURE_DEPRECATE_MEMORY
352 #define _CRT_INSECURE_DEPRECATE_MEMORY(_Replacement)
353 #endif
354
355 #ifndef _CRT_INSECURE_DEPRECATE_GLOBALS
356 #define _CRT_INSECURE_DEPRECATE_GLOBALS(_Replacement)
357 #endif
358
359 #ifndef _CRT_MANAGED_HEAP_DEPRECATE
360 #define _CRT_MANAGED_HEAP_DEPRECATE
361 #endif
362
363 #ifndef _CRT_OBSOLETE
364 #define _CRT_OBSOLETE(_NewItem)
365 #endif
366
367 #ifndef __WIDL__
368
369 #if defined (_WIN32) && !defined (_WIN64) && !defined (__MINGW_USE_VC2005_COMPAT)
370 #ifndef _USE_32BIT_TIME_T
371 #define _USE_32BIT_TIME_T
372 #endif
373 #endif
374
375 #ifndef _CONST_RETURN
376 #define _CONST_RETURN
377 #endif
378
379 #ifndef UNALIGNED
380 #if defined(_M_IA64) || defined(_M_AMD64)
381 #define UNALIGNED __unaligned
382 #else
383 #define UNALIGNED
384 #endif
385 #endif /* UNALIGNED */
386
387 #ifndef _CRT_ALIGN
388 #ifdef _MSC_VER
389 #define _CRT_ALIGN(x) __declspec(align(x))
390 #else /* __GNUC__ */
391 #define _CRT_ALIGN(x) __attribute__ ((__aligned__ (x)))
392 #endif
393 #endif /* _CRT_ALIGN */
394
395 #endif /* __WIDL__ */
396
397 #ifndef __CRTDECL
398 #define __CRTDECL __cdecl
399 #endif
400
401 #define _ARGMAX 100
402
403 #ifndef _TRUNCATE
404 #define _TRUNCATE ((size_t)-1)
405 #endif
406
407 #ifndef _CRT_UNUSED
408 #define _CRT_UNUSED(x) (void)x
409 #endif
410
411 /* MSVC defines _NATIVE_NULLPTR_SUPPORTED when nullptr is supported. We emulate it here for GCC. */
412 #if __MINGW_GNUC_PREREQ(4, 6)
413 #if defined(__GNUC__) && (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
414 #define _NATIVE_NULLPTR_SUPPORTED
415 #endif
416 #endif
417
418 /* We are activating __USE_MINGW_ANSI_STDIO for various define indicators.
419 Note that we enable it also for _GNU_SOURCE in C++, but not for C case. */
420 #if (defined (_POSIX) || defined (_POSIX_SOURCE) || defined (_POSIX_C_SOURCE) \
421 || defined (_ISOC99_SOURCE) \
422 || defined (_XOPEN_SOURCE) || defined (_XOPEN_SOURCE_EXTENDED) \
423 || (defined (_GNU_SOURCE) && defined (__cplusplus)) \
424 || defined (_SVID_SOURCE)) \
425 && !defined(__USE_MINGW_ANSI_STDIO)
426 /* Enable __USE_MINGW_ANSI_STDIO if _POSIX defined
427 * and If user did _not_ specify it explicitly... */
428 # define __USE_MINGW_ANSI_STDIO 1
429 #endif
430
431 /* We are defining __USE_MINGW_ANSI_STDIO as 0 or 1 */
432 #if !defined(__USE_MINGW_ANSI_STDIO)
433 #define __USE_MINGW_ANSI_STDIO 0 /* was not defined so it should be 0 */
434 #elif (__USE_MINGW_ANSI_STDIO + 0) != 0 || (1 - __USE_MINGW_ANSI_STDIO - 1) == 2
435 #define __USE_MINGW_ANSI_STDIO 1 /* was defined as nonzero or empty so it should be 1 */
436 #else
437 #define __USE_MINGW_ANSI_STDIO 0 /* was defined as (int)zero and non-empty so it should be 0 */
438 #endif
439
440 /* _dowildcard is an int that controls the globbing of the command line.
441 * The MinGW32 (mingw.org) runtime calls it _CRT_glob, so we are adding
442 * a compatibility definition here: you can use either of _CRT_glob or
443 * _dowildcard .
444 * If _dowildcard is non-zero, the command line will be globbed: *.*
445 * will be expanded to be all files in the startup directory.
446 * In the mingw-w64 library a _dowildcard variable is defined as being
447 * 0, therefore command line globbing is DISABLED by default. To turn it
448 * on and to leave wildcard command line processing MS's globbing code,
449 * include a line in one of your source modules defining _dowildcard and
450 * setting it to -1, like so:
451 * int _dowildcard = -1;
452 */
453 #undef _CRT_glob
454 #define _CRT_glob _dowildcard
455
456
457 #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
458 #define NONAMELESSUNION 1
459 #endif
460 #if defined(NONAMELESSSTRUCT) && \
461 !defined(NONAMELESSUNION)
462 #define NONAMELESSUNION 1
463 #endif
464 #if defined(NONAMELESSUNION) && \
465 !defined(NONAMELESSSTRUCT)
466 #define NONAMELESSSTRUCT 1
467 #endif
468
469 #ifndef __ANONYMOUS_DEFINED
470 #define __ANONYMOUS_DEFINED
471 #define _ANONYMOUS_UNION __MINGW_EXTENSION
472 #define _ANONYMOUS_STRUCT __MINGW_EXTENSION
473 #ifndef NONAMELESSUNION
474 #define _UNION_NAME(x)
475 #define _STRUCT_NAME(x)
476 #else /* NONAMELESSUNION */
477 #define _UNION_NAME(x) x
478 #define _STRUCT_NAME(x) x
479 #endif
480 #endif /* __ANONYMOUS_DEFINED */
481
482 #ifndef DUMMYUNIONNAME
483 # ifdef NONAMELESSUNION
484 # define DUMMYUNIONNAME u
485 # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */
486 # define DUMMYUNIONNAME2 u2
487 # define DUMMYUNIONNAME3 u3
488 # define DUMMYUNIONNAME4 u4
489 # define DUMMYUNIONNAME5 u5
490 # define DUMMYUNIONNAME6 u6
491 # define DUMMYUNIONNAME7 u7
492 # define DUMMYUNIONNAME8 u8
493 # define DUMMYUNIONNAME9 u9
494 # else /* NONAMELESSUNION */
495 # define DUMMYUNIONNAME
496 # define DUMMYUNIONNAME1 /* Wine uses this variant */
497 # define DUMMYUNIONNAME2
498 # define DUMMYUNIONNAME3
499 # define DUMMYUNIONNAME4
500 # define DUMMYUNIONNAME5
501 # define DUMMYUNIONNAME6
502 # define DUMMYUNIONNAME7
503 # define DUMMYUNIONNAME8
504 # define DUMMYUNIONNAME9
505 # endif
506 #endif /* DUMMYUNIONNAME */
507
508 #ifndef DUMMYSTRUCTNAME
509 # ifdef NONAMELESSUNION
510 # define DUMMYSTRUCTNAME s
511 # define DUMMYSTRUCTNAME1 s1 /* Wine uses this variant */
512 # define DUMMYSTRUCTNAME2 s2
513 # define DUMMYSTRUCTNAME3 s3
514 # define DUMMYSTRUCTNAME4 s4
515 # define DUMMYSTRUCTNAME5 s5
516 # else
517 # define DUMMYSTRUCTNAME
518 # define DUMMYSTRUCTNAME1 /* Wine uses this variant */
519 # define DUMMYSTRUCTNAME2
520 # define DUMMYSTRUCTNAME3
521 # define DUMMYSTRUCTNAME4
522 # define DUMMYSTRUCTNAME5
523 # endif
524 #endif /* DUMMYSTRUCTNAME */
525
526
527 /* Macros for __uuidof template-based emulation */
528 #if defined(__cplusplus) && (USE___UUIDOF == 0)
529
530 #if __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L
531 #define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
532 extern "C++" { \
533 template<> struct __mingw_uuidof_s<type> { \
534 static constexpr IID __uuid_inst = { \
535 l,w1,w2, {b1,b2,b3,b4,b5,b6,b7,b8} \
536 }; \
537 }; \
538 template<> constexpr const GUID &__mingw_uuidof<type>() { \
539 return __mingw_uuidof_s<type>::__uuid_inst; \
540 } \
541 template<> constexpr const GUID &__mingw_uuidof<type*>() { \
542 return __mingw_uuidof_s<type>::__uuid_inst; \
543 } \
544 }
545 #else
546 #define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
547 extern "C++" { \
548 template<> inline const GUID &__mingw_uuidof<type>() { \
549 static const IID __uuid_inst = {l,w1,w2, {b1,b2,b3,b4,b5,b6,b7,b8}}; \
550 return __uuid_inst; \
551 } \
552 template<> inline const GUID &__mingw_uuidof<type*>() { \
553 return __mingw_uuidof<type>(); \
554 } \
555 }
556 #endif
557
558 #define __uuidof(type) __mingw_uuidof<__typeof(type)>()
559
560 #else
561
562 #define __CRT_UUID_DECL(type,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
563
564 #endif
565
566 #ifdef __cplusplus
567 extern "C" {
568 #endif
569
570
571 #ifdef __MINGW_INTRIN_INLINE
572 #ifdef __has_builtin
573 #define __MINGW_DEBUGBREAK_IMPL !__has_builtin(__debugbreak)
574 #else
575 #define __MINGW_DEBUGBREAK_IMPL 1
576 #endif
577 #if __MINGW_DEBUGBREAK_IMPL == 1
578 void __cdecl __debugbreak(void);
__debugbreak(void)579 __MINGW_INTRIN_INLINE void __cdecl __debugbreak(void)
580 {
581 __asm__ __volatile__("int {$}3":);
582 }
583 #endif
584 #endif
585
586 /* mingw-w64 specific functions: */
587 const char *__mingw_get_crt_info (void);
588
589 #ifdef __cplusplus
590 }
591 #endif
592
593 #endif /* _INC__MINGW_H */
594
595 #ifndef MINGW_SDK_INIT
596 #define MINGW_SDK_INIT
597
598 #ifdef MINGW_HAS_SECURE_API
599 #define __STDC_SECURE_LIB__ 200411L
600 #define __GOT_SECURE_LIB__ __STDC_SECURE_LIB__
601 #endif
602
603 #ifndef __WIDL__
604 #include "sdks/_mingw_directx.h"
605 #include "sdks/_mingw_ddk.h"
606 #endif
607
608 #endif /* MINGW_SDK_INIT */
609