GRPC Core  0.10.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
port_platform.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPC_SUPPORT_PORT_PLATFORM_H
35 #define GRPC_SUPPORT_PORT_PLATFORM_H
36 
37 /* Get windows.h included everywhere (we need it) */
38 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
39 #ifndef WIN32_LEAN_AND_MEAN
40 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
41 #define WIN32_LEAN_AND_MEAN
42 #endif /* WIN32_LEAN_AND_MEAN */
43 
44 #ifndef NOMINMAX
45 #define GRPC_NOMINMX_WAS_NOT_DEFINED
46 #define NOMINMAX
47 #endif /* NOMINMAX */
48 
49 #if defined(_WIN32_WINNT)
50 #if _WIN32_WINNT < 0x0600
51 #undef _WIN32_WINNT
52 #define _WIN32_WINNT 0x0600
53 #endif /* _WIN32_WINNT < 0x0600 */
54 #endif /* defined(_WIN32_WINNT) */
55 
56 #include <windows.h>
57 
58 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
59 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
60 #undef WIN32_LEAN_AND_MEAN
61 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
62 
63 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
64 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
65 #undef NOMINMAX
66 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
67 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) */
68 
69 /* Override this file with one for your platform if you need to redefine
70  things. */
71 
72 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
73 #if defined(_WIN64) || defined(WIN64)
74 #define GPR_PLATFORM_STRING "windows"
75 #define GPR_WIN32 1
76 #define GPR_ARCH_64 1
77 #define GPR_GETPID_IN_PROCESS_H 1
78 #define GPR_WINSOCK_SOCKET 1
79 #ifdef __GNUC__
80 #define GPR_GCC_ATOMIC 1
81 #define GPR_GCC_TLS 1
82 #else
83 #define GPR_WIN32_ATOMIC 1
84 #define GPR_MSVC_TLS 1
85 #endif
86 #define GPR_WINDOWS_CRASH_HANDLER 1
87 #elif defined(_WIN32) || defined(WIN32)
88 #define GPR_PLATFORM_STRING "windows"
89 #define GPR_ARCH_32 1
90 #define GPR_WIN32 1
91 #define GPR_GETPID_IN_PROCESS_H 1
92 #define GPR_WINSOCK_SOCKET 1
93 #ifdef __GNUC__
94 #define GPR_GCC_ATOMIC 1
95 #define GPR_GCC_TLS 1
96 #else
97 #define GPR_WIN32_ATOMIC 1
98 #define GPR_MSVC_TLS 1
99 #endif
100 #define GPR_WINDOWS_CRASH_HANDLER 1
101 #elif defined(ANDROID) || defined(__ANDROID__)
102 #define GPR_PLATFORM_STRING "android"
103 #define GPR_ANDROID 1
104 #define GPR_ARCH_32 1
105 #define GPR_CPU_LINUX 1
106 #define GPR_GCC_SYNC 1
107 #define GPR_GCC_TLS 1
108 #define GPR_POSIX_MULTIPOLL_WITH_POLL 1
109 #define GPR_POSIX_WAKEUP_FD 1
110 #define GPR_LINUX_EVENTFD 1
111 #define GPR_POSIX_SOCKET 1
112 #define GPR_POSIX_SOCKETADDR 1
113 #define GPR_POSIX_SOCKETUTILS 1
114 #define GPR_POSIX_ENV 1
115 #define GPR_POSIX_FILE 1
116 #define GPR_POSIX_STRING 1
117 #define GPR_POSIX_SUBPROCESS 1
118 #define GPR_POSIX_SYNC 1
119 #define GPR_POSIX_TIME 1
120 #define GPR_GETPID_IN_UNISTD_H 1
121 #define GPR_HAVE_MSG_NOSIGNAL 1
122 #elif defined(__linux__)
123 #define GPR_PLATFORM_STRING "linux"
124 #ifndef _BSD_SOURCE
125 #define _BSD_SOURCE
126 #endif
127 #ifndef _DEFAULT_SOURCE
128 #define _DEFAULT_SOURCE
129 #endif
130 #ifndef _GNU_SOURCE
131 #define _GNU_SOURCE
132 #endif
133 #include <features.h>
134 #define GPR_CPU_LINUX 1
135 #define GPR_GCC_ATOMIC 1
136 #define GPR_GCC_TLS 1
137 #define GPR_LINUX 1
138 #define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1
139 #define GPR_POSIX_WAKEUP_FD 1
140 #define GPR_POSIX_SOCKET 1
141 #define GPR_POSIX_SOCKETADDR 1
142 #ifdef __GLIBC_PREREQ
143 #if __GLIBC_PREREQ(2, 9)
144 #define GPR_LINUX_EVENTFD 1
145 #endif
146 #if __GLIBC_PREREQ(2, 10)
147 #define GPR_LINUX_SOCKETUTILS 1
148 #endif
149 #if __GLIBC_PREREQ(2, 17)
150 #define GPR_LINUX_ENV 1
151 #endif
152 #endif
153 #ifndef GPR_LINUX_EVENTFD
154 #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1
155 #endif
156 #ifndef GPR_LINUX_SOCKETUTILS
157 #define GPR_POSIX_SOCKETUTILS
158 #endif
159 #ifndef GPR_LINUX_ENV
160 #define GPR_POSIX_ENV 1
161 #endif
162 #define GPR_POSIX_FILE 1
163 #define GPR_POSIX_STRING 1
164 #define GPR_POSIX_SUBPROCESS 1
165 #define GPR_POSIX_SYNC 1
166 #define GPR_POSIX_TIME 1
167 #define GPR_GETPID_IN_UNISTD_H 1
168 #define GPR_HAVE_MSG_NOSIGNAL 1
169 #ifdef _LP64
170 #define GPR_ARCH_64 1
171 #else /* _LP64 */
172 #define GPR_ARCH_32 1
173 #endif /* _LP64 */
174 #elif defined(__APPLE__)
175 #include <TargetConditionals.h>
176 #ifndef _BSD_SOURCE
177 #define _BSD_SOURCE
178 #endif
179 #if TARGET_OS_IPHONE
180 #define GPR_PLATFORM_STRING "ios"
181 #define GPR_CPU_IPHONE 1
182 #define GPR_PTHREAD_TLS 1
183 #else /* TARGET_OS_IPHONE */
184 #define GPR_PLATFORM_STRING "osx"
185 #define GPR_CPU_POSIX 1
186 #define GPR_GCC_TLS 1
187 #endif
188 #define GPR_GCC_ATOMIC 1
189 #define GPR_POSIX_LOG 1
190 #define GPR_POSIX_MULTIPOLL_WITH_POLL 1
191 #define GPR_POSIX_WAKEUP_FD 1
192 #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1
193 #define GPR_POSIX_SOCKET 1
194 #define GPR_POSIX_SOCKETADDR 1
195 #define GPR_POSIX_SOCKETUTILS 1
196 #define GPR_POSIX_ENV 1
197 #define GPR_POSIX_FILE 1
198 #define GPR_POSIX_STRING 1
199 #define GPR_POSIX_SUBPROCESS 1
200 #define GPR_POSIX_SYNC 1
201 #define GPR_POSIX_TIME 1
202 #define GPR_GETPID_IN_UNISTD_H 1
203 #define GPR_HAVE_SO_NOSIGPIPE 1
204 #ifdef _LP64
205 #define GPR_ARCH_64 1
206 #else /* _LP64 */
207 #define GPR_ARCH_32 1
208 #endif /* _LP64 */
209 #elif defined(__FreeBSD__)
210 #define GPR_PLATFORM_STRING "freebsd"
211 #ifndef _BSD_SOURCE
212 #define _BSD_SOURCE
213 #endif
214 #define GPR_CPU_POSIX 1
215 #define GPR_GCC_ATOMIC 1
216 #define GPR_GCC_TLS 1
217 #define GPR_POSIX_LOG 1
218 #define GPR_POSIX_MULTIPOLL_WITH_POLL 1
219 #define GPR_POSIX_WAKEUP_FD 1
220 #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1
221 #define GPR_POSIX_SOCKET 1
222 #define GPR_POSIX_SOCKETADDR 1
223 #define GPR_POSIX_SOCKETUTILS 1
224 #define GPR_POSIX_ENV 1
225 #define GPR_POSIX_FILE 1
226 #define GPR_POSIX_STRING 1
227 #define GPR_POSIX_SUBPROCESS 1
228 #define GPR_POSIX_SYNC 1
229 #define GPR_POSIX_TIME 1
230 #define GPR_GETPID_IN_UNISTD_H 1
231 #define GPR_HAVE_SO_NOSIGPIPE 1
232 #ifdef _LP64
233 #define GPR_ARCH_64 1
234 #else /* _LP64 */
235 #define GPR_ARCH_32 1
236 #endif /* _LP64 */
237 #else
238 #error Could not auto-detect platform
239 #endif
240 #endif /* GPR_NO_AUTODETECT_PLATFORM */
241 
242 #ifndef GPR_PLATFORM_STRING
243 #warning "GPR_PLATFORM_STRING not auto-detected"
244 #define GPR_PLATFORM_STRING "unknown"
245 #endif
246 
247 /* For a common case, assume that the platform has a C99-like stdint.h */
248 
249 #include <stdint.h>
250 
251 /* Cache line alignment */
252 #ifndef GPR_CACHELINE_SIZE_LOG
253 #if defined(__i386__) || defined(__x86_64__)
254 #define GPR_CACHELINE_SIZE_LOG 6
255 #endif
256 #ifndef GPR_CACHELINE_SIZE_LOG
257 /* A reasonable default guess. Note that overestimates tend to waste more
258  space, while underestimates tend to waste more time. */
259 #define GPR_CACHELINE_SIZE_LOG 6
260 #endif /* GPR_CACHELINE_SIZE_LOG */
261 #endif /* GPR_CACHELINE_SIZE_LOG */
262 
263 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
264 
265 /* scrub GCC_ATOMIC if it's not available on this compiler */
266 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
267 #undef GPR_GCC_ATOMIC
268 #define GPR_GCC_SYNC 1
269 #endif
270 
271 /* Validate platform combinations */
272 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
273  defined(GPR_WIN32_ATOMIC) != \
274  1
275 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32_ATOMIC
276 #endif
277 
278 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
279 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
280 #endif
281 
282 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WIN32) + \
283  defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
284  1
285 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WIN32, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
286 #endif
287 
288 #if defined(GPR_POSIX_MULTIPOLL_WITH_POLL) && !defined(GPR_POSIX_SOCKET)
289 #error Must define GPR_POSIX_SOCKET to use GPR_POSIX_MULTIPOLL_WITH_POLL
290 #endif
291 
292 #if defined(GPR_POSIX_SOCKET) + defined(GPR_WINSOCK_SOCKET) + \
293  defined(GPR_CUSTOM_SOCKET) != \
294  1
295 #error Must define exactly one of GPR_POSIX_SOCKET, GPR_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET
296 #endif
297 
298 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
299  defined(GPR_CUSTOM_TLS) != \
300  1
301 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS
302 #endif
303 
304 typedef int16_t gpr_int16;
305 typedef int32_t gpr_int32;
306 typedef int64_t gpr_int64;
307 typedef uint8_t gpr_uint8;
308 typedef uint16_t gpr_uint16;
309 typedef uint32_t gpr_uint32;
310 typedef uint64_t gpr_uint64;
311 typedef intmax_t gpr_intmax;
312 typedef intptr_t gpr_intptr;
313 typedef uintmax_t gpr_uintmax;
314 typedef uintptr_t gpr_uintptr;
315 
316 /* INT64_MAX is unavailable on some platforms. */
317 #define GPR_INT64_MAX (gpr_int64)(~(gpr_uint64)0 >> 1)
318 
319 /* maximum alignment needed for any type on this platform, rounded up to a
320  power of two */
321 #define GPR_MAX_ALIGNMENT 16
322 
323 #ifndef GRPC_MUST_USE_RESULT
324 #ifdef __GNUC__
325 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
326 #else
327 #define GRPC_MUST_USE_RESULT
328 #endif
329 #endif
330 
331 #endif /* GRPC_SUPPORT_PORT_PLATFORM_H */
intptr_t gpr_intptr
Definition: port_platform.h:312
uint8_t gpr_uint8
Definition: port_platform.h:307
uintptr_t gpr_uintptr
Definition: port_platform.h:314
uint32_t gpr_uint32
Definition: port_platform.h:309
uintmax_t gpr_uintmax
Definition: port_platform.h:313
int64_t gpr_int64
Definition: port_platform.h:306
uint16_t gpr_uint16
Definition: port_platform.h:308
int32_t gpr_int32
Definition: port_platform.h:305
uint64_t gpr_uint64
Definition: port_platform.h:310
intmax_t gpr_intmax
Definition: port_platform.h:311
int16_t gpr_int16
Definition: port_platform.h:304