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