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