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/* s390x (_M_S390X) */
386
387#if defined(__s390x__)
388#ifndef _M_S390X
389// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
390#define _M_S390X 1
391#endif
392#endif
393
394/* E2K (_M_E2K) */
395
396#if defined(__e2k__)
397#ifndef _M_E2K
398// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
399#define _M_E2K 1
400#endif
401#endif
402
403/* RISCV64 (_M_RISCV64) */
404
405#if defined(__riscv)
406#if defined(__riscv_xlen)
407#if __riscv_xlen == 64
408#ifndef _M_RISCV64
409// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
410#define _M_RISCV64 1
411#endif
412#elif __riscv_xlen == 32
413#ifndef _M_RISCV32
414// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
415#define _M_RISCV32 1
416#endif
417#else
418#error "Unknown/unsupported RISCV xlen value"
419#endif
420#endif
421#endif
422
428/* Windows (_WIN32) */
429
430/* WinRT (_WINRT) */
431
432#if defined(WINAPI_FAMILY)
433#if (WINAPI_FAMILY == WINAPI_FAMILY_APP)
434#ifndef _WINRT
435// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
436#define _WINRT 1
437#endif
438#endif
439#endif
440
441#if defined(__cplusplus_winrt)
442#ifndef _WINRT
443// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
444#define _WINRT 1
445#endif
446#endif
447
448/* Linux (__linux__) */
449
450#if defined(linux) || defined(__linux)
451#ifndef __linux__
452#define __linux__ 1
453#endif
454#endif
455
456/* GNU/Linux (__gnu_linux__) */
457
458/* Apple Platforms (iOS, Mac OS X) */
459
460#if (defined(__APPLE__) && defined(__MACH__))
461
462#include <TargetConditionals.h>
463
464#if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1)
465
466/* iOS (__IOS__) */
467
468#ifndef __IOS__
469// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
470#define __IOS__ 1
471#endif
472
473#elif (TARGET_OS_MAC == 1)
474
475/* Mac OS X (__MACOSX__) */
476
477#ifndef __MACOSX__
478// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
479#define __MACOSX__ 1
480#endif
481
482#endif
483#endif
484
485/* Android (__ANDROID__) */
486
487/* Cygwin (__CYGWIN__) */
488
489/* FreeBSD (__FreeBSD__) */
490
491/* NetBSD (__NetBSD__) */
492
493/* OpenBSD (__OpenBSD__) */
494
495/* DragonFly (__DragonFly__) */
496
497/* Solaris (__sun) */
498
499#if defined(sun)
500#ifndef __sun
501// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
502#define __sun 1
503#endif
504#endif
505
506/* IRIX (__sgi) */
507
508#if defined(sgi)
509#ifndef __sgi
510// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
511#define __sgi 1
512#endif
513#endif
514
515/* AIX (_AIX) */
516
517#if defined(__TOS_AIX__)
518#ifndef _AIX
519// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
520#define _AIX 1
521#endif
522#endif
523
524/* HP-UX (__hpux) */
525
526#if defined(hpux) || defined(_hpux)
527#ifndef __hpux
528// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
529#define __hpux 1
530#endif
531#endif
532
533/* BeOS (__BEOS__) */
534
535/* QNX (__QNXNTO__) */
536
542#if defined(__gnu_linux__)
543#include <endian.h>
544#endif
545
546#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
547 defined(__DragonFly__) || defined(__APPLE__)
548#include <sys/param.h>
549#endif
550
551/* Big-Endian */
552
553#ifdef __BYTE_ORDER
554
555#if (__BYTE_ORDER == __BIG_ENDIAN)
556#ifndef __BIG_ENDIAN__
557// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
558#define __BIG_ENDIAN__ 1
559#endif
560#endif
561
562#else
563
564#if defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIPSEB) || \
565 defined(__MIPSEB) || defined(__MIPSEB__)
566#ifndef __BIG_ENDIAN__
567// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
568#define __BIG_ENDIAN__ 1
569#endif
570#endif
571
572#endif /* __BYTE_ORDER */
573
574/* Little-Endian */
575
576#ifdef __BYTE_ORDER
577
578#if (__BYTE_ORDER == __LITTLE_ENDIAN)
579#ifndef __LITTLE_ENDIAN__
580// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
581#define __LITTLE_ENDIAN__ 1
582#endif
583#endif
584
585#else
586
587#if defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || \
588 defined(__MIPSEL) || defined(__MIPSEL__) || defined(__e2k__)
589#ifndef __LITTLE_ENDIAN__
590// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
591#define __LITTLE_ENDIAN__ 1
592#endif
593#endif
594
595#endif /* __BYTE_ORDER */
596
597WINPR_PRAGMA_DIAG_POP
598
599#if defined(__cplusplus) && (__cplusplus >= 201703L)
600#define WINPR_DEPRECATED(obj) [[deprecated]] obj
601#define WINPR_DEPRECATED_VAR(text, obj) [[deprecated("[deprecated] " text)]] obj
602#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
603#define WINPR_DEPRECATED(obj) [[deprecated]] obj
604#define WINPR_DEPRECATED_VAR(text, obj) [[deprecated("[deprecated] " text)]] obj
605#elif defined(__GNUC__)
606#define WINPR_DEPRECATED(obj) obj __attribute__((deprecated))
607#define WINPR_DEPRECATED_VAR(text, obj) obj __attribute__((deprecated("[deprecated] " text)))
608#else
609#define WINPR_DEPRECATED(obj) obj
610#define WINPR_DEPRECATED_VAR(text, obj) obj
611#endif
612
613#if defined(__cplusplus) && (__cplusplus >= 201703L)
614#define WINPR_DECLSPEC_NORETURN [[noreturn]]
615#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
616#define WINPR_DECLSPEC_NORETURN [[noreturn]]
617#elif defined(WIN32) && !defined(__CYGWIN__)
618#define WINPR_DECLSPEC_NORETURN __declspec(noreturn)
619#elif defined(__GNUC__)
620#define WINPR_DECLSPEC_NORETURN __attribute__((__noreturn__))
621#else
622#define WINPR_DECLSPEC_NORETURN
623#endif
624
625#define WINPR_NORETURN(obj) WINPR_DECLSPEC_NORETURN obj
626
627#define INLINE inline
628
629#ifdef WINPR_DLL
630#if defined _WIN32 || defined __CYGWIN__
631#ifdef WINPR_EXPORTS
632#ifdef __GNUC__
633#define WINPR_API __attribute__((dllexport))
634#else
635#define WINPR_API __declspec(dllexport)
636#endif
637#else
638#ifdef __GNUC__
639#define WINPR_API __attribute__((dllimport))
640#else
641#define WINPR_API __declspec(dllimport)
642#endif
643#endif
644#else
645#if defined(__GNUC__) && (__GNUC__ >= 4)
646#if defined(__cplusplus) && (__cplusplus >= 201703L)
647#define WINPR_API [[gnu::visibility("default")]]
648#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
649#define WINPR_API [[gnu::visibility("default")]]
650#else
651#define WINPR_API __attribute__((visibility("default")))
652#endif
653#else
654#define WINPR_API
655#endif
656#endif
657#else /* WINPR_DLL */
658#define WINPR_API
659#endif
660
661#if defined(__clang__)
662#if defined(__cplusplus) && (__cplusplus >= 201703L)
663#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
664 [[gnu::malloc, nodiscard]]
665#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
666#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
667 [[gnu::malloc, nodiscard]]
668#else
669#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
670 __attribute__((malloc, warn_unused_result))
671#endif
672#elif defined(__GNUC__)
673#if (__GNUC__ <= 10)
674#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
675 __attribute__((malloc, warn_unused_result))
676#else
677#if defined(__cplusplus) && (__cplusplus >= 201703L)
678#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
679 [[gnu::malloc(deallocator, ptrindex), nodiscard]]
680#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
681#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
682 [[gnu::malloc(deallocator, ptrindex), nodiscard]]
683#else
684#define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
685 __attribute__((malloc(deallocator, ptrindex), warn_unused_result))
686#endif
687#endif
688#elif defined(_MSC_VER)
689#define WINPR_ATTR_MALLOC(deallocator, ptrindex) __declspec(restrict)
690#endif
691
692#if defined(__GNUC__) || defined(__clang__)
693#if defined(__cplusplus) && (__cplusplus >= 201703L)
694#define WINPR_ATTR_FORMAT_ARG(pos, args) [[gnu::format(printf, pos, args)]]
695#define WINPR_FORMAT_ARG
696#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
697#define WINPR_ATTR_FORMAT_ARG(pos, args) [[gnu::format(printf, pos, args)]]
698#define WINPR_FORMAT_ARG
699#else
700#define WINPR_ATTR_FORMAT_ARG(pos, args) __attribute__((__format__(__printf__, pos, args)))
701#define WINPR_FORMAT_ARG
702#endif
703#elif defined(_MSC_VER)
704#define WINPR_ATTR_FORMAT_ARG(pos, args)
705#define WINPR_FORMAT_ARG _Printf_format_string_
706#endif
707
708#if defined(EXPORT_ALL_SYMBOLS)
709#define WINPR_LOCAL WINPR_API
710#elif defined _WIN32 || defined __CYGWIN__
711#define WINPR_LOCAL
712#elif defined(__GNUC__) && (__GNUC__ >= 4)
713#if defined(__cplusplus) && (__cplusplus >= 201703L)
714#define WINPR_LOCAL [[gnu::visibility("hidden")]]
715#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
716#define WINPR_LOCAL [[gnu::visibility("hidden")]]
717#else
718#define WINPR_LOCAL __attribute__((visibility("hidden")))
719#endif
720#else
721#define WINPR_LOCAL
722#endif
723
724// WARNING: *do not* use thread-local storage for new code because it is not portable
725// It is only used for VirtualChannelInit, and all FreeRDP channels use VirtualChannelInitEx
726// The old virtual channel API is only realistically used on Windows where TLS is available
727#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
728 !defined(__STDC_NO_THREADS__) // C11
729#include <threads.h>
730
731#define WINPR_TLS thread_local
732#elif defined _WIN32 || defined __CYGWIN__
733#ifdef __GNUC__
734#define WINPR_TLS __thread
735#else
736#define WINPR_TLS __declspec(thread)
737#endif
738#elif !defined(__IOS__)
739#define WINPR_TLS __thread
740#else
741// thread-local storage is not supported on iOS
742// don't warn because it isn't actually used on iOS
743#define WINPR_TLS
744#endif
745
746#define WINPR_ALIGN64 DECLSPEC_ALIGN(8)
747
748#if defined(__cplusplus) && (__cplusplus >= 201703L)
749#define WINPR_ATTR_UNUSED [[maybe_unused]]
750#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
751#define WINPR_ATTR_UNUSED [[maybe_unused]]
752#elif defined(__GNUC__) || defined(__clang__)
753#define WINPR_ATTR_UNUSED __attribute__((unused))
754#else
755#define WINPR_ATTR_UNUSED
756#endif
757
758#define WINPR_UNUSED(x) (void)(x)
759
760#endif /* WINPR_PLATFORM_H */