David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | a43aadd | 2016-01-21 10:01:28 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, 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 | |
| 37 | /* Get windows.h included everywhere (we need it) */ |
| 38 | #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) |
| 39 | #ifndef WIN32_LEAN_AND_MEAN |
| 40 | #define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
| 41 | #define WIN32_LEAN_AND_MEAN |
| 42 | #endif /* WIN32_LEAN_AND_MEAN */ |
| 43 | |
| 44 | #ifndef NOMINMAX |
| 45 | #define GRPC_NOMINMX_WAS_NOT_DEFINED |
| 46 | #define NOMINMAX |
| 47 | #endif /* NOMINMAX */ |
| 48 | |
| 49 | #ifndef _WIN32_WINNT |
| 50 | #error \ |
| 51 | "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" |
| 52 | #else /* !defined(_WIN32_WINNT) */ |
| 53 | #if (_WIN32_WINNT < 0x0600) |
| 54 | #error \ |
| 55 | "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" |
| 56 | #endif /* _WIN32_WINNT < 0x0600 */ |
| 57 | #endif /* defined(_WIN32_WINNT) */ |
| 58 | |
| 59 | #include <windows.h> |
| 60 | |
| 61 | #ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
| 62 | #undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
| 63 | #undef WIN32_LEAN_AND_MEAN |
| 64 | #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ |
| 65 | |
| 66 | #ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED |
| 67 | #undef GRPC_NOMINMAX_WAS_NOT_DEFINED |
| 68 | #undef NOMINMAX |
| 69 | #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ |
| 70 | #endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \ |
| 71 | defined(WIN32) */ |
| 72 | |
| 73 | /* Override this file with one for your platform if you need to redefine |
| 74 | things. */ |
| 75 | |
| 76 | #if !defined(GPR_NO_AUTODETECT_PLATFORM) |
| 77 | #if defined(_WIN64) || defined(WIN64) |
| 78 | #define GPR_PLATFORM_STRING "windows" |
| 79 | #define GPR_WIN32 1 |
| 80 | #define GPR_ARCH_64 1 |
| 81 | #define GPR_GETPID_IN_PROCESS_H 1 |
| 82 | #define GPR_WINSOCK_SOCKET 1 |
Nicolas "Pixel" Noble | 4fba286 | 2016-01-31 07:00:53 +0100 | [diff] [blame] | 83 | #define GPR_WINDOWS_SUBPROCESS 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 84 | #ifdef __GNUC__ |
| 85 | #define GPR_GCC_ATOMIC 1 |
| 86 | #define GPR_GCC_TLS 1 |
| 87 | #else |
| 88 | #define GPR_WIN32_ATOMIC 1 |
| 89 | #define GPR_MSVC_TLS 1 |
| 90 | #endif |
| 91 | #define GPR_WINDOWS_CRASH_HANDLER 1 |
| 92 | #elif defined(_WIN32) || defined(WIN32) |
| 93 | #define GPR_PLATFORM_STRING "windows" |
| 94 | #define GPR_ARCH_32 1 |
| 95 | #define GPR_WIN32 1 |
| 96 | #define GPR_GETPID_IN_PROCESS_H 1 |
| 97 | #define GPR_WINSOCK_SOCKET 1 |
Nicolas "Pixel" Noble | 13a8f5b | 2016-01-31 10:06:02 +0100 | [diff] [blame] | 98 | #define GPR_WINDOWS_SUBPROCESS 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 99 | #ifdef __GNUC__ |
| 100 | #define GPR_GCC_ATOMIC 1 |
| 101 | #define GPR_GCC_TLS 1 |
| 102 | #else |
| 103 | #define GPR_WIN32_ATOMIC 1 |
| 104 | #define GPR_MSVC_TLS 1 |
| 105 | #endif |
| 106 | #define GPR_WINDOWS_CRASH_HANDLER 1 |
| 107 | #elif defined(ANDROID) || defined(__ANDROID__) |
| 108 | #define GPR_PLATFORM_STRING "android" |
| 109 | #define GPR_ANDROID 1 |
| 110 | #define GPR_ARCH_32 1 |
| 111 | #define GPR_CPU_LINUX 1 |
| 112 | #define GPR_GCC_SYNC 1 |
| 113 | #define GPR_GCC_TLS 1 |
| 114 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 115 | #define GPR_POSIX_WAKEUP_FD 1 |
| 116 | #define GPR_LINUX_EVENTFD 1 |
| 117 | #define GPR_POSIX_SOCKET 1 |
| 118 | #define GPR_POSIX_SOCKETADDR 1 |
| 119 | #define GPR_POSIX_SOCKETUTILS 1 |
| 120 | #define GPR_POSIX_ENV 1 |
| 121 | #define GPR_POSIX_FILE 1 |
| 122 | #define GPR_POSIX_STRING 1 |
| 123 | #define GPR_POSIX_SUBPROCESS 1 |
| 124 | #define GPR_POSIX_SYNC 1 |
| 125 | #define GPR_POSIX_TIME 1 |
| 126 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 127 | #define GPR_HAVE_MSG_NOSIGNAL 1 |
| 128 | #elif defined(__linux__) |
| 129 | #define GPR_POSIX_CRASH_HANDLER 1 |
| 130 | #define GPR_PLATFORM_STRING "linux" |
| 131 | #ifndef _BSD_SOURCE |
| 132 | #define _BSD_SOURCE |
| 133 | #endif |
| 134 | #ifndef _DEFAULT_SOURCE |
| 135 | #define _DEFAULT_SOURCE |
| 136 | #endif |
| 137 | #ifndef _GNU_SOURCE |
| 138 | #define _GNU_SOURCE |
| 139 | #endif |
| 140 | #include <features.h> |
| 141 | #define GPR_CPU_LINUX 1 |
| 142 | #define GPR_GCC_ATOMIC 1 |
| 143 | #define GPR_GCC_TLS 1 |
| 144 | #define GPR_LINUX 1 |
| 145 | #define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1 |
| 146 | #define GPR_POSIX_WAKEUP_FD 1 |
| 147 | #define GPR_POSIX_SOCKET 1 |
| 148 | #define GPR_POSIX_SOCKETADDR 1 |
| 149 | #ifdef __GLIBC_PREREQ |
| 150 | #if __GLIBC_PREREQ(2, 9) |
| 151 | #define GPR_LINUX_EVENTFD 1 |
| 152 | #endif |
| 153 | #if __GLIBC_PREREQ(2, 10) |
| 154 | #define GPR_LINUX_SOCKETUTILS 1 |
| 155 | #endif |
Craig Tiller | 9828aad | 2016-02-01 14:07:34 -0800 | [diff] [blame] | 156 | #endif |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 157 | #define GPR_LINUX_ENV 1 |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 158 | #ifndef GPR_LINUX_EVENTFD |
| 159 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 160 | #endif |
| 161 | #ifndef GPR_LINUX_SOCKETUTILS |
| 162 | #define GPR_POSIX_SOCKETUTILS |
| 163 | #endif |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 164 | #define GPR_POSIX_FILE 1 |
| 165 | #define GPR_POSIX_STRING 1 |
| 166 | #define GPR_POSIX_SUBPROCESS 1 |
| 167 | #define GPR_POSIX_SYNC 1 |
| 168 | #define GPR_POSIX_TIME 1 |
| 169 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 170 | #define GPR_HAVE_MSG_NOSIGNAL 1 |
| 171 | #ifdef _LP64 |
| 172 | #define GPR_ARCH_64 1 |
| 173 | #else /* _LP64 */ |
| 174 | #define GPR_ARCH_32 1 |
| 175 | #endif /* _LP64 */ |
| 176 | #elif defined(__APPLE__) |
| 177 | #include <TargetConditionals.h> |
| 178 | #ifndef _BSD_SOURCE |
| 179 | #define _BSD_SOURCE |
| 180 | #endif |
| 181 | #define GPR_MSG_IOVLEN_TYPE int |
| 182 | #if TARGET_OS_IPHONE |
| 183 | #define GPR_FORBID_UNREACHABLE_CODE 1 |
| 184 | #define GPR_PLATFORM_STRING "ios" |
| 185 | #define GPR_CPU_IPHONE 1 |
| 186 | #define GPR_PTHREAD_TLS 1 |
| 187 | #else /* TARGET_OS_IPHONE */ |
| 188 | #define GPR_PLATFORM_STRING "osx" |
| 189 | #define GPR_CPU_POSIX 1 |
| 190 | #define GPR_GCC_TLS 1 |
| 191 | #define GPR_POSIX_CRASH_HANDLER 1 |
| 192 | #endif |
| 193 | #define GPR_GCC_ATOMIC 1 |
| 194 | #define GPR_POSIX_LOG 1 |
| 195 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 196 | #define GPR_POSIX_WAKEUP_FD 1 |
| 197 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 198 | #define GPR_POSIX_SOCKET 1 |
| 199 | #define GPR_POSIX_SOCKETADDR 1 |
| 200 | #define GPR_POSIX_SOCKETUTILS 1 |
| 201 | #define GPR_POSIX_ENV 1 |
| 202 | #define GPR_POSIX_FILE 1 |
| 203 | #define GPR_POSIX_STRING 1 |
| 204 | #define GPR_POSIX_SUBPROCESS 1 |
| 205 | #define GPR_POSIX_SYNC 1 |
| 206 | #define GPR_POSIX_TIME 1 |
| 207 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 208 | #define GPR_HAVE_SO_NOSIGPIPE 1 |
| 209 | #ifdef _LP64 |
| 210 | #define GPR_ARCH_64 1 |
| 211 | #else /* _LP64 */ |
| 212 | #define GPR_ARCH_32 1 |
| 213 | #endif /* _LP64 */ |
| 214 | #elif defined(__FreeBSD__) |
| 215 | #define GPR_PLATFORM_STRING "freebsd" |
| 216 | #ifndef _BSD_SOURCE |
| 217 | #define _BSD_SOURCE |
| 218 | #endif |
| 219 | #define GPR_CPU_POSIX 1 |
| 220 | #define GPR_GCC_ATOMIC 1 |
| 221 | #define GPR_GCC_TLS 1 |
| 222 | #define GPR_POSIX_LOG 1 |
| 223 | #define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
| 224 | #define GPR_POSIX_WAKEUP_FD 1 |
| 225 | #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
| 226 | #define GPR_POSIX_SOCKET 1 |
| 227 | #define GPR_POSIX_SOCKETADDR 1 |
| 228 | #define GPR_POSIX_SOCKETUTILS 1 |
| 229 | #define GPR_POSIX_ENV 1 |
| 230 | #define GPR_POSIX_FILE 1 |
| 231 | #define GPR_POSIX_STRING 1 |
| 232 | #define GPR_POSIX_SUBPROCESS 1 |
| 233 | #define GPR_POSIX_SYNC 1 |
| 234 | #define GPR_POSIX_TIME 1 |
| 235 | #define GPR_GETPID_IN_UNISTD_H 1 |
| 236 | #define GPR_HAVE_SO_NOSIGPIPE 1 |
| 237 | #ifdef _LP64 |
| 238 | #define GPR_ARCH_64 1 |
| 239 | #else /* _LP64 */ |
| 240 | #define GPR_ARCH_32 1 |
| 241 | #endif /* _LP64 */ |
| 242 | #else |
| 243 | #error Could not auto-detect platform |
| 244 | #endif |
| 245 | #endif /* GPR_NO_AUTODETECT_PLATFORM */ |
| 246 | |
| 247 | #ifndef GPR_PLATFORM_STRING |
| 248 | #warning "GPR_PLATFORM_STRING not auto-detected" |
| 249 | #define GPR_PLATFORM_STRING "unknown" |
| 250 | #endif |
| 251 | |
| 252 | #ifdef GPR_GCOV |
| 253 | #undef GPR_FORBID_UNREACHABLE_CODE |
| 254 | #define GPR_FORBID_UNREACHABLE_CODE 1 |
| 255 | #endif |
| 256 | |
Nicolas "Pixel" Noble | 221c9c7 | 2016-02-04 18:05:17 +0100 | [diff] [blame^] | 257 | #ifdef _MSC_VER |
| 258 | #if _MSC_VER < 1700 |
| 259 | typedef __int8 int8_t; |
| 260 | typedef __int16 int16_t; |
| 261 | typedef __int32 int32_t; |
| 262 | typedef __int64 int64_t; |
| 263 | typedef unsigned __int8 uint8_t; |
| 264 | typedef unsigned __int16 uint16_t; |
| 265 | typedef unsigned __int32 uint32_t; |
| 266 | typedef unsigned __int64 uint64_t; |
| 267 | #else |
| 268 | #include <stdint.h> |
| 269 | #endif /* _MSC_VER < 1700 */ |
| 270 | #else |
| 271 | #include <stdint.h> |
| 272 | #endif /* _MSC_VER */ |
| 273 | |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 274 | /* Cache line alignment */ |
| 275 | #ifndef GPR_CACHELINE_SIZE_LOG |
| 276 | #if defined(__i386__) || defined(__x86_64__) |
| 277 | #define GPR_CACHELINE_SIZE_LOG 6 |
| 278 | #endif |
| 279 | #ifndef GPR_CACHELINE_SIZE_LOG |
| 280 | /* A reasonable default guess. Note that overestimates tend to waste more |
| 281 | space, while underestimates tend to waste more time. */ |
| 282 | #define GPR_CACHELINE_SIZE_LOG 6 |
| 283 | #endif /* GPR_CACHELINE_SIZE_LOG */ |
| 284 | #endif /* GPR_CACHELINE_SIZE_LOG */ |
| 285 | |
| 286 | #define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG) |
| 287 | |
| 288 | /* scrub GCC_ATOMIC if it's not available on this compiler */ |
| 289 | #if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED) |
| 290 | #undef GPR_GCC_ATOMIC |
| 291 | #define GPR_GCC_SYNC 1 |
| 292 | #endif |
| 293 | |
| 294 | /* Validate platform combinations */ |
| 295 | #if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \ |
| 296 | defined(GPR_WIN32_ATOMIC) != \ |
| 297 | 1 |
| 298 | #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32_ATOMIC |
| 299 | #endif |
| 300 | |
| 301 | #if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1 |
| 302 | #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64 |
| 303 | #endif |
| 304 | |
| 305 | #if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WIN32) + \ |
| 306 | defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \ |
| 307 | 1 |
| 308 | #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WIN32, GPR_CPU_IPHONE, GPR_CPU_CUSTOM |
| 309 | #endif |
| 310 | |
| 311 | #if defined(GPR_POSIX_MULTIPOLL_WITH_POLL) && !defined(GPR_POSIX_SOCKET) |
| 312 | #error Must define GPR_POSIX_SOCKET to use GPR_POSIX_MULTIPOLL_WITH_POLL |
| 313 | #endif |
| 314 | |
| 315 | #if defined(GPR_POSIX_SOCKET) + defined(GPR_WINSOCK_SOCKET) + \ |
| 316 | defined(GPR_CUSTOM_SOCKET) != \ |
| 317 | 1 |
| 318 | #error Must define exactly one of GPR_POSIX_SOCKET, GPR_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET |
| 319 | #endif |
| 320 | |
| 321 | #if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \ |
| 322 | defined(GPR_CUSTOM_TLS) != \ |
| 323 | 1 |
| 324 | #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS |
| 325 | #endif |
| 326 | |
| 327 | /* maximum alignment needed for any type on this platform, rounded up to a |
| 328 | power of two */ |
| 329 | #define GPR_MAX_ALIGNMENT 16 |
| 330 | |
| 331 | #ifndef GRPC_MUST_USE_RESULT |
| 332 | #ifdef __GNUC__ |
| 333 | #define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) |
| 334 | #else |
| 335 | #define GRPC_MUST_USE_RESULT |
| 336 | #endif |
| 337 | #endif |
| 338 | |
| 339 | #if GPR_FORBID_UNREACHABLE_CODE |
| 340 | #define GPR_UNREACHABLE_CODE(STATEMENT) |
| 341 | #else |
| 342 | #define GPR_UNREACHABLE_CODE(STATEMENT) \ |
| 343 | do { \ |
| 344 | gpr_log(GPR_ERROR, "Should never reach here."); \ |
| 345 | abort(); \ |
| 346 | STATEMENT; \ |
| 347 | } while (0) |
| 348 | #endif /* GPR_FORBID_UNREACHABLE_CODE */ |
| 349 | |
Craig Tiller | 9b42637 | 2016-01-29 07:58:22 -0800 | [diff] [blame] | 350 | #ifndef GPR_API |
| 351 | #define GPR_API |
| 352 | #endif |
| 353 | |
| 354 | #ifndef GRPC_API |
| 355 | #define GRPC_API GPR_API |
| 356 | #endif |
| 357 | |
| 358 | #ifndef CENSUS_API |
| 359 | #define CENSUS_API GRPC_API |
| 360 | #endif |
| 361 | |
David Garcia Quintas | 08a0a33 | 2016-01-21 01:04:36 -0800 | [diff] [blame] | 362 | #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ |