David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #ifndef GRPC_IMPL_CODEGEN_PORT_PLATFORM_H |
| 35 | #define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H |
| 36 | |
Craig Tiller | 71ea4a1 | 2016-02-04 15:06:41 -0800 | [diff] [blame] | 37 | /* |
| 38 | * Define GPR_BACKWARDS_COMPATIBILITY_MODE to try harder to be ABI |
| 39 | * compatible with older platforms (currently only on Linux) |
| 40 | * Causes: |
| 41 | * - some libc calls to be gotten via dlsym |
| 42 | * - some syscalls to be made directly |
| 43 | */ |
| 44 | |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 45 | /* Get windows.h included everywhere (we need it) */ |
| 46 | #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) |
| 47 | #ifndef WIN32_LEAN_AND_MEAN |
| 48 | #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
| 49 | #define WIN32_LEAN_AND_MEAN |
| 50 | #endif /* WIN32_LEAN_AND_MEAN */ |
| 51 | |
| 52 | #ifndef NOMINMAX |
| 53 | #define GRPC_NOMINMX_WAS_NOT_DEFINED |
| 54 | #define NOMINMAX |
| 55 | #endif /* NOMINMAX */ |
| 56 | |
| 57 | #ifndef _WIN32_WINNT |
| 58 | #error \ |
| 59 | "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" |
| 60 | #else /* !defined(_WIN32_WINNT) */ |
| 61 | #if (_WIN32_WINNT < 0x0600) |
| 62 | #error \ |
| 63 | "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" |
| 64 | #endif /* _WIN32_WINNT < 0x0600 */ |
| 65 | #endif /* defined(_WIN32_WINNT) */ |
| 66 | |
| 67 | #include <windows.h> |
| 68 | |
| 69 | #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
| 70 | #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
| 71 | #undef WIN32_LEAN_AND_MEAN |
| 72 | #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ |
| 73 | |
| 74 | #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED |
| 75 | #undef GRPC_NOMINMAX_WAS_NOT_DEFINED |
| 76 | #undef NOMINMAX |
| 77 | #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ |
| 78 | #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \ |
| 79 | defined(WIN32) */ |
| 80 | |
| 81 | /* Override this file with one for your platform if you need to redefine |
| 82 | things. */ |
| 83 | |
| 84 | #if !defined(GPR_NO_AUTODETECT_PLATFORM) |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 85 | #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 86 | #if defined(_WIN64) || defined(WIN64) |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 87 | #define GPR_ARCH_64 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 88 | #else |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 89 | #define GPR_ARCH_32 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 90 | #endif |
| 91 | #define GPR_PLATFORM_STRING "windows" |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 92 | #define GPR_WIN32 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 93 | #define GPR_WINSOCK_SOCKET 1 |
Nicolas "Pixel" Noble | 13a8f5b | 2016-01-31 10:06:02 +0100 | [diff] [blame] | 94 | #define GPR_WINDOWS_SUBPROCESS 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 95 | #define GPR_WIN32_ENV |
| 96 | #ifdef __MSYS__ |
| 97 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 98 | #define GPR_MSYS_TMPFILE |
| 99 | #define GPR_POSIX_LOG |
| 100 | #define GPR_POSIX_STRING |
| 101 | #define GPR_POSIX_TIME |
| 102 | #else |
| 103 | #define GPR_GETPID_IN_PROCESS_H 1 |
| 104 | #define GPR_WIN32_TMPFILE |
| 105 | #define GPR_WIN32_LOG |
| 106 | #define GPR_WINDOWS_CRASH_HANDLER 1 |
| 107 | #define GPR_WIN32_STRING |
| 108 | #define GPR_WIN32_TIME |
| 109 | #endif |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 110 | #ifdef __GNUC__ |
| 111 | #define GPR_GCC_ATOMIC 1 |
| 112 | #define GPR_GCC_TLS 1 |
| 113 | #else |
| 114 | #define GPR_WIN32_ATOMIC 1 |
| 115 | #define GPR_MSVC_TLS 1 |
| 116 | #endif |
Masood Malekghassemi | f4c70ca | 2016-05-05 19:14:05 -0700 | [diff] [blame^] | 117 | #elif defined(GPR_MANYLINUX1) |
| 118 | // TODO(atash): manylinux1 is just another __linux__ but with ancient |
| 119 | // libraries; it should be integrated with the `__linux__` definitions below. |
| 120 | #define GPR_PLATFORM_STRING "manylinux" |
| 121 | #define GPR_POSIX_CRASH_HANDLER 1 |
| 122 | #define GPR_CPU_LINUX 1 |
| 123 | #define GPR_GCC_ATOMIC 1 |
| 124 | #define GPR_GCC_TLS 1 |
| 125 | #define GPR_LINUX 1 |
| 126 | #define GPR_LINUX_LOG 1 |
| 127 | #define GPR_POSIX_SOCKET 1 |
| 128 | #define GPR_POSIX_WAKEUP_FD 1 |
| 129 | #define GPR_POSIX_SOCKETADDR 1 |
| 130 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 131 | #define GPR_POSIX_SOCKETUTILS 1 |
| 132 | #define GPR_HAVE_UNIX_SOCKET 1 |
| 133 | #define GPR_HAVE_IP_PKTINFO 1 |
| 134 | #define GPR_HAVE_IPV6_RECVPKTINFO 1 |
| 135 | #define GPR_LINUX_ENV 1 |
| 136 | #define GPR_POSIX_FILE 1 |
| 137 | #define GPR_POSIX_TMPFILE 1 |
| 138 | #define GPR_POSIX_STRING 1 |
| 139 | #define GPR_POSIX_SUBPROCESS 1 |
| 140 | #define GPR_POSIX_SYNC 1 |
| 141 | #define GPR_POSIX_TIME 1 |
| 142 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 143 | #define GPR_HAVE_MSG_NOSIGNAL 1 |
| 144 | #ifdef _LP64 |
| 145 | #define GPR_ARCH_64 1 |
| 146 | #else /* _LP64 */ |
| 147 | #define GPR_ARCH_32 1 |
| 148 | #endif /* _LP64 */ |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 149 | #elif defined(ANDROID) || defined(__ANDROID__) |
| 150 | #define GPR_PLATFORM_STRING "android" |
| 151 | #define GPR_ANDROID 1 |
| 152 | #define GPR_ARCH_32 1 |
| 153 | #define GPR_CPU_LINUX 1 |
| 154 | #define GPR_GCC_SYNC 1 |
| 155 | #define GPR_GCC_TLS 1 |
| 156 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 157 | #define GPR_POSIX_WAKEUP_FD 1 |
| 158 | #define GPR_LINUX_EVENTFD 1 |
| 159 | #define GPR_POSIX_SOCKET 1 |
| 160 | #define GPR_POSIX_SOCKETADDR 1 |
| 161 | #define GPR_POSIX_SOCKETUTILS 1 |
| 162 | #define GPR_POSIX_ENV 1 |
Nicolas "Pixel" Noble | a0091cb | 2016-04-15 07:47:50 +0200 | [diff] [blame] | 163 | #define GPR_POSIX_FILE 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 164 | #define GPR_POSIX_TMPFILE 1 |
| 165 | #define GPR_POSIX_LOG |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 166 | #define GPR_POSIX_STRING 1 |
| 167 | #define GPR_POSIX_SUBPROCESS 1 |
| 168 | #define GPR_POSIX_SYNC 1 |
| 169 | #define GPR_POSIX_TIME 1 |
| 170 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 171 | #define GPR_HAVE_MSG_NOSIGNAL 1 |
ahedberg | 803931d | 2016-03-11 17:24:12 -0500 | [diff] [blame] | 172 | #define GPR_HAVE_UNIX_SOCKET 1 |
ahedberg | 8d7cff4 | 2016-03-24 11:16:44 -0400 | [diff] [blame] | 173 | #define GPR_HAVE_IP_PKTINFO 1 |
| 174 | #define GPR_HAVE_IPV6_RECVPKTINFO 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 175 | #elif defined(__linux__) |
| 176 | #define GPR_POSIX_CRASH_HANDLER 1 |
| 177 | #define GPR_PLATFORM_STRING "linux" |
| 178 | #ifndef _BSD_SOURCE |
| 179 | #define _BSD_SOURCE |
| 180 | #endif |
| 181 | #ifndef _DEFAULT_SOURCE |
| 182 | #define _DEFAULT_SOURCE |
| 183 | #endif |
| 184 | #ifndef _GNU_SOURCE |
| 185 | #define _GNU_SOURCE |
| 186 | #endif |
| 187 | #include <features.h> |
| 188 | #define GPR_CPU_LINUX 1 |
| 189 | #define GPR_GCC_ATOMIC 1 |
| 190 | #define GPR_GCC_TLS 1 |
| 191 | #define GPR_LINUX 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 192 | #define GPR_LINUX_LOG |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 193 | #define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1 |
| 194 | #define GPR_POSIX_WAKEUP_FD 1 |
| 195 | #define GPR_POSIX_SOCKET 1 |
| 196 | #define GPR_POSIX_SOCKETADDR 1 |
ahedberg | 803931d | 2016-03-11 17:24:12 -0500 | [diff] [blame] | 197 | #define GPR_HAVE_UNIX_SOCKET 1 |
ahedberg | 8d7cff4 | 2016-03-24 11:16:44 -0400 | [diff] [blame] | 198 | #define GPR_HAVE_IP_PKTINFO 1 |
| 199 | #define GPR_HAVE_IPV6_RECVPKTINFO 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 200 | #ifdef __GLIBC_PREREQ |
| 201 | #if __GLIBC_PREREQ(2, 9) |
| 202 | #define GPR_LINUX_EVENTFD 1 |
| 203 | #endif |
| 204 | #if __GLIBC_PREREQ(2, 10) |
| 205 | #define GPR_LINUX_SOCKETUTILS 1 |
| 206 | #endif |
Craig Tiller | 9828aad | 2016-02-01 14:07:34 -0800 | [diff] [blame] | 207 | #endif |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 208 | #define GPR_LINUX_ENV 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 209 | #ifndef GPR_LINUX_EVENTFD |
| 210 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 211 | #endif |
| 212 | #ifndef GPR_LINUX_SOCKETUTILS |
| 213 | #define GPR_POSIX_SOCKETUTILS |
| 214 | #endif |
Nicolas "Pixel" Noble | a0091cb | 2016-04-15 07:47:50 +0200 | [diff] [blame] | 215 | #define GPR_POSIX_FILE 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 216 | #define GPR_POSIX_TMPFILE 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 217 | #define GPR_POSIX_STRING 1 |
| 218 | #define GPR_POSIX_SUBPROCESS 1 |
| 219 | #define GPR_POSIX_SYNC 1 |
| 220 | #define GPR_POSIX_TIME 1 |
| 221 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 222 | #define GPR_HAVE_MSG_NOSIGNAL 1 |
| 223 | #ifdef _LP64 |
| 224 | #define GPR_ARCH_64 1 |
| 225 | #else /* _LP64 */ |
| 226 | #define GPR_ARCH_32 1 |
| 227 | #endif /* _LP64 */ |
| 228 | #elif defined(__APPLE__) |
| 229 | #include <TargetConditionals.h> |
| 230 | #ifndef _BSD_SOURCE |
| 231 | #define _BSD_SOURCE |
| 232 | #endif |
| 233 | #define GPR_MSG_IOVLEN_TYPE int |
| 234 | #if TARGET_OS_IPHONE |
| 235 | #define GPR_FORBID_UNREACHABLE_CODE 1 |
| 236 | #define GPR_PLATFORM_STRING "ios" |
| 237 | #define GPR_CPU_IPHONE 1 |
| 238 | #define GPR_PTHREAD_TLS 1 |
| 239 | #else /* TARGET_OS_IPHONE */ |
| 240 | #define GPR_PLATFORM_STRING "osx" |
| 241 | #define GPR_CPU_POSIX 1 |
| 242 | #define GPR_GCC_TLS 1 |
| 243 | #define GPR_POSIX_CRASH_HANDLER 1 |
| 244 | #endif |
| 245 | #define GPR_GCC_ATOMIC 1 |
| 246 | #define GPR_POSIX_LOG 1 |
| 247 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 248 | #define GPR_POSIX_WAKEUP_FD 1 |
| 249 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 250 | #define GPR_POSIX_SOCKET 1 |
| 251 | #define GPR_POSIX_SOCKETADDR 1 |
| 252 | #define GPR_POSIX_SOCKETUTILS 1 |
| 253 | #define GPR_POSIX_ENV 1 |
Nicolas "Pixel" Noble | a0091cb | 2016-04-15 07:47:50 +0200 | [diff] [blame] | 254 | #define GPR_POSIX_FILE 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 255 | #define GPR_POSIX_TMPFILE 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 256 | #define GPR_POSIX_STRING 1 |
| 257 | #define GPR_POSIX_SUBPROCESS 1 |
| 258 | #define GPR_POSIX_SYNC 1 |
| 259 | #define GPR_POSIX_TIME 1 |
| 260 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 261 | #define GPR_HAVE_SO_NOSIGPIPE 1 |
ahedberg | 803931d | 2016-03-11 17:24:12 -0500 | [diff] [blame] | 262 | #define GPR_HAVE_UNIX_SOCKET 1 |
ahedberg | 8d7cff4 | 2016-03-24 11:16:44 -0400 | [diff] [blame] | 263 | #define GPR_HAVE_IP_PKTINFO 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 264 | #ifdef _LP64 |
| 265 | #define GPR_ARCH_64 1 |
| 266 | #else /* _LP64 */ |
| 267 | #define GPR_ARCH_32 1 |
| 268 | #endif /* _LP64 */ |
| 269 | #elif defined(__FreeBSD__) |
| 270 | #define GPR_PLATFORM_STRING "freebsd" |
| 271 | #ifndef _BSD_SOURCE |
| 272 | #define _BSD_SOURCE |
| 273 | #endif |
| 274 | #define GPR_CPU_POSIX 1 |
| 275 | #define GPR_GCC_ATOMIC 1 |
| 276 | #define GPR_GCC_TLS 1 |
| 277 | #define GPR_POSIX_LOG 1 |
| 278 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 279 | #define GPR_POSIX_WAKEUP_FD 1 |
| 280 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 281 | #define GPR_POSIX_SOCKET 1 |
| 282 | #define GPR_POSIX_SOCKETADDR 1 |
| 283 | #define GPR_POSIX_SOCKETUTILS 1 |
| 284 | #define GPR_POSIX_ENV 1 |
Nicolas "Pixel" Noble | a0091cb | 2016-04-15 07:47:50 +0200 | [diff] [blame] | 285 | #define GPR_POSIX_FILE 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 286 | #define GPR_POSIX_TMPFILE 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 287 | #define GPR_POSIX_STRING 1 |
| 288 | #define GPR_POSIX_SUBPROCESS 1 |
| 289 | #define GPR_POSIX_SYNC 1 |
| 290 | #define GPR_POSIX_TIME 1 |
| 291 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 292 | #define GPR_HAVE_SO_NOSIGPIPE 1 |
ahedberg | 803931d | 2016-03-11 17:24:12 -0500 | [diff] [blame] | 293 | #define GPR_HAVE_UNIX_SOCKET 1 |
ahedberg | 8d7cff4 | 2016-03-24 11:16:44 -0400 | [diff] [blame] | 294 | #define GPR_HAVE_IP_PKTINFO 1 |
| 295 | #define GPR_HAVE_IPV6_RECVPKTINFO 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 296 | #ifdef _LP64 |
| 297 | #define GPR_ARCH_64 1 |
| 298 | #else /* _LP64 */ |
| 299 | #define GPR_ARCH_32 1 |
| 300 | #endif /* _LP64 */ |
Sam Clegg | 8ec33f0 | 2016-02-02 17:44:55 -0800 | [diff] [blame] | 301 | #elif defined(__native_client__) |
| 302 | #define GPR_PLATFORM_STRING "nacl" |
| 303 | #ifndef _BSD_SOURCE |
| 304 | #define _BSD_SOURCE |
| 305 | #endif |
| 306 | #ifndef _DEFAULT_SOURCE |
| 307 | #define _DEFAULT_SOURCE |
| 308 | #endif |
| 309 | #ifndef _GNU_SOURCE |
| 310 | #define _GNU_SOURCE |
| 311 | #endif |
| 312 | #define GPR_CPU_POSIX 1 |
| 313 | #define GPR_GCC_ATOMIC 1 |
| 314 | #define GPR_GCC_TLS 1 |
| 315 | #define GPR_POSIX_LOG 1 |
| 316 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 317 | #define GPR_POSIX_WAKEUP_FD 1 |
| 318 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 319 | #define GPR_POSIX_SOCKET 1 |
| 320 | #define GPR_POSIX_SOCKETADDR 1 |
| 321 | #define GPR_POSIX_SOCKETUTILS 1 |
| 322 | #define GPR_POSIX_ENV 1 |
Nicolas "Pixel" Noble | a0091cb | 2016-04-15 07:47:50 +0200 | [diff] [blame] | 323 | #define GPR_POSIX_FILE 1 |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 324 | #define GPR_POSIX_TMPFILE 1 |
Sam Clegg | 8ec33f0 | 2016-02-02 17:44:55 -0800 | [diff] [blame] | 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_GETPID_IN_UNISTD_H 1 |
| 330 | #ifdef _LP64 |
| 331 | #define GPR_ARCH_64 1 |
| 332 | #else /* _LP64 */ |
| 333 | #define GPR_ARCH_32 1 |
| 334 | #endif /* _LP64 */ |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 335 | #else |
Sam Clegg | 8ec33f0 | 2016-02-02 17:44:55 -0800 | [diff] [blame] | 336 | #error "Could not auto-detect platform" |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 337 | #endif |
| 338 | #endif /* GPR_NO_AUTODETECT_PLATFORM */ |
| 339 | |
| 340 | #ifndef GPR_PLATFORM_STRING |
| 341 | #warning "GPR_PLATFORM_STRING not auto-detected" |
| 342 | #define GPR_PLATFORM_STRING "unknown" |
| 343 | #endif |
| 344 | |
| 345 | #ifdef GPR_GCOV |
| 346 | #undef GPR_FORBID_UNREACHABLE_CODE |
| 347 | #define GPR_FORBID_UNREACHABLE_CODE 1 |
| 348 | #endif |
| 349 | |
Nicolas "Pixel" Noble | 221c9c7 | 2016-02-04 18:05:17 +0100 | [diff] [blame] | 350 | #ifdef _MSC_VER |
| 351 | #if _MSC_VER < 1700 |
| 352 | typedef __int8 int8_t; |
| 353 | typedef __int16 int16_t; |
| 354 | typedef __int32 int32_t; |
| 355 | typedef __int64 int64_t; |
| 356 | typedef unsigned __int8 uint8_t; |
| 357 | typedef unsigned __int16 uint16_t; |
| 358 | typedef unsigned __int32 uint32_t; |
| 359 | typedef unsigned __int64 uint64_t; |
| 360 | #else |
| 361 | #include <stdint.h> |
| 362 | #endif /* _MSC_VER < 1700 */ |
| 363 | #else |
| 364 | #include <stdint.h> |
| 365 | #endif /* _MSC_VER */ |
| 366 | |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 367 | /* Cache line alignment */ |
| 368 | #ifndef GPR_CACHELINE_SIZE_LOG |
| 369 | #if defined(__i386__) || defined(__x86_64__) |
| 370 | #define GPR_CACHELINE_SIZE_LOG 6 |
| 371 | #endif |
| 372 | #ifndef GPR_CACHELINE_SIZE_LOG |
| 373 | /* A reasonable default guess. Note that overestimates tend to waste more |
| 374 | space, while underestimates tend to waste more time. */ |
| 375 | #define GPR_CACHELINE_SIZE_LOG 6 |
| 376 | #endif /* GPR_CACHELINE_SIZE_LOG */ |
| 377 | #endif /* GPR_CACHELINE_SIZE_LOG */ |
| 378 | |
| 379 | #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG) |
| 380 | |
| 381 | /* scrub GCC_ATOMIC if it's not available on this compiler */ |
| 382 | #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED) |
| 383 | #undef GPR_GCC_ATOMIC |
| 384 | #define GPR_GCC_SYNC 1 |
| 385 | #endif |
| 386 | |
| 387 | /* Validate platform combinations */ |
| 388 | #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \ |
| 389 | defined(GPR_WIN32_ATOMIC) != \ |
| 390 | 1 |
| 391 | #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32_ATOMIC |
| 392 | #endif |
| 393 | |
| 394 | #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1 |
| 395 | #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64 |
| 396 | #endif |
| 397 | |
| 398 | #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WIN32) + \ |
| 399 | defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \ |
| 400 | 1 |
| 401 | #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WIN32, GPR_CPU_IPHONE, GPR_CPU_CUSTOM |
| 402 | #endif |
| 403 | |
| 404 | #if defined(GPR_POSIX_MULTIPOLL_WITH_POLL) && !defined(GPR_POSIX_SOCKET) |
| 405 | #error Must define GPR_POSIX_SOCKET to use GPR_POSIX_MULTIPOLL_WITH_POLL |
| 406 | #endif |
| 407 | |
| 408 | #if defined(GPR_POSIX_SOCKET) + defined(GPR_WINSOCK_SOCKET) + \ |
| 409 | defined(GPR_CUSTOM_SOCKET) != \ |
| 410 | 1 |
| 411 | #error Must define exactly one of GPR_POSIX_SOCKET, GPR_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET |
| 412 | #endif |
| 413 | |
| 414 | #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \ |
| 415 | defined(GPR_CUSTOM_TLS) != \ |
| 416 | 1 |
| 417 | #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS |
| 418 | #endif |
| 419 | |
| 420 | /* maximum alignment needed for any type on this platform, rounded up to a |
| 421 | power of two */ |
| 422 | #define GPR_MAX_ALIGNMENT 16 |
| 423 | |
| 424 | #ifndef GRPC_MUST_USE_RESULT |
| 425 | #ifdef __GNUC__ |
| 426 | #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) |
| 427 | #else |
| 428 | #define GRPC_MUST_USE_RESULT |
| 429 | #endif |
| 430 | #endif |
| 431 | |
| 432 | #if GPR_FORBID_UNREACHABLE_CODE |
| 433 | #define GPR_UNREACHABLE_CODE(STATEMENT) |
| 434 | #else |
| 435 | #define GPR_UNREACHABLE_CODE(STATEMENT) \ |
| 436 | do { \ |
| 437 | gpr_log(GPR_ERROR, "Should never reach here."); \ |
| 438 | abort(); \ |
| 439 | STATEMENT; \ |
| 440 | } while (0) |
| 441 | #endif /* GPR_FORBID_UNREACHABLE_CODE */ |
| 442 | |
Nicolas "Pixel" Noble | cd41a0b | 2016-02-08 22:53:14 +0100 | [diff] [blame] | 443 | #ifndef GPRAPI |
| 444 | #define GPRAPI |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame] | 445 | #endif |
| 446 | |
Nicolas "Pixel" Noble | cd41a0b | 2016-02-08 22:53:14 +0100 | [diff] [blame] | 447 | #ifndef GRPCAPI |
| 448 | #define GRPCAPI GPRAPI |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame] | 449 | #endif |
| 450 | |
Nicolas "Pixel" Noble | cd41a0b | 2016-02-08 22:53:14 +0100 | [diff] [blame] | 451 | #ifndef CENSUSAPI |
| 452 | #define CENSUSAPI GRPCAPI |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame] | 453 | #endif |
| 454 | |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 455 | #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ |