Skip to content

Commit 6af2297

Browse files
committed
Remove Zend Signals
Zend Signals installed process-wide handlers for seven signals on every request and deferred them while a per-thread counter was non-zero. Since timeouts only set EG(vm_interrupt), the only remaining callers were the OPcache shared memory writes, which now block signals themselves. On ZTS the design cannot work: dispositions and delivery are per process while the handler table, depth counter and queue are per thread. A signal delivered to another thread is not deferred, and that thread does not see handlers registered by the one that installed them. The per-request handlers also replaced those of host runtimes without SA_ONSTACK. Official Docker images and many ZTS packages already disable it. Zend/zend_signal.h and its API are removed too: SAPIs and extensions use signal() and sigaction() directly.
1 parent 3d31a6d commit 6af2297

29 files changed

Lines changed: 33 additions & 705 deletions

‎UPGRADING‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ PHP 8.7 UPGRADE NOTES
2222
- Core:
2323
. Block declaration support for the encoding declare has been removed as it
2424
did not function properly.
25+
. Zend Signals has been removed, along with the --disable-zend-signals
26+
configure option and the "Zend Signal Handling" phpinfo() entry. Signals
27+
are no longer deferred while the engine runs. OPcache now blocks signals
28+
itself while writing to shared memory, and pcntl_signal() handlers are
29+
replaced at request shutdown by the handler installed before the request,
30+
instead of SIG_DFL.
2531

2632
- Curl:
2733
. curl_multi_exec() now throws a TypeError when $still_running cannot be
@@ -184,6 +190,9 @@ PHP 8.7 UPGRADE NOTES
184190
11. Changes to INI File Handling
185191
========================================
186192

193+
- Core:
194+
. The zend.signal_check INI setting has been removed.
195+
187196
- Opcache:
188197
. opcache.max_accelerated_files now defaults to 16229 (previously 10000),
189198
accepts values up to 1048793 (previously 1000000), and logs a warning for

‎UPGRADING.INTERNALS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ PHP 8.7 INTERNALS UPGRADE NOTES
1515
========================
1616

1717
- Breaking changes:
18+
. Zend Signals has been removed, along with Zend/zend_signal.h. ZEND_SIGNALS,
19+
SIGG(), zend_signal_globals_t, HANDLE_BLOCK_INTERRUPTIONS(),
20+
HANDLE_UNBLOCK_INTERRUPTIONS(), ZEND_SIGNAL_BLOCK_INTERRUPTIONS(),
21+
ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS(), zend_signal_startup(),
22+
zend_signal_init(), zend_signal_activate(), zend_signal_deactivate(),
23+
zend_signal() and zend_sigaction() no longer exist. Use signal() and
24+
sigaction() directly.
1825
. Added zend_module_entry.child_init_func, an optional void callback invoked
1926
by php_child_init() in the child process after core child initialization.
2027
It runs in module dependency order for started modules and may run before a
@@ -97,6 +104,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES
97104

98105
- Unix build system changes:
99106
. Autoconf minimum required version upgraded to 2.71.
107+
. The --disable-zend-signals configure option has been removed.
100108

101109
========================
102110
3. Module changes

‎Zend/Zend.m4‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ AX_CHECK_COMPILE_FLAG([-fno-common],
216216
[CFLAGS="-fno-common $CFLAGS"])
217217
218218
ZEND_CHECK_ALIGNMENT
219-
ZEND_CHECK_SIGNALS
220219
ZEND_CHECK_MAX_EXECUTION_TIMERS
221220
])
222221

@@ -435,28 +434,6 @@ AS_VAR_IF([php_cv_align_mm], [failed],
435434
])
436435
])
437436

438-
dnl
439-
dnl ZEND_CHECK_SIGNALS
440-
dnl
441-
dnl Check whether to enable Zend signal handling if supported by the system.
442-
dnl
443-
AC_DEFUN([ZEND_CHECK_SIGNALS], [dnl
444-
AC_ARG_ENABLE([zend-signals],
445-
[AS_HELP_STRING([--disable-zend-signals],
446-
[Disable Zend signal handling])],
447-
[ZEND_SIGNALS=$enableval],
448-
[ZEND_SIGNALS=yes])
449-
450-
AC_CHECK_FUNCS([sigaction],, [ZEND_SIGNALS=no])
451-
AS_VAR_IF([ZEND_SIGNALS], [yes],
452-
[AC_DEFINE([ZEND_SIGNALS], [1],
453-
[Define to 1 if Zend signal handling is supported and enabled.])
454-
AS_VAR_APPEND([CFLAGS], [" -DZEND_SIGNALS"])])
455-
456-
AC_MSG_CHECKING([whether to enable Zend signal handling])
457-
AC_MSG_RESULT([$ZEND_SIGNALS])
458-
])
459-
460437
dnl
461438
dnl ZEND_CHECK_MAX_EXECUTION_TIMERS
462439
dnl

