FreeRDP
winpr.h
1 
19 #ifndef WINPR_H
20 #define WINPR_H
21 
22 #include <winpr/platform.h>
23 
24 #ifdef WINPR_DLL
25 #if defined _WIN32 || defined __CYGWIN__
26 #ifdef WINPR_EXPORTS
27 #ifdef __GNUC__
28 #define WINPR_API __attribute__((dllexport))
29 #else
30 #define WINPR_API __declspec(dllexport)
31 #endif
32 #else
33 #ifdef __GNUC__
34 #define WINPR_API __attribute__((dllimport))
35 #else
36 #define WINPR_API __declspec(dllimport)
37 #endif
38 #endif
39 #else
40 #if defined(__GNUC__) && (__GNUC__ >= 4)
41 #define WINPR_API __attribute__((visibility("default")))
42 #else
43 #define WINPR_API
44 #endif
45 #endif
46 #else /* WINPR_DLL */
47 #define WINPR_API
48 #endif
49 
50 #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ <= 10)
51 #define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
52  __attribute__((malloc, warn_unused_result))
53 #elif defined(__GNUC__)
54 #define WINPR_ATTR_MALLOC(deallocator, ptrindex) \
55  __attribute__((malloc(deallocator, ptrindex), warn_unused_result))
56 #else
57 #define WINPR_ATTR_MALLOC(deallocator, ptrindex) __declspec(restrict)
58 #endif
59 
60 #if defined(__GNUC__) || defined(__clang__)
61 #define WINPR_ATTR_FORMAT_ARG(pos, args) __attribute__((__format__(__printf__, pos, args)))
62 #define WINPR_FORMAT_ARG
63 #else
64 #define WINPR_ATTR_FORMAT_ARG(pos, args)
65 #define WINPR_FORMAT_ARG _Printf_format_string_
66 #endif
67 
68 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
69 #define WINPR_DEPRECATED(obj) [[deprecated]] obj
70 #define WINPR_DEPRECATED_VAR(text, obj) [[deprecated(text)]] obj
71 #define WINPR_NORETURN(obj) [[noreturn]] obj
72 #elif defined(WIN32) && !defined(__CYGWIN__)
73 #define WINPR_DEPRECATED(obj) __declspec(deprecated) obj
74 #define WINPR_DEPRECATED_VAR(text, obj) __declspec(deprecated(text)) obj
75 #define WINPR_NORETURN(obj) __declspec(noreturn) obj
76 #elif defined(__GNUC__)
77 #define WINPR_DEPRECATED(obj) obj __attribute__((deprecated))
78 #define WINPR_DEPRECATED_VAR(text, obj) obj __attribute__((deprecated(text)))
79 #define WINPR_NORETURN(obj) __attribute__((__noreturn__)) obj
80 #else
81 #define WINPR_DEPRECATED(obj) obj
82 #define WINPR_DEPRECATED_VAR(text, obj) obj
83 #define WINPR_NORETURN(obj) obj
84 #endif
85 
86 #if defined(EXPORT_ALL_SYMBOLS)
87 #define WINPR_LOCAL WINPR_API
88 #else
89 #if defined _WIN32 || defined __CYGWIN__
90 #define WINPR_LOCAL
91 #else
92 #if defined(__GNUC__) && (__GNUC__ >= 4)
93 #define WINPR_LOCAL __attribute__((visibility("hidden")))
94 #else
95 #define WINPR_LOCAL
96 #endif
97 #endif
98 #endif
99 
100 // WARNING: *do not* use thread-local storage for new code because it is not portable
101 // It is only used for VirtualChannelInit, and all FreeRDP channels use VirtualChannelInitEx
102 // The old virtual channel API is only realistically used on Windows where TLS is available
103 #if defined _WIN32 || defined __CYGWIN__
104 #ifdef __GNUC__
105 #define WINPR_TLS __thread
106 #else
107 #define WINPR_TLS __declspec(thread)
108 #endif
109 #elif !defined(__IOS__)
110 #define WINPR_TLS __thread
111 #else
112 // thread-local storage is not supported on iOS
113 // don't warn because it isn't actually used on iOS
114 #define WINPR_TLS
115 #endif
116 
117 #ifdef _WIN32
118 #define INLINE __inline
119 #else
120 #define INLINE inline
121 #endif
122 
123 #if defined(__GNUC__) || defined(__clang__)
124 #define WINPR_ALIGN64 __attribute__((aligned(8)))
125 #else
126 #ifdef _WIN32
127 #define WINPR_ALIGN64 __declspec(align(8))
128 #else
129 #define WINPR_ALIGN64
130 #endif
131 #endif
132 
133 WINPR_API void winpr_get_version(int* major, int* minor, int* revision);
134 WINPR_API const char* winpr_get_version_string(void);
135 WINPR_API const char* winpr_get_build_revision(void);
136 WINPR_API const char* winpr_get_build_config(void);
137 
138 #define WINPR_UNUSED(x) (void)(x)
139 
140 #if defined(__GNUC__) || defined(__clang__)
148 #define WINPR_REINTERPRET_CAST(ptr, srcType, dstType) \
149  __extension__({ \
150  union \
151  { \
152  srcType src; \
153  dstType dst; \
154  } cnv; \
155  cnv.src = ptr; \
156  cnv.dst; \
157  })
158 
166 #define WINPR_CAST_CONST_PTR_AWAY(ptr, dstType) \
167  __extension__({ \
168  union \
169  { \
170  typeof(ptr) src; \
171  dstType dst; \
172  } cnv; \
173  cnv.src = ptr; \
174  cnv.dst; \
175  })
176 
184 #define WINPR_FUNC_PTR_CAST(ptr, dstType) \
185  __extension__({ \
186  union \
187  { \
188  typeof(ptr) src; \
189  dstType dst; \
190  } cnv; \
191  cnv.src = ptr; \
192  cnv.dst; \
193  })
194 #else
195 #define WINPR_REINTERPRET_CAST(ptr, srcType, dstType) (dstType) ptr
196 #define WINPR_CAST_CONST_PTR_AWAY(ptr, dstType) (dstType) ptr
197 #define WINPR_FUNC_PTR_CAST(ptr, dstType) (dstType)(uintptr_t) ptr
198 #endif
199 
200 #endif /* WINPR_H */