1
0
Fork 0

5.3 support

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@485 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
This commit is contained in:
Xuefer 2007-12-28 10:16:12 +00:00
parent adf9a227cf
commit b96c159e8e
10 changed files with 246 additions and 36 deletions

View File

@ -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()

View File

@ -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"
};

View File

@ -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) /* {{{ */

View File

@ -150,6 +150,9 @@ static int op_get_flowinfo(op_flowinfo_t *fi, zend_op *opline) /* {{{ */
case ZEND_JMPNZ:
case ZEND_JMPZ_EX:
case ZEND_JMPNZ_EX:
#ifdef ZEND_JMP_SET
case ZEND_JMP_SET:
#endif
#ifdef ZEND_JMP_NO_CTOR
case ZEND_JMP_NO_CTOR:
#endif
@ -346,9 +349,12 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{
bbid_t id;
op_flowinfo_t fi;
zend_op *opline;
bbid_t *bbids = do_alloca(count * sizeof(bbid_t));
bbid_t *catchbbids = do_alloca(count * sizeof(bbid_t));
zend_bool *markbbhead = do_alloca(count * sizeof(zend_bool));
ALLOCA_FLAG(use_heap_bbids)
ALLOCA_FLAG(use_heap_catchbbids)
ALLOCA_FLAG(use_heap_markbbhead)
bbid_t *bbids = my_do_alloca(count * sizeof(bbid_t), use_heap_bbids);
bbid_t *catchbbids = my_do_alloca(count * sizeof(bbid_t), use_heap_catchbbids);
zend_bool *markbbhead = my_do_alloca(count * sizeof(zend_bool), use_heap_markbbhead);
/* {{{ mark jmpin/jumpout */
memset(markbbhead, 0, count * sizeof(zend_bool));
@ -449,9 +455,9 @@ static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count) /* {{{
}
/* }}} */
free_alloca(catchbbids);
free_alloca(bbids);
free_alloca(markbbhead);
my_free_alloca(markbbhead, use_heap_markbbhead);
my_free_alloca(catchbbids, use_heap_catchbbids);
my_free_alloca(bbids, use_heap_bbids);
return SUCCESS;
}
/* }}} */

View File

@ -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"
}

View File

@ -2,6 +2,7 @@
PHP4_x_DIR=
PHP5_0_DIR=
PHP5_1_DIR=
PHP5_3_DIR=
PHP6_x_DIR=
PHP_DEVEL_DIR=

View File

@ -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;

20
utils.c
View File

@ -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;

View File

@ -608,9 +608,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;
@ -671,7 +673,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;
@ -715,8 +717,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)) {
@ -724,12 +727,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;
}
@ -887,6 +890,7 @@ static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce T
int n;
php_stream *stream;
xc_hash_value_t hv;
ulong old_rsid = EG(regular_list).nNextFreeElement;
stream = php_stream_open_wrapper(xce->name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL);
if (!stream) {
@ -900,6 +904,9 @@ static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce T
PHP_MD5Final((unsigned char *) php->md5, &context);
php_stream_close(stream);
if (EG(regular_list).nNextFreeElement = old_rsid + 1) {
EG(regular_list).nNextFreeElement = old_rsid;
}
if (n < 0) {
return FAILURE;

View File

@ -9,6 +9,7 @@
#include <php.h>
#include <zend_compile.h>
#include <zend_API.h>
#include <zend.h>
#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)