summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2016-06-20 16:03:31 +0300
committerDmitry Stogov <dmitry@zend.com>2016-06-20 16:03:31 +0300
commitad55348e6610bc9465b04cb8e4b57cdbefbe0ac2 (patch)
tree57b64d9b6fe9093aaa4e5576390a3ce32bdc9f85
parent4042f543c409669993223cc4d3b878a92567d0f0 (diff)
downloadphp-git-ad55348e6610bc9465b04cb8e4b57cdbefbe0ac2.tar.gz
Protect OPcache from termination during SHM modification.
-rw-r--r--ext/opcache/ZendAccelerator.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 222935bad0..2f756b0844 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -989,6 +989,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
zend_string *str = accel_find_interned_string(cwd_str);
if (!str) {
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
str = accel_new_interned_string(zend_string_copy(cwd_str));
@@ -998,6 +999,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
}
zend_shared_alloc_unlock();
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
}
if (str) {
char buf[32];
@@ -1029,6 +1031,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
zend_string *str = accel_find_interned_string(ZCG(include_path));
if (!str) {
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
str = accel_new_interned_string(zend_string_copy(ZCG(include_path)));
@@ -1037,6 +1040,7 @@ char *accel_make_persistent_key(const char *path, int path_length, int *key_len)
}
zend_shared_alloc_unlock();
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
}
if (str) {
char buf[32];
@@ -1134,6 +1138,7 @@ int zend_accel_invalidate(const char *filename, int filename_len, zend_bool forc
if (force ||
!ZCG(accel_directives).validate_timestamps ||
do_validate_timestamps(persistent_script, &file_handle) == FAILURE) {
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
if (!persistent_script->corrupted) {
@@ -1148,6 +1153,7 @@ int zend_accel_invalidate(const char *filename, int filename_len, zend_bool forc
}
zend_shared_alloc_unlock();
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
}
}
@@ -1594,9 +1600,11 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type)
}
}
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
persistent_script = zend_file_cache_script_load(file_handle);
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
if (persistent_script) {
/* see bug #15471 (old BTS) */
if (persistent_script->script.filename) {
@@ -1716,11 +1724,13 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
persistent_script = (zend_persistent_script *)bucket->data;
if (key && !persistent_script->corrupted) {
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
zend_accel_add_key(key, key_length, bucket);
zend_shared_alloc_unlock();
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
}
}
}
@@ -1751,6 +1761,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
ZCG(counted) = 1;
}
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
/* If script is found then validate_timestamps if option is enabled */
@@ -1815,6 +1826,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
/* No memory left. Behave like without the Accelerator */
if (ZSMMG(memory_exhausted) || ZCSG(restart_pending)) {
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
return accelerator_orig_compile_file(file_handle, type);
}
@@ -1832,6 +1844,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
*/
if (!persistent_script) {
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
return op_array;
}
if (from_shared_memory) {
@@ -1885,6 +1898,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
persistent_script->dynamic_members.last_used = ZCG(request_time);
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
/* Fetch jit auto globals used in the script before execution */
if (persistent_script->ping_auto_globals_mask) {
@@ -1973,11 +1987,13 @@ static zend_string* persistent_zend_resolve_path(const char *filename, int filen
if (!persistent_script->corrupted) {
if (key) {
/* add another "key" for the same bucket */
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
zend_accel_add_key(key, key_length, bucket);
zend_shared_alloc_unlock();
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
} else {
ZCG(key_len) = 0;
}
@@ -2058,6 +2074,7 @@ static void accel_activate(void)
}
#endif
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
if (ZCG(counted)) {
@@ -2114,6 +2131,7 @@ static void accel_activate(void)
}
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
if (ZCSG(last_restart_time) != ZCG(last_restart_time)) {
/* SHM was reinitialized. */
@@ -2755,6 +2773,7 @@ static int accel_startup(zend_extension *extension)
zend_shared_alloc_unlock();
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
#ifdef HAVE_OPCACHE_FILE_CACHE
} else if (!ZCG(accel_directives).file_cache) {
accel_startup_ok = 0;
@@ -2882,6 +2901,7 @@ void zend_accel_schedule_restart(zend_accel_restart_reason reason)
}
zend_accel_error(ACCEL_LOG_DEBUG, "Restart Scheduled!");
+ HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
ZCSG(restart_pending) = 1;
ZCSG(restart_reason) = reason;
@@ -2894,6 +2914,7 @@ void zend_accel_schedule_restart(zend_accel_restart_reason reason)
ZCSG(force_restart_time) = 0;
}
SHM_PROTECT();
+ HANDLE_UNBLOCK_INTERRUPTIONS();
}
/* this is needed because on WIN32 lock is not decreased unless ZCG(counted) is set */