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(__GNUC__) && ZEND_GCC_VERSION >= 4005) || __has_builtin(__builtin_unreachable)) && PHP_HAVE_BUILTIN_EXPECT 93 # define ZEND_ASSUME(c) do { \ 94 if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \ 95 } while (0) 96 #else 97 # define ZEND_ASSUME(c) 98 #endif 99 100 #if ZEND_DEBUG 101 # define ZEND_ASSERT(c) assert(c) 102 #else 103 # define ZEND_ASSERT(c) ZEND_ASSUME(c) 104 #endif 105 106 #if ZEND_DEBUG 107 # define ZEND_UNREACHABLE() do {ZEND_ASSERT(0); ZEND_ASSUME(0);} while (0) 108 #else 109 # define ZEND_UNREACHABLE() ZEND_ASSUME(0) 110 #endif 111 112 /* pseudo fallthrough keyword; */ 113 #if defined(__GNUC__) && __GNUC__ >= 7 114 # define ZEND_FALLTHROUGH __attribute__((__fallthrough__)) 115 #else 116 # define ZEND_FALLTHROUGH ((void)0) 117 #endif 118 119 /* Only use this macro if you know for sure that all of the switches values 120 are covered by its case statements */ 121 #define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_UNREACHABLE(); break; 122 123 #if defined(__GNUC__) && __GNUC__ >= 4 124 # define ZEND_IGNORE_VALUE(x) (({ __typeof__ (x) __x = (x); (void) __x; })) 125 #else 126 # define ZEND_IGNORE_VALUE(x) ((void) (x)) 127 #endif 128 129 #define zend_quiet_write(...) ZEND_IGNORE_VALUE(write(__VA_ARGS__)) 130 131 /* all HAVE_XXX test have to be after the include of zend_config above */ 132 133 #if defined(HAVE_LIBDL) && !defined(ZEND_WIN32) 134 135 # if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__) 136 # define __SANITIZE_ADDRESS__ 137 # endif 138 139 # ifndef RTLD_LAZY 140 # define RTLD_LAZY 1 /* Solaris 1, FreeBSD's (2.1.7.1 and older) */ 141 # endif 142 143 # ifndef RTLD_GLOBAL 144 # define RTLD_GLOBAL 0 145 # endif 146 147 # ifdef PHP_USE_RTLD_NOW 148 # define PHP_RTLD_MODE RTLD_NOW 149 # else 150 # define PHP_RTLD_MODE RTLD_LAZY 151 # endif 152 153 # if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT) 154 # define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT) 155 # elif defined(RTLD_DEEPBIND) && !defined(__SANITIZE_ADDRESS__) && !__has_feature(memory_sanitizer) 156 # define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL | RTLD_DEEPBIND) 157 # else 158 # define DL_LOAD(libname) dlopen(libname, PHP_RTLD_MODE | RTLD_GLOBAL) 159 # endif 160 # define DL_UNLOAD dlclose 161 # if defined(DLSYM_NEEDS_UNDERSCORE) 162 # define DL_FETCH_SYMBOL(h,s) dlsym((h), "_" s) 163 # else 164 # define DL_FETCH_SYMBOL dlsym 165 # endif 166 # define DL_ERROR dlerror 167 # define DL_HANDLE void * 168 # define ZEND_EXTENSIONS_SUPPORT 1 169 #elif defined(ZEND_WIN32) 170 # define DL_LOAD(libname) LoadLibrary(libname) 171 # define DL_FETCH_SYMBOL GetProcAddress 172 # define DL_UNLOAD FreeLibrary 173 # define DL_HANDLE HMODULE 174 # define ZEND_EXTENSIONS_SUPPORT 1 175 #else 176 # define DL_HANDLE void * 177 # define ZEND_EXTENSIONS_SUPPORT 0 178 #endif 179 180 #if defined(HAVE_ALLOCA_H) && !defined(_ALLOCA_H) 181 # include <alloca.h> 182 #endif 183 /* AIX requires this to be the first thing in the file. */ 184 #ifndef __GNUC__ 185 # ifndef HAVE_ALLOCA_H 186 # ifdef _AIX 187 # pragma alloca 188 # else 189 # ifndef alloca /* predefined by HP cc +Olibcalls */ 190 char *alloca(); 191 # endif 192 # endif 193 # endif 194 #endif 195 196 #if !ZEND_DEBUG && (defined(HAVE_ALLOCA) || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(HPUX)) && !defined(DARWIN) 197 # define ZEND_ALLOCA_MAX_SIZE (32 * 1024) 198 # define ALLOCA_FLAG(name) \ 199 bool name; 200 # define SET_ALLOCA_FLAG(name) \ 201 name = true 202 # define do_alloca_ex(size, limit, use_heap) \ 203 ((use_heap = (UNEXPECTED((size) > (limit)))) ? emalloc(size) : alloca(size)) 204 # define do_alloca(size, use_heap) \ 205 do_alloca_ex(size, ZEND_ALLOCA_MAX_SIZE, use_heap) 206 # define free_alloca(p, use_heap) \ 207 do { if (UNEXPECTED(use_heap)) efree(p); } while (0) 208 #else 209 # define ALLOCA_FLAG(name) 210 # define SET_ALLOCA_FLAG(name) 211 # define do_alloca(p, use_heap) emalloc(p) 212 # define free_alloca(p, use_heap) efree(p) 213 #endif 214 215 #if ZEND_GCC_VERSION >= 2096 || __has_attribute(__malloc__) 216 # define ZEND_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 217 #elif defined(ZEND_WIN32) 218 # define ZEND_ATTRIBUTE_MALLOC __declspec(allocator) __declspec(restrict) 219 #else 220 # define ZEND_ATTRIBUTE_MALLOC 221 #endif 222 223 #if ZEND_GCC_VERSION >= 4003 || __has_attribute(alloc_size) 224 # define ZEND_ATTRIBUTE_ALLOC_SIZE(X) __attribute__ ((alloc_size(X))) 225 # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y) __attribute__ ((alloc_size(X,Y))) 226 #else 227 # define ZEND_ATTRIBUTE_ALLOC_SIZE(X) 228 # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y) 229 #endif 230 231 #if ZEND_GCC_VERSION >= 3000 232 # define ZEND_ATTRIBUTE_CONST __attribute__((const)) 233 #else 234 # define ZEND_ATTRIBUTE_CONST 235 #endif 236 237 #if ZEND_GCC_VERSION >= 2007 || __has_attribute(format) 238 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first))) 239 #else 240 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) 241 #endif 242 243 #if (ZEND_GCC_VERSION >= 3001 && !defined(__INTEL_COMPILER)) || __has_attribute(format) 244 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first))) 245 #else 246 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) 247 #endif 248 249 #if ZEND_GCC_VERSION >= 3001 || __has_attribute(deprecated) 250 # define ZEND_ATTRIBUTE_DEPRECATED __attribute__((deprecated)) 251 #elif defined(ZEND_WIN32) 252 # define ZEND_ATTRIBUTE_DEPRECATED __declspec(deprecated) 253 #else 254 # define ZEND_ATTRIBUTE_DEPRECATED 255 #endif 256 257 #if ZEND_GCC_VERSION >= 4003 || __has_attribute(unused) 258 # define ZEND_ATTRIBUTE_UNUSED __attribute__((unused)) 259 #else 260 # define ZEND_ATTRIBUTE_UNUSED 261 #endif 262 263 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003 264 # define ZEND_COLD __attribute__((cold)) 265 # define ZEND_HOT __attribute__((hot)) 266 # ifdef __OPTIMIZE__ 267 # define ZEND_OPT_SIZE __attribute__((optimize("Os"))) 268 # define ZEND_OPT_SPEED __attribute__((optimize("Ofast"))) 269 # else 270 # define ZEND_OPT_SIZE 271 # define ZEND_OPT_SPEED 272 # endif 273 #else 274 # define ZEND_COLD 275 # define ZEND_HOT 276 # define ZEND_OPT_SIZE 277 # define ZEND_OPT_SPEED 278 #endif 279 280 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 5000 281 # define ZEND_ATTRIBUTE_UNUSED_LABEL __attribute__((unused)); 282 # define ZEND_ATTRIBUTE_COLD_LABEL __attribute__((cold)); 283 # define ZEND_ATTRIBUTE_HOT_LABEL __attribute__((hot)); 284 #else 285 # define ZEND_ATTRIBUTE_UNUSED_LABEL 286 # define ZEND_ATTRIBUTE_COLD_LABEL 287 # define ZEND_ATTRIBUTE_HOT_LABEL 288 #endif 289 290 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004 && defined(__i386__) 291 # define ZEND_FASTCALL __attribute__((fastcall)) 292 #elif defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER == 1700 293 # define ZEND_FASTCALL __fastcall 294 #elif defined(_MSC_VER) && _MSC_VER >= 1800 && !defined(__clang__) 295 # define ZEND_FASTCALL __vectorcall 296 #else 297 # define ZEND_FASTCALL 298 #endif 299 300 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) || __has_attribute(noreturn) 301 # define HAVE_NORETURN 302 # define ZEND_NORETURN __attribute__((noreturn)) 303 #elif defined(ZEND_WIN32) 304 # define HAVE_NORETURN 305 # define ZEND_NORETURN __declspec(noreturn) 306 #else 307 # define ZEND_NORETURN 308 #endif 309 310 #if __has_attribute(force_align_arg_pointer) 311 # define ZEND_STACK_ALIGNED __attribute__((force_align_arg_pointer)) 312 #else 313 # define ZEND_STACK_ALIGNED 314 #endif 315 316 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) 317 # define HAVE_NORETURN_ALIAS 318 # define HAVE_ATTRIBUTE_WEAK 319 #endif 320 321 #if ZEND_GCC_VERSION >= 3001 || __has_builtin(__builtin_constant_p) 322 # define HAVE_BUILTIN_CONSTANT_P 323 #endif 324 325 #ifdef HAVE_BUILTIN_CONSTANT_P 326 # define ZEND_CONST_COND(_condition, _default) \ 327 (__builtin_constant_p(_condition) ? (_condition) : (_default)) 328 #else 329 # define ZEND_CONST_COND(_condition, _default) \ 330 (_default) 331 #endif 332 333 #if ZEND_DEBUG || defined(ZEND_WIN32_NEVER_INLINE) 334 # define zend_always_inline inline 335 # define zend_never_inline 336 #else 337 # if defined(__GNUC__) 338 # if __GNUC__ >= 3 339 # define zend_always_inline inline __attribute__((always_inline)) 340 # define zend_never_inline __attribute__((noinline)) 341 # else 342 # define zend_always_inline inline 343 # define zend_never_inline 344 # endif 345 # elif defined(_MSC_VER) 346 # define zend_always_inline __forceinline 347 # define zend_never_inline __declspec(noinline) 348 # else 349 # if __has_attribute(always_inline) 350 # define zend_always_inline inline __attribute__((always_inline)) 351 # else 352 # define zend_always_inline inline 353 # endif 354 # if __has_attribute(noinline) 355 # define zend_never_inline __attribute__((noinline)) 356 # else 357 # define zend_never_inline 358 # endif 359 # endif 360 #endif /* ZEND_DEBUG */ 361 362 #ifdef PHP_HAVE_BUILTIN_EXPECT 363 # define EXPECTED(condition) __builtin_expect(!!(condition), 1) 364 # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0) 365 #else 366 # define EXPECTED(condition) (condition) 367 # define UNEXPECTED(condition) (condition) 368 #endif 369 370 #ifndef XtOffsetOf 371 # define XtOffsetOf(s_type, field) offsetof(s_type, field) 372 #endif 373 374 #ifdef HAVE_SIGSETJMP 375 # define SETJMP(a) sigsetjmp(a, 0) 376 # define LONGJMP(a,b) siglongjmp(a, b) 377 # define JMP_BUF sigjmp_buf 378 #else 379 # define SETJMP(a) setjmp(a) 380 # define LONGJMP(a,b) longjmp(a, b) 381 # define JMP_BUF jmp_buf 382 #endif 383 384 #if ZEND_DEBUG 385 # define ZEND_FILE_LINE_D const char *__zend_filename, const uint32_t __zend_lineno 386 # define ZEND_FILE_LINE_DC , ZEND_FILE_LINE_D 387 # define ZEND_FILE_LINE_ORIG_D const char *__zend_orig_filename, const uint32_t __zend_orig_lineno 388 # define ZEND_FILE_LINE_ORIG_DC , ZEND_FILE_LINE_ORIG_D 389 # define ZEND_FILE_LINE_RELAY_C __zend_filename, __zend_lineno 390 # define ZEND_FILE_LINE_RELAY_CC , ZEND_FILE_LINE_RELAY_C 391 # define ZEND_FILE_LINE_C __FILE__, __LINE__ 392 # define ZEND_FILE_LINE_CC , ZEND_FILE_LINE_C 393 # define ZEND_FILE_LINE_EMPTY_C NULL, 0 394 # define ZEND_FILE_LINE_EMPTY_CC , ZEND_FILE_LINE_EMPTY_C 395 # define ZEND_FILE_LINE_ORIG_RELAY_C __zend_orig_filename, __zend_orig_lineno 396 # define ZEND_FILE_LINE_ORIG_RELAY_CC , ZEND_FILE_LINE_ORIG_RELAY_C 397 #else 398 # define ZEND_FILE_LINE_D void 399 # define ZEND_FILE_LINE_DC 400 # define ZEND_FILE_LINE_ORIG_D void 401 # define ZEND_FILE_LINE_ORIG_DC 402 # define ZEND_FILE_LINE_RELAY_C 403 # define ZEND_FILE_LINE_RELAY_CC 404 # define ZEND_FILE_LINE_C 405 # define ZEND_FILE_LINE_CC 406 # define ZEND_FILE_LINE_EMPTY_C 407 # define ZEND_FILE_LINE_EMPTY_CC 408 # define ZEND_FILE_LINE_ORIG_RELAY_C 409 # define ZEND_FILE_LINE_ORIG_RELAY_CC 410 #endif /* ZEND_DEBUG */ 411 412 #if ZEND_DEBUG 413 # define Z_DBG(expr) (expr) 414 #else 415 # define Z_DBG(expr) 416 #endif 417 418 #ifdef ZTS 419 # define ZTS_V 1 420 #else 421 # define ZTS_V 0 422 #endif 423 424 #ifndef LONG_MAX 425 # define LONG_MAX 2147483647L 426 #endif 427 428 #ifndef LONG_MIN 429 # define LONG_MIN (- LONG_MAX - 1) 430 #endif 431 432 #define MAX_LENGTH_OF_DOUBLE 32 433 434 #undef MIN 435 #undef MAX 436 #define MAX(a, b) (((a)>(b))?(a):(b)) 437 #define MIN(a, b) (((a)<(b))?(a):(b)) 438 439 #define ZEND_BIT_TEST(bits, bit) \ 440 (((bits)[(bit) / (sizeof((bits)[0])*8)] >> ((bit) & (sizeof((bits)[0])*8-1))) & 1) 441 442 #define ZEND_INFINITY INFINITY 443 444 #define ZEND_NAN NAN 445 446 #if defined(__cplusplus) && __cplusplus >= 201103L 447 extern "C++" { 448 # include <cmath> 449 } 450 # define zend_isnan std::isnan 451 # define zend_isinf std::isinf 452 # define zend_finite std::isfinite 453 #else 454 # include <math.h> 455 # define zend_isnan(a) isnan(a) 456 # define zend_isinf(a) isinf(a) 457 # define zend_finite(a) isfinite(a) 458 #endif 459 460 #define ZEND_STRL(str) (str), (sizeof(str)-1) 461 #define ZEND_STRS(str) (str), (sizeof(str)) 462 #define ZEND_NORMALIZE_BOOL(n) \ 463 ((n) ? (((n)<0) ? -1 : 1) : 0) 464 #define ZEND_TRUTH(x) ((x) ? 1 : 0) 465 #define ZEND_LOG_XOR(a, b) (ZEND_TRUTH(a) ^ ZEND_TRUTH(b)) 466 467 /** 468 * Do a three-way comparison of two integers and returns -1, 0 or 1 469 * depending on whether #a is smaller, equal or larger than #b. 470 */ 471 #define ZEND_THREEWAY_COMPARE(a, b) ((a) == (b) ? 0 : ((a) < (b) ? -1 : 1)) 472 473 #define ZEND_MAX_RESERVED_RESOURCES 6 474 475 /* excpt.h on Digital Unix 4.0 defines function_table */ 476 #undef function_table 477 478 #ifdef ZEND_WIN32 479 #define ZEND_SECURE_ZERO(var, size) RtlSecureZeroMemory((var), (size)) 480 #else 481 #define ZEND_SECURE_ZERO(var, size) explicit_bzero((var), (size)) 482 #endif 483 484 /* This check should only be used on network socket, not file descriptors */ 485 #ifdef ZEND_WIN32 486 #define ZEND_VALID_SOCKET(sock) (INVALID_SOCKET != (sock)) 487 #else 488 #define ZEND_VALID_SOCKET(sock) ((sock) >= 0) 489 #endif 490 491 /* Intrinsics macros start. */ 492 493 /* Memory sanitizer is incompatible with ifunc resolvers. Even if the resolver 494 * is marked as no_sanitize("memory") it will still be instrumented and crash. */ 495 #if __has_feature(memory_sanitizer) || __has_feature(thread_sanitizer) || \ 496 __has_feature(dataflow_sanitizer) 497 # undef HAVE_FUNC_ATTRIBUTE_IFUNC 498 #endif 499 500 /* Only use ifunc resolvers if we have __builtin_cpu_supports() and __builtin_cpu_init(), 501 * otherwise the use of zend_cpu_supports() may not be safe inside ifunc resolvers. */ 502 #if defined(HAVE_FUNC_ATTRIBUTE_IFUNC) && defined(HAVE_FUNC_ATTRIBUTE_TARGET) && \ 503 defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(PHP_HAVE_BUILTIN_CPU_INIT) 504 # define ZEND_INTRIN_HAVE_IFUNC_TARGET 1 505 #endif 506 507 #if (defined(__i386__) || defined(__x86_64__)) 508 # if defined(HAVE_TMMINTRIN_H) 509 # define PHP_HAVE_SSSE3 510 # endif 511 512 # if defined(HAVE_NMMINTRIN_H) 513 # define PHP_HAVE_SSE4_2 514 # endif 515 516 # if defined(HAVE_WMMINTRIN_H) 517 # define PHP_HAVE_PCLMUL 518 # endif 519 520 /* 521 * AVX2 support was added in gcc 4.7, but AVX2 intrinsics don't work in 522 * __attribute__((target("avx2"))) functions until gcc 4.9. 523 */ 524 # if defined(HAVE_IMMINTRIN_H) && \ 525 (defined(__llvm__) || defined(__clang__) || (defined(__GNUC__) && ZEND_GCC_VERSION >= 4009)) 526 # define PHP_HAVE_AVX2 527 # endif 528 #endif 529 530 #ifdef __SSSE3__ 531 /* Instructions compiled directly. */ 532 # define ZEND_INTRIN_SSSE3_NATIVE 1 533 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSSE3)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 534 /* Function resolved by ifunc or MINIT. */ 535 # define ZEND_INTRIN_SSSE3_RESOLVER 1 536 #endif 537 538 /* Do not use for conditional declaration of API functions! */ 539 #if defined(ZEND_INTRIN_SSSE3_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 540 # define ZEND_INTRIN_SSSE3_FUNC_PROTO 1 541 #elif defined(ZEND_INTRIN_SSSE3_RESOLVER) 542 # define ZEND_INTRIN_SSSE3_FUNC_PTR 1 543 #endif 544 545 #ifdef ZEND_INTRIN_SSSE3_RESOLVER 546 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 547 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func) ZEND_API func __attribute__((target("ssse3"))) 548 # else 549 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func) func 550 # endif 551 #else 552 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func) 553 #endif 554 555 #ifdef __SSE4_2__ 556 /* Instructions compiled directly. */ 557 # define ZEND_INTRIN_SSE4_2_NATIVE 1 558 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSE4_2)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 559 /* Function resolved by ifunc or MINIT. */ 560 # define ZEND_INTRIN_SSE4_2_RESOLVER 1 561 #endif 562 563 /* Do not use for conditional declaration of API functions! */ 564 #if defined(ZEND_INTRIN_SSE4_2_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 565 # define ZEND_INTRIN_SSE4_2_FUNC_PROTO 1 566 #elif defined(ZEND_INTRIN_SSE4_2_RESOLVER) 567 # define ZEND_INTRIN_SSE4_2_FUNC_PTR 1 568 #endif 569 570 #ifdef ZEND_INTRIN_SSE4_2_RESOLVER 571 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 572 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) ZEND_API func __attribute__((target("sse4.2"))) 573 # else 574 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) func 575 # endif 576 #else 577 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) 578 #endif 579 580 #ifdef __PCLMUL__ 581 /* Instructions compiled directly. */ 582 # define ZEND_INTRIN_PCLMUL_NATIVE 1 583 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_PCLMUL)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 584 /* Function resolved by ifunc or MINIT. */ 585 # define ZEND_INTRIN_PCLMUL_RESOLVER 1 586 #endif 587 588 /* Do not use for conditional declaration of API functions! */ 589 #if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000)) 590 /* __builtin_cpu_supports has pclmul from gcc9 */ 591 # define ZEND_INTRIN_PCLMUL_FUNC_PROTO 1 592 #elif defined(ZEND_INTRIN_PCLMUL_RESOLVER) 593 # define ZEND_INTRIN_PCLMUL_FUNC_PTR 1 594 #endif 595 596 #ifdef ZEND_INTRIN_PCLMUL_RESOLVER 597 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 598 # define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) ZEND_API func __attribute__((target("pclmul"))) 599 # else 600 # define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) func 601 # endif 602 #else 603 # define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) 604 #endif 605 606 #if defined(ZEND_INTRIN_SSE4_2_NATIVE) && defined(ZEND_INTRIN_PCLMUL_NATIVE) 607 /* Instructions compiled directly. */ 608 # define ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE 1 609 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSE4_2) && defined(PHP_HAVE_PCLMUL)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 610 /* Function resolved by ifunc or MINIT. */ 611 # define ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER 1 612 #endif 613 614 /* Do not use for conditional declaration of API functions! */ 615 #if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000)) 616 /* __builtin_cpu_supports has pclmul from gcc9 */ 617 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1 618 #elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) 619 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR 1 620 #endif 621 622 #ifdef ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER 623 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 624 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) ZEND_API func __attribute__((target("sse4.2,pclmul"))) 625 # else 626 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) func 627 # endif 628 #else 629 # define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) 630 #endif 631 632 #ifdef __AVX2__ 633 # define ZEND_INTRIN_AVX2_NATIVE 1 634 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_AVX2)) || (defined(ZEND_WIN32) && (!defined(_M_ARM64))) 635 # define ZEND_INTRIN_AVX2_RESOLVER 1 636 #endif 637 638 /* Do not use for conditional declaration of API functions! */ 639 #if defined(ZEND_INTRIN_AVX2_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) 640 # define ZEND_INTRIN_AVX2_FUNC_PROTO 1 641 #elif defined(ZEND_INTRIN_AVX2_RESOLVER) 642 # define ZEND_INTRIN_AVX2_FUNC_PTR 1 643 #endif 644 645 #ifdef ZEND_INTRIN_AVX2_RESOLVER 646 # ifdef HAVE_FUNC_ATTRIBUTE_TARGET 647 # define ZEND_INTRIN_AVX2_FUNC_DECL(func) ZEND_API func __attribute__((target("avx2"))) 648 # else 649 # define ZEND_INTRIN_AVX2_FUNC_DECL(func) func 650 # endif 651 #else 652 # define ZEND_INTRIN_AVX2_FUNC_DECL(func) 653 #endif 654 655 /* Intrinsics macros end. */ 656 657 #ifdef ZEND_WIN32 658 # define ZEND_SET_ALIGNED(alignment, decl) __declspec(align(alignment)) decl 659 #elif defined(HAVE_ATTRIBUTE_ALIGNED) 660 # define ZEND_SET_ALIGNED(alignment, decl) decl __attribute__ ((__aligned__ (alignment))) 661 #else 662 # define ZEND_SET_ALIGNED(alignment, decl) decl 663 #endif 664 665 #define ZEND_SLIDE_TO_ALIGNED(alignment, ptr) (((zend_uintptr_t)(ptr) + ((alignment)-1)) & ~((alignment)-1)) 666 #define ZEND_SLIDE_TO_ALIGNED16(ptr) ZEND_SLIDE_TO_ALIGNED(Z_UL(16), ptr) 667 668 #ifdef ZEND_WIN32 669 # define _ZEND_EXPAND_VA(a) a 670 # define ZEND_EXPAND_VA(code) _ZEND_EXPAND_VA(code) 671 #else 672 # define ZEND_EXPAND_VA(code) code 673 #endif 674 675 /* On CPU with few registers, it's cheaper to reload value then use spill slot */ 676 #if defined(__i386__) || (defined(_WIN32) && !defined(_WIN64)) 677 # define ZEND_PREFER_RELOAD 678 #endif 679 680 #if defined(ZEND_WIN32) && defined(_DEBUG) 681 # define ZEND_IGNORE_LEAKS_BEGIN() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) 682 # define ZEND_IGNORE_LEAKS_END() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF) 683 #else 684 # define ZEND_IGNORE_LEAKS_BEGIN() 685 # define ZEND_IGNORE_LEAKS_END() 686 #endif 687 688 /* MSVC yields C4090 when a (const T **) is passed to a (void *); ZEND_VOIDP works around that */ 689 #ifdef _MSC_VER 690 # define ZEND_VOIDP(ptr) ((void *) ptr) 691 #else 692 # define ZEND_VOIDP(ptr) (ptr) 693 #endif 694 695 #if __has_attribute(__indirect_return__) 696 # define ZEND_INDIRECT_RETURN __attribute__((__indirect_return__)) 697 #else 698 # define ZEND_INDIRECT_RETURN 699 #endif 700 701 #endif /* ZEND_PORTABILITY_H */ 702