From 48990a5846229129f4d2277de0865b4c03a02a09 Mon Sep 17 00:00:00 2001 From: MARiA so cute <33935209+NathanFreeman@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:41:18 +0800 Subject: [PATCH 1/2] sync master branch code --- .github/workflows/ext.yml | 110 ++-- .github/workflows/framework.yml | 7 +- config.m4 | 56 +- ext-src/php_swoole_call_stack.h | 25 +- ext-src/swoole_http_request.cc | 34 +- ext-src/swoole_odbc.cc | 4 +- tests/swoole_client_sync/eof.phpt | 2 +- tests/swoole_client_sync/eof_close.phpt | 2 +- tests/swoole_curl/multi/bug4393.phpt | 2 +- tests/swoole_function/substr_unserialize.phpt | 4 +- tests/swoole_pdo_oracle/bug44301.phpt | 3 +- tests/swoole_pdo_oracle/bug_33707.phpt | 1 + .../pdo_oci_attr_autocommit_2.phpt | 3 +- thirdparty/multipart_parser.c | 4 +- thirdparty/php/standard/proc_open.cc | 4 +- thirdparty/php/streams/plain_wrapper.c | 2 +- thirdparty/php83/Zend/zend_call_stack.cc | 539 ------------------ thirdparty/php83/Zend/zend_call_stack.h | 96 ---- 18 files changed, 143 insertions(+), 755 deletions(-) delete mode 100644 thirdparty/php83/Zend/zend_call_stack.cc delete mode 100644 thirdparty/php83/Zend/zend_call_stack.h diff --git a/.github/workflows/ext.yml b/.github/workflows/ext.yml index 6264c176cfa..f79bc4247e5 100644 --- a/.github/workflows/ext.yml +++ b/.github/workflows/ext.yml @@ -2,70 +2,72 @@ name: ext-swoole on: [push, pull_request] +env: + CPPFLAGS: "-I/opt/homebrew/opt/pcre2/include/" + jobs: build-ubuntu-latest: if: "!contains(github.event.head_commit.message, '[test]')" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: install-deps - run: sudo apt update -y && sudo apt install -y libcurl4-openssl-dev php-curl libc-ares-dev - - name: phpize - run: phpize - - name: build1 - run: ./configure && - make clean && make -j$(nproc) - - name: build2 - run: ./configure --enable-sockets && - make clean && make -j$(nproc) - - name: build3 - run: ./configure --enable-sockets --enable-mysqlnd && - make clean && make -j$(nproc) - - name: build5 - run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl && - make clean && make -j$(nproc) - - name: build6 - run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-debug-log && - make clean && make -j$(nproc) - - name: build7 - run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-debug-log && - make clean && make -j$(nproc) - - name: build8 - run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log && - make clean && make -j$(nproc) - - name: build with thread context - run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log --enable-thread-context && - make clean && make -j$(nproc) + - uses: actions/checkout@v4 + - name: install-deps + run: sudo apt update -y && sudo apt install -y libcurl4-openssl-dev php-curl libc-ares-dev + - name: phpize + run: phpize + - name: build1 + run: ./configure && + make clean && make -j$(nproc) + - name: build2 + run: ./configure --enable-sockets && + make clean && make -j$(nproc) + - name: build3 + run: ./configure --enable-sockets --enable-mysqlnd && + make clean && make -j$(nproc) + - name: build5 + run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl && + make clean && make -j$(nproc) + - name: build6 + run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-debug-log && + make clean && make -j$(nproc) + - name: build7 + run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-debug-log && + make clean && make -j$(nproc) + - name: build8 + run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log && + make clean && make -j$(nproc) + - name: build with thread context + run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log --enable-thread-context && + make clean && make -j$(nproc) build-macos-latest: if: "!contains(github.event.head_commit.message, '[test]')" runs-on: macos-latest steps: - - name: install dependencies - run: brew install openssl && brew link openssl && brew install curl && brew link curl && brew install c-ares && brew link c-ares - - uses: actions/checkout@v4 - - name: phpize - run: phpize - - name: build1 - run: ./configure && make clean && make -j$(sysctl -n hw.ncpu) - - name: build2 - run: ./configure --enable-sockets && - make clean && make -j$(sysctl -n hw.ncpu) - - name: build3 - run: ./configure --enable-sockets --enable-mysqlnd && - make clean && make -j$(sysctl -n hw.ncpu) - - name: build5 - run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl - --with-openssl-dir=/usr/local/opt/openssl@1.1 && - make clean && make -j$(sysctl -n hw.ncpu) - - name: build6 - run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-swoole-curl --enable-debug-log - --with-openssl-dir=/usr/local/opt/openssl@1.1 && - make clean && make -j$(sysctl -n hw.ncpu) - - name: build7 - run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-swoole-curl --enable-debug-log --enable-cares - --with-openssl-dir=/usr/local/opt/openssl@1.1 && - make clean && make -j$(sysctl -n hw.ncpu) + - name: install dependencies + run: brew reinstall php + - uses: actions/checkout@v4 + - name: phpize + run: phpize + - name: build1 + run: ./configure CPPFLAGS="${CPPFLAGS}" && make clean && make -j$(sysctl -n hw.ncpu) + - name: build2 + run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets && + make clean && make -j$(sysctl -n hw.ncpu) + - name: build3 + run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd && + make clean && make -j$(sysctl -n hw.ncpu) + - name: build5 + run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd --enable-openssl && + make clean && make -j$(sysctl -n hw.ncpu) + - name: build6 + run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd --enable-openssl + --enable-swoole-curl --enable-debug-log && + make clean && make -j$(sysctl -n hw.ncpu) + - name: build7 + run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd --enable-openssl --enable-swoole-curl + --enable-debug-log --enable-cares && + make clean && make -j$(sysctl -n hw.ncpu) build-alpine-latest: if: "!contains(github.event.head_commit.message, '[test]')" diff --git a/.github/workflows/framework.yml b/.github/workflows/framework.yml index 1a591640c4e..9c1ee641498 100644 --- a/.github/workflows/framework.yml +++ b/.github/workflows/framework.yml @@ -4,6 +4,9 @@ on: push: pull_request: +env: + CPPFLAGS: "-I/opt/homebrew/opt/pcre2/include/" + jobs: linux: runs-on: ubuntu-latest @@ -120,10 +123,8 @@ jobs: - name: Build Swoole run: | - brew install openssl && brew link openssl - brew install c-ares && brew link c-ares phpize - ./configure --enable-openssl --with-openssl-dir=/usr/local/opt/openssl@1.1 --enable-mysqlnd --enable-swoole-curl --enable-cares + ./configure CPPFLAGS="${CPPFLAGS}" --enable-openssl --enable-mysqlnd --enable-swoole-curl --enable-cares make -j$(sysctl -n hw.ncpu) sudo make install php --ri swoole diff --git a/config.m4 b/config.m4 index 9458be30016..8e3feb89969 100644 --- a/config.m4 +++ b/config.m4 @@ -362,7 +362,6 @@ if test "$PHP_SWOOLE" != "no"; then AC_CHECK_LIB(pthread, pthread_mutexattr_setrobust, AC_DEFINE(HAVE_PTHREAD_MUTEXATTR_SETROBUST, 1, [have pthread_mutexattr_setrobust])) AC_CHECK_LIB(pthread, pthread_mutex_consistent, AC_DEFINE(HAVE_PTHREAD_MUTEX_CONSISTENT, 1, [have pthread_mutex_consistent])) AC_CHECK_LIB(pcre, pcre_compile, AC_DEFINE(HAVE_PCRE, 1, [have pcre])) - AC_CHECK_LIB(cares, ares_gethostbyname, AC_DEFINE(HAVE_CARES, 1, [have c-ares])) if test "$PHP_SWOOLE_DEV" = "yes"; then AX_CHECK_COMPILE_FLAG(-Wbool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wbool-conversion") @@ -400,6 +399,9 @@ if test "$PHP_SWOOLE" != "no"; then fi if test "$PHP_SWOOLE_CURL" = "yes"; then + PKG_CHECK_MODULES([CURL], [libcurl >= 7.56.0]) + PHP_EVAL_LIBLINE($CURL_LIBS, SWOOLE_SHARED_LIBADD) + PHP_EVAL_INCLINE($CURL_CFLAGS) AC_DEFINE(SW_USE_CURL, 1, [do we enable cURL native client]) fi @@ -837,15 +839,24 @@ EOF PHP_ADD_LIBRARY(z, 1, SWOOLE_SHARED_LIBADD) ]) - if test "$PHP_BROTLI" = "yes"; then - AC_CHECK_LIB(brotlienc, BrotliEncoderCreateInstance, [ - AC_CHECK_LIB(brotlidec, BrotliDecoderCreateInstance, [ - AC_DEFINE(SW_HAVE_COMPRESSION, 1, [have compression]) - AC_DEFINE(SW_HAVE_BROTLI, 1, [have brotli encoder]) - PHP_ADD_LIBRARY(brotlienc, 1, SWOOLE_SHARED_LIBADD) - PHP_ADD_LIBRARY(brotlidec, 1, SWOOLE_SHARED_LIBADD) - ]) - ]) + if test "$PHP_BROTLI" != "no" || test "$PHP_BROTLI_DIR" != "no"; then + if test "$PHP_BROTLI_DIR" != "no"; then + PHP_ADD_INCLUDE("${PHP_BROTLI_DIR}/include") + PHP_ADD_LIBRARY_WITH_PATH(brotli, "${PHP_BROTLI_DIR}/${PHP_LIBDIR}") + PHP_ADD_LIBRARY_WITH_PATH(brotlienc, "${PHP_BROTLI_DIR}/${PHP_LIBDIR}") + PHP_ADD_LIBRARY_WITH_PATH(brotlidec, "${PHP_BROTLI_DIR}/${PHP_LIBDIR}") + else + PKG_CHECK_MODULES([BROTLIENC], [libbrotlienc]) + PHP_EVAL_LIBLINE($BROTLIENC_LIBS, SWOOLE_SHARED_LIBADD) + PHP_EVAL_INCLINE($BROTLIENC_CFLAGS) + + PKG_CHECK_MODULES([BROTLIDEC], [libbrotlidec]) + PHP_EVAL_LIBLINE($BROTLIDEC_LIBS, SWOOLE_SHARED_LIBADD) + PHP_EVAL_INCLINE($BROTLIDEC_CFLAGS) + fi + + AC_DEFINE(SW_HAVE_COMPRESSION, 1, [have compression]) + AC_DEFINE(SW_HAVE_BROTLI, 1, [have brotli encoder]) fi PHP_ADD_LIBRARY(pthread) @@ -894,8 +905,11 @@ EOF fi if test "$PHP_CARES" = "yes"; then + PKG_CHECK_MODULES([CARES], [libcares]) + PHP_EVAL_LIBLINE($CARES_LIBS, SWOOLE_SHARED_LIBADD) + PHP_EVAL_INCLINE($CARES_CFLAGS) AC_DEFINE(SW_USE_CARES, 1, [do we enable c-ares support]) - PHP_ADD_LIBRARY(cares, 1, SWOOLE_SHARED_LIBADD) + AC_DEFINE(HAVE_CARES, 1, [have c-ares]) fi AC_SWOOLE_CPU_AFFINITY @@ -944,13 +958,23 @@ EOF fi if test "$PHP_OPENSSL" != "no" || test "$PHP_OPENSSL_DIR" != "no"; then - if test "$PHP_OPENSSL_DIR" != "no"; then + if test "$PHP_OPENSSL_DIR" != "no"; then PHP_ADD_INCLUDE("${PHP_OPENSSL_DIR}/include") PHP_ADD_LIBRARY_WITH_PATH(ssl, "${PHP_OPENSSL_DIR}/${PHP_LIBDIR}") + + PHP_ADD_LIBRARY(ssl, 1, SWOOLE_SHARED_LIBADD) + PHP_ADD_LIBRARY(crypto, 1, SWOOLE_SHARED_LIBADD) + else + PKG_CHECK_MODULES([SSL], [libssl]) + PHP_EVAL_LIBLINE($SSL_LIBS, SWOOLE_SHARED_LIBADD) + PHP_EVAL_INCLINE($SSL_CFLAGS) + + PKG_CHECK_MODULES([CRYPTO], [libcrypto]) + PHP_EVAL_LIBLINE($CRYPTO_LIBS, SWOOLE_SHARED_LIBADD) + PHP_EVAL_INCLINE($CRYPTO_CFLAGS) fi + AC_DEFINE(SW_USE_OPENSSL, 1, [enable openssl support]) - PHP_ADD_LIBRARY(ssl, 1, SWOOLE_SHARED_LIBADD) - PHP_ADD_LIBRARY(crypto, 1, SWOOLE_SHARED_LIBADD) fi if test "$PHP_BROTLI_DIR" != "no"; then @@ -1006,8 +1030,7 @@ EOF thirdparty/php/sockets/conversions.cc \ thirdparty/php/sockets/sockaddr_conv.cc \ thirdparty/php/standard/var_decoder.cc \ - thirdparty/php/standard/proc_open.cc \ - thirdparty/php83/Zend/zend_call_stack.cc" + thirdparty/php/standard/proc_open.cc" swoole_source_file="$swoole_source_file \ thirdparty/swoole_http_parser.c \ @@ -1232,5 +1255,6 @@ EOF if test "$PHP_SWOOLE_SQLITE" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php80/pdo_sqlite) PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php81/pdo_sqlite) + PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php83/pdo_sqlite) fi fi diff --git a/ext-src/php_swoole_call_stack.h b/ext-src/php_swoole_call_stack.h index 009bc90cef6..8c89f8305bc 100644 --- a/ext-src/php_swoole_call_stack.h +++ b/ext-src/php_swoole_call_stack.h @@ -14,25 +14,16 @@ +----------------------------------------------------------------------+ */ -#pragma once - #include "php_swoole.h" #ifdef ZEND_CHECK_STACK_LIMIT - #include "thirdparty/php83/Zend/zend_call_stack.h" -#endif - -#ifdef ZEND_CHECK_STACK_LIMIT - #define HOOK_PHP_CALL_STACK(exp) \ - zend_call_stack __stack; \ - zend_call_stack_get(&__stack); \ - auto __stack_base = EG(stack_base); \ - auto __stack_limit = EG(stack_limit); \ - EG(stack_base) = __stack.base; \ - EG(stack_limit) = zend_call_stack_limit(__stack.base, __stack.max_size, EG(reserved_stack_size)); \ - exp \ - EG(stack_base) = __stack_base; \ - EG(stack_limit) = __stack_limit; +#define HOOK_PHP_CALL_STACK(callback) \ + auto __stack_limit = EG(stack_limit); \ + auto __stack_base = EG(stack_base); \ + EG(stack_base) = (void *) 0; \ + EG(stack_limit) = (void *) 0; \ + callback EG(stack_limit) = __stack_limit; \ + EG(stack_base) = __stack_base; #else - #define HOOK_PHP_CALL_STACK(exp) exp +#define HOOK_PHP_CALL_STACK(callback) callback #endif diff --git a/ext-src/swoole_http_request.cc b/ext-src/swoole_http_request.cc index 565395d5976..b9b6e6f6581 100644 --- a/ext-src/swoole_http_request.cc +++ b/ext-src/swoole_http_request.cc @@ -342,16 +342,15 @@ bool swoole_http_token_list_contains_value(const char *at, size_t length, const static int http_request_on_header_value(swoole_http_parser *parser, const char *at, size_t length) { HttpContext *ctx = (HttpContext *) parser->data; zval *zheader = ctx->request.zheader; + char *header_name = ctx->current_header_name; size_t header_len = ctx->current_header_name_len; - char header_name[header_len]; - zend_str_tolower_copy(header_name, ctx->current_header_name, header_len); - if (ctx->parse_cookie && SW_STREQ(header_name, header_len, "cookie")) { + if (ctx->parse_cookie && SW_STRCASEEQ(header_name, header_len, "cookie")) { zval *zcookie = swoole_http_init_and_read_property( swoole_http_request_ce, ctx->request.zobject, &ctx->request.zcookie, SW_ZSTR_KNOWN(SW_ZEND_STR_COOKIE)); swoole_http_parse_cookie(zcookie, at, length); return 0; - } else if (SW_STREQ(header_name, header_len, "upgrade") && + } else if (SW_STRCASEEQ(header_name, header_len, "upgrade") && swoole_http_token_list_contains_value(at, length, "websocket")) { ctx->websocket = 1; if (ctx->co_socket) { @@ -372,7 +371,7 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char * } } else if ((parser->method == PHP_HTTP_POST || parser->method == PHP_HTTP_PUT || parser->method == PHP_HTTP_DELETE || parser->method == PHP_HTTP_PATCH) && - SW_STREQ(header_name, header_len, "content-type")) { + SW_STRCASEEQ(header_name, header_len, "content-type")) { if (SW_STR_ISTARTS_WITH(at, length, "application/x-www-form-urlencoded")) { ctx->request.post_form_urlencoded = 1; } else if (SW_STR_ISTARTS_WITH(at, length, "multipart/form-data")) { @@ -387,11 +386,11 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char * } } #ifdef SW_HAVE_COMPRESSION - else if (ctx->enable_compression && SW_STREQ(header_name, header_len, "accept-encoding")) { + else if (ctx->enable_compression && SW_STRCASEEQ(header_name, header_len, "accept-encoding")) { ctx->set_compression_method(at, length); } #endif - else if (SW_STREQ(header_name, header_len, "transfer-encoding") && SW_STR_ISTARTS_WITH(at, length, "chunked")) { + else if (SW_STRCASEEQ(header_name, header_len, "transfer-encoding") && SW_STR_ISTARTS_WITH(at, length, "chunked")) { ctx->recv_chunked = 1; } @@ -402,24 +401,27 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char * /** * some common request header key */ - if (SW_STREQ(header_name, header_len, "host")) { + if (SW_STRCASEEQ(header_name, header_len, "host")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_HOST), &tmp); - } else if (SW_STREQ(header_name, header_len, "user-agent")) { + } else if (SW_STRCASEEQ(header_name, header_len, "user-agent")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_USER_AGENT), &tmp); - } else if (SW_STREQ(header_name, header_len, "accept")) { + } else if (SW_STRCASEEQ(header_name, header_len, "accept")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_ACCEPT), &tmp); - } else if (SW_STREQ(header_name, header_len, "content-type")) { + } else if (SW_STRCASEEQ(header_name, header_len, "content-type")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_CONTENT_TYPE), &tmp); - } else if (SW_STREQ(header_name, header_len, "content-length")) { + } else if (SW_STRCASEEQ(header_name, header_len, "content-length")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_CONTENT_LENGTH), &tmp); - } else if (SW_STREQ(header_name, header_len, "authorization")) { + } else if (SW_STRCASEEQ(header_name, header_len, "authorization")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_AUTHORIZATION), &tmp); - } else if (SW_STREQ(header_name, header_len, "connection")) { + } else if (SW_STRCASEEQ(header_name, header_len, "connection")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_CONNECTION), &tmp); - } else if (SW_STREQ(header_name, header_len, "accept-encoding")) { + } else if (SW_STRCASEEQ(header_name, header_len, "accept-encoding")) { zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_ACCEPT_ENCODING), &tmp); } else { - zend_hash_str_update(Z_ARR_P(zheader), header_name, header_len, &tmp); + char *new_header_name = estrndup(header_name, header_len); + zend_str_tolower_copy(new_header_name, header_name, header_len); + zend_hash_str_update(Z_ARR_P(zheader), new_header_name, header_len, &tmp); + efree(new_header_name); } return 0; diff --git a/ext-src/swoole_odbc.cc b/ext-src/swoole_odbc.cc index cdeacad023a..42a82a69b50 100644 --- a/ext-src/swoole_odbc.cc +++ b/ext-src/swoole_odbc.cc @@ -205,7 +205,7 @@ int php_swoole_odbc_minit(int module_id) { if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("ODBC_ATTR_USE_CURSOR_LIBRARY")) == nullptr) { #ifdef SQL_ATTR_CONNECTION_POOLING - char *pooling_val = NULL; + const char *pooling_val = NULL; #endif #ifdef SQL_ATTR_CONNECTION_POOLING @@ -214,7 +214,7 @@ int php_swoole_odbc_minit(int module_id) { * request without affecting others, which goes against our isolated request * policy. So, we use cfg_get_string here to check it this once. * */ - if (FAILURE == cfg_get_string("pdo_odbc.connection_pooling", &pooling_val) || pooling_val == NULL) { + if (FAILURE == cfg_get_string("pdo_odbc.connection_pooling", (char **) &pooling_val) || pooling_val == NULL) { pooling_val = "strict"; } if (strcasecmp(pooling_val, "strict") == 0 || strcmp(pooling_val, "1") == 0) { diff --git a/tests/swoole_client_sync/eof.phpt b/tests/swoole_client_sync/eof.phpt index b022cf1ca2e..7da34170476 100644 --- a/tests/swoole_client_sync/eof.phpt +++ b/tests/swoole_client_sync/eof.phpt @@ -34,7 +34,7 @@ $pm->parentFunc = function ($pid) use ($port) { for ($i = 0; $i < 1000; $i++) { $pkg = $client->recv(); Assert::assert($pkg != false); - $_pkg = unserialize($pkg); + $_pkg = swoole_substr_unserialize($pkg, 0, strlen($pkg) - 4); Assert::assert(is_array($_pkg)); Assert::same($_pkg['i'], $i); Assert::assert(strlen($_pkg['data']) > 8192 and strlen($_pkg['data']) <= 256 * 1024); diff --git a/tests/swoole_client_sync/eof_close.phpt b/tests/swoole_client_sync/eof_close.phpt index 6a71216c3d0..484dc19964c 100644 --- a/tests/swoole_client_sync/eof_close.phpt +++ b/tests/swoole_client_sync/eof_close.phpt @@ -24,7 +24,7 @@ $pm->parentFunc = function ($pid) use ($port, $pkg, $pm) { $client->send("recv\r\n\r\n"); $recvPkg = $client->recv(); Assert::assert($recvPkg != false); - $_pkg = unserialize($recvPkg); + $_pkg = swoole_substr_unserialize($recvPkg, 0, strlen($recvPkg) - 4); Assert::assert(is_array($_pkg)); Assert::eq($_pkg['data'], $pkg); $recvPkg = $client->recv(); diff --git a/tests/swoole_curl/multi/bug4393.phpt b/tests/swoole_curl/multi/bug4393.phpt index aa09b5755ad..6ea973d2e47 100644 --- a/tests/swoole_curl/multi/bug4393.phpt +++ b/tests/swoole_curl/multi/bug4393.phpt @@ -51,7 +51,7 @@ run(function () { while ($n--) { $s = microtime(true); $test(); - Assert::lessThan(microtime(true) - $s, 2.0); + Assert::lessThan(microtime(true) - $s, 3.0); } echo 'Done' . PHP_EOL; diff --git a/tests/swoole_function/substr_unserialize.phpt b/tests/swoole_function/substr_unserialize.phpt index 7ee9d98483b..efdd0324776 100644 --- a/tests/swoole_function/substr_unserialize.phpt +++ b/tests/swoole_function/substr_unserialize.phpt @@ -12,11 +12,11 @@ $a['int'] = rand(1, 999999); $a['list'] = ['a,', 'b', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx']; $val = serialize($a); -$str = pack('N', strlen($val)).$val."\r\n"; +$str = pack('N', strlen($val)) . $val . "\r\n"; $l = strlen($str) - 6; Assert::eq(swoole_substr_unserialize($str, 4, $l), $a); -Assert::eq(swoole_substr_unserialize($str, 4), $a); +Assert::eq(@swoole_substr_unserialize($str, 4), $a); Assert::eq(@swoole_substr_unserialize($str, 0), false); Assert::eq(@swoole_substr_unserialize($str, 6), false); Assert::eq(@swoole_substr_unserialize($str, 4, $l - 4), false); diff --git a/tests/swoole_pdo_oracle/bug44301.phpt b/tests/swoole_pdo_oracle/bug44301.phpt index f0d66cd2657..74a0c637fe1 100644 --- a/tests/swoole_pdo_oracle/bug44301.phpt +++ b/tests/swoole_pdo_oracle/bug44301.phpt @@ -29,4 +29,5 @@ run(function() { ?> --EXPECTF-- SQLSTATE[HY000]: General error: 942 OCIStmtExecute: ORA-00942: table or view does not exist - (%s%epdo_oci%eoci_statement.c:%d) +Help: %s + (%s:%d) diff --git a/tests/swoole_pdo_oracle/bug_33707.phpt b/tests/swoole_pdo_oracle/bug_33707.phpt index a689fe58302..18bfb9a02f4 100644 --- a/tests/swoole_pdo_oracle/bug_33707.phpt +++ b/tests/swoole_pdo_oracle/bug_33707.phpt @@ -31,5 +31,6 @@ array(3) { int(942) [2]=> string(%d) "OCIStmtExecute: ORA-00942: table or view does not exist +Help: %s (%s:%d)" } diff --git a/tests/swoole_pdo_oracle/pdo_oci_attr_autocommit_2.phpt b/tests/swoole_pdo_oracle/pdo_oci_attr_autocommit_2.phpt index 142e051c2f0..4af96053e69 100644 --- a/tests/swoole_pdo_oracle/pdo_oci_attr_autocommit_2.phpt +++ b/tests/swoole_pdo_oracle/pdo_oci_attr_autocommit_2.phpt @@ -110,7 +110,8 @@ Test 1 Check beginTransaction insertion Test 2 Cause an exception and test beginTransaction rollback Caught expected exception at line %d SQLSTATE[HY000]: General error: 12899 OCIStmtExecute: ORA-12899: %s -%s +Help: %s + (%s:%d) Test 3 Setting ATTR_AUTOCOMMIT to true will commit and end the transaction PDO::ATTR_AUTOCOMMIT: bool(true) Caught expected exception at line %d diff --git a/thirdparty/multipart_parser.c b/thirdparty/multipart_parser.c index 8061de10699..96539faf816 100644 --- a/thirdparty/multipart_parser.c +++ b/thirdparty/multipart_parser.c @@ -127,9 +127,9 @@ int multipart_parser_error_msg(multipart_parser *p, char *buf, size_t len) { case MPPE_PAUSED: return snprintf(buf, len, "parser paused"); case MPPE_UNKNOWN: + return snprintf(buf, len, "parser unknown"); default: - abort(); - return 0; + return snprintf(buf, len, "parser abort"); case MPPE_BOUNDARY_END_NO_CRLF: ret = snprintf(buf, len, "no CRLF at first boundary end: "); break; diff --git a/thirdparty/php/standard/proc_open.cc b/thirdparty/php/standard/proc_open.cc index b3e50ec9d89..4363be6b0e2 100644 --- a/thirdparty/php/standard/proc_open.cc +++ b/thirdparty/php/standard/proc_open.cc @@ -512,7 +512,7 @@ static descriptorspec_item *alloc_descriptor_array(HashTable *descriptorspec) { return (descriptorspec_item *) ecalloc(sizeof(descriptorspec_item), ndescriptors); } -static zend_string *get_string_parameter(zval *array, int index, char *param_name) { +static zend_string *get_string_parameter(zval *array, int index, const char *param_name) { zval *array_item; if ((array_item = zend_hash_index_find(Z_ARRVAL_P(array), index)) == NULL) { zend_value_error("Missing %s", param_name); @@ -1193,7 +1193,7 @@ PHP_FUNCTION(swoole_proc_open) { close_descriptor(descriptors[i].childend); if (descriptors[i].type == DESCRIPTOR_TYPE_PIPE) { - char *mode_string = NULL; + const char *mode_string = NULL; switch (descriptors[i].mode_flags) { #ifdef PHP_WIN32 diff --git a/thirdparty/php/streams/plain_wrapper.c b/thirdparty/php/streams/plain_wrapper.c index c4281f10687..c283f85b930 100644 --- a/thirdparty/php/streams/plain_wrapper.c +++ b/thirdparty/php/streams/plain_wrapper.c @@ -725,7 +725,7 @@ static int sw_php_stdiop_set_option(php_stream *stream, int option, int value, v if (do_fstat(data, 1) != 0) { return PHP_STREAM_OPTION_RETURN_ERR; } - if (range->offset > data->sb.st_size) { + if (range->offset > (size_t) data->sb.st_size) { range->offset = data->sb.st_size; } if (range->length == 0 || diff --git a/thirdparty/php83/Zend/zend_call_stack.cc b/thirdparty/php83/Zend/zend_call_stack.cc deleted file mode 100644 index d6726196580..00000000000 --- a/thirdparty/php83/Zend/zend_call_stack.cc +++ /dev/null @@ -1,539 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.00 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.zend.com/license/2_00.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Arnaud Le Blanc | - +----------------------------------------------------------------------+ -*/ - -/* Inspired from Chromium's stack_util.cc */ - -/* git bash: 6602ddead5c81fb67ebf2b21c32b58aa1de67699 */ - -#include "php_swoole.h" - -#if PHP_VERSION_ID >= 80300 -#include "zend.h" -#include "zend_globals.h" -#include "zend_portability.h" -#include "zend_call_stack.h" -#include -#ifdef ZEND_WIN32 -# include -# include -#else /* ZEND_WIN32 */ -# include -# ifdef HAVE_UNISTD_H -# include -# endif -# ifdef HAVE_SYS_TYPES_H -# include -# endif -#endif /* ZEND_WIN32 */ -#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) -# include -#endif -#ifdef __FreeBSD__ -# include -# include -# include -# include -#endif -#ifdef __OpenBSD__ -typedef int boolean_t; -# include -# include -# include -# include -#endif -#ifdef __linux__ -#include -#endif - -#ifdef ZEND_CHECK_STACK_LIMIT - -/* Called once per process or thread */ -ZEND_API void zend_call_stack_init(void) { - if (!zend_call_stack_get(&EG(call_stack))) { - EG(call_stack) = (zend_call_stack){0}; - } - - switch (EG(max_allowed_stack_size)) { - case ZEND_MAX_ALLOWED_STACK_SIZE_DETECT: { - void *base = EG(call_stack).base; - size_t size = EG(call_stack).max_size; - if (UNEXPECTED(base == (void*)0)) { - base = zend_call_stack_position(); - size = zend_call_stack_default_size(); - /* base is not the actual stack base */ - size -= 32 * 1024; - } - EG(stack_base) = base; - EG(stack_limit) = zend_call_stack_limit(base, size, EG(reserved_stack_size)); - break; - } - case ZEND_MAX_ALLOWED_STACK_SIZE_UNCHECKED: { - EG(stack_base) = (void*)0; - EG(stack_limit) = (void*)0; - break; - } - default: { - ZEND_ASSERT(EG(max_allowed_stack_size) > 0); - void *base = EG(call_stack).base; - if (UNEXPECTED(base == (void*)0)) { - base = zend_call_stack_position(); - } - EG(stack_base) = base; - EG(stack_limit) = zend_call_stack_limit(base, EG(max_allowed_stack_size), EG(reserved_stack_size)); - break; - } - } -} - -#ifdef __linux__ -static bool zend_call_stack_is_main_thread(void) { -# ifdef HAVE_GETTID - return getpid() == gettid(); -# else - return getpid() == syscall(SYS_gettid); -# endif -} - -# if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) -static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) -{ - pthread_attr_t attr; - int error; - void *addr; - size_t max_size; - - /* pthread_getattr_np() will return bogus values for the main thread with - * musl or with some old glibc versions */ - ZEND_ASSERT(!zend_call_stack_is_main_thread()); - - error = pthread_getattr_np(pthread_self(), &attr); - if (error) { - return false; - } - - error = pthread_attr_getstack(&attr, &addr, &max_size); - if (error) { - return false; - } - -# if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)) - { - size_t guard_size; - /* In glibc prior to 2.8, addr and size include the guard pages */ - error = pthread_attr_getguardsize(&attr, &guard_size); - if (error) { - return false; - } - - addr = (int8_t*)addr + guard_size; - max_size -= guard_size; - } -# endif /* glibc < 2.8 */ - - stack->base = (int8_t*)addr + max_size; - stack->max_size = max_size; - - return true; -} -# else /* defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ -static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) -{ - return false; -} -# endif /* defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ - -static bool zend_call_stack_get_linux_proc_maps(zend_call_stack *stack) -{ - FILE *f; - char buffer[4096]; - uintptr_t addr_on_stack = (uintptr_t)&buffer; - uintptr_t start, end, prev_end = 0; - size_t max_size; - bool found = false; - struct rlimit rlim; - int error; - - /* This method is relevant only for the main thread */ - ZEND_ASSERT(zend_call_stack_is_main_thread()); - - /* Scan the process memory mappings to find the one containing the stack. - * - * The end of the stack mapping is the base of the stack. The start is - * adjusted by the kernel as the stack grows. The maximum stack size is - * determined by RLIMIT_STACK and the previous mapping. - * - * - * ^ Higher addresses ^ - * : : - * : : - * Mapping end --> |-------------------| <-- Stack base (stack start) - * | | ^ - * | Stack Mapping | | Stack size - * | | v - * Mapping start --> |-------------------| <-- Current stack end - * (adjusted : : - * downwards as the . . - * stack grows) : : - * |-------------------| - * | Some Mapping | The previous mapping may prevent - * |-------------------| stack growth - * : : - * : : - * v Lower addresses v - */ - - f = fopen("/proc/self/maps", "r"); - if (!f) { - return false; - } - - while (fgets(buffer, sizeof(buffer), f) && sscanf(buffer, "%" SCNxPTR "-%" SCNxPTR, &start, &end) == 2) { - if (start <= addr_on_stack && end >= addr_on_stack) { - found = true; - break; - } - prev_end = end; - } - - fclose(f); - - if (!found) { - return false; - } - - error = getrlimit(RLIMIT_STACK, &rlim); - if (error || rlim.rlim_cur == RLIM_INFINITY) { - return false; - } - - max_size = rlim.rlim_cur; - - /* Previous mapping may prevent the stack from growing */ - if (end - max_size < prev_end) { - max_size = prev_end - end; - } - - stack->base = (void*)end; - stack->max_size = max_size; - - return true; -} - -static bool zend_call_stack_get_linux(zend_call_stack *stack) -{ - if (zend_call_stack_is_main_thread()) { - return zend_call_stack_get_linux_proc_maps(stack); - } - - return zend_call_stack_get_linux_pthread(stack); -} -#else /* __linux__ */ -static bool zend_call_stack_get_linux(zend_call_stack *stack) -{ - return false; -} -#endif /* __linux__ */ - -#ifdef __FreeBSD__ -static bool zend_call_stack_is_main_thread(void) -{ - int is_main = pthread_main_np(); - return is_main == -1 || is_main == 1; -} - -# if defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) -static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) -{ - pthread_attr_t attr; - int error; - void *addr; - size_t max_size; - - /* pthread will return bogus values for the main thread */ - ZEND_ASSERT(!zend_call_stack_is_main_thread()); - - pthread_attr_init(&attr); - - error = pthread_attr_get_np(pthread_self(), &attr); - if (error) { - goto fail; - } - - error = pthread_attr_getstack(&attr, &addr, &max_size); - if (error) { - goto fail; - } - - stack->base = (int8_t*)addr + max_size; - stack->max_size = max_size; - - pthread_attr_destroy(&attr); - return true; - -fail: - pthread_attr_destroy(&attr); - return false; -} -# else /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ -static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) -{ - return false; -} -# endif /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ - -static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack) -{ - void *stack_base; - int mib[2] = {CTL_KERN, KERN_USRSTACK}; - size_t len = sizeof(stack_base); - struct rlimit rlim; - - /* This method is relevant only for the main thread */ - ZEND_ASSERT(zend_call_stack_is_main_thread()); - - if (sysctl(mib, sizeof(mib)/sizeof(*mib), &stack_base, &len, NULL, 0) != 0) { - return false; - } - - if (getrlimit(RLIMIT_STACK, &rlim) != 0) { - return false; - } - - if (rlim.rlim_cur == RLIM_INFINITY) { - return false; - } - - size_t guard_size = getpagesize(); - - stack->base = stack_base; - stack->max_size = rlim.rlim_cur - guard_size; - - return true; -} - -static bool zend_call_stack_get_freebsd(zend_call_stack *stack) -{ - if (zend_call_stack_is_main_thread()) { - return zend_call_stack_get_freebsd_sysctl(stack); - } - - return zend_call_stack_get_freebsd_pthread(stack); -} -#else -static bool zend_call_stack_get_freebsd(zend_call_stack *stack) -{ - return false; -} -#endif /* __FreeBSD__ */ - -#ifdef ZEND_WIN32 -static bool zend_call_stack_get_win32(zend_call_stack *stack) -{ - ULONG_PTR low_limit, high_limit; - ULONG size; - MEMORY_BASIC_INFORMATION guard_region = {0}, uncommitted_region = {0}; - size_t result_size, page_size; - - /* The stack consists of three regions: committed, guard, and uncommitted. - * Memory is committed when the guard region is accessed. If only one page - * is left in the uncommitted region, a stack overflow error is raised - * instead. - * - * The total useable stack size is the size of the committed and uncommitted - * regions less one page. - * - * http://blogs.msdn.com/b/satyem/archive/2012/08/13/thread-s-stack-memory-management.aspx - * https://learn.microsoft.com/en-us/windows/win32/procthread/thread-stack-size - * - * ^ Higher addresses ^ - * : : - * : : - * high_limit --> |--------------------| - * ^ | | - * | | Committed region | - * | | | - * | |------------------- | <-- guard_region.BaseAddress - * reserved | | | + guard_region.RegionSize - * size | | Guard region | - * | | | - * | |--------------------| <-- guard_region.BaseAddress, - * | | | uncommitted_region.BaseAddress - * | | Uncommitted region | + uncommitted_region.RegionSize - * v | | - * low_limit --> |------------------- | <-- uncommitted_region.BaseAddress - * : : - * : : - * v Lower addresses v - */ - - GetCurrentThreadStackLimits(&low_limit, &high_limit); - - result_size = VirtualQuery((void*)low_limit, - &uncommitted_region, sizeof(uncommitted_region)); - ZEND_ASSERT(result_size >= sizeof(uncommitted_region)); - - result_size = VirtualQuery((int8_t*)uncommitted_region.BaseAddress + uncommitted_region.RegionSize, - &guard_region, sizeof(guard_region)); - ZEND_ASSERT(result_size >= sizeof(uncommitted_region)); - - stack->base = (void*)high_limit; - stack->max_size = (uintptr_t)high_limit - (uintptr_t)low_limit; - - ZEND_ASSERT(stack->max_size > guard_region.RegionSize); - stack->max_size -= guard_region.RegionSize; - - /* The uncommitted region does not shrink below 1 page */ - page_size = zend_get_page_size(); - ZEND_ASSERT(stack->max_size > page_size); - stack->max_size -= page_size; - - return true; -} -#else /* ZEND_WIN32 */ -static bool zend_call_stack_get_win32(zend_call_stack *stack) -{ - return false; -} -#endif /* ZEND_WIN32 */ - -#if defined(__APPLE__) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) -static bool zend_call_stack_get_macos(zend_call_stack *stack) -{ - void *base = pthread_get_stackaddr_np(pthread_self()); - size_t max_size; - - if (pthread_main_np()) { - /* pthread_get_stacksize_np() returns a too low value for the main - * thread in OSX 10.9, 10.10: - * https://mail.openjdk.org/pipermail/hotspot-dev/2013-October/011353.html - * https://github.com/rust-lang/rust/issues/43347 - */ - - /* Stack size is 8MiB by default for main threads - * https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html */ - max_size = 8 * 1024 * 1024; - } else { - max_size = pthread_get_stacksize_np(pthread_self()); - } - - stack->base = base; - stack->max_size = max_size; - - return true; -} -#else /* defined(__APPLE__) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) */ -static bool zend_call_stack_get_macos(zend_call_stack *stack) -{ - return false; -} -#endif /* defined(__APPLE__) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) */ - -#if defined(__OpenBSD__) -#if defined(HAVE_PTHREAD_STACKSEG_NP) -static bool zend_call_stack_get_openbsd_pthread(zend_call_stack *stack) -{ - stack_t ss; - - if (pthread_stackseg_np(pthread_self(), &ss) != 0) { - return false; - } - - stack->base = (char *)ss.ss_sp - ss.ss_size; - stack->max_size = ss.ss_size - sysconf(_SC_PAGE_SIZE); - - return true; -} -#else -static bool zend_call_stack_get_openbsd_pthread(zend_call_stack *stack) -{ - return false; -} -#endif /* defined(HAVE_PTHREAD_STACKSEG_NP) */ - -static bool zend_call_stack_get_openbsd_vm(zend_call_stack *stack) -{ - struct _ps_strings ps; - struct rlimit rlim; - int mib[2] = {CTL_VM, VM_PSSTRINGS }; - size_t len = sizeof(ps), pagesize; - - if (sysctl(mib, 2, &ps, &len, NULL, 0) != 0) { - return false; - } - - if (getrlimit(RLIMIT_STACK, &rlim) != 0) { - return false; - } - - if (rlim.rlim_cur == RLIM_INFINITY) { - return false; - } - - pagesize = sysconf(_SC_PAGE_SIZE); - - stack->base = (void *)((uintptr_t)ps.val + (pagesize - 1) & ~(pagesize - 1)); - stack->max_size = rlim.rlim_cur - pagesize; - - return true; -} - -static bool zend_call_stack_get_openbsd(zend_call_stack *stack) -{ - // TIB_THREAD_INITIAL_STACK is private and here we avoid using pthread's api (ie pthread_main_np) - if (!TIB_GET()->tib_thread || (TIB_GET()->tib_thread_flags & 0x002) != 0) { - return zend_call_stack_get_openbsd_vm(stack); - } - - return zend_call_stack_get_openbsd_pthread(stack); -} - -#else -static bool zend_call_stack_get_openbsd(zend_call_stack *stack) -{ - return false; -} -#endif /* defined(__OpenBSD__) */ - -/** Get the stack information for the calling thread */ -ZEND_API bool zend_call_stack_get(zend_call_stack *stack) -{ - if (zend_call_stack_get_linux(stack)) { - return true; - } - - if (zend_call_stack_get_freebsd(stack)) { - return true; - } - - if (zend_call_stack_get_win32(stack)) { - return true; - } - - if (zend_call_stack_get_macos(stack)) { - return true; - } - - if (zend_call_stack_get_openbsd(stack)) { - return true; - } - - return false; -} - -#endif /* ZEND_CHECK_STACK_LIMIT */ -#endif diff --git a/thirdparty/php83/Zend/zend_call_stack.h b/thirdparty/php83/Zend/zend_call_stack.h deleted file mode 100644 index 2472bbb7006..00000000000 --- a/thirdparty/php83/Zend/zend_call_stack.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.00 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.zend.com/license/2_00.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Arnaud Le Blanc | - +----------------------------------------------------------------------+ -*/ - -/* git bash: 6602ddead5c81fb67ebf2b21c32b58aa1de67699 */ - -#ifndef ZEND_CALL_STACK_H -#define ZEND_CALL_STACK_H - -#include "zend.h" -#include "zend_portability.h" -#ifdef __APPLE__ -# include -#endif - -#ifdef ZEND_CHECK_STACK_LIMIT - -typedef struct _zend_call_stack { - void *base; - size_t max_size; -} zend_call_stack; - -ZEND_API void zend_call_stack_init(void); - -ZEND_API bool zend_call_stack_get(zend_call_stack *stack); - -/** Returns an approximation of the current stack position */ -static zend_always_inline void *zend_call_stack_position(void) { -#ifdef ZEND_WIN32 - return _AddressOfReturnAddress(); -#elif PHP_HAVE_BUILTIN_FRAME_ADDRESS - return __builtin_frame_address(0); -#else - void *a; - void *pos = (void*)&a; - return pos; -#endif -} - -static zend_always_inline bool zend_call_stack_overflowed(void *stack_limit) { - return (uintptr_t) zend_call_stack_position() <= (uintptr_t) stack_limit; -} - -static inline void* zend_call_stack_limit(void *base, size_t size, size_t reserved_size) -{ - if (UNEXPECTED(size > (uintptr_t)base)) { - return (void*)0; - } - - base = (int8_t*)base - size; - - if (UNEXPECTED(UINTPTR_MAX - (uintptr_t)base < reserved_size)) { - return (void*)UINTPTR_MAX; - } - - return (int8_t*)base + reserved_size; -} - -static inline size_t zend_call_stack_default_size(void) -{ -#ifdef __linux__ - return 8 * 1024 * 1024; -#endif -#if defined(__FreeBSD__) || defined(__NetBSD__) - return 4 * 1024 * 1024; -#endif -#ifdef __OpenBSD__ - return 512 * 1024; -#endif -#ifdef __APPLE__ - // https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html - if (pthread_main_np()) { - return 8 * 1024 * 1024; - } - return 512 * 1024; -#endif - - return 2 * 1024 * 1024; -} - -#endif /* ZEND_CHECK_STACK_LIMIT */ -#endif /* ZEND_CALL_STACK_H */ From 6052e10dc3c8267b2590609067ee926588bdb841 Mon Sep 17 00:00:00 2001 From: MARiA so cute <33935209+NathanFreeman@users.noreply.github.com> Date: Thu, 6 Jun 2024 10:42:43 +0800 Subject: [PATCH 2/2] remove unused code --- config.m4 | 1 - 1 file changed, 1 deletion(-) diff --git a/config.m4 b/config.m4 index 8e3feb89969..f35158b4d20 100644 --- a/config.m4 +++ b/config.m4 @@ -987,7 +987,6 @@ EOF fi if test "$PHP_NGHTTP2_DIR" != "no"; then - AC_DEFINE(SW_USE_SYSTEM_LIBNGHTTP2, 1, [Use the system libnghttp2]) PHP_ADD_INCLUDE("${PHP_NGHTTP2_DIR}/include") PHP_ADD_LIBRARY_WITH_PATH(nghttp2, "${PHP_NGHTTP2_DIR}/${PHP_LIBDIR}") PHP_ADD_LIBRARY(nghttp2, 1, SWOOLE_SHARED_LIBADD)