GRPC C++  1.50.0
port_platform.h
Go to the documentation of this file.
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 /* Get windows.h included everywhere (we need it) */
52 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
53 #ifndef WIN32_LEAN_AND_MEAN
54 #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
55 #define WIN32_LEAN_AND_MEAN
56 #endif /* WIN32_LEAN_AND_MEAN */
57 
58 #ifndef NOMINMAX
59 #define GRPC_NOMINMX_WAS_NOT_DEFINED
60 #define NOMINMAX
61 #endif /* NOMINMAX */
62 
63 #include <windows.h>
64 
65 #ifndef _WIN32_WINNT
66 #error \
67  "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
68 #else /* !defined(_WIN32_WINNT) */
69 #if (_WIN32_WINNT < 0x0600)
70 #error \
71  "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
72 #endif /* _WIN32_WINNT < 0x0600 */
73 #endif /* defined(_WIN32_WINNT) */
74 
75 #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
76 #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
77 #undef WIN32_LEAN_AND_MEAN
78 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
79 
80 #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED
81 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
82 #undef NOMINMAX
83 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
84 #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
85  defined(WIN32) */
86 
87 /* Override this file with one for your platform if you need to redefine
88  things. */
89 
90 #if !defined(GPR_NO_AUTODETECT_PLATFORM)
91 #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
92 #if defined(_WIN64) || defined(WIN64)
93 #define GPR_ARCH_64 1
94 #else
95 #define GPR_ARCH_32 1
96 #endif
97 #define GPR_PLATFORM_STRING "windows"
98 #define GPR_WINDOWS 1
99 #define GPR_WINDOWS_SUBPROCESS 1
100 #define GPR_WINDOWS_ENV
101 #ifdef __MSYS__
102 #define GPR_GETPID_IN_UNISTD_H 1
103 #define GPR_MSYS_TMPFILE
104 #define GPR_POSIX_LOG
105 #define GPR_POSIX_STRING
106 #define GPR_POSIX_TIME
107 #else
108 #define GPR_GETPID_IN_PROCESS_H 1
109 #define GPR_WINDOWS_TMPFILE
110 #define GPR_WINDOWS_LOG
111 #define GPR_WINDOWS_CRASH_HANDLER 1
112 #define GPR_WINDOWS_STAT
113 #define GPR_WINDOWS_STRING
114 #define GPR_WINDOWS_TIME
115 #endif
116 #ifdef __GNUC__
117 #define GPR_GCC_ATOMIC 1
118 #else
119 #define GPR_WINDOWS_ATOMIC 1
120 #endif
121 #elif defined(ANDROID) || defined(__ANDROID__)
122 #define GPR_PLATFORM_STRING "android"
123 #define GPR_ANDROID 1
124 #ifndef __ANDROID_API__
125 #error "__ANDROID_API__ must be defined for Android builds."
126 #endif
127 #if __ANDROID_API__ < 21
128 #error "Requires Android API v21 and above"
129 #endif
130 #define GPR_SUPPORT_BINDER_TRANSPORT 1
131 // TODO(apolcyn): re-evaluate support for c-ares
132 // on android after upgrading our c-ares dependency.
133 // See https://github.com/grpc/grpc/issues/18038.
134 #define GRPC_ARES 0
135 #ifdef _LP64
136 #define GPR_ARCH_64 1
137 #else /* _LP64 */
138 #define GPR_ARCH_32 1
139 #endif /* _LP64 */
140 #define GPR_CPU_POSIX 1
141 #define GPR_GCC_SYNC 1
142 #define GPR_POSIX_ENV 1
143 #define GPR_POSIX_TMPFILE 1
144 #define GPR_POSIX_STAT 1
145 #define GPR_ANDROID_LOG 1
146 #define GPR_POSIX_STRING 1
147 #define GPR_POSIX_SUBPROCESS 1
148 #define GPR_POSIX_SYNC 1
149 #define GPR_POSIX_TIME 1
150 #define GPR_HAS_PTHREAD_H 1
151 #define GPR_GETPID_IN_UNISTD_H 1
152 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
153 #elif defined(__linux__)
154 #define GPR_PLATFORM_STRING "linux"
155 #ifndef _BSD_SOURCE
156 #define _BSD_SOURCE
157 #endif
158 #ifndef _DEFAULT_SOURCE
159 #define _DEFAULT_SOURCE
160 #endif
161 #ifndef _GNU_SOURCE
162 #define _GNU_SOURCE
163 #endif
164 #include <features.h>
165 #define GPR_CPU_LINUX 1
166 #define GPR_GCC_ATOMIC 1
167 #define GPR_LINUX 1
168 #define GPR_LINUX_LOG
169 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
170 #define GPR_LINUX_ENV 1
171 #define GPR_POSIX_TMPFILE 1
172 #define GPR_POSIX_STAT 1
173 #define GPR_POSIX_STRING 1
174 #define GPR_POSIX_SUBPROCESS 1
175 #define GPR_POSIX_SYNC 1
176 #define GPR_POSIX_TIME 1
177 #define GPR_HAS_PTHREAD_H 1
178 #define GPR_GETPID_IN_UNISTD_H 1
179 #ifdef _LP64
180 #define GPR_ARCH_64 1
181 #else /* _LP64 */
182 #define GPR_ARCH_32 1
183 #endif /* _LP64 */
184 #ifdef __GLIBC__
185 #define GPR_POSIX_CRASH_HANDLER 1
186 #ifdef __GLIBC_PREREQ
187 #if __GLIBC_PREREQ(2, 12)
188 #define GPR_LINUX_PTHREAD_NAME 1
189 #endif
190 #else
191 // musl libc & others
192 #define GPR_LINUX_PTHREAD_NAME 1
193 #endif
194 #include <linux/version.h>
195 #else /* musl libc */
196 #define GPR_MUSL_LIBC_COMPAT 1
197 #endif
198 #elif defined(__ASYLO__)
199 #define GPR_ARCH_64 1
200 #define GPR_CPU_POSIX 1
201 #define GPR_PLATFORM_STRING "asylo"
202 #define GPR_GCC_SYNC 1
203 #define GPR_POSIX_STAT 1
204 #define GPR_POSIX_SYNC 1
205 #define GPR_POSIX_STRING 1
206 #define GPR_POSIX_LOG 1
207 #define GPR_POSIX_TIME 1
208 #define GPR_POSIX_ENV 1
209 #define GPR_ASYLO 1
210 #define GRPC_POSIX_SOCKET 1
211 #define GRPC_POSIX_SOCKETADDR
212 #define GRPC_POSIX_SOCKETUTILS 1
213 #define GRPC_TIMER_USE_GENERIC 1
214 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
215 #define GRPC_POSIX_WAKEUP_FD 1
216 #define GRPC_HAVE_MSG_NOSIGNAL 1
217 #define GRPC_HAVE_UNIX_SOCKET 1
218 #define GRPC_ARES 0
219 #define GPR_NO_AUTODETECT_PLATFORM 1
220 #elif defined(__APPLE__)
221 #include <Availability.h>
222 #include <TargetConditionals.h>
223 #ifndef _BSD_SOURCE
224 #define _BSD_SOURCE
225 #endif
226 #if TARGET_OS_IPHONE
227 #define GPR_PLATFORM_STRING "ios"
228 #define GPR_CPU_IPHONE 1
229 #define GRPC_CFSTREAM 1
230 /* the c-ares resolver isn't safe to enable on iOS */
231 #define GRPC_ARES 0
232 #else /* TARGET_OS_IPHONE */
233 #define GPR_PLATFORM_STRING "osx"
234 #define GPR_CPU_POSIX 1
235 #define GPR_POSIX_CRASH_HANDLER 1
236 #endif
237 #if !(defined(__has_feature) && __has_feature(cxx_thread_local))
238 #define GPR_PTHREAD_TLS 1
239 #endif
240 #define GPR_APPLE 1
241 #define GPR_GCC_ATOMIC 1
242 #define GPR_POSIX_LOG 1
243 #define GPR_POSIX_ENV 1
244 #define GPR_POSIX_TMPFILE 1
245 #define GPR_POSIX_STAT 1
246 #define GPR_POSIX_STRING 1
247 #define GPR_POSIX_SUBPROCESS 1
248 #define GPR_POSIX_SYNC 1
249 #define GPR_POSIX_TIME 1
250 #define GPR_HAS_PTHREAD_H 1
251 #define GPR_GETPID_IN_UNISTD_H 1
252 #ifndef GRPC_CFSTREAM
253 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
254 #endif
255 #ifdef _LP64
256 #define GPR_ARCH_64 1
257 #else /* _LP64 */
258 #define GPR_ARCH_32 1
259 #endif /* _LP64 */
260 #elif defined(__FreeBSD__)
261 #define GPR_PLATFORM_STRING "freebsd"
262 #ifndef _BSD_SOURCE
263 #define _BSD_SOURCE
264 #endif
265 #define GPR_FREEBSD 1
266 #define GPR_CPU_POSIX 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_STAT 1
272 #define GPR_POSIX_STRING 1
273 #define GPR_POSIX_SUBPROCESS 1
274 #define GPR_POSIX_SYNC 1
275 #define GPR_POSIX_TIME 1
276 #define GPR_HAS_PTHREAD_H 1
277 #define GPR_GETPID_IN_UNISTD_H 1
278 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
279 #ifdef _LP64
280 #define GPR_ARCH_64 1
281 #else /* _LP64 */
282 #define GPR_ARCH_32 1
283 #endif /* _LP64 */
284 #elif defined(__OpenBSD__)
285 #define GPR_PLATFORM_STRING "openbsd"
286 #ifndef _BSD_SOURCE
287 #define _BSD_SOURCE
288 #endif
289 #define GPR_OPENBSD 1
290 #define GPR_CPU_POSIX 1
291 #define GPR_GCC_ATOMIC 1
292 #define GPR_POSIX_LOG 1
293 #define GPR_POSIX_ENV 1
294 #define GPR_POSIX_TMPFILE 1
295 #define GPR_POSIX_STAT 1
296 #define GPR_POSIX_STRING 1
297 #define GPR_POSIX_SUBPROCESS 1
298 #define GPR_POSIX_SYNC 1
299 #define GPR_POSIX_TIME 1
300 #define GPR_HAS_PTHREAD_H 1
301 #define GPR_GETPID_IN_UNISTD_H 1
302 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
303 #ifdef _LP64
304 #define GPR_ARCH_64 1
305 #else /* _LP64 */
306 #define GPR_ARCH_32 1
307 #endif /* _LP64 */
308 #elif defined(__sun) && defined(__SVR4)
309 #define GPR_PLATFORM_STRING "solaris"
310 #define GPR_SOLARIS 1
311 #define GPR_CPU_POSIX 1
312 #define GPR_GCC_ATOMIC 1
313 #define GPR_POSIX_LOG 1
314 #define GPR_POSIX_ENV 1
315 #define GPR_POSIX_TMPFILE 1
316 #define GPR_POSIX_STAT 1
317 #define GPR_POSIX_STRING 1
318 #define GPR_POSIX_SUBPROCESS 1
319 #define GPR_POSIX_SYNC 1
320 #define GPR_POSIX_TIME 1
321 #define GPR_HAS_PTHREAD_H 1
322 #define GPR_GETPID_IN_UNISTD_H 1
323 #ifdef _LP64
324 #define GPR_ARCH_64 1
325 #else /* _LP64 */
326 #define GPR_ARCH_32 1
327 #endif /* _LP64 */
328 #elif defined(_AIX)
329 #define GPR_PLATFORM_STRING "aix"
330 #ifndef _ALL_SOURCE
331 #define _ALL_SOURCE
332 #endif
333 #define GPR_AIX 1
334 #define GPR_CPU_POSIX 1
335 #define GPR_GCC_ATOMIC 1
336 #define GPR_POSIX_LOG 1
337 #define GPR_POSIX_ENV 1
338 #define GPR_POSIX_TMPFILE 1
339 #define GPR_POSIX_STAT 1
340 #define GPR_POSIX_STRING 1
341 #define GPR_POSIX_SUBPROCESS 1
342 #define GPR_POSIX_SYNC 1
343 #define GPR_POSIX_TIME 1
344 #define GPR_HAS_PTHREAD_H 1
345 #define GPR_GETPID_IN_UNISTD_H 1
346 #ifdef _LP64
347 #define GPR_ARCH_64 1
348 #else /* _LP64 */
349 #define GPR_ARCH_32 1
350 #endif /* _LP64 */
351 #elif defined(__NetBSD__)
352 // NetBSD is a community-supported platform.
353 // Please contact Thomas Klausner <wiz@NetBSD.org> for support.
354 #define GPR_PLATFORM_STRING "netbsd"
355 #ifndef _BSD_SOURCE
356 #define _BSD_SOURCE
357 #endif
358 #define GPR_NETBSD 1
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_STAT 1
366 #define GPR_POSIX_STRING 1
367 #define GPR_POSIX_SUBPROCESS 1
368 #define GPR_POSIX_SYNC 1
369 #define GPR_POSIX_TIME 1
370 #define GPR_GETPID_IN_UNISTD_H 1
371 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
372 #ifdef _LP64
373 #define GPR_ARCH_64 1
374 #else /* _LP64 */
375 #define GPR_ARCH_32 1
376 #endif /* _LP64 */
377 #elif defined(__native_client__)
378 #define GPR_PLATFORM_STRING "nacl"
379 #ifndef _BSD_SOURCE
380 #define _BSD_SOURCE
381 #endif
382 #ifndef _DEFAULT_SOURCE
383 #define _DEFAULT_SOURCE
384 #endif
385 #ifndef _GNU_SOURCE
386 #define _GNU_SOURCE
387 #endif
388 #define GPR_NACL 1
389 #define GPR_CPU_POSIX 1
390 #define GPR_GCC_ATOMIC 1
391 #define GPR_POSIX_LOG 1
392 #define GPR_POSIX_ENV 1
393 #define GPR_POSIX_TMPFILE 1
394 #define GPR_POSIX_STAT 1
395 #define GPR_POSIX_STRING 1
396 #define GPR_POSIX_SUBPROCESS 1
397 #define GPR_POSIX_SYNC 1
398 #define GPR_POSIX_TIME 1
399 #define GPR_HAS_PTHREAD_H 1
400 #define GPR_GETPID_IN_UNISTD_H 1
401 #ifdef _LP64
402 #define GPR_ARCH_64 1
403 #else /* _LP64 */
404 #define GPR_ARCH_32 1
405 #endif /* _LP64 */
406 #elif defined(__Fuchsia__)
407 #define GRPC_ARES 0
408 #define GPR_FUCHSIA 1
409 #define GPR_ARCH_64 1
410 #define GPR_PLATFORM_STRING "fuchsia"
411 #include <features.h>
412 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
413 // invoked.
414 #define GPR_MUSL_LIBC_COMPAT 1
415 #define GPR_CPU_POSIX 1
416 #define GPR_GCC_ATOMIC 1
417 #define GPR_POSIX_LOG 1
418 #define GPR_POSIX_SYNC 1
419 #define GPR_POSIX_ENV 1
420 #define GPR_POSIX_TMPFILE 1
421 #define GPR_POSIX_STAT 1
422 #define GPR_POSIX_SUBPROCESS 1
423 #define GPR_POSIX_SYNC 1
424 #define GPR_POSIX_STRING 1
425 #define GPR_POSIX_TIME 1
426 #define GPR_HAS_PTHREAD_H 1
427 #define GPR_GETPID_IN_UNISTD_H 1
428 #define GRPC_ROOT_PEM_PATH "/config/ssl/cert.pem"
429 #elif defined(__HAIKU__)
430 #define GPR_PLATFORM_STRING "haiku"
431 // Haiku is a community-supported platform.
432 // Please contact Jerome Duval <jerome.duval@gmail.com> for support.
433 #ifndef _BSD_SOURCE
434 #define _BSD_SOURCE
435 #endif
436 #define GPR_HAIKU 1
437 #define GPR_CPU_POSIX 1
438 #define GPR_GCC_ATOMIC 1
439 #define GPR_POSIX_LOG 1
440 #define GPR_POSIX_ENV 1
441 #define GPR_POSIX_TMPFILE 1
442 #define GPR_POSIX_STAT 1
443 #define GPR_POSIX_STRING 1
444 #define GPR_POSIX_SUBPROCESS 1
445 #define GPR_POSIX_SYNC 1
446 #define GPR_POSIX_TIME 1
447 #define GPR_HAS_PTHREAD_H 1
448 #define GPR_GETPID_IN_UNISTD_H 1
449 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
450 #ifdef _LP64
451 #define GPR_ARCH_64 1
452 #else /* _LP64 */
453 #define GPR_ARCH_32 1
454 #endif /* _LP64 */
455 #else
456 #error "Could not auto-detect platform"
457 #endif
458 #endif /* GPR_NO_AUTODETECT_PLATFORM */
459 
460 #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
461 /*
462  * For backward compatibility mode, reset _FORTIFY_SOURCE to prevent
463  * a library from having non-standard symbols such as __asprintf_chk.
464  * This helps non-glibc systems such as alpine using musl to find symbols.
465  */
466 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
467 #undef _FORTIFY_SOURCE
468 #define _FORTIFY_SOURCE 0
469 #endif
470 #endif
471 
472 #if defined(__has_include)
473 #if __has_include(<atomic>)
474 #define GRPC_HAS_CXX11_ATOMIC
475 #endif /* __has_include(<atomic>) */
476 #endif /* defined(__has_include) */
477 
478 #ifndef GPR_PLATFORM_STRING
479 #warning "GPR_PLATFORM_STRING not auto-detected"
480 #define GPR_PLATFORM_STRING "unknown"
481 #endif
482 
483 #ifdef GPR_GCOV
484 #undef GPR_FORBID_UNREACHABLE_CODE
485 #define GPR_FORBID_UNREACHABLE_CODE 1
486 #endif
487 
488 #ifdef _MSC_VER
489 #if _MSC_VER < 1700
490 typedef __int8 int8_t;
491 typedef __int16 int16_t;
492 typedef __int32 int32_t;
493 typedef __int64 int64_t;
494 typedef unsigned __int8 uint8_t;
495 typedef unsigned __int16 uint16_t;
496 typedef unsigned __int32 uint32_t;
497 typedef unsigned __int64 uint64_t;
498 #else
499 #include <stdint.h>
500 #endif /* _MSC_VER < 1700 */
501 #else
502 #include <stdint.h>
503 #endif /* _MSC_VER */
504 
505 /* Type of cycle clock implementation */
506 #ifdef GPR_LINUX
507 /* Disable cycle clock by default.
508  TODO(soheil): enable when we support fallback for unstable cycle clocks.
509 #if defined(__i386__)
510 #define GPR_CYCLE_COUNTER_RDTSC_32 1
511 #elif defined(__x86_64__) || defined(__amd64__)
512 #define GPR_CYCLE_COUNTER_RDTSC_64 1
513 #else
514 #define GPR_CYCLE_COUNTER_FALLBACK 1
515 #endif
516 */
517 #define GPR_CYCLE_COUNTER_FALLBACK 1
518 #else
519 #define GPR_CYCLE_COUNTER_FALLBACK 1
520 #endif /* GPR_LINUX */
521 
522 /* Cache line alignment */
523 #ifndef GPR_CACHELINE_SIZE_LOG
524 #if defined(__i386__) || defined(__x86_64__)
525 #define GPR_CACHELINE_SIZE_LOG 6
526 #endif
527 #ifndef GPR_CACHELINE_SIZE_LOG
528 /* A reasonable default guess. Note that overestimates tend to waste more
529  space, while underestimates tend to waste more time. */
530 #define GPR_CACHELINE_SIZE_LOG 6
531 #endif /* GPR_CACHELINE_SIZE_LOG */
532 #endif /* GPR_CACHELINE_SIZE_LOG */
533 
534 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
535 
536 /* scrub GCC_ATOMIC if it's not available on this compiler */
537 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
538 #undef GPR_GCC_ATOMIC
539 #define GPR_GCC_SYNC 1
540 #endif
541 
542 /* Validate platform combinations */
543 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
544  defined(GPR_WINDOWS_ATOMIC) != \
545  1
546 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
547 #endif
548 
549 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
550 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
551 #endif
552 
553 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
554  defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
555  1
556 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
557 #endif
558 
559 /* maximum alignment needed for any type on this platform, rounded up to a
560  power of two */
561 #define GPR_MAX_ALIGNMENT 16
562 
563 #ifndef GRPC_ARES
564 #define GRPC_ARES 1
565 #endif
566 
567 #ifndef GRPC_IF_NAMETOINDEX
568 #define GRPC_IF_NAMETOINDEX 1
569 #endif
570 
571 #ifndef GRPC_MUST_USE_RESULT
572 #if defined(__GNUC__) && !defined(__MINGW32__)
573 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
574 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
575 #else
576 #define GRPC_MUST_USE_RESULT
577 #define GPR_ALIGN_STRUCT(n)
578 #endif
579 #ifdef USE_STRICT_WARNING
580 /* When building with USE_STRICT_WARNING (which -Werror), types with this
581  attribute will be treated as annotated with warn_unused_result, enforcing
582  returned values of this type should be used.
583  This is added in grpc::Status in mind to address the issue where it always
584  has this annotation internally but OSS doesn't, sometimes causing internal
585  build failure. To prevent this, this is added while not introducing
586  a breaking change to existing user code which may not use returned values
587  of grpc::Status. */
588 #define GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING GRPC_MUST_USE_RESULT
589 #else
590 #define GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING
591 #endif
592 #endif
593 
594 #ifndef GRPC_UNUSED
595 #if defined(__GNUC__) && !defined(__MINGW32__)
596 #define GRPC_UNUSED __attribute__((unused))
597 #else
598 #define GRPC_UNUSED
599 #endif
600 #endif
601 
602 #ifndef GPR_PRINT_FORMAT_CHECK
603 #ifdef __GNUC__
604 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
605  __attribute__((format(printf, FORMAT_STR, ARGS)))
606 #else
607 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
608 #endif
609 #endif /* GPR_PRINT_FORMAT_CHECK */
610 
611 #ifndef GPR_HAS_CPP_ATTRIBUTE
612 #ifdef __has_cpp_attribute
613 #define GPR_HAS_CPP_ATTRIBUTE(a) __has_cpp_attribute(a)
614 #else
615 #define GPR_HAS_CPP_ATTRIBUTE(a) 0
616 #endif
617 #endif /* GPR_HAS_CPP_ATTRIBUTE */
618 
619 #ifndef GPR_HAS_ATTRIBUTE
620 #ifdef __has_attribute
621 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
622 #else
623 #define GPR_HAS_ATTRIBUTE(a) 0
624 #endif
625 #endif /* GPR_HAS_ATTRIBUTE */
626 
627 #if GPR_HAS_ATTRIBUTE(noreturn)
628 #define GPR_ATTRIBUTE_NORETURN __attribute__((noreturn))
629 #else
630 #define GPR_ATTRIBUTE_NORETURN
631 #endif
632 
633 #if GPR_FORBID_UNREACHABLE_CODE
634 #define GPR_UNREACHABLE_CODE(STATEMENT)
635 #else
636 #ifdef __cplusplus
637 extern "C" {
638 #endif
639 extern void gpr_unreachable_code(const char* reason, const char* file,
641 #ifdef __cplusplus
642 }
643 #endif
644 #define GPR_UNREACHABLE_CODE(STATEMENT) \
645  do { \
646  gpr_unreachable_code(#STATEMENT, __FILE__, __LINE__); \
647  STATEMENT; \
648  } while (0)
649 #endif /* GPR_FORBID_UNREACHABLE_CODE */
650 
651 #ifndef GPRAPI
652 #define GPRAPI
653 #endif
654 
655 #ifndef GRPCAPI
656 #define GRPCAPI GPRAPI
657 #endif
658 
659 #ifndef CENSUSAPI
660 #define CENSUSAPI GRPCAPI
661 #endif
662 
663 #ifndef GPR_HAS_FEATURE
664 #ifdef __has_feature
665 #define GPR_HAS_FEATURE(a) __has_feature(a)
666 #else
667 #define GPR_HAS_FEATURE(a) 0
668 #endif
669 #endif /* GPR_HAS_FEATURE */
670 
671 #ifndef GPR_ATTRIBUTE_NOINLINE
672 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
673 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
674 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
675 #else
676 #define GPR_ATTRIBUTE_NOINLINE
677 #endif
678 #endif /* GPR_ATTRIBUTE_NOINLINE */
679 
680 #ifndef GPR_NO_UNIQUE_ADDRESS
681 #if GPR_HAS_CPP_ATTRIBUTE(no_unique_address)
682 #define GPR_NO_UNIQUE_ADDRESS [[no_unique_address]]
683 #else
684 #define GPR_NO_UNIQUE_ADDRESS
685 #endif
686 #endif /* GPR_NO_UNIQUE_ADDRESS */
687 
688 #ifndef GRPC_DEPRECATED
689 #if GPR_HAS_CPP_ATTRIBUTE(deprecated)
690 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
691 #else
692 #define GRPC_DEPRECATED(reason)
693 #endif
694 #endif /* GRPC_DEPRECATED */
695 
696 #ifndef GPR_ATTRIBUTE_WEAK
697 /* Attribute weak is broken on LLVM/windows:
698  * https://bugs.llvm.org/show_bug.cgi?id=37598 */
699 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
700  !(defined(__llvm__) && defined(_WIN32))
701 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
702 #define GPR_HAS_ATTRIBUTE_WEAK 1
703 #else
704 #define GPR_ATTRIBUTE_WEAK
705 #endif
706 #endif /* GPR_ATTRIBUTE_WEAK */
707 
708 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
709 #if GPR_HAS_FEATURE(thread_sanitizer)
710 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
711 #endif /* GPR_HAS_FEATURE */
712 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
713 #define GPR_ATTRIBUTE_NO_TSAN
714 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
715 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
716 
717 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
718 #ifndef GRPC_TSAN_SUPPRESSED
719 #if defined(__SANITIZE_THREAD__)
720 #define GRPC_TSAN_ENABLED
721 #elif GPR_HAS_FEATURE(thread_sanitizer)
722 #define GRPC_TSAN_ENABLED
723 #endif
724 #endif
725 
726 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
727 #ifndef GRPC_ASAN_SUPPRESSED
728 #if defined(__SANITIZE_ADDRESS__)
729 #define GRPC_ASAN_ENABLED
730 #elif GPR_HAS_FEATURE(address_sanitizer)
731 #define GRPC_ASAN_ENABLED
732 #endif
733 #endif
734 
735 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
736 #ifndef GRPC_ALLOW_EXCEPTIONS
737 #ifdef GPR_WINDOWS
738 #if defined(_MSC_VER) && defined(_CPPUNWIND)
739 #define GRPC_ALLOW_EXCEPTIONS 1
740 #elif defined(__EXCEPTIONS)
741 #define GRPC_ALLOW_EXCEPTIONS 1
742 #else
743 #define GRPC_ALLOW_EXCEPTIONS 0
744 #endif
745 #else /* GPR_WINDOWS */
746 #ifdef __EXCEPTIONS
747 #define GRPC_ALLOW_EXCEPTIONS 1
748 #else /* __EXCEPTIONS */
749 #define GRPC_ALLOW_EXCEPTIONS 0
750 #endif /* __EXCEPTIONS */
751 #endif /* __GPR_WINDOWS */
752 #endif /* GRPC_ALLOW_EXCEPTIONS */
753 
754 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
755  * most likely. Ideally, also collect performance numbers to justify the claim.
756  */
757 #ifdef __GNUC__
758 #define GPR_LIKELY(x) __builtin_expect((x), 1)
759 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
760 #else /* __GNUC__ */
761 #define GPR_LIKELY(x) (x)
762 #define GPR_UNLIKELY(x) (x)
763 #endif /* __GNUC__ */
764 
765 #ifndef __STDC_FORMAT_MACROS
766 #define __STDC_FORMAT_MACROS
767 #endif
768 
769 #define GRPC_CALLBACK_API_NONEXPERIMENTAL
770 
771 /* clang 11 with msan miscompiles destruction of [[no_unique_address]] members
772  * of zero size - for a repro see:
773  * test/core/compiler_bugs/miscompile_with_no_unique_address_test.cc
774  */
775 #ifdef __clang__
776 #if __clang__ && __clang_major__ <= 11 && __has_feature(memory_sanitizer)
777 #undef GPR_NO_UNIQUE_ADDRESS
778 #define GPR_NO_UNIQUE_ADDRESS
779 #endif
780 #endif
781 
782 #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */
gpr_log_func_args::file
const char * file
Definition: log.h:78
gpr_unreachable_code
void gpr_unreachable_code(const char *reason, const char *file, int line)
GPR_ATTRIBUTE_NORETURN
#define GPR_ATTRIBUTE_NORETURN
Definition: port_platform.h:630
gpr_log_func_args::line
int line
Definition: log.h:79