]> granicus.if.org Git - php/commitdiff
Added VM instrumentation ability
authorDmitry Stogov <dmitry@zend.com>
Mon, 19 Feb 2018 13:42:02 +0000 (16:42 +0300)
committerDmitry Stogov <dmitry@zend.com>
Mon, 19 Feb 2018 13:42:02 +0000 (16:42 +0300)
Zend/zend.c
Zend/zend_vm.h
Zend/zend_vm_execute.h
Zend/zend_vm_execute.skl
Zend/zend_vm_gen.php

index dc0cab8cc02670b0c3fd8beffbbefdbd8e77328b..efe51b7b471aa3502189a46d6ef86a5bea1ef111 100644 (file)
@@ -705,8 +705,6 @@ static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p
 }
 /* }}} */
 
-void zend_init_opcodes_handlers(void);
-
 static void module_destructor_zval(zval *zv) /* {{{ */
 {
        zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
@@ -807,7 +805,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) /
        /* Set up the default garbage collection implementation. */
        gc_collect_cycles = zend_gc_collect_cycles;
 
-       zend_init_opcodes_handlers();
+       zend_vm_init();
 
        /* set up version */
        zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
@@ -939,6 +937,8 @@ int zend_post_startup(void) /* {{{ */
 
 void zend_shutdown(void) /* {{{ */
 {
+       zend_vm_dtor();
+
        zend_destroy_rsrc_list(&EG(persistent_list));
        zend_destroy_modules();
 
index 34751c72497f411e2695ff5a5ddb8cd685bf8505..8d4e2b79d4990a3c2eb49c038165eaf52e03b167 100644 (file)
@@ -32,6 +32,9 @@ ZEND_API const zend_op *zend_get_halt_op(void);
 ZEND_API int ZEND_FASTCALL zend_vm_call_opcode_handler(zend_execute_data *ex);
 ZEND_API int zend_vm_kind(void);
 
+void zend_vm_init(void);
+void zend_vm_dtor(void);
+
 END_EXTERN_C()
 
 #define ZEND_VM_SET_OPCODE_HANDLER(opline) zend_vm_set_opcode_handler(opline)
index 71a6a4d3bfb17968970a83f35914c1e203393a79..5f35f90b22827077f9345fc6f60f1cfd0c9a1520 100644 (file)
@@ -336,6 +336,12 @@ static const void *zend_vm_get_opcode_handler_func(zend_uchar opcode, const zend
 #ifndef VM_TRACE
 # define VM_TRACE(op)
 #endif
+#ifndef VM_TRACE_START()
+# define VM_TRACE_START()
+#endif
+#ifndef VM_TRACE_END()
+# define VM_TRACE_END()
+#endif
 #if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)
 #define HYBRID_NEXT()     goto *(void**)(OPLINE->handler)
 #define HYBRID_SWITCH()   HYBRID_NEXT();
@@ -62308,7 +62314,7 @@ ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value)
 }
 
 
-void zend_init_opcodes_handlers(void)
+void zend_vm_init(void)
 {
        static const void * const labels[] = {
                ZEND_NOP_SPEC_HANDLER,
@@ -66461,6 +66467,12 @@ void zend_init_opcodes_handlers(void)
        zend_handlers_count = sizeof(labels) / sizeof(void*);
        zend_spec_handlers = specs;
 #endif
+       VM_TRACE_START();
+}
+
+void zend_vm_dtor(void)
+{
+       VM_TRACE_END();
 }
 
 static HashTable *zend_handlers_table = NULL;
index 25809a90b30a56c790cbc41f1e36646ad4e06bf5..dfe25bce70874b595d908db06b12f324f30dcb71 100644 (file)
@@ -47,6 +47,12 @@ ZEND_API void zend_{%EXECUTOR_NAME%}(zend_op_array *op_array, zval *return_value
 void {%INITIALIZER_NAME%}(void)
 {
        {%EXTERNAL_LABELS%}
+       VM_TRACE_START();
+}
+
+void zend_vm_dtor(void)
+{
+       VM_TRACE_END();
 }
 
 static HashTable *zend_handlers_table = NULL;
index ad99c1086fd9927860c15308b360b97e94da434e..eae662a7f862250d338603a31749069d6eefa0c6 100644 (file)
@@ -1710,6 +1710,12 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
                                        out($f,"#ifndef VM_TRACE\n");
                                        out($f,"# define VM_TRACE(op)\n");
                                        out($f,"#endif\n");
+                                       out($f,"#ifndef VM_TRACE_START()\n");
+                                       out($f,"# define VM_TRACE_START()\n");
+                                       out($f,"#endif\n");
+                                       out($f,"#ifndef VM_TRACE_END()\n");
+                                       out($f,"# define VM_TRACE_END()\n");
+                                       out($f,"#endif\n");
                                        switch ($kind) {
                                                case ZEND_VM_KIND_HYBRID:
                                                        out($f,"#if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID)\n");
@@ -2514,7 +2520,7 @@ function gen_vm($def, $skel) {
        out($f, "255\n};\n\n");
 
        // Generate specialized executor
-       gen_executor($f, $skl, ZEND_VM_SPEC, ZEND_VM_KIND, "execute", "zend_init_opcodes_handlers");
+       gen_executor($f, $skl, ZEND_VM_SPEC, ZEND_VM_KIND, "execute", "zend_vm_init");
 
        // Generate zend_vm_get_opcode_handler() function
        out($f, "static const void *zend_vm_get_opcode_handler_ex(uint32_t spec, const zend_op* op)\n");