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
23 * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI
24 * compatible with older platforms (currently only on Linux)
26 * - some libc calls to be gotten via dlsym
27 * - some syscalls to be made directly
31 * Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil
33 #ifndef GPR_ABSEIL_SYNC
34 #if defined(__APPLE__)
35 // This is disabled on Apple platforms because macos/grpc_basictests_c_cpp
36 // fails with this. https://github.com/grpc/grpc/issues/23661
38 #define GPR_ABSEIL_SYNC 1
40 #endif // GPR_ABSEIL_SYNC
43 * Defines GRPC_ERROR_IS_ABSEIL_STATUS to use absl::Status for grpc_error_handle
45 // #define GRPC_ERROR_IS_ABSEIL_STATUS 1
47 /* Get windows.h included everywhere (we need it) */
48 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
49 #ifndef WIN32_LEAN_AND_MEAN
50 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
51 #define WIN32_LEAN_AND_MEAN
52 #endif /* WIN32_LEAN_AND_MEAN */
55 #define GRPC_NOMINMX_WAS_NOT_DEFINED
63 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
64 #else /* !defined(_WIN32_WINNT) */
65 #if (_WIN32_WINNT < 0x0600)
67 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
68 #endif /* _WIN32_WINNT < 0x0600 */
69 #endif /* defined(_WIN32_WINNT) */
71 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
72 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
73 #undef WIN32_LEAN_AND_MEAN
74 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
76 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
77 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
79 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
80 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
83 /* Override this file with one for your platform if you need to redefine
86 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
87 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
88 #if defined(_WIN64) || defined(WIN64)
93 #define GPR_PLATFORM_STRING "windows"
95 #define GPR_WINDOWS_SUBPROCESS 1
96 #define GPR_WINDOWS_ENV
98 #define GPR_GETPID_IN_UNISTD_H 1
99 #define GPR_MSYS_TMPFILE
100 #define GPR_POSIX_LOG
101 #define GPR_POSIX_STRING
102 #define GPR_POSIX_TIME
104 #define GPR_GETPID_IN_PROCESS_H 1
105 #define GPR_WINDOWS_TMPFILE
106 #define GPR_WINDOWS_LOG
107 #define GPR_WINDOWS_CRASH_HANDLER 1
108 #define GPR_WINDOWS_STAT
109 #define GPR_WINDOWS_STRING
110 #define GPR_WINDOWS_TIME
113 #define GPR_GCC_ATOMIC 1
115 #define GPR_WINDOWS_ATOMIC 1
117 #define GPR_STDCPP_TLS 1
118 #elif defined(ANDROID) || defined(__ANDROID__)
119 #define GPR_PLATFORM_STRING "android"
120 #define GPR_ANDROID 1
121 // TODO(apolcyn): re-evaluate support for c-ares
122 // on android after upgrading our c-ares dependency.
123 // See https://github.com/grpc/grpc/issues/18038.
126 #define GPR_ARCH_64 1
128 #define GPR_ARCH_32 1
130 #define GPR_CPU_POSIX 1
131 #define GPR_GCC_SYNC 1
132 #define GPR_STDCPP_TLS 1
133 #define GPR_POSIX_ENV 1
134 #define GPR_POSIX_TMPFILE 1
135 #define GPR_POSIX_STAT 1
136 #define GPR_ANDROID_LOG 1
137 #define GPR_POSIX_STRING 1
138 #define GPR_POSIX_SUBPROCESS 1
139 #define GPR_POSIX_SYNC 1
140 #define GPR_POSIX_TIME 1
141 #define GPR_HAS_PTHREAD_H 1
142 #define GPR_GETPID_IN_UNISTD_H 1
143 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
144 #elif defined(__linux__)
145 #define GPR_PLATFORM_STRING "linux"
149 #ifndef _DEFAULT_SOURCE
150 #define _DEFAULT_SOURCE
155 #include <features.h>
156 #define GPR_CPU_LINUX 1
157 #define GPR_GCC_ATOMIC 1
158 #define GPR_STDCPP_TLS 1
160 #define GPR_LINUX_LOG
161 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
162 #define GPR_LINUX_ENV 1
163 #define GPR_POSIX_TMPFILE 1
164 #define GPR_POSIX_STAT 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_HAS_PTHREAD_H 1
170 #define GPR_GETPID_IN_UNISTD_H 1
172 #define GPR_ARCH_64 1
174 #define GPR_ARCH_32 1
177 #define GPR_POSIX_CRASH_HANDLER 1
178 #define GPR_LINUX_PTHREAD_NAME 1
179 #include <linux/version.h>
180 #else /* musl libc */
181 #define GPR_MUSL_LIBC_COMPAT 1
183 #elif defined(__ASYLO__)
184 #define GPR_ARCH_64 1
185 #define GPR_CPU_POSIX 1
186 #define GPR_GCC_TLS 1
187 #define GPR_PLATFORM_STRING "asylo"
188 #define GPR_GCC_SYNC 1
189 #define GPR_POSIX_SYNC 1
190 #define GPR_POSIX_STRING 1
191 #define GPR_POSIX_LOG 1
192 #define GPR_POSIX_TIME 1
193 #define GPR_POSIX_ENV 1
195 #define GRPC_POSIX_SOCKET 1
196 #define GRPC_POSIX_SOCKETADDR
197 #define GRPC_POSIX_SOCKETUTILS 1
198 #define GRPC_TIMER_USE_GENERIC 1
199 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
200 #define GRPC_POSIX_WAKEUP_FD 1
202 #define GPR_NO_AUTODETECT_PLATFORM 1
203 #elif defined(__APPLE__)
204 #include <Availability.h>
205 #include <TargetConditionals.h>
210 #define GPR_PLATFORM_STRING "ios"
211 #define GPR_CPU_IPHONE 1
212 #define GRPC_CFSTREAM 1
213 /* the c-ares resolver isn't safe to enable on iOS */
215 #else /* TARGET_OS_IPHONE */
216 #define GPR_PLATFORM_STRING "osx"
217 #define GPR_CPU_POSIX 1
218 #define GPR_POSIX_CRASH_HANDLER 1
221 #if __has_feature(cxx_thread_local)
222 #define GPR_STDCPP_TLS 1
225 #ifndef GPR_STDCPP_TLS
226 #define GPR_PTHREAD_TLS 1
229 #define GPR_GCC_ATOMIC 1
230 #define GPR_POSIX_LOG 1
231 #define GPR_POSIX_ENV 1
232 #define GPR_POSIX_TMPFILE 1
233 #define GPR_POSIX_STAT 1
234 #define GPR_POSIX_STRING 1
235 #define GPR_POSIX_SUBPROCESS 1
236 #define GPR_POSIX_SYNC 1
237 #define GPR_POSIX_TIME 1
238 #define GPR_HAS_PTHREAD_H 1
239 #define GPR_GETPID_IN_UNISTD_H 1
240 #ifndef GRPC_CFSTREAM
241 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
244 #define GPR_ARCH_64 1
246 #define GPR_ARCH_32 1
248 #elif defined(__FreeBSD__)
249 #define GPR_PLATFORM_STRING "freebsd"
253 #define GPR_FREEBSD 1
254 #define GPR_CPU_POSIX 1
255 #define GPR_GCC_ATOMIC 1
256 #define GPR_GCC_TLS 1
257 #define GPR_POSIX_LOG 1
258 #define GPR_POSIX_ENV 1
259 #define GPR_POSIX_TMPFILE 1
260 #define GPR_POSIX_STAT 1
261 #define GPR_POSIX_STRING 1
262 #define GPR_POSIX_SUBPROCESS 1
263 #define GPR_POSIX_SYNC 1
264 #define GPR_POSIX_TIME 1
265 #define GPR_HAS_PTHREAD_H 1
266 #define GPR_GETPID_IN_UNISTD_H 1
267 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
269 #define GPR_ARCH_64 1
271 #define GPR_ARCH_32 1
273 #elif defined(__OpenBSD__)
274 #define GPR_PLATFORM_STRING "openbsd"
278 #define GPR_OPENBSD 1
279 #define GPR_CPU_POSIX 1
280 #define GPR_GCC_ATOMIC 1
281 #define GPR_GCC_TLS 1
282 #define GPR_POSIX_LOG 1
283 #define GPR_POSIX_ENV 1
284 #define GPR_POSIX_TMPFILE 1
285 #define GPR_POSIX_STAT 1
286 #define GPR_POSIX_STRING 1
287 #define GPR_POSIX_SUBPROCESS 1
288 #define GPR_POSIX_SYNC 1
289 #define GPR_POSIX_TIME 1
290 #define GPR_HAS_PTHREAD_H 1
291 #define GPR_GETPID_IN_UNISTD_H 1
292 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
294 #define GPR_ARCH_64 1
296 #define GPR_ARCH_32 1
298 #elif defined(__sun) && defined(__SVR4)
299 #define GPR_PLATFORM_STRING "solaris"
300 #define GPR_SOLARIS 1
301 #define GPR_CPU_POSIX 1
302 #define GPR_GCC_ATOMIC 1
303 #define GPR_GCC_TLS 1
304 #define GPR_POSIX_LOG 1
305 #define GPR_POSIX_ENV 1
306 #define GPR_POSIX_TMPFILE 1
307 #define GPR_POSIX_STAT 1
308 #define GPR_POSIX_STRING 1
309 #define GPR_POSIX_SUBPROCESS 1
310 #define GPR_POSIX_SYNC 1
311 #define GPR_POSIX_TIME 1
312 #define GPR_HAS_PTHREAD_H 1
313 #define GPR_GETPID_IN_UNISTD_H 1
315 #define GPR_ARCH_64 1
317 #define GPR_ARCH_32 1
320 #define GPR_PLATFORM_STRING "aix"
325 #define GPR_CPU_POSIX 1
326 #define GPR_GCC_ATOMIC 1
327 #define GPR_GCC_TLS 1
328 #define GPR_POSIX_LOG 1
329 #define GPR_POSIX_ENV 1
330 #define GPR_POSIX_TMPFILE 1
331 #define GPR_POSIX_STAT 1
332 #define GPR_POSIX_STRING 1
333 #define GPR_POSIX_SUBPROCESS 1
334 #define GPR_POSIX_SYNC 1
335 #define GPR_POSIX_TIME 1
336 #define GPR_HAS_PTHREAD_H 1
337 #define GPR_GETPID_IN_UNISTD_H 1
339 #define GPR_ARCH_64 1
341 #define GPR_ARCH_32 1
343 #elif defined(__native_client__)
344 #define GPR_PLATFORM_STRING "nacl"
348 #ifndef _DEFAULT_SOURCE
349 #define _DEFAULT_SOURCE
355 #define GPR_CPU_POSIX 1
356 #define GPR_GCC_ATOMIC 1
357 #define GPR_GCC_TLS 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_PTHREAD_TLS 1
385 #define GPR_POSIX_LOG 1
386 #define GPR_POSIX_SYNC 1
387 #define GPR_POSIX_ENV 1
388 #define GPR_POSIX_TMPFILE 1
389 #define GPR_POSIX_STAT 1
390 #define GPR_POSIX_SUBPROCESS 1
391 #define GPR_POSIX_SYNC 1
392 #define GPR_POSIX_STRING 1
393 #define GPR_POSIX_TIME 1
394 #define GPR_HAS_PTHREAD_H 1
395 #define GPR_GETPID_IN_UNISTD_H 1
396 #define GRPC_ROOT_PEM_PATH "/config/ssl/cert.pem"
398 #error "Could not auto-detect platform"
400 #endif /* GPR_NO_AUTODETECT_PLATFORM */
402 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
404 * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
405 * a library from having non-standard symbols such as __asprintf_chk.
406 * This helps non-glibc systems such as alpine using musl to find symbols.
408 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
409 #undef _FORTIFY_SOURCE
410 #define _FORTIFY_SOURCE 0
414 #if defined(__has_include)
415 #if __has_include(<atomic>)
416 #define GRPC_HAS_CXX11_ATOMIC
417 #endif /* __has_include(<atomic>) */
418 #endif /* defined(__has_include) */
420 #ifndef GPR_PLATFORM_STRING
421 #warning "GPR_PLATFORM_STRING not auto-detected"
422 #define GPR_PLATFORM_STRING "unknown"
426 #undef GPR_FORBID_UNREACHABLE_CODE
427 #define GPR_FORBID_UNREACHABLE_CODE 1
432 typedef __int8 int8_t;
433 typedef __int16 int16_t;
434 typedef __int32 int32_t;
435 typedef __int64 int64_t;
436 typedef unsigned __int8 uint8_t;
437 typedef unsigned __int16 uint16_t;
438 typedef unsigned __int32 uint32_t;
439 typedef unsigned __int64 uint64_t;
442 #endif /* _MSC_VER < 1700 */
445 #endif /* _MSC_VER */
447 /* Type of cycle clock implementation */
449 /* Disable cycle clock by default.
450 TODO(soheil): enable when we support fallback for unstable cycle clocks.
451 #if defined(__i386__)
452 #define GPR_CYCLE_COUNTER_RDTSC_32 1
453 #elif defined(__x86_64__) || defined(__amd64__)
454 #define GPR_CYCLE_COUNTER_RDTSC_64 1
456 #define GPR_CYCLE_COUNTER_FALLBACK 1
459 #define GPR_CYCLE_COUNTER_FALLBACK 1
461 #define GPR_CYCLE_COUNTER_FALLBACK 1
462 #endif /* GPR_LINUX */
464 /* Cache line alignment */
465 #ifndef GPR_CACHELINE_SIZE_LOG
466 #if defined(__i386__) || defined(__x86_64__)
467 #define GPR_CACHELINE_SIZE_LOG 6
469 #ifndef GPR_CACHELINE_SIZE_LOG
470 /* A reasonable default guess. Note that overestimates tend to waste more
471 space, while underestimates tend to waste more time. */
472 #define GPR_CACHELINE_SIZE_LOG 6
473 #endif /* GPR_CACHELINE_SIZE_LOG */
474 #endif /* GPR_CACHELINE_SIZE_LOG */
476 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
478 /* scrub GCC_ATOMIC if it's not available on this compiler */
479 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
480 #undef GPR_GCC_ATOMIC
481 #define GPR_GCC_SYNC 1
484 /* Validate platform combinations */
485 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
486 defined(GPR_WINDOWS_ATOMIC) != \
488 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
491 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
492 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
495 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
496 defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
498 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
501 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
502 defined(GPR_STDCPP_TLS) + defined(GPR_CUSTOM_TLS) != \
504 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_STDCPP_TLS, GPR_CUSTOM_TLS
507 /* maximum alignment needed for any type on this platform, rounded up to a
509 #define GPR_MAX_ALIGNMENT 16
515 #ifndef GRPC_IF_NAMETOINDEX
516 #define GRPC_IF_NAMETOINDEX 1
519 #ifndef GRPC_MUST_USE_RESULT
520 #if defined(__GNUC__) && !defined(__MINGW32__)
521 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
522 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
524 #define GRPC_MUST_USE_RESULT
525 #define GPR_ALIGN_STRUCT(n)
530 #if defined(__GNUC__) && !defined(__MINGW32__)
531 #define GRPC_UNUSED __attribute__((unused))
537 #ifndef GPR_PRINT_FORMAT_CHECK
539 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
540 __attribute__((format(printf, FORMAT_STR, ARGS)))
542 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
544 #endif /* GPR_PRINT_FORMAT_CHECK */
546 #if GPR_FORBID_UNREACHABLE_CODE
547 #define GPR_UNREACHABLE_CODE(STATEMENT)
549 #define GPR_UNREACHABLE_CODE(STATEMENT) \
551 gpr_log(GPR_ERROR, "Should never reach here."); \
555 #endif /* GPR_FORBID_UNREACHABLE_CODE */
562 #define GRPCAPI GPRAPI
566 #define CENSUSAPI GRPCAPI
569 #ifndef GPR_HAS_CPP_ATTRIBUTE
570 #ifdef __has_cpp_attribute
571 #define GPR_HAS_CPP_ATTRIBUTE(a) __has_cpp_attribute(a)
573 #define GPR_HAS_CPP_ATTRIBUTE(a) 0
575 #endif /* GPR_HAS_CPP_ATTRIBUTE */
577 #ifndef GPR_HAS_ATTRIBUTE
578 #ifdef __has_attribute
579 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
581 #define GPR_HAS_ATTRIBUTE(a) 0
583 #endif /* GPR_HAS_ATTRIBUTE */
585 #ifndef GPR_HAS_FEATURE
587 #define GPR_HAS_FEATURE(a) __has_feature(a)
589 #define GPR_HAS_FEATURE(a) 0
591 #endif /* GPR_HAS_FEATURE */
593 #ifndef GPR_ATTRIBUTE_NOINLINE
594 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
595 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
596 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
598 #define GPR_ATTRIBUTE_NOINLINE
600 #endif /* GPR_ATTRIBUTE_NOINLINE */
602 #ifndef GPR_NO_UNIQUE_ADDRESS
603 #if GPR_HAS_CPP_ATTRIBUTE(no_unique_address)
604 #define GPR_NO_UNIQUE_ADDRESS [[no_unique_address]]
606 #define GPR_NO_UNIQUE_ADDRESS
608 #endif /* GPR_NO_UNIQUE_ADDRESS */
610 #ifndef GRPC_DEPRECATED
611 #if GPR_HAS_CPP_ATTRIBUTE(deprecated)
612 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
614 #define GRPC_DEPRECATED(reason)
616 #endif /* GRPC_DEPRECATED */
618 #ifndef GPR_ATTRIBUTE_WEAK
619 /* Attribute weak is broken on LLVM/windows:
620 * https://bugs.llvm.org/show_bug.cgi?id=37598 */
621 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
622 !(defined(__llvm__) && defined(_WIN32))
623 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
624 #define GPR_HAS_ATTRIBUTE_WEAK 1
626 #define GPR_ATTRIBUTE_WEAK
628 #endif /* GPR_ATTRIBUTE_WEAK */
630 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
631 #if GPR_HAS_FEATURE(thread_sanitizer)
632 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
633 #endif /* GPR_HAS_FEATURE */
634 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
635 #define GPR_ATTRIBUTE_NO_TSAN
636 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
637 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
639 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
640 #ifndef GRPC_TSAN_SUPPRESSED
641 #if defined(__SANITIZE_THREAD__)
642 #define GRPC_TSAN_ENABLED
643 #elif GPR_HAS_FEATURE(thread_sanitizer)
644 #define GRPC_TSAN_ENABLED
648 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
649 #ifndef GRPC_ASAN_SUPPRESSED
650 #if defined(__SANITIZE_ADDRESS__)
651 #define GRPC_ASAN_ENABLED
652 #elif GPR_HAS_FEATURE(address_sanitizer)
653 #define GRPC_ASAN_ENABLED
657 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
658 #ifndef GRPC_ALLOW_EXCEPTIONS
660 #if defined(_MSC_VER) && defined(_CPPUNWIND)
661 #define GRPC_ALLOW_EXCEPTIONS 1
662 #elif defined(__EXCEPTIONS)
663 #define GRPC_ALLOW_EXCEPTIONS 1
665 #define GRPC_ALLOW_EXCEPTIONS 0
667 #else /* GPR_WINDOWS */
669 #define GRPC_ALLOW_EXCEPTIONS 1
670 #else /* __EXCEPTIONS */
671 #define GRPC_ALLOW_EXCEPTIONS 0
672 #endif /* __EXCEPTIONS */
673 #endif /* __GPR_WINDOWS */
674 #endif /* GRPC_ALLOW_EXCEPTIONS */
676 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
677 * most likely. Ideally, also collect performance numbers to justify the claim.
680 #define GPR_LIKELY(x) __builtin_expect((x), 1)
681 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
683 #define GPR_LIKELY(x) (x)
684 #define GPR_UNLIKELY(x) (x)
685 #endif /* __GNUC__ */
687 #ifndef __STDC_FORMAT_MACROS
688 #define __STDC_FORMAT_MACROS
691 /* Selectively enable EventEngine on specific platforms. This default can be
692 * overridden using the GRPC_USE_EVENT_ENGINE compiler flag.
694 #ifndef GRPC_USE_EVENT_ENGINE
695 /* Not enabled by default on any platforms yet. (2021.06) */
696 #elif GRPC_USE_EVENT_ENGINE == 0
697 /* Building with `-DGRPC_USE_EVENT_ENGINE=0` will override the default. */
698 #undef GRPC_USE_EVENT_ENGINE
699 #endif /* GRPC_USE_EVENT_ENGINE */
701 #ifdef GRPC_USE_EVENT_ENGINE
702 #undef GPR_SUPPORT_CHANNELS_FROM_FD
704 #endif /* GRPC_USE_EVENT_ENGINE */
706 #define GRPC_CALLBACK_API_NONEXPERIMENTAL
708 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */