From 5d85c2567074f0e55e029a22a34e36bc8517b082 Mon Sep 17 00:00:00 2001 From: Xuefer Date: Sun, 5 Jul 2009 06:30:54 +0000 Subject: [PATCH] PHP 5.3 support git-svn-id: svn://svn.lighttpd.net/xcache/branches/1.3@617 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- const_string.c | 18 ++-- const_string_opcodes_php5.3.h | 156 ++++++++++++++++++++++++++++++++++ coverager.c | 5 +- prepare.devel | 5 ++ prepare.devel.inc.example | 1 + processor/processor.m4 | 23 +++-- utils.c | 20 +++-- xcache.c | 13 +-- xcache.h | 19 +++++ 9 files changed, 230 insertions(+), 30 deletions(-) create mode 100644 const_string_opcodes_php5.3.h diff --git a/const_string.c b/const_string.c index 5b310f1..6ce8320 100644 --- a/const_string.c +++ b/const_string.c @@ -88,17 +88,13 @@ const char *xc_get_data_type(zend_uchar data_type) /* }}} */ /* {{{ xc_get_opcode */ #if PHP_MAJOR_VERSION >= 6 -# include "const_string_opcodes_php6.x.h" -#else -# ifdef ZEND_ENGINE_2_1 -# include "const_string_opcodes_php5.1.h" -# else -# ifdef ZEND_ENGINE_2 -# include "const_string_opcodes_php5.0.h" -# else -# include "const_string_opcodes_php4.x.h" -# endif -# endif +# include "const_string_opcodes_php6.x.h" +#elif defined(ZEND_ENGINE_2_3) +# include "const_string_opcodes_php5.3.h" +#elif defined(ZEND_ENGINE_2_1) +# include "const_string_opcodes_php5.1.h" +#elif defined(ZEND_ENGINE_2) +# include "const_string_opcodes_php5.0.h" #endif zend_uchar xc_get_opcode_count() diff --git a/const_string_opcodes_php5.3.h b/const_string_opcodes_php5.3.h new file mode 100644 index 0000000..10b1ba3 --- /dev/null +++ b/const_string_opcodes_php5.3.h @@ -0,0 +1,156 @@ +/* size = 152 */ +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 */ "INIT_NS_FCALL_BY_NAME", +/* 70 */ "FREE", +/* 71 */ "INIT_ARRAY", +/* 72 */ "ADD_ARRAY_ELEMENT", +/* 73 */ "INCLUDE_OR_EVAL", +/* 74 */ "UNSET_VAR", +/* 75 */ "UNSET_DIM", +/* 76 */ "UNSET_OBJ", +/* 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 */ "UNDEF", +/* 101 */ "EXT_STMT", +/* 102 */ "EXT_FCALL_BEGIN", +/* 103 */ "EXT_FCALL_END", +/* 104 */ "EXT_NOP", +/* 105 */ "TICKS", +/* 106 */ "SEND_VAR_NO_REF", +/* 107 */ "CATCH", +/* 108 */ "THROW", +/* 109 */ "FETCH_CLASS", +/* 110 */ "CLONE", +/* 111 */ "UNDEF", +/* 112 */ "INIT_METHOD_CALL", +/* 113 */ "INIT_STATIC_METHOD_CALL", +/* 114 */ "ISSET_ISEMPTY_VAR", +/* 115 */ "ISSET_ISEMPTY_DIM_OBJ", +/* 116 */ "UNDEF", +/* 117 */ "UNDEF", +/* 118 */ "UNDEF", +/* 119 */ "UNDEF", +/* 120 */ "UNDEF", +/* 121 */ "UNDEF", +/* 122 */ "UNDEF", +/* 123 */ "UNDEF", +/* 124 */ "UNDEF", +/* 125 */ "UNDEF", +/* 126 */ "UNDEF", +/* 127 */ "UNDEF", +/* 128 */ "UNDEF", +/* 129 */ "UNDEF", +/* 130 */ "UNDEF", +/* 131 */ "UNDEF", +/* 132 */ "PRE_INC_OBJ", +/* 133 */ "PRE_DEC_OBJ", +/* 134 */ "POST_INC_OBJ", +/* 135 */ "POST_DEC_OBJ", +/* 136 */ "ASSIGN_OBJ", +/* 137 */ "OP_DATA", +/* 138 */ "INSTANCEOF", +/* 139 */ "DECLARE_CLASS", +/* 140 */ "DECLARE_INHERITED_CLASS", +/* 141 */ "DECLARE_FUNCTION", +/* 142 */ "RAISE_ABSTRACT_ERROR", +/* 143 */ "DECLARE_CONST", +/* 144 */ "ADD_INTERFACE", +/* 145 */ "UNDEF", +/* 146 */ "VERIFY_ABSTRACT_CLASS", +/* 147 */ "ASSIGN_DIM", +/* 148 */ "ISSET_ISEMPTY_PROP_OBJ", +/* 149 */ "HANDLE_EXCEPTION", +/* 150 */ "USER_OPCODE", +/* 151 */ "UNDEF", +/* 152 */ "JMP_SET" +}; diff --git a/coverager.c b/coverager.c index e852066..dbf884e 100644 --- a/coverager.c +++ b/coverager.c @@ -35,9 +35,10 @@ void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC { char *fullpath; struct stat st; + ALLOCA_FLAG(use_heap) TRACE("mkdirs %s %d %s %d", root, rootlen, path, pathlen); - fullpath = do_alloca(rootlen + pathlen + 1); + fullpath = my_do_alloca(rootlen + pathlen + 1, use_heap); memcpy(fullpath, root, rootlen); memcpy(fullpath + rootlen, path, pathlen); fullpath[rootlen + pathlen] = '\0'; @@ -58,7 +59,7 @@ void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC mkdir(fullpath, 0700); #endif } - free_alloca(fullpath); + my_free_alloca(fullpath, use_heap); } /* }}} */ static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t cov TSRMLS_DC) /* {{{ */ diff --git a/prepare.devel b/prepare.devel index e279f50..12ab58b 100755 --- a/prepare.devel +++ b/prepare.devel @@ -27,6 +27,7 @@ make_const_string() { make_const_string_opcodes_php4.x.h make_const_string_opcodes_php5.0.h make_const_string_opcodes_php5.1.h + make_const_string_opcodes_php5.3.h make_const_string_opcodes_php6.x.h } @@ -47,6 +48,10 @@ make_const_string_opcodes_php5.1.h() { precheck const_string_opcodes_php5.1.h "${PHP5_1_DIR}/Zend/zend_vm_def.h" && "$AWK" -f ./mkopcode.awk < "$I" > "$O.tmp" && mv "$O.tmp" "$O" } +make_const_string_opcodes_php5.3.h() { + precheck const_string_opcodes_php5.3.h "${PHP5_3_DIR}/Zend/zend_vm_def.h" && "$AWK" -f ./mkopcode.awk < "$I" > "$O.tmp" && mv "$O.tmp" "$O" +} + make_const_string_opcodes_php6.x.h() { precheck const_string_opcodes_php6.x.h "${PHP6_x_DIR}/Zend/zend_vm_def.h" && "$AWK" -f ./mkopcode.awk < "$I" > "$O.tmp" && mv "$O.tmp" "$O" } diff --git a/prepare.devel.inc.example b/prepare.devel.inc.example index ba10760..c5cb79d 100644 --- a/prepare.devel.inc.example +++ b/prepare.devel.inc.example @@ -2,6 +2,7 @@ PHP4_x_DIR= PHP5_0_DIR= PHP5_1_DIR= +PHP5_3_DIR= PHP6_x_DIR= PHP_DEVEL_DIR= diff --git a/processor/processor.m4 b/processor/processor.m4 index eb70cf3..ce51f3d 100644 --- a/processor/processor.m4 +++ b/processor/processor.m4 @@ -80,11 +80,13 @@ DEF_STRUCT_P_FUNC(`zval', , `dnl {{{ zval_copy_ctor(dst); ZVAL_REFCOUNT(dst) = 1; DONE(value) - DONE(refcount) DONE(type) - DONE(is_ref) #ifdef ZEND_ENGINE_2_3 - COPY(idx_type) + DONE(is_ref__gc) + DONE(refcount__gc) +#else + DONE(is_ref) + DONE(refcount) #endif } while(0); return; @@ -148,14 +150,18 @@ proc_unicode: dnl }}} DONE(value) DISPATCH(zval_data_type, type) +#ifdef ZEND_ENGINE_2_3 + DISPATCH(zend_uchar, is_ref__gc) +#else DISPATCH(zend_uchar, is_ref) -#ifdef ZEND_ENGINE_2 +#endif + +#ifdef ZEND_ENGINE_2_3 + DISPATCH(zend_uint, refcount__gc) +#elif defined(ZEND_ENGINE_2) DISPATCH(zend_uint, refcount) #else DISPATCH(zend_ushort, refcount) -#endif -#ifdef ZEND_ENGINE_2_3 - DISPATCH(zend_uchar, idx_type) #endif ')dnl IFDASM ') @@ -478,6 +484,9 @@ DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{ case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: +#ifdef ZEND_JMP_SET + case ZEND_JMP_SET: +#endif dst->op2.u.jmp_addr = processor->active_opcodes_dst + (src->op2.u.jmp_addr - processor->active_opcodes_src); break; diff --git a/utils.c b/utils.c index 57b1b84..0a0a1d5 100644 --- a/utils.c +++ b/utils.c @@ -19,7 +19,7 @@ #endif #define OP_ZVAL_DTOR(op) do { \ - (op).u.constant.is_ref = 0; \ + Z_UNSET_ISREF((op).u.constant); \ zval_dtor(&(op).u.constant); \ } while(0) xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, /* {{{ */ @@ -151,6 +151,9 @@ 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 + case ZEND_JMP_SET: +#endif opline->op2.u.opline_num = opline->op2.u.jmp_addr - op_array->opcodes; assert(opline->op2.u.opline_num < op_array->last); break; @@ -180,12 +183,13 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ end = opline + op_array->last; while (opline < end) { if (opline->op1.op_type == IS_CONST) { - opline->op1.u.constant.is_ref = 1; - opline->op1.u.constant.refcount = 2; /* Make sure is_ref won't be reset */ + Z_SET_ISREF(opline->op1.u.constant); + Z_SET_REFCOUNT(opline->op1.u.constant, 2); /* Make sure is_ref won't be reset */ + } if (opline->op2.op_type == IS_CONST) { - opline->op2.u.constant.is_ref = 1; - opline->op2.u.constant.refcount = 2; + Z_SET_ISREF(opline->op2.u.constant); + Z_SET_REFCOUNT(opline->op2.u.constant, 2); } #ifdef ZEND_ENGINE_2_1 switch (opline->opcode) { @@ -197,6 +201,9 @@ 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 + case ZEND_JMP_SET: +#endif assert(opline->op2.u.opline_num < op_array->last); opline->op2.u.jmp_addr = op_array->opcodes + opline->op2.u.opline_num; break; @@ -298,6 +305,9 @@ int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zen case ZEND_JMPNZ: case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: +#ifdef ZEND_JMP_SET + case ZEND_JMP_SET: +#endif next = begin + opline->op2.u.opline_num; break; diff --git a/xcache.c b/xcache.c index 33ba825..a480b5b 100644 --- a/xcache.c +++ b/xcache.c @@ -541,9 +541,11 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM zend_uint i; xc_entry_data_php_t *p = xce->data.php; zend_op_array *old_active_op_array = CG(active_op_array); + ALLOCA_FLAG(use_heap) + #ifndef ZEND_ENGINE_2 /* new ptr which is stored inside CG(class_table) */ - xc_cest_t **new_cest_ptrs = (xc_cest_t **)do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt); + xc_cest_t **new_cest_ptrs = (xc_cest_t **)my_do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt, use_heap); #endif CG(active_op_array) = p->op_array; @@ -604,7 +606,7 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM } #ifndef ZEND_ENGINE_2 - free_alloca(new_cest_ptrs); + my_free_alloca(new_cest_ptrs, use_heap); #endif CG(active_op_array) = old_active_op_array; return p->op_array; @@ -648,8 +650,9 @@ static int xc_stat(const char *filename, const char *include_path, struct stat * char *tokbuf; int size = strlen(include_path) + 1; char tokens[] = { DEFAULT_DIR_SEPARATOR, '\0' }; + ALLOCA_FLAG(use_heap) - paths = (char *)do_alloca(size); + paths = (char *)my_do_alloca(size, use_heap); memcpy(paths, include_path, size); for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) { @@ -657,12 +660,12 @@ static int xc_stat(const char *filename, const char *include_path, struct stat * continue; } if (VCWD_STAT(filepath, pbuf) == 0) { - free_alloca(paths); + my_free_alloca(paths, use_heap); return SUCCESS; } } - free_alloca(paths); + my_free_alloca(paths, use_heap); return FAILURE; } diff --git a/xcache.h b/xcache.h index 7559346..f420cfe 100644 --- a/xcache.h +++ b/xcache.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "php_ini.h" #include "zend_hash.h" @@ -37,6 +38,24 @@ # define ZESW(v1, v2) v2 #endif +#ifdef ALLOCA_FLAG +# define my_do_alloca(size, use_heap) do_alloca(size, use_heap) +# define my_free_alloca(size, use_heap) free_alloca(size, use_heap) +#else +# define my_do_alloca(size, use_heap) do_alloca(size) +# define my_free_alloca(size, use_heap) free_alloca(size) +# define ALLOCA_FLAG(x) +#endif +#ifndef Z_SET_ISREF +# define Z_SET_ISREF(z) (z).is_ref = 1; +#endif +#ifndef Z_UNSET_ISREF +# define Z_UNSET_ISREF(z) (z).is_ref = 0; +#endif +#ifndef Z_SET_REFCOUNT +# define Z_SET_REFCOUNT(z, rc) (z).refcount = rc; +#endif + /* {{{ dirty fix for PHP 6 */ #ifdef add_assoc_long_ex static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)