From 0147fd546f4b1ba94206d3239c15339a07c0f7b5 Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Sun, 22 Nov 2026 23:35:36 +0100 Subject: [PATCH] session: use pread()/pwrite() unconditionally on non-Windows The PHP_PREAD_TEST and PHP_PWRITE_TEST configure checks work around a glibc bug fixed in 2.2.5 and missing off64_t prototypes. Both functions are POSIX, so remove the checks. The checks have to execute a test program, which is not possible when cross-compiling, so cross-compiled builds never used pread()/pwrite(). --- UPGRADING.INTERNALS | 4 ++ build/php.m4 | 101 ---------------------------------------- ext/session/config.m4 | 2 - ext/session/mod_files.c | 16 ++----- main/php.h | 8 ---- 5 files changed, 8 insertions(+), 123 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index a2f9bc7f01c9..0affc2be6281 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -116,6 +116,10 @@ PHP 8.7 INTERNALS UPGRADE NOTES - Unix build system changes: . Autoconf minimum required version upgraded to 2.71. + . The PHP_PREAD_TEST and PHP_PWRITE_TEST M4 macros have been removed, along + with the HAVE_PREAD, HAVE_PWRITE, PHP_PREAD_64 and PHP_PWRITE_64 symbols. + pread() and pwrite() are POSIX and can be used unconditionally on non-Windows + platforms. ======================== 3. Module changes diff --git a/build/php.m4 b/build/php.m4 index d8bf0221e83e..4e6c52ec41ee 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -1137,107 +1137,6 @@ AS_CASE([$php_cv_time_r_type], [Define to 1 you have IRIX-style reentrant time functions.])]) ]) -dnl -dnl PHP_DOES_PWRITE_WORK -dnl -dnl Internal. -dnl -AC_DEFUN([PHP_DOES_PWRITE_WORK], [ -AC_RUN_IFELSE([AC_LANG_SOURCE([ -#include -#include -#include -#include -#include -#include -$1 - int main(void) { - int fd = open("conftest_pwrite", O_WRONLY|O_CREAT, 0600); - - if (fd < 0) return 1; - if (pwrite(fd, "text", 4, 0) != 4) return 1; - /* Linux glibc breakage until 2.2.5 */ - if (pwrite(fd, "text", 4, -1) != -1 || errno != EINVAL) return 1; - return 0; - } - ])], - [php_cv_func_pwrite=yes], - [php_cv_func_pwrite=no], - [php_cv_func_pwrite=no]) -]) - -dnl -dnl PHP_DOES_PREAD_WORK -dnl -dnl Internal. -dnl -AC_DEFUN([PHP_DOES_PREAD_WORK], [ -echo test > conftest_pread -AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#include -#include -#include -#include -#include -#include -$1 - int main(void) { - char buf[3]; - int fd = open("conftest_pread", O_RDONLY); - if (fd < 0) return 1; - if (pread(fd, buf, 2, 0) != 2) return 1; - /* Linux glibc breakage until 2.2.5 */ - if (pread(fd, buf, 2, -1) != -1 || errno != EINVAL) return 1; - return 0; - } - ]])], - [php_cv_func_pread=yes], - [php_cv_func_pread=no], - [php_cv_func_pread=no]) -]) - -dnl -dnl PHP_PWRITE_TEST -dnl -AC_DEFUN([PHP_PWRITE_TEST], [ -AC_CACHE_CHECK([whether pwrite works], [php_cv_func_pwrite], [ - PHP_DOES_PWRITE_WORK - AS_VAR_IF([php_cv_func_pwrite], [no], [ - PHP_DOES_PWRITE_WORK([ssize_t pwrite(int, void *, size_t, off64_t);]) - AS_VAR_IF([php_cv_func_pwrite], [yes], [php_cv_func_pwrite=64]) - ]) -]) - -AS_VAR_IF([php_cv_func_pwrite], [no],, [ - AC_DEFINE([HAVE_PWRITE], [1], - [Define to 1 if you have the 'pwrite' function.]) - AS_VAR_IF([php_cv_func_pwrite], [64], - [AC_DEFINE([PHP_PWRITE_64], [1], - [Define to 1 if 'pwrite' declaration with 'off64_t' is missing.])]) -]) -]) - -dnl -dnl PHP_PREAD_TEST -dnl -AC_DEFUN([PHP_PREAD_TEST], [ -AC_CACHE_CHECK([whether pread works], [php_cv_func_pread], [ - PHP_DOES_PREAD_WORK - AS_VAR_IF([php_cv_func_pread], [no], [ - PHP_DOES_PREAD_WORK([ssize_t pread(int, void *, size_t, off64_t);]) - AS_VAR_IF([php_cv_func_pread], [yes], [php_cv_func_pread=64]) - ]) -]) - -AS_VAR_IF([php_cv_func_pread], [no],, [ - AC_DEFINE([HAVE_PREAD], [1], - [Define to 1 if you have the 'pread' function.]) - AS_VAR_IF([php_cv_func_pread], [64], - [AC_DEFINE([PHP_PREAD_64], [1], - [Define to 1 if 'pread' declaration with 'off64_t' is missing.])]) -]) -]) - dnl dnl PHP_MISSING_TIME_R_DECL dnl diff --git a/ext/session/config.m4 b/ext/session/config.m4 index cce00e585122..72805d558354 100644 --- a/ext/session/config.m4 +++ b/ext/session/config.m4 @@ -12,8 +12,6 @@ PHP_ARG_WITH([mm], [no]) if test "$PHP_SESSION" != "no"; then - PHP_PWRITE_TEST - PHP_PREAD_TEST PHP_NEW_EXTENSION([session], [mod_user_class.c session.c mod_files.c mod_mm.c mod_user.c], [$ext_shared],, diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 4528ebb70bcf..81b6713512bf 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -233,11 +233,8 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string return FAILURE; } -#ifdef HAVE_PWRITE - n = pwrite(data->fd, ZSTR_VAL(val), ZSTR_LEN(val), 0); -#else - lseek(data->fd, 0, SEEK_SET); #ifdef PHP_WIN32 + lseek(data->fd, 0, SEEK_SET); { unsigned int to_write = SESS_FILE_BUF_SIZE(ZSTR_LEN(val)); char *buf = ZSTR_VAL(val); @@ -253,8 +250,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string } while (wrote > 0); } #else - n = write(data->fd, ZSTR_VAL(val), ZSTR_LEN(val)); -#endif + n = pwrite(data->fd, ZSTR_VAL(val), ZSTR_LEN(val), 0); #endif if (n != ZSTR_LEN(val)) { @@ -501,11 +497,8 @@ PS_READ_FUNC(files) *val = zend_string_alloc(sbuf.st_size, false); -#ifdef HAVE_PREAD - n = pread(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val), 0); -#else - lseek(data->fd, 0, SEEK_SET); #ifdef PHP_WIN32 + lseek(data->fd, 0, SEEK_SET); { unsigned int to_read = SESS_FILE_BUF_SIZE(ZSTR_LEN(*val)); char *buf = ZSTR_VAL(*val); @@ -522,8 +515,7 @@ PS_READ_FUNC(files) } #else - n = read(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val)); -#endif + n = pread(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val), 0); #endif if (n != (zend_long)sbuf.st_size) { diff --git a/main/php.h b/main/php.h index e5a6d6f9633f..39fc61804db8 100644 --- a/main/php.h +++ b/main/php.h @@ -262,14 +262,6 @@ extern char **environ; extern const char php_build_date[]; -#ifdef PHP_PWRITE_64 -ssize_t pwrite(int, void *, size_t, off64_t); -#endif - -#ifdef PHP_PREAD_64 -ssize_t pread(int, void *, size_t, off64_t); -#endif - BEGIN_EXTERN_C() void phperror(char *error); PHPAPI size_t php_write(void *buf, size_t size);