Go to the documentation of this file.
19 #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
20 #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H
34 #define GRPC_USE_ABSL 1
40 #ifndef GPR_ABSEIL_SYNC
45 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
46 #ifndef WIN32_LEAN_AND_MEAN
47 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
48 #define WIN32_LEAN_AND_MEAN
52 #define GRPC_NOMINMX_WAS_NOT_DEFINED
60 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
62 #if (_WIN32_WINNT < 0x0600)
64 "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
68 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
69 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
70 #undef WIN32_LEAN_AND_MEAN
73 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
74 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
83 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
84 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
85 #if defined(_WIN64) || defined(WIN64)
90 #define GPR_PLATFORM_STRING "windows"
92 #define GPR_WINDOWS_SUBPROCESS 1
93 #define GPR_WINDOWS_ENV
95 #define GPR_GETPID_IN_UNISTD_H 1
96 #define GPR_MSYS_TMPFILE
98 #define GPR_POSIX_STRING
99 #define GPR_POSIX_TIME
101 #define GPR_GETPID_IN_PROCESS_H 1
102 #define GPR_WINDOWS_TMPFILE
103 #define GPR_WINDOWS_LOG
104 #define GPR_WINDOWS_CRASH_HANDLER 1
105 #define GPR_WINDOWS_STRING
106 #define GPR_WINDOWS_TIME
109 #define GPR_GCC_ATOMIC 1
110 #define GPR_GCC_TLS 1
112 #define GPR_WINDOWS_ATOMIC 1
113 #define GPR_MSVC_TLS 1
115 #elif defined(GPR_MANYLINUX1)
118 #define GPR_PLATFORM_STRING "manylinux"
119 #define GPR_POSIX_CRASH_HANDLER 1
120 #define GPR_CPU_POSIX 1
121 #define GPR_GCC_ATOMIC 1
122 #define GPR_GCC_TLS 1
124 #define GPR_LINUX_LOG 1
125 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
126 #define GPR_LINUX_ENV 1
127 #define GPR_POSIX_TMPFILE 1
128 #define GPR_POSIX_STRING 1
129 #define GPR_POSIX_SUBPROCESS 1
130 #define GPR_POSIX_SYNC 1
131 #define GPR_POSIX_TIME 1
132 #define GPR_HAS_PTHREAD_H 1
133 #define GPR_GETPID_IN_UNISTD_H 1
135 #define GPR_ARCH_64 1
137 #define GPR_ARCH_32 1
139 #include <linux/version.h>
140 #elif defined(ANDROID) || defined(__ANDROID__)
141 #define GPR_PLATFORM_STRING "android"
142 #define GPR_ANDROID 1
148 #define GPR_ARCH_64 1
150 #define GPR_ARCH_32 1
152 #define GPR_CPU_POSIX 1
153 #define GPR_GCC_SYNC 1
154 #define GPR_GCC_TLS 1
155 #define GPR_POSIX_ENV 1
156 #define GPR_POSIX_TMPFILE 1
157 #define GPR_ANDROID_LOG 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
164 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
165 #elif defined(__linux__)
166 #define GPR_PLATFORM_STRING "linux"
170 #ifndef _DEFAULT_SOURCE
171 #define _DEFAULT_SOURCE
176 #include <features.h>
177 #define GPR_CPU_LINUX 1
178 #define GPR_GCC_ATOMIC 1
179 #define GPR_GCC_TLS 1
181 #define GPR_LINUX_LOG
182 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
183 #define GPR_LINUX_ENV 1
184 #define GPR_POSIX_TMPFILE 1
185 #define GPR_POSIX_STRING 1
186 #define GPR_POSIX_SUBPROCESS 1
187 #define GPR_POSIX_SYNC 1
188 #define GPR_POSIX_TIME 1
189 #define GPR_HAS_PTHREAD_H 1
190 #define GPR_GETPID_IN_UNISTD_H 1
192 #define GPR_ARCH_64 1
194 #define GPR_ARCH_32 1
197 #define GPR_POSIX_CRASH_HANDLER 1
198 #define GPR_LINUX_PTHREAD_NAME 1
199 #include <linux/version.h>
201 #define GPR_MUSL_LIBC_COMPAT 1
203 #elif defined(__ASYLO__)
204 #define GPR_ARCH_64 1
205 #define GPR_CPU_POSIX 1
206 #define GPR_GCC_TLS 1
207 #define GPR_PLATFORM_STRING "asylo"
208 #define GPR_GCC_SYNC 1
209 #define GPR_POSIX_SYNC 1
210 #define GPR_POSIX_STRING 1
211 #define GPR_POSIX_LOG 1
212 #define GPR_POSIX_TIME 1
213 #define GPR_POSIX_ENV 1
215 #define GRPC_POSIX_SOCKET 1
216 #define GRPC_POSIX_SOCKETADDR
217 #define GRPC_POSIX_SOCKETUTILS 1
218 #define GRPC_TIMER_USE_GENERIC 1
219 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
220 #define GRPC_POSIX_WAKEUP_FD 1
222 #define GPR_NO_AUTODETECT_PLATFORM 1
223 #elif defined(__APPLE__)
224 #include <Availability.h>
225 #include <TargetConditionals.h>
230 #define GPR_PLATFORM_STRING "ios"
231 #define GPR_CPU_IPHONE 1
232 #define GPR_PTHREAD_TLS 1
233 #define GRPC_CFSTREAM 1
237 #define GPR_PLATFORM_STRING "osx"
238 #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
239 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7
240 #define GPR_CPU_IPHONE 1
241 #define GPR_PTHREAD_TLS 1
243 #define GPR_CPU_POSIX 1
247 #ifndef GRPC_BAZEL_BUILD
248 #define GPR_GCC_TLS 1
250 #define GPR_PTHREAD_TLS 1
252 #define GPR_APPLE_PTHREAD_NAME 1
255 #define GPR_CPU_POSIX 1
258 #ifndef GRPC_BAZEL_BUILD
259 #define GPR_GCC_TLS 1
261 #define GPR_PTHREAD_TLS 1
264 #define GPR_POSIX_CRASH_HANDLER 1
267 #define GPR_GCC_ATOMIC 1
268 #define GPR_POSIX_LOG 1
269 #define GPR_POSIX_ENV 1
270 #define GPR_POSIX_TMPFILE 1
271 #define GPR_POSIX_STRING 1
272 #define GPR_POSIX_SUBPROCESS 1
273 #define GPR_POSIX_SYNC 1
274 #define GPR_POSIX_TIME 1
275 #define GPR_HAS_PTHREAD_H 1
276 #define GPR_GETPID_IN_UNISTD_H 1
277 #ifndef GRPC_CFSTREAM
278 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
281 #define GPR_ARCH_64 1
283 #define GPR_ARCH_32 1
285 #elif defined(__FreeBSD__)
286 #define GPR_PLATFORM_STRING "freebsd"
290 #define GPR_FREEBSD 1
291 #define GPR_CPU_POSIX 1
292 #define GPR_GCC_ATOMIC 1
293 #define GPR_GCC_TLS 1
294 #define GPR_POSIX_LOG 1
295 #define GPR_POSIX_ENV 1
296 #define GPR_POSIX_TMPFILE 1
297 #define GPR_POSIX_STRING 1
298 #define GPR_POSIX_SUBPROCESS 1
299 #define GPR_POSIX_SYNC 1
300 #define GPR_POSIX_TIME 1
301 #define GPR_HAS_PTHREAD_H 1
302 #define GPR_GETPID_IN_UNISTD_H 1
303 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
305 #define GPR_ARCH_64 1
307 #define GPR_ARCH_32 1
309 #elif defined(__OpenBSD__)
310 #define GPR_PLATFORM_STRING "openbsd"
314 #define GPR_OPENBSD 1
315 #define GPR_CPU_POSIX 1
316 #define GPR_GCC_ATOMIC 1
317 #define GPR_GCC_TLS 1
318 #define GPR_POSIX_LOG 1
319 #define GPR_POSIX_ENV 1
320 #define GPR_POSIX_TMPFILE 1
321 #define GPR_POSIX_STRING 1
322 #define GPR_POSIX_SUBPROCESS 1
323 #define GPR_POSIX_SYNC 1
324 #define GPR_POSIX_TIME 1
325 #define GPR_HAS_PTHREAD_H 1
326 #define GPR_GETPID_IN_UNISTD_H 1
327 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
329 #define GPR_ARCH_64 1
331 #define GPR_ARCH_32 1
333 #elif defined(__sun) && defined(__SVR4)
334 #define GPR_PLATFORM_STRING "solaris"
335 #define GPR_SOLARIS 1
336 #define GPR_CPU_POSIX 1
337 #define GPR_GCC_ATOMIC 1
338 #define GPR_GCC_TLS 1
339 #define GPR_POSIX_LOG 1
340 #define GPR_POSIX_ENV 1
341 #define GPR_POSIX_TMPFILE 1
342 #define GPR_POSIX_STRING 1
343 #define GPR_POSIX_SUBPROCESS 1
344 #define GPR_POSIX_SYNC 1
345 #define GPR_POSIX_TIME 1
346 #define GPR_HAS_PTHREAD_H 1
347 #define GPR_GETPID_IN_UNISTD_H 1
349 #define GPR_ARCH_64 1
351 #define GPR_ARCH_32 1
354 #define GPR_PLATFORM_STRING "aix"
359 #define GPR_CPU_POSIX 1
360 #define GPR_GCC_ATOMIC 1
361 #define GPR_GCC_TLS 1
362 #define GPR_POSIX_LOG 1
363 #define GPR_POSIX_ENV 1
364 #define GPR_POSIX_TMPFILE 1
365 #define GPR_POSIX_STRING 1
366 #define GPR_POSIX_SUBPROCESS 1
367 #define GPR_POSIX_SYNC 1
368 #define GPR_POSIX_TIME 1
369 #define GPR_HAS_PTHREAD_H 1
370 #define GPR_GETPID_IN_UNISTD_H 1
372 #define GPR_ARCH_64 1
374 #define GPR_ARCH_32 1
376 #elif defined(__native_client__)
377 #define GPR_PLATFORM_STRING "nacl"
381 #ifndef _DEFAULT_SOURCE
382 #define _DEFAULT_SOURCE
388 #define GPR_CPU_POSIX 1
389 #define GPR_GCC_ATOMIC 1
390 #define GPR_GCC_TLS 1
391 #define GPR_POSIX_LOG 1
392 #define GPR_POSIX_ENV 1
393 #define GPR_POSIX_TMPFILE 1
394 #define GPR_POSIX_STRING 1
395 #define GPR_POSIX_SUBPROCESS 1
396 #define GPR_POSIX_SYNC 1
397 #define GPR_POSIX_TIME 1
398 #define GPR_HAS_PTHREAD_H 1
399 #define GPR_GETPID_IN_UNISTD_H 1
401 #define GPR_ARCH_64 1
403 #define GPR_ARCH_32 1
405 #elif defined(__Fuchsia__)
406 #define GPR_FUCHSIA 1
407 #define GPR_ARCH_64 1
408 #define GPR_PLATFORM_STRING "fuchsia"
409 #include <features.h>
412 #define GPR_MUSL_LIBC_COMPAT 1
413 #define GPR_CPU_POSIX 1
414 #define GPR_GCC_ATOMIC 1
415 #define GPR_PTHREAD_TLS 1
416 #define GPR_POSIX_LOG 1
417 #define GPR_POSIX_SYNC 1
418 #define GPR_POSIX_ENV 1
419 #define GPR_POSIX_TMPFILE 1
420 #define GPR_POSIX_SUBPROCESS 1
421 #define GPR_POSIX_SYNC 1
422 #define GPR_POSIX_STRING 1
423 #define GPR_POSIX_TIME 1
424 #define GPR_HAS_PTHREAD_H 1
425 #define GPR_GETPID_IN_UNISTD_H 1
427 #error "Could not auto-detect platform"
431 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
437 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
438 #undef _FORTIFY_SOURCE
439 #define _FORTIFY_SOURCE 0
454 #if defined(__ANDROID__) && defined(GPR_GCC_TLS)
455 #if __has_include(<android/ndk-version.h>)
456 #include <android/ndk-version.h>
458 #if (defined(__clang__) && defined(__NDK_MAJOR__) && defined(__NDK_MINOR__) && \
459 ((__NDK_MAJOR__ < 12) || \
460 ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))) || \
461 (defined(__GNUC__) && !defined(__clang__))
463 #define GPR_PTHREAD_TLS 1
467 #if defined(__has_include)
468 #if __has_include(<atomic>)
469 #define GRPC_HAS_CXX11_ATOMIC
473 #ifndef GPR_PLATFORM_STRING
474 #warning "GPR_PLATFORM_STRING not auto-detected"
475 #define GPR_PLATFORM_STRING "unknown"
479 #undef GPR_FORBID_UNREACHABLE_CODE
480 #define GPR_FORBID_UNREACHABLE_CODE 1
485 typedef __int8 int8_t;
486 typedef __int16 int16_t;
487 typedef __int32 int32_t;
488 typedef __int64 int64_t;
489 typedef unsigned __int8 uint8_t;
490 typedef unsigned __int16 uint16_t;
491 typedef unsigned __int32 uint32_t;
492 typedef unsigned __int64 uint64_t;
512 #define GPR_CYCLE_COUNTER_FALLBACK 1
514 #define GPR_CYCLE_COUNTER_FALLBACK 1
518 #ifndef GPR_CACHELINE_SIZE_LOG
519 #if defined(__i386__) || defined(__x86_64__)
520 #define GPR_CACHELINE_SIZE_LOG 6
522 #ifndef GPR_CACHELINE_SIZE_LOG
525 #define GPR_CACHELINE_SIZE_LOG 6
529 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
532 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
533 #undef GPR_GCC_ATOMIC
534 #define GPR_GCC_SYNC 1
538 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
539 defined(GPR_WINDOWS_ATOMIC) != \
541 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
544 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
545 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
548 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
549 defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
551 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
554 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
555 defined(GPR_CUSTOM_TLS) != \
557 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS
562 #define GPR_MAX_ALIGNMENT 16
568 #ifndef GRPC_IF_NAMETOINDEX
569 #define GRPC_IF_NAMETOINDEX 1
572 #ifndef GRPC_MUST_USE_RESULT
573 #if defined(__GNUC__) && !defined(__MINGW32__)
574 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
575 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
577 #define GRPC_MUST_USE_RESULT
578 #define GPR_ALIGN_STRUCT(n)
583 #if defined(__GNUC__) && !defined(__MINGW32__)
584 #define GRPC_UNUSED __attribute__((unused))
590 #ifndef GPR_PRINT_FORMAT_CHECK
592 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
593 __attribute__((format(printf, FORMAT_STR, ARGS)))
595 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
599 #if GPR_FORBID_UNREACHABLE_CODE
600 #define GPR_UNREACHABLE_CODE(STATEMENT)
602 #define GPR_UNREACHABLE_CODE(STATEMENT) \
604 gpr_log(GPR_ERROR, "Should never reach here."); \
615 #define GRPCAPI GPRAPI
619 #define CENSUSAPI GRPCAPI
622 #ifndef GPR_HAS_ATTRIBUTE
623 #ifdef __has_attribute
624 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
626 #define GPR_HAS_ATTRIBUTE(a) 0
630 #ifndef GPR_HAS_FEATURE
632 #define GPR_HAS_FEATURE(a) __has_feature(a)
634 #define GPR_HAS_FEATURE(a) 0
638 #ifndef GPR_ATTRIBUTE_NOINLINE
639 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
640 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
641 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
643 #define GPR_ATTRIBUTE_NOINLINE
647 #ifndef GPR_ATTRIBUTE_WEAK
650 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
651 !(defined(__llvm__) && defined(_WIN32))
652 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
653 #define GPR_HAS_ATTRIBUTE_WEAK 1
655 #define GPR_ATTRIBUTE_WEAK
659 #ifndef GPR_ATTRIBUTE_NO_TSAN
660 #if GPR_HAS_FEATURE(thread_sanitizer)
661 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
663 #ifndef GPR_ATTRIBUTE_NO_TSAN
664 #define GPR_ATTRIBUTE_NO_TSAN
669 #ifndef GRPC_TSAN_SUPPRESSED
670 #if defined(__SANITIZE_THREAD__)
671 #define GRPC_TSAN_ENABLED
672 #elif GPR_HAS_FEATURE(thread_sanitizer)
673 #define GRPC_TSAN_ENABLED
678 #ifndef GRPC_ASAN_SUPPRESSED
679 #if defined(__SANITIZE_ADDRESS__)
680 #define GRPC_ASAN_ENABLED
681 #elif GPR_HAS_FEATURE(address_sanitizer)
682 #define GRPC_ASAN_ENABLED
687 #ifndef GRPC_ALLOW_EXCEPTIONS
689 #if defined(_MSC_VER) && defined(_CPPUNWIND)
690 #define GRPC_ALLOW_EXCEPTIONS 1
691 #elif defined(__EXCEPTIONS)
692 #define GRPC_ALLOW_EXCEPTIONS 1
694 #define GRPC_ALLOW_EXCEPTIONS 0
698 #define GRPC_ALLOW_EXCEPTIONS 1
700 #define GRPC_ALLOW_EXCEPTIONS 0
709 #define GPR_LIKELY(x) __builtin_expect((x), 1)
710 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
712 #define GPR_LIKELY(x) (x)
713 #define GPR_UNLIKELY(x) (x)
716 #ifndef __STDC_FORMAT_MACROS
717 #define __STDC_FORMAT_MACROS