diff --git a/ext/posix/posix.c b/ext/posix/posix.c index 049d0bfdf19c..104d8bd659dd 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -51,6 +51,10 @@ #define POSIX_PID_MAX INT_MAX #endif +/* RLIM_INFINITY does not fit into a 32-bit zend_long if rlim_t is 64-bit. + * posix_setrlimit() maps -1 to RLIM_INFINITY, so use that in this case. */ +#define PHP_POSIX_RLIM_INFINITY (RLIM_INFINITY > ZEND_LONG_MAX ? -1 : (zend_long) RLIM_INFINITY) + #include "posix_arginfo.h" ZEND_DECLARE_MODULE_GLOBALS(posix) diff --git a/ext/posix/posix.stub.php b/ext/posix/posix.stub.php index 2ee9cdbc3147..94aeba3b6401 100644 --- a/ext/posix/posix.stub.php +++ b/ext/posix/posix.stub.php @@ -187,7 +187,7 @@ #ifdef HAVE_SETRLIMIT /** * @var int - * @cvalue RLIM_INFINITY + * @cvalue PHP_POSIX_RLIM_INFINITY */ const POSIX_RLIMIT_INFINITY = UNKNOWN; #endif diff --git a/ext/posix/posix_arginfo.h b/ext/posix/posix_arginfo.h index 6172cdf3a1ce..35a051b2ae72 100644 --- a/ext/posix/posix_arginfo.h +++ b/ext/posix/posix_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit posix.stub.php instead. - * Stub hash: 25e0aa769d72988ebca07fff96c8ed1fcb6b7d5e */ + * Stub hash: 058523eee3f040ad14c41bceca4068d877054892 */ #include "zend_constants.h" @@ -413,7 +413,7 @@ static void register_posix_symbols(int module_number) REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NPTS", RLIMIT_NPTS, CONST_PERSISTENT); #endif #if defined(HAVE_SETRLIMIT) - REGISTER_LONG_CONSTANT("POSIX_RLIMIT_INFINITY", RLIM_INFINITY, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("POSIX_RLIMIT_INFINITY", PHP_POSIX_RLIM_INFINITY, CONST_PERSISTENT); #endif #if defined(_SC_ARG_MAX) REGISTER_LONG_CONSTANT("POSIX_SC_ARG_MAX", _SC_ARG_MAX, CONST_PERSISTENT); diff --git a/ext/posix/tests/posix_setrlimit_infinity.phpt b/ext/posix/tests/posix_setrlimit_infinity.phpt new file mode 100644 index 000000000000..c04878cb5aec --- /dev/null +++ b/ext/posix/tests/posix_setrlimit_infinity.phpt @@ -0,0 +1,34 @@ +--TEST-- +posix_setrlimit() with POSIX_RLIMIT_INFINITY +--EXTENSIONS-- +posix +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +array(2) { + [0]=> + int(1024) + [1]=> + string(9) "unlimited" +} +bool(true) +array(2) { + [0]=> + string(9) "unlimited" + [1]=> + string(9) "unlimited" +}