From fe7f699c0a8081ff7b9c6699729436cd9d13ecf0 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 18 May 2024 21:53:15 +0100 Subject: [PATCH] ext/pcntl: adding SIGTRAP handling for freebsd. if a restricted file descriptor based syscall by the system had been attempted, a SIGTRAP is raised with the syscall id. close GH-14266 --- NEWS | 1 + ext/pcntl/pcntl.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/NEWS b/NEWS index c469ba952a8..4fefc16d6cd 100644 --- a/NEWS +++ b/NEWS @@ -146,6 +146,7 @@ PHP NEWS . Added pcntl_getcpu for Linux/FreeBSD/Solaris/Illumos. (David Carlier) . Added pcntl_getqos_class/pcntl_setqos_class for macOs. (David Carlier) . Added SIGCKPT/SIGCKPTEXIT constants for DragonFlyBSD. (David Carlier) + . Added FreeBSD's SIGTRAP handling to pcntl_siginfo_to_zval. (David Carlier) - PCRE: . Upgrade bundled pcre2lib to version 10.43. (nielsdos) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index e1451188bb1..31048e47b06 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -1067,6 +1067,20 @@ static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_sigi add_assoc_long_ex(user_siginfo, "fd", sizeof("fd")-1, siginfo->si_fd); # endif break; +#endif + +#ifdef SIGTRAP + case SIGTRAP: +# if defined(si_syscall) && defined(__FreeBSD__) + if (siginfo->si_code == TRAP_CAP) { + add_assoc_long_ex(user_siginfo, "syscall", sizeof("syscall")-1, (zend_long)siginfo->si_syscall); + } else { + add_assoc_long_ex(user_siginfo, "trapno", sizeof("trapno")-1, (zend_long)siginfo->si_trapno); + } + +# endif + break; + #endif } #if defined(SIGRTMIN) && defined(SIGRTMAX)