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
42 /* Get windows.h included everywhere (we need it) */
43 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
44 #ifndef WIN32_LEAN_AND_MEAN
45 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
46 #define WIN32_LEAN_AND_MEAN
47 #endif /* WIN32_LEAN_AND_MEAN */
50 #define GRPC_NOMINMX_WAS_NOT_DEFINED
58 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
59 #else /* !defined(_WIN32_WINNT) */
60 #if (_WIN32_WINNT < 0x0600)
62 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
63 #endif /* _WIN32_WINNT < 0x0600 */
64 #endif /* defined(_WIN32_WINNT) */
66 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
67 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
68 #undef WIN32_LEAN_AND_MEAN
69 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
71 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
72 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
74 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
75 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
78 /* Override this file with one for your platform if you need to redefine
81 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
82 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
83 #if defined(_WIN64) || defined(WIN64)
88 #define GPR_PLATFORM_STRING "windows"
90 #define GPR_WINDOWS_SUBPROCESS 1
91 #define GPR_WINDOWS_ENV
93 #define GPR_GETPID_IN_UNISTD_H 1
94 #define GPR_MSYS_TMPFILE
96 #define GPR_POSIX_STRING
97 #define GPR_POSIX_TIME
99 #define GPR_GETPID_IN_PROCESS_H 1
100 #define GPR_WINDOWS_TMPFILE
101 #define GPR_WINDOWS_LOG
102 #define GPR_WINDOWS_CRASH_HANDLER 1
103 #define GPR_WINDOWS_STRING
104 #define GPR_WINDOWS_TIME
107 #define GPR_GCC_ATOMIC 1
108 #define GPR_GCC_TLS 1
110 #define GPR_WINDOWS_ATOMIC 1
111 #define GPR_MSVC_TLS 1
113 #elif defined(ANDROID) || defined(__ANDROID__)
114 #define GPR_PLATFORM_STRING "android"
115 #define GPR_ANDROID 1
116 // TODO(apolcyn): re-evaluate support for c-ares
117 // on android after upgrading our c-ares dependency.
118 // See https://github.com/grpc/grpc/issues/18038.
121 #define GPR_ARCH_64 1
123 #define GPR_ARCH_32 1
125 #define GPR_CPU_POSIX 1
126 #define GPR_GCC_SYNC 1
127 #define GPR_GCC_TLS 1
128 #define GPR_POSIX_ENV 1
129 #define GPR_POSIX_TMPFILE 1
130 #define GPR_ANDROID_LOG 1
131 #define GPR_POSIX_STRING 1
132 #define GPR_POSIX_SUBPROCESS 1
133 #define GPR_POSIX_SYNC 1
134 #define GPR_POSIX_TIME 1
135 #define GPR_HAS_PTHREAD_H 1
136 #define GPR_GETPID_IN_UNISTD_H 1
137 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
138 #elif defined(__linux__)
139 #define GPR_PLATFORM_STRING "linux"
143 #ifndef _DEFAULT_SOURCE
144 #define _DEFAULT_SOURCE
149 #include <features.h>
150 #define GPR_CPU_LINUX 1
151 #define GPR_GCC_ATOMIC 1
152 #define GPR_GCC_TLS 1
154 #define GPR_LINUX_LOG
155 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
156 #define GPR_LINUX_ENV 1
157 #define GPR_POSIX_TMPFILE 1
158 #define GPR_POSIX_STRING 1
159 #define GPR_POSIX_SUBPROCESS 1
160 #define GPR_POSIX_SYNC 1
161 #define GPR_POSIX_TIME 1
162 #define GPR_HAS_PTHREAD_H 1
163 #define GPR_GETPID_IN_UNISTD_H 1
165 #define GPR_ARCH_64 1
167 #define GPR_ARCH_32 1
170 #define GPR_POSIX_CRASH_HANDLER 1
171 #define GPR_LINUX_PTHREAD_NAME 1
172 #include <linux/version.h>
173 #else /* musl libc */
174 #define GPR_MUSL_LIBC_COMPAT 1
176 #elif defined(__ASYLO__)
177 #define GPR_ARCH_64 1
178 #define GPR_CPU_POSIX 1
179 #define GPR_GCC_TLS 1
180 #define GPR_PLATFORM_STRING "asylo"
181 #define GPR_GCC_SYNC 1
182 #define GPR_POSIX_SYNC 1
183 #define GPR_POSIX_STRING 1
184 #define GPR_POSIX_LOG 1
185 #define GPR_POSIX_TIME 1
186 #define GPR_POSIX_ENV 1
188 #define GRPC_POSIX_SOCKET 1
189 #define GRPC_POSIX_SOCKETADDR
190 #define GRPC_POSIX_SOCKETUTILS 1
191 #define GRPC_TIMER_USE_GENERIC 1
192 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
193 #define GRPC_POSIX_WAKEUP_FD 1
195 #define GPR_NO_AUTODETECT_PLATFORM 1
196 #elif defined(__APPLE__)
197 #include <Availability.h>
198 #include <TargetConditionals.h>
203 #define GPR_PLATFORM_STRING "ios"
204 #define GPR_CPU_IPHONE 1
205 #define GPR_PTHREAD_TLS 1
206 #define GRPC_CFSTREAM 1
207 /* the c-ares resolver isn't safe to enable on iOS */
209 #else /* TARGET_OS_IPHONE */
210 #define GPR_PLATFORM_STRING "osx"
211 #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
212 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7
213 #define GPR_CPU_IPHONE 1
214 #define GPR_PTHREAD_TLS 1
215 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 */
216 #define GPR_CPU_POSIX 1
217 /* TODO(vjpai): there is a reported issue in bazel build for Mac where __thread
218 in a header is currently not working (bazelbuild/bazel#4341). Remove
219 the following conditional and use GPR_GCC_TLS when that is fixed */
220 #ifndef GRPC_BAZEL_BUILD
221 #define GPR_GCC_TLS 1
222 #else /* GRPC_BAZEL_BUILD */
223 #define GPR_PTHREAD_TLS 1
224 #endif /* GRPC_BAZEL_BUILD */
225 #define GPR_APPLE_PTHREAD_NAME 1
227 #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */
228 #define GPR_CPU_POSIX 1
229 /* TODO(vjpai): Remove the following conditional and use only GPR_GCC_TLS
230 when bazelbuild/bazel#4341 is fixed */
231 #ifndef GRPC_BAZEL_BUILD
232 #define GPR_GCC_TLS 1
233 #else /* GRPC_BAZEL_BUILD */
234 #define GPR_PTHREAD_TLS 1
235 #endif /* GRPC_BAZEL_BUILD */
237 #define GPR_POSIX_CRASH_HANDLER 1
240 #define GPR_GCC_ATOMIC 1
241 #define GPR_POSIX_LOG 1
242 #define GPR_POSIX_ENV 1
243 #define GPR_POSIX_TMPFILE 1
244 #define GPR_POSIX_STRING 1
245 #define GPR_POSIX_SUBPROCESS 1
246 #define GPR_POSIX_SYNC 1
247 #define GPR_POSIX_TIME 1
248 #define GPR_HAS_PTHREAD_H 1
249 #define GPR_GETPID_IN_UNISTD_H 1
250 #ifndef GRPC_CFSTREAM
251 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
254 #define GPR_ARCH_64 1
256 #define GPR_ARCH_32 1
258 #elif defined(__FreeBSD__)
259 #define GPR_PLATFORM_STRING "freebsd"
263 #define GPR_FREEBSD 1
264 #define GPR_CPU_POSIX 1
265 #define GPR_GCC_ATOMIC 1
266 #define GPR_GCC_TLS 1
267 #define GPR_POSIX_LOG 1
268 #define GPR_POSIX_ENV 1
269 #define GPR_POSIX_TMPFILE 1
270 #define GPR_POSIX_STRING 1
271 #define GPR_POSIX_SUBPROCESS 1
272 #define GPR_POSIX_SYNC 1
273 #define GPR_POSIX_TIME 1
274 #define GPR_HAS_PTHREAD_H 1
275 #define GPR_GETPID_IN_UNISTD_H 1
276 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
278 #define GPR_ARCH_64 1
280 #define GPR_ARCH_32 1
282 #elif defined(__OpenBSD__)
283 #define GPR_PLATFORM_STRING "openbsd"
287 #define GPR_OPENBSD 1
288 #define GPR_CPU_POSIX 1
289 #define GPR_GCC_ATOMIC 1
290 #define GPR_GCC_TLS 1
291 #define GPR_POSIX_LOG 1
292 #define GPR_POSIX_ENV 1
293 #define GPR_POSIX_TMPFILE 1
294 #define GPR_POSIX_STRING 1
295 #define GPR_POSIX_SUBPROCESS 1
296 #define GPR_POSIX_SYNC 1
297 #define GPR_POSIX_TIME 1
298 #define GPR_HAS_PTHREAD_H 1
299 #define GPR_GETPID_IN_UNISTD_H 1
300 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
302 #define GPR_ARCH_64 1
304 #define GPR_ARCH_32 1
306 #elif defined(__sun) && defined(__SVR4)
307 #define GPR_PLATFORM_STRING "solaris"
308 #define GPR_SOLARIS 1
309 #define GPR_CPU_POSIX 1
310 #define GPR_GCC_ATOMIC 1
311 #define GPR_GCC_TLS 1
312 #define GPR_POSIX_LOG 1
313 #define GPR_POSIX_ENV 1
314 #define GPR_POSIX_TMPFILE 1
315 #define GPR_POSIX_STRING 1
316 #define GPR_POSIX_SUBPROCESS 1
317 #define GPR_POSIX_SYNC 1
318 #define GPR_POSIX_TIME 1
319 #define GPR_HAS_PTHREAD_H 1
320 #define GPR_GETPID_IN_UNISTD_H 1
322 #define GPR_ARCH_64 1
324 #define GPR_ARCH_32 1
327 #define GPR_PLATFORM_STRING "aix"
332 #define GPR_CPU_POSIX 1
333 #define GPR_GCC_ATOMIC 1
334 #define GPR_GCC_TLS 1
335 #define GPR_POSIX_LOG 1
336 #define GPR_POSIX_ENV 1
337 #define GPR_POSIX_TMPFILE 1
338 #define GPR_POSIX_STRING 1
339 #define GPR_POSIX_SUBPROCESS 1
340 #define GPR_POSIX_SYNC 1
341 #define GPR_POSIX_TIME 1
342 #define GPR_HAS_PTHREAD_H 1
343 #define GPR_GETPID_IN_UNISTD_H 1
345 #define GPR_ARCH_64 1
347 #define GPR_ARCH_32 1
349 #elif defined(__native_client__)
350 #define GPR_PLATFORM_STRING "nacl"
354 #ifndef _DEFAULT_SOURCE
355 #define _DEFAULT_SOURCE
361 #define GPR_CPU_POSIX 1
362 #define GPR_GCC_ATOMIC 1
363 #define GPR_GCC_TLS 1
364 #define GPR_POSIX_LOG 1
365 #define GPR_POSIX_ENV 1
366 #define GPR_POSIX_TMPFILE 1
367 #define GPR_POSIX_STRING 1
368 #define GPR_POSIX_SUBPROCESS 1
369 #define GPR_POSIX_SYNC 1
370 #define GPR_POSIX_TIME 1
371 #define GPR_HAS_PTHREAD_H 1
372 #define GPR_GETPID_IN_UNISTD_H 1
374 #define GPR_ARCH_64 1
376 #define GPR_ARCH_32 1
378 #elif defined(__Fuchsia__)
379 #define GPR_FUCHSIA 1
380 #define GPR_ARCH_64 1
381 #define GPR_PLATFORM_STRING "fuchsia"
382 #include <features.h>
383 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
385 #define GPR_MUSL_LIBC_COMPAT 1
386 #define GPR_CPU_POSIX 1
387 #define GPR_GCC_ATOMIC 1
388 #define GPR_PTHREAD_TLS 1
389 #define GPR_POSIX_LOG 1
390 #define GPR_POSIX_SYNC 1
391 #define GPR_POSIX_ENV 1
392 #define GPR_POSIX_TMPFILE 1
393 #define GPR_POSIX_SUBPROCESS 1
394 #define GPR_POSIX_SYNC 1
395 #define GPR_POSIX_STRING 1
396 #define GPR_POSIX_TIME 1
397 #define GPR_HAS_PTHREAD_H 1
398 #define GPR_GETPID_IN_UNISTD_H 1
400 #error "Could not auto-detect platform"
402 #endif /* GPR_NO_AUTODETECT_PLATFORM */
404 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
406 * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
407 * a library from having non-standard symbols such as __asprintf_chk.
408 * This helps non-glibc systems such as alpine using musl to find symbols.
410 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
411 #undef _FORTIFY_SOURCE
412 #define _FORTIFY_SOURCE 0
417 * There are platforms for which TLS should not be used even though the
418 * compiler makes it seem like it's supported (Android NDK < r12b for example).
419 * This is primarily because of linker problems and toolchain misconfiguration:
420 * TLS isn't supported until NDK r12b per
421 * https://developer.android.com/ndk/downloads/revision_history.html
422 * TLS also does not work with Android NDK if GCC is being used as the compiler
424 * Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
425 * <android/ndk-version.h>. For NDK < r16, users should define these macros,
426 * e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11. */
427 #if defined(__ANDROID__) && defined(GPR_GCC_TLS)
428 #if __has_include(<android/ndk-version.h>)
429 #include <android/ndk-version.h>
430 #endif /* __has_include(<android/ndk-version.h>) */
431 #if (defined(__clang__) && defined(__NDK_MAJOR__) && defined(__NDK_MINOR__) && \
432 ((__NDK_MAJOR__ < 12) || \
433 ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))) || \
434 (defined(__GNUC__) && !defined(__clang__))
436 #define GPR_PTHREAD_TLS 1
438 #endif /*defined(__ANDROID__) && defined(GPR_GCC_TLS) */
440 #if defined(__has_include)
441 #if __has_include(<atomic>)
442 #define GRPC_HAS_CXX11_ATOMIC
443 #endif /* __has_include(<atomic>) */
444 #endif /* defined(__has_include) */
446 #ifndef GPR_PLATFORM_STRING
447 #warning "GPR_PLATFORM_STRING not auto-detected"
448 #define GPR_PLATFORM_STRING "unknown"
452 #undef GPR_FORBID_UNREACHABLE_CODE
453 #define GPR_FORBID_UNREACHABLE_CODE 1
458 typedef __int8 int8_t;
459 typedef __int16 int16_t;
460 typedef __int32 int32_t;
461 typedef __int64 int64_t;
462 typedef unsigned __int8 uint8_t;
463 typedef unsigned __int16 uint16_t;
464 typedef unsigned __int32 uint32_t;
465 typedef unsigned __int64 uint64_t;
468 #endif /* _MSC_VER < 1700 */
471 #endif /* _MSC_VER */
473 /* Type of cycle clock implementation */
475 /* Disable cycle clock by default.
476 TODO(soheil): enable when we support fallback for unstable cycle clocks.
477 #if defined(__i386__)
478 #define GPR_CYCLE_COUNTER_RDTSC_32 1
479 #elif defined(__x86_64__) || defined(__amd64__)
480 #define GPR_CYCLE_COUNTER_RDTSC_64 1
482 #define GPR_CYCLE_COUNTER_FALLBACK 1
485 #define GPR_CYCLE_COUNTER_FALLBACK 1
487 #define GPR_CYCLE_COUNTER_FALLBACK 1
488 #endif /* GPR_LINUX */
490 /* Cache line alignment */
491 #ifndef GPR_CACHELINE_SIZE_LOG
492 #if defined(__i386__) || defined(__x86_64__)
493 #define GPR_CACHELINE_SIZE_LOG 6
495 #ifndef GPR_CACHELINE_SIZE_LOG
496 /* A reasonable default guess. Note that overestimates tend to waste more
497 space, while underestimates tend to waste more time. */
498 #define GPR_CACHELINE_SIZE_LOG 6
499 #endif /* GPR_CACHELINE_SIZE_LOG */
500 #endif /* GPR_CACHELINE_SIZE_LOG */
502 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
504 /* scrub GCC_ATOMIC if it's not available on this compiler */
505 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
506 #undef GPR_GCC_ATOMIC
507 #define GPR_GCC_SYNC 1
510 /* Validate platform combinations */
511 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
512 defined(GPR_WINDOWS_ATOMIC) != \
514 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
517 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
518 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
521 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
522 defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
524 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
527 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
528 defined(GPR_CUSTOM_TLS) != \
530 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS
533 /* maximum alignment needed for any type on this platform, rounded up to a
535 #define GPR_MAX_ALIGNMENT 16
541 #ifndef GRPC_IF_NAMETOINDEX
542 #define GRPC_IF_NAMETOINDEX 1
545 #ifndef GRPC_MUST_USE_RESULT
546 #if defined(__GNUC__) && !defined(__MINGW32__)
547 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
548 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
550 #define GRPC_MUST_USE_RESULT
551 #define GPR_ALIGN_STRUCT(n)
556 #if defined(__GNUC__) && !defined(__MINGW32__)
557 #define GRPC_UNUSED __attribute__((unused))
563 #ifndef GPR_PRINT_FORMAT_CHECK
565 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
566 __attribute__((format(printf, FORMAT_STR, ARGS)))
568 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
570 #endif /* GPR_PRINT_FORMAT_CHECK */
572 #if GPR_FORBID_UNREACHABLE_CODE
573 #define GPR_UNREACHABLE_CODE(STATEMENT)
575 #define GPR_UNREACHABLE_CODE(STATEMENT) \
577 gpr_log(GPR_ERROR, "Should never reach here."); \
581 #endif /* GPR_FORBID_UNREACHABLE_CODE */
588 #define GRPCAPI GPRAPI
592 #define CENSUSAPI GRPCAPI
595 #ifndef GPR_HAS_ATTRIBUTE
596 #ifdef __has_attribute
597 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
599 #define GPR_HAS_ATTRIBUTE(a) 0
601 #endif /* GPR_HAS_ATTRIBUTE */
603 #ifndef GPR_HAS_FEATURE
605 #define GPR_HAS_FEATURE(a) __has_feature(a)
607 #define GPR_HAS_FEATURE(a) 0
609 #endif /* GPR_HAS_FEATURE */
611 #ifndef GPR_ATTRIBUTE_NOINLINE
612 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
613 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
614 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
616 #define GPR_ATTRIBUTE_NOINLINE
618 #endif /* GPR_ATTRIBUTE_NOINLINE */
620 #ifndef GPR_ATTRIBUTE_WEAK
621 /* Attribute weak is broken on LLVM/windows:
622 * https://bugs.llvm.org/show_bug.cgi?id=37598 */
623 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
624 !(defined(__llvm__) && defined(_WIN32))
625 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
626 #define GPR_HAS_ATTRIBUTE_WEAK 1
628 #define GPR_ATTRIBUTE_WEAK
630 #endif /* GPR_ATTRIBUTE_WEAK */
632 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
633 #if GPR_HAS_FEATURE(thread_sanitizer)
634 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
635 #endif /* GPR_HAS_FEATURE */
636 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
637 #define GPR_ATTRIBUTE_NO_TSAN
638 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
639 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
641 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
642 #ifndef GRPC_TSAN_SUPPRESSED
643 #if defined(__SANITIZE_THREAD__)
644 #define GRPC_TSAN_ENABLED
645 #elif GPR_HAS_FEATURE(thread_sanitizer)
646 #define GRPC_TSAN_ENABLED
650 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
651 #ifndef GRPC_ASAN_SUPPRESSED
652 #if defined(__SANITIZE_ADDRESS__)
653 #define GRPC_ASAN_ENABLED
654 #elif GPR_HAS_FEATURE(address_sanitizer)
655 #define GRPC_ASAN_ENABLED
659 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
660 #ifndef GRPC_ALLOW_EXCEPTIONS
662 #if defined(_MSC_VER) && defined(_CPPUNWIND)
663 #define GRPC_ALLOW_EXCEPTIONS 1
664 #elif defined(__EXCEPTIONS)
665 #define GRPC_ALLOW_EXCEPTIONS 1
667 #define GRPC_ALLOW_EXCEPTIONS 0
669 #else /* GPR_WINDOWS */
671 #define GRPC_ALLOW_EXCEPTIONS 1
672 #else /* __EXCEPTIONS */
673 #define GRPC_ALLOW_EXCEPTIONS 0
674 #endif /* __EXCEPTIONS */
675 #endif /* __GPR_WINDOWS */
676 #endif /* GRPC_ALLOW_EXCEPTIONS */
678 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
679 * most likely. Ideally, also collect performance numbers to justify the claim.
682 #define GPR_LIKELY(x) __builtin_expect((x), 1)
683 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
685 #define GPR_LIKELY(x) (x)
686 #define GPR_UNLIKELY(x) (x)
687 #endif /* __GNUC__ */
689 #ifndef __STDC_FORMAT_MACROS
690 #define __STDC_FORMAT_MACROS
693 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */