diff options
| author | Dmitry Stogov <dmitry@zend.com> | 2018-03-06 03:00:46 +0300 |
|---|---|---|
| committer | Dmitry Stogov <dmitry@zend.com> | 2018-03-06 03:00:46 +0300 |
| commit | 44e1d2f8a990ecb0dd12c9ee69f8b6ea1d2914be (patch) | |
| tree | 555e0ea7503e76405bd7168189e001dde9a04b4e | |
| parent | 47f5f878260ede087a780402e1853afbe8dbf6cb (diff) | |
| parent | 020a02ef9d9bbd14d9f37a5d50020f2a4cbea778 (diff) | |
| download | php-git-44e1d2f8a990ecb0dd12c9ee69f8b6ea1d2914be.tar.gz | |
Merge branch 'PHP-7.2'
* PHP-7.2:
Replaced usafe reference from SHM to process memory with SHM to SHM reference.
| -rw-r--r-- | ext/opcache/ZendAccelerator.c | 13 | ||||
| -rw-r--r-- | ext/opcache/ZendAccelerator.h | 3 | ||||
| -rw-r--r-- | ext/opcache/zend_persist.c | 36 | ||||
| -rw-r--r-- | ext/opcache/zend_persist.h | 2 |
4 files changed, 45 insertions, 9 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index c822cefd3e..2061a34328 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1363,8 +1363,8 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script ZCG(mem) = zend_arena_alloc(&CG(arena), memory_used); #endif - /* Copy into shared memory */ - new_persistent_script = zend_accel_script_persist(new_persistent_script, NULL, 0); + /* Copy into memory block */ + new_persistent_script = zend_accel_script_persist(new_persistent_script, NULL, 0, 0); zend_shared_alloc_destroy_xlat_table(); @@ -1489,7 +1489,7 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr } /* Copy into shared memory */ - new_persistent_script = zend_accel_script_persist(new_persistent_script, &key, key_length); + new_persistent_script = zend_accel_script_persist(new_persistent_script, &key, key_length, 1); zend_shared_alloc_destroy_xlat_table(); @@ -2466,6 +2466,8 @@ static inline int accel_find_sapi(void) static int zend_accel_init_shm(void) { + int i; + zend_shared_alloc_lock(); if (ZCG(accel_directives).interned_strings_buffer) { @@ -2529,6 +2531,11 @@ static int zend_accel_init_shm(void) ZCSG(last_restart_time) = 0; ZCSG(restart_in_progress) = 0; + + for (i = 0; i < -HT_MIN_MASK; i++) { + ZCSG(uninitialized_bucket)[i] = HT_INVALID_IDX; + } + zend_shared_alloc_unlock(); return SUCCESS; diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 5f59f14b9b..378f38b363 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -285,6 +285,9 @@ typedef struct _zend_accel_shared_globals { #endif zend_bool restart_in_progress; + /* uninitialized HashTable Support */ + uint32_t uninitialized_bucket[-HT_MIN_MASK]; + /* Interned Strings Support (must be the last element) */ zend_string_table interned_strings; } zend_accel_shared_globals; diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 034067af09..890ba47c26 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -92,13 +92,21 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement ht->pDestructor = NULL; if (!(HT_FLAGS(ht) & HASH_FLAG_INITIALIZED)) { - HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) { + HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket)); + } else { + HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + } return; } if (ht->nNumUsed == 0) { efree(HT_GET_DATA_ADDR(ht)); ht->nTableMask = HT_MIN_MASK; - HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) { + HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket)); + } else { + HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + } HT_FLAGS(ht) &= ~HASH_FLAG_INITIALIZED; return; } @@ -179,13 +187,21 @@ static void zend_hash_persist_immutable(HashTable *ht) ht->pDestructor = NULL; if (!(HT_FLAGS(ht) & HASH_FLAG_INITIALIZED)) { - HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) { + HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket)); + } else { + HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + } return; } if (ht->nNumUsed == 0) { efree(HT_GET_DATA_ADDR(ht)); ht->nTableMask = HT_MIN_MASK; - HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) { + HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket)); + } else { + HT_SET_DATA_ADDR(ht, &uninitialized_bucket); + } HT_FLAGS(ht) &= ~HASH_FLAG_INITIALIZED; return; } @@ -863,9 +879,16 @@ static void zend_accel_persist_class_table(HashTable *class_table) zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce); } -zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length) +zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length, int for_shm) { script->mem = ZCG(mem); + script->corrupted = 0; + ZCG(current_persistent_script) = script; + + if (!for_shm) { + /* script is not going to be saved in SHM */ + script->corrupted = 1; + } ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */ zend_shared_alloc_clear_xlat_table(); @@ -890,6 +913,9 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script zend_hash_persist(&script->script.function_table, zend_persist_op_array); zend_persist_op_array_ex(&script->script.main_op_array, script); + script->corrupted = 0; + ZCG(current_persistent_script) = NULL; + return script; } diff --git a/ext/opcache/zend_persist.h b/ext/opcache/zend_persist.h index 73198403d6..6774c046f0 100644 --- a/ext/opcache/zend_persist.h +++ b/ext/opcache/zend_persist.h @@ -24,6 +24,6 @@ int zend_accel_script_persistable(zend_persistent_script *script); uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, const char *key, unsigned int key_length, int for_shm); -zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length); +zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length, int for_shm); #endif /* ZEND_PERSIST_H */ |
