summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-06-20 10:52:18 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-06-20 16:21:39 +0200
commiteaafb69eea9dba06ee542383a746d3668fa072cf (patch)
tree56713e27861410b6767f9cc8347691ee3288dcbe
parent961935fde224f4488d3335bf8f509fb679e06e58 (diff)
downloadphp-git-eaafb69eea9dba06ee542383a746d3668fa072cf.tar.gz
Change indexing scheme for symtable_cache
symtable_cache_ptr now points to the first unused symtable_cache entry, rahter than the last used one. This avoids taking a pointer to the minus first element of the array, which is UB. Instead we take a pointer to the end plus one, which is not UB.
-rw-r--r--Zend/zend_execute.c2
-rw-r--r--Zend/zend_execute_API.c13
-rw-r--r--Zend/zend_globals.h2
3 files changed, 9 insertions, 8 deletions
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 5588ada56a..95a63e9bcf 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -3337,7 +3337,7 @@ ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table) /* {{{
/* clean before putting into the cache, since clean
could call dtors, which could use cached hash */
zend_symtable_clean(symbol_table);
- *(++EG(symtable_cache_ptr)) = symbol_table;
+ *(EG(symtable_cache_ptr)++) = symbol_table;
}
}
/* }}} */
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index e0cc560d4b..4117b48baf 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -132,8 +132,8 @@ void init_executor(void) /* {{{ */
original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
#endif
- EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
- EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
+ EG(symtable_cache_ptr) = EG(symtable_cache);
+ EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE;
EG(no_extensions) = 0;
EG(function_table) = CG(function_table);
@@ -400,10 +400,10 @@ void shutdown_executor(void) /* {{{ */
zend_cleanup_internal_classes();
- while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
+ while (EG(symtable_cache_ptr) > EG(symtable_cache)) {
+ EG(symtable_cache_ptr)--;
zend_hash_destroy(*EG(symtable_cache_ptr));
FREE_HASHTABLE(*EG(symtable_cache_ptr));
- EG(symtable_cache_ptr)--;
}
zend_hash_destroy(&EG(included_files));
@@ -1476,9 +1476,8 @@ ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
}
ZEND_ADD_CALL_FLAG(ex, ZEND_CALL_HAS_SYMBOL_TABLE);
- if (EG(symtable_cache_ptr) >= EG(symtable_cache)) {
- /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
- symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--);
+ if (EG(symtable_cache_ptr) > EG(symtable_cache)) {
+ symbol_table = ex->symbol_table = *(--EG(symtable_cache_ptr));
if (!ex->func->op_array.last_var) {
return symbol_table;
}
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index d88fdabcf7..a64e4beac2 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -136,7 +136,9 @@ struct _zend_executor_globals {
/* symbol table cache */
zend_array *symtable_cache[SYMTABLE_CACHE_SIZE];
+ /* Pointer to one past the end of the symtable_cache */
zend_array **symtable_cache_limit;
+ /* Pointer to first unused symtable_cache slot */
zend_array **symtable_cache_ptr;
zend_array symbol_table; /* main symbol table */