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


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:54