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