summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-02-15 16:34:32 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-02-15 16:37:12 +0100
commita9497cecf3a76b3264ed0807023cd59e9bcf6f23 (patch)
tree07696c94955f9c28e2a3a24250f6979b94dbd340
parent0520eb8772280be6469200e37f6e3f25a9c4ff96 (diff)
downloadphp-git-a9497cecf3a76b3264ed0807023cd59e9bcf6f23.tar.gz
Fix preload auto globals handling
We need to compute the auto globals mask before EG(symbol_table) is cleaned out.
-rw-r--r--ext/opcache/ZendAccelerator.c16
-rw-r--r--ext/opcache/tests/preload_005.phpt16
-rw-r--r--ext/opcache/tests/preload_globals.inc5
3 files changed, 29 insertions, 8 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 985c66c32e..f30b675959 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -3837,8 +3837,15 @@ static int accel_preload(const char *config)
if (ret == SUCCESS) {
zend_persistent_script *script;
zend_string *filename;
+ int ping_auto_globals_mask;
int i;
+ if (PG(auto_globals_jit)) {
+ ping_auto_globals_mask = zend_accel_get_auto_globals();
+ } else {
+ ping_auto_globals_mask = zend_accel_get_auto_globals_no_jit();
+ }
+
/* Release stored values to avoid dangling pointers */
zend_hash_graceful_reverse_destroy(&EG(symbol_table));
zend_hash_init(&EG(symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
@@ -3859,14 +3866,7 @@ static int accel_preload(const char *config)
}
script = create_persistent_script();
-
- /* Fill in the ping_auto_globals_mask for the new script. If jit for auto globals is enabled we
- will have to ping the used auto global variables before execution */
- if (PG(auto_globals_jit)) {
- script->ping_auto_globals_mask = zend_accel_get_auto_globals();
- } else {
- script->ping_auto_globals_mask = zend_accel_get_auto_globals_no_jit();
- }
+ script->ping_auto_globals_mask = ping_auto_globals_mask;
/* Store all functions and classes in a single pseudo-file */
filename = zend_string_init("$PRELOAD$", strlen("$PRELOAD$"), 0);
diff --git a/ext/opcache/tests/preload_005.phpt b/ext/opcache/tests/preload_005.phpt
new file mode 100644
index 0000000000..1bcfae4d79
--- /dev/null
+++ b/ext/opcache/tests/preload_005.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Handling of auto globals during preloading
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.preload={PWD}/preload_globals.inc
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$x = 123;
+var_dump(get_x());
+?>
+--EXPECT--
+int(123)
diff --git a/ext/opcache/tests/preload_globals.inc b/ext/opcache/tests/preload_globals.inc
new file mode 100644
index 0000000000..213dc60fab
--- /dev/null
+++ b/ext/opcache/tests/preload_globals.inc
@@ -0,0 +1,5 @@
+<?php
+
+function get_x() {
+ return $GLOBALS["x"];
+}