Skip to content

Commit 418e0fc

Browse files
committed
Fix GH-9653: does not inconditionally support copy_file_range on older kernels.
As mentioned in its manpage, it had been reworked in the 5.3 line to support cross filesystem interactions.
1 parent a5003bb commit 418e0fc

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

configure.ac

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ PHP_CHECK_FUNC(socketpair, socket, network)
364364
PHP_CHECK_FUNC(htonl, socket, network)
365365
PHP_CHECK_FUNC(gethostname, nsl, network)
366366
PHP_CHECK_FUNC(gethostbyaddr, nsl, network)
367-
PHP_CHECK_FUNC(copy_file_range)
368367
PHP_CHECK_FUNC(dlopen, dl, root)
369368
PHP_CHECK_FUNC(dlsym, dl, root)
370369
if test "$ac_cv_func_dlopen" = "yes"; then
@@ -691,6 +690,39 @@ if test "$ac_cv_func_getaddrinfo" = yes; then
691690
AC_DEFINE(HAVE_GETADDRINFO,1,[Define if you have the getaddrinfo function])
692691
fi
693692

693+
AC_CACHE_CHECK([for copy_file_range], ac_cv_copy_file_range,
694+
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
695+
#if defined(__linux__)
696+
#if !defined(_GNU_SOURCE)
697+
#define _GNU_SOURCE
698+
#endif
699+
#include <linux/version.h>
700+
#elif defined(__FreeBSD__)
701+
// TODO checks kernel version once this syscall is fixed on FreeBSD
702+
#include <sys/param.h>
703+
#include <sys/types.h>
704+
#endif
705+
#include <unistd.h>
706+
707+
int main(void) {
708+
(void)copy_file_range(-1, 0, -1, 0, 0, 0);
709+
#if defined(__linux__)
710+
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0)
711+
return 1;
712+
#else
713+
return 0;
714+
#endif
715+
#else
716+
return 1;
717+
#endif
718+
}
719+
]])], [ac_cv_copy_file_range=yes], [ac_cv_copy_file_range=no])
720+
])
721+
722+
if test "$ac_cv_copy_file_range" = yes; then
723+
AC_DEFINE(HAVE_COPY_FILE_RANGE,1,[Define if copy_file_range support])
724+
fi
725+
694726
AC_REPLACE_FUNCS(strlcat strlcpy explicit_bzero getopt)
695727
AC_FUNC_ALLOCA
696728
PHP_TIME_R_TYPE

0 commit comments

Comments
 (0)