[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Arnaud Le Blanc | Date: | Fri, 25 Sep 2026 13:36:32 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141558@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-09-25T15:33:17+02:00
Commit: https://github.com/php/php-src/commit/0c2444643e866da1fe219acd079464006e350531
Raw diff: https://github.com/php/php-src/commit/0c2444643e866da1fe219acd079464006e350531.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
ext/pcntl: do not drop queued signals when an exception is pending (#23624)
Changed paths:
A ext/pcntl/tests/pcntl_signal_dispatch_exception_2.phpt
A ext/pcntl/tests/pcntl_signal_dispatch_exception_3.phpt
A ext/pcntl/tests/pcntl_signal_dispatch_exception_pending.phpt
A ext/pcntl/tests/pcntl_signal_dispatch_exception_pending_user_frame.phpt
M NEWS
M ext/pcntl/pcntl.c
M ext/zend_test/test.c
M ext/zend_test/test.stub.php
M ext/zend_test/test_arginfo.h
M ext/zend_test/test_decl.h
M ext/zend_test/test_legacy_arginfo.h
Diff:
diff --git a/NEWS b/NEWS
index 0d1d864e52a3..40bc06f89e22 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,12 @@ PHP NEWS
. Fixed bug GH-23679 (Tracing JIT writes a parent private property into a
child's shadowing public property). (Ilia Alshanetsky)
+- PCNTL:
+ . Fixed pcntl_signal_dispatch() dropping the queued signals when it runs while
+ an exception is pending. (nicolas-grekas)
+ . Fixed pcntl_signal_dispatch() dropping the signals queued behind a handler
+ that throws. (nicolas-grekas)
+
24 Sep 2026, PHP 8.6.0RC2
- Core:
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 265b47e52dc7..38e6c4ae2bc3 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -29,6 +29,7 @@
#include "ext/standard/info.h"
#include "php_signal.h"
#include "php_ticks.h"
+#include "zend_exceptions.h"
#include "zend_fibers.h"
#include "main/php_main.h"
@@ -1352,6 +1353,9 @@ void pcntl_signal_dispatch(void)
{
zval params[2], *handle, retval;
struct php_pcntl_pending_signal *queue, *next;
+ zend_object *old_exception;
+ const zend_op *old_opline_before_exception = NULL;
+ const zend_op *old_opline = NULL;
sigset_t mask;
sigset_t old_mask;
@@ -1379,8 +1383,24 @@ void pcntl_signal_dispatch(void)
PCNTL_G(head) = NULL; /* simple stores are atomic */
PCNTL_G(tail) = NULL;
+ /* Dispatching can happen with an exception pending, e.g. from the interrupt check that runs
+ * right after an internal function threw. call_user_function() does nothing in that state,
+ * so set the exception aside while the handlers run. The frame is left as found: depending
+ * on the caller, the exception may not be registered on it yet, or may already be on its
+ * way to a catch block, and the caller takes it from there once we return. */
+ old_exception = EG(exception);
+ if (old_exception) {
+ if (EG(current_execute_data)) {
+ old_opline = EG(current_execute_data)->opline;
+ }
+ old_opline_before_exception = EG(opline_before_exception);
+ EG(exception) = NULL;
+ }
+
/* Allocate */
while (queue) {
+ bool handler_threw = false;
+
if ((handle = zend_hash_index_find(&PCNTL_G(php_signal_table), queue->signo)) != NULL) {
if (Z_TYPE_P(handle) != IS_LONG) {
ZVAL_LONG(¶ms[0], queue->signo);
@@ -1392,9 +1412,7 @@ void pcntl_signal_dispatch(void)
zval_ptr_dtor(&retval);
zval_ptr_dtor(¶ms[1]);
- if (EG(exception)) {
- break;
- }
+ handler_threw = NULL != EG(exception);
}
}
@@ -1402,17 +1420,44 @@ void pcntl_signal_dispatch(void)
queue->next = PCNTL_G(spares);
PCNTL_G(spares) = queue;
queue = next;
+
+ /* No other handler can be called while the exception propagates */
+ if (handler_threw) {
+ break;
+ }
}
- /* drain the remaining in case of exception thrown */
- while (queue) {
- next = queue->next;
- queue->next = PCNTL_G(spares);
- PCNTL_G(spares) = queue;
- queue = next;
+ if (old_exception) {
+ if (EG(current_execute_data)) {
+ EG(current_execute_data)->opline = old_opline;
+ }
+ EG(opline_before_exception) = old_opline_before_exception;
+ if (EG(exception)) {
+ zend_exception_set_previous(EG(exception), old_exception);
+ } else {
+ EG(exception) = old_exception;
+ }
}
- PCNTL_G(pending_signals) = false;
+ if (UNEXPECTED(queue)) {
+ /* Put back what the throwing handler did not get to, instead of dropping it, and ask
+ * the engine to come back once the exception has been handled. Signals are still
+ * blocked here, so PCNTL_G(head) cannot have been repopulated in the meantime. */
+ next = queue;
+
+ while (next->next) {
+ next = next->next;
+ }
+
+ PCNTL_G(head) = queue;
+ PCNTL_G(tail) = next;
+
+ if (PCNTL_G(async_signals)) {
+ zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
+ }
+ } else {
+ PCNTL_G(pending_signals) = false;
+ }
/* Re-enable queue */
PCNTL_G(processing_signal_queue) = false;
diff --git a/ext/pcntl/tests/pcntl_signal_dispatch_exception_2.phpt
b/ext/pcntl/tests/pcntl_signal_dispatch_exception_2.phpt
new file mode 100644
index 000000000000..ebd868df5d4b
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_signal_dispatch_exception_2.phpt
@@ -0,0 +1,44 @@
+--TEST--
+pcntl_signal_dispatch() keeps the signals left in the queue by a throwing handler
+--EXTENSIONS--
+pcntl
+posix
+--FILE--
+<?php
+
+$called = [];
+
+pcntl_signal(SIGUSR1, function ($signo) use (&$called) {
+ $called[] = 'SIGUSR1';
+ throw new \Exception('Exception in signal handler');
+});
+
+pcntl_signal(SIGUSR2, function ($signo) use (&$called) {
+ $called[] = 'SIGUSR2';
+});
+
+pcntl_signal(SIGHUP, function ($signo) use (&$called) {
+ $called[] = 'SIGHUP';
+});
+
+posix_kill(posix_getpid(), SIGUSR1);
+posix_kill(posix_getpid(), SIGUSR2);
+posix_kill(posix_getpid(), SIGHUP);
+
+try {
+ pcntl_signal_dispatch();
+} catch (\Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+echo "Handlers called: " . implode(', ', $called) . "\n";
+
+pcntl_signal_dispatch();
+
+echo "Handlers called: " . implode(', ', $called) . "\n";
+
+?>
+--EXPECT--
+Exception in signal handler
+Handlers called: SIGUSR1
+Handlers called: SIGUSR1, SIGUSR2, SIGHUP
diff --git a/ext/pcntl/tests/pcntl_signal_dispatch_exception_3.phpt
b/ext/pcntl/tests/pcntl_signal_dispatch_exception_3.phpt
new file mode 100644
index 000000000000..ff877e3c0400
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_signal_dispatch_exception_3.phpt
@@ -0,0 +1,47 @@
+--TEST--
+pcntl_signal_dispatch() delivers the signals a throwing handler left behind once its exception is
handled
+--EXTENSIONS--
+pcntl
+posix
+--FILE--
+<?php
+
+$called = [];
+
+pcntl_signal(SIGUSR1, function ($signo) use (&$called) {
+ $called[] = 'SIGUSR1';
+ throw new \Exception('Exception in signal handler');
+});
+
+pcntl_signal(SIGUSR2, function ($signo) use (&$called) {
+ $called[] = 'SIGUSR2';
+});
+
+pcntl_signal(SIGHUP, function ($signo) use (&$called) {
+ $called[] = 'SIGHUP';
+});
+
+// Queued, not dispatched: asynchronous signals are off
+posix_kill(posix_getpid(), SIGUSR1);
+posix_kill(posix_getpid(), SIGUSR2);
+
+pcntl_async_signals(true);
+
+try {
+ // Delivered asynchronously, so the whole queue is dispatched
+ posix_kill(posix_getpid(), SIGHUP);
+ echo "Not reached\n";
+} catch (\Exception $e) {
+ echo $e->getMessage() . "\n";
+}
+
+// No explicit dispatch: the engine delivers what the throwing handler left behind
+// on its own, as soon as the exception has been handled
+usleep(1000);
+
+echo "Handlers called: " . implode(', ', $called) . "\n";
+
+?>
+--EXPECT--
+Exception in signal handler
+Handlers called: SIGUSR1, SIGUSR2, SIGHUP
diff --git a/ext/pcntl/tests/pcntl_signal_dispatch_exception_pending.phpt
b/ext/pcntl/tests/pcntl_signal_dispatch_exception_pending.phpt
new file mode 100644
index 000000000000..5a7968e9b382
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_signal_dispatch_exception_pending.phpt
@@ -0,0 +1,24 @@
+--TEST--
+pcntl_signal_dispatch() runs the handlers of the signals raised while an internal function ran and
then threw
+--EXTENSIONS--
+pcntl
+zend_test
+--FILE--
+<?php
+
+pcntl_async_signals(true);
+
+pcntl_signal(SIGUSR1, function ($signo) {
+ echo "Handler called\n";
+});
+
+try {
+ zend_test_raise_and_throw(SIGUSR1);
+} catch (\Exception $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Handler called
+Exception after raise()
diff --git a/ext/pcntl/tests/pcntl_signal_dispatch_exception_pending_user_frame.phpt
b/ext/pcntl/tests/pcntl_signal_dispatch_exception_pending_user_frame.phpt
new file mode 100644
index 000000000000..bae00348c144
--- /dev/null
+++ b/ext/pcntl/tests/pcntl_signal_dispatch_exception_pending_user_frame.phpt
@@ -0,0 +1,33 @@
+--TEST--
+pcntl_signal_dispatch() with an exception pending after an internal function called from a user
frame
+--EXTENSIONS--
+pcntl
+zend_test
+--FILE--
+<?php
+
+pcntl_signal(SIGUSR1, function ($signo) {
+ echo "Handler called from ", debug_backtrace()[1]['function'],
"()\n";
+});
+
+pcntl_async_signals(true);
+
+function test() {
+ declare(ticks=1) {
+ register_tick_function('zend_test_raise_and_throw', SIGUSR1);
+ }
+ unregister_tick_function('zend_test_raise_and_throw');
+}
+
+test();
+
+?>
+--EXPECTF--
+Handler called from test()
+
+Fatal error: Uncaught Exception: Exception after raise() in %s:%d
+Stack trace:
+#0 %s(%d): zend_test_raise_and_throw(%d)
+#1 %s(%d): test()
+#2 {main}
+ thrown in %s on line %d
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index 82bfa8d38e33..4853e1f61e70 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -41,6 +41,8 @@
#include "zend_observer.h"
#include "test_decl.h"
+#include <signal.h>
+
#if defined(HAVE_LIBXML) && !defined(PHP_WIN32)
# include <libxml/globals.h>
# include <libxml/parser.h>
@@ -1444,6 +1446,22 @@ static ZEND_FUNCTION(zend_test_uri_parser)
php_uri_free(uri);
}
+static ZEND_FUNCTION(zend_test_raise_and_throw)
+{
+ zend_long signo;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_LONG(signo)
+ ZEND_PARSE_PARAMETERS_END();
+
+ if (raise((int) signo) != 0) {
+ zend_throw_error(NULL, "raise() failed");
+ RETURN_THROWS();
+ }
+
+ zend_throw_exception(NULL, "Exception after raise()", 0);
+}
+
static bool has_opline(zend_execute_data *execute_data)
{
return execute_data
diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php
index 3c09668bddb1..afeae903c668 100644
--- a/ext/zend_test/test.stub.php
+++ b/ext/zend_test/test.stub.php
@@ -423,6 +423,8 @@ function zend_get_map_ptr_last(): int {}
function zend_test_crash(?string $message = null): void {}
+ function zend_test_raise_and_throw(int $signal): void {}
+
function zend_test_fill_packed_array(array &$array): void {}
/** @return resource */
diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h
index f3901c9b7330..d01e3d036c7f 100644
--- a/ext/zend_test/test_arginfo.h
+++ b/ext/zend_test/test_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit test.stub.php instead.
- * Stub hash: 4d728e740122add9d4c91f5c1abb5f5017690636
+ * Stub hash: 2b25ec2985ed2c14165625a0603ad2a122a255c7
* Has decl header: yes */
#include "zend_attributes.h"
@@ -285,6 +285,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_crash, 0, 0, IS_VOID,
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, message, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_raise_and_throw, 0, 1, IS_VOID, 0)
+ ZEND_ARG_TYPE_INFO(0, signal, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_fill_packed_array, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(1, array, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@@ -507,6 +511,7 @@ static ZEND_FUNCTION(zend_test_zend_call_stack_use_all);
static ZEND_FUNCTION(zend_test_is_string_marked_as_valid_utf8);
static ZEND_FUNCTION(zend_get_map_ptr_last);
static ZEND_FUNCTION(zend_test_crash);
+static ZEND_FUNCTION(zend_test_raise_and_throw);
static ZEND_FUNCTION(zend_test_fill_packed_array);
static ZEND_FUNCTION(zend_test_create_throwing_resource);
static ZEND_FUNCTION(get_open_basedir);
@@ -683,6 +688,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(zend_test_is_string_marked_as_valid_utf8,
arginfo_zend_test_is_string_marked_as_valid_utf8)
ZEND_FE(zend_get_map_ptr_last, arginfo_zend_get_map_ptr_last)
ZEND_FE(zend_test_crash, arginfo_zend_test_crash)
+ ZEND_FE(zend_test_raise_and_throw, arginfo_zend_test_raise_and_throw)
ZEND_FE(zend_test_fill_packed_array, arginfo_zend_test_fill_packed_array)
ZEND_FE(zend_test_create_throwing_resource, arginfo_zend_test_create_throwing_resource)
ZEND_FE(get_open_basedir, arginfo_get_open_basedir)
diff --git a/ext/zend_test/test_decl.h b/ext/zend_test/test_decl.h
index 7e41dc18eabb..d2bc04df8f4e 100644
--- a/ext/zend_test/test_decl.h
+++ b/ext/zend_test/test_decl.h
@@ -1,8 +1,8 @@
/* This is a generated file, edit test.stub.php instead.
- * Stub hash: 4d728e740122add9d4c91f5c1abb5f5017690636 */
+ * Stub hash: 2b25ec2985ed2c14165625a0603ad2a122a255c7 */
-#ifndef ZEND_TEST_DECL_4d728e740122add9d4c91f5c1abb5f5017690636_H
-#define ZEND_TEST_DECL_4d728e740122add9d4c91f5c1abb5f5017690636_H
+#ifndef ZEND_TEST_DECL_2b25ec2985ed2c14165625a0603ad2a122a255c7_H
+#define ZEND_TEST_DECL_2b25ec2985ed2c14165625a0603ad2a122a255c7_H
typedef enum zend_enum_ZendTestUnitEnum {
ZEND_ENUM_ZendTestUnitEnum_Foo = 1,
@@ -27,4 +27,4 @@ typedef enum zend_enum_ZendTestEnumWithInterface {
ZEND_ENUM_ZendTestEnumWithInterface_Bar = 2,
} zend_enum_ZendTestEnumWithInterface;
-#endif /* ZEND_TEST_DECL_4d728e740122add9d4c91f5c1abb5f5017690636_H */
+#endif /* ZEND_TEST_DECL_2b25ec2985ed2c14165625a0603ad2a122a255c7_H */
diff --git a/ext/zend_test/test_legacy_arginfo.h b/ext/zend_test/test_legacy_arginfo.h
index d9a7709ab22f..e12e72eb6d28 100644
--- a/ext/zend_test/test_legacy_arginfo.h
+++ b/ext/zend_test/test_legacy_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit test.stub.php instead.
- * Stub hash: 4d728e740122add9d4c91f5c1abb5f5017690636
+ * Stub hash: 2b25ec2985ed2c14165625a0603ad2a122a255c7
* Has decl header: yes */
#include "zend_constants.h"
@@ -227,6 +227,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_zend_test_crash, 0, 0, 0)
ZEND_ARG_INFO(0, message)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_zend_test_raise_and_throw, 0, 0, 1)
+ ZEND_ARG_INFO(0, signal)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_zend_test_fill_packed_array, 0, 0, 1)
ZEND_ARG_INFO(1, array)
ZEND_END_ARG_INFO()
@@ -431,6 +435,7 @@ static ZEND_FUNCTION(zend_test_zend_call_stack_use_all);
static ZEND_FUNCTION(zend_test_is_string_marked_as_valid_utf8);
static ZEND_FUNCTION(zend_get_map_ptr_last);
static ZEND_FUNCTION(zend_test_crash);
+static ZEND_FUNCTION(zend_test_raise_and_throw);
static ZEND_FUNCTION(zend_test_fill_packed_array);
static ZEND_FUNCTION(zend_test_create_throwing_resource);
static ZEND_FUNCTION(get_open_basedir);
@@ -579,6 +584,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(zend_test_is_string_marked_as_valid_utf8,
arginfo_zend_test_is_string_marked_as_valid_utf8)
ZEND_FE(zend_get_map_ptr_last, arginfo_zend_get_map_ptr_last)
ZEND_FE(zend_test_crash, arginfo_zend_test_crash)
+ ZEND_FE(zend_test_raise_and_throw, arginfo_zend_test_raise_and_throw)
ZEND_FE(zend_test_fill_packed_array, arginfo_zend_test_fill_packed_array)
ZEND_FE(zend_test_create_throwing_resource, arginfo_zend_test_create_throwing_resource)
ZEND_FE(get_open_basedir, arginfo_get_open_basedir)