From aec6c6345c63559b48db13d2ddc8d3f8546d88c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 14 Feb 2024 22:05:44 +0100 Subject: [PATCH 1/2] add support for Zend Max Exeuction Timers on FreeBSD --- Zend/Zend.m4 | 2 +- Zend/zend_max_execution_timer.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 06b19c85c712b..edaf6a298a548 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -279,7 +279,7 @@ AC_ARG_ENABLE([zend-max-execution-timers], [ZEND_MAX_EXECUTION_TIMERS=$enableval], [ZEND_MAX_EXECUTION_TIMERS='no']) -AS_CASE(["$host_alias"], [*linux*], [], [ZEND_MAX_EXECUTION_TIMERS='no']) +AS_CASE(["$host_alias"], [*linux*|*freebsd*], [], [ZEND_MAX_EXECUTION_TIMERS='no']) PHP_CHECK_FUNC(timer_create, rt) if test "$ac_cv_func_timer_create" != "yes"; then diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index 48a4d1bd66415..f4f3793061acd 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -23,6 +23,9 @@ #include #include #include +# ifdef __FreeBSD__ +# include +# endif #include "zend.h" #include "zend_globals.h" @@ -45,7 +48,11 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ sev.sigev_notify = SIGEV_THREAD_ID; sev.sigev_value.sival_ptr = &EG(max_execution_timer_timer); sev.sigev_signo = SIGRTMIN; +# ifdef __FreeBSD__ + sev.sigev_notify_thread_id = pthread_getthreadid_np(); +# else sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid); +# endif // Measure wall time instead of CPU time as originally planned now that it is possible https://github.com/php/php-src/pull/6504#issuecomment-1370303727 if (timer_create(CLOCK_BOOTTIME, &sev, &EG(max_execution_timer_timer)) != 0) { From 8a8399f8de257d2a1a9c951fbdb1ec2d2f9197dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 15 Feb 2024 17:34:37 +0100 Subject: [PATCH 2/2] use CLOCK_MONOTONIC on FreeBSD --- Zend/zend_max_execution_timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index f4f3793061acd..92b70fbb2a6ad 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -36,6 +36,13 @@ # define sigev_notify_thread_id _sigev_un._tid # endif +// FreeBSD doesn't support CLOCK_BOOTTIME +# ifdef __FreeBSD__ +# define ZEND_MAX_EXECUTION_TIMERS_CLOCK CLOCK_MONOTONIC +# else +# define ZEND_MAX_EXECUTION_TIMERS_CLOCK CLOCK_BOOTTIME +# endif + ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ { pid_t pid = getpid(); @@ -55,7 +62,7 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ # endif // Measure wall time instead of CPU time as originally planned now that it is possible https://github.com/php/php-src/pull/6504#issuecomment-1370303727 - if (timer_create(CLOCK_BOOTTIME, &sev, &EG(max_execution_timer_timer)) != 0) { + if (timer_create(ZEND_MAX_EXECUTION_TIMERS_CLOCK, &sev, &EG(max_execution_timer_timer)) != 0) { zend_strerror_noreturn(E_ERROR, errno, "Could not create timer"); }