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