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