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