Skip to content

Commit 3c6e9be

Browse files
committed
Call global code of preloaded script in global context
1 parent 2dddab0 commit 3c6e9be

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,6 +4246,10 @@ static int preload_autoload(zend_string *filename)
42464246
{
42474247
zend_persistent_script *persistent_script;
42484248
zend_op_array *op_array;
4249+
zend_execute_data *old_execute_data;
4250+
zend_class_entry *old_fake_scope;
4251+
zend_bool do_bailout = 0;
4252+
int ret = SUCCESS;
42494253

42504254
if (zend_hash_exists(&EG(included_files), filename)) {
42514255
return FAILURE;
@@ -4256,18 +4260,55 @@ static int preload_autoload(zend_string *filename)
42564260
return FAILURE;
42574261
}
42584262

4263+
zend_hash_add_empty_element(&EG(included_files), filename);
4264+
4265+
if (persistent_script->ping_auto_globals_mask) {
4266+
zend_accel_set_auto_globals(persistent_script->ping_auto_globals_mask);
4267+
}
4268+
42594269
op_array = zend_accel_load_script(persistent_script, 1);
42604270
if (!op_array) {
42614271
return FAILURE;
42624272
}
42634273

4264-
// TODO: we may need to execute this in some special context ???
4265-
zend_execute(op_array, NULL);
4274+
/* Execute in global context */
4275+
old_execute_data = EG(current_execute_data);
4276+
EG(current_execute_data) = NULL;
4277+
old_fake_scope = EG(fake_scope);
4278+
EG(fake_scope) = NULL;
4279+
zend_exception_save();
4280+
4281+
zend_try {
4282+
zend_execute(op_array, NULL);
4283+
} zend_catch {
4284+
do_bailout = 1;
4285+
} zend_end_try();
4286+
4287+
if (EG(exception)) {
4288+
ret = FAILURE;
4289+
}
4290+
4291+
zend_exception_restore();
4292+
EG(fake_scope) = old_fake_scope;
4293+
EG(current_execute_data) = old_execute_data;
4294+
while (old_execute_data) {
4295+
if (old_execute_data->func && (ZEND_CALL_INFO(old_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
4296+
if (old_execute_data->symbol_table == &EG(symbol_table)) {
4297+
zend_attach_symbol_table(old_execute_data);
4298+
}
4299+
break;
4300+
}
4301+
old_execute_data = old_execute_data->prev_execute_data;
4302+
}
42664303

42674304
destroy_op_array(op_array);
42684305
efree_size(op_array, sizeof(zend_op_array));
42694306

4270-
return SUCCESS;
4307+
if (do_bailout) {
4308+
zend_bailout();
4309+
}
4310+
4311+
return ret;
42714312
}
42724313

42734314
static int accel_preload(const char *config)

0 commit comments

Comments
 (0)