summaryrefslogtreecommitdiff
path: root/Zend/zend_execute_API.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_execute_API.c')
-rw-r--r--Zend/zend_execute_API.c343
1 files changed, 203 insertions, 140 deletions
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index dde4b20b0b..f7bce4f4e5 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
- | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
+ | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -14,6 +14,7 @@
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
+ | Dmitry Stogov <dmitry@zend.com> |
+----------------------------------------------------------------------+
*/
@@ -37,19 +38,19 @@
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
ZEND_API void (*zend_execute_ex)(zend_execute_data *execute_data);
ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
/* true globals */
-ZEND_API const zend_fcall_info empty_fcall_info = { 0, NULL, {{0}, {{0}}, {0}}, NULL, NULL, NULL, NULL, 0, 0 };
+ZEND_API const zend_fcall_info empty_fcall_info = { 0, {{0}, {{0}}, {0}}, NULL, NULL, NULL, 0, 0 };
ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL };
#ifdef ZEND_WIN32
-#ifdef ZTS
-__declspec(thread)
-#endif
-HANDLE tq_timer = NULL;
+ZEND_TLS HANDLE tq_timer = NULL;
#endif
#if 0&&ZEND_DEBUG
@@ -72,7 +73,7 @@ static void zend_handle_sigsegv(int dummy) /* {{{ */
zend_get_executed_filename(),
zend_get_executed_lineno());
/* See http://support.microsoft.com/kb/190351 */
-#ifdef PHP_WIN32
+#ifdef ZEND_WIN32
fflush(stderr);
#endif
}
@@ -132,7 +133,7 @@ void init_executor(void) /* {{{ */
zend_init_fpu();
ZVAL_NULL(&EG(uninitialized_zval));
- ZVAL_NULL(&EG(error_zval));
+ ZVAL_ERROR(&EG(error_zval));
/* destroys stack frame, therefore makes core dumps worthless */
#if 0&&ZEND_DEBUG
original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
@@ -171,14 +172,12 @@ void init_executor(void) /* {{{ */
zend_objects_store_init(&EG(objects_store), 1024);
EG(full_tables_cleanup) = 0;
-#ifdef ZEND_WIN32
EG(timed_out) = 0;
-#endif
EG(exception) = NULL;
EG(prev_exception) = NULL;
- EG(scope) = NULL;
+ EG(fake_scope) = NULL;
EG(ht_iterators_count) = sizeof(EG(ht_iterators_slots)) / sizeof(HashTableIterator);
EG(ht_iterators_used) = 0;
@@ -220,9 +219,9 @@ static void zend_throw_or_error(int fetch_type, zend_class_entry *exception_ce,
zend_vspprintf(&message, 0, format, va);
if (fetch_type & ZEND_FETCH_CLASS_EXCEPTION) {
- zend_throw_error(exception_ce, message);
+ zend_throw_error(exception_ce, "%s", message);
} else {
- zend_error(E_ERROR, message);
+ zend_error(E_ERROR, "%s", message);
}
efree(message);
@@ -297,8 +296,8 @@ void shutdown_executor(void) /* {{{ */
}
zend_stack_clean(&EG(user_error_handlers_error_reporting), NULL, 1);
- zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_DESTRUCTOR, 1);
- zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_DESTRUCTOR, 1);
+ zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1);
+ zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1);
} zend_end_try();
zend_try {
@@ -399,6 +398,12 @@ void shutdown_executor(void) /* {{{ */
zend_shutdown_fpu();
+#if ZEND_DEBUG
+ if (EG(ht_iterators_used) && !CG(unclean_shutdown)) {
+ zend_error(E_WARNING, "Leaked %" PRIu32 " hashtable iterators", EG(ht_iterators_used));
+ }
+#endif
+
EG(ht_iterators_used) = 0;
if (EG(ht_iterators) != EG(ht_iterators_slots)) {
efree(EG(ht_iterators));
@@ -518,6 +523,21 @@ ZEND_API uint zend_get_executed_lineno(void) /* {{{ */
}
/* }}} */
+ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */
+{
+ zend_execute_data *ex = EG(current_execute_data);
+
+ while (1) {
+ if (!ex) {
+ return NULL;
+ } else if (ex->func && (ZEND_USER_CODE(ex->func->type) || ex->func->common.scope)) {
+ return ex->func->common.scope;
+ }
+ ex = ex->prev_execute_data;
+ }
+}
+/* }}} */
+
ZEND_API zend_bool zend_is_executing(void) /* {{{ */
{
return EG(current_execute_data) != 0;
@@ -541,32 +561,27 @@ ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ *
}
/* }}} */
-#define IS_VISITED_CONSTANT 0x80
-#define IS_CONSTANT_VISITED(p) (Z_TYPE_P(p) & IS_VISITED_CONSTANT)
-#define MARK_CONSTANT_VISITED(p) Z_TYPE_INFO_P(p) |= IS_VISITED_CONSTANT
-#define RESET_CONSTANT_VISITED(p) Z_TYPE_INFO_P(p) &= ~IS_VISITED_CONSTANT
-
-ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_class_entry *scope) /* {{{ */
+ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */
{
zval *const_value;
char *colon;
+ zend_bool inline_change;
- if (IS_CONSTANT_VISITED(p)) {
- zend_throw_error(zend_ce_error, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
- return FAILURE;
- } else if (Z_TYPE_P(p) == IS_CONSTANT) {
- int refcount;
-
+ if (Z_TYPE_P(p) == IS_CONSTANT) {
+ if (IS_CONSTANT_VISITED(p)) {
+ zend_throw_error(NULL, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
+ return FAILURE;
+ }
+ inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
SEPARATE_ZVAL_NOREF(p);
MARK_CONSTANT_VISITED(p);
- refcount = Z_REFCOUNTED_P(p) ? Z_REFCOUNT_P(p) : 1;
if (Z_CONST_FLAGS_P(p) & IS_CONSTANT_CLASS) {
ZEND_ASSERT(EG(current_execute_data));
if (inline_change) {
zend_string_release(Z_STR_P(p));
}
- if (EG(scope) && EG(scope)->name) {
- ZVAL_STR_COPY(p, EG(scope)->name);
+ if (scope && scope->name) {
+ ZVAL_STR_COPY(p, scope->name);
} else {
ZVAL_EMPTY_STRING(p);
}
@@ -577,7 +592,7 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
RESET_CONSTANT_VISITED(p);
return FAILURE;
} else if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
- zend_throw_error(zend_ce_error, "Undefined class constant '%s'", Z_STRVAL_P(p));
+ zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(p));
RESET_CONSTANT_VISITED(p);
return FAILURE;
} else {
@@ -593,21 +608,8 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
}
}
- if (actual[0] == '\\') {
- if (inline_change) {
- memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p));
- --Z_STRLEN_P(p);
- } else {
- ++actual;
- }
- --actual_len;
- }
if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
- if (ZSTR_VAL(save)[0] == '\\') {
- zend_throw_error(zend_ce_error, "Undefined constant '%s'", ZSTR_VAL(save) + 1);
- } else {
- zend_throw_error(zend_ce_error, "Undefined constant '%s'", ZSTR_VAL(save));
- }
+ zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(save));
if (inline_change) {
zend_string_release(save);
}
@@ -631,19 +633,12 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
zend_string_release(Z_STR_P(p));
}
ZVAL_COPY_VALUE(p, const_value);
- if (Z_OPT_CONSTANT_P(p)) {
- if (UNEXPECTED(zval_update_constant_ex(p, 1, NULL) != SUCCESS)) {
- RESET_CONSTANT_VISITED(p);
- return FAILURE;
- }
- }
zval_opt_copy_ctor(p);
}
-
- if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount);
} else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
zval tmp;
+ inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0;
if (UNEXPECTED(zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope) != SUCCESS)) {
return FAILURE;
}
@@ -656,31 +651,23 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
}
/* }}} */
-ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change) /* {{{ */
-{
- return zval_update_constant_ex(pp, inline_change, NULL);
-}
-/* }}} */
-
-int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[]) /* {{{ */
+ZEND_API int zval_update_constant(zval *pp) /* {{{ */
{
- return call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, 1, NULL);
+ return zval_update_constant_ex(pp, EG(current_execute_data) ? zend_get_executed_scope() : CG(active_class_entry));
}
/* }}} */
-int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation, zend_array *symbol_table) /* {{{ */
+int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation) /* {{{ */
{
zend_fcall_info fci;
fci.size = sizeof(fci);
- fci.function_table = function_table;
fci.object = object ? Z_OBJ_P(object) : NULL;
ZVAL_COPY_VALUE(&fci.function_name, function_name);
fci.retval = retval_ptr;
fci.param_count = param_count;
fci.params = params;
fci.no_separation = (zend_bool) no_separation;
- fci.symbol_table = symbol_table;
return zend_call_function(&fci, NULL);
}
@@ -689,11 +676,9 @@ int call_user_function_ex(HashTable *function_table, zval *object, zval *functio
int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /* {{{ */
{
uint32_t i;
- zend_class_entry *calling_scope = NULL;
zend_execute_data *call, dummy_execute_data;
zend_fcall_info_cache fci_cache_local;
zend_function *func;
- zend_class_entry *orig_scope;
ZVAL_UNDEF(fci->retval);
@@ -713,8 +698,6 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
break;
}
- orig_scope = EG(scope);
-
/* Initialize execute_data */
if (!EG(current_execute_data)) {
/* This only happens when we're called outside any execute()'s
@@ -770,10 +753,11 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
}
func = fci_cache->function_handler;
- call = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_FUNCTION,
- func, fci->param_count, fci_cache->called_scope, fci_cache->object);
- calling_scope = fci_cache->calling_scope;
- fci->object = fci_cache->object;
+ fci->object = (func->common.fn_flags & ZEND_ACC_STATIC) ?
+ NULL : fci_cache->object;
+
+ call = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC,
+ func, fci->param_count, fci_cache->called_scope, fci->object);
if (fci->object &&
(!EG(objects_store).object_buckets ||
!IS_OBJ_VALID(EG(objects_store).object_buckets[fci->object->handle]))) {
@@ -785,7 +769,10 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
if (func->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
if (func->common.fn_flags & ZEND_ACC_ABSTRACT) {
- zend_throw_error(zend_ce_error, "Cannot call abstract method %s::%s()", ZSTR_VAL(func->common.scope->name), ZSTR_VAL(func->common.function_name));
+ zend_throw_error(NULL, "Cannot call abstract method %s::%s()", ZSTR_VAL(func->common.scope->name), ZSTR_VAL(func->common.function_name));
+ if (EG(current_execute_data) == &dummy_execute_data) {
+ EG(current_execute_data) = dummy_execute_data.prev_execute_data;
+ }
return FAILURE;
}
if (func->common.fn_flags & ZEND_ACC_DEPRECATED) {
@@ -839,27 +826,16 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
ZVAL_COPY_VALUE(param, arg);
}
- EG(scope) = calling_scope;
- if (func->common.fn_flags & ZEND_ACC_STATIC) {
- fci->object = NULL;
+ if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
+ ZEND_ASSERT(GC_TYPE((zend_object*)func->op_array.prototype) == IS_OBJECT);
+ GC_REFCOUNT((zend_object*)func->op_array.prototype)++;
+ ZEND_ADD_CALL_FLAG(call, ZEND_CALL_CLOSURE);
}
- Z_OBJ(call->This) = fci->object;
if (func->type == ZEND_USER_FUNCTION) {
int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
- EG(scope) = func->common.scope;
- call->symbol_table = fci->symbol_table;
- if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) {
- ZEND_ASSERT(GC_TYPE(func->op_array.prototype) == IS_OBJECT);
- GC_REFCOUNT(func->op_array.prototype)++;
- ZEND_ADD_CALL_FLAG(call, ZEND_CALL_CLOSURE);
- }
- if (EXPECTED((func->op_array.fn_flags & ZEND_ACC_GENERATOR) == 0)) {
- zend_init_execute_data(call, &func->op_array, fci->retval);
- zend_execute_ex(call);
- } else {
- zend_generator_create_zval(call, &func->op_array, fci->retval);
- }
+ zend_init_execute_data(call, &func->op_array, fci->retval);
+ zend_execute_ex(call);
if (call_via_handler) {
/* We must re-initialize function again */
fci_cache->initialized = 0;
@@ -867,9 +843,6 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
} else if (func->type == ZEND_INTERNAL_FUNCTION) {
int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0;
ZVAL_NULL(fci->retval);
- if (func->common.scope) {
- EG(scope) = func->common.scope;
- }
call->prev_execute_data = EG(current_execute_data);
call->return_value = NULL; /* this is not a constructor call */
EG(current_execute_data) = call;
@@ -907,7 +880,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval);
EG(current_execute_data) = call->prev_execute_data;
} else {
- zend_throw_error(zend_ce_error, "Cannot call overloaded function for non-object");
+ zend_throw_error(NULL, "Cannot call overloaded function for non-object");
}
zend_vm_stack_free_args(call);
@@ -923,7 +896,6 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
}
}
- EG(scope) = orig_scope;
zend_vm_stack_free_call_frame(call);
if (EG(current_execute_data) == &dummy_execute_data) {
@@ -942,7 +914,6 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
zend_class_entry *ce = NULL;
zval args[1];
zval local_retval;
- int retval;
zend_string *lc_name;
zend_fcall_info fcall_info;
zend_fcall_info_cache fcall_cache;
@@ -981,7 +952,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
}
if (!EG(autoload_func)) {
- zend_function *func = zend_hash_str_find_ptr(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1);
+ zend_function *func = zend_hash_find_ptr(EG(function_table), CG(known_strings)[ZEND_STR_MAGIC_AUTOLOAD]);
if (func) {
EG(autoload_func) = func;
} else {
@@ -994,7 +965,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
}
/* Verify class name before passing it to __autoload() */
- if (strspn(ZSTR_VAL(name), "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\") != ZSTR_LEN(name)) {
+ if (strspn(ZSTR_VAL(name), "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\") != ZSTR_LEN(name)) {
if (!key) {
zend_string_release(lc_name);
}
@@ -1022,9 +993,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
}
fcall_info.size = sizeof(fcall_info);
- fcall_info.function_table = EG(function_table);
ZVAL_STR_COPY(&fcall_info.function_name, EG(autoload_func)->common.function_name);
- fcall_info.symbol_table = NULL;
fcall_info.retval = &local_retval;
fcall_info.param_count = 1;
fcall_info.params = args;
@@ -1038,7 +1007,9 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
fcall_cache.object = NULL;
zend_exception_save();
- retval = zend_call_function(&fcall_info, &fcall_cache);
+ if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) {
+ ce = zend_hash_find_ptr(EG(class_table), lc_name);
+ }
zend_exception_restore();
zval_ptr_dtor(&args[0]);
@@ -1048,9 +1019,6 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
zval_ptr_dtor(&local_retval);
- if (retval == SUCCESS) {
- ce = zend_hash_find_ptr(EG(class_table), lc_name);
- }
if (!key) {
zend_string_release(lc_name);
}
@@ -1067,11 +1035,13 @@ ZEND_API zend_class_entry *zend_lookup_class(zend_string *name) /* {{{ */
ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex) /* {{{ */
{
while (ex) {
- if (ex->called_scope) {
- return ex->called_scope;
+ if (Z_TYPE(ex->This) == IS_OBJECT) {
+ return Z_OBJCE(ex->This);
+ } else if (Z_CE(ex->This)) {
+ return Z_CE(ex->This);
} else if (ex->func) {
if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) {
- return ex->called_scope;
+ return NULL;
}
}
ex = ex->prev_execute_data;
@@ -1083,11 +1053,11 @@ ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex) /* {{{ *
ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex) /* {{{ */
{
while (ex) {
- if (Z_OBJ(ex->This)) {
+ if (Z_TYPE(ex->This) == IS_OBJECT) {
return Z_OBJ(ex->This);
} else if (ex->func) {
if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) {
- return Z_OBJ(ex->This);
+ return NULL;
}
}
ex = ex->prev_execute_data;
@@ -1183,8 +1153,63 @@ ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name,
}
/* }}} */
-ZEND_API void zend_timeout(int dummy) /* {{{ */
+static void zend_set_timeout_ex(zend_long seconds, int reset_signals);
+
+ZEND_API ZEND_NORETURN void zend_timeout(int dummy) /* {{{ */
{
+#if defined(PHP_WIN32)
+# ifndef ZTS
+ /* No action is needed if we're timed out because zero seconds are
+ just ignored. Also, the hard timeout needs to be respected. If the
+ timer is not restarted properly, it could hang in the shutdown
+ function. */
+ if (EG(hard_timeout) > 0) {
+ EG(timed_out) = 0;
+ zend_set_timeout_ex(EG(hard_timeout), 1);
+ /* XXX Abused, introduce an additional flag if the value needs to be kept. */
+ EG(hard_timeout) = 0;
+ }
+# endif
+#else
+ EG(timed_out) = 0;
+ zend_set_timeout_ex(0, 1);
+#endif
+
+ zend_error_noreturn(E_ERROR, "Maximum execution time of %pd second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
+}
+/* }}} */
+
+#ifndef ZEND_WIN32
+static void zend_timeout_handler(int dummy) /* {{{ */
+{
+#ifndef ZTS
+ if (EG(timed_out)) {
+ /* Die on hard timeout */
+ const char *error_filename = NULL;
+ uint error_lineno = 0;
+ char *log_buffer = NULL;
+
+ if (zend_is_compiling()) {
+ error_filename = ZSTR_VAL(zend_get_compiled_filename());
+ error_lineno = zend_get_compiled_lineno();
+ } else if (zend_is_executing()) {
+ error_filename = zend_get_executed_filename();
+ if (error_filename[0] == '[') { /* [no active file] */
+ error_filename = NULL;
+ error_lineno = 0;
+ } else {
+ error_lineno = zend_get_executed_lineno();
+ }
+ }
+ if (!error_filename) {
+ error_filename = "Unknown";
+ }
+
+ zend_spprintf(&log_buffer, 0, "\nFatal error: Maximum execution time of %pd+%pd seconds exceeded (terminated) in %s on line %d\n", EG(timeout_seconds), EG(hard_timeout), error_filename, error_lineno);
+ write(2, log_buffer, strlen(log_buffer));
+ _exit(1);
+ }
+#endif
if (zend_on_timeout) {
#ifdef ZEND_SIGNALS
@@ -1199,9 +1224,17 @@ ZEND_API void zend_timeout(int dummy) /* {{{ */
zend_on_timeout(EG(timeout_seconds));
}
- zend_error_noreturn(E_ERROR, "Maximum execution time of %pd second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
+ EG(timed_out) = 1;
+
+#ifndef ZTS
+ if (EG(hard_timeout) > 0) {
+ /* Set hard timeout */
+ zend_set_timeout_ex(EG(hard_timeout), 1);
+ }
+#endif
}
/* }}} */
+#endif
#ifdef ZEND_WIN32
VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
@@ -1224,11 +1257,9 @@ VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
#define SIGPROF 27
#endif
-void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
+static void zend_set_timeout_ex(zend_long seconds, int reset_signals) /* {{{ */
{
- EG(timeout_seconds) = seconds;
-
#ifdef ZEND_WIN32
if(!seconds) {
return;
@@ -1239,7 +1270,6 @@ void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
delete and recreate. */
if (NULL != tq_timer) {
if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) {
- EG(timed_out) = 0;
tq_timer = NULL;
zend_error_noreturn(E_ERROR, "Could not delete queued timer");
return;
@@ -1249,12 +1279,10 @@ void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
/* XXX passing NULL means the default timer queue provided by the system is used */
if (!CreateTimerQueueTimer(&tq_timer, NULL, (WAITORTIMERCALLBACK)tq_timer_cb, (VOID*)&EG(timed_out), seconds*1000, 0, WT_EXECUTEONLYONCE)) {
- EG(timed_out) = 0;
tq_timer = NULL;
zend_error_noreturn(E_ERROR, "Could not queue new timer");
return;
}
- EG(timed_out) = 0;
#else
# ifdef HAVE_SETITIMER
{
@@ -1277,15 +1305,23 @@ void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
if (reset_signals) {
# ifdef ZEND_SIGNALS
- zend_signal(signo, zend_timeout);
+ zend_signal(signo, zend_timeout_handler);
# else
sigset_t sigset;
-
- signal(signo, zend_timeout);
+# ifdef HAVE_SIGACTION
+ struct sigaction act;
+
+ act.sa_handler = zend_timeout_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_RESETHAND | SA_NODEFER;
+ sigaction(signo, &act, NULL);
+# else
+ signal(signo, zend_timeout_handler);
+# endif /* HAVE_SIGACTION */
sigemptyset(&sigset);
sigaddset(&sigset, signo);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
-# endif
+# endif /* ZEND_SIGNALS */
}
}
# endif /* HAVE_SETITIMER */
@@ -1293,6 +1329,15 @@ void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
}
/* }}} */
+void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */
+{
+
+ EG(timeout_seconds) = seconds;
+ zend_set_timeout_ex(seconds, reset_signals);
+ EG(timed_out) = 0;
+}
+/* }}} */
+
void zend_unset_timeout(void) /* {{{ */
{
#ifdef ZEND_WIN32
@@ -1320,35 +1365,38 @@ void zend_unset_timeout(void) /* {{{ */
#endif
}
# endif
+ EG(timed_out) = 0;
#endif
}
/* }}} */
zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {{{ */
{
- zend_class_entry *ce;
+ zend_class_entry *ce, *scope;
int fetch_sub_type = fetch_type & ZEND_FETCH_CLASS_MASK;
check_fetch_type:
switch (fetch_sub_type) {
case ZEND_FETCH_CLASS_SELF:
- if (UNEXPECTED(!EG(scope))) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Cannot access self:: when no class scope is active");
+ scope = zend_get_executed_scope();
+ if (UNEXPECTED(!scope)) {
+ zend_throw_or_error(fetch_type, NULL, "Cannot access self:: when no class scope is active");
}
- return EG(scope);
+ return scope;
case ZEND_FETCH_CLASS_PARENT:
- if (UNEXPECTED(!EG(scope))) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Cannot access parent:: when no class scope is active");
+ scope = zend_get_executed_scope();
+ if (UNEXPECTED(!scope)) {
+ zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when no class scope is active");
return NULL;
}
- if (UNEXPECTED(!EG(scope)->parent)) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Cannot access parent:: when current class scope has no parent");
+ if (UNEXPECTED(!scope->parent)) {
+ zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when current class scope has no parent");
}
- return EG(scope)->parent;
+ return scope->parent;
case ZEND_FETCH_CLASS_STATIC:
ce = zend_get_called_scope(EG(current_execute_data));
if (UNEXPECTED(!ce)) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Cannot access static:: when no class scope is active");
+ zend_throw_or_error(fetch_type, NULL, "Cannot access static:: when no class scope is active");
return NULL;
}
return ce;
@@ -1366,11 +1414,11 @@ check_fetch_type:
} else if ((ce = zend_lookup_class_ex(class_name, NULL, 1)) == NULL) {
if (!(fetch_type & ZEND_FETCH_CLASS_SILENT) && !EG(exception)) {
if (fetch_sub_type == ZEND_FETCH_CLASS_INTERFACE) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Interface '%s' not found", ZSTR_VAL(class_name));
+ zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name));
} else if (fetch_sub_type == ZEND_FETCH_CLASS_TRAIT) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Trait '%s' not found", ZSTR_VAL(class_name));
+ zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name));
} else {
- zend_throw_or_error(fetch_type, zend_ce_error, "Class '%s' not found", ZSTR_VAL(class_name));
+ zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name));
}
}
return NULL;
@@ -1388,11 +1436,11 @@ zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *
} else if ((ce = zend_lookup_class_ex(class_name, key, 1)) == NULL) {
if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) {
if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Interface '%s' not found", ZSTR_VAL(class_name));
+ zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name));
} else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
- zend_throw_or_error(fetch_type, zend_ce_error, "Trait '%s' not found", ZSTR_VAL(class_name));
+ zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name));
} else {
- zend_throw_or_error(fetch_type, zend_ce_error, "Class '%s' not found", ZSTR_VAL(class_name));
+ zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name));
}
}
return NULL;
@@ -1479,10 +1527,11 @@ ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
if (!ex) {
return NULL;
}
- if (ex->symbol_table) {
+ if (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE) {
return ex->symbol_table;
}
+ 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)--);
@@ -1583,7 +1632,7 @@ ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force) /* {{
}
if (execute_data) {
- if (!execute_data->symbol_table) {
+ if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
zend_ulong h = zend_string_hash_val(name);
zend_op_array *op_array = &execute_data->func->op_array;
@@ -1625,7 +1674,7 @@ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, i
}
if (execute_data) {
- if (!execute_data->symbol_table) {
+ if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
zend_ulong h = zend_hash_func(name, len);
zend_op_array *op_array = &execute_data->func->op_array;
if (EXPECTED(op_array->last_var)) {
@@ -1658,6 +1707,20 @@ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, i
}
/* }}} */
+ZEND_API int zend_forbid_dynamic_call(const char *func_name) /* {{{ */
+{
+ zend_execute_data *ex = EG(current_execute_data);
+ ZEND_ASSERT(ex != NULL && ex->func != NULL);
+
+ if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
+ zend_error(E_WARNING, "Cannot call %s dynamically", func_name);
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4