1 /* 2 +----------------------------------------------------------------------+ 3 | Zend Engine | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 2.00 of the Zend license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.zend.com/license/2_00.txt. | 11 | If you did not receive a copy of the Zend license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@zend.com so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Authors: Andi Gutmans <andi@php.net> | 16 | Zeev Suraski <zeev@php.net> | 17 | Dmitry Stogov <dmitry@php.net> | 18 +----------------------------------------------------------------------+ 19 */ 20 21 #ifndef ZEND_PORTABILITY_H 22 #define ZEND_PORTABILITY_H 23 24 #ifdef __cplusplus 25 #define BEGIN_EXTERN_C() extern "C" { 26 #define END_EXTERN_C() } 27 #else 28 #define BEGIN_EXTERN_C() 29 #define END_EXTERN_C() 30 #endif 31 32 /* 33 * general definitions 34 */ 35 36 #ifdef ZEND_WIN32 37 # include "zend_config.w32.h" 38 # define ZEND_PATHS_SEPARATOR ';' 39 #elif defined(__riscos__) 40 # include <zend_config.h> 41 # define ZEND_PATHS_SEPARATOR ';' 42 #else 43 # include <zend_config.h> 44 # define ZEND_PATHS_SEPARATOR ':' 45 #endif 46 47 #include "../TSRM/TSRM.h" 48 49 #include <stdio.h> 50 #include <assert.h> 51 #include <math.h> 52 53 #ifdef HAVE_UNIX_H 54 # include <unix.h> 55 #endif 56 57 #include <stdarg.h> 58 #include <stddef.h> 59 60 #ifdef HAVE_DLFCN_H 61 # include <dlfcn.h> 62 #endif 63 64 #include <limits.h> 65 66 #if defined(ZEND_WIN32) && !defined(__clang__) 67 #include <intrin.h> 68 #endif 69 70 #include "zend_range_check.h" 71 72 /* GCC x.y.z supplies __GNUC__ = x and __GNUC_MINOR__ = y */ 73 #ifdef __GNUC__ 74 # define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 75 #else 76 # define ZEND_GCC_VERSION 0 77 #endif 78 79 /* Compatibility with non-clang compilers */ 80 #ifndef __has_attribute 81 # define __has_attribute(x) 0 82 #endif 83 #ifndef __has_builtin 84 # define __has_builtin(x) 0 85 #endif 86 #ifndef __has_feature 87 # define __has_feature(x) 0 88 #endif 89 90 #if defined(ZEND_WIN32) && !defined(__clang__) 91 # define ZEND_ASSUME(c) __assume(c) 92 #elif defined(__clang__) && __has_builtin(__builtin_assume) 93 # pragma clang diagnostic ignored "-Wassume" 94 # define ZEND_ASSUME(c) __builtin_assume(c) 95 #elif PHP_HAVE_BUILTIN_UNREACHABLE && PHP_HAVE_BUILTIN_EXPECT 96 # define ZEND_ASSUME(c) do { \ 97 if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \ 98 } while (0) 99 #else 100 # define ZEND_ASSUME(c) 101 #endif 102 103 #if ZEND_DEBUG 104 # define ZEND_ASSERT(c) assert(c) 105 #else 106 # define ZEND_ASSERT(c) ZEND_ASSUME(c) 107 #endif 108 109 #ifdef PHP_HAVE_BUILTIN_UNREACHABLE 110 # define _ZEND_UNREACHABLE() __builtin_unreachable() 111 #else 112 # define _ZEND_UNREACHABLE() ZEND_ASSUME(0) 113 #endif 114 115 #if ZEND_DEBUG 116 # define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); _ZEND_UNREACHABLE();} while (0) 117 #else 118 # define ZEND_UNREACHABLE() _ZEND_UNREACHABLE() 119 #endif 120 121 /* pseudo fallthrough keyword; */ 122 #if defined(__GNUC__) && __GNUC__ >= 7 123 # define ZEND_FALLTHROUGH __attribute__((__fallthrough__)) 124 #else 125 # define ZEND_FALLTHROUGH ((void)0) 126 #endif 127 128 /* Only use this macro if you know for sure that all of the switches values 129 are covered by its case statements */ 130 #define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_UNREACHABLE(); break; 131 132 #if defined(__GNUC__) && __GNUC__ >= 4 133 # define ZEND_IGNORE_VALUE(x) (({ __typeof__ (x) __x = (x); (void) __x; })) 134 #else 135 # define ZEND_IGNORE_VALUE(x) ((void) (x)) 136 #endif 137 138 #define zend_quiet_write(...) ZEND_IGNORE_VALUE(write(__VA_ARGS__)) 139 140 /* all HAVE_XXX test have to be after the include of zend_config above */ 141 142 #if defined(HAVE_LIBDL) && !defined(ZEND_WIN32) 143 144 # if __has_feature(address_sanitizer) 145 # define __SANITIZE_ADDRESS__ 146 # endif 147 148 # ifndef RTLD_LAZY 149 # define RTLD_LAZY 1 /* Solaris 1, FreeBSD's (2.1.7.1 and older) */ 150 # endif 151 152 # ifndef RTLD_GLOBAL 153 # define RTLD_GLOBAL 0 154 # endif 155 156 # ifdef PHP_USE_RTLD_NOW 157 # define PHP_RTLD_MODE RTLD_NOW 158 # else 159 # define PHP_RTLD_MODE RTLD_LAZY 160 # endif 161 162 # if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT) 163 # define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT) 164 # elif defined(RTLD_DEEPBIND) && !defined(__SANITIZE_ADDRESS__) && !__has_feature(memory_sanitizer) 165 # define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_DEEPBIND) 166 # else 167 # define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL) 168 # endif 169 # define DL_UNLOAD dlclose 170 # if defined(DLSYM_NEEDS_UNDERSCORE) 171 # define DL_FETCH_SYMBOL(h,s) dlsym((h), "_" s) 172 # else 173 # define DL_FETCH_SYMBOL dlsym 174 # endif 175 # define DL_ERROR dlerror 176 # define DL_HANDLE void * 177 # define ZEND_EXTENSIONS_SUPPORT 1 178 #elif defined(ZEND_WIN32) 179 # define DL_LOAD(libname) LoadLibrary(libname) 180 # define DL_FETCH_SYMBOL GetProcAddress 181 # define DL_UNLOAD FreeLibrary 182 # define DL_HANDLE HMODULE 183 # define ZEND_EXTENSIONS_SUPPORT 1 184 #else 185 # define DL_HANDLE void * 186 # define ZEND_EXTENSIONS_SUPPORT 0 187 #endif 188 189 #if defined(HAVE_ALLOCA_H) && !defined(_ALLOCA_H) 190 # include <alloca.h> 191 #endif 192 /* AIX requires this to be the first thing in the file. */ 193 #ifndef __GNUC__ 194 # ifndef HAVE_ALLOCA_H 195 # ifdef _AIX 196 # pragma alloca 197 # else 198 # ifndef alloca /* predefined by HP cc +Olibcalls */ 199 char *alloca(); 200 # endif 201 # endif 202 # endif 203 #endif 204 205 #if !ZEND_DEBUG && (defined(HAVE_ALLOCA) || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(HPUX)) && !defined(__APPLE__) 206 # define ZEND_ALLOCA_MAX_SIZE (32 * 1024) 207 # define ALLOCA_FLAG(name) \ 208 bool name; 209 # define SET_ALLOCA_FLAG(name) \ 210 name = true 211 # define do_alloca_ex(size, limit, use_heap) \ 212 ((use_heap = (UNEXPECTED((size) > (limit)))) ? emalloc(size) : alloca(size)) 213 # define do_alloca(size, use_heap) \ 214 do_alloca_ex(size, ZEND_ALLOCA_MAX_SIZE, use_heap) 215 # define free_alloca(p, use_heap) \ 216 do { if (UNEXPECTED(use_heap)) efree(p); } while (0) 217 #else 218 # define ALLOCA_FLAG(name) 219 # define SET_ALLOCA_FLAG(name) 220 # define do_alloca(p, use_heap) emalloc(p) 221 # define free_alloca(p, use_heap) efree(p) 222 #endif 223 224 #if ZEND_GCC_VERSION >= 2096 || __has_attribute(__malloc__) 225 # define ZEND_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 226 #elif defined(ZEND_WIN32) 227 # define ZEND_ATTRIBUTE_MALLOC __declspec(allocator) __declspec(restrict) 228 #else 229 # define ZEND_ATTRIBUTE_MALLOC 230 #endif 231 232 #if ZEND_GCC_VERSION >= 4003 || __has_attribute(alloc_size) 233 # define ZEND_ATTRIBUTE_ALLOC_SIZE(X) __attribute__ ((alloc_size(X))) 234 # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y) __attribute__ ((alloc_size(X,Y))) 235 #else 236 # define ZEND_ATTRIBUTE_ALLOC_SIZE(X) 237 # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y) 238 #endif 239 240 #if ZEND_GCC_VERSION >= 3000 241 # define ZEND_ATTRIBUTE_CONST __attribute__((const)) 242 #else 243 # define ZEND_ATTRIBUTE_CONST 244 #endif 245 246 #if ZEND_GCC_VERSION >= 2007 || __has_attribute(format) 247 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first))) 248 #else 249 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) 250 #endif 251 252 #if (ZEND_GCC_VERSION >= 3001 && !defined(__INTEL_COMPILER)) || __has_attribute(format) 253 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first))) 254 #else 255 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) 256 #endif 257 258 #if ZEND_GCC_VERSION >= 3001 || __has_attribute(deprecated) 259 # define ZEND_ATTRIBUTE_DEPRECATED __attribute__((deprecated)) 260 #elif defined(ZEND_WIN32) 261 # define ZEND_ATTRIBUTE_DEPRECATED __declspec(deprecated) 262 #else 263 # define ZEND_ATTRIBUTE_DEPRECATED 264 #endif 265 266 #if ZEND_GCC_VERSION >= 4003 || __has_attribute(unused) 267 # define ZEND_ATTRIBUTE_UNUSED __attribute__((unused)) 268 #else 269 # define ZEND_ATTRIBUTE_UNUSED 270 #endif 271 272 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003 273 # define ZEND_COLD __attribute__((cold)) 274 # ifdef __OPTIMIZE__ 275 # define ZEND_OPT_SIZE __attribute__((optimize("Os"))) 276 # define ZEND_OPT_SPEED __attribute__((optimize("Ofast"))) 277 # else 278 # define ZEND_OPT_SIZE 279 # define ZEND_OPT_SPEED 280 # endif 281 #else 282 # define ZEND_COLD 283 # define ZEND_OPT_SIZE 284 # define ZEND_OPT_SPEED 285 #endif 286 287 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 5000 288 # define ZEND_ATTRIBUTE_UNUSED_LABEL __attribute__((unused)); 289 # define ZEND_ATTRIBUTE_COLD_LABEL __attribute__((cold)); 290 #else 291 # define ZEND_ATTRIBUTE_UNUSED_LABEL 292 # define ZEND_ATTRIBUTE_COLD_LABEL 293 #endif 294 295 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004 && defined(__i386__) 296 # define ZEND_FASTCALL __attribute__((fastcall)) 297 #elif defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER == 1700 298 # define ZEND_FASTCALL __fastcall 299 #elif defined(_MSC_VER) && _MSC_VER >= 1800 && !defined(__clang__) 300 # define ZEND_FASTCALL __vectorcall 301 #else 302 # define ZEND_FASTCALL 303 #endif 304 305 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(__APPLE__) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) || __has_attribute(noreturn) 306 # define HAVE_NORETURN 307 # define ZEND_NORETURN __attribute__((noreturn)) 308 #elif defined(ZEND_WIN32) 309 # define HAVE_NORETURN 310 # define ZEND_NORETURN __declspec(noreturn) 311 #else 312 # define ZEND_NORETURN 313 #endif 314 315 #if __has_attribute(force_align_arg_pointer) 316 # define ZEND_STACK_ALIGNED __attribute__((force_align_arg_pointer)) 317 #else 318 # define ZEND_STACK_ALIGNED 319 #endif 320 321 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(__APPLE__) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) 322 # define HAVE_NORETURN_ALIAS 323 # define HAVE_ATTRIBUTE_WEAK 324 #endif 325 326 #if ZEND_GCC_VERSION >= 3001 || __has_builtin(__builtin_constant_p) 327 # define HAVE_BUILTIN_CONSTANT_P 328 #endif 329 330 #if __has_attribute(element_count) 331 #define ZEND_ELEMENT_COUNT(m) __attribute__((element_count(m))) 332 #elif __has_attribute(counted_by) 333 #define ZEND_ELEMENT_COUNT(m) __attribute__((counted_by(m))) 334 #else 335 #define ZEND_ELEMENT_COUNT(m) 336 #endif 337 338 #ifdef HAVE_BUILTIN_CONSTANT_P 339 # define ZEND_CONST_COND(_condition, _default) \ 340 (__builtin_constant_p(_condition) ? (_condition) : (_default)) 341 #else 342 # define ZEND_CONST_COND(_condition, _default) \ 343 (_default) 344 #endif 345 346 #if ZEND_DEBUG || defined(ZEND_WIN32_NEVER_INLINE) 347 # define zend_always_inline inline 348 # define zend_never_inline 349 #else 350 # if defined(__GNUC__) 351 # if __GNUC__ >= 3 352 # define zend_always_inline inline __attribute__((always_inline)) 353 # define zend_never_inline __attribute__((noinline)) 354 # else 355 # define zend_always_inline inline 356 # define zend_never_inline 357 # endif 358 # elif defined(_MSC_VER) 359 # define zend_always_inline __forceinline 360 # define zend_never_inline __declspec(noinline) 361 # else 362 # if __has_attribute(always_inline) 363 # define zend_always_inline inline __attribute__((always_inline)) 364 # else 365 # define zend_always_inline inline 366 # endif 367 # if __has_attribute(noinline) 368 # define zend_never_inline __attribute__((noinline)) 369 # else 370 # define zend_never_inline 371 # endif 372 # endif 373 #endif /* ZEND_DEBUG */ 374 375 #ifdef PHP_HAVE_BUILTIN_EXPECT 376 # define EXPECTED(condition) __builtin_expect(!!(condition), 1) 377 # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0) 378 #else 379 # define EXPECTED(condition) (condition) 380 # define UNEXPECTED(condition) (condition) 381 #endif 382 383 #ifndef XtOffsetOf 384 # define XtOffsetOf(s_type, field) offsetof(s_type, field) 385 #endif 386 387 #ifdef HAVE_SIGSETJMP 388 # define SETJMP(a) sigsetjmp(a, 0) 389 # define LONGJMP(a,b) siglongjmp(a, b) 390 # define JMP_BUF sigjmp_buf 391 #else 392 # define SETJMP(a) setjmp(a) 393 # define LONGJMP(a,b) longjmp(a, b) 394 # define JMP_BUF jmp_buf 395 #endif 396 397 #if ZEND_DEBUG 398 # define ZEND_FILE_LINE_D const char *__zend_filename, const uint32_t __zend_lineno 399 # define ZEND_FILE_LINE_DC , ZEND_FILE_LINE_D 400 # define ZEND_FILE_LINE_ORIG_D const char *__zend_orig_filename, const uint32_t __zend_orig_lineno 401 # define ZEND_FILE_LINE_ORIG_DC , ZEND_FILE_LINE_ORIG_D 402 # define ZEND_FILE_LINE_RELAY_C __zend_filename, __zend_lineno 403 # define ZEND_FILE_LINE_RELAY_CC , ZEND_FILE_LINE_RELAY_C 404 # define ZEND_FILE_LINE_C __FILE__, __LINE__ 405 # define ZEND_FILE_LINE_CC , ZEND_FILE_LINE_C 406 # define ZEND_FILE_LINE_EMPTY_C NULL, 0 407 # define ZEND_FILE_LINE_EMPTY_CC , ZEND_FILE_LINE_EMPTY_C 408 # define ZEND_FILE_LINE_ORIG_RELAY_C __zend_orig_filename, __zend_orig_lineno 409 # define ZEND_FILE_LINE_ORIG_RELAY_CC , ZEND_FILE_LINE_ORIG_RELAY_C 410 #else 411 # define ZEND_FILE_LINE_D void 412 # define ZEND_FILE_LINE_DC 413 # define ZEND_FILE_LINE_ORIG_D void 414 # define ZEND_FILE_LINE_ORIG_DC 415 # define ZEND_FILE_LINE_RELAY_C 416 # define ZEND_FILE_LINE_RELAY_CC 417 # define ZEND_FILE_LINE_C 418 # define ZEND_FILE_LINE_CC 419 # define ZEND_FILE_LINE_EMPTY_C 420 # define ZEND_FILE_LINE_EMPTY_CC 421 # define ZEND_FILE_LINE_ORIG_RELAY_C 422 # define ZEND_FILE_LINE_ORIG_RELAY_CC 423 #endif /* ZEND_DEBUG */ 424 425 #if ZEND_DEBUG 426 # define Z_DBG(expr) (expr) 427 #else 428 # define Z_DBG(expr) 429 #endif 430 431 #ifdef ZTS 432 # define ZTS_V 1 433 #else 434 # define ZTS_V 0 435 #endif 436 437 #ifndef LONG_MAX 438 # define LONG_MAX 2147483647L 439 #endif 440 441 #ifndef LONG_MIN 442 # define LONG_MIN (- LONG_MAX - 1) 443 #endif 444 445 #define MAX_LENGTH_OF_DOUBLE 32 446 447 #undef MIN 448 #undef MAX 449 #define MAX(a, b) (((a)>(b))?(a):(b)) 450 #define MIN(a, b) (((a)<(b))?(a):(b)) 451 452 #define ZEND_BIT_TEST(bits, bit) \ 453 (((bits)[(bit) / (sizeof((bits)[0])*8)] >> ((bit) & (sizeof((bits)[0])*8-1))) & 1) 454 455 #define ZEND_INFINITY INFINITY 456 457 #define ZEND_NAN NAN 458 459 #if defined(__cplusplus) && __cplusplus >= 201103L 460 extern "C++" { 461 # include <cmath> 462 } 463 # define zend_isnan std::isnan 464 # define zend_isinf std::isinf 465 # define zend_finite std::isfinite 466 #else 467 # include <math.h> 468 # define zend_isnan(a) isnan(a) 469 # define zend_isinf(a) isinf(a) 470 # define zend_finite(a) isfinite(a) 471 #endif 472 473 #define ZEND_STRL(str) (str), (sizeof(str)-1) 474 #define ZEND_STRS(str) (str), (sizeof(str)) 475 #define ZEND_NORMALIZE_BOOL(n) \ 476 ((n) ? (((n)<0) ? -1 : 1) : 0) 477 #define ZEND_TRUTH(x) ((x) ? 1 : 0) 478 #define ZEND_LOG_XOR(a, b) (ZEND_TRUTH(a) ^ ZEND_TRUTH(b)) 479 480 /** 481 * Do a three-way comparison of two integers and returns -1, 0 or 1 482 * depending on whether #a is smaller, equal or larger than #b. 483 */ 484 #define ZEND_THREEWAY_COMPARE(a, b) ((a) == (b) ? 0 : ((a) < (b) ? -1 : 1)) 485 486 #define ZEND_MAX_RESERVED_RESOURCES 6 487 488 /* excpt.h on Digital Unix 4.0 defines function_table */ 489 #undef function_table 490 491 #ifdef ZEND_WIN32 492 #define ZEND_SECURE_ZERO(var, size) RtlSecureZeroMemory((var), (size)) 493 #else 494 #define ZEND_SECURE_ZERO(var, size) explicit_bzero((var), (size)) 495 #endif 496 497 /* This check should only be used on network socket, not file descriptors */ 498 #ifdef ZEND_WIN32 499 #define ZEND_VALID_SOCKET(sock) (INVALID_SOCKET != (sock)) 500 #else 501 #define ZEND_VALID_SOCKET(sock) ((sock) >= 0) 502 #endif 503 504 /* Intrinsics macros start. */ 505 506 /* Memory sanitizer is incompatible with ifunc resolvers. Even if the resolver 507 * is marked as no_sanitize("memory") it will still be instrumented and crash. */ 508 #if __has_feature(memory_sanitizer) || __has_feature(thread_sanitizer) || \ 509 __has_feature(dataflow_sanitizer) 510 # undef HAVE_FUNC_ATTRIBUTE_IFUNC 511 #endif 512 513 /* Only use ifunc resolvers if we have __builtin_cpu_supports() and __builtin_cpu_init(), 514 * otherwise the use of zend_cpu_supports() may not be safe inside ifunc resolvers. */ 515 #if defined(HAVE_FUNC_ATTRIBUTE_IFUNC) && defined(HAVE_FUNC_ATTRIBUTE_TARGET) && \ 516 defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(PHP_HAVE_BUILTIN_CPU_INIT) 517 # define ZEND_INTRIN_HAVE_IFUNC_TARGET 1 518 #endif 519 520 #if (defined(__i386__) || defined(__x86_64__)) 521 # if defined(HAVE_TMMINTRIN_H) 522 # define PHP_HAVE_SSSE3 523 # endif 524 525 # if defined(HAVE_NMMINTRIN_H) 526 # define PHP_HAVE_SSE4_2 527 # endif 528 529 # if defined(HAVE_WMMINTRIN_H) 530 # define PHP_HAVE_PCLMUL 531 # endif 532 533 /* 534 * AVX2 support was added in gcc 4.7, but AVX2 intrinsics don't work in 535 * __attribute__((target("avx2"))) functions until gcc 4.9. 536 */ 537 # if defined(HAVE_IMMINTRIN_H) && \ 538 (defined(__llvm__) || defined(__clang__) || (defined(__GNUC__) && ZEND_GCC_VERSION >= 4009)) 539 # define PHP_HAVE_AVX2 540 # endif 541 #endif 542 543 #ifdef __SSSE3__ 544 /* Instructions compiled directly. */ 545 # define ZEND_INTRIN_SSSE3_NATIVE 1 546 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSSE3)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 547 /* Function resolved by ifunc or MINIT. */ 548 # define ZEND_INTRIN_SSSE3_RESOLVER 1 549 #endif 550 551 /* Do not use for conditional declaration of API functions! */ 552 #if defined(ZEND_INTRIN_SSSE3_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 553 # define ZEND_INTRIN_SSSE3_FUNC_PROTO 1 554 #elif defined(ZEND_INTRIN_SSSE3_RESOLVER) 555 # define ZEND_INTRIN_SSSE3_FUNC_PTR 1 556 #endif 557 558 #ifdef ZEND_INTRIN_SSSE3_RESOLVER 559 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 560 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func) ZEND_API func __attribute__((target("ssse3"))) 561 # else 562 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func) func 563 # endif 564 #else 565 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func) 566 #endif 567 568 #ifdef __SSE4_2__ 569 /* Instructions compiled directly. */ 570 # define ZEND_INTRIN_SSE4_2_NATIVE 1 571 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSE4_2)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 572 /* Function resolved by ifunc or MINIT. */ 573 # define ZEND_INTRIN_SSE4_2_RESOLVER 1 574 #endif 575 576 /* Do not use for conditional declaration of API functions! */ 577 #if defined(ZEND_INTRIN_SSE4_2_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 578 # define ZEND_INTRIN_SSE4_2_FUNC_PROTO 1 579 #elif defined(ZEND_INTRIN_SSE4_2_RESOLVER) 580 # define ZEND_INTRIN_SSE4_2_FUNC_PTR 1 581 #endif 582 583 #ifdef ZEND_INTRIN_SSE4_2_RESOLVER 584 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 585 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) ZEND_API func __attribute__((target("sse4.2"))) 586 # else 587 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) func 588 # endif 589 #else 590 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) 591 #endif 592 593 #ifdef __PCLMUL__ 594 /* Instructions compiled directly. */ 595 # define ZEND_INTRIN_PCLMUL_NATIVE 1 596 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_PCLMUL)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 597 /* Function resolved by ifunc or MINIT. */ 598 # define ZEND_INTRIN_PCLMUL_RESOLVER 1 599 #endif 600 601 /* Do not use for conditional declaration of API functions! */ 602 #if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000)) 603 /* __builtin_cpu_supports has pclmul from gcc9 */ 604 # define ZEND_INTRIN_PCLMUL_FUNC_PROTO 1 605 #elif defined(ZEND_INTRIN_PCLMUL_RESOLVER) 606 # define ZEND_INTRIN_PCLMUL_FUNC_PTR 1 607 #endif 608 609 #ifdef ZEND_INTRIN_PCLMUL_RESOLVER 610 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 611 # define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) ZEND_API func __attribute__((target("pclmul"))) 612 # else 613 # define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) func 614 # endif 615 #else 616 # define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) 617 #endif 618 619 #if defined(ZEND_INTRIN_SSE4_2_NATIVE) && defined(ZEND_INTRIN_PCLMUL_NATIVE) 620 /* Instructions compiled directly. */ 621 # define ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE 1 622 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSE4_2) && defined(PHP_HAVE_PCLMUL)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 623 /* Function resolved by ifunc or MINIT. */ 624 # define ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER 1 625 #endif 626 627 /* Do not use for conditional declaration of API functions! */ 628 #if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000)) 629 /* __builtin_cpu_supports has pclmul from gcc9 */ 630 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1 631 #elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) 632 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR 1 633 #endif 634 635 #ifdef ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER 636 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 637 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) ZEND_API func __attribute__((target("sse4.2,pclmul"))) 638 # else 639 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) func 640 # endif 641 #else 642 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) 643 #endif 644 645 #ifdef __AVX2__ 646 # define ZEND_INTRIN_AVX2_NATIVE 1 647 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_AVX2)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 648 # define ZEND_INTRIN_AVX2_RESOLVER 1 649 #endif 650 651 /* Do not use for conditional declaration of API functions! */ 652 #if defined(ZEND_INTRIN_AVX2_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 653 # define ZEND_INTRIN_AVX2_FUNC_PROTO 1 654 #elif defined(ZEND_INTRIN_AVX2_RESOLVER) 655 # define ZEND_INTRIN_AVX2_FUNC_PTR 1 656 #endif 657 658 #ifdef ZEND_INTRIN_AVX2_RESOLVER 659 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 660 # define ZEND_INTRIN_AVX2_FUNC_DECL(func) ZEND_API func __attribute__((target("avx2"))) 661 # else 662 # define ZEND_INTRIN_AVX2_FUNC_DECL(func) func 663 # endif 664 #else 665 # define ZEND_INTRIN_AVX2_FUNC_DECL(func) 666 #endif 667 668 #if PHP_HAVE_AVX512_SUPPORTS && defined(HAVE_FUNC_ATTRIBUTE_TARGET) || defined(ZEND_WIN32) 669 #define ZEND_INTRIN_AVX512_RESOLVER 1 670 #endif 671 672 #if defined(ZEND_INTRIN_AVX512_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 673 # define ZEND_INTRIN_AVX512_FUNC_PROTO 1 674 #elif defined(ZEND_INTRIN_AVX512_RESOLVER) 675 # define ZEND_INTRIN_AVX512_FUNC_PTR 1 676 #endif 677 678 #ifdef ZEND_INTRIN_AVX512_RESOLVER 679 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 680 # define ZEND_INTRIN_AVX512_FUNC_DECL(func) ZEND_API func __attribute__((target("avx512f,avx512cd,avx512vl,avx512dq,avx512bw"))) 681 # else 682 # define ZEND_INTRIN_AVX512_FUNC_DECL(func) func 683 # endif 684 #else 685 # define ZEND_INTRIN_AVX512_FUNC_DECL(func) 686 #endif 687 688 #if PHP_HAVE_AVX512_VBMI_SUPPORTS && defined(HAVE_FUNC_ATTRIBUTE_TARGET) 689 #define ZEND_INTRIN_AVX512_VBMI_RESOLVER 1 690 #endif 691 692 #if defined(ZEND_INTRIN_AVX512_VBMI_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 693 # define ZEND_INTRIN_AVX512_VBMI_FUNC_PROTO 1 694 #elif defined(ZEND_INTRIN_AVX512_VBMI_RESOLVER) 695 # define ZEND_INTRIN_AVX512_VBMI_FUNC_PTR 1 696 #endif 697 698 #ifdef ZEND_INTRIN_AVX512_VBMI_RESOLVER 699 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 700 # define ZEND_INTRIN_AVX512_VBMI_FUNC_DECL(func) ZEND_API func __attribute__((target("avx512f,avx512cd,avx512vl,avx512dq,avx512bw,avx512vbmi"))) 701 # else 702 # define ZEND_INTRIN_AVX512_VBMI_FUNC_DECL(func) func 703 # endif 704 #else 705 # define ZEND_INTRIN_AVX512_VBMI_FUNC_DECL(func) 706 #endif 707 708 /* Intrinsics macros end. */ 709 710 #ifdef ZEND_WIN32 711 # define ZEND_SET_ALIGNED(alignment, decl) __declspec(align(alignment)) decl 712 #elif defined(HAVE_ATTRIBUTE_ALIGNED) 713 # define ZEND_SET_ALIGNED(alignment, decl) decl __attribute__ ((__aligned__ (alignment))) 714 #else 715 # define ZEND_SET_ALIGNED(alignment, decl) decl 716 #endif 717 718 #define ZEND_SLIDE_TO_ALIGNED(alignment, ptr) (((uintptr_t)(ptr) + ((alignment)-1)) & ~((alignment)-1)) 719 #define ZEND_SLIDE_TO_ALIGNED16(ptr) ZEND_SLIDE_TO_ALIGNED(Z_UL(16), ptr) 720 721 #ifdef ZEND_WIN32 722 # define _ZEND_EXPAND_VA(a) a 723 # define ZEND_EXPAND_VA(code) _ZEND_EXPAND_VA(code) 724 #else 725 # define ZEND_EXPAND_VA(code) code 726 #endif 727 728 /* On CPU with few registers, it's cheaper to reload value then use spill slot */ 729 #if defined(__i386__) || (defined(_WIN32) && !defined(_WIN64)) 730 # define ZEND_PREFER_RELOAD 731 #endif 732 733 #if defined(ZEND_WIN32) && defined(_DEBUG) 734 # define ZEND_IGNORE_LEAKS_BEGIN() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) 735 # define ZEND_IGNORE_LEAKS_END() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF) 736 #else 737 # define ZEND_IGNORE_LEAKS_BEGIN() 738 # define ZEND_IGNORE_LEAKS_END() 739 #endif 740 741 /* MSVC yields C4090 when a (const T **) is passed to a (void *); ZEND_VOIDP works around that */ 742 #ifdef _MSC_VER 743 # define ZEND_VOIDP(ptr) ((void *) ptr) 744 #else 745 # define ZEND_VOIDP(ptr) (ptr) 746 #endif 747 748 #if __has_attribute(__indirect_return__) 749 # define ZEND_INDIRECT_RETURN __attribute__((__indirect_return__)) 750 #else 751 # define ZEND_INDIRECT_RETURN 752 #endif 753 754 #define __ZEND_DO_PRAGMA(x) _Pragma(#x) 755 #define _ZEND_DO_PRAGMA(x) __ZEND_DO_PRAGMA(x) 756 #if defined(__clang__) 757 # define ZEND_DIAGNOSTIC_IGNORED_START(warning) \ 758 _Pragma("clang diagnostic push") \ 759 _ZEND_DO_PRAGMA(clang diagnostic ignored warning) 760 # define ZEND_DIAGNOSTIC_IGNORED_END \ 761 _Pragma("clang diagnostic pop") 762 #elif defined(__GNUC__) 763 # define ZEND_DIAGNOSTIC_IGNORED_START(warning) \ 764 _Pragma("GCC diagnostic push") \ 765 _ZEND_DO_PRAGMA(GCC diagnostic ignored warning) 766 # define ZEND_DIAGNOSTIC_IGNORED_END \ 767 _Pragma("GCC diagnostic pop") 768 #else 769 # define ZEND_DIAGNOSTIC_IGNORED_START(warning) 770 # define ZEND_DIAGNOSTIC_IGNORED_END 771 #endif 772 773 /** @deprecated */ 774 #define ZEND_CGG_DIAGNOSTIC_IGNORED_START ZEND_DIAGNOSTIC_IGNORED_START 775 /** @deprecated */ 776 #define ZEND_CGG_DIAGNOSTIC_IGNORED_END ZEND_DIAGNOSTIC_IGNORED_END 777 778 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */ 779 # define ZEND_STATIC_ASSERT(c, m) _Static_assert((c), m) 780 #else 781 # define ZEND_STATIC_ASSERT(c, m) 782 #endif 783 784 #endif /* ZEND_PORTABILITY_H */ 785