• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 0
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 GPR_FUCHSIA 1
370 #define GPR_ARCH_64 1
371 #define GPR_PLATFORM_STRING "fuchsia"
372 #include <features.h>
373 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
374 // invoked.
375 #define GPR_MUSL_LIBC_COMPAT 1
376 #define GPR_CPU_POSIX 1
377 #define GPR_GCC_ATOMIC 1
378 #define GPR_PTHREAD_TLS 1
379 #define GPR_POSIX_LOG 1
380 #define GPR_POSIX_SYNC 1
381 #define GPR_POSIX_ENV 1
382 #define GPR_POSIX_TMPFILE 1
383 #define GPR_POSIX_STAT 1
384 #define GPR_POSIX_SUBPROCESS 1
385 #define GPR_POSIX_SYNC 1
386 #define GPR_POSIX_STRING 1
387 #define GPR_POSIX_TIME 1
388 #define GPR_HAS_PTHREAD_H 1
389 #define GPR_GETPID_IN_UNISTD_H 1
390 #else
391 #error "Could not auto-detect platform"
392 #endif
393 #endif /* GPR_NO_AUTODETECT_PLATFORM */
394 
395 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
396 /*
397  * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
398  * a library from having non-standard symbols such as __asprintf_chk.
399  * This helps non-glibc systems such as alpine using musl to find symbols.
400  */
401 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
402 #undef _FORTIFY_SOURCE
403 #define _FORTIFY_SOURCE 0
404 #endif
405 #endif
406 
407 #if defined(__has_include)
408 #if __has_include(<atomic>)
409 #define GRPC_HAS_CXX11_ATOMIC
410 #endif /* __has_include(<atomic>) */
411 #endif /* defined(__has_include) */
412 
413 #ifndef GPR_PLATFORM_STRING
414 #warning "GPR_PLATFORM_STRING not auto-detected"
415 #define GPR_PLATFORM_STRING "unknown"
416 #endif
417 
418 #ifdef GPR_GCOV
419 #undef GPR_FORBID_UNREACHABLE_CODE
420 #define GPR_FORBID_UNREACHABLE_CODE 1
421 #endif
422 
423 #ifdef _MSC_VER
424 #if _MSC_VER < 1700
425 typedef __int8 int8_t;
426 typedef __int16 int16_t;
427 typedef __int32 int32_t;
428 typedef __int64 int64_t;
429 typedef unsigned __int8 uint8_t;
430 typedef unsigned __int16 uint16_t;
431 typedef unsigned __int32 uint32_t;
432 typedef unsigned __int64 uint64_t;
433 #else
434 #include <stdint.h>
435 #endif /* _MSC_VER < 1700 */
436 #else
437 #include <stdint.h>
438 #endif /* _MSC_VER */
439 
440 /* Type of cycle clock implementation */
441 #ifdef GPR_LINUX
442 /* Disable cycle clock by default.
443    TODO(soheil): enable when we support fallback for unstable cycle clocks.
444 #if defined(__i386__)
445 #define GPR_CYCLE_COUNTER_RDTSC_32 1
446 #elif defined(__x86_64__) || defined(__amd64__)
447 #define GPR_CYCLE_COUNTER_RDTSC_64 1
448 #else
449 #define GPR_CYCLE_COUNTER_FALLBACK 1
450 #endif
451 */
452 #define GPR_CYCLE_COUNTER_FALLBACK 1
453 #else
454 #define GPR_CYCLE_COUNTER_FALLBACK 1
455 #endif /* GPR_LINUX */
456 
457 /* Cache line alignment */
458 #ifndef GPR_CACHELINE_SIZE_LOG
459 #if defined(__i386__) || defined(__x86_64__)
460 #define GPR_CACHELINE_SIZE_LOG 6
461 #endif
462 #ifndef GPR_CACHELINE_SIZE_LOG
463 /* A reasonable default guess. Note that overestimates tend to waste more
464    space, while underestimates tend to waste more time. */
465 #define GPR_CACHELINE_SIZE_LOG 6
466 #endif /* GPR_CACHELINE_SIZE_LOG */
467 #endif /* GPR_CACHELINE_SIZE_LOG */
468 
469 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
470 
471 /* scrub GCC_ATOMIC if it's not available on this compiler */
472 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
473 #undef GPR_GCC_ATOMIC
474 #define GPR_GCC_SYNC 1
475 #endif
476 
477 /* Validate platform combinations */
478 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
479         defined(GPR_WINDOWS_ATOMIC) !=                \
480     1
481 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
482 #endif
483 
484 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
485 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
486 #endif
487 
488 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
489         defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) !=                 \
490     1
491 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
492 #endif
493 
494 #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \
495         defined(GPR_STDCPP_TLS) + defined(GPR_CUSTOM_TLS) !=                  \
496     1
497 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_STDCPP_TLS, GPR_CUSTOM_TLS
498 #endif
499 
500 /* maximum alignment needed for any type on this platform, rounded up to a
501    power of two */
502 #define GPR_MAX_ALIGNMENT 16
503 
504 #ifndef GRPC_ARES
505 #define GRPC_ARES 1
506 #endif
507 
508 #ifndef GRPC_IF_NAMETOINDEX
509 #define GRPC_IF_NAMETOINDEX 1
510 #endif
511 
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)))
516 #else
517 #define GRPC_MUST_USE_RESULT
518 #define GPR_ALIGN_STRUCT(n)
519 #endif
520 #endif
521 
522 #ifndef GRPC_UNUSED
523 #if defined(__GNUC__) && !defined(__MINGW32__)
524 #define GRPC_UNUSED __attribute__((unused))
525 #else
526 #define GRPC_UNUSED
527 #endif
528 #endif
529 
530 #ifndef GPR_PRINT_FORMAT_CHECK
531 #ifdef __GNUC__
532 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
533   __attribute__((format(printf, FORMAT_STR, ARGS)))
534 #else
535 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
536 #endif
537 #endif /* GPR_PRINT_FORMAT_CHECK */
538 
539 #if GPR_FORBID_UNREACHABLE_CODE
540 #define GPR_UNREACHABLE_CODE(STATEMENT)
541 #else
542 #define GPR_UNREACHABLE_CODE(STATEMENT)             \
543   do {                                              \
544     gpr_log(GPR_ERROR, "Should never reach here."); \
545     abort();                                        \
546     STATEMENT;                                      \
547   } while (0)
548 #endif /* GPR_FORBID_UNREACHABLE_CODE */
549 
550 #ifndef GPRAPI
551 #define GPRAPI
552 #endif
553 
554 #ifndef GRPCAPI
555 #define GRPCAPI GPRAPI
556 #endif
557 
558 #ifndef CENSUSAPI
559 #define CENSUSAPI GRPCAPI
560 #endif
561 
562 #ifndef GPR_HAS_ATTRIBUTE
563 #ifdef __has_attribute
564 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
565 #else
566 #define GPR_HAS_ATTRIBUTE(a) 0
567 #endif
568 #endif /* GPR_HAS_ATTRIBUTE */
569 
570 #ifndef GPR_HAS_FEATURE
571 #ifdef __has_feature
572 #define GPR_HAS_FEATURE(a) __has_feature(a)
573 #else
574 #define GPR_HAS_FEATURE(a) 0
575 #endif
576 #endif /* GPR_HAS_FEATURE */
577 
578 #ifndef GPR_ATTRIBUTE_NOINLINE
579 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
580 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
581 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
582 #else
583 #define GPR_ATTRIBUTE_NOINLINE
584 #endif
585 #endif /* GPR_ATTRIBUTE_NOINLINE */
586 
587 #ifndef GPR_ATTRIBUTE_WEAK
588 /* Attribute weak is broken on LLVM/windows:
589  * https://bugs.llvm.org/show_bug.cgi?id=37598 */
590 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
591     !(defined(__llvm__) && defined(_WIN32))
592 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
593 #define GPR_HAS_ATTRIBUTE_WEAK 1
594 #else
595 #define GPR_ATTRIBUTE_WEAK
596 #endif
597 #endif /* GPR_ATTRIBUTE_WEAK */
598 
599 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
600 #if GPR_HAS_FEATURE(thread_sanitizer)
601 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
602 #endif                        /* GPR_HAS_FEATURE */
603 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
604 #define GPR_ATTRIBUTE_NO_TSAN
605 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
606 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
607 
608 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
609 #ifndef GRPC_TSAN_SUPPRESSED
610 #if defined(__SANITIZE_THREAD__)
611 #define GRPC_TSAN_ENABLED
612 #elif GPR_HAS_FEATURE(thread_sanitizer)
613 #define GRPC_TSAN_ENABLED
614 #endif
615 #endif
616 
617 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
618 #ifndef GRPC_ASAN_SUPPRESSED
619 #if defined(__SANITIZE_ADDRESS__)
620 #define GRPC_ASAN_ENABLED
621 #elif GPR_HAS_FEATURE(address_sanitizer)
622 #define GRPC_ASAN_ENABLED
623 #endif
624 #endif
625 
626 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
627 #ifndef GRPC_ALLOW_EXCEPTIONS
628 #ifdef GPR_WINDOWS
629 #if defined(_MSC_VER) && defined(_CPPUNWIND)
630 #define GRPC_ALLOW_EXCEPTIONS 1
631 #elif defined(__EXCEPTIONS)
632 #define GRPC_ALLOW_EXCEPTIONS 1
633 #else
634 #define GRPC_ALLOW_EXCEPTIONS 0
635 #endif
636 #else /* GPR_WINDOWS */
637 #ifdef __EXCEPTIONS
638 #define GRPC_ALLOW_EXCEPTIONS 1
639 #else /* __EXCEPTIONS */
640 #define GRPC_ALLOW_EXCEPTIONS 0
641 #endif /* __EXCEPTIONS */
642 #endif /* __GPR_WINDOWS */
643 #endif /* GRPC_ALLOW_EXCEPTIONS */
644 
645 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
646  * most likely. Ideally, also collect performance numbers to justify the claim.
647  */
648 #ifdef __GNUC__
649 #define GPR_LIKELY(x) __builtin_expect((x), 1)
650 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
651 #else /* __GNUC__ */
652 #define GPR_LIKELY(x) (x)
653 #define GPR_UNLIKELY(x) (x)
654 #endif /* __GNUC__ */
655 
656 #ifndef __STDC_FORMAT_MACROS
657 #define __STDC_FORMAT_MACROS
658 #endif
659 
660 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */
661