1
0
mirror of https://github.com/php/php-src.git synced 2026-04-24 16:38:25 +02:00

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.
This commit is contained in:
Nikita Popov
2019-06-20 10:52:18 +02:00
parent 961935fde2
commit eaafb69eea
3 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -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;
}
}
/* }}} */
+6 -7
View File
@@ -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;
}
+2
View File
@@ -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 */