Skip to content

Commit 4d8e0d4

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Moved NEWS entry Fixed possible crashes, because of inconsistent PCRE cache and opcache SHM reset
2 parents f0eb642 + 7bc4bd0 commit 4d8e0d4

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static zend_always_inline zend_string *accel_find_interned_string(zend_string *s
429429
}
430430

431431
if (!ZCG(counted)) {
432-
if (accel_activate_add() == FAILURE) {
432+
if (!ZCG(accelerator_enabled) || accel_activate_add() == FAILURE) {
433433
return str;
434434
}
435435
ZCG(counted) = 1;
@@ -1145,7 +1145,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
11451145
cwd_len = ZSTR_LEN(cwd_str);
11461146
if (ZCG(cwd_check)) {
11471147
ZCG(cwd_check) = 0;
1148-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1148+
if (ZCG(accelerator_enabled)) {
11491149

11501150
zend_string *str = accel_find_interned_string(cwd_str);
11511151
if (!str) {
@@ -1185,7 +1185,7 @@ char *accel_make_persistent_key(const char *path, size_t path_length, int *key_l
11851185

11861186
if (ZCG(include_path_check)) {
11871187
ZCG(include_path_check) = 0;
1188-
if ((ZCG(counted) || ZCSG(accelerator_enabled))) {
1188+
if (ZCG(accelerator_enabled)) {
11891189

11901190
zend_string *str = accel_find_interned_string(ZCG(include_path));
11911191
if (!str) {
@@ -1268,7 +1268,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
12681268
zend_string *realpath;
12691269
zend_persistent_script *persistent_script;
12701270

1271-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
1271+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
12721272
return FAILURE;
12731273
}
12741274

@@ -1872,7 +1872,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
18721872
return accelerator_orig_compile_file(file_handle, type);
18731873
} else if (file_cache_only) {
18741874
return file_cache_compile_file(file_handle, type);
1875-
} else if ((!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
1875+
} else if (!ZCG(accelerator_enabled) ||
18761876
(ZCSG(restart_in_progress) && accel_restart_is_active())) {
18771877
if (ZCG(accel_directives).file_cache) {
18781878
return file_cache_compile_file(file_handle, type);
@@ -2159,10 +2159,8 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
21592159
/* zend_resolve_path() replacement for PHP 5.3 and above */
21602160
static zend_string* persistent_zend_resolve_path(const char *filename, size_t filename_len)
21612161
{
2162-
if (ZCG(enabled) && accel_startup_ok &&
2163-
!file_cache_only &&
2164-
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
2165-
!ZCSG(restart_in_progress)) {
2162+
if (!file_cache_only &&
2163+
ZCG(accelerator_enabled)) {
21662164

21672165
/* check if callback is called from include_once or it's a main request */
21682166
if ((!EG(current_execute_data) &&
@@ -2304,6 +2302,7 @@ int accel_activate(INIT_FUNC_ARGS)
23042302
zend_alter_ini_entry_chars(key, "0", 1, ZEND_INI_SYSTEM, ZEND_INI_STAGE_RUNTIME);
23052303
zend_string_release_ex(key, 0);
23062304
zend_accel_error(ACCEL_LOG_WARNING, "Can't cache files in chroot() directory with too big inode");
2305+
ZCG(accelerator_enabled) = 0;
23072306
return SUCCESS;
23082307
}
23092308
}
@@ -2365,12 +2364,15 @@ int accel_activate(INIT_FUNC_ARGS)
23652364
}
23662365
accel_restart_leave();
23672366
}
2368-
} else {
2367+
}
2368+
if (!ZCG(pcre_reseted)) {
23692369
reset_pcre = 1;
23702370
}
23712371
zend_shared_alloc_unlock();
23722372
}
23732373

2374+
ZCG(accelerator_enabled) = ZCSG(accelerator_enabled);
2375+
23742376
SHM_PROTECT();
23752377
HANDLE_UNBLOCK_INTERRUPTIONS();
23762378

@@ -2382,8 +2384,10 @@ int accel_activate(INIT_FUNC_ARGS)
23822384
realpath_cache_clean();
23832385

23842386
accel_reset_pcre_cache();
2387+
ZCG(pcre_reseted) = 0;
23852388
} else if (reset_pcre) {
23862389
accel_reset_pcre_cache();
2390+
ZCG(pcre_reseted) = 1;
23872391
}
23882392

23892393

ext/opcache/ZendAccelerator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ typedef struct _zend_accel_globals {
196196
int counted; /* the process uses shared memory */
197197
zend_bool enabled;
198198
zend_bool locked; /* thread obtained exclusive lock */
199+
zend_bool accelerator_enabled; /* accelerator enabled for current request */
200+
zend_bool pcre_reseted;
199201
HashTable bind_hash; /* prototype and zval lookup table */
200202
zend_accel_directives accel_directives;
201203
zend_string *cwd; /* current working directory or NULL */

ext/opcache/zend_accelerator_module.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
442442
{
443443
php_info_print_table_start();
444444

445-
if (ZCG(enabled) && accel_startup_ok &&
446-
((ZCG(counted) || ZCSG(accelerator_enabled)) || file_cache_only)
447-
) {
445+
if (ZCG(accelerator_enabled) || file_cache_only) {
448446
php_info_print_table_row(2, "Opcode Caching", "Up and Running");
449447
} else {
450448
php_info_print_table_row(2, "Opcode Caching", "Disabled");
@@ -553,7 +551,7 @@ static int accelerator_get_scripts(zval *return_value)
553551
struct timeval exec_time;
554552
struct timeval fetch_time;
555553

556-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
554+
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
557555
return 0;
558556
}
559557

@@ -615,7 +613,7 @@ static ZEND_FUNCTION(opcache_get_status)
615613
array_init(return_value);
616614

617615
/* Trivia */
618-
add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled)));
616+
add_assoc_bool(return_value, "opcache_enabled", ZCG(accelerator_enabled));
619617

620618
if (ZCG(accel_directives).file_cache) {
621619
add_assoc_string(return_value, "file_cache", ZCG(accel_directives).file_cache);
@@ -900,7 +898,7 @@ static ZEND_FUNCTION(opcache_is_script_cached)
900898
RETURN_FALSE;
901899
}
902900

903-
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
901+
if (!ZCG(accelerator_enabled)) {
904902
RETURN_FALSE;
905903
}
906904

0 commit comments

Comments
 (0)