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