]> granicus.if.org Git - php/commitdiff
Move a part of opcache initialization into post_startup phase (when all extensions...
authorDmitry Stogov <dmitry@zend.com>
Wed, 18 Oct 2017 14:18:54 +0000 (17:18 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 18 Oct 2017 14:18:54 +0000 (17:18 +0300)
Zend/zend.c
Zend/zend.h
ext/opcache/ZendAccelerator.c
main/main.c

index 2621851941f5051ae3d251f982c2b66d9e87158f..f881c6c0389681bd3ebf92557b2f6a33decc5bd6 100644 (file)
@@ -76,6 +76,7 @@ void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_li
 void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
 ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
 ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
+ZEND_API int (*zend_post_startup_cb)(void) = NULL;
 
 void (*zend_on_timeout)(int seconds);
 
@@ -868,7 +869,7 @@ void zend_register_standard_ini_entries(void) /* {{{ */
 /* Unlink the global (r/o) copies of the class, function and constant tables,
  * and use a fresh r/w copy for the startup thread
  */
-void zend_post_startup(void) /* {{{ */
+int zend_post_startup(void) /* {{{ */
 {
 #ifdef ZTS
        zend_encoding **script_encoding_list;
@@ -898,6 +899,17 @@ void zend_post_startup(void) /* {{{ */
        global_persistent_list = &EG(persistent_list);
        zend_copy_ini_directives();
 #endif
+
+       if (zend_post_startup_cb) {
+               int (*cb)(void) = zend_post_startup_cb;
+
+               zend_post_startup_cb = NULL;
+               if (cb() != SUCCESS) {
+                       return FAILURE;
+               }
+       }
+
+       return SUCCESS;
 }
 /* }}} */
 
index 8ec3ec2c04b477cc9b2b68ceb6f839dbc453d6e0..3cd5036dddb34cc34b4fc9c1d37a5e3bba27dd5f 100644 (file)
@@ -222,7 +222,7 @@ BEGIN_EXTERN_C()
 int zend_startup(zend_utility_functions *utility_functions, char **extensions);
 void zend_shutdown(void);
 void zend_register_standard_ini_entries(void);
-void zend_post_startup(void);
+int zend_post_startup(void);
 void zend_set_utility_values(zend_utility_values *utility_values);
 
 ZEND_API ZEND_COLD void _zend_bailout(const char *filename, uint32_t lineno);
@@ -270,6 +270,7 @@ extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format
 extern void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
 extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
 extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, size_t filename_len);
+extern ZEND_API int (*zend_post_startup_cb)(void);
 
 ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
 ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
index e24262fb205fd4bc52829d075304042d5f34ef42..400db342f214e6ea2c97271c33d79f2158830fba 100644 (file)
@@ -117,8 +117,10 @@ static int (*accelerator_orig_zend_stream_open_function)(const char *filename, z
 static zend_string *(*accelerator_orig_zend_resolve_path)(const char *filename, size_t filename_len);
 static zif_handler orig_chdir = NULL;
 static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
+static int (*orig_post_startup_cb)(void);
 
 static void accel_gen_system_id(void);
+static int accel_post_startup(void);
 
 #ifdef ZEND_WIN32
 # define INCREMENT(v) InterlockedIncrement64(&ZCSG(v))
@@ -2138,11 +2140,6 @@ static void accel_activate(void)
                return;
        }
 
-       if (!ZCG(function_table).nTableSize) {
-               zend_hash_init(&ZCG(function_table), zend_hash_num_elements(CG(function_table)), NULL, ZEND_FUNCTION_DTOR, 1);
-               zend_accel_copy_internal_functions();
-       }
-
        /* PHP-5.4 and above return "double", but we use 1 sec precision */
        ZCG(auto_globals_mask) = 0;
        ZCG(request_time) = (time_t)sapi_get_request_time();
@@ -2567,9 +2564,6 @@ static void accel_move_code_to_huge_pages(void)
 
 static int accel_startup(zend_extension *extension)
 {
-       zend_function *func;
-       zend_ini_entry *ini_entry;
-
 #ifdef ZTS
        accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
 #else
@@ -2614,6 +2608,29 @@ static int accel_startup(zend_extension *extension)
                return SUCCESS ;
        }
 
+       orig_post_startup_cb = zend_post_startup_cb;
+       zend_post_startup_cb = accel_post_startup;
+
+       return SUCCESS;
+}
+
+static int accel_post_startup(void)
+{
+       zend_function *func;
+       zend_ini_entry *ini_entry;
+
+       if (orig_post_startup_cb) {
+               int (*cb)(void) = orig_post_startup_cb;
+
+               orig_post_startup_cb = NULL;
+               if (cb() != SUCCESS) {
+                       return FAILURE;
+               }
+       }
+
+       zend_hash_init(&ZCG(function_table), zend_hash_num_elements(CG(function_table)), NULL, ZEND_FUNCTION_DTOR, 1);
+       zend_accel_copy_internal_functions();
+
 /********************************************/
 /* End of non-SHM dependent initializations */
 /********************************************/
index dfa33789137e366c07ee999105718125d2313628..aeb12268a593fd2a1d6110f3660743d290d1a042 100644 (file)
@@ -2193,7 +2193,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
                module->info_func = PHP_MINFO(php_core);
        }
 
-       zend_post_startup();
+       if (zend_post_startup() != SUCCESS) {
+               return FAILURE;
+       }
 
        module_initialized = 1;