Imported Upstream version 1.37.0
[platform/upstream/grpc.git] / include / grpc / impl / codegen / port_platform.h
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 /*
31  * Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil
32  */
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
37 #else
38 #define GPR_ABSEIL_SYNC 1
39 #endif
40 #endif  // GPR_ABSEIL_SYNC
41
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 */
48
49 #ifndef NOMINMAX
50 #define GRPC_NOMINMX_WAS_NOT_DEFINED
51 #define NOMINMAX
52 #endif /* NOMINMAX */
53
54 #include <windows.h>
55
56 #ifndef _WIN32_WINNT
57 #error \
58     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
59 #else /* !defined(_WIN32_WINNT) */
60 #if (_WIN32_WINNT < 0x0600)
61 #error \
62     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
63 #endif /* _WIN32_WINNT < 0x0600 */
64 #endif /* defined(_WIN32_WINNT) */
65
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 */
70
71 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
72 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
73 #undef NOMINMAX
74 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
75 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
76           defined(WIN32) */
77
78 /* Override this file with one for your platform if you need to redefine
79    things.  */
80
81 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
82 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
83 #if defined(_WIN64) || defined(WIN64)
84 #define GPR_ARCH_64 1
85 #else
86 #define GPR_ARCH_32 1
87 #endif
88 #define GPR_PLATFORM_STRING "windows"
89 #define GPR_WINDOWS 1
90 #define GPR_WINDOWS_SUBPROCESS 1
91 #define GPR_WINDOWS_ENV
92 #ifdef __MSYS__
93 #define GPR_GETPID_IN_UNISTD_H 1
94 #define GPR_MSYS_TMPFILE
95 #define GPR_POSIX_LOG
96 #define GPR_POSIX_STRING
97 #define GPR_POSIX_TIME
98 #else
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_STAT
104 #define GPR_WINDOWS_STRING
105 #define GPR_WINDOWS_TIME
106 #endif
107 #ifdef __GNUC__
108 #define GPR_GCC_ATOMIC 1
109 #else
110 #define GPR_WINDOWS_ATOMIC 1
111 #endif
112 #define GPR_STDCPP_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.
119 #define GRPC_ARES 0
120 #ifdef _LP64
121 #define GPR_ARCH_64 1
122 #else /* _LP64 */
123 #define GPR_ARCH_32 1
124 #endif /* _LP64 */
125 #define GPR_CPU_POSIX 1
126 #define GPR_GCC_SYNC 1
127 #define GPR_STDCPP_TLS 1
128 #define GPR_POSIX_ENV 1
129 #define GPR_POSIX_TMPFILE 1
130 #define GPR_POSIX_STAT 1
131 #define GPR_ANDROID_LOG 1
132 #define GPR_POSIX_STRING 1
133 #define GPR_POSIX_SUBPROCESS 1
134 #define GPR_POSIX_SYNC 1
135 #define GPR_POSIX_TIME 1
136 #define GPR_HAS_PTHREAD_H 1
137 #define GPR_GETPID_IN_UNISTD_H 1
138 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
139 #elif defined(__linux__)
140 #define GPR_PLATFORM_STRING "linux"
141 #ifndef _BSD_SOURCE
142 #define _BSD_SOURCE
143 #endif
144 #ifndef _DEFAULT_SOURCE
145 #define _DEFAULT_SOURCE
146 #endif
147 #ifndef _GNU_SOURCE
148 #define _GNU_SOURCE
149 #endif
150 #include <features.h>
151 #define GPR_CPU_LINUX 1
152 #define GPR_GCC_ATOMIC 1
153 #define GPR_STDCPP_TLS 1
154 #define GPR_LINUX 1
155 #define GPR_LINUX_LOG
156 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
157 #define GPR_LINUX_ENV 1
158 #define GPR_POSIX_TMPFILE 1
159 #define GPR_POSIX_STAT 1
160 #define GPR_POSIX_STRING 1
161 #define GPR_POSIX_SUBPROCESS 1
162 #define GPR_POSIX_SYNC 1
163 #define GPR_POSIX_TIME 1
164 #define GPR_HAS_PTHREAD_H 1
165 #define GPR_GETPID_IN_UNISTD_H 1
166 #ifdef _LP64
167 #define GPR_ARCH_64 1
168 #else /* _LP64 */
169 #define GPR_ARCH_32 1
170 #endif /* _LP64 */
171 #ifdef __GLIBC__
172 #define GPR_POSIX_CRASH_HANDLER 1
173 #define GPR_LINUX_PTHREAD_NAME 1
174 #include <linux/version.h>
175 #else /* musl libc */
176 #define GPR_MUSL_LIBC_COMPAT 1
177 #endif
178 #elif defined(__ASYLO__)
179 #define GPR_ARCH_64 1
180 #define GPR_CPU_POSIX 1
181 #define GPR_GCC_TLS 1
182 #define GPR_PLATFORM_STRING "asylo"
183 #define GPR_GCC_SYNC 1
184 #define GPR_POSIX_SYNC 1
185 #define GPR_POSIX_STRING 1
186 #define GPR_POSIX_LOG 1
187 #define GPR_POSIX_TIME 1
188 #define GPR_POSIX_ENV 1
189 #define GPR_ASYLO 1
190 #define GRPC_POSIX_SOCKET 1
191 #define GRPC_POSIX_SOCKETADDR
192 #define GRPC_POSIX_SOCKETUTILS 1
193 #define GRPC_TIMER_USE_GENERIC 1
194 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
195 #define GRPC_POSIX_WAKEUP_FD 1
196 #define GRPC_ARES 0
197 #define GPR_NO_AUTODETECT_PLATFORM 1
198 #elif defined(__APPLE__)
199 #include <Availability.h>
200 #include <TargetConditionals.h>
201 #ifndef _BSD_SOURCE
202 #define _BSD_SOURCE
203 #endif
204 #if TARGET_OS_IPHONE
205 #define GPR_PLATFORM_STRING "ios"
206 #define GPR_CPU_IPHONE 1
207 #define GRPC_CFSTREAM 1
208 /* the c-ares resolver isn't safe to enable on iOS */
209 #define GRPC_ARES 0
210 #else /* TARGET_OS_IPHONE */
211 #define GPR_PLATFORM_STRING "osx"
212 #define GPR_CPU_POSIX 1
213 #define GPR_POSIX_CRASH_HANDLER 1
214 #endif
215 #ifdef __has_feature
216 #if __has_feature(cxx_thread_local)
217 #define GPR_STDCPP_TLS 1
218 #endif
219 #endif
220 #ifndef GPR_STDCPP_TLS
221 #define GPR_PTHREAD_TLS 1
222 #endif
223 #define GPR_APPLE 1
224 #define GPR_GCC_ATOMIC 1
225 #define GPR_POSIX_LOG 1
226 #define GPR_POSIX_ENV 1
227 #define GPR_POSIX_TMPFILE 1
228 #define GPR_POSIX_STAT 1
229 #define GPR_POSIX_STRING 1
230 #define GPR_POSIX_SUBPROCESS 1
231 #define GPR_POSIX_SYNC 1
232 #define GPR_POSIX_TIME 1
233 #define GPR_HAS_PTHREAD_H 1
234 #define GPR_GETPID_IN_UNISTD_H 1
235 #ifndef GRPC_CFSTREAM
236 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
237 #endif
238 #ifdef _LP64
239 #define GPR_ARCH_64 1
240 #else /* _LP64 */
241 #define GPR_ARCH_32 1
242 #endif /* _LP64 */
243 #elif defined(__FreeBSD__)
244 #define GPR_PLATFORM_STRING "freebsd"
245 #ifndef _BSD_SOURCE
246 #define _BSD_SOURCE
247 #endif
248 #define GPR_FREEBSD 1
249 #define GPR_CPU_POSIX 1
250 #define GPR_GCC_ATOMIC 1
251 #define GPR_GCC_TLS 1
252 #define GPR_POSIX_LOG 1
253 #define GPR_POSIX_ENV 1
254 #define GPR_POSIX_TMPFILE 1
255 #define GPR_POSIX_STAT 1
256 #define GPR_POSIX_STRING 1
257 #define GPR_POSIX_SUBPROCESS 1
258 #define GPR_POSIX_SYNC 1
259 #define GPR_POSIX_TIME 1
260 #define GPR_HAS_PTHREAD_H 1
261 #define GPR_GETPID_IN_UNISTD_H 1
262 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
263 #ifdef _LP64
264 #define GPR_ARCH_64 1
265 #else /* _LP64 */
266 #define GPR_ARCH_32 1
267 #endif /* _LP64 */
268 #elif defined(__OpenBSD__)
269 #define GPR_PLATFORM_STRING "openbsd"
270 #ifndef _BSD_SOURCE
271 #define _BSD_SOURCE
272 #endif
273 #define GPR_OPENBSD 1
274 #define GPR_CPU_POSIX 1
275 #define GPR_GCC_ATOMIC 1
276 #define GPR_GCC_TLS 1
277 #define GPR_POSIX_LOG 1
278 #define GPR_POSIX_ENV 1
279 #define GPR_POSIX_TMPFILE 1
280 #define GPR_POSIX_STAT 1
281 #define GPR_POSIX_STRING 1
282 #define GPR_POSIX_SUBPROCESS 1
283 #define GPR_POSIX_SYNC 1
284 #define GPR_POSIX_TIME 1
285 #define GPR_HAS_PTHREAD_H 1
286 #define GPR_GETPID_IN_UNISTD_H 1
287 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
288 #ifdef _LP64
289 #define GPR_ARCH_64 1
290 #else /* _LP64 */
291 #define GPR_ARCH_32 1
292 #endif /* _LP64 */
293 #elif defined(__sun) && defined(__SVR4)
294 #define GPR_PLATFORM_STRING "solaris"
295 #define GPR_SOLARIS 1
296 #define GPR_CPU_POSIX 1
297 #define GPR_GCC_ATOMIC 1
298 #define GPR_GCC_TLS 1
299 #define GPR_POSIX_LOG 1
300 #define GPR_POSIX_ENV 1
301 #define GPR_POSIX_TMPFILE 1
302 #define GPR_POSIX_STAT 1
303 #define GPR_POSIX_STRING 1
304 #define GPR_POSIX_SUBPROCESS 1
305 #define GPR_POSIX_SYNC 1
306 #define GPR_POSIX_TIME 1
307 #define GPR_HAS_PTHREAD_H 1
308 #define GPR_GETPID_IN_UNISTD_H 1
309 #ifdef _LP64
310 #define GPR_ARCH_64 1
311 #else /* _LP64 */
312 #define GPR_ARCH_32 1
313 #endif /* _LP64 */
314 #elif defined(_AIX)
315 #define GPR_PLATFORM_STRING "aix"
316 #ifndef _ALL_SOURCE
317 #define _ALL_SOURCE
318 #endif
319 #define GPR_AIX 1
320 #define GPR_CPU_POSIX 1
321 #define GPR_GCC_ATOMIC 1
322 #define GPR_GCC_TLS 1
323 #define GPR_POSIX_LOG 1
324 #define GPR_POSIX_ENV 1
325 #define GPR_POSIX_TMPFILE 1
326 #define GPR_POSIX_STAT 1
327 #define GPR_POSIX_STRING 1
328 #define GPR_POSIX_SUBPROCESS 1
329 #define GPR_POSIX_SYNC 1
330 #define GPR_POSIX_TIME 1
331 #define GPR_HAS_PTHREAD_H 1
332 #define GPR_GETPID_IN_UNISTD_H 1
333 #ifdef _LP64
334 #define GPR_ARCH_64 1
335 #else /* _LP64 */
336 #define GPR_ARCH_32 1
337 #endif /* _LP64 */
338 #elif defined(__native_client__)
339 #define GPR_PLATFORM_STRING "nacl"
340 #ifndef _BSD_SOURCE
341 #define _BSD_SOURCE
342 #endif
343 #ifndef _DEFAULT_SOURCE
344 #define _DEFAULT_SOURCE
345 #endif
346 #ifndef _GNU_SOURCE
347 #define _GNU_SOURCE
348 #endif
349 #define GPR_NACL 1
350 #define GPR_CPU_POSIX 1
351 #define GPR_GCC_ATOMIC 1
352 #define GPR_GCC_TLS 1
353 #define GPR_POSIX_LOG 1
354 #define GPR_POSIX_ENV 1
355 #define GPR_POSIX_TMPFILE 1
356 #define GPR_POSIX_STAT 1
357 #define GPR_POSIX_STRING 1
358 #define GPR_POSIX_SUBPROCESS 1
359 #define GPR_POSIX_SYNC 1
360 #define GPR_POSIX_TIME 1
361 #define GPR_HAS_PTHREAD_H 1
362 #define GPR_GETPID_IN_UNISTD_H 1
363 #ifdef _LP64
364 #define GPR_ARCH_64 1
365 #else /* _LP64 */
366 #define GPR_ARCH_32 1
367 #endif /* _LP64 */
368 #elif defined(__Fuchsia__)
369 #define GRPC_ARES 0
370 #define GPR_FUCHSIA 1
371 #define GPR_ARCH_64 1
372 #define GPR_PLATFORM_STRING "fuchsia"
373 #include <features.h>
374 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
375 // invoked.
376 #define GPR_MUSL_LIBC_COMPAT 1
377 #define GPR_CPU_POSIX 1
378 #define GPR_GCC_ATOMIC 1
379 #define GPR_PTHREAD_TLS 1
380 #define GPR_POSIX_LOG 1
381 #define GPR_POSIX_SYNC 1
382 #define GPR_POSIX_ENV 1
383 #define GPR_POSIX_TMPFILE 1
384 #define GPR_POSIX_STAT 1
385 #define GPR_POSIX_SUBPROCESS 1
386 #define GPR_POSIX_SYNC 1
387 #define GPR_POSIX_STRING 1
388 #define GPR_POSIX_TIME 1
389 #define GPR_HAS_PTHREAD_H 1
390 #define GPR_GETPID_IN_UNISTD_H 1
391 #define GRPC_ROOT_PEM_PATH "/config/ssl/cert.pem"
392 #else
393 #error "Could not auto-detect platform"
394 #endif
395 #endif /* GPR_NO_AUTODETECT_PLATFORM */
396
397 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
398 /*
399  * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
400  * a library from having non-standard symbols such as __asprintf_chk.
401  * This helps non-glibc systems such as alpine using musl to find symbols.
402  */
403 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
404 #undef _FORTIFY_SOURCE
405 #define _FORTIFY_SOURCE 0
406 #endif
407 #endif
408
409 #if defined(__has_include)
410 #if __has_include(<atomic>)
411 #define GRPC_HAS_CXX11_ATOMIC
412 #endif /* __has_include(<atomic>) */
413 #endif /* defined(__has_include) */
414
415 #ifndef GPR_PLATFORM_STRING
416 #warning "GPR_PLATFORM_STRING not auto-detected"
417 #define GPR_PLATFORM_STRING "unknown"
418 #endif
419
420 #ifdef GPR_GCOV
421 #undef GPR_FORBID_UNREACHABLE_CODE
422 #define GPR_FORBID_UNREACHABLE_CODE 1
423 #endif
424
425 #ifdef _MSC_VER
426 #if _MSC_VER < 1700
427 typedef __int8 int8_t;
428 typedef __int16 int16_t;
429 typedef __int32 int32_t;
430 typedef __int64 int64_t;
431 typedef unsigned __int8 uint8_t;
432 typedef unsigned __int16 uint16_t;
433 typedef unsigned __int32 uint32_t;
434 typedef unsigned __int64 uint64_t;
435 #else
436 #include <stdint.h>
437 #endif /* _MSC_VER < 1700 */
438 #else
439 #include <stdint.h>
440 #endif /* _MSC_VER */
441
442 /* Type of cycle clock implementation */
443 #ifdef GPR_LINUX
444 /* Disable cycle clock by default.
445    TODO(soheil): enable when we support fallback for unstable cycle clocks.
446 #if defined(__i386__)
447 #define GPR_CYCLE_COUNTER_RDTSC_32 1
448 #elif defined(__x86_64__) || defined(__amd64__)
449 #define GPR_CYCLE_COUNTER_RDTSC_64 1
450 #else
451 #define GPR_CYCLE_COUNTER_FALLBACK 1
452 #endif
453 */
454 #define GPR_CYCLE_COUNTER_FALLBACK 1
455 #else
456 #define GPR_CYCLE_COUNTER_FALLBACK 1
457 #endif /* GPR_LINUX */
458
459 /* Cache line alignment */
460 #ifndef GPR_CACHELINE_SIZE_LOG
461 #if defined(__i386__) || defined(__x86_64__)
462 #define GPR_CACHELINE_SIZE_LOG 6
463 #endif
464 #ifndef GPR_CACHELINE_SIZE_LOG
465 /* A reasonable default guess. Note that overestimates tend to waste more
466    space, while underestimates tend to waste more time. */
467 #define GPR_CACHELINE_SIZE_LOG 6
468 #endif /* GPR_CACHELINE_SIZE_LOG */
469 #endif /* GPR_CACHELINE_SIZE_LOG */
470
471 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
472
473 /* scrub GCC_ATOMIC if it's not available on this compiler */
474 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
475 #undef GPR_GCC_ATOMIC
476 #define GPR_GCC_SYNC 1
477 #endif
478
479 /* Validate platform combinations */
480 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
481         defined(GPR_WINDOWS_ATOMIC) !=                \
482     1
483 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
484 #endif
485
486 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
487 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
488 #endif
489
490 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
491         defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) !=                 \
492     1
493 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
494 #endif
495
496 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
497         defined(GPR_STDCPP_TLS) + defined(GPR_CUSTOM_TLS) !=                  \
498     1
499 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_STDCPP_TLS, GPR_CUSTOM_TLS
500 #endif
501
502 /* maximum alignment needed for any type on this platform, rounded up to a
503    power of two */
504 #define GPR_MAX_ALIGNMENT 16
505
506 #ifndef GRPC_ARES
507 #define GRPC_ARES 1
508 #endif
509
510 #ifndef GRPC_IF_NAMETOINDEX
511 #define GRPC_IF_NAMETOINDEX 1
512 #endif
513
514 #ifndef GRPC_MUST_USE_RESULT
515 #if defined(__GNUC__) && !defined(__MINGW32__)
516 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
517 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
518 #else
519 #define GRPC_MUST_USE_RESULT
520 #define GPR_ALIGN_STRUCT(n)
521 #endif
522 #endif
523
524 #ifndef GRPC_UNUSED
525 #if defined(__GNUC__) && !defined(__MINGW32__)
526 #define GRPC_UNUSED __attribute__((unused))
527 #else
528 #define GRPC_UNUSED
529 #endif
530 #endif
531
532 #ifndef GPR_PRINT_FORMAT_CHECK
533 #ifdef __GNUC__
534 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
535   __attribute__((format(printf, FORMAT_STR, ARGS)))
536 #else
537 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
538 #endif
539 #endif /* GPR_PRINT_FORMAT_CHECK */
540
541 #if GPR_FORBID_UNREACHABLE_CODE
542 #define GPR_UNREACHABLE_CODE(STATEMENT)
543 #else
544 #define GPR_UNREACHABLE_CODE(STATEMENT)             \
545   do {                                              \
546     gpr_log(GPR_ERROR, "Should never reach here."); \
547     abort();                                        \
548     STATEMENT;                                      \
549   } while (0)
550 #endif /* GPR_FORBID_UNREACHABLE_CODE */
551
552 #ifndef GPRAPI
553 #define GPRAPI
554 #endif
555
556 #ifndef GRPCAPI
557 #define GRPCAPI GPRAPI
558 #endif
559
560 #ifndef CENSUSAPI
561 #define CENSUSAPI GRPCAPI
562 #endif
563
564 #ifndef GPR_HAS_ATTRIBUTE
565 #ifdef __has_attribute
566 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
567 #else
568 #define GPR_HAS_ATTRIBUTE(a) 0
569 #endif
570 #endif /* GPR_HAS_ATTRIBUTE */
571
572 #ifndef GPR_HAS_FEATURE
573 #ifdef __has_feature
574 #define GPR_HAS_FEATURE(a) __has_feature(a)
575 #else
576 #define GPR_HAS_FEATURE(a) 0
577 #endif
578 #endif /* GPR_HAS_FEATURE */
579
580 #ifndef GPR_ATTRIBUTE_NOINLINE
581 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
582 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
583 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
584 #else
585 #define GPR_ATTRIBUTE_NOINLINE
586 #endif
587 #endif /* GPR_ATTRIBUTE_NOINLINE */
588
589 #ifndef GPR_ATTRIBUTE_WEAK
590 /* Attribute weak is broken on LLVM/windows:
591  * https://bugs.llvm.org/show_bug.cgi?id=37598 */
592 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
593     !(defined(__llvm__) && defined(_WIN32))
594 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
595 #define GPR_HAS_ATTRIBUTE_WEAK 1
596 #else
597 #define GPR_ATTRIBUTE_WEAK
598 #endif
599 #endif /* GPR_ATTRIBUTE_WEAK */
600
601 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
602 #if GPR_HAS_FEATURE(thread_sanitizer)
603 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
604 #endif                        /* GPR_HAS_FEATURE */
605 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
606 #define GPR_ATTRIBUTE_NO_TSAN
607 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
608 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
609
610 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
611 #ifndef GRPC_TSAN_SUPPRESSED
612 #if defined(__SANITIZE_THREAD__)
613 #define GRPC_TSAN_ENABLED
614 #elif GPR_HAS_FEATURE(thread_sanitizer)
615 #define GRPC_TSAN_ENABLED
616 #endif
617 #endif
618
619 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
620 #ifndef GRPC_ASAN_SUPPRESSED
621 #if defined(__SANITIZE_ADDRESS__)
622 #define GRPC_ASAN_ENABLED
623 #elif GPR_HAS_FEATURE(address_sanitizer)
624 #define GRPC_ASAN_ENABLED
625 #endif
626 #endif
627
628 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
629 #ifndef GRPC_ALLOW_EXCEPTIONS
630 #ifdef GPR_WINDOWS
631 #if defined(_MSC_VER) && defined(_CPPUNWIND)
632 #define GRPC_ALLOW_EXCEPTIONS 1
633 #elif defined(__EXCEPTIONS)
634 #define GRPC_ALLOW_EXCEPTIONS 1
635 #else
636 #define GRPC_ALLOW_EXCEPTIONS 0
637 #endif
638 #else /* GPR_WINDOWS */
639 #ifdef __EXCEPTIONS
640 #define GRPC_ALLOW_EXCEPTIONS 1
641 #else /* __EXCEPTIONS */
642 #define GRPC_ALLOW_EXCEPTIONS 0
643 #endif /* __EXCEPTIONS */
644 #endif /* __GPR_WINDOWS */
645 #endif /* GRPC_ALLOW_EXCEPTIONS */
646
647 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
648  * most likely. Ideally, also collect performance numbers to justify the claim.
649  */
650 #ifdef __GNUC__
651 #define GPR_LIKELY(x) __builtin_expect((x), 1)
652 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
653 #else /* __GNUC__ */
654 #define GPR_LIKELY(x) (x)
655 #define GPR_UNLIKELY(x) (x)
656 #endif /* __GNUC__ */
657
658 #ifndef __STDC_FORMAT_MACROS
659 #define __STDC_FORMAT_MACROS
660 #endif
661
662 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */