Imported Upstream version 1.41.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 // IWYU pragma: private, include <grpc/support/port_platform.h>
23
24 /*
25  * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI
26  * compatible with older platforms (currently only on Linux)
27  * Causes:
28  *  - some libc calls to be gotten via dlsym
29  *  - some syscalls to be made directly
30  */
31
32 // [[deprecated]] attribute is only available since C++14
33 #if __cplusplus >= 201402L
34 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
35 #else
36 #define GRPC_DEPRECATED(reason)
37 #endif  // __cplusplus >= 201402L
38
39 /*
40  * Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil
41  */
42 #ifndef GPR_ABSEIL_SYNC
43 #if defined(__APPLE__)
44 // This is disabled on Apple platforms because macos/grpc_basictests_c_cpp
45 // fails with this. https://github.com/grpc/grpc/issues/23661
46 #else
47 #define GPR_ABSEIL_SYNC 1
48 #endif
49 #endif  // GPR_ABSEIL_SYNC
50
51 /*
52  * Defines GRPC_ERROR_IS_ABSEIL_STATUS to use absl::Status for grpc_error_handle
53  */
54 // #define GRPC_ERROR_IS_ABSEIL_STATUS 1
55
56 /* Get windows.h included everywhere (we need it) */
57 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
58 #ifndef WIN32_LEAN_AND_MEAN
59 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
60 #define WIN32_LEAN_AND_MEAN
61 #endif /* WIN32_LEAN_AND_MEAN */
62
63 #ifndef NOMINMAX
64 #define GRPC_NOMINMX_WAS_NOT_DEFINED
65 #define NOMINMAX
66 #endif /* NOMINMAX */
67
68 #include <windows.h>
69
70 #ifndef _WIN32_WINNT
71 #error \
72     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
73 #else /* !defined(_WIN32_WINNT) */
74 #if (_WIN32_WINNT < 0x0600)
75 #error \
76     "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
77 #endif /* _WIN32_WINNT < 0x0600 */
78 #endif /* defined(_WIN32_WINNT) */
79
80 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
81 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
82 #undef WIN32_LEAN_AND_MEAN
83 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
84
85 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
86 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
87 #undef NOMINMAX
88 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
89 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
90           defined(WIN32) */
91
92 /* Override this file with one for your platform if you need to redefine
93    things.  */
94
95 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
96 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
97 #if defined(_WIN64) || defined(WIN64)
98 #define GPR_ARCH_64 1
99 #else
100 #define GPR_ARCH_32 1
101 #endif
102 #define GPR_PLATFORM_STRING "windows"
103 #define GPR_WINDOWS 1
104 #define GPR_WINDOWS_SUBPROCESS 1
105 #define GPR_WINDOWS_ENV
106 #ifdef __MSYS__
107 #define GPR_GETPID_IN_UNISTD_H 1
108 #define GPR_MSYS_TMPFILE
109 #define GPR_POSIX_LOG
110 #define GPR_POSIX_STRING
111 #define GPR_POSIX_TIME
112 #else
113 #define GPR_GETPID_IN_PROCESS_H 1
114 #define GPR_WINDOWS_TMPFILE
115 #define GPR_WINDOWS_LOG
116 #define GPR_WINDOWS_CRASH_HANDLER 1
117 #define GPR_WINDOWS_STAT
118 #define GPR_WINDOWS_STRING
119 #define GPR_WINDOWS_TIME
120 #endif
121 #ifdef __GNUC__
122 #define GPR_GCC_ATOMIC 1
123 #else
124 #define GPR_WINDOWS_ATOMIC 1
125 #endif
126 #elif defined(ANDROID) || defined(__ANDROID__)
127 #define GPR_PLATFORM_STRING "android"
128 #define GPR_ANDROID 1
129 #ifdef __ANDROID_API__
130 #if (__ANDROID_API__) >= 29
131 #define GPR_SUPPORT_BINDER_TRANSPORT 1
132 #endif
133 #endif
134 // TODO(apolcyn): re-evaluate support for c-ares
135 // on android after upgrading our c-ares dependency.
136 // See https://github.com/grpc/grpc/issues/18038.
137 #define GRPC_ARES 0
138 #ifdef _LP64
139 #define GPR_ARCH_64 1
140 #else /* _LP64 */
141 #define GPR_ARCH_32 1
142 #endif /* _LP64 */
143 #define GPR_CPU_POSIX 1
144 #define GPR_GCC_SYNC 1
145 #define GPR_POSIX_ENV 1
146 #define GPR_POSIX_TMPFILE 1
147 #define GPR_POSIX_STAT 1
148 #define GPR_ANDROID_LOG 1
149 #define GPR_POSIX_STRING 1
150 #define GPR_POSIX_SUBPROCESS 1
151 #define GPR_POSIX_SYNC 1
152 #define GPR_POSIX_TIME 1
153 #define GPR_HAS_PTHREAD_H 1
154 #define GPR_GETPID_IN_UNISTD_H 1
155 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
156 #elif defined(__linux__)
157 #define GPR_PLATFORM_STRING "linux"
158 #ifndef _BSD_SOURCE
159 #define _BSD_SOURCE
160 #endif
161 #ifndef _DEFAULT_SOURCE
162 #define _DEFAULT_SOURCE
163 #endif
164 #ifndef _GNU_SOURCE
165 #define _GNU_SOURCE
166 #endif
167 #include <features.h>
168 #define GPR_CPU_LINUX 1
169 #define GPR_GCC_ATOMIC 1
170 #define GPR_LINUX 1
171 #define GPR_LINUX_LOG
172 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
173 #define GPR_LINUX_ENV 1
174 #define GPR_POSIX_TMPFILE 1
175 #define GPR_POSIX_STAT 1
176 #define GPR_POSIX_STRING 1
177 #define GPR_POSIX_SUBPROCESS 1
178 #define GPR_POSIX_SYNC 1
179 #define GPR_POSIX_TIME 1
180 #define GPR_HAS_PTHREAD_H 1
181 #define GPR_GETPID_IN_UNISTD_H 1
182 #ifdef _LP64
183 #define GPR_ARCH_64 1
184 #else /* _LP64 */
185 #define GPR_ARCH_32 1
186 #endif /* _LP64 */
187 #ifdef __GLIBC__
188 #define GPR_POSIX_CRASH_HANDLER 1
189 #define GPR_LINUX_PTHREAD_NAME 1
190 #include <linux/version.h>
191 #else /* musl libc */
192 #define GPR_MUSL_LIBC_COMPAT 1
193 #endif
194 #elif defined(__ASYLO__)
195 #define GPR_ARCH_64 1
196 #define GPR_CPU_POSIX 1
197 #define GPR_PLATFORM_STRING "asylo"
198 #define GPR_GCC_SYNC 1
199 #define GPR_POSIX_SYNC 1
200 #define GPR_POSIX_STRING 1
201 #define GPR_POSIX_LOG 1
202 #define GPR_POSIX_TIME 1
203 #define GPR_POSIX_ENV 1
204 #define GPR_ASYLO 1
205 #define GRPC_POSIX_SOCKET 1
206 #define GRPC_POSIX_SOCKETADDR
207 #define GRPC_POSIX_SOCKETUTILS 1
208 #define GRPC_TIMER_USE_GENERIC 1
209 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
210 #define GRPC_POSIX_WAKEUP_FD 1
211 #define GRPC_ARES 0
212 #define GPR_NO_AUTODETECT_PLATFORM 1
213 #elif defined(__APPLE__)
214 #include <Availability.h>
215 #include <TargetConditionals.h>
216 #ifndef _BSD_SOURCE
217 #define _BSD_SOURCE
218 #endif
219 #if TARGET_OS_IPHONE
220 #define GPR_PLATFORM_STRING "ios"
221 #define GPR_CPU_IPHONE 1
222 #define GRPC_CFSTREAM 1
223 /* the c-ares resolver isn't safe to enable on iOS */
224 #define GRPC_ARES 0
225 #else /* TARGET_OS_IPHONE */
226 #define GPR_PLATFORM_STRING "osx"
227 #define GPR_CPU_POSIX 1
228 #define GPR_POSIX_CRASH_HANDLER 1
229 #endif
230 #if !(defined(__has_feature) && __has_feature(cxx_thread_local))
231 #define GPR_PTHREAD_TLS 1
232 #endif
233 #define GPR_APPLE 1
234 #define GPR_GCC_ATOMIC 1
235 #define GPR_POSIX_LOG 1
236 #define GPR_POSIX_ENV 1
237 #define GPR_POSIX_TMPFILE 1
238 #define GPR_POSIX_STAT 1
239 #define GPR_POSIX_STRING 1
240 #define GPR_POSIX_SUBPROCESS 1
241 #define GPR_POSIX_SYNC 1
242 #define GPR_POSIX_TIME 1
243 #define GPR_HAS_PTHREAD_H 1
244 #define GPR_GETPID_IN_UNISTD_H 1
245 #ifndef GRPC_CFSTREAM
246 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
247 #endif
248 #ifdef _LP64
249 #define GPR_ARCH_64 1
250 #else /* _LP64 */
251 #define GPR_ARCH_32 1
252 #endif /* _LP64 */
253 #elif defined(__FreeBSD__)
254 #define GPR_PLATFORM_STRING "freebsd"
255 #ifndef _BSD_SOURCE
256 #define _BSD_SOURCE
257 #endif
258 #define GPR_FREEBSD 1
259 #define GPR_CPU_POSIX 1
260 #define GPR_GCC_ATOMIC 1
261 #define GPR_POSIX_LOG 1
262 #define GPR_POSIX_ENV 1
263 #define GPR_POSIX_TMPFILE 1
264 #define GPR_POSIX_STAT 1
265 #define GPR_POSIX_STRING 1
266 #define GPR_POSIX_SUBPROCESS 1
267 #define GPR_POSIX_SYNC 1
268 #define GPR_POSIX_TIME 1
269 #define GPR_HAS_PTHREAD_H 1
270 #define GPR_GETPID_IN_UNISTD_H 1
271 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
272 #ifdef _LP64
273 #define GPR_ARCH_64 1
274 #else /* _LP64 */
275 #define GPR_ARCH_32 1
276 #endif /* _LP64 */
277 #elif defined(__OpenBSD__)
278 #define GPR_PLATFORM_STRING "openbsd"
279 #ifndef _BSD_SOURCE
280 #define _BSD_SOURCE
281 #endif
282 #define GPR_OPENBSD 1
283 #define GPR_CPU_POSIX 1
284 #define GPR_GCC_ATOMIC 1
285 #define GPR_POSIX_LOG 1
286 #define GPR_POSIX_ENV 1
287 #define GPR_POSIX_TMPFILE 1
288 #define GPR_POSIX_STAT 1
289 #define GPR_POSIX_STRING 1
290 #define GPR_POSIX_SUBPROCESS 1
291 #define GPR_POSIX_SYNC 1
292 #define GPR_POSIX_TIME 1
293 #define GPR_HAS_PTHREAD_H 1
294 #define GPR_GETPID_IN_UNISTD_H 1
295 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
296 #ifdef _LP64
297 #define GPR_ARCH_64 1
298 #else /* _LP64 */
299 #define GPR_ARCH_32 1
300 #endif /* _LP64 */
301 #elif defined(__sun) && defined(__SVR4)
302 #define GPR_PLATFORM_STRING "solaris"
303 #define GPR_SOLARIS 1
304 #define GPR_CPU_POSIX 1
305 #define GPR_GCC_ATOMIC 1
306 #define GPR_POSIX_LOG 1
307 #define GPR_POSIX_ENV 1
308 #define GPR_POSIX_TMPFILE 1
309 #define GPR_POSIX_STAT 1
310 #define GPR_POSIX_STRING 1
311 #define GPR_POSIX_SUBPROCESS 1
312 #define GPR_POSIX_SYNC 1
313 #define GPR_POSIX_TIME 1
314 #define GPR_HAS_PTHREAD_H 1
315 #define GPR_GETPID_IN_UNISTD_H 1
316 #ifdef _LP64
317 #define GPR_ARCH_64 1
318 #else /* _LP64 */
319 #define GPR_ARCH_32 1
320 #endif /* _LP64 */
321 #elif defined(_AIX)
322 #define GPR_PLATFORM_STRING "aix"
323 #ifndef _ALL_SOURCE
324 #define _ALL_SOURCE
325 #endif
326 #define GPR_AIX 1
327 #define GPR_CPU_POSIX 1
328 #define GPR_GCC_ATOMIC 1
329 #define GPR_POSIX_LOG 1
330 #define GPR_POSIX_ENV 1
331 #define GPR_POSIX_TMPFILE 1
332 #define GPR_POSIX_STAT 1
333 #define GPR_POSIX_STRING 1
334 #define GPR_POSIX_SUBPROCESS 1
335 #define GPR_POSIX_SYNC 1
336 #define GPR_POSIX_TIME 1
337 #define GPR_HAS_PTHREAD_H 1
338 #define GPR_GETPID_IN_UNISTD_H 1
339 #ifdef _LP64
340 #define GPR_ARCH_64 1
341 #else /* _LP64 */
342 #define GPR_ARCH_32 1
343 #endif /* _LP64 */
344 #elif defined(__native_client__)
345 #define GPR_PLATFORM_STRING "nacl"
346 #ifndef _BSD_SOURCE
347 #define _BSD_SOURCE
348 #endif
349 #ifndef _DEFAULT_SOURCE
350 #define _DEFAULT_SOURCE
351 #endif
352 #ifndef _GNU_SOURCE
353 #define _GNU_SOURCE
354 #endif
355 #define GPR_NACL 1
356 #define GPR_CPU_POSIX 1
357 #define GPR_GCC_ATOMIC 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
368 #ifdef _LP64
369 #define GPR_ARCH_64 1
370 #else /* _LP64 */
371 #define GPR_ARCH_32 1
372 #endif /* _LP64 */
373 #elif defined(__Fuchsia__)
374 #define GRPC_ARES 0
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
380 // invoked.
381 #define GPR_MUSL_LIBC_COMPAT 1
382 #define GPR_CPU_POSIX 1
383 #define GPR_GCC_ATOMIC 1
384 #define GPR_POSIX_LOG 1
385 #define GPR_POSIX_SYNC 1
386 #define GPR_POSIX_ENV 1
387 #define GPR_POSIX_TMPFILE 1
388 #define GPR_POSIX_STAT 1
389 #define GPR_POSIX_SUBPROCESS 1
390 #define GPR_POSIX_SYNC 1
391 #define GPR_POSIX_STRING 1
392 #define GPR_POSIX_TIME 1
393 #define GPR_HAS_PTHREAD_H 1
394 #define GPR_GETPID_IN_UNISTD_H 1
395 #define GRPC_ROOT_PEM_PATH "/config/ssl/cert.pem"
396 #else
397 #error "Could not auto-detect platform"
398 #endif
399 #endif /* GPR_NO_AUTODETECT_PLATFORM */
400
401 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
402 /*
403  * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
404  * a library from having non-standard symbols such as __asprintf_chk.
405  * This helps non-glibc systems such as alpine using musl to find symbols.
406  */
407 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
408 #undef _FORTIFY_SOURCE
409 #define _FORTIFY_SOURCE 0
410 #endif
411 #endif
412
413 #if defined(__has_include)
414 #if __has_include(<atomic>)
415 #define GRPC_HAS_CXX11_ATOMIC
416 #endif /* __has_include(<atomic>) */
417 #endif /* defined(__has_include) */
418
419 #ifndef GPR_PLATFORM_STRING
420 #warning "GPR_PLATFORM_STRING not auto-detected"
421 #define GPR_PLATFORM_STRING "unknown"
422 #endif
423
424 #ifdef GPR_GCOV
425 #undef GPR_FORBID_UNREACHABLE_CODE
426 #define GPR_FORBID_UNREACHABLE_CODE 1
427 #endif
428
429 #ifdef _MSC_VER
430 #if _MSC_VER < 1700
431 typedef __int8 int8_t;
432 typedef __int16 int16_t;
433 typedef __int32 int32_t;
434 typedef __int64 int64_t;
435 typedef unsigned __int8 uint8_t;
436 typedef unsigned __int16 uint16_t;
437 typedef unsigned __int32 uint32_t;
438 typedef unsigned __int64 uint64_t;
439 #else
440 #include <stdint.h>
441 #endif /* _MSC_VER < 1700 */
442 #else
443 #include <stdint.h>
444 #endif /* _MSC_VER */
445
446 /* Type of cycle clock implementation */
447 #ifdef GPR_LINUX
448 /* Disable cycle clock by default.
449    TODO(soheil): enable when we support fallback for unstable cycle clocks.
450 #if defined(__i386__)
451 #define GPR_CYCLE_COUNTER_RDTSC_32 1
452 #elif defined(__x86_64__) || defined(__amd64__)
453 #define GPR_CYCLE_COUNTER_RDTSC_64 1
454 #else
455 #define GPR_CYCLE_COUNTER_FALLBACK 1
456 #endif
457 */
458 #define GPR_CYCLE_COUNTER_FALLBACK 1
459 #else
460 #define GPR_CYCLE_COUNTER_FALLBACK 1
461 #endif /* GPR_LINUX */
462
463 /* Cache line alignment */
464 #ifndef GPR_CACHELINE_SIZE_LOG
465 #if defined(__i386__) || defined(__x86_64__)
466 #define GPR_CACHELINE_SIZE_LOG 6
467 #endif
468 #ifndef GPR_CACHELINE_SIZE_LOG
469 /* A reasonable default guess. Note that overestimates tend to waste more
470    space, while underestimates tend to waste more time. */
471 #define GPR_CACHELINE_SIZE_LOG 6
472 #endif /* GPR_CACHELINE_SIZE_LOG */
473 #endif /* GPR_CACHELINE_SIZE_LOG */
474
475 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
476
477 /* scrub GCC_ATOMIC if it's not available on this compiler */
478 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
479 #undef GPR_GCC_ATOMIC
480 #define GPR_GCC_SYNC 1
481 #endif
482
483 /* Validate platform combinations */
484 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
485         defined(GPR_WINDOWS_ATOMIC) !=                \
486     1
487 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
488 #endif
489
490 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
491 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
492 #endif
493
494 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
495         defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) !=                 \
496     1
497 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
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_CPP_ATTRIBUTE
563 #ifdef __has_cpp_attribute
564 #define GPR_HAS_CPP_ATTRIBUTE(a) __has_cpp_attribute(a)
565 #else
566 #define GPR_HAS_CPP_ATTRIBUTE(a) 0
567 #endif
568 #endif /* GPR_HAS_CPP_ATTRIBUTE */
569
570 #ifndef GPR_HAS_ATTRIBUTE
571 #ifdef __has_attribute
572 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
573 #else
574 #define GPR_HAS_ATTRIBUTE(a) 0
575 #endif
576 #endif /* GPR_HAS_ATTRIBUTE */
577
578 #ifndef GPR_HAS_FEATURE
579 #ifdef __has_feature
580 #define GPR_HAS_FEATURE(a) __has_feature(a)
581 #else
582 #define GPR_HAS_FEATURE(a) 0
583 #endif
584 #endif /* GPR_HAS_FEATURE */
585
586 #ifndef GPR_ATTRIBUTE_NOINLINE
587 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
588 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
589 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
590 #else
591 #define GPR_ATTRIBUTE_NOINLINE
592 #endif
593 #endif /* GPR_ATTRIBUTE_NOINLINE */
594
595 #ifndef GPR_NO_UNIQUE_ADDRESS
596 #if GPR_HAS_CPP_ATTRIBUTE(no_unique_address)
597 #define GPR_NO_UNIQUE_ADDRESS [[no_unique_address]]
598 #else
599 #define GPR_NO_UNIQUE_ADDRESS
600 #endif
601 #endif /* GPR_NO_UNIQUE_ADDRESS */
602
603 #ifndef GRPC_DEPRECATED
604 #if GPR_HAS_CPP_ATTRIBUTE(deprecated)
605 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
606 #else
607 #define GRPC_DEPRECATED(reason)
608 #endif
609 #endif /* GRPC_DEPRECATED */
610
611 #ifndef GPR_ATTRIBUTE_WEAK
612 /* Attribute weak is broken on LLVM/windows:
613  * https://bugs.llvm.org/show_bug.cgi?id=37598 */
614 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
615     !(defined(__llvm__) && defined(_WIN32))
616 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
617 #define GPR_HAS_ATTRIBUTE_WEAK 1
618 #else
619 #define GPR_ATTRIBUTE_WEAK
620 #endif
621 #endif /* GPR_ATTRIBUTE_WEAK */
622
623 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
624 #if GPR_HAS_FEATURE(thread_sanitizer)
625 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
626 #endif                        /* GPR_HAS_FEATURE */
627 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
628 #define GPR_ATTRIBUTE_NO_TSAN
629 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
630 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
631
632 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
633 #ifndef GRPC_TSAN_SUPPRESSED
634 #if defined(__SANITIZE_THREAD__)
635 #define GRPC_TSAN_ENABLED
636 #elif GPR_HAS_FEATURE(thread_sanitizer)
637 #define GRPC_TSAN_ENABLED
638 #endif
639 #endif
640
641 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
642 #ifndef GRPC_ASAN_SUPPRESSED
643 #if defined(__SANITIZE_ADDRESS__)
644 #define GRPC_ASAN_ENABLED
645 #elif GPR_HAS_FEATURE(address_sanitizer)
646 #define GRPC_ASAN_ENABLED
647 #endif
648 #endif
649
650 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
651 #ifndef GRPC_ALLOW_EXCEPTIONS
652 #ifdef GPR_WINDOWS
653 #if defined(_MSC_VER) && defined(_CPPUNWIND)
654 #define GRPC_ALLOW_EXCEPTIONS 1
655 #elif defined(__EXCEPTIONS)
656 #define GRPC_ALLOW_EXCEPTIONS 1
657 #else
658 #define GRPC_ALLOW_EXCEPTIONS 0
659 #endif
660 #else /* GPR_WINDOWS */
661 #ifdef __EXCEPTIONS
662 #define GRPC_ALLOW_EXCEPTIONS 1
663 #else /* __EXCEPTIONS */
664 #define GRPC_ALLOW_EXCEPTIONS 0
665 #endif /* __EXCEPTIONS */
666 #endif /* __GPR_WINDOWS */
667 #endif /* GRPC_ALLOW_EXCEPTIONS */
668
669 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
670  * most likely. Ideally, also collect performance numbers to justify the claim.
671  */
672 #ifdef __GNUC__
673 #define GPR_LIKELY(x) __builtin_expect((x), 1)
674 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
675 #else /* __GNUC__ */
676 #define GPR_LIKELY(x) (x)
677 #define GPR_UNLIKELY(x) (x)
678 #endif /* __GNUC__ */
679
680 #ifndef __STDC_FORMAT_MACROS
681 #define __STDC_FORMAT_MACROS
682 #endif
683
684 /* Selectively enable EventEngine on specific platforms. This default can be
685  * overridden using the GRPC_USE_EVENT_ENGINE compiler flag.
686  */
687 #ifndef GRPC_USE_EVENT_ENGINE
688 /* Not enabled by default on any platforms yet. (2021.06) */
689 #elif GRPC_USE_EVENT_ENGINE == 0
690 /* Building with `-DGRPC_USE_EVENT_ENGINE=0` will override the default. */
691 #undef GRPC_USE_EVENT_ENGINE
692 #endif /* GRPC_USE_EVENT_ENGINE */
693
694 #ifdef GRPC_USE_EVENT_ENGINE
695 #undef GPR_SUPPORT_CHANNELS_FROM_FD
696 #define GRPC_ARES 0
697 #endif /* GRPC_USE_EVENT_ENGINE */
698
699 #define GRPC_CALLBACK_API_NONEXPERIMENTAL
700
701 /* clang 11 with msan miscompiles destruction of [[no_unique_address]] members
702  * of zero size - for a repro see:
703  * test/core/compiler_bugs/miscompile_with_no_unique_address_test.cc
704  */
705 #ifdef __clang__
706 #if __clang__ && __clang_major__ <= 11 && __has_feature(memory_sanitizer)
707 #undef GPR_NO_UNIQUE_ADDRESS
708 #define GPR_NO_UNIQUE_ADDRESS
709 #endif
710 #endif
711
712 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */