FreeRDP
Loading...
Searching...
No Matches
platform.h
1
20#ifndef WINPR_PLATFORM_H
21#define WINPR_PLATFORM_H
22
23#include <stdlib.h>
24
25/* MSVC only defines _Pragma if you compile with /std:c11 with no extensions
26 * see
27 * https://learn.microsoft.com/en-us/cpp/preprocessor/pragma-directives-and-the-pragma-keyword?view=msvc-170#the-pragma-preprocessing-operator
28 */
29#if !defined(_MSC_VER)
30#define WINPR_DO_PRAGMA(x) _Pragma(#x)
31#else
32#define WINPR_DO_PRAGMA(x) __pragma(#x)
33#endif
34
35/* COVERITY_BUILD must be defined by build system */
36#if !defined(COVERITY_BUILD)
37#define WINPR_DO_COVERITY_PRAGMA(x)
38#else
39#define WINPR_DO_COVERITY_PRAGMA(x) WINPR_DO_PRAGMA(x)
40#endif
41
42#if defined(__GNUC__)
43#define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(GCC warning #msg)
44#elif defined(__clang__)
45#define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(GCC warning #msg)
46#elif defined(_MSC_VER) && (_MSC_VER >= 1920)
47#define WINPR_PRAGMA_WARNING(msg) WINPR_DO_PRAGMA(message \x28 #msg \x29)
48#else
49#define WINPR_PRAGMA_WARNING(msg)
50#endif
51
52// C99 related macros
53#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
54#define WINPR_RESTRICT restrict
55#elif defined(_MSC_VER) && _MSC_VER >= 1900
56#define WINPR_RESTRICT __restrict
57#else
58#define WINPR_RESTRICT
59#endif
60
61// C23 related macros
62#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
63#define WINPR_FALLTHROUGH \
64 (void)0; \
65 [[fallthrough]];
66#elif defined(__clang__)
67#define WINPR_FALLTHROUGH \
68 (void)0; \
69 __attribute__((fallthrough));
70#elif defined(__GNUC__) && (__GNUC__ >= 7)
71#define WINPR_FALLTHROUGH \
72 (void)0; \
73 __attribute__((fallthrough));
74#else
75#define WINPR_FALLTHROUGH (void)0;
76#endif
77
78#if defined(__clang__)
79#define WINPR_PRAGMA_DIAG_PUSH WINPR_DO_PRAGMA(clang diagnostic push)
80#define WINPR_PRAGMA_DIAG_IGNORED_OVERLENGTH_STRINGS \
81 WINPR_DO_PRAGMA(clang diagnostic ignored "-Woverlength-strings")
82#define WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS
83/* unsupported by clang WINPR_DO_PRAGMA(clang diagnostic ignored "-Wdiscarded-qualifiers") */
84#define WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC WINPR_DO_PRAGMA(clang diagnostic ignored "-Wpedantic")
85#define WINPR_PRAGMA_DIAG_IGNORED_MISSING_PROTOTYPES \
86 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wmissing-prototypes")
87#define WINPR_PRAGMA_DIAG_IGNORED_STRICT_PROTOTYPES \
88 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wstrict-prototypes")
89#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO \
90 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wreserved-id-macro")
91#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_MACRO \
92 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wunused-macros")
93#define WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
94 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wunknown-pragmas")
95#define WINPR_PRAGMA_DIAG_IGNORED_DEPRECATED_DECL \
96 WINPR_DO_PRAGMA(clang diagnostic ignored \
97 "-Wdeprecated-declarations")
99#if __clang_major__ >= 13
100#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER \
101 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wreserved-identifier")
102#else
103#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
104#endif
105
106#define WINPR_PRAGMA_DIAG_IGNORED_ATOMIC_SEQ_CST \
107 WINPR_DO_PRAGMA(clang diagnostic ignored "-Watomic-implicit-seq-cst")
108#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR \
109 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wunused-const-variable")
110#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \
111 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wformat-security")
112#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
113 WINPR_DO_PRAGMA(clang diagnostic ignored \
114 "-Wtautological-constant-out-of-range-compare")
118#if __clang_major__ >= 12
119#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
120 WINPR_DO_PRAGMA(clang diagnostic ignored \
121 "-Wtautological-value-range-compare")
123#else
124#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE
125#endif
126
127#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \
128 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wformat-nonliteral")
129#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC /* not supported \
130 WINPR_DO_PRAGMA(clang diagnostic ignored "-Wmismatched-dealloc") */
131#define WINPR_PRAGMA_DIAG_POP WINPR_DO_PRAGMA(clang diagnostic pop)
132#define WINPR_PRAGMA_UNROLL_LOOP \
133 _Pragma("clang loop vectorize_width(8) interleave_count(8)")
135#elif defined(__GNUC__)
136#define WINPR_PRAGMA_DIAG_PUSH WINPR_DO_PRAGMA(GCC diagnostic push)
137#define WINPR_PRAGMA_DIAG_IGNORED_OVERLENGTH_STRINGS \
138 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Woverlength-strings")
139#define WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS \
140 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wdiscarded-qualifiers")
141#define WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wpedantic")
142#define WINPR_PRAGMA_DIAG_IGNORED_MISSING_PROTOTYPES \
143 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wmissing-prototypes")
144#define WINPR_PRAGMA_DIAG_IGNORED_STRICT_PROTOTYPES \
145 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wstrict-prototypes")
146#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO /* not supported WINPR_DO_PRAGMA(GCC \
147 diagnostic ignored "-Wreserved-id-macro") \
148 */
149#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_MACRO \
150 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wunused-macros")
151#define WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
152 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas")
153#define WINPR_PRAGMA_DIAG_IGNORED_DEPRECATED_DECL \
154 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
157#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
158/* not supported WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wreserved-identifier") */
159#define WINPR_PRAGMA_DIAG_IGNORED_ATOMIC_SEQ_CST /* not supported WINPR_DO_PRAGMA(GCC diagnostic \
160 ignored \
161 "-Watomic-implicit-seq-cst") */
162#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR \
163 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wunused-const-variable")
164#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \
165 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wformat-security")
166#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE /* not supported
167 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare") */
168#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE /* not supported
169 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wtautological-value-range-compare") */
170#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \
171 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
172#if __GNUC__ >= 11
173#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC \
174 WINPR_DO_PRAGMA(GCC diagnostic ignored "-Wmismatched-dealloc")
175#else
176#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
177#endif
178#define WINPR_PRAGMA_DIAG_POP WINPR_DO_PRAGMA(GCC diagnostic pop)
179#define WINPR_PRAGMA_UNROLL_LOOP \
180 WINPR_DO_PRAGMA(GCC unroll 8) WINPR_DO_PRAGMA(GCC ivdep)
181#else
182#define WINPR_PRAGMA_DIAG_PUSH
183#define WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC
184#define WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS
185#define WINPR_PRAGMA_DIAG_IGNORED_OVERLENGTH_STRINGS
186#define WINPR_PRAGMA_DIAG_IGNORED_MISSING_PROTOTYPES
187#define WINPR_PRAGMA_DIAG_IGNORED_STRICT_PROTOTYPES
188#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
189#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_MACRO
190#define WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS
191#define WINPR_PRAGMA_DIAG_IGNORED_DEPRECATED_DECL
192#define WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
193#define WINPR_PRAGMA_DIAG_IGNORED_ATOMIC_SEQ_CST
194#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR
195#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY
196#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE
197#define WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE
198#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
199#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
200#define WINPR_PRAGMA_DIAG_POP
201#define WINPR_PRAGMA_UNROLL_LOOP
202#endif
203
204#if defined(MSVC)
205#undef WINPR_PRAGMA_UNROLL_LOOP
206#define WINPR_PRAGMA_UNROLL_LOOP WINPR_DO_PRAGMA(loop(ivdep))
207#endif
208
209WINPR_PRAGMA_DIAG_PUSH
210
211WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
212
213/*
214 * Processor Architectures:
215 * http://sourceforge.net/p/predef/wiki/Architectures/
216 *
217 * Visual Studio Predefined Macros:
218 * http://msdn.microsoft.com/en-ca/library/vstudio/b0084kay.aspx
219 */
220
221/* Intel x86 (_M_IX86) */
222
223#if defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || \
224 defined(__i586__) || defined(__i686__) || defined(__X86__) || defined(_X86_) || \
225 defined(__I86__) || defined(__IA32__) || defined(__THW_INTEL__) || defined(__INTEL__) || \
226 defined(_M_IX86)
227#ifndef _M_IX86
228#define _M_IX86 1
229#endif
230#endif
231
232/* AMD64 (_M_AMD64) */
233
234#if defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \
235 defined(_M_X64)
236#ifndef _M_AMD64
237// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
238#define _M_AMD64 1
239#endif
240#endif
241
242/* Intel ia64 */
243#if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
244#ifndef _M_IA64
245// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
246#define _M_IA64 1
247#endif
248#endif
249
250/* Intel x86 or AMD64 (_M_IX86_AMD64) */
251
252#if defined(_M_IX86) || defined(_M_AMD64)
253#ifndef _M_IX86_AMD64
254// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
255#define _M_IX86_AMD64 1
256#endif
257#endif
258
259/* ARM (_M_ARM) */
260
261#if defined(__arm__) || defined(__thumb__) || defined(__TARGET_ARCH_ARM) || \
262 defined(__TARGET_ARCH_THUMB)
263#ifndef _M_ARM
264// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
265#define _M_ARM 1
266#endif
267#endif
268
269/* ARM64 (_M_ARM64) */
270
271#if defined(__aarch64__)
272#ifndef _M_ARM64
273#define _M_ARM64 1
274#endif
275#endif
276
277/* MIPS (_M_MIPS) */
278
279#if defined(mips) || defined(__mips) || defined(__mips__) || defined(__MIPS__)
280#ifndef _M_MIPS
281// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
282#define _M_MIPS 1
283#endif
284#endif
285
286/* MIPS64 (_M_MIPS64) */
287
288#if defined(mips64) || defined(__mips64) || defined(__mips64__) || defined(__MIPS64__)
289#ifndef _M_MIPS64
290// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
291#define _M_MIPS64 1
292#endif
293#endif
294
295/* PowerPC (_M_PPC) */
296
297#if defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || \
298 defined(_ARCH_PPC)
299#ifndef _M_PPC
300// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
301#define _M_PPC 1
302#endif
303#endif
304
305/* Intel Itanium (_M_IA64) */
306
307#if defined(__ia64) || defined(__ia64__) || defined(_IA64) || defined(__IA64__)
308#ifndef _M_IA64
309// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
310#define _M_IA64 1
311#endif
312#endif
313
314/* Alpha (_M_ALPHA) */
315
316#if defined(__alpha) || defined(__alpha__)
317#ifndef _M_ALPHA
318// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
319#define _M_ALPHA 1
320#endif
321#endif
322
323/* SPARC (_M_SPARC) */
324
325#if defined(__sparc) || defined(__sparc__)
326#ifndef _M_SPARC
327// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
328#define _M_SPARC 1
329#endif
330#endif
331
332/* E2K (_M_E2K) */
333
334#if defined(__e2k__)
335#ifndef _M_E2K
336// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
337#define _M_E2K 1
338#endif
339#endif
340
346/* Windows (_WIN32) */
347
348/* WinRT (_WINRT) */
349
350#if defined(WINAPI_FAMILY)
351#if (WINAPI_FAMILY == WINAPI_FAMILY_APP)
352#ifndef _WINRT
353// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
354#define _WINRT 1
355#endif
356#endif
357#endif
358
359#if defined(__cplusplus_winrt)
360#ifndef _WINRT
361// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
362#define _WINRT 1
363#endif
364#endif
365
366/* Linux (__linux__) */
367
368#if defined(linux) || defined(__linux)
369#ifndef __linux__
370#define __linux__ 1
371#endif
372#endif
373
374/* GNU/Linux (__gnu_linux__) */
375
376/* Apple Platforms (iOS, Mac OS X) */
377
378#if (defined(__APPLE__) && defined(__MACH__))
379
380#include <TargetConditionals.h>
381
382#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
383
384/* iOS (__IOS__) */
385
386#ifndef __IOS__
387// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
388#define __IOS__ 1
389#endif
390
391#elif (TARGET_OS_MAC == 1)
392
393/* Mac OS X (__MACOSX__) */
394
395#ifndef __MACOSX__
396// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
397#define __MACOSX__ 1
398#endif
399
400#endif
401#endif
402
403/* Android (__ANDROID__) */
404
405/* Cygwin (__CYGWIN__) */
406
407/* FreeBSD (__FreeBSD__) */
408
409/* NetBSD (__NetBSD__) */
410
411/* OpenBSD (__OpenBSD__) */
412
413/* DragonFly (__DragonFly__) */
414
415/* Solaris (__sun) */
416
417#if defined(sun)
418#ifndef __sun
419// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
420#define __sun 1
421#endif
422#endif
423
424/* IRIX (__sgi) */
425
426#if defined(sgi)
427#ifndef __sgi
428// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
429#define __sgi 1
430#endif
431#endif
432
433/* AIX (_AIX) */
434
435#if defined(__TOS_AIX__)
436#ifndef _AIX
437// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
438#define _AIX 1
439#endif
440#endif
441
442/* HP-UX (__hpux) */
443
444#if defined(hpux) || defined(_hpux)
445#ifndef __hpux
446// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
447#define __hpux 1
448#endif
449#endif
450
451/* BeOS (__BEOS__) */
452
453/* QNX (__QNXNTO__) */
454
460#if defined(__gnu_linux__)
461#include <endian.h>
462#endif
463
464#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
465 defined(__DragonFly__) || defined(__APPLE__)
466#include <sys/param.h>
467#endif
468
469/* Big-Endian */
470
471#ifdef __BYTE_ORDER
472
473#if (__BYTE_ORDER == __BIG_ENDIAN)
474#ifndef __BIG_ENDIAN__
475// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
476#define __BIG_ENDIAN__ 1
477#endif
478#endif
479
480#else
481
482#if defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIPSEB) || \
483 defined(__MIPSEB) || defined(__MIPSEB__)
484#ifndef __BIG_ENDIAN__
485// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
486#define __BIG_ENDIAN__ 1
487#endif
488#endif
489
490#endif /* __BYTE_ORDER */
491
492/* Little-Endian */
493
494#ifdef __BYTE_ORDER
495
496#if (__BYTE_ORDER == __LITTLE_ENDIAN)
497#ifndef __LITTLE_ENDIAN__
498// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
499#define __LITTLE_ENDIAN__ 1
500#endif
501#endif
502
503#else
504
505#if defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || \
506 defined(__MIPSEL) || defined(__MIPSEL__) || defined(__e2k__)
507#ifndef __LITTLE_ENDIAN__
508// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
509#define __LITTLE_ENDIAN__ 1
510#endif
511#endif
512
513#endif /* __BYTE_ORDER */
514
515WINPR_PRAGMA_DIAG_POP
516
517#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
518#define WINPR_DEPRECATED(obj) [[deprecated]] obj
519#define WINPR_DEPRECATED_VAR(text, obj) [[deprecated(text)]] obj
520#define WINPR_NORETURN(obj) [[noreturn]] obj
521#elif defined(WIN32) && !defined(__CYGWIN__)
522#define WINPR_DEPRECATED(obj) __declspec(deprecated) obj
523#define WINPR_DEPRECATED_VAR(text, obj) __declspec(deprecated(text)) obj
524#define WINPR_NORETURN(obj) __declspec(noreturn) obj
525#elif defined(__GNUC__)
526#define WINPR_DEPRECATED(obj) obj __attribute__((deprecated))
527#define WINPR_DEPRECATED_VAR(text, obj) obj __attribute__((deprecated(text)))
528#define WINPR_NORETURN(obj) __attribute__((__noreturn__)) obj
529#else
530#define WINPR_DEPRECATED(obj) obj
531#define WINPR_DEPRECATED_VAR(text, obj) obj
532#define WINPR_NORETURN(obj) obj
533#endif
534
535#ifdef _WIN32
536#define INLINE __inline
537#else
538#define INLINE inline
539#endif
540
541#ifdef WINPR_DLL
542#if defined _WIN32 || defined __CYGWIN__
543#ifdef WINPR_EXPORTS
544#ifdef __GNUC__
545#define WINPR_API __attribute__((dllexport))
546#else
547#define WINPR_API __declspec(dllexport)
548#endif
549#else
550#ifdef __GNUC__
551#define WINPR_API __attribute__((dllimport))
552#else
553#define WINPR_API __declspec(dllimport)
554#endif
555#endif
556#else
557#if defined(__GNUC__) && (__GNUC__ >= 4)
558#define WINPR_API __attribute__((visibility("default")))
559#else
560#define WINPR_API
561#endif
562#endif
563#else /* WINPR_DLL */
564#define WINPR_API
565#endif
566
567#if defined(__clang__) || defined(__GNUC__) && (__GNUC__ <= 10)
568#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
569 __attribute__((malloc, warn_unused_result))
570#elif defined(__GNUC__)
571#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
572 __attribute__((malloc(deallocator, ptrindex), warn_unused_result))
573#else
574#define WINPR_ATTR_MALLOC(deallocator, ptrindex) __declspec(restrict)
575#endif
576
577#if defined(__GNUC__) || defined(__clang__)
578#define WINPR_ATTR_FORMAT_ARG(pos, args) __attribute__((__format__(__printf__, pos, args)))
579#define WINPR_FORMAT_ARG
580#else
581#define WINPR_ATTR_FORMAT_ARG(pos, args)
582#define WINPR_FORMAT_ARG _Printf_format_string_
583#endif
584
585#if defined(EXPORT_ALL_SYMBOLS)
586#define WINPR_LOCAL WINPR_API
587#else
588#if defined _WIN32 || defined __CYGWIN__
589#define WINPR_LOCAL
590#else
591#if defined(__GNUC__) && (__GNUC__ >= 4)
592#define WINPR_LOCAL __attribute__((visibility("hidden")))
593#else
594#define WINPR_LOCAL
595#endif
596#endif
597#endif
598
599// WARNING: *do not* use thread-local storage for new code because it is not portable
600// It is only used for VirtualChannelInit, and all FreeRDP channels use VirtualChannelInitEx
601// The old virtual channel API is only realistically used on Windows where TLS is available
602#if defined _WIN32 || defined __CYGWIN__
603#ifdef __GNUC__
604#define WINPR_TLS __thread
605#else
606#define WINPR_TLS __declspec(thread)
607#endif
608#elif !defined(__IOS__)
609#define WINPR_TLS __thread
610#else
611// thread-local storage is not supported on iOS
612// don't warn because it isn't actually used on iOS
613#define WINPR_TLS
614#endif
615
616#if defined(__GNUC__) || defined(__clang__)
617#define WINPR_ALIGN64 __attribute__((aligned(8)))
618#else
619#ifdef _WIN32
620#define WINPR_ALIGN64 __declspec(align(8))
621#else
622#define WINPR_ALIGN64
623#endif
624#endif
625
626#if defined(__cplusplus) && (__cplusplus >= 201703L)
627#define WINPR_ATTR_UNUSED [[maybe_unused]]
628#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202000L)
629#define WINPR_ATTR_UNUSED [[maybe_unused]]
630#elif defined(__GNUC__) || defined(__clang__)
631#define WINPR_ATTR_UNUSED __attribute__((unused))
632#else
633#define WINPR_ATTR_UNUSED
634#endif
635
636#define WINPR_UNUSED(x) (void)(x)
637
638#endif /* WINPR_PLATFORM_H */