2013-02-13 20:26:47 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2013-03-19 14:32:24 +08:00
|
|
|
| Zend OPcache |
|
2013-02-13 20:26:47 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2018-01-02 12:55:14 +08:00
|
|
|
| Copyright (c) 1998-2018 The PHP Group |
|
2013-02-13 20:26:47 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_01.txt |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
| Stanislav Malyshev <stas@zend.com> |
|
|
|
|
| Dmitry Stogov <dmitry@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zend.h"
|
|
|
|
#include "ZendAccelerator.h"
|
|
|
|
#include "zend_persist.h"
|
|
|
|
#include "zend_extensions.h"
|
|
|
|
#include "zend_shared_alloc.h"
|
|
|
|
#include "zend_vm.h"
|
|
|
|
#include "zend_constants.h"
|
|
|
|
#include "zend_operators.h"
|
|
|
|
|
|
|
|
#define zend_accel_store(p, size) \
|
2014-12-14 06:06:14 +08:00
|
|
|
(p = _zend_shared_memdup((void*)p, size, 1))
|
2013-02-13 20:26:47 +08:00
|
|
|
#define zend_accel_memdup(p, size) \
|
2014-12-14 06:06:14 +08:00
|
|
|
_zend_shared_memdup((void*)p, size, 0)
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2017-01-30 19:25:50 +08:00
|
|
|
#ifdef HAVE_OPCACHE_FILE_CACHE
|
|
|
|
#define zend_set_str_gc_flags(str) do { \
|
2018-03-05 21:01:43 +08:00
|
|
|
if (file_cache_only) { \
|
2017-01-30 19:25:50 +08:00
|
|
|
GC_FLAGS(str) = IS_STR_INTERNED; \
|
|
|
|
} else { \
|
|
|
|
GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define zend_set_str_gc_flags(str) GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT
|
|
|
|
#endif
|
|
|
|
|
2014-08-15 16:40:07 +08:00
|
|
|
#define zend_accel_store_string(str) do { \
|
2014-04-09 13:43:42 +08:00
|
|
|
zend_string *new_str = zend_shared_alloc_get_xlat_entry(str); \
|
|
|
|
if (new_str) { \
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_release(str); \
|
2014-04-09 13:43:42 +08:00
|
|
|
str = new_str; \
|
|
|
|
} else { \
|
2015-06-29 21:44:54 +08:00
|
|
|
new_str = zend_accel_memdup((void*)str, _ZSTR_STRUCT_SIZE(ZSTR_LEN(str))); \
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_release(str); \
|
2014-04-09 13:43:42 +08:00
|
|
|
str = new_str; \
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_hash_val(str); \
|
2017-01-30 19:25:50 +08:00
|
|
|
zend_set_str_gc_flags(str); \
|
2014-04-09 13:43:42 +08:00
|
|
|
} \
|
|
|
|
} while (0)
|
2014-08-15 16:40:07 +08:00
|
|
|
#define zend_accel_memdup_string(str) do { \
|
2015-06-29 21:44:54 +08:00
|
|
|
str = zend_accel_memdup(str, _ZSTR_STRUCT_SIZE(ZSTR_LEN(str))); \
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_hash_val(str); \
|
2017-01-30 19:25:50 +08:00
|
|
|
zend_set_str_gc_flags(str); \
|
2014-06-10 01:29:20 +08:00
|
|
|
} while (0)
|
2014-08-15 16:40:07 +08:00
|
|
|
#define zend_accel_store_interned_string(str) do { \
|
2014-04-09 13:43:42 +08:00
|
|
|
if (!IS_ACCEL_INTERNED(str)) { \
|
|
|
|
zend_accel_store_string(str); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2014-08-15 16:40:07 +08:00
|
|
|
#define zend_accel_memdup_interned_string(str) do { \
|
2014-06-10 01:29:20 +08:00
|
|
|
if (!IS_ACCEL_INTERNED(str)) { \
|
|
|
|
zend_accel_memdup_string(str); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
typedef void (*zend_persist_func_t)(zval*);
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_persist_zval(zval *z);
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2015-03-13 22:13:19 +08:00
|
|
|
static const uint32_t uninitialized_bucket[-HT_MIN_MASK] =
|
|
|
|
{HT_INVALID_IDX, HT_INVALID_IDX};
|
2013-05-29 03:45:36 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2015-04-21 05:27:21 +08:00
|
|
|
uint32_t idx, nIndex;
|
2014-02-10 14:04:30 +08:00
|
|
|
Bucket *p;
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2018-03-06 05:56:16 +08:00
|
|
|
ht->pDestructor = NULL;
|
|
|
|
|
2014-12-27 16:07:12 +08:00
|
|
|
if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) {
|
2018-03-06 07:43:26 +08:00
|
|
|
if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
|
|
|
|
HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
|
|
|
|
} else {
|
|
|
|
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
|
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-08-31 18:56:42 +08:00
|
|
|
if (ht->nNumUsed == 0) {
|
|
|
|
efree(HT_GET_DATA_ADDR(ht));
|
|
|
|
ht->nTableMask = HT_MIN_MASK;
|
2018-03-06 07:43:26 +08:00
|
|
|
if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
|
|
|
|
HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
|
|
|
|
} else {
|
|
|
|
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
|
|
|
|
}
|
2015-08-31 18:56:42 +08:00
|
|
|
ht->u.flags &= ~HASH_FLAG_INITIALIZED;
|
|
|
|
return;
|
|
|
|
}
|
2014-04-21 22:25:34 +08:00
|
|
|
if (ht->u.flags & HASH_FLAG_PACKED) {
|
2015-03-13 22:13:19 +08:00
|
|
|
void *data = HT_GET_DATA_ADDR(ht);
|
|
|
|
zend_accel_store(data, HT_USED_SIZE(ht));
|
|
|
|
HT_SET_DATA_ADDR(ht, data);
|
2016-06-22 01:12:29 +08:00
|
|
|
} else if (ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 2) {
|
2015-04-21 05:27:21 +08:00
|
|
|
/* compact table */
|
|
|
|
void *old_data = HT_GET_DATA_ADDR(ht);
|
|
|
|
Bucket *old_buckets = ht->arData;
|
2016-06-22 01:12:29 +08:00
|
|
|
uint32_t hash_size;
|
2015-09-02 18:03:31 +08:00
|
|
|
|
|
|
|
if (ht->nNumUsed <= HT_MIN_SIZE) {
|
|
|
|
hash_size = HT_MIN_SIZE;
|
|
|
|
} else {
|
2016-06-22 01:12:29 +08:00
|
|
|
hash_size = (uint32_t)(-(int32_t)ht->nTableMask);
|
2015-09-02 18:03:31 +08:00
|
|
|
while (hash_size >> 1 > ht->nNumUsed) {
|
|
|
|
hash_size >>= 1;
|
|
|
|
}
|
2015-08-31 18:56:42 +08:00
|
|
|
}
|
2016-06-22 01:12:29 +08:00
|
|
|
ht->nTableMask = (uint32_t)(-(int32_t)hash_size);
|
2015-08-31 18:56:42 +08:00
|
|
|
ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
|
2015-04-21 05:27:21 +08:00
|
|
|
HT_SET_DATA_ADDR(ht, ZCG(mem));
|
2015-06-20 15:18:00 +08:00
|
|
|
ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE((hash_size * sizeof(uint32_t)) + (ht->nNumUsed * sizeof(Bucket))));
|
2015-04-21 05:27:21 +08:00
|
|
|
HT_HASH_RESET(ht);
|
|
|
|
memcpy(ht->arData, old_buckets, ht->nNumUsed * sizeof(Bucket));
|
|
|
|
efree(old_data);
|
|
|
|
|
|
|
|
for (idx = 0; idx < ht->nNumUsed; idx++) {
|
|
|
|
p = ht->arData + idx;
|
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
|
|
|
|
/* persist bucket and key */
|
|
|
|
if (p->key) {
|
|
|
|
zend_accel_store_interned_string(p->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* persist the data itself */
|
|
|
|
pPersistElement(&p->val);
|
|
|
|
|
|
|
|
nIndex = p->h | ht->nTableMask;
|
|
|
|
Z_NEXT(p->val) = HT_HASH(ht, nIndex);
|
|
|
|
HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
|
|
|
|
}
|
|
|
|
return;
|
2014-04-07 22:22:03 +08:00
|
|
|
} else {
|
2015-03-13 22:13:19 +08:00
|
|
|
void *data = ZCG(mem);
|
|
|
|
void *old_data = HT_GET_DATA_ADDR(ht);
|
|
|
|
|
2015-08-31 18:56:42 +08:00
|
|
|
ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
|
2016-09-05 05:33:32 +08:00
|
|
|
ZCG(mem) = (void*)((char*)data + ZEND_ALIGNED_SIZE(HT_USED_SIZE(ht)));
|
2015-03-13 22:13:19 +08:00
|
|
|
memcpy(data, old_data, HT_USED_SIZE(ht));
|
|
|
|
efree(old_data);
|
|
|
|
HT_SET_DATA_ADDR(ht, data);
|
2014-02-10 14:04:30 +08:00
|
|
|
}
|
2015-03-13 22:13:19 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
for (idx = 0; idx < ht->nNumUsed; idx++) {
|
|
|
|
p = ht->arData + idx;
|
2014-03-29 03:34:49 +08:00
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
2013-02-13 20:26:47 +08:00
|
|
|
|
|
|
|
/* persist bucket and key */
|
2014-03-29 03:34:49 +08:00
|
|
|
if (p->key) {
|
|
|
|
zend_accel_store_interned_string(p->key);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* persist the data itself */
|
2014-12-14 06:06:14 +08:00
|
|
|
pPersistElement(&p->val);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_hash_persist_immutable(HashTable *ht)
|
2014-05-29 22:21:56 +08:00
|
|
|
{
|
2015-04-21 05:27:21 +08:00
|
|
|
uint32_t idx, nIndex;
|
2014-05-29 22:21:56 +08:00
|
|
|
Bucket *p;
|
|
|
|
|
2018-03-06 05:56:16 +08:00
|
|
|
ht->pDestructor = NULL;
|
|
|
|
|
2014-12-27 16:07:12 +08:00
|
|
|
if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) {
|
2018-03-06 07:43:26 +08:00
|
|
|
if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
|
|
|
|
HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
|
|
|
|
} else {
|
|
|
|
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
|
|
|
|
}
|
2014-05-29 22:21:56 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-08-31 18:56:42 +08:00
|
|
|
if (ht->nNumUsed == 0) {
|
|
|
|
efree(HT_GET_DATA_ADDR(ht));
|
|
|
|
ht->nTableMask = HT_MIN_MASK;
|
2018-03-06 07:43:26 +08:00
|
|
|
if (EXPECTED(!ZCG(current_persistent_script)->corrupted)) {
|
|
|
|
HT_SET_DATA_ADDR(ht, &ZCSG(uninitialized_bucket));
|
|
|
|
} else {
|
|
|
|
HT_SET_DATA_ADDR(ht, &uninitialized_bucket);
|
|
|
|
}
|
2015-08-31 18:56:42 +08:00
|
|
|
ht->u.flags &= ~HASH_FLAG_INITIALIZED;
|
|
|
|
return;
|
|
|
|
}
|
2014-05-29 22:21:56 +08:00
|
|
|
if (ht->u.flags & HASH_FLAG_PACKED) {
|
2015-03-13 22:13:19 +08:00
|
|
|
HT_SET_DATA_ADDR(ht, zend_accel_memdup(HT_GET_DATA_ADDR(ht), HT_USED_SIZE(ht)));
|
2016-06-22 01:12:29 +08:00
|
|
|
} else if (ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 2) {
|
2015-04-21 05:27:21 +08:00
|
|
|
/* compact table */
|
|
|
|
void *old_data = HT_GET_DATA_ADDR(ht);
|
|
|
|
Bucket *old_buckets = ht->arData;
|
2016-06-22 01:12:29 +08:00
|
|
|
uint32_t hash_size;
|
2015-09-02 18:03:31 +08:00
|
|
|
|
|
|
|
if (ht->nNumUsed <= HT_MIN_SIZE) {
|
|
|
|
hash_size = HT_MIN_SIZE;
|
|
|
|
} else {
|
2016-06-22 01:12:29 +08:00
|
|
|
hash_size = (uint32_t)(-(int32_t)ht->nTableMask);
|
2015-09-02 18:03:31 +08:00
|
|
|
while (hash_size >> 1 > ht->nNumUsed) {
|
|
|
|
hash_size >>= 1;
|
|
|
|
}
|
2015-08-31 18:56:42 +08:00
|
|
|
}
|
2016-06-22 01:12:29 +08:00
|
|
|
ht->nTableMask = (uint32_t)(-(int32_t)hash_size);
|
2015-08-31 18:56:42 +08:00
|
|
|
ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
|
2015-04-21 05:27:21 +08:00
|
|
|
HT_SET_DATA_ADDR(ht, ZCG(mem));
|
|
|
|
ZCG(mem) = (void*)((char*)ZCG(mem) + (hash_size * sizeof(uint32_t)) + (ht->nNumUsed * sizeof(Bucket)));
|
|
|
|
HT_HASH_RESET(ht);
|
|
|
|
memcpy(ht->arData, old_buckets, ht->nNumUsed * sizeof(Bucket));
|
|
|
|
efree(old_data);
|
|
|
|
|
|
|
|
for (idx = 0; idx < ht->nNumUsed; idx++) {
|
|
|
|
p = ht->arData + idx;
|
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
|
|
|
|
/* persist bucket and key */
|
|
|
|
if (p->key) {
|
|
|
|
zend_accel_memdup_interned_string(p->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* persist the data itself */
|
2016-04-28 09:13:34 +08:00
|
|
|
zend_persist_zval(&p->val);
|
2015-04-21 05:27:21 +08:00
|
|
|
|
|
|
|
nIndex = p->h | ht->nTableMask;
|
|
|
|
Z_NEXT(p->val) = HT_HASH(ht, nIndex);
|
|
|
|
HT_HASH(ht, nIndex) = HT_IDX_TO_HASH(idx);
|
|
|
|
}
|
|
|
|
return;
|
2014-05-29 22:21:56 +08:00
|
|
|
} else {
|
2015-03-13 22:13:19 +08:00
|
|
|
void *data = ZCG(mem);
|
|
|
|
|
2015-08-31 18:56:42 +08:00
|
|
|
ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
|
2016-09-05 05:33:32 +08:00
|
|
|
ZCG(mem) = (void*)((char*)data + ZEND_ALIGNED_SIZE(HT_USED_SIZE(ht)));
|
2015-03-13 22:13:19 +08:00
|
|
|
memcpy(data, HT_GET_DATA_ADDR(ht), HT_USED_SIZE(ht));
|
|
|
|
HT_SET_DATA_ADDR(ht, data);
|
2014-05-29 22:21:56 +08:00
|
|
|
}
|
|
|
|
for (idx = 0; idx < ht->nNumUsed; idx++) {
|
|
|
|
p = ht->arData + idx;
|
|
|
|
if (Z_TYPE(p->val) == IS_UNDEF) continue;
|
|
|
|
|
|
|
|
/* persist bucket and key */
|
|
|
|
if (p->key) {
|
2014-06-10 01:29:20 +08:00
|
|
|
zend_accel_memdup_interned_string(p->key);
|
2014-05-29 22:21:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* persist the data itself */
|
2016-04-28 09:13:34 +08:00
|
|
|
zend_persist_zval(&p->val);
|
2014-05-29 22:21:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_ast *zend_persist_ast(zend_ast *ast)
|
2013-11-07 02:21:07 +08:00
|
|
|
{
|
2014-08-26 03:21:16 +08:00
|
|
|
uint32_t i;
|
2013-11-07 02:21:07 +08:00
|
|
|
zend_ast *node;
|
|
|
|
|
2014-08-16 04:02:53 +08:00
|
|
|
if (ast->kind == ZEND_AST_ZVAL) {
|
|
|
|
zend_ast_zval *copy = zend_accel_memdup(ast, sizeof(zend_ast_zval));
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_persist_zval(©->val);
|
2014-08-16 04:02:53 +08:00
|
|
|
node = (zend_ast *) copy;
|
|
|
|
} else if (zend_ast_is_list(ast)) {
|
|
|
|
zend_ast_list *list = zend_ast_get_list(ast);
|
|
|
|
zend_ast_list *copy = zend_accel_memdup(ast,
|
2014-08-26 19:57:19 +08:00
|
|
|
sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * list->children);
|
2014-08-16 04:02:53 +08:00
|
|
|
for (i = 0; i < list->children; i++) {
|
|
|
|
if (copy->child[i]) {
|
2014-12-14 06:06:14 +08:00
|
|
|
copy->child[i] = zend_persist_ast(copy->child[i]);
|
2014-08-16 04:02:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
node = (zend_ast *) copy;
|
2013-11-07 02:21:07 +08:00
|
|
|
} else {
|
2014-08-26 03:21:16 +08:00
|
|
|
uint32_t children = zend_ast_get_num_children(ast);
|
2014-08-26 19:57:19 +08:00
|
|
|
node = zend_accel_memdup(ast, sizeof(zend_ast) - sizeof(zend_ast *) + sizeof(zend_ast *) * children);
|
2014-08-16 04:02:53 +08:00
|
|
|
for (i = 0; i < children; i++) {
|
|
|
|
if (node->child[i]) {
|
2014-12-14 06:06:14 +08:00
|
|
|
node->child[i] = zend_persist_ast(node->child[i]);
|
2013-11-07 02:21:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 04:02:53 +08:00
|
|
|
|
2013-11-07 02:21:07 +08:00
|
|
|
efree(ast);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_persist_zval(zval *z)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2014-03-29 03:34:49 +08:00
|
|
|
void *new_ptr;
|
|
|
|
|
2014-04-03 19:26:23 +08:00
|
|
|
switch (Z_TYPE_P(z)) {
|
2013-02-13 20:26:47 +08:00
|
|
|
case IS_STRING:
|
|
|
|
case IS_CONSTANT:
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(Z_STR_P(z));
|
2017-03-04 17:39:13 +08:00
|
|
|
Z_TYPE_FLAGS_P(z) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
|
2014-06-10 01:29:20 +08:00
|
|
|
break;
|
2013-02-13 20:26:47 +08:00
|
|
|
case IS_ARRAY:
|
2014-03-29 03:34:49 +08:00
|
|
|
new_ptr = zend_shared_alloc_get_xlat_entry(Z_ARR_P(z));
|
|
|
|
if (new_ptr) {
|
|
|
|
Z_ARR_P(z) = new_ptr;
|
2016-11-29 03:59:57 +08:00
|
|
|
Z_TYPE_FLAGS_P(z) = IS_TYPE_COPYABLE;
|
2014-03-29 03:34:49 +08:00
|
|
|
} else {
|
2016-11-29 03:59:57 +08:00
|
|
|
if (!Z_REFCOUNTED_P(z)) {
|
2014-05-29 22:21:56 +08:00
|
|
|
Z_ARR_P(z) = zend_accel_memdup(Z_ARR_P(z), sizeof(zend_array));
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_hash_persist_immutable(Z_ARRVAL_P(z));
|
2014-05-29 22:21:56 +08:00
|
|
|
} else {
|
2014-09-09 04:40:14 +08:00
|
|
|
GC_REMOVE_FROM_BUFFER(Z_ARR_P(z));
|
2014-05-29 22:21:56 +08:00
|
|
|
zend_accel_store(Z_ARR_P(z), sizeof(zend_array));
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_hash_persist(Z_ARRVAL_P(z), zend_persist_zval);
|
2014-08-05 19:38:43 +08:00
|
|
|
/* make immutable array */
|
2016-11-29 03:59:57 +08:00
|
|
|
Z_TYPE_FLAGS_P(z) = IS_TYPE_COPYABLE;
|
2014-08-05 19:38:43 +08:00
|
|
|
GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
|
2015-02-20 18:28:26 +08:00
|
|
|
GC_FLAGS(Z_COUNTED_P(z)) |= IS_ARRAY_IMMUTABLE;
|
2015-04-24 14:34:50 +08:00
|
|
|
Z_ARRVAL_P(z)->u.flags |= HASH_FLAG_STATIC_KEYS;
|
2014-08-05 19:38:43 +08:00
|
|
|
Z_ARRVAL_P(z)->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
|
2014-05-29 22:21:56 +08:00
|
|
|
}
|
2014-03-29 03:34:49 +08:00
|
|
|
}
|
2013-02-13 20:26:47 +08:00
|
|
|
break;
|
2014-03-29 03:34:49 +08:00
|
|
|
case IS_REFERENCE:
|
|
|
|
new_ptr = zend_shared_alloc_get_xlat_entry(Z_REF_P(z));
|
|
|
|
if (new_ptr) {
|
|
|
|
Z_REF_P(z) = new_ptr;
|
|
|
|
} else {
|
|
|
|
zend_accel_store(Z_REF_P(z), sizeof(zend_reference));
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_persist_zval(Z_REFVAL_P(z));
|
2014-03-29 03:34:49 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-11-07 02:21:07 +08:00
|
|
|
case IS_CONSTANT_AST:
|
2014-03-29 03:34:49 +08:00
|
|
|
new_ptr = zend_shared_alloc_get_xlat_entry(Z_AST_P(z));
|
|
|
|
if (new_ptr) {
|
|
|
|
Z_AST_P(z) = new_ptr;
|
2016-11-29 03:59:57 +08:00
|
|
|
Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_COPYABLE;
|
2014-03-29 03:34:49 +08:00
|
|
|
} else {
|
|
|
|
zend_accel_store(Z_AST_P(z), sizeof(zend_ast_ref));
|
2014-12-14 06:06:14 +08:00
|
|
|
Z_ASTVAL_P(z) = zend_persist_ast(Z_ASTVAL_P(z));
|
2016-11-29 03:59:57 +08:00
|
|
|
Z_TYPE_FLAGS_P(z) = IS_TYPE_CONSTANT | IS_TYPE_COPYABLE;
|
2015-02-20 18:28:26 +08:00
|
|
|
GC_REFCOUNT(Z_COUNTED_P(z)) = 2;
|
2014-03-29 03:34:49 +08:00
|
|
|
}
|
2013-11-07 02:21:07 +08:00
|
|
|
break;
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_script* main_persistent_script)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2014-04-16 17:36:38 +08:00
|
|
|
int already_stored = 0;
|
2013-02-13 20:26:47 +08:00
|
|
|
zend_op *persist_ptr;
|
2014-04-17 19:40:45 +08:00
|
|
|
zval *orig_literals = NULL;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2013-02-13 20:26:47 +08:00
|
|
|
if (op_array->type != ZEND_USER_FUNCTION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:59:30 +08:00
|
|
|
if (op_array->refcount && --(*op_array->refcount) == 0) {
|
2013-02-13 20:26:47 +08:00
|
|
|
efree(op_array->refcount);
|
|
|
|
}
|
|
|
|
op_array->refcount = NULL;
|
|
|
|
|
|
|
|
if (main_persistent_script) {
|
2014-07-03 02:03:21 +08:00
|
|
|
zend_execute_data *orig_execute_data = EG(current_execute_data);
|
|
|
|
zend_execute_data fake_execute_data;
|
2014-04-25 04:56:15 +08:00
|
|
|
zval *offset;
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2014-07-03 02:03:21 +08:00
|
|
|
memset(&fake_execute_data, 0, sizeof(fake_execute_data));
|
|
|
|
fake_execute_data.func = (zend_function*)op_array;
|
|
|
|
EG(current_execute_data) = &fake_execute_data;
|
2014-12-14 06:06:14 +08:00
|
|
|
if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1)) != NULL) {
|
2014-04-25 04:56:15 +08:00
|
|
|
main_persistent_script->compiler_halt_offset = Z_LVAL_P(offset);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
2014-07-03 02:03:21 +08:00
|
|
|
EG(current_execute_data) = orig_execute_data;
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
2014-04-16 17:36:38 +08:00
|
|
|
if (op_array->static_variables) {
|
2015-02-20 18:28:26 +08:00
|
|
|
HashTable *stored = zend_shared_alloc_get_xlat_entry(op_array->static_variables);
|
|
|
|
|
|
|
|
if (stored) {
|
|
|
|
op_array->static_variables = stored;
|
|
|
|
} else {
|
2016-04-28 09:13:34 +08:00
|
|
|
zend_hash_persist(op_array->static_variables, zend_persist_zval);
|
2015-02-20 18:28:26 +08:00
|
|
|
zend_accel_store(op_array->static_variables, sizeof(HashTable));
|
|
|
|
/* make immutable array */
|
|
|
|
GC_REFCOUNT(op_array->static_variables) = 2;
|
|
|
|
GC_TYPE_INFO(op_array->static_variables) = IS_ARRAY | (IS_ARRAY_IMMUTABLE << 8);
|
2015-04-24 14:34:50 +08:00
|
|
|
op_array->static_variables->u.flags |= HASH_FLAG_STATIC_KEYS;
|
2015-02-20 18:28:26 +08:00
|
|
|
op_array->static_variables->u.flags &= ~HASH_FLAG_APPLY_PROTECTION;
|
|
|
|
}
|
2014-04-16 17:36:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (zend_shared_alloc_get_xlat_entry(op_array->opcodes)) {
|
|
|
|
already_stored = 1;
|
|
|
|
}
|
|
|
|
|
2013-02-13 20:26:47 +08:00
|
|
|
if (op_array->literals) {
|
2014-04-16 17:36:38 +08:00
|
|
|
if (already_stored) {
|
|
|
|
orig_literals = zend_shared_alloc_get_xlat_entry(op_array->literals);
|
|
|
|
ZEND_ASSERT(orig_literals != NULL);
|
2013-02-13 20:26:47 +08:00
|
|
|
op_array->literals = orig_literals;
|
|
|
|
} else {
|
2014-04-17 19:40:45 +08:00
|
|
|
zval *p = zend_accel_memdup(op_array->literals, sizeof(zval) * op_array->last_literal);
|
|
|
|
zval *end = p + op_array->last_literal;
|
2013-02-13 20:26:47 +08:00
|
|
|
orig_literals = op_array->literals;
|
|
|
|
op_array->literals = p;
|
|
|
|
while (p < end) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_persist_zval(p);
|
2013-02-13 20:26:47 +08:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
efree(orig_literals);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 17:36:38 +08:00
|
|
|
if (already_stored) {
|
|
|
|
persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->opcodes);
|
|
|
|
ZEND_ASSERT(persist_ptr != NULL);
|
2013-02-13 20:26:47 +08:00
|
|
|
op_array->opcodes = persist_ptr;
|
|
|
|
} else {
|
|
|
|
zend_op *new_opcodes = zend_accel_memdup(op_array->opcodes, sizeof(zend_op) * op_array->last);
|
2014-12-12 15:19:41 +08:00
|
|
|
#if ZEND_USE_ABS_CONST_ADDR || ZEND_USE_ABS_JMP_ADDR
|
2013-02-13 20:26:47 +08:00
|
|
|
zend_op *opline = new_opcodes;
|
|
|
|
zend_op *end = new_opcodes + op_array->last;
|
|
|
|
int offset = 0;
|
|
|
|
|
2013-02-25 15:29:54 +08:00
|
|
|
for (; opline < end ; opline++, offset++) {
|
2014-12-12 15:19:41 +08:00
|
|
|
# if ZEND_USE_ABS_CONST_ADDR
|
2015-11-12 07:02:24 +08:00
|
|
|
if (opline->op1_type == IS_CONST) {
|
2013-02-13 20:26:47 +08:00
|
|
|
opline->op1.zv = (zval*)((char*)opline->op1.zv + ((char*)op_array->literals - (char*)orig_literals));
|
|
|
|
}
|
2015-11-12 07:02:24 +08:00
|
|
|
if (opline->op2_type == IS_CONST) {
|
2013-02-13 20:26:47 +08:00
|
|
|
opline->op2.zv = (zval*)((char*)opline->op2.zv + ((char*)op_array->literals - (char*)orig_literals));
|
|
|
|
}
|
2014-12-12 15:19:41 +08:00
|
|
|
# endif
|
|
|
|
# if ZEND_USE_ABS_JMP_ADDR
|
2015-11-12 07:02:24 +08:00
|
|
|
if (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO) {
|
2013-03-12 02:49:05 +08:00
|
|
|
/* fix jumps to point to new array */
|
2013-02-13 20:26:47 +08:00
|
|
|
switch (opline->opcode) {
|
|
|
|
case ZEND_JMP:
|
|
|
|
case ZEND_FAST_CALL:
|
2015-11-12 07:02:24 +08:00
|
|
|
opline->op1.jmp_addr = &new_opcodes[opline->op1.jmp_addr - op_array->opcodes];
|
2013-02-13 20:26:47 +08:00
|
|
|
break;
|
2014-04-30 15:23:19 +08:00
|
|
|
case ZEND_JMPZNZ:
|
|
|
|
/* relative extended_value don't have to be changed */
|
|
|
|
/* break omitted intentionally */
|
2013-02-13 20:26:47 +08:00
|
|
|
case ZEND_JMPZ:
|
|
|
|
case ZEND_JMPNZ:
|
|
|
|
case ZEND_JMPZ_EX:
|
|
|
|
case ZEND_JMPNZ_EX:
|
|
|
|
case ZEND_JMP_SET:
|
2014-09-28 18:31:52 +08:00
|
|
|
case ZEND_COALESCE:
|
2015-02-12 18:57:12 +08:00
|
|
|
case ZEND_FE_RESET_R:
|
|
|
|
case ZEND_FE_RESET_RW:
|
2015-03-02 17:25:40 +08:00
|
|
|
case ZEND_ASSERT_CHECK:
|
2015-11-12 07:02:24 +08:00
|
|
|
opline->op2.jmp_addr = &new_opcodes[opline->op2.jmp_addr - op_array->opcodes];
|
2013-02-13 20:26:47 +08:00
|
|
|
break;
|
2015-12-20 20:42:26 +08:00
|
|
|
case ZEND_DECLARE_ANON_CLASS:
|
|
|
|
case ZEND_DECLARE_ANON_INHERITED_CLASS:
|
2015-05-13 17:55:42 +08:00
|
|
|
case ZEND_FE_FETCH_R:
|
|
|
|
case ZEND_FE_FETCH_RW:
|
2017-03-18 06:45:05 +08:00
|
|
|
case ZEND_SWITCH_LONG:
|
|
|
|
case ZEND_SWITCH_STRING:
|
2015-05-13 17:55:42 +08:00
|
|
|
/* relative extended_value don't have to be changed */
|
|
|
|
break;
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-12 15:19:41 +08:00
|
|
|
# endif
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
2014-12-12 15:19:41 +08:00
|
|
|
#endif
|
2013-02-13 20:26:47 +08:00
|
|
|
|
|
|
|
efree(op_array->opcodes);
|
|
|
|
op_array->opcodes = new_opcodes;
|
|
|
|
|
|
|
|
if (op_array->run_time_cache) {
|
|
|
|
efree(op_array->run_time_cache);
|
|
|
|
op_array->run_time_cache = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 17:36:38 +08:00
|
|
|
if (op_array->function_name && !IS_ACCEL_INTERNED(op_array->function_name)) {
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_string *new_name;
|
2014-04-16 17:36:38 +08:00
|
|
|
if (already_stored) {
|
|
|
|
new_name = zend_shared_alloc_get_xlat_entry(op_array->function_name);
|
|
|
|
ZEND_ASSERT(new_name != NULL);
|
2013-02-13 20:26:47 +08:00
|
|
|
op_array->function_name = new_name;
|
|
|
|
} else {
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_accel_store_interned_string(op_array->function_name);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 17:36:38 +08:00
|
|
|
if (op_array->filename) {
|
|
|
|
/* do not free! PHP has centralized filename storage, compiler will free it */
|
2014-06-10 01:29:20 +08:00
|
|
|
zend_accel_memdup_string(op_array->filename);
|
2014-04-16 17:36:38 +08:00
|
|
|
}
|
|
|
|
|
2013-02-13 20:26:47 +08:00
|
|
|
if (op_array->arg_info) {
|
2015-01-09 04:40:36 +08:00
|
|
|
zend_arg_info *arg_info = op_array->arg_info;
|
|
|
|
uint32_t num_args = op_array->num_args;
|
|
|
|
|
|
|
|
if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
|
|
|
|
arg_info--;
|
|
|
|
num_args++;
|
|
|
|
}
|
2014-04-16 17:36:38 +08:00
|
|
|
if (already_stored) {
|
2015-01-09 04:40:36 +08:00
|
|
|
arg_info = zend_shared_alloc_get_xlat_entry(arg_info);
|
|
|
|
ZEND_ASSERT(arg_info != NULL);
|
2013-02-13 20:26:47 +08:00
|
|
|
} else {
|
2015-01-09 04:40:36 +08:00
|
|
|
uint32_t i;
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2014-12-22 21:44:39 +08:00
|
|
|
if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
|
|
|
|
num_args++;
|
|
|
|
}
|
2015-01-09 04:40:36 +08:00
|
|
|
zend_accel_store(arg_info, sizeof(zend_arg_info) * num_args);
|
2014-12-22 21:44:39 +08:00
|
|
|
for (i = 0; i < num_args; i++) {
|
2015-01-09 04:40:36 +08:00
|
|
|
if (arg_info[i].name) {
|
|
|
|
zend_accel_store_interned_string(arg_info[i].name);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
2017-01-13 16:37:46 +08:00
|
|
|
if (ZEND_TYPE_IS_CLASS(arg_info[i].type)) {
|
|
|
|
zend_string *type_name = ZEND_TYPE_NAME(arg_info[i].type);
|
|
|
|
zend_bool allow_null = ZEND_TYPE_ALLOW_NULL(arg_info[i].type);
|
|
|
|
|
|
|
|
zend_accel_store_interned_string(type_name);
|
|
|
|
arg_info[i].type = ZEND_TYPE_ENCODE_CLASS(type_name, allow_null);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 04:40:36 +08:00
|
|
|
if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
|
|
|
|
arg_info++;
|
|
|
|
}
|
|
|
|
op_array->arg_info = arg_info;
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 02:48:03 +08:00
|
|
|
if (op_array->live_range) {
|
|
|
|
zend_accel_store(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
|
2015-07-10 08:31:52 +08:00
|
|
|
}
|
|
|
|
|
2013-02-22 14:56:05 +08:00
|
|
|
if (op_array->scope) {
|
2013-02-13 20:26:47 +08:00
|
|
|
op_array->scope = zend_shared_alloc_get_xlat_entry(op_array->scope);
|
|
|
|
}
|
|
|
|
|
2013-02-22 14:56:05 +08:00
|
|
|
if (op_array->doc_comment) {
|
2013-02-13 20:26:47 +08:00
|
|
|
if (ZCG(accel_directives).save_comments) {
|
2014-05-06 01:56:05 +08:00
|
|
|
if (already_stored) {
|
|
|
|
op_array->doc_comment = zend_shared_alloc_get_xlat_entry(op_array->doc_comment);
|
|
|
|
ZEND_ASSERT(op_array->doc_comment != NULL);
|
|
|
|
} else {
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_accel_store_interned_string(op_array->doc_comment);
|
2014-05-06 01:56:05 +08:00
|
|
|
}
|
2013-02-13 20:26:47 +08:00
|
|
|
} else {
|
2014-04-16 17:36:38 +08:00
|
|
|
if (!already_stored) {
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_release(op_array->doc_comment);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
op_array->doc_comment = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 14:56:05 +08:00
|
|
|
if (op_array->try_catch_array) {
|
2013-02-13 20:26:47 +08:00
|
|
|
zend_accel_store(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch);
|
|
|
|
}
|
|
|
|
|
2013-02-22 14:56:05 +08:00
|
|
|
if (op_array->vars) {
|
2014-04-16 17:36:38 +08:00
|
|
|
if (already_stored) {
|
|
|
|
persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->vars);
|
|
|
|
ZEND_ASSERT(persist_ptr != NULL);
|
2014-03-29 03:34:49 +08:00
|
|
|
op_array->vars = (zend_string**)persist_ptr;
|
2013-02-13 20:26:47 +08:00
|
|
|
} else {
|
|
|
|
int i;
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store(op_array->vars, sizeof(zend_string*) * op_array->last_var);
|
2013-02-22 14:56:05 +08:00
|
|
|
for (i = 0; i < op_array->last_var; i++) {
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(op_array->vars[i]);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "prototype" may be undefined if "scope" isn't set */
|
2013-02-22 14:56:05 +08:00
|
|
|
if (op_array->scope && op_array->prototype) {
|
2013-02-13 20:26:47 +08:00
|
|
|
if ((persist_ptr = zend_shared_alloc_get_xlat_entry(op_array->prototype))) {
|
|
|
|
op_array->prototype = (union _zend_function*)persist_ptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
op_array->prototype = NULL;
|
|
|
|
}
|
2015-09-25 16:50:38 +08:00
|
|
|
|
|
|
|
ZCG(mem) = (void*)((char*)ZCG(mem) + ZEND_ALIGNED_SIZE(zend_extensions_op_array_persist(op_array, ZCG(mem))));
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_persist_op_array(zval *zv)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2015-03-05 19:23:48 +08:00
|
|
|
zend_op_array *op_array = Z_PTR_P(zv);
|
|
|
|
zend_op_array *old_op_array = zend_shared_alloc_get_xlat_entry(op_array);
|
|
|
|
if (old_op_array) {
|
|
|
|
Z_PTR_P(zv) = old_op_array;
|
|
|
|
if (op_array->refcount && --(*op_array->refcount) == 0) {
|
|
|
|
efree(op_array->refcount);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-10-09 18:01:19 +08:00
|
|
|
memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_op_array));
|
|
|
|
zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
|
|
|
|
Z_PTR_P(zv) = ZCG(arena_mem);
|
|
|
|
ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_op_array)));
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_persist_op_array_ex(Z_PTR_P(zv), NULL);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_persist_property_info(zval *zv)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2015-03-04 22:41:01 +08:00
|
|
|
zend_property_info *prop = zend_shared_alloc_get_xlat_entry(Z_PTR_P(zv));
|
2014-03-29 03:34:49 +08:00
|
|
|
|
2015-03-04 22:41:01 +08:00
|
|
|
if (prop) {
|
|
|
|
Z_PTR_P(zv) = prop;
|
|
|
|
return;
|
|
|
|
}
|
2014-10-09 18:01:19 +08:00
|
|
|
memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_property_info));
|
|
|
|
zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
|
|
|
|
prop = Z_PTR_P(zv) = ZCG(arena_mem);
|
|
|
|
ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_property_info)));
|
2015-03-04 22:41:01 +08:00
|
|
|
prop->ce = zend_shared_alloc_get_xlat_entry(prop->ce);
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(prop->name);
|
2013-02-22 14:56:05 +08:00
|
|
|
if (prop->doc_comment) {
|
2013-02-13 20:26:47 +08:00
|
|
|
if (ZCG(accel_directives).save_comments) {
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_accel_store_interned_string(prop->doc_comment);
|
2013-02-13 20:26:47 +08:00
|
|
|
} else {
|
2013-02-22 14:56:05 +08:00
|
|
|
if (!zend_shared_alloc_get_xlat_entry(prop->doc_comment)) {
|
2013-02-13 20:26:47 +08:00
|
|
|
zend_shared_alloc_register_xlat_entry(prop->doc_comment, prop->doc_comment);
|
|
|
|
}
|
2014-08-26 01:24:55 +08:00
|
|
|
zend_string_release(prop->doc_comment);
|
2013-02-13 20:26:47 +08:00
|
|
|
prop->doc_comment = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 17:40:42 +08:00
|
|
|
static void zend_persist_class_constant(zval *zv)
|
|
|
|
{
|
|
|
|
zend_class_constant *c = zend_shared_alloc_get_xlat_entry(Z_PTR_P(zv));
|
|
|
|
|
|
|
|
if (c) {
|
|
|
|
Z_PTR_P(zv) = c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_class_constant));
|
|
|
|
zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
|
|
|
|
c = Z_PTR_P(zv) = ZCG(arena_mem);
|
|
|
|
ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_class_constant)));
|
|
|
|
zend_persist_zval(&c->value);
|
|
|
|
c->ce = zend_shared_alloc_get_xlat_entry(c->ce);
|
|
|
|
if (c->doc_comment) {
|
|
|
|
if (ZCG(accel_directives).save_comments) {
|
|
|
|
zend_string *doc_comment = zend_shared_alloc_get_xlat_entry(c->doc_comment);
|
|
|
|
if (doc_comment) {
|
|
|
|
c->doc_comment = doc_comment;
|
|
|
|
} else {
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_accel_store_interned_string(c->doc_comment);
|
2015-12-08 17:40:42 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zend_string *doc_comment = zend_shared_alloc_get_xlat_entry(c->doc_comment);
|
|
|
|
if (!doc_comment) {
|
|
|
|
zend_shared_alloc_register_xlat_entry(c->doc_comment, c->doc_comment);
|
|
|
|
zend_string_release(c->doc_comment);
|
|
|
|
}
|
|
|
|
c->doc_comment = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_persist_class_entry(zval *zv)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_class_entry *ce = Z_PTR_P(zv);
|
2013-02-13 20:26:47 +08:00
|
|
|
|
|
|
|
if (ce->type == ZEND_USER_CLASS) {
|
2014-10-09 18:01:19 +08:00
|
|
|
memcpy(ZCG(arena_mem), Z_PTR_P(zv), sizeof(zend_class_entry));
|
|
|
|
zend_shared_alloc_register_xlat_entry(Z_PTR_P(zv), ZCG(arena_mem));
|
|
|
|
ce = Z_PTR_P(zv) = ZCG(arena_mem);
|
|
|
|
ZCG(arena_mem) = (void*)((char*)ZCG(arena_mem) + ZEND_ALIGNED_SIZE(sizeof(zend_class_entry)));
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(ce->name);
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_hash_persist(&ce->function_table, zend_persist_op_array);
|
2013-02-13 20:26:47 +08:00
|
|
|
if (ce->default_properties_table) {
|
|
|
|
int i;
|
|
|
|
|
2014-03-31 17:11:58 +08:00
|
|
|
zend_accel_store(ce->default_properties_table, sizeof(zval) * ce->default_properties_count);
|
2013-02-13 20:26:47 +08:00
|
|
|
for (i = 0; i < ce->default_properties_count; i++) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_persist_zval(&ce->default_properties_table[i]);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ce->default_static_members_table) {
|
|
|
|
int i;
|
|
|
|
|
2014-03-31 17:11:58 +08:00
|
|
|
zend_accel_store(ce->default_static_members_table, sizeof(zval) * ce->default_static_members_count);
|
2013-02-13 20:26:47 +08:00
|
|
|
for (i = 0; i < ce->default_static_members_count; i++) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_persist_zval(&ce->default_static_members_table[i]);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ce->static_members_table = NULL;
|
2014-08-15 16:40:07 +08:00
|
|
|
|
2015-12-08 17:40:42 +08:00
|
|
|
zend_hash_persist(&ce->constants_table, zend_persist_class_constant);
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2015-11-12 07:02:24 +08:00
|
|
|
if (ce->info.user.filename) {
|
2013-02-13 20:26:47 +08:00
|
|
|
/* do not free! PHP has centralized filename storage, compiler will free it */
|
2015-11-12 07:02:24 +08:00
|
|
|
zend_accel_memdup_string(ce->info.user.filename);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
2015-11-12 07:02:24 +08:00
|
|
|
if (ce->info.user.doc_comment) {
|
2013-02-13 20:26:47 +08:00
|
|
|
if (ZCG(accel_directives).save_comments) {
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_accel_store_interned_string(ce->info.user.doc_comment);
|
2013-02-13 20:26:47 +08:00
|
|
|
} else {
|
2015-11-12 07:02:24 +08:00
|
|
|
if (!zend_shared_alloc_get_xlat_entry(ce->info.user.doc_comment)) {
|
|
|
|
zend_shared_alloc_register_xlat_entry(ce->info.user.doc_comment, ce->info.user.doc_comment);
|
|
|
|
zend_string_release(ce->info.user.doc_comment);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
2015-11-12 07:02:24 +08:00
|
|
|
ce->info.user.doc_comment = NULL;
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_hash_persist(&ce->properties_info, zend_persist_property_info);
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->num_interfaces && ce->interfaces) {
|
2013-02-13 20:26:47 +08:00
|
|
|
efree(ce->interfaces);
|
|
|
|
}
|
|
|
|
ce->interfaces = NULL; /* will be filled in on fetch */
|
|
|
|
|
|
|
|
if (ce->num_traits && ce->traits) {
|
|
|
|
efree(ce->traits);
|
|
|
|
}
|
|
|
|
ce->traits = NULL;
|
|
|
|
|
|
|
|
if (ce->trait_aliases) {
|
|
|
|
int i = 0;
|
|
|
|
while (ce->trait_aliases[i]) {
|
|
|
|
if (ce->trait_aliases[i]->trait_method) {
|
|
|
|
if (ce->trait_aliases[i]->trait_method->method_name) {
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(ce->trait_aliases[i]->trait_method->method_name);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
if (ce->trait_aliases[i]->trait_method->class_name) {
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(ce->trait_aliases[i]->trait_method->class_name);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
ce->trait_aliases[i]->trait_method->ce = NULL;
|
|
|
|
zend_accel_store(ce->trait_aliases[i]->trait_method,
|
|
|
|
sizeof(zend_trait_method_reference));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ce->trait_aliases[i]->alias) {
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(ce->trait_aliases[i]->alias);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
zend_accel_store(ce->trait_aliases[i], sizeof(zend_trait_alias));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
zend_accel_store(ce->trait_aliases, sizeof(zend_trait_alias*) * (i + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ce->trait_precedences) {
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (ce->trait_precedences[i]) {
|
2014-03-29 03:34:49 +08:00
|
|
|
zend_accel_store_interned_string(ce->trait_precedences[i]->trait_method->method_name);
|
|
|
|
zend_accel_store_interned_string(ce->trait_precedences[i]->trait_method->class_name);
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->trait_precedences[i]->trait_method->ce = NULL;
|
|
|
|
zend_accel_store(ce->trait_precedences[i]->trait_method,
|
|
|
|
sizeof(zend_trait_method_reference));
|
|
|
|
|
|
|
|
if (ce->trait_precedences[i]->exclude_from_classes) {
|
|
|
|
int j = 0;
|
|
|
|
|
2014-03-29 03:34:49 +08:00
|
|
|
while (ce->trait_precedences[i]->exclude_from_classes[j].class_name) {
|
|
|
|
zend_accel_store_interned_string(ce->trait_precedences[i]->exclude_from_classes[j].class_name);
|
2013-02-13 20:26:47 +08:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
zend_accel_store(ce->trait_precedences[i]->exclude_from_classes,
|
2013-02-22 14:56:05 +08:00
|
|
|
sizeof(zend_class_entry*) * (j + 1));
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
zend_accel_store(ce->trait_precedences[i], sizeof(zend_trait_precedence));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
zend_accel_store(
|
2013-02-22 14:56:05 +08:00
|
|
|
ce->trait_precedences, sizeof(zend_trait_precedence*) * (i + 1));
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 22:41:01 +08:00
|
|
|
//static int zend_update_property_info_ce(zval *zv)
|
|
|
|
//{
|
|
|
|
// zend_property_info *prop = Z_PTR_P(zv);
|
|
|
|
//
|
|
|
|
// prop->ce = zend_shared_alloc_get_xlat_entry(prop->ce);
|
|
|
|
// return 0;
|
|
|
|
//}
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int zend_update_parent_ce(zval *zv)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2014-03-31 17:11:58 +08:00
|
|
|
zend_class_entry *ce = Z_PTR_P(zv);
|
2013-02-13 20:26:47 +08:00
|
|
|
|
|
|
|
if (ce->parent) {
|
|
|
|
ce->parent = zend_shared_alloc_get_xlat_entry(ce->parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update methods */
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->constructor) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->constructor = zend_shared_alloc_get_xlat_entry(ce->constructor);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->destructor) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->destructor = zend_shared_alloc_get_xlat_entry(ce->destructor);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->clone) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->clone = zend_shared_alloc_get_xlat_entry(ce->clone);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__get) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__get = zend_shared_alloc_get_xlat_entry(ce->__get);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__set) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__set = zend_shared_alloc_get_xlat_entry(ce->__set);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__call) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__call = zend_shared_alloc_get_xlat_entry(ce->__call);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->serialize_func) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->serialize_func = zend_shared_alloc_get_xlat_entry(ce->serialize_func);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->unserialize_func) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->unserialize_func = zend_shared_alloc_get_xlat_entry(ce->unserialize_func);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__isset) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__isset = zend_shared_alloc_get_xlat_entry(ce->__isset);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__unset) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__unset = zend_shared_alloc_get_xlat_entry(ce->__unset);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__tostring) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__tostring = zend_shared_alloc_get_xlat_entry(ce->__tostring);
|
|
|
|
}
|
2013-02-22 14:56:05 +08:00
|
|
|
if (ce->__callstatic) {
|
2013-02-13 20:26:47 +08:00
|
|
|
ce->__callstatic = zend_shared_alloc_get_xlat_entry(ce->__callstatic);
|
|
|
|
}
|
2014-04-26 04:32:51 +08:00
|
|
|
if (ce->__debugInfo) {
|
|
|
|
ce->__debugInfo = zend_shared_alloc_get_xlat_entry(ce->__debugInfo);
|
|
|
|
}
|
2015-03-04 22:41:01 +08:00
|
|
|
// zend_hash_apply(&ce->properties_info, (apply_func_t) zend_update_property_info_ce);
|
2013-02-13 20:26:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_accel_persist_class_table(HashTable *class_table)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_hash_persist(class_table, zend_persist_class_entry);
|
|
|
|
zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce);
|
2013-02-13 20:26:47 +08:00
|
|
|
}
|
|
|
|
|
2018-03-06 07:43:26 +08:00
|
|
|
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length, int for_shm)
|
2013-02-13 20:26:47 +08:00
|
|
|
{
|
2014-10-09 18:01:19 +08:00
|
|
|
script->mem = ZCG(mem);
|
|
|
|
|
2015-08-31 18:56:42 +08:00
|
|
|
ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
|
2013-02-13 20:26:47 +08:00
|
|
|
zend_shared_alloc_clear_xlat_table();
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-10-09 18:01:19 +08:00
|
|
|
zend_accel_store(script, sizeof(zend_persistent_script));
|
2015-05-07 04:46:49 +08:00
|
|
|
if (key && *key) {
|
2015-03-06 16:00:19 +08:00
|
|
|
*key = zend_accel_memdup(*key, key_length + 1);
|
|
|
|
}
|
2018-03-14 14:11:48 +08:00
|
|
|
|
|
|
|
script->corrupted = 0;
|
|
|
|
ZCG(current_persistent_script) = script;
|
|
|
|
|
|
|
|
if (!for_shm) {
|
|
|
|
/* script is not going to be saved in SHM */
|
|
|
|
script->corrupted = 1;
|
|
|
|
}
|
|
|
|
|
2017-03-04 17:39:13 +08:00
|
|
|
zend_accel_store_interned_string(script->script.filename);
|
2014-10-09 18:01:19 +08:00
|
|
|
|
2015-02-20 21:08:57 +08:00
|
|
|
#ifdef __SSE2__
|
|
|
|
/* Align to 64-byte boundary */
|
|
|
|
ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 63L) & ~63L);
|
2015-08-31 18:56:42 +08:00
|
|
|
#else
|
|
|
|
ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */
|
2015-02-20 21:08:57 +08:00
|
|
|
#endif
|
|
|
|
|
2014-10-09 18:01:19 +08:00
|
|
|
script->arena_mem = ZCG(arena_mem) = ZCG(mem);
|
|
|
|
ZCG(mem) = (void*)((char*)ZCG(mem) + script->arena_size);
|
|
|
|
|
2015-11-12 07:02:24 +08:00
|
|
|
zend_accel_persist_class_table(&script->script.class_table);
|
|
|
|
zend_hash_persist(&script->script.function_table, zend_persist_op_array);
|
|
|
|
zend_persist_op_array_ex(&script->script.main_op_array, script);
|
2013-02-13 20:26:47 +08:00
|
|
|
|
2018-03-06 07:43:26 +08:00
|
|
|
script->corrupted = 0;
|
|
|
|
ZCG(current_persistent_script) = NULL;
|
|
|
|
|
2013-02-13 20:26:47 +08:00
|
|
|
return script;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zend_accel_script_persistable(zend_persistent_script *script)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|