• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
20 #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
21 
22 /*
23  * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI
24  * compatible with older platforms (currently only on Linux)
25  * Causes:
26  *  - some libc calls to be gotten via dlsym
27  *  - some syscalls to be made directly
28  */
29 
30 /* Get windows.h included everywhere (we need it) */
31 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
32 #ifndef WIN32_LEAN_AND_MEAN
33 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
34 #define WIN32_LEAN_AND_MEAN
35 #endif /* WIN32_LEAN_AND_MEAN */
36 
37 #ifndef NOMINMAX
38 #define GRPC_NOMINMX_WAS_NOT_DEFINED
39 #define NOMINMAX
40 #endif /* NOMINMAX */
41 
42 #ifndef _WIN32_WINNT
43 #error \
44     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
45 #else /* !defined(_WIN32_WINNT) */
46 #if (_WIN32_WINNT < 0x0600)
47 #error \
48     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
49 #endif /* _WIN32_WINNT < 0x0600 */
50 #endif /* defined(_WIN32_WINNT) */
51 
52 #include <windows.h>
53 
54 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
55 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
56 #undef WIN32_LEAN_AND_MEAN
57 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
58 
59 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
60 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
61 #undef NOMINMAX
62 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
63 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
64           defined(WIN32) */
65 
66 /* Override this file with one for your platform if you need to redefine
67    things.  */
68 
69 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
70 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
71 #if defined(_WIN64) || defined(WIN64)
72 #define GPR_ARCH_64 1
73 #else
74 #define GPR_ARCH_32 1
75 #endif
76 #define GPR_PLATFORM_STRING "windows"
77 #define GPR_WINDOWS 1
78 #define GPR_WINDOWS_SUBPROCESS 1
79 #define GPR_WINDOWS_ENV
80 #ifdef __MSYS__
81 #define GPR_GETPID_IN_UNISTD_H 1
82 #define GPR_MSYS_TMPFILE
83 #define GPR_POSIX_LOG
84 #define GPR_POSIX_STRING
85 #define GPR_POSIX_TIME
86 #else
87 #define GPR_GETPID_IN_PROCESS_H 1
88 #define GPR_WINDOWS_TMPFILE
89 #define GPR_WINDOWS_LOG
90 #define GPR_WINDOWS_CRASH_HANDLER 1
91 #define GPR_WINDOWS_STRING
92 #define GPR_WINDOWS_TIME
93 #endif
94 #ifdef __GNUC__
95 #define GPR_GCC_ATOMIC 1
96 #define GPR_GCC_TLS 1
97 #else
98 #define GPR_WINDOWS_ATOMIC 1
99 #define GPR_MSVC_TLS 1
100 #endif
101 #elif defined(GPR_MANYLINUX1)
102 // TODO(atash): manylinux1 is just another __linux__ but with ancient
103 // libraries; it should be integrated with the `__linux__` definitions below.
104 #define GPR_PLATFORM_STRING "manylinux"
105 #define GPR_POSIX_CRASH_HANDLER 1
106 #define GPR_CPU_POSIX 1
107 #define GPR_GCC_ATOMIC 1
108 #define GPR_GCC_TLS 1
109 #define GPR_LINUX 1
110 #define GPR_LINUX_LOG 1
111 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
112 #define GPR_LINUX_ENV 1
113 #define GPR_POSIX_TMPFILE 1
114 #define GPR_POSIX_STRING 1
115 #define GPR_POSIX_SUBPROCESS 1
116 #define GPR_POSIX_SYNC 1
117 #define GPR_POSIX_TIME 1
118 #define GPR_GETPID_IN_UNISTD_H 1
119 #ifdef _LP64
120 #define GPR_ARCH_64 1
121 #else /* _LP64 */
122 #define GPR_ARCH_32 1
123 #endif /* _LP64 */
124 #elif defined(ANDROID) || defined(__ANDROID__)
125 #define GPR_PLATFORM_STRING "android"
126 #define GPR_ANDROID 1
127 #ifdef _LP64
128 #define GPR_ARCH_64 1
129 #else /* _LP64 */
130 #define GPR_ARCH_32 1
131 #endif /* _LP64 */
132 #define GPR_CPU_POSIX 1
133 #define GPR_GCC_SYNC 1
134 #define GPR_GCC_TLS 1
135 #define GPR_POSIX_ENV 1
136 #define GPR_POSIX_TMPFILE 1
137 #define GPR_ANDROID_LOG 1
138 #define GPR_POSIX_STRING 1
139 #define GPR_POSIX_SUBPROCESS 1
140 #define GPR_POSIX_SYNC 1
141 #define GPR_POSIX_TIME 1
142 #define GPR_GETPID_IN_UNISTD_H 1
143 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
144 #include <linux/version.h>
145 #elif defined(__linux__)
146 #define GPR_PLATFORM_STRING "linux"
147 #ifndef _BSD_SOURCE
148 #define _BSD_SOURCE
149 #endif
150 #ifndef _DEFAULT_SOURCE
151 #define _DEFAULT_SOURCE
152 #endif
153 #ifndef _GNU_SOURCE
154 #define _GNU_SOURCE
155 #endif
156 #include <features.h>
157 #define GPR_CPU_LINUX 1
158 #define GPR_GCC_ATOMIC 1
159 #define GPR_GCC_TLS 1
160 #define GPR_LINUX 1
161 #define GPR_LINUX_LOG
162 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
163 #define GPR_LINUX_ENV 1
164 #define GPR_POSIX_TMPFILE 1
165 #define GPR_POSIX_STRING 1
166 #define GPR_POSIX_SUBPROCESS 1
167 #define GPR_POSIX_SYNC 1
168 #define GPR_POSIX_TIME 1
169 #define GPR_GETPID_IN_UNISTD_H 1
170 #ifdef _LP64
171 #define GPR_ARCH_64 1
172 #else /* _LP64 */
173 #define GPR_ARCH_32 1
174 #endif /* _LP64 */
175 #ifdef __GLIBC__
176 #define GPR_POSIX_CRASH_HANDLER 1
177 #define GPR_LINUX_PTHREAD_NAME 1
178 #include <linux/version.h>
179 #else /* musl libc */
180 #define GPR_MUSL_LIBC_COMPAT 1
181 #endif
182 #elif defined(__APPLE__)
183 #include <Availability.h>
184 #include <TargetConditionals.h>
185 #ifndef _BSD_SOURCE
186 #define _BSD_SOURCE
187 #endif
188 #if TARGET_OS_IPHONE
189 #define GPR_PLATFORM_STRING "ios"
190 #define GPR_CPU_IPHONE 1
191 #define GPR_PTHREAD_TLS 1
192 #else /* TARGET_OS_IPHONE */
193 #define GPR_PLATFORM_STRING "osx"
194 #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
195 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7
196 #define GPR_CPU_IPHONE 1
197 #define GPR_PTHREAD_TLS 1
198 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 */
199 #define GPR_CPU_POSIX 1
200 /* TODO(vjpai): there is a reported issue in bazel build for Mac where __thread
201    in a header is currently not working (bazelbuild/bazel#4341). Remove
202    the following conditional and use GPR_GCC_TLS when that is fixed */
203 #ifndef GRPC_BAZEL_BUILD
204 #define GPR_GCC_TLS 1
205 #else /* GRPC_BAZEL_BUILD */
206 #define GPR_PTHREAD_TLS 1
207 #endif /* GRPC_BAZEL_BUILD */
208 #define GPR_APPLE_PTHREAD_NAME 1
209 #endif
210 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */
211 #define GPR_CPU_POSIX 1
212 /* TODO(vjpai): Remove the following conditional and use only GPR_GCC_TLS
213    when bazelbuild/bazel#4341 is fixed */
214 #ifndef GRPC_BAZEL_BUILD
215 #define GPR_GCC_TLS 1
216 #else /* GRPC_BAZEL_BUILD */
217 #define GPR_PTHREAD_TLS 1
218 #endif /* GRPC_BAZEL_BUILD */
219 #endif
220 #define GPR_POSIX_CRASH_HANDLER 1
221 #endif
222 #define GPR_APPLE 1
223 #define GPR_GCC_ATOMIC 1
224 #define GPR_POSIX_LOG 1
225 #define GPR_POSIX_ENV 1
226 #define GPR_POSIX_TMPFILE 1
227 #define GPR_POSIX_STRING 1
228 #define GPR_POSIX_SUBPROCESS 1
229 #define GPR_POSIX_SYNC 1
230 #define GPR_POSIX_TIME 1
231 #define GPR_GETPID_IN_UNISTD_H 1
232 /* TODO(mxyan): Remove when CFStream becomes default */
233 #ifndef GRPC_CFSTREAM
234 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
235 #endif
236 #ifdef _LP64
237 #define GPR_ARCH_64 1
238 #else /* _LP64 */
239 #define GPR_ARCH_32 1
240 #endif /* _LP64 */
241 #elif defined(__FreeBSD__)
242 #define GPR_PLATFORM_STRING "freebsd"
243 #ifndef _BSD_SOURCE
244 #define _BSD_SOURCE
245 #endif
246 #define GPR_FREEBSD 1
247 #define GPR_CPU_POSIX 1
248 #define GPR_GCC_ATOMIC 1
249 #define GPR_GCC_TLS 1
250 #define GPR_POSIX_LOG 1
251 #define GPR_POSIX_ENV 1
252 #define GPR_POSIX_TMPFILE 1
253 #define GPR_POSIX_STRING 1
254 #define GPR_POSIX_SUBPROCESS 1
255 #define GPR_POSIX_SYNC 1
256 #define GPR_POSIX_TIME 1
257 #define GPR_GETPID_IN_UNISTD_H 1
258 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
259 #ifdef _LP64
260 #define GPR_ARCH_64 1
261 #else /* _LP64 */
262 #define GPR_ARCH_32 1
263 #endif /* _LP64 */
264 #elif defined(__OpenBSD__)
265 #define GPR_PLATFORM_STRING "openbsd"
266 #ifndef _BSD_SOURCE
267 #define _BSD_SOURCE
268 #endif
269 #define GPR_OPENBSD 1
270 #define GPR_CPU_POSIX 1
271 #define GPR_GCC_ATOMIC 1
272 #define GPR_GCC_TLS 1
273 #define GPR_POSIX_LOG 1
274 #define GPR_POSIX_ENV 1
275 #define GPR_POSIX_TMPFILE 1
276 #define GPR_POSIX_STRING 1
277 #define GPR_POSIX_SUBPROCESS 1
278 #define GPR_POSIX_SYNC 1
279 #define GPR_POSIX_TIME 1
280 #define GPR_GETPID_IN_UNISTD_H 1
281 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
282 #ifdef _LP64
283 #define GPR_ARCH_64 1
284 #else /* _LP64 */
285 #define GPR_ARCH_32 1
286 #endif /* _LP64 */
287 #elif defined(__sun) && defined(__SVR4)
288 #define GPR_PLATFORM_STRING "solaris"
289 #define GPR_SOLARIS 1
290 #define GPR_CPU_POSIX 1
291 #define GPR_GCC_ATOMIC 1
292 #define GPR_GCC_TLS 1
293 #define GPR_POSIX_LOG 1
294 #define GPR_POSIX_ENV 1
295 #define GPR_POSIX_TMPFILE 1
296 #define GPR_POSIX_STRING 1
297 #define GPR_POSIX_SUBPROCESS 1
298 #define GPR_POSIX_SYNC 1
299 #define GPR_POSIX_TIME 1
300 #define GPR_GETPID_IN_UNISTD_H 1
301 #ifdef _LP64
302 #define GPR_ARCH_64 1
303 #else /* _LP64 */
304 #define GPR_ARCH_32 1
305 #endif /* _LP64 */
306 #elif defined(_AIX)
307 #define GPR_PLATFORM_STRING "aix"
308 #ifndef _ALL_SOURCE
309 #define _ALL_SOURCE
310 #endif
311 #define GPR_AIX 1
312 #define GPR_CPU_POSIX 1
313 #define GPR_GCC_ATOMIC 1
314 #define GPR_GCC_TLS 1
315 #define GPR_POSIX_LOG 1
316 #define GPR_POSIX_ENV 1
317 #define GPR_POSIX_TMPFILE 1
318 #define GPR_POSIX_STRING 1
319 #define GPR_POSIX_SUBPROCESS 1
320 #define GPR_POSIX_SYNC 1
321 #define GPR_POSIX_TIME 1
322 #define GPR_GETPID_IN_UNISTD_H 1
323 #ifdef _LP64
324 #define GPR_ARCH_64 1
325 #else /* _LP64 */
326 #define GPR_ARCH_32 1
327 #endif /* _LP64 */
328 #elif defined(__native_client__)
329 #define GPR_PLATFORM_STRING "nacl"
330 #ifndef _BSD_SOURCE
331 #define _BSD_SOURCE
332 #endif
333 #ifndef _DEFAULT_SOURCE
334 #define _DEFAULT_SOURCE
335 #endif
336 #ifndef _GNU_SOURCE
337 #define _GNU_SOURCE
338 #endif
339 #define GPR_NACL 1
340 #define GPR_CPU_POSIX 1
341 #define GPR_GCC_ATOMIC 1
342 #define GPR_GCC_TLS 1
343 #define GPR_POSIX_LOG 1
344 #define GPR_POSIX_ENV 1
345 #define GPR_POSIX_TMPFILE 1
346 #define GPR_POSIX_STRING 1
347 #define GPR_POSIX_SUBPROCESS 1
348 #define GPR_POSIX_SYNC 1
349 #define GPR_POSIX_TIME 1
350 #define GPR_GETPID_IN_UNISTD_H 1
351 #ifdef _LP64
352 #define GPR_ARCH_64 1
353 #else /* _LP64 */
354 #define GPR_ARCH_32 1
355 #endif /* _LP64 */
356 #else
357 #error "Could not auto-detect platform"
358 #endif
359 #endif /* GPR_NO_AUTODETECT_PLATFORM */
360 
361 /*
362  *  There are platforms for which TLS should not be used even though the
363  * compiler makes it seem like it's supported (Android NDK < r12b for example).
364  * This is primarily because of linker problems and toolchain misconfiguration:
365  * TLS isn't supported until NDK r12b per
366  * https://developer.android.com/ndk/downloads/revision_history.html
367  * TLS also does not work with Android NDK if GCC is being used as the compiler
368  * instead of Clang.
369  * Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
370  * <android/ndk-version.h>. For NDK < r16, users should define these macros,
371  * e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. */
372 #if defined(__ANDROID__) && defined(GPR_GCC_TLS)
373 #if __has_include(<android/ndk-version.h>)
374 #include <android/ndk-version.h>
375 #endif /* __has_include(<android/ndk-version.h>) */
376 #if (defined(__clang__) && defined(__NDK_MAJOR__) && defined(__NDK_MINOR__) && \
377      ((__NDK_MAJOR__ < 12) ||                                                  \
378       ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))) ||                      \
379     (defined(__GNUC__) && !defined(__clang__))
380 #undef GPR_GCC_TLS
381 #define GPR_PTHREAD_TLS 1
382 #endif
383 #endif /*defined(__ANDROID__) && defined(GPR_GCC_TLS) */
384 
385 #if defined(__has_include)
386 #if __has_include(<atomic>)
387 #define GRPC_HAS_CXX11_ATOMIC
388 #endif /* __has_include(<atomic>) */
389 #endif /* defined(__has_include) */
390 
391 #ifndef GPR_PLATFORM_STRING
392 #warning "GPR_PLATFORM_STRING not auto-detected"
393 #define GPR_PLATFORM_STRING "unknown"
394 #endif
395 
396 #ifdef GPR_GCOV
397 #undef GPR_FORBID_UNREACHABLE_CODE
398 #define GPR_FORBID_UNREACHABLE_CODE 1
399 #endif
400 
401 #ifdef _MSC_VER
402 #if _MSC_VER < 1700
403 typedef __int8 int8_t;
404 typedef __int16 int16_t;
405 typedef __int32 int32_t;
406 typedef __int64 int64_t;
407 typedef unsigned __int8 uint8_t;
408 typedef unsigned __int16 uint16_t;
409 typedef unsigned __int32 uint32_t;
410 typedef unsigned __int64 uint64_t;
411 #else
412 #include <stdint.h>
413 #endif /* _MSC_VER < 1700 */
414 #else
415 #include <stdint.h>
416 #endif /* _MSC_VER */
417 
418 /* Cache line alignment */
419 #ifndef GPR_CACHELINE_SIZE_LOG
420 #if defined(__i386__) || defined(__x86_64__)
421 #define GPR_CACHELINE_SIZE_LOG 6
422 #endif
423 #ifndef GPR_CACHELINE_SIZE_LOG
424 /* A reasonable default guess. Note that overestimates tend to waste more
425    space, while underestimates tend to waste more time. */
426 #define GPR_CACHELINE_SIZE_LOG 6
427 #endif /* GPR_CACHELINE_SIZE_LOG */
428 #endif /* GPR_CACHELINE_SIZE_LOG */
429 
430 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
431 
432 /* scrub GCC_ATOMIC if it's not available on this compiler */
433 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
434 #undef GPR_GCC_ATOMIC
435 #define GPR_GCC_SYNC 1
436 #endif
437 
438 /* Validate platform combinations */
439 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
440         defined(GPR_WINDOWS_ATOMIC) !=                \
441     1
442 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
443 #endif
444 
445 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
446 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
447 #endif
448 
449 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
450         defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) !=                 \
451     1
452 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
453 #endif
454 
455 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
456         defined(GPR_CUSTOM_TLS) !=                                            \
457     1
458 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS
459 #endif
460 
461 /* maximum alignment needed for any type on this platform, rounded up to a
462    power of two */
463 #define GPR_MAX_ALIGNMENT 16
464 
465 #ifndef GRPC_ARES
466 #define GRPC_ARES 0 // Disable GRPC_ARES for Android due to missing dependency
467 #endif
468 
469 #ifndef GRPC_MUST_USE_RESULT
470 #if defined(__GNUC__) && !defined(__MINGW32__)
471 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
472 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
473 #else
474 #define GRPC_MUST_USE_RESULT
475 #define GPR_ALIGN_STRUCT(n)
476 #endif
477 #endif
478 
479 #ifndef GRPC_UNUSED
480 #if defined(__GNUC__) && !defined(__MINGW32__)
481 #define GRPC_UNUSED __attribute__((unused))
482 #else
483 #define GRPC_UNUSED
484 #endif
485 #endif
486 
487 #ifndef GPR_PRINT_FORMAT_CHECK
488 #ifdef __GNUC__
489 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
490   __attribute__((format(printf, FORMAT_STR, ARGS)))
491 #else
492 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
493 #endif
494 #endif /* GPR_PRINT_FORMAT_CHECK */
495 
496 #if GPR_FORBID_UNREACHABLE_CODE
497 #define GPR_UNREACHABLE_CODE(STATEMENT)
498 #else
499 #define GPR_UNREACHABLE_CODE(STATEMENT)             \
500   do {                                              \
501     gpr_log(GPR_ERROR, "Should never reach here."); \
502     abort();                                        \
503     STATEMENT;                                      \
504   } while (0)
505 #endif /* GPR_FORBID_UNREACHABLE_CODE */
506 
507 #ifndef GPRAPI
508 #define GPRAPI
509 #endif
510 
511 #ifndef GRPCAPI
512 #define GRPCAPI GPRAPI
513 #endif
514 
515 #ifndef CENSUSAPI
516 #define CENSUSAPI GRPCAPI
517 #endif
518 
519 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
520 #if defined(__has_feature)
521 #if __has_feature(thread_sanitizer)
522 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
523 #endif                        /* __has_feature(thread_sanitizer) */
524 #endif                        /* defined(__has_feature) */
525 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
526 #define GPR_ATTRIBUTE_NO_TSAN
527 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
528 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
529 
530 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
531 #ifndef GRPC_ALLOW_EXCEPTIONS
532 /* If not already set, set to 1 on Windows (style guide standard) but to
533  * 0 on non-Windows platforms unless the compiler defines __EXCEPTIONS */
534 #ifdef GPR_WINDOWS
535 #define GRPC_ALLOW_EXCEPTIONS 1
536 #else /* GPR_WINDOWS */
537 #ifdef __EXCEPTIONS
538 #define GRPC_ALLOW_EXCEPTIONS 1
539 #else /* __EXCEPTIONS */
540 #define GRPC_ALLOW_EXCEPTIONS 0
541 #endif /* __EXCEPTIONS */
542 #endif /* __GPR_WINDOWS */
543 #endif /* GRPC_ALLOW_EXCEPTIONS */
544 
545 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
546  * most likely. Ideally, also collect performance numbers to justify the claim.
547  */
548 #ifdef __GNUC__
549 #define GPR_LIKELY(x) __builtin_expect((x), 1)
550 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
551 #else /* __GNUC__ */
552 #define GPR_LIKELY(x) (x)
553 #define GPR_UNLIKELY(x) (x)
554 #endif /* __GNUC__ */
555 
556 #ifndef __STDC_FORMAT_MACROS
557 #define __STDC_FORMAT_MACROS
558 #endif
559 
560 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */
561