3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
20 #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
22 // IWYU pragma: private, include <grpc/support/port_platform.h>
25 * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI
26 * compatible with older platforms (currently only on Linux)
28 * - some libc calls to be gotten via dlsym
29 * - some syscalls to be made directly
32 // [[deprecated]] attribute is only available since C++14
33 #if __cplusplus >= 201402L
34 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
36 #define GRPC_DEPRECATED(reason)
37 #endif // __cplusplus >= 201402L
40 * Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil
42 #ifndef GPR_ABSEIL_SYNC
43 #if defined(__APPLE__)
44 // This is disabled on Apple platforms because macos/grpc_basictests_c_cpp
45 // fails with this. https://github.com/grpc/grpc/issues/23661
47 #define GPR_ABSEIL_SYNC 1
49 #endif // GPR_ABSEIL_SYNC
52 * Defines GRPC_ERROR_IS_ABSEIL_STATUS to use absl::Status for grpc_error_handle
54 // #define GRPC_ERROR_IS_ABSEIL_STATUS 1
56 /* Get windows.h included everywhere (we need it) */
57 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
58 #ifndef WIN32_LEAN_AND_MEAN
59 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
60 #define WIN32_LEAN_AND_MEAN
61 #endif /* WIN32_LEAN_AND_MEAN */
64 #define GRPC_NOMINMX_WAS_NOT_DEFINED
72 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
73 #else /* !defined(_WIN32_WINNT) */
74 #if (_WIN32_WINNT < 0x0600)
76 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
77 #endif /* _WIN32_WINNT < 0x0600 */
78 #endif /* defined(_WIN32_WINNT) */
80 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
81 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
82 #undef WIN32_LEAN_AND_MEAN
83 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
85 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
86 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
88 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
89 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
92 /* Override this file with one for your platform if you need to redefine
95 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
96 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
97 #if defined(_WIN64) || defined(WIN64)
100 #define GPR_ARCH_32 1
102 #define GPR_PLATFORM_STRING "windows"
103 #define GPR_WINDOWS 1
104 #define GPR_WINDOWS_SUBPROCESS 1
105 #define GPR_WINDOWS_ENV
107 #define GPR_GETPID_IN_UNISTD_H 1
108 #define GPR_MSYS_TMPFILE
109 #define GPR_POSIX_LOG
110 #define GPR_POSIX_STRING
111 #define GPR_POSIX_TIME
113 #define GPR_GETPID_IN_PROCESS_H 1
114 #define GPR_WINDOWS_TMPFILE
115 #define GPR_WINDOWS_LOG
116 #define GPR_WINDOWS_CRASH_HANDLER 1
117 #define GPR_WINDOWS_STAT
118 #define GPR_WINDOWS_STRING
119 #define GPR_WINDOWS_TIME
122 #define GPR_GCC_ATOMIC 1
124 #define GPR_WINDOWS_ATOMIC 1
126 #elif defined(ANDROID) || defined(__ANDROID__)
127 #define GPR_PLATFORM_STRING "android"
128 #define GPR_ANDROID 1
129 #ifdef __ANDROID_API__
130 #if (__ANDROID_API__) >= 29
131 #define GPR_SUPPORT_BINDER_TRANSPORT 1
134 // TODO(apolcyn): re-evaluate support for c-ares
135 // on android after upgrading our c-ares dependency.
136 // See https://github.com/grpc/grpc/issues/18038.
139 #define GPR_ARCH_64 1
141 #define GPR_ARCH_32 1
143 #define GPR_CPU_POSIX 1
144 #define GPR_GCC_SYNC 1
145 #define GPR_POSIX_ENV 1
146 #define GPR_POSIX_TMPFILE 1
147 #define GPR_POSIX_STAT 1
148 #define GPR_ANDROID_LOG 1
149 #define GPR_POSIX_STRING 1
150 #define GPR_POSIX_SUBPROCESS 1
151 #define GPR_POSIX_SYNC 1
152 #define GPR_POSIX_TIME 1
153 #define GPR_HAS_PTHREAD_H 1
154 #define GPR_GETPID_IN_UNISTD_H 1
155 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
156 #elif defined(__linux__)
157 #define GPR_PLATFORM_STRING "linux"
161 #ifndef _DEFAULT_SOURCE
162 #define _DEFAULT_SOURCE
167 #include <features.h>
168 #define GPR_CPU_LINUX 1
169 #define GPR_GCC_ATOMIC 1
171 #define GPR_LINUX_LOG
172 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
173 #define GPR_LINUX_ENV 1
174 #define GPR_POSIX_TMPFILE 1
175 #define GPR_POSIX_STAT 1
176 #define GPR_POSIX_STRING 1
177 #define GPR_POSIX_SUBPROCESS 1
178 #define GPR_POSIX_SYNC 1
179 #define GPR_POSIX_TIME 1
180 #define GPR_HAS_PTHREAD_H 1
181 #define GPR_GETPID_IN_UNISTD_H 1
183 #define GPR_ARCH_64 1
185 #define GPR_ARCH_32 1
188 #define GPR_POSIX_CRASH_HANDLER 1
189 #define GPR_LINUX_PTHREAD_NAME 1
190 #include <linux/version.h>
191 #else /* musl libc */
192 #define GPR_MUSL_LIBC_COMPAT 1
194 #elif defined(__ASYLO__)
195 #define GPR_ARCH_64 1
196 #define GPR_CPU_POSIX 1
197 #define GPR_PLATFORM_STRING "asylo"
198 #define GPR_GCC_SYNC 1
199 #define GPR_POSIX_SYNC 1
200 #define GPR_POSIX_STRING 1
201 #define GPR_POSIX_LOG 1
202 #define GPR_POSIX_TIME 1
203 #define GPR_POSIX_ENV 1
205 #define GRPC_POSIX_SOCKET 1
206 #define GRPC_POSIX_SOCKETADDR
207 #define GRPC_POSIX_SOCKETUTILS 1
208 #define GRPC_TIMER_USE_GENERIC 1
209 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
210 #define GRPC_POSIX_WAKEUP_FD 1
212 #define GPR_NO_AUTODETECT_PLATFORM 1
213 #elif defined(__APPLE__)
214 #include <Availability.h>
215 #include <TargetConditionals.h>
220 #define GPR_PLATFORM_STRING "ios"
221 #define GPR_CPU_IPHONE 1
222 #define GRPC_CFSTREAM 1
223 /* the c-ares resolver isn't safe to enable on iOS */
225 #else /* TARGET_OS_IPHONE */
226 #define GPR_PLATFORM_STRING "osx"
227 #define GPR_CPU_POSIX 1
228 #define GPR_POSIX_CRASH_HANDLER 1
230 #if !(defined(__has_feature) && __has_feature(cxx_thread_local))
231 #define GPR_PTHREAD_TLS 1
234 #define GPR_GCC_ATOMIC 1
235 #define GPR_POSIX_LOG 1
236 #define GPR_POSIX_ENV 1
237 #define GPR_POSIX_TMPFILE 1
238 #define GPR_POSIX_STAT 1
239 #define GPR_POSIX_STRING 1
240 #define GPR_POSIX_SUBPROCESS 1
241 #define GPR_POSIX_SYNC 1
242 #define GPR_POSIX_TIME 1
243 #define GPR_HAS_PTHREAD_H 1
244 #define GPR_GETPID_IN_UNISTD_H 1
245 #ifndef GRPC_CFSTREAM
246 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
249 #define GPR_ARCH_64 1
251 #define GPR_ARCH_32 1
253 #elif defined(__FreeBSD__)
254 #define GPR_PLATFORM_STRING "freebsd"
258 #define GPR_FREEBSD 1
259 #define GPR_CPU_POSIX 1
260 #define GPR_GCC_ATOMIC 1
261 #define GPR_POSIX_LOG 1
262 #define GPR_POSIX_ENV 1
263 #define GPR_POSIX_TMPFILE 1
264 #define GPR_POSIX_STAT 1
265 #define GPR_POSIX_STRING 1
266 #define GPR_POSIX_SUBPROCESS 1
267 #define GPR_POSIX_SYNC 1
268 #define GPR_POSIX_TIME 1
269 #define GPR_HAS_PTHREAD_H 1
270 #define GPR_GETPID_IN_UNISTD_H 1
271 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
273 #define GPR_ARCH_64 1
275 #define GPR_ARCH_32 1
277 #elif defined(__OpenBSD__)
278 #define GPR_PLATFORM_STRING "openbsd"
282 #define GPR_OPENBSD 1
283 #define GPR_CPU_POSIX 1
284 #define GPR_GCC_ATOMIC 1
285 #define GPR_POSIX_LOG 1
286 #define GPR_POSIX_ENV 1
287 #define GPR_POSIX_TMPFILE 1
288 #define GPR_POSIX_STAT 1
289 #define GPR_POSIX_STRING 1
290 #define GPR_POSIX_SUBPROCESS 1
291 #define GPR_POSIX_SYNC 1
292 #define GPR_POSIX_TIME 1
293 #define GPR_HAS_PTHREAD_H 1
294 #define GPR_GETPID_IN_UNISTD_H 1
295 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
297 #define GPR_ARCH_64 1
299 #define GPR_ARCH_32 1
301 #elif defined(__sun) && defined(__SVR4)
302 #define GPR_PLATFORM_STRING "solaris"
303 #define GPR_SOLARIS 1
304 #define GPR_CPU_POSIX 1
305 #define GPR_GCC_ATOMIC 1
306 #define GPR_POSIX_LOG 1
307 #define GPR_POSIX_ENV 1
308 #define GPR_POSIX_TMPFILE 1
309 #define GPR_POSIX_STAT 1
310 #define GPR_POSIX_STRING 1
311 #define GPR_POSIX_SUBPROCESS 1
312 #define GPR_POSIX_SYNC 1
313 #define GPR_POSIX_TIME 1
314 #define GPR_HAS_PTHREAD_H 1
315 #define GPR_GETPID_IN_UNISTD_H 1
317 #define GPR_ARCH_64 1
319 #define GPR_ARCH_32 1
322 #define GPR_PLATFORM_STRING "aix"
327 #define GPR_CPU_POSIX 1
328 #define GPR_GCC_ATOMIC 1
329 #define GPR_POSIX_LOG 1
330 #define GPR_POSIX_ENV 1
331 #define GPR_POSIX_TMPFILE 1
332 #define GPR_POSIX_STAT 1
333 #define GPR_POSIX_STRING 1
334 #define GPR_POSIX_SUBPROCESS 1
335 #define GPR_POSIX_SYNC 1
336 #define GPR_POSIX_TIME 1
337 #define GPR_HAS_PTHREAD_H 1
338 #define GPR_GETPID_IN_UNISTD_H 1
340 #define GPR_ARCH_64 1
342 #define GPR_ARCH_32 1
344 #elif defined(__native_client__)
345 #define GPR_PLATFORM_STRING "nacl"
349 #ifndef _DEFAULT_SOURCE
350 #define _DEFAULT_SOURCE
356 #define GPR_CPU_POSIX 1
357 #define GPR_GCC_ATOMIC 1
358 #define GPR_POSIX_LOG 1
359 #define GPR_POSIX_ENV 1
360 #define GPR_POSIX_TMPFILE 1
361 #define GPR_POSIX_STAT 1
362 #define GPR_POSIX_STRING 1
363 #define GPR_POSIX_SUBPROCESS 1
364 #define GPR_POSIX_SYNC 1
365 #define GPR_POSIX_TIME 1
366 #define GPR_HAS_PTHREAD_H 1
367 #define GPR_GETPID_IN_UNISTD_H 1
369 #define GPR_ARCH_64 1
371 #define GPR_ARCH_32 1
373 #elif defined(__Fuchsia__)
375 #define GPR_FUCHSIA 1
376 #define GPR_ARCH_64 1
377 #define GPR_PLATFORM_STRING "fuchsia"
378 #include <features.h>
379 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
381 #define GPR_MUSL_LIBC_COMPAT 1
382 #define GPR_CPU_POSIX 1
383 #define GPR_GCC_ATOMIC 1
384 #define GPR_POSIX_LOG 1
385 #define GPR_POSIX_SYNC 1
386 #define GPR_POSIX_ENV 1
387 #define GPR_POSIX_TMPFILE 1
388 #define GPR_POSIX_STAT 1
389 #define GPR_POSIX_SUBPROCESS 1
390 #define GPR_POSIX_SYNC 1
391 #define GPR_POSIX_STRING 1
392 #define GPR_POSIX_TIME 1
393 #define GPR_HAS_PTHREAD_H 1
394 #define GPR_GETPID_IN_UNISTD_H 1
395 #define GRPC_ROOT_PEM_PATH "/config/ssl/cert.pem"
397 #error "Could not auto-detect platform"
399 #endif /* GPR_NO_AUTODETECT_PLATFORM */
401 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
403 * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
404 * a library from having non-standard symbols such as __asprintf_chk.
405 * This helps non-glibc systems such as alpine using musl to find symbols.
407 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
408 #undef _FORTIFY_SOURCE
409 #define _FORTIFY_SOURCE 0
413 #if defined(__has_include)
414 #if __has_include(<atomic>)
415 #define GRPC_HAS_CXX11_ATOMIC
416 #endif /* __has_include(<atomic>) */
417 #endif /* defined(__has_include) */
419 #ifndef GPR_PLATFORM_STRING
420 #warning "GPR_PLATFORM_STRING not auto-detected"
421 #define GPR_PLATFORM_STRING "unknown"
425 #undef GPR_FORBID_UNREACHABLE_CODE
426 #define GPR_FORBID_UNREACHABLE_CODE 1
431 typedef __int8 int8_t;
432 typedef __int16 int16_t;
433 typedef __int32 int32_t;
434 typedef __int64 int64_t;
435 typedef unsigned __int8 uint8_t;
436 typedef unsigned __int16 uint16_t;
437 typedef unsigned __int32 uint32_t;
438 typedef unsigned __int64 uint64_t;
441 #endif /* _MSC_VER < 1700 */
444 #endif /* _MSC_VER */
446 /* Type of cycle clock implementation */
448 /* Disable cycle clock by default.
449 TODO(soheil): enable when we support fallback for unstable cycle clocks.
450 #if defined(__i386__)
451 #define GPR_CYCLE_COUNTER_RDTSC_32 1
452 #elif defined(__x86_64__) || defined(__amd64__)
453 #define GPR_CYCLE_COUNTER_RDTSC_64 1
455 #define GPR_CYCLE_COUNTER_FALLBACK 1
458 #define GPR_CYCLE_COUNTER_FALLBACK 1
460 #define GPR_CYCLE_COUNTER_FALLBACK 1
461 #endif /* GPR_LINUX */
463 /* Cache line alignment */
464 #ifndef GPR_CACHELINE_SIZE_LOG
465 #if defined(__i386__) || defined(__x86_64__)
466 #define GPR_CACHELINE_SIZE_LOG 6
468 #ifndef GPR_CACHELINE_SIZE_LOG
469 /* A reasonable default guess. Note that overestimates tend to waste more
470 space, while underestimates tend to waste more time. */
471 #define GPR_CACHELINE_SIZE_LOG 6
472 #endif /* GPR_CACHELINE_SIZE_LOG */
473 #endif /* GPR_CACHELINE_SIZE_LOG */
475 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
477 /* scrub GCC_ATOMIC if it's not available on this compiler */
478 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
479 #undef GPR_GCC_ATOMIC
480 #define GPR_GCC_SYNC 1
483 /* Validate platform combinations */
484 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
485 defined(GPR_WINDOWS_ATOMIC) != \
487 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
490 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
491 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
494 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
495 defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
497 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
500 /* maximum alignment needed for any type on this platform, rounded up to a
502 #define GPR_MAX_ALIGNMENT 16
508 #ifndef GRPC_IF_NAMETOINDEX
509 #define GRPC_IF_NAMETOINDEX 1
512 #ifndef GRPC_MUST_USE_RESULT
513 #if defined(__GNUC__) && !defined(__MINGW32__)
514 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
515 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
517 #define GRPC_MUST_USE_RESULT
518 #define GPR_ALIGN_STRUCT(n)
523 #if defined(__GNUC__) && !defined(__MINGW32__)
524 #define GRPC_UNUSED __attribute__((unused))
530 #ifndef GPR_PRINT_FORMAT_CHECK
532 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
533 __attribute__((format(printf, FORMAT_STR, ARGS)))
535 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
537 #endif /* GPR_PRINT_FORMAT_CHECK */
539 #if GPR_FORBID_UNREACHABLE_CODE
540 #define GPR_UNREACHABLE_CODE(STATEMENT)
542 #define GPR_UNREACHABLE_CODE(STATEMENT) \
544 gpr_log(GPR_ERROR, "Should never reach here."); \
548 #endif /* GPR_FORBID_UNREACHABLE_CODE */
555 #define GRPCAPI GPRAPI
559 #define CENSUSAPI GRPCAPI
562 #ifndef GPR_HAS_CPP_ATTRIBUTE
563 #ifdef __has_cpp_attribute
564 #define GPR_HAS_CPP_ATTRIBUTE(a) __has_cpp_attribute(a)
566 #define GPR_HAS_CPP_ATTRIBUTE(a) 0
568 #endif /* GPR_HAS_CPP_ATTRIBUTE */
570 #ifndef GPR_HAS_ATTRIBUTE
571 #ifdef __has_attribute
572 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
574 #define GPR_HAS_ATTRIBUTE(a) 0
576 #endif /* GPR_HAS_ATTRIBUTE */
578 #ifndef GPR_HAS_FEATURE
580 #define GPR_HAS_FEATURE(a) __has_feature(a)
582 #define GPR_HAS_FEATURE(a) 0
584 #endif /* GPR_HAS_FEATURE */
586 #ifndef GPR_ATTRIBUTE_NOINLINE
587 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
588 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
589 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
591 #define GPR_ATTRIBUTE_NOINLINE
593 #endif /* GPR_ATTRIBUTE_NOINLINE */
595 #ifndef GPR_NO_UNIQUE_ADDRESS
596 #if GPR_HAS_CPP_ATTRIBUTE(no_unique_address)
597 #define GPR_NO_UNIQUE_ADDRESS [[no_unique_address]]
599 #define GPR_NO_UNIQUE_ADDRESS
601 #endif /* GPR_NO_UNIQUE_ADDRESS */
603 #ifndef GRPC_DEPRECATED
604 #if GPR_HAS_CPP_ATTRIBUTE(deprecated)
605 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
607 #define GRPC_DEPRECATED(reason)
609 #endif /* GRPC_DEPRECATED */
611 #ifndef GPR_ATTRIBUTE_WEAK
612 /* Attribute weak is broken on LLVM/windows:
613 * https://bugs.llvm.org/show_bug.cgi?id=37598 */
614 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
615 !(defined(__llvm__) && defined(_WIN32))
616 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
617 #define GPR_HAS_ATTRIBUTE_WEAK 1
619 #define GPR_ATTRIBUTE_WEAK
621 #endif /* GPR_ATTRIBUTE_WEAK */
623 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
624 #if GPR_HAS_FEATURE(thread_sanitizer)
625 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
626 #endif /* GPR_HAS_FEATURE */
627 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
628 #define GPR_ATTRIBUTE_NO_TSAN
629 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
630 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
632 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
633 #ifndef GRPC_TSAN_SUPPRESSED
634 #if defined(__SANITIZE_THREAD__)
635 #define GRPC_TSAN_ENABLED
636 #elif GPR_HAS_FEATURE(thread_sanitizer)
637 #define GRPC_TSAN_ENABLED
641 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
642 #ifndef GRPC_ASAN_SUPPRESSED
643 #if defined(__SANITIZE_ADDRESS__)
644 #define GRPC_ASAN_ENABLED
645 #elif GPR_HAS_FEATURE(address_sanitizer)
646 #define GRPC_ASAN_ENABLED
650 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
651 #ifndef GRPC_ALLOW_EXCEPTIONS
653 #if defined(_MSC_VER) && defined(_CPPUNWIND)
654 #define GRPC_ALLOW_EXCEPTIONS 1
655 #elif defined(__EXCEPTIONS)
656 #define GRPC_ALLOW_EXCEPTIONS 1
658 #define GRPC_ALLOW_EXCEPTIONS 0
660 #else /* GPR_WINDOWS */
662 #define GRPC_ALLOW_EXCEPTIONS 1
663 #else /* __EXCEPTIONS */
664 #define GRPC_ALLOW_EXCEPTIONS 0
665 #endif /* __EXCEPTIONS */
666 #endif /* __GPR_WINDOWS */
667 #endif /* GRPC_ALLOW_EXCEPTIONS */
669 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
670 * most likely. Ideally, also collect performance numbers to justify the claim.
673 #define GPR_LIKELY(x) __builtin_expect((x), 1)
674 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
676 #define GPR_LIKELY(x) (x)
677 #define GPR_UNLIKELY(x) (x)
678 #endif /* __GNUC__ */
680 #ifndef __STDC_FORMAT_MACROS
681 #define __STDC_FORMAT_MACROS
684 /* Selectively enable EventEngine on specific platforms. This default can be
685 * overridden using the GRPC_USE_EVENT_ENGINE compiler flag.
687 #ifndef GRPC_USE_EVENT_ENGINE
688 /* Not enabled by default on any platforms yet. (2021.06) */
689 #elif GRPC_USE_EVENT_ENGINE == 0
690 /* Building with `-DGRPC_USE_EVENT_ENGINE=0` will override the default. */
691 #undef GRPC_USE_EVENT_ENGINE
692 #endif /* GRPC_USE_EVENT_ENGINE */
694 #ifdef GRPC_USE_EVENT_ENGINE
695 #undef GPR_SUPPORT_CHANNELS_FROM_FD
697 #endif /* GRPC_USE_EVENT_ENGINE */
699 #define GRPC_CALLBACK_API_NONEXPERIMENTAL
701 /* clang 11 with msan miscompiles destruction of [[no_unique_address]] members
702 * of zero size - for a repro see:
703 * test/core/compiler_bugs/miscompile_with_no_unique_address_test.cc
706 #if __clang__ && __clang_major__ <= 11 && __has_feature(memory_sanitizer)
707 #undef GPR_NO_UNIQUE_ADDRESS
708 #define GPR_NO_UNIQUE_ADDRESS
712 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */