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