‎Zend/zend.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,6 @@ static ZEND_INI_MH(OnUpdateFiberStackSize) /* {{{ */
257257
}
258258
/* }}} */
259259

260-
#if ZEND_DEBUG
261-
# define SIGNAL_CHECK_DEFAULT "1"
262-
#else
263-
# define SIGNAL_CHECK_DEFAULT "0"
264-
#endif
265-
266260
ZEND_INI_BEGIN()
267261
ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting)
268262
STD_ZEND_INI_BOOLEAN("fatal_error_backtraces", "1", ZEND_INI_ALL, OnUpdateBool, fatal_error_backtrace_on, zend_executor_globals, executor_globals)
@@ -271,9 +265,6 @@ ZEND_INI_BEGIN()
271265
STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte, zend_compiler_globals, compiler_globals)
272266
ZEND_INI_ENTRY("zend.script_encoding", NULL, ZEND_INI_ALL, OnUpdateScriptEncoding)
273267
STD_ZEND_INI_BOOLEAN("zend.detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
274-
#ifdef ZEND_SIGNALS
275-
STD_ZEND_INI_BOOLEAN("zend.signal_check", SIGNAL_CHECK_DEFAULT, ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
276-
#endif
277268
STD_ZEND_INI_BOOLEAN("zend.exception_ignore_args", "0", ZEND_INI_ALL, OnUpdateBool, exception_ignore_args, zend_executor_globals, executor_globals)
278269
STD_ZEND_INI_ENTRY("zend.exception_string_param_max_len", "15", ZEND_INI_ALL, OnSetExceptionStringParamMaxLen, exception_string_param_max_len, zend_executor_globals, executor_globals)
279270
STD_ZEND_INI_ENTRY("fiber.stack_size", NULL, ZEND_INI_ALL, OnUpdateFiberStackSize, fiber_stack_size, zend_executor_globals, executor_globals)

‎Zend/zend.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@
3737
#include "zend_stream.h"
3838
#include "zend_smart_str_public.h"
3939
#include "zend_smart_string_public.h"
40-
#include "zend_signal.h"
4140
#include "zend_max_execution_timer.h"
4241

4342
#define zend_sprintf sprintf
4443

45-
#define HANDLE_BLOCK_INTERRUPTIONS() ZEND_SIGNAL_BLOCK_INTERRUPTIONS()
46-
#define HANDLE_UNBLOCK_INTERRUPTIONS() ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS()
47-
4844
#define INTERNAL_FUNCTION_PARAMETERS zend_execute_data *execute_data, zval *return_value
4945
#define INTERNAL_FUNCTION_PARAM_PASSTHRU execute_data, return_value
5046

‎Zend/zend_execute_API.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,24 +1695,20 @@ static void zend_set_timeout_ex(zend_long seconds, bool reset_signals) /* {{{ */
16951695
# endif
16961696

16971697
if (reset_signals) {
1698-
# ifdef ZEND_SIGNALS
1699-
zend_signal(signo, zend_timeout_handler);
1700-
# else
17011698
sigset_t sigset;
1702-
# ifdef HAVE_SIGACTION
1699+
# ifdef HAVE_SIGACTION
17031700
struct sigaction act;
17041701

17051702
act.sa_handler = zend_timeout_handler;
17061703
sigemptyset(&act.sa_mask);
17071704
act.sa_flags = SA_ONSTACK | SA_RESETHAND | SA_NODEFER;
17081705
sigaction(signo, &act, NULL);
1709-
# else
1706+
# else
17101707
signal(signo, zend_timeout_handler);
1711-
# endif /* HAVE_SIGACTION */
1708+
# endif /* HAVE_SIGACTION */
17121709
sigemptyset(&sigset);
17131710
sigaddset(&sigset, signo);
17141711
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
1715-
# endif /* ZEND_SIGNALS */
17161712
}
17171713
}
17181714
#endif /* HAVE_SETITIMER */

0 commit comments

Comments
 (0)