• 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_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 #define GPR_SUPPORT_BINDER_TRANSPORT 1
170 // TODO(apolcyn): re-evaluate support for c-ares
171 // on android after upgrading our c-ares dependency.
172 // See https://github.com/grpc/grpc/issues/18038.
173 #define GRPC_ARES 0
174 #ifdef _LP64
175 #define GPR_ARCH_64 1
176 #else /* _LP64 */
177 #define GPR_ARCH_32 1
178 #endif /* _LP64 */
179 #define GPR_CPU_POSIX 1
180 #define GPR_GCC_SYNC 1
181 #define GPR_POSIX_ENV 1
182 #define GPR_POSIX_TMPFILE 1
183 #define GPR_POSIX_STAT 1
184 #define GPR_ANDROID_LOG 1
185 #define GPR_POSIX_STRING 1
186 #define GPR_POSIX_SUBPROCESS 1
187 #define GPR_POSIX_SYNC 1
188 #define GPR_POSIX_TIME 1
189 #define GPR_HAS_PTHREAD_H 1
190 #define GPR_GETPID_IN_UNISTD_H 1
191 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
192 #elif defined(__linux__)
193 #define GPR_PLATFORM_STRING "linux"
194 #ifndef _BSD_SOURCE
195 #define _BSD_SOURCE
196 #endif
197 #ifndef _DEFAULT_SOURCE
198 #define _DEFAULT_SOURCE
199 #endif
200 #ifndef _GNU_SOURCE
201 #define _GNU_SOURCE
202 #endif
203 #include <features.h>
204 #define GPR_CPU_LINUX 1
205 #define GPR_GCC_ATOMIC 1
206 #define GPR_LINUX 1
207 #define GPR_LINUX_LOG
208 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
209 #define GPR_LINUX_ENV 1
210 #define GPR_POSIX_TMPFILE 1
211 #define GPR_POSIX_STAT 1
212 #define GPR_POSIX_STRING 1
213 #define GPR_POSIX_SUBPROCESS 1
214 #define GPR_POSIX_SYNC 1
215 #define GPR_POSIX_TIME 1
216 #define GPR_HAS_PTHREAD_H 1
217 #define GPR_GETPID_IN_UNISTD_H 1
218 #ifdef _LP64
219 #define GPR_ARCH_64 1
220 #else /* _LP64 */
221 #define GPR_ARCH_32 1
222 #endif /* _LP64 */
223 #ifdef __GLIBC__
224 #define GPR_POSIX_CRASH_HANDLER 1
225 #ifdef __GLIBC_PREREQ
226 #if __GLIBC_PREREQ(2, 12)
227 #define GPR_LINUX_PTHREAD_NAME 1
228 #endif
229 #else
230 // musl libc & others
231 #define GPR_LINUX_PTHREAD_NAME 1
232 #endif
233 #include <linux/version.h>
234 #else /* musl libc */
235 #define GPR_MUSL_LIBC_COMPAT 1
236 #endif
237 #elif defined(__ASYLO__)
238 #define GPR_ARCH_64 1
239 #define GPR_CPU_POSIX 1
240 #define GPR_PLATFORM_STRING "asylo"
241 #define GPR_GCC_SYNC 1
242 #define GPR_POSIX_STAT 1
243 #define GPR_POSIX_SYNC 1
244 #define GPR_POSIX_STRING 1
245 #define GPR_POSIX_LOG 1
246 #define GPR_POSIX_TIME 1
247 #define GPR_POSIX_ENV 1
248 #define GPR_ASYLO 1
249 #define GRPC_POSIX_SOCKET 1
250 #define GRPC_POSIX_SOCKETADDR
251 #define GRPC_POSIX_SOCKETUTILS 1
252 #define GRPC_TIMER_USE_GENERIC 1
253 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
254 #define GRPC_POSIX_WAKEUP_FD 1
255 #define GRPC_HAVE_MSG_NOSIGNAL 1
256 #define GRPC_HAVE_UNIX_SOCKET 1
257 #define GRPC_ARES 0
258 #define GPR_NO_AUTODETECT_PLATFORM 1
259 #elif defined(__APPLE__)
260 #include <Availability.h>
261 #include <TargetConditionals.h>
262 #ifndef _BSD_SOURCE
263 #define _BSD_SOURCE
264 #endif
265 #if TARGET_OS_IPHONE
266 #define GPR_PLATFORM_STRING "ios"
267 #define GPR_CPU_IPHONE 1
268 #define GRPC_CFSTREAM 1
269 /* the c-ares resolver isn't safe to enable on iOS */
270 #define GRPC_ARES 0
271 #else /* TARGET_OS_IPHONE */
272 #define GPR_PLATFORM_STRING "osx"
273 #define GPR_CPU_POSIX 1
274 #define GPR_POSIX_CRASH_HANDLER 1
275 #endif
276 #define GPR_APPLE 1
277 #define GPR_GCC_ATOMIC 1
278 #define GPR_POSIX_LOG 1
279 #define GPR_POSIX_ENV 1
280 #define GPR_POSIX_TMPFILE 1
281 #define GPR_POSIX_STAT 1
282 #define GPR_POSIX_STRING 1
283 #define GPR_POSIX_SUBPROCESS 1
284 #define GPR_POSIX_SYNC 1
285 #define GPR_POSIX_TIME 1
286 #define GPR_HAS_PTHREAD_H 1
287 #define GPR_GETPID_IN_UNISTD_H 1
288 #ifndef GRPC_CFSTREAM
289 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
290 #endif
291 #ifdef _LP64
292 #define GPR_ARCH_64 1
293 #else /* _LP64 */
294 #define GPR_ARCH_32 1
295 #endif /* _LP64 */
296 #elif defined(__FreeBSD__)
297 #define GPR_PLATFORM_STRING "freebsd"
298 #ifndef _BSD_SOURCE
299 #define _BSD_SOURCE
300 #endif
301 #define GPR_FREEBSD 1
302 #define GPR_CPU_POSIX 1
303 #define GPR_GCC_ATOMIC 1
304 #define GPR_POSIX_LOG 1
305 #define GPR_POSIX_ENV 1
306 #define GPR_POSIX_TMPFILE 1
307 #define GPR_POSIX_STAT 1
308 #define GPR_POSIX_STRING 1
309 #define GPR_POSIX_SUBPROCESS 1
310 #define GPR_POSIX_SYNC 1
311 #define GPR_POSIX_TIME 1
312 #define GPR_HAS_PTHREAD_H 1
313 #define GPR_GETPID_IN_UNISTD_H 1
314 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
315 #ifdef _LP64
316 #define GPR_ARCH_64 1
317 #else /* _LP64 */
318 #define GPR_ARCH_32 1
319 #endif /* _LP64 */
320 #elif defined(__OpenBSD__)
321 #define GPR_PLATFORM_STRING "openbsd"
322 #ifndef _BSD_SOURCE
323 #define _BSD_SOURCE
324 #endif
325 #define GPR_OPENBSD 1
326 #define GPR_CPU_POSIX 1
327 #define GPR_GCC_ATOMIC 1
328 #define GPR_POSIX_LOG 1
329 #define GPR_POSIX_ENV 1
330 #define GPR_POSIX_TMPFILE 1
331 #define GPR_POSIX_STAT 1
332 #define GPR_POSIX_STRING 1
333 #define GPR_POSIX_SUBPROCESS 1
334 #define GPR_POSIX_SYNC 1
335 #define GPR_POSIX_TIME 1
336 #define GPR_HAS_PTHREAD_H 1
337 #define GPR_GETPID_IN_UNISTD_H 1
338 #define GPR_SUPPORT_CHANNELS_FROM_FD 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(__sun) && defined(__SVR4)
345 #define GPR_PLATFORM_STRING "solaris"
346 #define GPR_SOLARIS 1
347 #define GPR_CPU_POSIX 1
348 #define GPR_GCC_ATOMIC 1
349 #define GPR_POSIX_LOG 1
350 #define GPR_POSIX_ENV 1
351 #define GPR_POSIX_TMPFILE 1
352 #define GPR_POSIX_STAT 1
353 #define GPR_POSIX_STRING 1
354 #define GPR_POSIX_SUBPROCESS 1
355 #define GPR_POSIX_SYNC 1
356 #define GPR_POSIX_TIME 1
357 #define GPR_HAS_PTHREAD_H 1
358 #define GPR_GETPID_IN_UNISTD_H 1
359 #ifdef _LP64
360 #define GPR_ARCH_64 1
361 #else /* _LP64 */
362 #define GPR_ARCH_32 1
363 #endif /* _LP64 */
364 #elif defined(_AIX)
365 #define GPR_PLATFORM_STRING "aix"
366 #ifndef _ALL_SOURCE
367 #define _ALL_SOURCE
368 #endif
369 #define GPR_AIX 1
370 #define GPR_CPU_POSIX 1
371 #define GPR_GCC_ATOMIC 1
372 #define GPR_POSIX_LOG 1
373 #define GPR_POSIX_ENV 1
374 #define GPR_POSIX_TMPFILE 1
375 #define GPR_POSIX_STAT 1
376 #define GPR_POSIX_STRING 1
377 #define GPR_POSIX_SUBPROCESS 1
378 #define GPR_POSIX_SYNC 1
379 #define GPR_POSIX_TIME 1
380 #define GPR_HAS_PTHREAD_H 1
381 #define GPR_GETPID_IN_UNISTD_H 1
382 #ifdef _LP64
383 #define GPR_ARCH_64 1
384 #else /* _LP64 */
385 #define GPR_ARCH_32 1
386 #endif /* _LP64 */
387 #elif defined(__NetBSD__)
388 // NetBSD is a community-supported platform.
389 // Please contact Thomas Klausner <wiz@NetBSD.org> for support.
390 #define GPR_PLATFORM_STRING "netbsd"
391 #ifndef _BSD_SOURCE
392 #define _BSD_SOURCE
393 #endif
394 #define GPR_NETBSD 1
395 #define GPR_CPU_POSIX 1
396 #define GPR_GCC_ATOMIC 1
397 #define GPR_GCC_TLS 1
398 #define GPR_POSIX_LOG 1
399 #define GPR_POSIX_ENV 1
400 #define GPR_POSIX_TMPFILE 1
401 #define GPR_POSIX_STAT 1
402 #define GPR_POSIX_STRING 1
403 #define GPR_POSIX_SUBPROCESS 1
404 #define GPR_POSIX_SYNC 1
405 #define GPR_POSIX_TIME 1
406 #define GPR_GETPID_IN_UNISTD_H 1
407 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
408 #ifdef _LP64
409 #define GPR_ARCH_64 1
410 #else /* _LP64 */
411 #define GPR_ARCH_32 1
412 #endif /* _LP64 */
413 #elif defined(__native_client__)
414 #define GPR_PLATFORM_STRING "nacl"
415 #ifndef _BSD_SOURCE
416 #define _BSD_SOURCE
417 #endif
418 #ifndef _DEFAULT_SOURCE
419 #define _DEFAULT_SOURCE
420 #endif
421 #ifndef _GNU_SOURCE
422 #define _GNU_SOURCE
423 #endif
424 #define GPR_NACL 1
425 #define GPR_CPU_POSIX 1
426 #define GPR_GCC_ATOMIC 1
427 #define GPR_POSIX_LOG 1
428 #define GPR_POSIX_ENV 1
429 #define GPR_POSIX_TMPFILE 1
430 #define GPR_POSIX_STAT 1
431 #define GPR_POSIX_STRING 1
432 #define GPR_POSIX_SUBPROCESS 1
433 #define GPR_POSIX_SYNC 1
434 #define GPR_POSIX_TIME 1
435 #define GPR_HAS_PTHREAD_H 1
436 #define GPR_GETPID_IN_UNISTD_H 1
437 #ifdef _LP64
438 #define GPR_ARCH_64 1
439 #else /* _LP64 */
440 #define GPR_ARCH_32 1
441 #endif /* _LP64 */
442 #elif defined(__Fuchsia__)
443 #define GRPC_ARES 0
444 #define GPR_FUCHSIA 1
445 #define GPR_ARCH_64 1
446 #define GPR_PLATFORM_STRING "fuchsia"
447 #include <features.h>
448 // Specifying musl libc affects wrap_memcpy.c. It causes memmove() to be
449 // invoked.
450 #define GPR_MUSL_LIBC_COMPAT 1
451 #define GPR_CPU_POSIX 1
452 #define GPR_GCC_ATOMIC 1
453 #define GPR_POSIX_LOG 1
454 #define GPR_POSIX_SYNC 1
455 #define GPR_POSIX_ENV 1
456 #define GPR_POSIX_TMPFILE 1
457 #define GPR_POSIX_STAT 1
458 #define GPR_POSIX_SUBPROCESS 1
459 #define GPR_POSIX_SYNC 1
460 #define GPR_POSIX_STRING 1
461 #define GPR_POSIX_TIME 1
462 #define GPR_HAS_PTHREAD_H 1
463 #define GPR_GETPID_IN_UNISTD_H 1
464 #define GRPC_ROOT_PEM_PATH "/config/ssl/cert.pem"
465 #elif defined(__HAIKU__)
466 #define GPR_PLATFORM_STRING "haiku"
467 // Haiku is a community-supported platform.
468 // Please contact Jerome Duval <jerome.duval@gmail.com> for support.
469 #ifndef _BSD_SOURCE
470 #define _BSD_SOURCE
471 #endif
472 #define GPR_HAIKU 1
473 #define GPR_CPU_POSIX 1
474 #define GPR_GCC_ATOMIC 1
475 #define GPR_POSIX_LOG 1
476 #define GPR_POSIX_ENV 1
477 #define GPR_POSIX_TMPFILE 1
478 #define GPR_POSIX_STAT 1
479 #define GPR_POSIX_STRING 1
480 #define GPR_POSIX_SUBPROCESS 1
481 #define GPR_POSIX_SYNC 1
482 #define GPR_POSIX_TIME 1
483 #define GPR_HAS_PTHREAD_H 1
484 #define GPR_GETPID_IN_UNISTD_H 1
485 #define GPR_SUPPORT_CHANNELS_FROM_FD 1
486 #ifdef _LP64
487 #define GPR_ARCH_64 1
488 #else /* _LP64 */
489 #define GPR_ARCH_32 1
490 #endif /* _LP64 */
491 #elif defined(__QNX__) || defined(__QNXNTO__)
492 #define GPR_PLATFORM_STRING "qnx"
493 #define GPR_CPU_POSIX 1
494 #define GPR_GCC_ATOMIC 1
495 #define GPR_POSIX_LOG 1
496 #define GPR_POSIX_ENV 1
497 #define GPR_POSIX_TMPFILE 1
498 #define GPR_POSIX_STAT 1
499 #define GPR_POSIX_STRING 1
500 #define GPR_POSIX_SYNC 1
501 #define GPR_POSIX_TIME 1
502 #define GPR_HAS_PTHREAD_H 1
503 #define GPR_GETPID_IN_UNISTD_H 1
504 #ifdef _LP64
505 #define GPR_ARCH_64 1
506 #else /* _LP64 */
507 #define GPR_ARCH_32 1
508 #endif /* _LP64 */
509 #else
510 #error "Could not auto-detect platform"
511 #endif
512 #endif /* GPR_NO_AUTODETECT_PLATFORM */
513 
514 #if defined(__has_include)
515 #if __has_include(<atomic>)
516 #define GRPC_HAS_CXX11_ATOMIC
517 #endif /* __has_include(<atomic>) */
518 #endif /* defined(__has_include) */
519 
520 #ifndef GPR_PLATFORM_STRING
521 #warning "GPR_PLATFORM_STRING not auto-detected"
522 #define GPR_PLATFORM_STRING "unknown"
523 #endif
524 
525 #ifdef GPR_GCOV
526 #undef GPR_FORBID_UNREACHABLE_CODE
527 #define GPR_FORBID_UNREACHABLE_CODE 1
528 #endif
529 
530 #ifdef _MSC_VER
531 #if _MSC_VER < 1700
532 typedef __int8 int8_t;
533 typedef __int16 int16_t;
534 typedef __int32 int32_t;
535 typedef __int64 int64_t;
536 typedef unsigned __int8 uint8_t;
537 typedef unsigned __int16 uint16_t;
538 typedef unsigned __int32 uint32_t;
539 typedef unsigned __int64 uint64_t;
540 #else
541 #include <stdint.h>
542 #endif /* _MSC_VER < 1700 */
543 #else
544 #include <stdint.h>
545 #endif /* _MSC_VER */
546 
547 /* Type of cycle clock implementation */
548 #ifdef GPR_LINUX
549 /* Disable cycle clock by default.
550    TODO(soheil): enable when we support fallback for unstable cycle clocks.
551 #if defined(__i386__)
552 #define GPR_CYCLE_COUNTER_RDTSC_32 1
553 #elif defined(__x86_64__) || defined(__amd64__)
554 #define GPR_CYCLE_COUNTER_RDTSC_64 1
555 #else
556 #define GPR_CYCLE_COUNTER_FALLBACK 1
557 #endif
558 */
559 #define GPR_CYCLE_COUNTER_FALLBACK 1
560 #else
561 #define GPR_CYCLE_COUNTER_FALLBACK 1
562 #endif /* GPR_LINUX */
563 
564 /* Cache line alignment */
565 #ifndef GPR_CACHELINE_SIZE_LOG
566 #if defined(__i386__) || defined(__x86_64__)
567 #define GPR_CACHELINE_SIZE_LOG 6
568 #endif
569 #ifndef GPR_CACHELINE_SIZE_LOG
570 /* A reasonable default guess. Note that overestimates tend to waste more
571    space, while underestimates tend to waste more time. */
572 #define GPR_CACHELINE_SIZE_LOG 6
573 #endif /* GPR_CACHELINE_SIZE_LOG */
574 #endif /* GPR_CACHELINE_SIZE_LOG */
575 
576 #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG)
577 
578 /* scrub GCC_ATOMIC if it's not available on this compiler */
579 #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED)
580 #undef GPR_GCC_ATOMIC
581 #define GPR_GCC_SYNC 1
582 #endif
583 
584 /* Validate platform combinations */
585 #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \
586         defined(GPR_WINDOWS_ATOMIC) !=                \
587     1
588 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
589 #endif
590 
591 #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
592 #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
593 #endif
594 
595 #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WINDOWS) + \
596         defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) !=                 \
597     1
598 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
599 #endif
600 
601 /* maximum alignment needed for any type on this platform, rounded up to a
602    power of two */
603 #define GPR_MAX_ALIGNMENT 16
604 
605 #ifndef GRPC_ARES
606 #define GRPC_ARES 1
607 #endif
608 
609 #ifndef GRPC_IF_NAMETOINDEX
610 #define GRPC_IF_NAMETOINDEX 1
611 #endif
612 
613 #ifndef GRPC_UNUSED
614 #if defined(__GNUC__) && !defined(__MINGW32__)
615 #define GRPC_UNUSED __attribute__((unused))
616 #else
617 #define GRPC_UNUSED
618 #endif
619 #endif
620 
621 #ifndef GPR_PRINT_FORMAT_CHECK
622 #ifdef __GNUC__
623 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS) \
624   __attribute__((format(printf, FORMAT_STR, ARGS)))
625 #else
626 #define GPR_PRINT_FORMAT_CHECK(FORMAT_STR, ARGS)
627 #endif
628 #endif /* GPR_PRINT_FORMAT_CHECK */
629 
630 #ifndef GPR_HAS_CPP_ATTRIBUTE
631 #ifdef __has_cpp_attribute
632 #define GPR_HAS_CPP_ATTRIBUTE(a) __has_cpp_attribute(a)
633 #else
634 #define GPR_HAS_CPP_ATTRIBUTE(a) 0
635 #endif
636 #endif /* GPR_HAS_CPP_ATTRIBUTE */
637 
638 #if defined(__GNUC__) && !defined(__MINGW32__)
639 #define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n)))
640 #else
641 #define GPR_ALIGN_STRUCT(n)
642 #endif
643 
644 #ifndef GRPC_MUST_USE_RESULT
645 #if GPR_HAS_CPP_ATTRIBUTE(nodiscard)
646 #define GRPC_MUST_USE_RESULT [[nodiscard]]
647 #elif defined(__GNUC__) && !defined(__MINGW32__)
648 #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))
649 #else
650 #define GRPC_MUST_USE_RESULT
651 #endif
652 #ifdef USE_STRICT_WARNING
653 /* When building with USE_STRICT_WARNING (which -Werror), types with this
654    attribute will be treated as annotated with warn_unused_result, enforcing
655    returned values of this type should be used.
656    This is added in grpc::Status in mind to address the issue where it always
657    has this annotation internally but OSS doesn't, sometimes causing internal
658    build failure. To prevent this, this is added while not introducing
659    a breaking change to existing user code which may not use returned values
660    of grpc::Status. */
661 #define GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING GRPC_MUST_USE_RESULT
662 #else
663 #define GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING
664 #endif
665 #endif
666 
667 #ifndef GRPC_REINITIALIZES
668 #if defined(__clang__)
669 #if GPR_HAS_CPP_ATTRIBUTE(clang::reinitializes)
670 #define GRPC_REINITIALIZES [[clang::reinitializes]]
671 #else
672 #define GRPC_REINITIALIZES
673 #endif
674 #else
675 #define GRPC_REINITIALIZES
676 #endif
677 #endif
678 
679 #ifndef GPR_HAS_ATTRIBUTE
680 #ifdef __has_attribute
681 #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a)
682 #else
683 #define GPR_HAS_ATTRIBUTE(a) 0
684 #endif
685 #endif /* GPR_HAS_ATTRIBUTE */
686 
687 #if GPR_HAS_ATTRIBUTE(noreturn)
688 #define GPR_ATTRIBUTE_NORETURN __attribute__((noreturn))
689 #else
690 #define GPR_ATTRIBUTE_NORETURN
691 #endif
692 
693 #if defined(GPR_FORBID_UNREACHABLE_CODE) && GPR_FORBID_UNREACHABLE_CODE
694 #define GPR_UNREACHABLE_CODE(STATEMENT)
695 #else
696 #ifdef __cplusplus
697 extern "C" {
698 #endif
699 extern void gpr_unreachable_code(const char* reason, const char* file,
700                                  int line) GPR_ATTRIBUTE_NORETURN;
701 #ifdef __cplusplus
702 }
703 #endif
704 #define GPR_UNREACHABLE_CODE(STATEMENT)                   \
705   do {                                                    \
706     gpr_unreachable_code(#STATEMENT, __FILE__, __LINE__); \
707     STATEMENT;                                            \
708   } while (0)
709 #endif /* GPR_FORBID_UNREACHABLE_CODE */
710 
711 #ifndef GPRAPI
712 #define GPRAPI
713 #endif
714 
715 #ifndef GRPCAPI
716 #define GRPCAPI GPRAPI
717 #endif
718 
719 #ifndef CENSUSAPI
720 #define CENSUSAPI GRPCAPI
721 #endif
722 
723 #ifndef GPR_HAS_FEATURE
724 #ifdef __has_feature
725 #define GPR_HAS_FEATURE(a) __has_feature(a)
726 #else
727 #define GPR_HAS_FEATURE(a) 0
728 #endif
729 #endif /* GPR_HAS_FEATURE */
730 
731 #ifndef GPR_ATTRIBUTE_NOINLINE
732 #if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__))
733 #define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline))
734 #define GPR_HAS_ATTRIBUTE_NOINLINE 1
735 #else
736 #define GPR_ATTRIBUTE_NOINLINE
737 #endif
738 #endif /* GPR_ATTRIBUTE_NOINLINE */
739 
740 #ifndef GPR_NO_UNIQUE_ADDRESS
741 #if GPR_HAS_CPP_ATTRIBUTE(no_unique_address)
742 #define GPR_NO_UNIQUE_ADDRESS [[no_unique_address]]
743 #else
744 #define GPR_NO_UNIQUE_ADDRESS
745 #endif
746 #endif /* GPR_NO_UNIQUE_ADDRESS */
747 
748 #ifndef GRPC_DEPRECATED
749 #if GPR_HAS_CPP_ATTRIBUTE(deprecated)
750 #define GRPC_DEPRECATED(reason) [[deprecated(reason)]]
751 #else
752 #define GRPC_DEPRECATED(reason)
753 #endif
754 #endif /* GRPC_DEPRECATED */
755 
756 #ifndef GPR_ATTRIBUTE_WEAK
757 /* Attribute weak is broken on LLVM/windows:
758  * https://bugs.llvm.org/show_bug.cgi?id=37598 */
759 #if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \
760     !(defined(__llvm__) && defined(_WIN32))
761 #define GPR_ATTRIBUTE_WEAK __attribute__((weak))
762 #define GPR_HAS_ATTRIBUTE_WEAK 1
763 #else
764 #define GPR_ATTRIBUTE_WEAK
765 #endif
766 #endif /* GPR_ATTRIBUTE_WEAK */
767 
768 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */
769 #if GPR_HAS_FEATURE(thread_sanitizer)
770 #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread")))
771 #endif                        /* GPR_HAS_FEATURE */
772 #ifndef GPR_ATTRIBUTE_NO_TSAN /* (2) */
773 #define GPR_ATTRIBUTE_NO_TSAN
774 #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */
775 #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */
776 
777 /* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */
778 #ifndef GRPC_TSAN_SUPPRESSED
779 #if defined(__SANITIZE_THREAD__)
780 #define GRPC_TSAN_ENABLED
781 #elif GPR_HAS_FEATURE(thread_sanitizer)
782 #define GRPC_TSAN_ENABLED
783 #endif
784 #endif
785 
786 /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */
787 #ifndef GRPC_ASAN_SUPPRESSED
788 #if defined(__SANITIZE_ADDRESS__)
789 #define GRPC_ASAN_ENABLED
790 #elif GPR_HAS_FEATURE(address_sanitizer)
791 #define GRPC_ASAN_ENABLED
792 #endif
793 #endif
794 
795 /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */
796 #ifndef GRPC_ALLOW_EXCEPTIONS
797 #ifdef GPR_WINDOWS
798 #if defined(_MSC_VER) && defined(_CPPUNWIND)
799 #define GRPC_ALLOW_EXCEPTIONS 1
800 #elif defined(__EXCEPTIONS)
801 #define GRPC_ALLOW_EXCEPTIONS 1
802 #else
803 #define GRPC_ALLOW_EXCEPTIONS 0
804 #endif
805 #else /* GPR_WINDOWS */
806 #ifdef __EXCEPTIONS
807 #define GRPC_ALLOW_EXCEPTIONS 1
808 #else /* __EXCEPTIONS */
809 #define GRPC_ALLOW_EXCEPTIONS 0
810 #endif /* __EXCEPTIONS */
811 #endif /* __GPR_WINDOWS */
812 #endif /* GRPC_ALLOW_EXCEPTIONS */
813 
814 /* Use GPR_LIKELY only in cases where you are sure that a certain outcome is the
815  * most likely. Ideally, also collect performance numbers to justify the claim.
816  */
817 #ifdef __GNUC__
818 #define GPR_LIKELY(x) __builtin_expect((x), 1)
819 #define GPR_UNLIKELY(x) __builtin_expect((x), 0)
820 #else /* __GNUC__ */
821 #define GPR_LIKELY(x) (x)
822 #define GPR_UNLIKELY(x) (x)
823 #endif /* __GNUC__ */
824 
825 #ifndef __STDC_FORMAT_MACROS
826 #define __STDC_FORMAT_MACROS
827 #endif
828 
829 /* MSVC doesn't do the empty base class optimization in debug builds by default,
830  * and because of ABI likely won't.
831  * This enables it for specific types, use as:
832  * class GPR_MSVC_EMPTY_BASE_CLASS_WORKAROUND Foo : public A, public B, public C
833  * {}; */
834 #ifndef GPR_MSVC_EMPTY_BASE_CLASS_WORKAROUND
835 #ifdef GPR_WINDOWS
836 #define GPR_MSVC_EMPTY_BASE_CLASS_WORKAROUND __declspec(empty_bases)
837 #else
838 #define GPR_MSVC_EMPTY_BASE_CLASS_WORKAROUND
839 #endif
840 #endif
841 
842 #define GRPC_CALLBACK_API_NONEXPERIMENTAL
843 
844 /* clang 12 and lower with msan miscompiles destruction of [[no_unique_address]]
845  * members of zero size - for a repro see:
846  * test/core/compiler_bugs/miscompile_with_no_unique_address_test.cc
847  */
848 #ifdef __clang__
849 #if __clang__ && __clang_major__ <= 12 && __has_feature(memory_sanitizer)
850 #undef GPR_NO_UNIQUE_ADDRESS
851 #define GPR_NO_UNIQUE_ADDRESS
852 #endif
853 #endif
854 
855 #endif /* GRPC_SUPPORT_PORT_PLATFORM_H */
856