Skip to content

add support for Zend Max Exeuction Timers on FreeBSD #13393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion Zend/zend_max_execution_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <errno.h>
#include <sys/syscall.h>
#include <sys/types.h>
# ifdef __FreeBSD__
# include <pthread_np.h>
# endif

#include "zend.h"
#include "zend_globals.h"
Expand All @@ -33,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();
Expand All @@ -45,10 +55,14 @@ 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) {
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");
}

Expand Down