summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2019-02-12 10:21:59 +0300
committerDmitry Stogov <dmitry@zend.com>2019-02-12 10:21:59 +0300
commit470f5891d48cad64fd73dbb34775b3bcce1337cf (patch)
tree449b03934361940f023bfd4d5b6c01acb3c90d56
parentb71146bde4fc5b829501341bd359fc8af94726ac (diff)
parent9222702633c63254b08466b322266b647ac3e905 (diff)
downloadphp-git-470f5891d48cad64fd73dbb34775b3bcce1337cf.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Avoid dependency on "struct flock" fields order.
-rw-r--r--ext/opcache/ZendAccelerator.c68
-rw-r--r--ext/opcache/ZendAccelerator.h13
-rw-r--r--ext/opcache/config.m457
-rw-r--r--ext/opcache/zend_shared_alloc.c21
4 files changed, 56 insertions, 103 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index a066954bf4..bb250e5c21 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -236,11 +236,12 @@ static inline void accel_restart_enter(void)
#ifdef ZEND_WIN32
INCREMENT(restart_in);
#else
-# ifdef _AIX
- static FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
-# else
- static const FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
-#endif
+ struct flock restart_in_progress;
+
+ restart_in_progress.l_type = F_WRLCK;
+ restart_in_progress.l_whence = SEEK_SET;
+ restart_in_progress.l_start = 2;
+ restart_in_progress.l_len = 1;
if (fcntl(lock_file, F_SETLK, &restart_in_progress) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC(+1): %s (%d)", strerror(errno), errno);
@@ -255,11 +256,12 @@ static inline void accel_restart_leave(void)
ZCSG(restart_in_progress) = 0;
DECREMENT(restart_in);
#else
-# ifdef _AIX
- static FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
-# else
- static const FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
-# endif
+ struct flock restart_finished;
+
+ restart_finished.l_type = F_UNLCK;
+ restart_finished.l_whence = SEEK_SET;
+ restart_finished.l_start = 2;
+ restart_finished.l_len = 1;
ZCSG(restart_in_progress) = 0;
if (fcntl(lock_file, F_SETLK, &restart_finished) == -1) {
@@ -272,7 +274,12 @@ static inline int accel_restart_is_active(void)
{
if (ZCSG(restart_in_progress)) {
#ifndef ZEND_WIN32
- FLOCK_STRUCTURE(restart_check, F_WRLCK, SEEK_SET, 2, 1);
+ struct flock restart_check;
+
+ restart_check.l_type = F_WRLCK;
+ restart_check.l_whence = SEEK_SET;
+ restart_check.l_start = 2;
+ restart_check.l_len = 1;
if (fcntl(lock_file, F_GETLK, &restart_check) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC: %s (%d)", strerror(errno), errno);
@@ -297,11 +304,12 @@ static inline int accel_activate_add(void)
#ifdef ZEND_WIN32
INCREMENT(mem_usage);
#else
-# ifdef _AIX
- static FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
-# else
- static const FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
-# endif
+ struct flock mem_usage_lock;
+
+ mem_usage_lock.l_type = F_RDLCK;
+ mem_usage_lock.l_whence = SEEK_SET;
+ mem_usage_lock.l_start = 1;
+ mem_usage_lock.l_len = 1;
if (fcntl(lock_file, F_SETLK, &mem_usage_lock) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1): %s (%d)", strerror(errno), errno);
@@ -320,11 +328,12 @@ static inline void accel_deactivate_sub(void)
ZCG(counted) = 0;
}
#else
-# ifdef _AIX
- static FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
-# else
- static const FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
-# endif
+ struct flock mem_usage_unlock;
+
+ mem_usage_unlock.l_type = F_UNLCK;
+ mem_usage_unlock.l_whence = SEEK_SET;
+ mem_usage_unlock.l_start = 1;
+ mem_usage_unlock.l_len = 1;
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(-1): %s (%d)", strerror(errno), errno);
@@ -337,11 +346,12 @@ static inline void accel_unlock_all(void)
#ifdef ZEND_WIN32
accel_deactivate_sub();
#else
-# ifdef _AIX
- static FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
-# else
- static const FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
-# endif
+ struct flock mem_usage_unlock_all;
+
+ mem_usage_unlock_all.l_type = F_UNLCK;
+ mem_usage_unlock_all.l_whence = SEEK_SET;
+ mem_usage_unlock_all.l_start = 0;
+ mem_usage_unlock_all.l_len = 0;
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock_all) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UnlockAll: %s (%d)", strerror(errno), errno);
@@ -830,8 +840,12 @@ static inline int accel_is_inactive(void)
return SUCCESS;
}
#else
- FLOCK_STRUCTURE(mem_usage_check, F_WRLCK, SEEK_SET, 1, 1);
+ struct flock mem_usage_check;
+ mem_usage_check.l_type = F_WRLCK;
+ mem_usage_check.l_whence = SEEK_SET;
+ mem_usage_check.l_start = 1;
+ mem_usage_check.l_len = 1;
mem_usage_check.l_pid = -1;
if (fcntl(lock_file, F_GETLK, &mem_usage_check) == -1) {
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC: %s (%d)", strerror(errno), errno);
diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h
index b87f93a435..82d666ccdd 100644
--- a/ext/opcache/ZendAccelerator.h
+++ b/ext/opcache/ZendAccelerator.h
@@ -89,19 +89,6 @@
/*** file locking ***/
#ifndef ZEND_WIN32
extern int lock_file;
-
-# if defined(HAVE_FLOCK_AIX64)
-# define FLOCK_STRUCTURE(name, type, whence, start, len) \
- struct flock name = {type, whence, 0, 0, 0, start, len }
-# elif defined(HAVE_FLOCK_BSD)
-# define FLOCK_STRUCTURE(name, type, whence, start, len) \
- struct flock name = {start, len, -1, type, whence}
-# elif defined(HAVE_FLOCK_LINUX)
-# define FLOCK_STRUCTURE(name, type, whence, start, len) \
- struct flock name = {type, whence, start, len}
-# else
-# error "Don't know how to define struct flock"
-# endif
#endif
#if defined(HAVE_OPCACHE_FILE_CACHE) && defined(ZEND_WIN32)
diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4
index 392f4c65a3..4810217c14 100644
--- a/ext/opcache/config.m4
+++ b/ext/opcache/config.m4
@@ -341,63 +341,6 @@ int main() {
msg=yes],[msg=no],[msg=no])
AC_MSG_RESULT([$msg])
-flock_type=unknown
-AC_MSG_CHECKING(for struct flock layout)
-
-if test "$flock_type" = "unknown"; then
-AC_RUN_IFELSE([AC_LANG_SOURCE([[
- #include <fcntl.h>
- struct flock lock = { 1, 2, 3, 4, 5, 6, 7 };
- int main() {
- if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 6 && lock.l_len== 7) {
- return 0;
- }
- return 1;
- }
-]])], [
- flock_type=aix64
- AC_DEFINE([HAVE_FLOCK_AIX64], [], [Struct flock is 64-bit AIX-type])
-], [])
-fi
-
-if test "$flock_type" = "unknown"; then
-AC_RUN_IFELSE([AC_LANG_SOURCE([[
- #include <fcntl.h>
- struct flock lock = { 1, 2, 3, 4, 5 };
- int main() {
- if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 3 && lock.l_len == 4) {
- return 0;
- }
- return 1;
- }
-]])], [
- flock_type=linux
- AC_DEFINE([HAVE_FLOCK_LINUX], [], [Struct flock is Linux-type])
-], [])
-fi
-
-if test "$flock_type" = "unknown"; then
-AC_RUN_IFELSE([AC_LANG_SOURCE([[
- #include <fcntl.h>
- struct flock lock = { 1, 2, 3, 4, 5 };
- int main() {
- if(lock.l_start == 1 && lock.l_len == 2 && lock.l_type == 4 && lock.l_whence == 5) {
- return 0;
- }
- return 1;
- }
-]])], [
- flock_type=bsd
- AC_DEFINE([HAVE_FLOCK_BSD], [], [Struct flock is BSD-type])
-], [])
-fi
-
-AC_MSG_RESULT([$flock_type])
-
-if test "$flock_type" = "unknown"; then
- AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])
-fi
-
PHP_NEW_EXTENSION(opcache,
ZendAccelerator.c \
zend_accelerator_blacklist.c \
diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c
index 17ddadbdd8..3db3c0106a 100644
--- a/ext/opcache/zend_shared_alloc.c
+++ b/ext/opcache/zend_shared_alloc.c
@@ -375,15 +375,15 @@ void zend_shared_alloc_safe_unlock(void)
}
}
-#ifndef ZEND_WIN32
-/* name l_type l_whence l_start l_len */
-static FLOCK_STRUCTURE(mem_write_lock, F_WRLCK, SEEK_SET, 0, 1);
-static FLOCK_STRUCTURE(mem_write_unlock, F_UNLCK, SEEK_SET, 0, 1);
-#endif
-
void zend_shared_alloc_lock(void)
{
#ifndef ZEND_WIN32
+ struct flock mem_write_lock;
+
+ mem_write_lock.l_type = F_WRLCK;
+ mem_write_lock.l_whence = SEEK_SET;
+ mem_write_lock.l_start = 0;
+ mem_write_lock.l_len = 1;
#ifdef ZTS
tsrm_mutex_lock(zts_lock);
@@ -414,6 +414,15 @@ void zend_shared_alloc_lock(void)
void zend_shared_alloc_unlock(void)
{
+#ifndef ZEND_WIN32
+ struct flock mem_write_unlock;
+
+ mem_write_unlock.l_type = F_UNLCK;
+ mem_write_unlock.l_whence = SEEK_SET;
+ mem_write_unlock.l_start = 0;
+ mem_write_unlock.l_len = 1;
+#endif
+
ZCG(locked) = 0;
#ifndef ZEND_WIN32