diff --git a/ChangeLog b/ChangeLog index ec171e0..508b18a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,14 +1,13 @@ 3.1.0 2013-??-?? ChangeLog ======== - * drop support for PHP_4 in source code * disassembler: fixes crash with nested sandbox * disassembler, Decompiler: improves support for PHP_5_4 * adds support for PHP_5_5 * compatible with fcntl fork * support for __FILE__ __DIR__ handling after files moved/hardlinked (without xcache.experimental) -3.0.3 2013-16-18 +3.0.3 2013-16.18 ======== * clean files in release (fix htdocs config) diff --git a/Makefile.frag.deps b/Makefile.frag.deps index 9c5f9f5..b83ca5f 100644 --- a/Makefile.frag.deps +++ b/Makefile.frag.deps @@ -1,24 +1,24 @@ $(XCACHE_INCLUDES_I) includes.lo $(builddir)/includes.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h mod_assembler/xc_assembler.lo $(builddir)/mod_assembler/xc_assembler.lo: -mod_cacher/xc_cacher.lo $(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H) +mod_cacher/xc_cacher.lo $(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h mod_coverager/xc_coverager.lo $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h mod_decoder/xc_decoder.lo $(builddir)/mod_decoder/xc_decoder.lo: -mod_disassembler/xc_disassembler.lo $(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H) +mod_disassembler/xc_disassembler.lo $(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h mod_encoder/xc_encoder.lo $(builddir)/mod_encoder/xc_encoder.lo: -mod_optimizer/xc_optimizer.lo $(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H) +mod_optimizer/xc_optimizer.lo $(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h util/xc_stack.lo $(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h util/xc_trace.lo $(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h -xcache.lo $(builddir)/xcache.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/util/xc_foreachcoresig.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_H) +xcache.lo $(builddir)/xcache.lo: $(srcdir)/util/xc_foreachcoresig.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h xcache/xc_allocator_bestfit.lo $(builddir)/xcache/xc_allocator_bestfit.lo: $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h xcache/xc_allocator.lo $(builddir)/xcache/xc_allocator.lo: $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h xcache/xc_compatibility.lo $(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h -xcache/xc_const_string.lo $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php5.0.h $(srcdir)/xcache/xc_const_string_opcodes_php5.1.h $(srcdir)/xcache/xc_const_string_opcodes_php5.3.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h $(srcdir)/xcache/xc_const_string_opcodes_php5.5.h $(srcdir)/xcache/xc_const_string_opcodes_php6.x.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h +xcache/xc_const_string.lo $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php4.x.h $(srcdir)/xcache/xc_const_string_opcodes_php5.0.h $(srcdir)/xcache/xc_const_string_opcodes_php5.1.h $(srcdir)/xcache/xc_const_string_opcodes_php5.3.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h $(srcdir)/xcache/xc_const_string_opcodes_php5.5.h $(srcdir)/xcache/xc_const_string_opcodes_php6.x.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h xcache/xc_extension.lo $(builddir)/xcache/xc_extension.lo: $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h xcache/xc_ini.lo $(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h xcache/xc_lock.lo $(builddir)/xcache/xc_lock.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h xcache/xc_malloc.lo $(builddir)/xcache/xc_malloc.lo: $(srcdir)/util/xc_align.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h xcache/xc_opcode_spec.lo $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_opcode_spec_def.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_shm.h -xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(XCACHE_PROC_C) $(XCACHE_PROC_H) +xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h xcache/xc_shm.lo $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache/xc_shm.h xcache/xc_shm_mmap.lo $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h diff --git a/devel/prepare.cfg.example b/devel/prepare.cfg.example index 78382d3..0968403 100644 --- a/devel/prepare.cfg.example +++ b/devel/prepare.cfg.example @@ -1,4 +1,5 @@ # copy this file as prepare.cfg before modifying +PHP4_x_DIR= PHP5_0_DIR= PHP5_1_DIR= PHP5_3_DIR= diff --git a/devel/prepare.mak b/devel/prepare.mak index 4f74ce7..2f826c0 100644 --- a/devel/prepare.mak +++ b/devel/prepare.mak @@ -17,6 +17,7 @@ clean_xc_const_string: .PHONY: xc_const_string xc_const_string: \ + xcache/xc_const_string_opcodes_php4.x.h \ xcache/xc_const_string_opcodes_php5.0.h \ xcache/xc_const_string_opcodes_php5.1.h \ xcache/xc_const_string_opcodes_php5.3.h \ @@ -33,6 +34,15 @@ xcache/xc_opcode_spec_def.h: ${EA_DIR}/opcodes.c mv "$@".tmp "$@" endif +ifeq (${PHP4_x_DIR},) +xcache/xc_const_string_opcodes_php4.x.h: dummy + @echo "Skipped $@: PHP_4_x_DIR not set" +else +xcache/xc_const_string_opcodes_php4.x.h: ${PHP4_x_DIR}/Zend/zend_compile.h + $(AWK) -f ./devel/gen_const_string_opcodes.awk < "$<" > "$@.tmp" + mv "$@.tmp" "$@" +endif + ifeq (${PHP5_0_DIR},) xcache/xc_const_string_opcodes_php5.0.h: dummy @echo "Skipped $@: PHP_5_0_DIR not set" diff --git a/lib/Decompiler.class.php b/lib/Decompiler.class.php index 16435bd..f0d0e6f 100644 --- a/lib/Decompiler.class.php +++ b/lib/Decompiler.class.php @@ -145,7 +145,7 @@ class Decompiler_Object // {{{ // }}} class Decompiler_Value extends Decompiler_Object // {{{ { - public $value; + var $value; function Decompiler_Value($value = null) { @@ -174,7 +174,7 @@ class Decompiler_Value extends Decompiler_Object // {{{ // }}} class Decompiler_Code extends Decompiler_Object // {{{ { - public $src; + var $src; function Decompiler_Code($src) { @@ -192,10 +192,10 @@ class Decompiler_Code extends Decompiler_Object // {{{ // }}} class Decompiler_Binop extends Decompiler_Code // {{{ { - public $opc; - public $op1; - public $op2; - public $parent; + var $opc; + var $op1; + var $op2; + var $parent; function Decompiler_Binop($parent, $op1, $opc, $op2) { @@ -233,9 +233,9 @@ class Decompiler_Binop extends Decompiler_Code // {{{ // }}} class Decompiler_TriOp extends Decompiler_Code // {{{ { - public $condition; - public $trueValue; - public $falseValue; + var $condition; + var $trueValue; + var $falseValue; function Decompiler_TriOp($condition, $trueValue, $falseValue) { @@ -261,8 +261,8 @@ class Decompiler_TriOp extends Decompiler_Code // {{{ // }}} class Decompiler_Fetch extends Decompiler_Code // {{{ { - public $src; - public $fetchType; + var $src; + var $fetchType; function Decompiler_Fetch($src, $type, $globalSrc) { @@ -294,7 +294,7 @@ class Decompiler_Fetch extends Decompiler_Code // {{{ // }}} class Decompiler_Box // {{{ { - public $obj; + var $obj; function Decompiler_Box(&$obj) { @@ -309,10 +309,10 @@ class Decompiler_Box // {{{ // }}} class Decompiler_Dim extends Decompiler_Value // {{{ { - public $offsets = array(); - public $isLast = false; - public $isObject = false; - public $assign = null; + var $offsets = array(); + var $isLast = false; + var $isObject = false; + var $assign = null; function toCode($indent) { @@ -341,9 +341,9 @@ class Decompiler_DimBox extends Decompiler_Box // {{{ // }}} class Decompiler_List extends Decompiler_Code // {{{ { - public $src; - public $dims = array(); - public $everLocked = false; + var $src; + var $dims = array(); + var $everLocked = false; function toCode($indent) { @@ -499,7 +499,7 @@ class Decompiler_ConstArray extends Decompiler_Array // {{{ // }}} class Decompiler_ForeachBox extends Decompiler_Box // {{{ { - public $iskey; + var $iskey; function toCode($indent) { @@ -510,12 +510,12 @@ class Decompiler_ForeachBox extends Decompiler_Box // {{{ class Decompiler { - public $namespace; - public $namespaceDecided; - public $activeFile; - public $activeClass; - public $activeMethod; - public $activeFunction; + var $namespace; + var $namespaceDecided; + var $activeFile; + var $activeClass; + var $activeMethod; + var $activeFunction; function Decompiler() { @@ -1374,7 +1374,7 @@ class Decompiler // */ } unset($op); - if ($op_array['try_catch_array']) { + if (isset($op_array['try_catch_array'])) { foreach ($op_array['try_catch_array'] as $try_catch_element) { $catch_op = $try_catch_element['catch_op']; $try_op = $try_catch_element['try_op']; @@ -1492,7 +1492,7 @@ class Decompiler array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); $EX['object'] = (int) $res['var']; $EX['called_scope'] = null; - $EX['fbc'] = 'new ' . $this->stripNamespace($this->getOpVal($op1, $EX)); + $EX['fbc'] = 'new ' . $this->stripNamespace(isset($op1['constant']) ? $op1['constant'] : $this->getOpVal($op1, $EX)); break; // }}} case XC_THROW: // {{{ @@ -1538,6 +1538,10 @@ class Decompiler } if ($op1['op_type'] == XC_IS_CONST) { + if (!ZEND_ENGINE_2) { + $resvar = $op1['constant']; + break; + } $resvar = $this->stripNamespace($op1['constant']); } else { @@ -1554,7 +1558,7 @@ class Decompiler case XC_FETCH_FUNC_ARG: case XC_FETCH_UNSET: case XC_FETCH_IS: - $fetchType = defined('ZEND_FETCH_TYPE_MASK') ? ($ext & ZEND_FETCH_TYPE_MASK) : $op2['EA.type']; + $fetchType = defined('ZEND_FETCH_TYPE_MASK') ? ($ext & ZEND_FETCH_TYPE_MASK) : $op2[!ZEND_ENGINE_2 ? 'fetch_type' : 'EA.type']; $name = isset($op1['constant']) ? $op1['constant'] : unquoteName($this->getOpVal($op1, $EX), $EX); if ($fetchType == ZEND_FETCH_STATIC_MEMBER) { $class = isset($op2['constant']) ? $op2['constant'] : $this->getOpVal($op2, $EX); @@ -1600,7 +1604,12 @@ class Decompiler $src = $this->getOpVal($op1, $EX); if (is_a($src, "Decompiler_ForeachBox")) { assert($opc == XC_FETCH_DIM_TMP_VAR); - $src = clone $src; + if (ZEND_ENGINE_2) { + $src = clone($src); + } + else { + $src = new Decompiler_ForeachBox($src->obj); + } $src->iskey = $op2['constant']; $resvar = $src; break; @@ -1641,7 +1650,7 @@ class Decompiler $dim->isObject = true; } else if ($opc == XC_UNSET_DIM_OBJ) { - $dim->isObject = $ext == ZEND_UNSET_OBJ; + $dim->isObject = ZEND_ENGINE_2 ? $ext == ZEND_UNSET_OBJ : false /* cannot distingue */; } unset($dim); $rvalue = $dimbox; @@ -1791,8 +1800,7 @@ class Decompiler } } - /* TODO: use type mask */ - switch (($ext & ZEND_ISSET_ISEMPTY_MASK)) { + switch (((!ZEND_ENGINE_2 ? $op['op2']['var'] /* constant */ : $ext) & ZEND_ISSET_ISEMPTY_MASK)) { case ZEND_ISSET: $rvalue = "isset(" . str($rvalue) . ")"; break; @@ -1844,6 +1852,9 @@ class Decompiler // }}} case XC_INIT_NS_FCALL_BY_NAME: case XC_INIT_FCALL_BY_NAME: // {{{ + if (!ZEND_ENGINE_2 && ($ext & ZEND_CTOR_CALL)) { + break; + } array_push($EX['arg_types_stack'], array($EX['fbc'], $EX['object'], $EX['called_scope'])); $EX['object'] = null; $EX['called_scope'] = null; @@ -2528,28 +2539,34 @@ class Decompiler } // }}} // {{{ properties - if (!ZEND_ENGINE_2_4) { + if (ZEND_ENGINE_2 && !ZEND_ENGINE_2_4) { $default_static_members = $class[ZEND_ENGINE_2_1 ? 'default_static_members' : 'static_members']; } - $member_variables = $class['properties_info']; + $member_variables = $class[ZEND_ENGINE_2 ? 'properties_info' : 'default_properties']; if ($member_variables) { echo "\n"; - foreach ($member_variables as $name => $info) { - if (!empty($info['doc_comment'])) { + foreach ($member_variables as $name => $dummy) { + $info = isset($class['properties_info']) ? $class['properties_info'][$name] : null; + if (isset($info) && !empty($info['doc_comment'])) { echo $newindent; echo $info['doc_comment']; echo "\n"; } echo $newindent; - $static = ($info['flags'] & ZEND_ACC_STATIC); + if (ZEND_ENGINE_2) { + $static = ($info['flags'] & ZEND_ACC_STATIC); - if ($static) { - echo "static "; + if ($static) { + echo "static "; + } } $mangleSuffix = ''; - if (!isset($info)) { + if (!ZEND_ENGINE_2) { + echo 'var '; + } + else if (!isset($info)) { echo 'public '; } else { @@ -2576,6 +2593,9 @@ class Decompiler if (ZEND_ENGINE_2_4) { $value = $class[$static ? 'default_static_members_table' : 'default_properties_table'][$info['offset']]; } + else if (!ZEND_ENGINE_2) { + $value = $class['default_properties'][$name]; + } else { $key = $info['name'] . $mangleSuffix; if ($static) { @@ -2728,6 +2748,7 @@ define('ZEND_ENGINE_2_4', PHP_VERSION >= "5.4"); define('ZEND_ENGINE_2_3', ZEND_ENGINE_2_4 || PHP_VERSION >= "5.3."); define('ZEND_ENGINE_2_2', ZEND_ENGINE_2_3 || PHP_VERSION >= "5.2."); define('ZEND_ENGINE_2_1', ZEND_ENGINE_2_2 || PHP_VERSION >= "5.1."); +define('ZEND_ENGINE_2', ZEND_ENGINE_2_1 || PHP_VERSION >= "5.0."); define('ZEND_ACC_STATIC', 0x01); define('ZEND_ACC_ABSTRACT', 0x02); @@ -2879,24 +2900,48 @@ if (preg_match_all('!XC_[A-Z_]+!', file_get_contents(__FILE__), $ms)) { } //*/ foreach (array ( + 'XC_ADD_INTERFACE' => -1, + 'XC_ASSIGN_DIM' => -1, + 'XC_ASSIGN_OBJ' => -1, + 'XC_CATCH' => -1, + 'XC_CLONE' => -1, + 'XC_DECLARE_CLASS' => -1, 'XC_DECLARE_CONST' => -1, + 'XC_DECLARE_FUNCTION' => -1, 'XC_DECLARE_FUNCTION_OR_CLASS' => -1, + 'XC_DECLARE_INHERITED_CLASS' => -1, 'XC_DECLARE_INHERITED_CLASS_DELAYED' => -1, 'XC_DECLARE_LAMBDA_FUNCTION' => -1, 'XC_DO_FCALL_BY_FUNC' => -1, + 'XC_FETCH_CLASS' => -1, 'XC_GOTO' => -1, + 'XC_HANDLE_EXCEPTION' => -1, 'XC_INIT_CTOR_CALL' => -1, 'XC_INIT_FCALL_BY_FUNC' => -1, + 'XC_INIT_METHOD_CALL' => -1, 'XC_INIT_NS_FCALL_BY_NAME' => -1, + 'XC_INIT_STATIC_METHOD_CALL' => -1, + 'XC_INSTANCEOF' => -1, 'XC_ISSET_ISEMPTY' => -1, + 'XC_ISSET_ISEMPTY_DIM_OBJ' => -1, + 'XC_ISSET_ISEMPTY_PROP_OBJ' => -1, + 'XC_ISSET_ISEMPTY_VAR' => -1, 'XC_JMP_NO_CTOR' => -1, 'XC_JMP_SET' => -1, 'XC_JMP_SET_VAR' => -1, + 'XC_OP_DATA' => -1, + 'XC_POST_DEC_OBJ' => -1, + 'XC_POST_INC_OBJ' => -1, + 'XC_PRE_DEC_OBJ' => -1, + 'XC_PRE_INC_OBJ' => -1, 'XC_QM_ASSIGN_VAR' => -1, + 'XC_RAISE_ABSTRACT_ERROR' => -1, + 'XC_THROW' => -1, 'XC_UNSET_DIM' => -1, 'XC_UNSET_DIM_OBJ' => -1, 'XC_UNSET_OBJ' => -1, 'XC_USER_OPCODE' => -1, + 'XC_VERIFY_ABSTRACT_CLASS' => -1, ) as $k => $v) { if (!defined($k)) { define($k, $v); diff --git a/mod_cacher/xc_cache.h b/mod_cacher/xc_cache.h index 33afe93..75e7b4a 100644 --- a/mod_cacher/xc_cache.h +++ b/mod_cacher/xc_cache.h @@ -43,7 +43,7 @@ typedef struct { ulong h; zend_uint methodinfo_cnt; xc_op_array_info_t *methodinfos; - zend_class_entry *class_entry; + xc_cest_t cest; #ifndef ZEND_COMPILE_DELAYED_BINDING int oplineno; #endif @@ -189,8 +189,10 @@ zend_bool xc_is_ro(const void *p); zend_bool xc_is_shm(const void *p); /* {{{ xc_gc_op_array_t */ typedef struct { +#ifdef ZEND_ENGINE_2 zend_uint num_args; zend_arg_info *arg_info; +#endif #ifdef ZEND_ENGINE_2_4 zend_literal *literals; #endif diff --git a/mod_cacher/xc_cacher.c b/mod_cacher/xc_cacher.c index 7720381..8dac4ab 100644 --- a/mod_cacher/xc_cacher.c +++ b/mod_cacher/xc_cacher.c @@ -762,6 +762,11 @@ static zend_op_array *xc_entry_install(xc_entry_php_t *entry_php TSRMLS_DC) /* { zend_uint i; xc_entry_data_php_t *p = entry_php->php; zend_op_array *old_active_op_array = CG(active_op_array); +#ifndef ZEND_ENGINE_2 + ALLOCA_FLAG(use_heap) + /* new ptr which is stored inside CG(class_table) */ + xc_cest_t **new_cest_ptrs = (xc_cest_t **)xc_do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt, use_heap); +#endif CG(active_op_array) = p->op_array; @@ -784,11 +789,21 @@ static zend_op_array *xc_entry_install(xc_entry_php_t *entry_php TSRMLS_DC) /* { /* install class */ for (i = 0; i < p->classinfo_cnt; i ++) { xc_classinfo_t *ci = &p->classinfos[i]; +#ifndef ZEND_ENGINE_2 + zend_class_entry *ce = CestToCePtr(ci->cest); + /* fix pointer to the be which inside class_table */ + if (ce->parent) { + zend_uint class_idx = (/* class_num */ (int) (long) ce->parent) - 1; + assert(class_idx < i); + ci->cest.parent = new_cest_ptrs[class_idx]; + } + new_cest_ptrs[i] = +#endif #ifdef ZEND_COMPILE_DELAYED_BINDING - xc_install_class(entry_php->entry.name.str.val, ci->class_entry, -1, + xc_install_class(entry_php->entry.name.str.val, &ci->cest, -1, UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC); #else - xc_install_class(entry_php->entry.name.str.val, ci->class_entry, ci->oplineno, + xc_install_class(entry_php->entry.name.str.val, &ci->cest, ci->oplineno, UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC); #endif } @@ -810,6 +825,14 @@ static zend_op_array *xc_entry_install(xc_entry_php_t *entry_php TSRMLS_DC) /* { CG(zend_lineno) = 0; #endif + i = 1; +#ifndef ZEND_ENGINE_2_2 + zend_hash_add(&EG(included_files), entry_php->entry.name.str.val, entry_php->entry.name.str.len+1, (void *)&i, sizeof(int), NULL); +#endif + +#ifndef ZEND_ENGINE_2 + xc_free_alloca(new_cest_ptrs, use_heap); +#endif CG(active_op_array) = old_active_op_array; return p->op_array; } @@ -995,7 +1018,12 @@ static int xc_stat(const char *filepath, struct stat *statbuf TSRMLS_DC) /* {{{ wrapper = php_stream_locate_url_wrapper(filepath, &path_for_open, 0 TSRMLS_CC); if (wrapper && wrapper->wops->url_stat - && wrapper->wops->url_stat(wrapper, path_for_open, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL TSRMLS_CC) == SUCCESS) { +#ifdef ZEND_ENGINE_2 + && wrapper->wops->url_stat(wrapper, path_for_open, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL TSRMLS_CC) == SUCCESS +#else + && wrapper->wops->url_stat(wrapper, path_for_open, &ssb TSRMLS_CC) == SUCCESS +#endif + ) { *statbuf = ssb.sb; return SUCCESS; } @@ -1273,12 +1301,12 @@ static void xc_cache_early_binding_class_cb(zend_op *opline, int oplineno, void char *class_name; zend_uint i; int class_len; - zend_class_entry *class_entry; + xc_cest_t cest; xc_entry_data_php_t *php = (xc_entry_data_php_t *) data; class_name = Z_OP_CONSTANT(opline->op1).value.str.val; class_len = Z_OP_CONSTANT(opline->op1).value.str.len; - if (zend_hash_find(CG(class_table), class_name, class_len, (void **) &class_entry) == FAILURE) { + if (zend_hash_find(CG(class_table), class_name, class_len, (void **) &cest) == FAILURE) { assert(0); } TRACE("got ZEND_DECLARE_INHERITED_CLASS: %s", class_name + 1); @@ -1721,13 +1749,15 @@ static void xc_compile_php(xc_compiler_t *compiler, zend_file_handle *h, int typ } while(0) #ifdef HAVE_XCACHE_CONSTANT - b = EG(zend_constants)->pListHead; COPY_H(xc_constinfo_t, constinfos, constinfo_cnt, constant, zend_constant); + b = EG(zend_constants)->pListHead; COPY_H(xc_constinfo_t, constinfos, constinfo_cnt, constant, zend_constant); #endif - b = CG(function_table)->pListHead; COPY_H(xc_funcinfo_t, funcinfos, funcinfo_cnt, func, zend_function); - b = CG(class_table)->pListHead; COPY_H(xc_classinfo_t, classinfos, classinfo_cnt, class_entry, zend_class_entry *); + b = CG(function_table)->pListHead; COPY_H(xc_funcinfo_t, funcinfos, funcinfo_cnt, func, zend_function); + b = CG(class_table)->pListHead; COPY_H(xc_classinfo_t, classinfos, classinfo_cnt, cest, xc_cest_t); #undef COPY_H + /* for ZE1, cest need to be fixed inside store */ + #ifdef ZEND_ENGINE_2_1 /* scan for acatived auto globals */ i = 0; @@ -1764,7 +1794,8 @@ static void xc_compile_php(xc_compiler_t *compiler, zend_file_handle *h, int typ for (i = 0; i < compiler->new_php.classinfo_cnt; i ++) { xc_classinfo_t *classinfo = &compiler->new_php.classinfos[i]; - classinfo->methodinfo_cnt = classinfo->class_entry->function_table.nTableSize; + zend_class_entry *ce = CestToCePtr(classinfo->cest); + classinfo->methodinfo_cnt = ce->function_table.nTableSize; if (classinfo->methodinfo_cnt) { int j; @@ -1773,7 +1804,7 @@ static void xc_compile_php(xc_compiler_t *compiler, zend_file_handle *h, int typ goto err_alloc; } - for (j = 0, b = classinfo->class_entry->function_table.pListHead; b; j ++, b = b->pListNext) { + for (j = 0, b = ce->function_table.pListHead; b; j ++, b = b->pListNext) { xc_collect_op_array_info(compiler, &const_usage, &classinfo->methodinfos[j], (zend_op_array *) b->pData TSRMLS_CC); } } @@ -1973,7 +2004,11 @@ static zend_op_array *xc_compile_file_sandboxed(void *data TSRMLS_DC) /* {{{ */ sandboxed_compiler->stored_php = stored_php; /* discard newly compiled result, restore from stored one */ if (compiler->new_php.op_array) { +#ifdef ZEND_ENGINE_2 destroy_op_array(compiler->new_php.op_array TSRMLS_CC); +#else + destroy_op_array(compiler->new_php.op_array); +#endif efree(compiler->new_php.op_array); compiler->new_php.op_array = NULL; } @@ -2147,7 +2182,6 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) / if (!XG(cacher) || !h->filename || !SG(request_info).path_translated - ) { TRACE("%s", "cacher not enabled"); return old_compile_file(h, type TSRMLS_CC); @@ -2236,8 +2270,9 @@ void xc_gc_add_op_array(xc_gc_op_array_t *gc_op_array TSRMLS_DC) /* {{{ */ static void xc_gc_op_array(void *pDest) /* {{{ */ { xc_gc_op_array_t *op_array = (xc_gc_op_array_t *) pDest; - zend_uint i; +#ifdef ZEND_ENGINE_2 if (op_array->arg_info) { + zend_uint i; for (i = 0; i < op_array->num_args; i++) { efree((char *) ZSTR_V(op_array->arg_info[i].name)); if (ZSTR_V(op_array->arg_info[i].class_name)) { @@ -2246,6 +2281,7 @@ static void xc_gc_op_array(void *pDest) /* {{{ */ } efree(op_array->arg_info); } +#endif if (op_array->opcodes) { efree(op_array->opcodes); } @@ -2761,8 +2797,8 @@ static void xc_holds_destroy(TSRMLS_D) /* {{{ */ static void xc_request_init(TSRMLS_D) /* {{{ */ { if (!XG(internal_table_copied)) { - zend_function dummy_func; - zend_class_entry *dummy_class_entry; + zend_function tmp_func; + xc_cest_t tmp_cest; #ifdef HAVE_XCACHE_CONSTANT zend_hash_destroy(&XG(internal_constant_table)); @@ -2779,14 +2815,16 @@ static void xc_request_init(TSRMLS_D) /* {{{ */ #ifdef HAVE_XCACHE_CONSTANT xc_copy_internal_zend_constants(&XG(internal_constant_table), EG(zend_constants)); #endif - zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &dummy_func, sizeof(dummy_func)); - zend_hash_copy(&XG(internal_class_table), CG(class_table), NULL, &dummy_class_entry, sizeof(dummy_class_entry)); + zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &tmp_func, sizeof(tmp_func)); + zend_hash_copy(&XG(internal_class_table), CG(class_table), NULL, &tmp_cest, sizeof(tmp_cest)); XG(internal_table_copied) = 1; } xc_holds_init(TSRMLS_C); xc_var_namespace_init(TSRMLS_C); +#ifdef ZEND_ENGINE_2 zend_llist_init(&XG(gc_op_arrays), sizeof(xc_gc_op_array_t), xc_gc_op_array, 0); +#endif #if PHP_API_VERSION <= 20041225 XG(request_time) = time(NULL); @@ -2807,7 +2845,9 @@ static void xc_request_shutdown(TSRMLS_D) /* {{{ */ xc_gc_expires_var(TSRMLS_C); xc_gc_deletes(TSRMLS_C); xc_var_namespace_destroy(TSRMLS_C); +#ifdef ZEND_ENGINE_2 zend_llist_destroy(&XG(gc_op_arrays)); +#endif } /* }}} */ @@ -3738,10 +3778,16 @@ static PHP_RINIT_FUNCTION(xcache_cacher) /* {{{ */ return SUCCESS; } /* }}} */ -/* {{{ static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xcache_cacher) */ +/* {{{ static PHP_RSHUTDOWN_FUNCTION(xcache_cacher) */ +#ifndef ZEND_ENGINE_2 +static PHP_RSHUTDOWN_FUNCTION(xcache_cacher) +#else static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xcache_cacher) +#endif { +#ifdef ZEND_ENGINE_2 TSRMLS_FETCH(); +#endif xc_request_shutdown(TSRMLS_C); return SUCCESS; @@ -3754,13 +3800,22 @@ static zend_module_entry xcache_cacher_module_entry = { /* {{{ */ PHP_MINIT(xcache_cacher), PHP_MSHUTDOWN(xcache_cacher), PHP_RINIT(xcache_cacher), +#ifndef ZEND_ENGINE_2 + PHP_RSHUTDOWN(xcache_cacher), +#else NULL, +#endif PHP_MINFO(xcache_cacher), XCACHE_VERSION, #ifdef PHP_GINIT NO_MODULE_GLOBALS, #endif +#ifdef ZEND_ENGINE_2 ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xcache_cacher), +#else + NULL, + NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ diff --git a/mod_coverager/xc_coverager.c b/mod_coverager/xc_coverager.c index 3b73a65..db29f49 100644 --- a/mod_coverager/xc_coverager.c +++ b/mod_coverager/xc_coverager.c @@ -702,7 +702,12 @@ static zend_module_entry xcache_coverager_module_entry = { /* {{{ */ #ifdef PHP_GINIT NO_MODULE_GLOBALS, #endif +#ifdef ZEND_ENGINE_2 NULL, +#else + NULL, + NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ diff --git a/mod_disassembler/xc_disassembler.c b/mod_disassembler/xc_disassembler.c index e32ad71..6c04488 100644 --- a/mod_disassembler/xc_disassembler.c +++ b/mod_disassembler/xc_disassembler.c @@ -75,7 +75,7 @@ static void xc_dasm(zval *output, zend_op_array *op_array TSRMLS_DC) /* {{{ */ ALLOC_INIT_ZVAL(zv); array_init(zv); - xc_dasm_zend_class_entry(&dasm, zv, *(zend_class_entry **)b->pData TSRMLS_CC); + xc_dasm_zend_class_entry(&dasm, zv, CestToCePtr(*(xc_cest_t *)b->pData) TSRMLS_CC); keysize = BUCKET_KEY_SIZE(b) + 2; if (keysize > bufsize) { @@ -150,7 +150,11 @@ zend_op_array *xc_dasm_sandboxed(void *data TSRMLS_DC) /* {{{ */ xc_dasm(sandboxed_dasm->output, op_array TSRMLS_CC); /* free */ +#ifdef ZEND_ENGINE_2 destroy_op_array(op_array TSRMLS_CC); +#else + destroy_op_array(op_array); +#endif efree(op_array); return NULL; @@ -246,7 +250,12 @@ static zend_module_entry xcache_disassembler_module_entry = { /* {{{ */ #ifdef PHP_GINIT NO_MODULE_GLOBALS, #endif +#ifdef ZEND_ENGINE_2 + NULL, +#else NULL, + NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ diff --git a/mod_optimizer/xc_optimizer.c b/mod_optimizer/xc_optimizer.c index 169770b..a0503a3 100644 --- a/mod_optimizer/xc_optimizer.c +++ b/mod_optimizer/xc_optimizer.c @@ -44,7 +44,9 @@ typedef struct _bb_t { int size; bbid_t fall; +#ifdef ZEND_ENGINE_2 bbid_t catch; +#endif #ifdef ZEND_ENGINE_2_5 bbid_t finally; #endif @@ -312,7 +314,9 @@ static bb_t *bb_new_ex(zend_op *opcodes, int count) /* {{{ */ bb_t *bb = (bb_t *) ecalloc(sizeof(bb_t), 1); bb->fall = BBID_INVALID; +#ifdef ZEND_ENGINE_2 bb->catch = BBID_INVALID; +#endif #ifdef ZEND_ENGINE_2_5 bb->finally = BBID_INVALID; #endif @@ -346,12 +350,12 @@ static void bb_print(bb_t *bb, zend_op_array *op_array) /* {{{ */ int line = bb->opcodes - op_array->opcodes; op_flowinfo_t fi; zend_op *last = bb->opcodes + bb->count - 1; - bbid_t catchbbid = bb->catch; + bbid_t catchbbid = ZESW(BBID_INVALID, bb->catch); bbid_t finallybbid; #ifdef ZEND_ENGINE_2_5 - finallybbid = bb->finally; -#else finallybbid = BBID_INVALID; +#else + finallybbid = bb->finally; #endif op_get_flowinfo(&fi, last); @@ -423,7 +427,9 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ typedef struct { zend_bool isbbhead; bbid_t bbid; +#ifdef ZEND_ENGINE_2 bbid_t catchbbid; +#endif #ifdef ZEND_ENGINE_2_5 bbid_t finallybbid; #endif @@ -450,6 +456,7 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ } } } +#ifdef ZEND_ENGINE_2 /* mark try start */ for (i = 0; i < op_array->last_try_catch; i ++) { oplineinfos[op_array->try_catch_array[i].try_op].isbbhead = 1; @@ -458,6 +465,7 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ oplineinfos[op_array->try_catch_array[i].finally_op].isbbhead = 1; #endif } +#endif /* }}} */ /* {{{ fill op lines with newly allocated id */ for (i = 0; i < count; i ++) { @@ -473,6 +481,7 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ TRACE("bbids[%d] = %d", i, id); } /* }}} */ +#ifdef ZEND_ENGINE_2 /* {{{ fill op lines with catch id */ for (i = 0; i < count; i ++) { oplineinfos[i].catchbbid = BBID_INVALID; @@ -501,6 +510,7 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ } #endif /* }}} */ +#endif /* {{{ create basic blocks */ start = 0; id = 0; @@ -512,7 +522,9 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ opline = op_array->opcodes + start; bb = bbs_new_bb_ex(bbs, opline, i - start); +#ifdef ZEND_ENGINE_2 bb->catch = oplineinfos[start].catchbbid; +#endif #ifdef ZEND_ENGINE_2_5 bb->finally = oplineinfos[start].finallybbid; #endif @@ -553,7 +565,10 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{ static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */ { int bbid; +#ifdef ZEND_ENGINE_2 + bbid_t lasttrybbid; bbid_t lastcatchbbid; +#endif #ifdef ZEND_ENGINE_2_5 bbid_t lastfinallybbid; #endif @@ -579,29 +594,31 @@ static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */ } } +#ifdef ZEND_ENGINE_2 + lasttrybbid = BBID_INVALID; lastcatchbbid = BBID_INVALID; -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 lastfinallybbid = BBID_INVALID; -#endif +# endif op_array->last_try_catch = 0; for (bbid = 0; bbid < bbs_count(bbs); bbid ++) { bb_t *bb = bbs_get(bbs, bbid); if (lastcatchbbid != bb->catch -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 || lastfinallybbid != bb->finally -#endif +# endif ) { if (bb->catch != BBID_INVALID -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 && bb->finally != BBID_INVALID -#endif +# endif ) { zend_uint try_op = bbs_get(bbs, bbid)->opnum; zend_uint catch_op = bbs_get(bbs, bb->catch)->opnum; -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 zend_uint finally_op = bbs_get(bbs, bb->finally)->opnum; -#endif +# endif zend_bool already_in_try_catch = 0; int j; @@ -610,9 +627,9 @@ static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */ zend_try_catch_element *element = &op_array->try_catch_array[j]; if (try_op >= element->try_op && try_op < element->catch_op && catch_op == element->catch_op -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 && finally_op == element->finally_op -#endif +# endif ) { already_in_try_catch = 1; break; @@ -624,18 +641,19 @@ static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */ op_array->try_catch_array = erealloc(op_array->try_catch_array, sizeof(zend_try_catch_element) * op_array->last_try_catch); op_array->try_catch_array[try_catch_offset].try_op = try_op; op_array->try_catch_array[try_catch_offset].catch_op = catch_op; -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 op_array->try_catch_array[try_catch_offset].finally_op = finally_op; -#endif +# endif } } lastcatchbbid = bb->catch; -#ifdef ZEND_ENGINE_2_5 +# ifdef ZEND_ENGINE_2_5 lastfinallybbid = bb->finally; -#endif +# endif } } /* it is impossible to have last bb catched */ +#endif /* ZEND_ENGINE_2 */ } /* }}} */ @@ -766,7 +784,12 @@ static zend_module_entry xcache_optimizer_module_entry = { /* {{{ */ #ifdef PHP_GINIT NO_MODULE_GLOBALS, #endif +#ifdef ZEND_ENGINE_2 + NULL, +#else NULL, + NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ diff --git a/processor/head.m4 b/processor/head.m4 index a5b1b27..59b4171 100644 --- a/processor/head.m4 +++ b/processor/head.m4 @@ -247,8 +247,8 @@ static zend_ulong xc_get_class_num(xc_processor_t *processor, zend_class_entry * return processor->cache_class_index + 1; } for (i = 0; i < php->classinfo_cnt; i ++) { - ceptr = php->classinfos[i].class_entry; - if (ceptr == ce) { + ceptr = CestToCePtr(php->classinfos[i].cest); + if (ZCEP_REFCOUNT_PTR(ceptr) == ZCEP_REFCOUNT_PTR(ce)) { processor->cache_ce = ceptr; processor->cache_class_index = i; return i + 1; @@ -260,13 +260,16 @@ static zend_ulong xc_get_class_num(xc_processor_t *processor, zend_class_entry * define(`xc_get_class_num', `xc_get_class_numNOTDEFINED') /* }}} */ /* {{{ xc_get_class */ +#ifdef ZEND_ENGINE_2 static zend_class_entry *xc_get_class(xc_processor_t *processor, zend_ulong class_num) { /* must be parent or currrent class */ assert(class_num <= processor->active_class_index + 1); - return processor->php_dst->classinfos[class_num - 1].class_entry; + return CestToCePtr(processor->php_dst->classinfos[class_num - 1].cest); } +#endif define(`xc_get_class', `xc_get_classNOTDEFINED') /* }}} */ +#ifdef ZEND_ENGINE_2 /* fix method on store */ static void xc_fix_method(xc_processor_t *processor, zend_op_array *dst TSRMLS_DC) /* {{{ */ { @@ -341,6 +344,7 @@ static void xc_fix_method(xc_processor_t *processor, zend_op_array *dst TSRMLS_D } } /* }}} */ +#endif /* {{{ call op_array ctor handler */ extern zend_bool xc_have_op_array_ctor; static void xc_zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC) diff --git a/processor/processor.m4 b/processor/processor.m4 index abc38e6..ad4c39c 100644 --- a/processor/processor.m4 +++ b/processor/processor.m4 @@ -11,7 +11,9 @@ DECL_STRUCT_P_FUNC(`zend_constant') DECL_STRUCT_P_FUNC(`zend_function') DECL_STRUCT_P_FUNC(`xc_entry_var_t') DECL_STRUCT_P_FUNC(`xc_entry_php_t') +#ifdef ZEND_ENGINE_2 DECL_STRUCT_P_FUNC(`zend_property_info') +#endif /* }}} */ dnl ==================================================== #ifdef IS_CV @@ -31,6 +33,18 @@ DEF_STRUCT_P_FUNC(`zend_uint', , `dnl {{{ DONE_SIZE(sizeof(src[0])) ') dnl }}} +#ifndef ZEND_ENGINE_2 +DEF_STRUCT_P_FUNC(`int', , `dnl {{{ + IFCOPY(`*dst = *src;') + IFDPRINT(` + INDENT() + fprintf(stderr, "%d\n", src[0]); + ') + DONE_SIZE(sizeof(src[0])) +') +dnl }}} +#endif +#ifdef ZEND_ENGINE_2 DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{ PROCESS(zend_uint, try_op) PROCESS(zend_uint, catch_op) @@ -40,6 +54,7 @@ DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{ #endif ') dnl }}} +#endif DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{ #ifdef ZEND_ENGINE_2_2 PROCESS(int, start) @@ -51,7 +66,9 @@ DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{ dnl }}} DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr', `zval_ptr') DEF_HASH_TABLE_FUNC(`HashTable_zend_function', `zend_function') +#ifdef ZEND_ENGINE_2 DEF_HASH_TABLE_FUNC(`HashTable_zend_property_info', `zend_property_info') +#endif DEF_STRUCT_P_FUNC(`zval', , `dnl {{{ IFDASM(`do { zval_dtor(dst); @@ -115,6 +132,10 @@ proc_unicode: case IS_OBJECT: IFNOTMEMCPY(`IFCOPY(`memcpy(dst, src, sizeof(src[0]));')') dnl STRUCT(value.obj) +#ifndef ZEND_ENGINE_2 + STRUCT_P(zend_class_entry, value.obj.ce) + STRUCT_P(HashTable, value.obj.properties, HashTable_zval_ptr) +#endif break; default: @@ -132,8 +153,10 @@ dnl }}} #ifdef ZEND_ENGINE_2_3 PROCESS(zend_uint, refcount__gc) -#else +#elif defined(ZEND_ENGINE_2) PROCESS(zend_uint, refcount) +#else + PROCESS(zend_ushort, refcount) #endif ')dnl IFDASM ') @@ -184,7 +207,7 @@ DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{ IFCOPY(` dnl fprintf(stderr, "copy from %p to %p\n", src[0], dst[0]); ') - IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", src[0]);') + IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", (void *) src[0]);') STRUCT_P_EX(zval, dst[0], src[0], `[0]', `', ` ') FIXPOINTER_EX(zval, dst[0]) } while (0); @@ -204,6 +227,7 @@ DEF_STRUCT_P_FUNC(`zval_ptr_nullable', , `dnl {{{ DONE_SIZE(sizeof(zval_ptr_nullable)) ') dnl }}} +#ifdef ZEND_ENGINE_2 DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{ PROCESS(zend_uint, name_len) PROC_ZSTRING_L(, name, name_len) @@ -222,6 +246,7 @@ DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{ #endif ') dnl }}} +#endif #ifdef HAVE_XCACHE_CONSTANT DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{ STRUCT(zval, value) @@ -255,6 +280,7 @@ DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{ DONE_SIZE(sizeof(src[0])) ') dnl }}} +#ifdef ZEND_ENGINE_2 DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{ PROCESS(zend_uint, flags) PROCESS(int, name_length) @@ -273,6 +299,7 @@ DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{ #endif ') dnl }}} +#endif #ifdef ZEND_ENGINE_2_4 DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{ PROCESS(unsigned int, mname_len) @@ -335,14 +362,31 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{ PROCESS(char, type) PROCESS(zend_uint, name_length) PROC_ZSTRING_L(, name, name_length) - PROC_CLASS_ENTRY_P(parent) + IFRESTORE(` +#ifndef ZEND_ENGINE_2 + /* just copy parent and resolve on install_class */ + COPY(parent) +#else + PROC_CLASS_ENTRY_P(parent) +#endif + ', ` + PROC_CLASS_ENTRY_P(parent) + ') +#ifdef ZEND_ENGINE_2 PROCESS(int, refcount) +#else + STRUCT_P(int, refcount) +#endif #ifndef ZEND_ENGINE_2_4 PROCESS(zend_bool, constants_updated) #endif +#ifdef ZEND_ENGINE_2 PROCESS(zend_uint, ce_flags) +#endif +#ifdef ZEND_ENGINE_2 STRUCT(HashTable, properties_info, HashTable_zend_property_info) +#endif #ifdef ZEND_ENGINE_2_4 STRUCT_ARRAY(int, default_properties_count, zval_ptr_nullable, default_properties_table) @@ -359,11 +403,12 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{ STRUCT(HashTable, default_static_members, HashTable_zval_ptr) IFCOPY(`dst->static_members = &dst->default_static_members;') DONE(static_members) -# else +# elif defined(ZEND_ENGINE_2) STRUCT_P(HashTable, static_members, HashTable_zval_ptr) # endif #endif /* ZEND_ENGINE_2_4 */ +#ifdef ZEND_ENGINE_2 STRUCT(HashTable, constants_table, HashTable_zval_ptr) #ifdef ZEND_ENGINE_2_2 @@ -448,6 +493,11 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{ /* # NOT DONE */ COPY(module) # endif +#else /* ZEND_ENGINE_2 */ + COPY(handle_function_call) + COPY(handle_property_get) + COPY(handle_property_set) +#endif dnl must do after SETNULL(constructor) and dst->parent STRUCT(HashTable, function_table, HashTable_zend_function) IFRESTORE(`dst->function_table.pDestructor = ZEND_FUNCTION_DTOR;') @@ -554,6 +604,9 @@ DEF_STRUCT_P_FUNC(`znode', , `dnl {{{ case IS_UNUSED: IFDASM(`PROCESS(zend_uint, u.var)') PROCESS(zend_uint, u.opline_num) +#ifndef ZEND_ENGINE_2 + PROCESS(zend_uint, u.fetch_type) +#endif PROCESS(zend_uint, u.EA.type) break; ') @@ -606,14 +659,15 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{ UNION_znode_op_literal(op2) #endif popdef(`UNION_znode_op_literal') +#ifdef ZEND_ENGINE_2 switch (src->opcode) { -#ifdef ZEND_GOTO +# ifdef ZEND_GOTO case ZEND_GOTO: -#endif +# endif case ZEND_JMP: -#ifdef ZEND_FAST_CALL +# ifdef ZEND_FAST_CALL case ZEND_FAST_CALL: -#endif +# endif assert(Z_OP(src->op1).jmp_addr >= processor->active_op_array_src->opcodes && Z_OP(src->op1).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last); Z_OP(dst->op1).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(src->op1).jmp_addr - processor->active_op_array_src->opcodes); assert(Z_OP(dst->op1).jmp_addr >= processor->active_op_array_dst->opcodes && Z_OP(dst->op1).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last); @@ -623,12 +677,12 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{ case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: -#ifdef ZEND_JMP_SET +# ifdef ZEND_JMP_SET case ZEND_JMP_SET: -#endif -#ifdef ZEND_JMP_SET_VAR +# endif +# ifdef ZEND_JMP_SET_VAR case ZEND_JMP_SET_VAR: -#endif +# endif assert(Z_OP(src->op2).jmp_addr >= processor->active_op_array_src->opcodes && Z_OP(src->op2).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last); Z_OP(dst->op2).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(src->op2).jmp_addr - processor->active_op_array_src->opcodes); assert(Z_OP(dst->op2).jmp_addr >= processor->active_op_array_dst->opcodes && Z_OP(dst->op2).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last); @@ -637,8 +691,11 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{ default: break; } +# endif ') +#ifdef ZEND_ENGINE_2 PROCESS(opcode_handler_t, handler) +#endif ') dnl }}} #ifdef ZEND_ENGINE_2_4 @@ -685,8 +742,10 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ #endif /* deep */ STRUCT_P(HashTable, static_variables, HashTable_zval_ptr) +#ifdef ZEND_ENGINE_2 STRUCT_ARRAY(zend_uint, num_args, zend_arg_info, arg_info) gc_arg_info = 1; +#endif dst->filename = processor->entry_php_src->filepath; #ifdef ZEND_ENGINE_2_4 if (src->literals) { @@ -730,7 +789,9 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ #ifdef ZEND_FAST_CALL case ZEND_FAST_CALL: #endif +#ifdef ZEND_ENGINE_2 Z_OP(opline->op1).jmp_addr = &dst->opcodes[Z_OP(opline->op1).jmp_addr - src->opcodes]; +#endif break; case ZEND_JMPZ: @@ -743,7 +804,9 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ #ifdef ZEND_JMP_SET_VAR case ZEND_JMP_SET_VAR: #endif +#ifdef ZEND_ENGINE_2 Z_OP(opline->op2).jmp_addr = &dst->opcodes[Z_OP(opline->op2).jmp_addr - src->opcodes]; +#endif break; default: @@ -757,8 +820,10 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ #endif ) { xc_gc_op_array_t gc_op_array; +#ifdef ZEND_ENGINE_2 gc_op_array.num_args = gc_arg_info ? dst->num_args : 0; gc_op_array.arg_info = gc_arg_info ? dst->arg_info : NULL; +#endif gc_op_array.opcodes = gc_opcodes ? dst->opcodes : NULL; #ifdef ZEND_ENGINE_2_4 gc_op_array.literals = gc_literals ? dst->literals : NULL; @@ -775,6 +840,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ /* Common elements */ PROCESS(zend_uchar, type) PROC_ZSTRING(, function_name) +#ifdef ZEND_ENGINE_2 PROCESS(zend_uint, fn_flags) STRUCT_ARRAY(zend_uint, num_args, zend_arg_info, arg_info) PROCESS(zend_uint, num_args) @@ -782,6 +848,26 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ # ifndef ZEND_ENGINE_2_4 PROCESS(zend_bool, pass_rest_by_reference) # endif +#else + if (src->arg_types) { + ALLOC(dst->arg_types, zend_uchar, src->arg_types[0] + 1) + IFCOPY(`memcpy(dst->arg_types, src->arg_types, sizeof(src->arg_types[0]) * (src->arg_types[0]+1));') + IFDASM(`do { + int i; + zval *zv; + ALLOC_INIT_ZVAL(zv); + array_init(zv); + for (i = 0; i < src->arg_types[0]; i ++) { + add_next_index_long(zv, src->arg_types[i + 1]); + } + add_assoc_zval_ex(dst, ZEND_STRS("arg_types"), zv); + } while (0);') + DONE(arg_types) + } + else { + COPYNULL(arg_types) + } +#endif #ifndef ZEND_ENGINE_2_4 PROCESS(unsigned char, return_reference) #endif @@ -832,9 +918,14 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ #ifndef ZEND_ENGINE_2_4 PROCESS(zend_uint, current_brk_cont) #endif +#ifndef ZEND_ENGINE_2 + PROCESS(zend_bool, uses_globals) +#endif +#ifdef ZEND_ENGINE_2 STRUCT_ARRAY(int, last_try_catch, zend_try_catch_element, try_catch_array) PROCESS(int, last_try_catch) +#endif #ifdef ZEND_ENGINE_2_5 PROCESS(zend_bool, has_finally_block) #endif @@ -865,10 +956,12 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ PROC_STRING(script_encoding) ') #endif +#ifdef ZEND_ENGINE_2 PROCESS(zend_uint, line_start) PROCESS(zend_uint, line_end) PROCESS(int, doc_comment_len) PROC_ZSTRING_L(, doc_comment, doc_comment_len) +#endif #ifdef ZEND_COMPILE_DELAYED_BINDING PROCESS(zend_uint, early_binding); #endif @@ -885,6 +978,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ } while (0); IFRESTORE(`xc_fix_op_array_info(processor->entry_php_src, processor->php_src, dst, shallow_copy, op_array_info TSRMLS_CC);') +#ifdef ZEND_ENGINE_2 dnl mark it as -1 on store, and lookup parent on restore IFSTORE(`dst->prototype = (processor->active_class_entry_src && src->prototype) ? (zend_function *) -1 : NULL;', ` IFRESTORE(`do { @@ -913,12 +1007,16 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{ ') DONE(prototype) +#endif + +#ifdef ZEND_ENGINE_2 PROC_CLASS_ENTRY_P(scope) IFCOPY(` if (src->scope) { xc_fix_method(processor, dst TSRMLS_CC); } ') +#endif IFRESTORE(` if (xc_have_op_array_ctor) { @@ -1003,7 +1101,11 @@ DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{ processor->active_op_array_infos_src = src->methodinfos; processor->active_op_array_index = 0; ') - STRUCT_P(zend_class_entry, class_entry) +#ifdef ZEND_ENGINE_2 + STRUCT_P(zend_class_entry, cest) +#else + STRUCT(zend_class_entry, cest) +#endif #ifndef ZEND_COMPILE_DELAYED_BINDING PROCESS(int, oplineno) #endif diff --git a/xcache.c b/xcache.c index 707e2f3..0772f51 100644 --- a/xcache.c +++ b/xcache.c @@ -114,13 +114,17 @@ static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */ } /* }}} */ /* {{{ PHP_GINIT_FUNCTION(xcache) */ -#define xcache_globals xcacheglobals +#pragma GCC push_options +#pragma GCC diagnostic ignored "-Wshadow" + #ifdef PHP_GINIT_FUNCTION static PHP_GINIT_FUNCTION(xcache) #else -static void xc_init_globals(zend_xcache_globals *xcache_globals TSRMLS_DC) +static void xc_init_globals(zend_xcache_globals* xcache_globals TSRMLS_DC) #endif { +#pragma GCC pop_options + memset(xcache_globals, 0, sizeof(zend_xcache_globals)); #ifdef HAVE_XCACHE_CONSTANT @@ -129,12 +133,10 @@ static void xc_init_globals(zend_xcache_globals *xcache_globals TSRMLS_DC) zend_hash_init_ex(&xcache_globals->internal_function_table, 1, NULL, NULL, 1, 0); zend_hash_init_ex(&xcache_globals->internal_class_table, 1, NULL, NULL, 1, 0); } -#undef xcache_globals /* }}} */ /* {{{ PHP_GSHUTDOWN_FUNCTION(xcache) */ static #ifdef PHP_GSHUTDOWN_FUNCTION -#define xcache_globals xcacheglobals PHP_GSHUTDOWN_FUNCTION(xcache) #else void xc_shutdown_globals(zend_xcache_globals* xcache_globals TSRMLS_DC) @@ -168,7 +170,6 @@ void xc_shutdown_globals(zend_xcache_globals* xcache_globals TSRMLS_DC) zend_hash_destroy(&xcache_globals->internal_class_table); } } -#undef xcache_globals /* }}} */ /* {{{ proto int xcache_get_refcount(mixed variable) @@ -884,7 +885,12 @@ zend_module_entry xcache_module_entry = { PHP_GINIT(xcache), PHP_GSHUTDOWN(xcache), #endif +#ifdef ZEND_ENGINE_2 NULL /* ZEND_MODULE_POST_ZEND_DEACTIVATE_N */, +#else + NULL, + NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; diff --git a/xcache/xc_compatibility.c b/xcache/xc_compatibility.c index 22a57c3..07ad6f5 100644 --- a/xcache/xc_compatibility.c +++ b/xcache/xc_compatibility.c @@ -1,6 +1,18 @@ #include "xc_compatibility.h" #ifndef ZEND_ENGINE_2_3 +#include "ext/standard/php_string.h" +size_t xc_dirname(char *path, size_t len) /* {{{ */ +{ +#ifdef ZEND_ENGINE_2 + return php_dirname(path, len); +#else + php_dirname(path, len); + return strlen(path); +#endif +} +/* }}} */ + long xc_atol(const char *str, int str_len) /* {{{ */ { long retval; diff --git a/xcache/xc_compatibility.h b/xcache/xc_compatibility.h index 98305f0..e96f74f 100644 --- a/xcache/xc_compatibility.h +++ b/xcache/xc_compatibility.h @@ -27,7 +27,12 @@ #endif #define NOTHING -/* ZendEngine version code Switcher */ +/* ZendEngine code Switcher */ +#ifndef ZEND_ENGINE_2 +# define ZESW(v1, v2) v1 +#else +# define ZESW(v1, v2) v2 +#endif #ifdef ZEND_ENGINE_2_4 # define ZEND_24(pre24, v24) v24 #else @@ -207,9 +212,24 @@ typedef const zstr const_zstr; #endif /* }}} */ +/* the class entry type to be stored in class_table */ +typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t; + +/* xc_cest_t to (zend_class_entry*) */ +#define CestToCePtr(st) (ZESW(\ + &(st), \ + st \ + ) ) + +/* ZCEP=zend class entry ptr */ +#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \ + (pce)->refcount, \ + &((pce)->refcount) \ + )) + #ifndef ZEND_ENGINE_2_3 -#include "ext/standard/php_string.h" -static inline size_t zend_dirname(char *path, size_t len) { return php_dirname(path, len); } +size_t xc_dirname(char *path, size_t len); +#define zend_dirname xc_dirname long xc_atol(const char *str, int len); #define zend_atol xc_atol #endif @@ -219,7 +239,11 @@ long xc_atol(const char *str, int len); #endif #ifndef PHP_FE_END -# define PHP_FE_END {NULL, NULL, NULL, 0, 0} +# ifdef ZEND_ENGINE_2 +# define PHP_FE_END {NULL, NULL, NULL, 0, 0} +# else +# define PHP_FE_END {NULL, NULL, NULL} +# endif #endif #endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */ diff --git a/xcache/xc_const_string.c b/xcache/xc_const_string.c index ea39838..def49da 100644 --- a/xcache/xc_const_string.c +++ b/xcache/xc_const_string.c @@ -71,8 +71,10 @@ const char *xc_get_data_type(zend_uchar data_type) # include "xc_const_string_opcodes_php5.3.h" #elif defined(ZEND_ENGINE_2_1) # include "xc_const_string_opcodes_php5.1.h" -#else +#elif defined(ZEND_ENGINE_2) # include "xc_const_string_opcodes_php5.0.h" +#else +# include "xc_const_string_opcodes_php4.x.h" #endif zend_uchar xc_get_opcode_count() diff --git a/xcache/xc_const_string_opcodes_php4.x.h b/xcache/xc_const_string_opcodes_php4.x.h new file mode 100644 index 0000000..c40396e --- /dev/null +++ b/xcache/xc_const_string_opcodes_php4.x.h @@ -0,0 +1,116 @@ +/* size = 113 */ +static const char *const xc_opcode_names[] = { +/* 0 */ "NOP", +/* 1 */ "ADD", +/* 2 */ "SUB", +/* 3 */ "MUL", +/* 4 */ "DIV", +/* 5 */ "MOD", +/* 6 */ "SL", +/* 7 */ "SR", +/* 8 */ "CONCAT", +/* 9 */ "BW_OR", +/* 10 */ "BW_AND", +/* 11 */ "BW_XOR", +/* 12 */ "BW_NOT", +/* 13 */ "BOOL_NOT", +/* 14 */ "BOOL_XOR", +/* 15 */ "IS_IDENTICAL", +/* 16 */ "IS_NOT_IDENTICAL", +/* 17 */ "IS_EQUAL", +/* 18 */ "IS_NOT_EQUAL", +/* 19 */ "IS_SMALLER", +/* 20 */ "IS_SMALLER_OR_EQUAL", +/* 21 */ "CAST", +/* 22 */ "QM_ASSIGN", +/* 23 */ "ASSIGN_ADD", +/* 24 */ "ASSIGN_SUB", +/* 25 */ "ASSIGN_MUL", +/* 26 */ "ASSIGN_DIV", +/* 27 */ "ASSIGN_MOD", +/* 28 */ "ASSIGN_SL", +/* 29 */ "ASSIGN_SR", +/* 30 */ "ASSIGN_CONCAT", +/* 31 */ "ASSIGN_BW_OR", +/* 32 */ "ASSIGN_BW_AND", +/* 33 */ "ASSIGN_BW_XOR", +/* 34 */ "PRE_INC", +/* 35 */ "PRE_DEC", +/* 36 */ "POST_INC", +/* 37 */ "POST_DEC", +/* 38 */ "ASSIGN", +/* 39 */ "ASSIGN_REF", +/* 40 */ "ECHO", +/* 41 */ "PRINT", +/* 42 */ "JMP", +/* 43 */ "JMPZ", +/* 44 */ "JMPNZ", +/* 45 */ "JMPZNZ", +/* 46 */ "JMPZ_EX", +/* 47 */ "JMPNZ_EX", +/* 48 */ "CASE", +/* 49 */ "SWITCH_FREE", +/* 50 */ "BRK", +/* 51 */ "CONT", +/* 52 */ "BOOL", +/* 53 */ "INIT_STRING", +/* 54 */ "ADD_CHAR", +/* 55 */ "ADD_STRING", +/* 56 */ "ADD_VAR", +/* 57 */ "BEGIN_SILENCE", +/* 58 */ "END_SILENCE", +/* 59 */ "INIT_FCALL_BY_NAME", +/* 60 */ "DO_FCALL", +/* 61 */ "DO_FCALL_BY_NAME", +/* 62 */ "RETURN", +/* 63 */ "RECV", +/* 64 */ "RECV_INIT", +/* 65 */ "SEND_VAL", +/* 66 */ "SEND_VAR", +/* 67 */ "SEND_REF", +/* 68 */ "NEW", +/* 69 */ "JMP_NO_CTOR", +/* 70 */ "FREE", +/* 71 */ "INIT_ARRAY", +/* 72 */ "ADD_ARRAY_ELEMENT", +/* 73 */ "INCLUDE_OR_EVAL", +/* 74 */ "UNSET_VAR", +/* 75 */ "UNSET_DIM_OBJ", +/* 76 */ "ISSET_ISEMPTY", +/* 77 */ "FE_RESET", +/* 78 */ "FE_FETCH", +/* 79 */ "EXIT", +/* 80 */ "FETCH_R", +/* 81 */ "FETCH_DIM_R", +/* 82 */ "FETCH_OBJ_R", +/* 83 */ "FETCH_W", +/* 84 */ "FETCH_DIM_W", +/* 85 */ "FETCH_OBJ_W", +/* 86 */ "FETCH_RW", +/* 87 */ "FETCH_DIM_RW", +/* 88 */ "FETCH_OBJ_RW", +/* 89 */ "FETCH_IS", +/* 90 */ "FETCH_DIM_IS", +/* 91 */ "FETCH_OBJ_IS", +/* 92 */ "FETCH_FUNC_ARG", +/* 93 */ "FETCH_DIM_FUNC_ARG", +/* 94 */ "FETCH_OBJ_FUNC_ARG", +/* 95 */ "FETCH_UNSET", +/* 96 */ "FETCH_DIM_UNSET", +/* 97 */ "FETCH_OBJ_UNSET", +/* 98 */ "FETCH_DIM_TMP_VAR", +/* 99 */ "FETCH_CONSTANT", +/* 100 */ "DECLARE_FUNCTION_OR_CLASS", +/* 101 */ "EXT_STMT", +/* 102 */ "EXT_FCALL_BEGIN", +/* 103 */ "EXT_FCALL_END", +/* 104 */ "EXT_NOP", +/* 105 */ "TICKS", +/* 106 */ "SEND_VAR_NO_REF", +/* 107 */ "UNDEF", +/* 108 */ "UNDEF", +/* 109 */ "UNDEF", +/* 110 */ "DO_FCALL_BY_FUNC", +/* 111 */ "INIT_FCALL_BY_FUNC", +/* 112 */ "UNDEF" +}; diff --git a/xcache/xc_const_string_opcodes_php5.3.h b/xcache/xc_const_string_opcodes_php5.3.h index 48bea60..585720e 100644 --- a/xcache/xc_const_string_opcodes_php5.3.h +++ b/xcache/xc_const_string_opcodes_php5.3.h @@ -151,9 +151,7 @@ static const char *const xc_opcode_names[] = { /* 148 */ "ISSET_ISEMPTY_PROP_OBJ", /* 149 */ "HANDLE_EXCEPTION", /* 150 */ "USER_OPCODE", -#ifdef ZEND_ENGINE_2_3 /* 151 */ "UNDEF", /* 152 */ "JMP_SET", /* 153 */ "DECLARE_LAMBDA_FUNCTION" -#endif }; diff --git a/xcache/xc_ini.h b/xcache/xc_ini.h index 5086424..ee72a96 100644 --- a/xcache/xc_ini.h +++ b/xcache/xc_ini.h @@ -12,5 +12,8 @@ PHP_INI_MH(xcache_OnUpdateDummy); PHP_INI_MH(xcache_OnUpdateULong); PHP_INI_MH(xcache_OnUpdateBool); PHP_INI_MH(xcache_OnUpdateString); +#ifndef ZEND_ENGINE_2 +#define OnUpdateLong OnUpdateInt +#endif #endif /* XC_INI_H_E208B8E597E7FAD950D249BE9C6B6F53 */ diff --git a/xcache/xc_opcode_spec.c b/xcache/xc_opcode_spec.c index 5043506..fe86eb0 100644 --- a/xcache/xc_opcode_spec.c +++ b/xcache/xc_opcode_spec.c @@ -4,7 +4,11 @@ /* {{{ opcode_spec */ #define OPSPEC(ext, op1, op2, res) { OPSPEC_##ext, OPSPEC_##op1, OPSPEC_##op2, OPSPEC_##res }, -#define OPSPEC_VAR_2 OPSPEC_STD +#ifdef ZEND_ENGINE_2 +# define OPSPEC_VAR_2 OPSPEC_STD +#else +# define OPSPEC_VAR_2 OPSPEC_VAR +#endif #ifdef ZEND_ENGINE_2_4 #undef OPSPEC_FETCH #define OPSPEC_FETCH OPSPEC_STD diff --git a/xcache/xc_opcode_spec_def.h b/xcache/xc_opcode_spec_def.h index 6898740..af33a61 100644 --- a/xcache/xc_opcode_spec_def.h +++ b/xcache/xc_opcode_spec_def.h @@ -22,6 +22,7 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( UNUSED, STD, STD, TMP) /* 20 IS_SMALLER_OR_EQUAL */ OPSPEC( CAST, STD, UNUSED, TMP) /* 21 CAST */ OPSPEC( UNUSED, STD, UNUSED, TMP) /* 22 QM_ASSIGN */ +#ifdef ZEND_ENGINE_2 OPSPEC( ASSIGN, STD, STD, VAR) /* 23 ASSIGN_ADD */ OPSPEC( ASSIGN, STD, STD, VAR) /* 24 ASSIGN_SUB */ OPSPEC( ASSIGN, STD, STD, VAR) /* 25 ASSIGN_MUL */ @@ -33,6 +34,19 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( ASSIGN, STD, STD, VAR) /* 31 ASSIGN_BW_OR */ OPSPEC( ASSIGN, STD, STD, VAR) /* 32 ASSIGN_BW_AND */ OPSPEC( ASSIGN, STD, STD, VAR) /* 33 ASSIGN_BW_XOR */ +#else + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) + OPSPEC( UNUSED, VAR, STD, VAR) +#endif OPSPEC( UNUSED, VAR, UNUSED, VAR) /* 34 PRE_INC */ OPSPEC( UNUSED, VAR, UNUSED, VAR) /* 35 PRE_DEC */ OPSPEC( UNUSED, VAR, UNUSED, TMP) /* 36 POST_INC */ @@ -41,12 +55,23 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( UNUSED, VAR, VAR, VAR) /* 39 ASSIGN_REF */ OPSPEC( UNUSED, STD, UNUSED, UNUSED) /* 40 ECHO */ OPSPEC( UNUSED, STD, UNUSED, TMP) /* 41 PRINT */ +#ifdef ZEND_ENGINE_2 OPSPEC( UNUSED, JMPADDR, UNUSED, UNUSED) /* 42 JMP */ OPSPEC( UNUSED, STD, JMPADDR, UNUSED) /* 43 JMPZ */ OPSPEC( UNUSED, STD, JMPADDR, UNUSED) /* 44 JMPNZ */ +#else + OPSPEC( UNUSED, OPLINE, UNUSED, UNUSED) + OPSPEC( UNUSED, STD, OPLINE, UNUSED) + OPSPEC( UNUSED, STD, OPLINE, UNUSED) +#endif OPSPEC( OPLINE, STD, OPLINE, UNUSED) /* 45 JMPZNZ */ +#ifdef ZEND_ENGINE_2 OPSPEC( UNUSED, STD, JMPADDR, TMP) /* 46 JMPZ_EX */ OPSPEC( UNUSED, STD, JMPADDR, TMP) /* 47 JMPNZ_EX */ +#else + OPSPEC( UNUSED, STD, OPLINE, TMP) + OPSPEC( UNUSED, STD, OPLINE, TMP) +#endif OPSPEC( UNUSED, STD, STD, TMP) /* 48 CASE */ OPSPEC( BIT, STD, UNUSED, UNUSED) /* 49 SWITCH_FREE */ OPSPEC( UNUSED, BRK, STD, UNUSED) /* 50 BRK */ @@ -59,15 +84,24 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( UNUSED, UNUSED, UNUSED, TMP) /* 57 BEGIN_SILENCE */ OPSPEC( UNUSED, TMP, UNUSED, UNUSED) /* 58 END_SILENCE */ OPSPEC(INIT_FCALL, STD, STD, UNUSED) /* 59 INIT_FCALL_BY_NAME */ +#ifdef ZEND_ENGINE_2 OPSPEC( FCALL, STD, OPLINE, VAR) /* 60 DO_FCALL */ OPSPEC( FCALL, STD, OPLINE, VAR) /* 61 DO_FCALL_BY_NAME */ +#else + OPSPEC( FCALL, STD, UNUSED, VAR) + OPSPEC( FCALL, STD, UNUSED, VAR) +#endif OPSPEC( UNUSED, STD, UNUSED, UNUSED) /* 62 RETURN */ OPSPEC( UNUSED, ARG, UNUSED, VAR) /* 63 RECV */ OPSPEC( UNUSED, ARG, STD, VAR) /* 64 RECV_INIT */ OPSPEC( SEND, STD, ARG, UNUSED) /* 65 SEND_VAL */ OPSPEC( SEND, VAR, ARG, UNUSED) /* 66 SEND_VAR */ OPSPEC( SEND, VAR, ARG, UNUSED) /* 67 SEND_REF */ +#ifdef ZEND_ENGINE_2 OPSPEC( UNUSED, CLASS, UNUSED, VAR) /* 68 NEW */ +#else + OPSPEC( UNUSED, STD, UNUSED, VAR) +#endif #ifdef ZEND_ENGINE_2_3 OPSPEC( STD, STD, STD, UNUSED) /* 69 INIT_NS_FCALL_BY_NAME */ #elif defined(ZEND_ENGINE_2_1) @@ -114,8 +148,10 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( UNUSED, STD, STD, VAR) /* 98 FETCH_DIM_TMP_VAR */ #ifdef ZEND_ENGINE_2_3 OPSPEC( UNUSED, VAR_2, STD, TMP) /* 99 FETCH_CONSTANT */ -#else +#elif defined(ZEND_ENGINE_2) OPSPEC( UNUSED, UCLASS, STD, TMP) /* 99 FETCH_CONSTANT */ +#else + OPSPEC( UNUSED, STD, UNUSED, TMP) /* 99 FETCH_CONSTANT */ #endif #ifdef ZEND_ENGINE_2_3 OPSPEC( STD, JMPADDR, STD, UNUSED) /* 100 GOTO */ @@ -128,27 +164,28 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 104 EXT_NOP */ OPSPEC( UNUSED, STD, UNUSED, UNUSED) /* 105 TICKS */ OPSPEC(SEND_NOREF, VAR, ARG, UNUSED) /* 106 SEND_VAR_NO_REF */ -#ifdef ZEND_ENGINE_2_4 +#ifdef ZEND_ENGINE_2 +# ifdef ZEND_ENGINE_2_4 OPSPEC( OPLINE, STD, STD, UNUSED) /* 107 CATCH */ -#else +# else OPSPEC( OPLINE, CLASS, STD, UNUSED) /* 107 CATCH */ -#endif +# endif OPSPEC( UNUSED, STD, OPLINE, UNUSED) /* 108 THROW */ OPSPEC( FCLASS, STD, STD, CLASS) /* 109 FETCH_CLASS */ OPSPEC( UNUSED, STD, UNUSED, VAR) /* 110 CLONE */ -#ifdef ZEND_ENGINE_2_4 +# ifdef ZEND_ENGINE_2_4 OPSPEC( UNUSED, STD, UNUSED, UNUSED) /* 111 RETURN_BY_REF */ -#else +# else OPSPEC( UNUSED, STD, UNUSED, UNUSED) /* 111 INIT_CTOR_CALL */ -#endif +# endif OPSPEC( UNUSED, STD, STD, VAR) /* 112 INIT_METHOD_CALL */ -#ifdef ZEND_ENGINE_2_3 +# ifdef ZEND_ENGINE_2_3 OPSPEC( UNUSED, STD, STD, UNUSED) /* 113 INIT_STATIC_METHOD_CALL */ -#else +# else OPSPEC( UNUSED, UCLASS, STD, UNUSED) /* 113 INIT_STATIC_METHOD_CALL */ -#endif +# endif OPSPEC( ISSET, STD, FETCH, TMP) /* 114 ISSET_ISEMPTY_VAR */ OPSPEC( ISSET, STD, STD, TMP) /* 115 ISSET_ISEMPTY_DIM_OBJ */ @@ -180,45 +217,53 @@ static const xc_opcode_spec_t xc_opcode_spec[] = { OPSPEC( CLASS, STD, STD, CLASS) /* 140 DECLARE_INHERITED_CLASS */ OPSPEC( UNUSED, STD, STD, UNUSED) /* 141 DECLARE_FUNCTION */ OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 142 RAISE_ABSTRACT_ERROR */ -#ifdef ZEND_ENGINE_2_3 +# ifdef ZEND_ENGINE_2_3 OPSPEC( DECLARE, STD, STD, UNUSED) /* 143 DECLARE_CONST */ -#else +# else OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 143 UNDEF-143 */ -#endif -#ifdef ZEND_ENGINE_2_3 +# endif +# ifdef ZEND_ENGINE_2_3 OPSPEC( IFACE, CLASS, STD, UNUSED) /* 144 ADD_INTERFACE */ -#else +# else OPSPEC( IFACE, CLASS, CLASS, UNUSED) /* 144 ADD_INTERFACE */ -#endif -#ifdef ZEND_ENGINE_2_3 +# endif +# ifdef ZEND_ENGINE_2_3 OPSPEC( CLASS, STD, STD, OPLINE) /* 145 DECLARE_INHERITED_CLASS_DELAYED */ -#else +# else OPSPEC( UNUSED, CLASS, STD, UNUSED) /* 145 VERIFY_INSTANCEOF */ -#endif +# endif OPSPEC( UNUSED, CLASS, UNUSED, UNUSED) /* 146 VERIFY_ABSTRACT_CLASS */ OPSPEC( UNUSED, STD, STD, VAR) /* 147 ASSIGN_DIM */ OPSPEC( ISSET, STD, STD, TMP) /* 148 ISSET_ISEMPTY_PROP_OBJ */ OPSPEC( STD, UNUSED, UNUSED, STD) /* 149 HANDLE_EXCEPTION */ -#ifdef ZEND_ENGINE_2_1 +# ifdef ZEND_ENGINE_2_1 OPSPEC( STD, UNUSED, UNUSED, STD) /* 150 USER_OPCODE */ -#endif -#ifdef ZEND_ENGINE_2_3 +# endif +# ifdef ZEND_ENGINE_2_3 OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 151 UNDEF */ OPSPEC( UNUSED, STD, JMPADDR, TMP) /* 152 JMP_SET */ OPSPEC( UNUSED, STD, STD, TMP) /* 153 DECLARE_LAMBDA_FUNCTION */ -#endif -#ifdef ZEND_ENGINE_2_4 +# endif +# ifdef ZEND_ENGINE_2_4 OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 154 ADD_TRAIT */ OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 155 BIND_TRAITS */ OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 156 SEPARATE */ OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 157 QM_ASSIGN_VAR */ OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 158 JMP_SET_VAR */ -#endif -#ifdef ZEND_ENGINE_2_5 +# endif +# ifdef ZEND_ENGINE_2_5 OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 159 DISCARD_EXCEPTION */ OPSPEC( UNUSED, STD, STD, UNUSED) /* 160 YIELD */ OPSPEC( UNUSED, STD, UNUSED, UNUSED) /* 161 GENERATOR_RETURN */ OPSPEC( UNUSED, JMPADDR, UNUSED, UNUSED) /* 162 FAST_CALL */ OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 163 FAST_RET */ -#endif +# endif +#else /* ZEND_ENGINE_2 */ + OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 107 UNDEF */ + OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 108 UNDEF */ + OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 109 UNDEF */ + OPSPEC( FCALL, STD, OPLINE, VAR) /* 61 DO_FCALL_BY_FUNC */ + OPSPEC(INIT_FCALL, STD, STD, UNUSED) /* 111 INIT_FCALL_BY_FUNC */ + OPSPEC( UNUSED, UNUSED, UNUSED, UNUSED) /* 112 UNDEF */ +#endif /* ZEND_ENGINE_2 */ }; diff --git a/xcache/xc_sandbox.c b/xcache/xc_sandbox.c index fb56250..ff038a3 100644 --- a/xcache/xc_sandbox.c +++ b/xcache/xc_sandbox.c @@ -194,8 +194,8 @@ static xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, con zend_hash_init_ex(&TG(class_table), 16, NULL, ZEND_CLASS_DTOR, h->persistent, h->bApplyProtection); #if 0 && TODO { - zend_class_entry *dummy_class_entry; - zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &dummy_class_entry, sizeof(dummy_class_entry)); + xc_cest_t tmp_cest; + zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &tmp_cest, sizeof(tmp_cest)); } #endif TG(internal_class_tail) = TG(class_table).pListTail; @@ -277,7 +277,7 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */ b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead; /* install class */ while (b != NULL) { - xc_install_class(sandbox->filename, *(zend_class_entry **)b->pData, -1, + xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1, BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); b = b->pListNext; } diff --git a/xcache/xc_utils.c b/xcache/xc_utils.c index abedd14..43933ea 100644 --- a/xcache/xc_utils.c +++ b/xcache/xc_utils.c @@ -77,20 +77,35 @@ typedef struct { int xc_apply_method(zend_function *zf, xc_apply_method_info *mi TSRMLS_DC) /* {{{ */ { /* avoid duplicate apply for shadowed method */ +#ifdef ZEND_ENGINE_2 if (mi->ce != zf->common.scope) { /* fprintf(stderr, "avoided duplicate %s\n", zf->common.function_name); */ return 0; } +#else + char *name = zf->common.function_name; + int name_s = strlen(name) + 1; + zend_class_entry *ce; + zend_function *ptr; + + for (ce = mi->ce->parent; ce; ce = ce->parent) { + if (zend_hash_find(&ce->function_table, name, name_s, (void **) &ptr) == SUCCESS) { + if (ptr->op_array.refcount == zf->op_array.refcount) { + return 0; + } + } + } +#endif return xc_apply_function(zf, &mi->fi TSRMLS_CC); } /* }}} */ -static int xc_apply_class(zend_class_entry **ce, xc_apply_func_info *fi TSRMLS_DC) /* {{{ */ +static int xc_apply_cest(xc_cest_t *cest, xc_apply_func_info *fi TSRMLS_DC) /* {{{ */ { xc_apply_method_info mi; mi.fi = *fi; - mi.ce = *ce; - zend_hash_apply_with_argument(&((*ce)->function_table), (apply_func_arg_t) xc_apply_method, &mi TSRMLS_CC); + mi.ce = CestToCePtr(*cest); + zend_hash_apply_with_argument(&(CestToCePtr(*cest)->function_table), (apply_func_arg_t) xc_apply_method, &mi TSRMLS_CC); return 0; } /* }}} */ @@ -99,14 +114,16 @@ int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC) / xc_apply_func_info fi; fi.applyer = applyer; zend_hash_apply_with_argument(cr->function_table, (apply_func_arg_t) xc_apply_function, &fi TSRMLS_CC); - zend_hash_apply_with_argument(cr->class_table, (apply_func_arg_t) xc_apply_class, &fi TSRMLS_CC); + zend_hash_apply_with_argument(cr->class_table, (apply_func_arg_t) xc_apply_cest, &fi TSRMLS_CC); return applyer(cr->op_array TSRMLS_CC); } /* }}} */ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ { +#ifdef ZEND_ENGINE_2 zend_op *opline, *opline_end; +#endif #ifdef ZEND_ENGINE_2_4 if (!(op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) { @@ -118,26 +135,27 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ } #endif +#ifdef ZEND_ENGINE_2 opline = op_array->opcodes; opline_end = opline + op_array->last; while (opline < opline_end) { -#ifdef ZEND_ENGINE_2_4 +# ifdef ZEND_ENGINE_2_4 if (opline->op1_type == IS_CONST) { opline->op1.constant = opline->op1.literal - op_array->literals; } if (opline->op2_type == IS_CONST) { opline->op2.constant = opline->op2.literal - op_array->literals; } -#endif +# endif switch (opline->opcode) { -#ifdef ZEND_GOTO +# ifdef ZEND_GOTO case ZEND_GOTO: -#endif +# endif case ZEND_JMP: -#ifdef ZEND_FAST_CALL +# ifdef ZEND_FAST_CALL case ZEND_FAST_CALL: -#endif +# endif assert(Z_OP(opline->op1).jmp_addr >= op_array->opcodes && (zend_uint) (Z_OP(opline->op1).jmp_addr - op_array->opcodes) < op_array->last); Z_OP(opline->op1).opline_num = Z_OP(opline->op1).jmp_addr - op_array->opcodes; break; @@ -145,18 +163,20 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: -#ifdef ZEND_JMP_SET +# ifdef ZEND_JMP_SET case ZEND_JMP_SET: -#endif -#ifdef ZEND_JMP_SET_VAR +# endif +# ifdef ZEND_JMP_SET_VAR case ZEND_JMP_SET_VAR: -#endif +# endif assert(Z_OP(opline->op2).jmp_addr >= op_array->opcodes && (zend_uint) (Z_OP(opline->op2).jmp_addr - op_array->opcodes) < op_array->last); Z_OP(opline->op2).opline_num = Z_OP(opline->op2).jmp_addr - op_array->opcodes; break; } opline++; } +#endif /* ZEND_ENGINE_2 */ + #ifdef ZEND_ENGINE_2_4 op_array->fn_flags &= ~ZEND_ACC_DONE_PASS_TWO; #else @@ -168,7 +188,9 @@ int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ /* }}} */ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ { +#ifdef ZEND_ENGINE_2 zend_op *opline, *opline_end; +#endif #ifdef ZEND_ENGINE_2_4 zend_literal *literal = op_array->literals; #endif @@ -198,17 +220,18 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ } #endif +#ifdef ZEND_ENGINE_2 opline = op_array->opcodes; opline_end = opline + op_array->last; while (opline < opline_end) { -#ifdef ZEND_ENGINE_2_4 +# ifdef ZEND_ENGINE_2_4 if (opline->op1_type == IS_CONST) { opline->op1.literal = op_array->literals + opline->op1.constant; } if (opline->op2_type == IS_CONST) { opline->op2.literal = op_array->literals + opline->op2.constant; } -#else +# else if (Z_OP_TYPE(opline->op1) == IS_CONST) { Z_SET_ISREF(Z_OP_CONSTANT(opline->op1)); Z_SET_REFCOUNT(Z_OP_CONSTANT(opline->op1), 2); /* Make sure is_ref won't be reset */ @@ -217,15 +240,15 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ Z_SET_ISREF(Z_OP_CONSTANT(opline->op2)); Z_SET_REFCOUNT(Z_OP_CONSTANT(opline->op2), 2); } -#endif +# endif switch (opline->opcode) { -#ifdef ZEND_GOTO +# ifdef ZEND_GOTO case ZEND_GOTO: -#endif +# endif case ZEND_JMP: -#ifdef ZEND_FAST_CALL +# ifdef ZEND_FAST_CALL case ZEND_FAST_CALL: -#endif +# endif assert(Z_OP(opline->op1).opline_num < op_array->last); Z_OP(opline->op1).jmp_addr = op_array->opcodes + Z_OP(opline->op1).opline_num; break; @@ -233,12 +256,12 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: -#ifdef ZEND_JMP_SET +# ifdef ZEND_JMP_SET case ZEND_JMP_SET: -#endif -#ifdef ZEND_JMP_SET_VAR +# endif +# ifdef ZEND_JMP_SET_VAR case ZEND_JMP_SET_VAR: -#endif +# endif assert(Z_OP(opline->op2).opline_num < op_array->last); Z_OP(opline->op2).jmp_addr = op_array->opcodes + Z_OP(opline->op2).opline_num; break; @@ -246,6 +269,7 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ /* ZEND_VM_SET_OPCODE_HANDLER(opline); this is not undone, don't redo. only do this for loader */ opline++; } +#endif /* ZEND_ENGINE_2 */ #ifdef ZEND_ENGINE_2_4 op_array->fn_flags |= ZEND_ACC_DONE_PASS_TWO; @@ -258,6 +282,7 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ static void xc_fix_opcode_ex_znode(int tofix, xc_op_spec_t spec, Z_OP_TYPEOF_TYPE *op_type, znode_op *op, int type TSRMLS_DC) /* {{{ */ { +#ifdef ZEND_ENGINE_2 if ((*op_type != IS_UNUSED && (spec == OPSPEC_UCLASS || spec == OPSPEC_CLASS)) || spec == OPSPEC_FETCH) { if (tofix) { @@ -283,6 +308,7 @@ static void xc_fix_opcode_ex_znode(int tofix, xc_op_spec_t spec, Z_OP_TYPEOF_TYP Z_OP(*op).var *= sizeof(temp_variable); } } +#endif } /* }}} */ @@ -359,9 +385,17 @@ int xc_foreach_early_binding_class(zend_op_array *op_array, xc_foreach_early_bin opline = opline_end; break; +#ifdef ZEND_ENGINE_2 case ZEND_DECLARE_INHERITED_CLASS: callback(opline, opline - begin, data TSRMLS_CC); break; +#else + case ZEND_DECLARE_FUNCTION_OR_CLASS: + if (opline->extended_value == ZEND_DECLARE_INHERITED_CLASS) { + callback(opline, opline - begin, data TSRMLS_CC); + } + break; +#endif } if (opline < next) { @@ -385,6 +419,7 @@ int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, int opl opline = &(op_array->opcodes[oplineno]); switch (opline->opcode) { +#ifdef ZEND_ENGINE_2 case ZEND_DECLARE_INHERITED_CLASS: { zval *parent_name; @@ -433,6 +468,12 @@ int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, int opl abstract_op->opcode = ZEND_NOP; ZEND_VM_SET_OPCODE_HANDLER(abstract_op); } +#else + case ZEND_DECLARE_FUNCTION_OR_CLASS: + if (do_bind_function_or_class(opline, NULL, class_table, 1) == FAILURE) { + return FAILURE; + } +#endif break; default: @@ -494,7 +535,7 @@ void xc_install_function(ZEND_24(NOTHING, const) char *filename, zend_function * func, sizeof(zend_op_array), NULL ) == FAILURE) { - CG(zend_lineno) = func->op_array.line_start; + CG(zend_lineno) = ZESW(func->op_array.opcodes[0].lineno, func->op_array.line_start); #ifdef IS_UNICODE zend_error(E_ERROR, "Cannot redeclare %R()", type, key); #else @@ -504,9 +545,11 @@ void xc_install_function(ZEND_24(NOTHING, const) char *filename, zend_function * } } /* }}} */ -void xc_install_class(ZEND_24(NOTHING, const) char *filename, zend_class_entry *ce, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ +ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(NOTHING, const) char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ { zend_bool istmpkey; + zend_class_entry *cep = CestToCePtr(*cest); + ZESW(void *stored_ce_ptr, NOTHING); #ifdef IS_UNICODE istmpkey = (type == IS_STRING && ZSTR_S(key)[0] == 0) || ZSTR_U(key)[0] == 0; @@ -515,8 +558,8 @@ void xc_install_class(ZEND_24(NOTHING, const) char *filename, zend_class_entry * #endif if (istmpkey) { zend_u_hash_quick_update(CG(class_table), type, key, len, h, - &ce, sizeof(zend_class_entry *), - NULL + cest, sizeof(xc_cest_t), + ZESW(&stored_ce_ptr, NULL) ); #ifndef ZEND_COMPILE_DELAYED_BINDING if (oplineno != -1) { @@ -525,17 +568,18 @@ void xc_install_class(ZEND_24(NOTHING, const) char *filename, zend_class_entry * #endif } else if (zend_u_hash_quick_add(CG(class_table), type, key, len, h, - &ce, sizeof(zend_class_entry *), - NULL + cest, sizeof(xc_cest_t), + ZESW(&stored_ce_ptr, NULL) ) == FAILURE) { - CG(zend_lineno) = Z_CLASS_INFO(*ce).line_start; + CG(zend_lineno) = ZESW(0, Z_CLASS_INFO(*cep).line_start); #ifdef IS_UNICODE - zend_error(E_ERROR, "Cannot redeclare class %R", type, ce->name); + zend_error(E_ERROR, "Cannot redeclare class %R", type, cep->name); #else - zend_error(E_ERROR, "Cannot redeclare class %s", ce->name); + zend_error(E_ERROR, "Cannot redeclare class %s", cep->name); #endif assert(oplineno == -1); } + ZESW(return (xc_cest_t *) stored_ce_ptr, NOTHING); } /* }}} */ diff --git a/xcache/xc_utils.h b/xcache/xc_utils.h index 0688059..eae8826 100644 --- a/xcache/xc_utils.h +++ b/xcache/xc_utils.h @@ -42,7 +42,7 @@ int xc_foreach_early_binding_class(zend_op_array *op_array, xc_foreach_early_bin void xc_install_constant(ZEND_24(NOTHING, const) char *filename, zend_constant *constant, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); #endif void xc_install_function(ZEND_24(NOTHING, const) char *filename, zend_function *func, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); -void xc_install_class(ZEND_24(NOTHING, const) char *filename, zend_class_entry *class_entry, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); +ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(NOTHING, const) char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); typedef zend_bool (*xc_if_func_t)(void *data);