Browse Source

fix disassembler for 2.4 literal

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@930 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 10 years ago
parent
commit
9d48a497ba
  1. 7
      disassembler.c
  2. 2
      processor/hashtable.m4
  3. 2
      processor/head.m4
  4. 21
      processor/processor.m4
  5. 6
      processor/struct.m4
  6. 9
      utils.c

7
disassembler.c

@ -22,6 +22,7 @@ static void xc_dasm(xc_sandbox_t *sandbox, zval *dst, zend_op_array *op_array TS
xc_compile_result_t cr;
int bufsize = 2;
char *buf;
xc_dasm_t dasm;
xc_compile_result_init_cur(&cr, op_array TSRMLS_CC);
@ -33,7 +34,7 @@ static void xc_dasm(xc_sandbox_t *sandbox, zval *dst, zend_op_array *op_array TS
ALLOC_INIT_ZVAL(zv);
array_init(zv);
xc_dasm_zend_op_array(zv, op_array TSRMLS_CC);
xc_dasm_zend_op_array(&dasm, zv, op_array TSRMLS_CC);
add_assoc_zval_ex(dst, ZEND_STRS("op_array"), zv);
buf = emalloc(bufsize);
@ -46,7 +47,7 @@ static void xc_dasm(xc_sandbox_t *sandbox, zval *dst, zend_op_array *op_array TS
ALLOC_INIT_ZVAL(zv);
array_init(zv);
xc_dasm_zend_function(zv, b->pData TSRMLS_CC);
xc_dasm_zend_function(&dasm, zv, b->pData TSRMLS_CC);
keysize = BUCKET_KEY_SIZE(b) + 2;
if (keysize > bufsize) {
@ -83,7 +84,7 @@ static void xc_dasm(xc_sandbox_t *sandbox, zval *dst, zend_op_array *op_array TS
ALLOC_INIT_ZVAL(zv);
array_init(zv);
xc_dasm_zend_class_entry(zv, CestToCePtr(*(xc_cest_t *)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) {

2
processor/hashtable.m4

@ -36,7 +36,7 @@ define(`DEF_HASH_TABLE_FUNC', `
for (b = src->pListHead; b != NULL; b = b->pListNext) {
ALLOC_INIT_ZVAL(zv);
array_init(zv);
FUNC_NAME (zv, (($2*)b->pData) TSRMLS_CC);
FUNC_NAME (dasm, zv, (($2*)b->pData) TSRMLS_CC);
keysize = BUCKET_KEY_SIZE(b) + 2;
if (keysize > bufsize) {
do {

2
processor/head.m4

@ -106,6 +106,8 @@ struct _xc_processor_t {
IFAUTOCHECK(xc_stack_t allocsizes;)
};
/* }}} */
/* export: typedef struct _xc_dasm_t { const zend_op_array *active_op_array_src; } xc_dasm_t; :export {{{ */
/* }}} */
/* {{{ memsetptr */
IFAUTOCHECK(`dnl
static void *memsetptr(void *mem, void *content, size_t n)

21
processor/processor.m4

@ -160,7 +160,7 @@ dnl }}}
DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
IFDASM(`
pushdefFUNC_NAME(`zval')
FUNC_NAME (dst, src[0] TSRMLS_CC);
FUNC_NAME (dasm, dst, src[0] TSRMLS_CC);
popdef(`FUNC_NAME')
', `
do {
@ -320,7 +320,7 @@ dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
IFDASM(`
pushdefFUNC_NAME(`zend_trait_alias')
FUNC_NAME (dst, src[0] TSRMLS_CC);
FUNC_NAME (dasm, dst, src[0] TSRMLS_CC);
popdef(`FUNC_NAME')
', `
ALLOC(dst[0], zend_trait_alias)
@ -333,7 +333,7 @@ dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
IFDASM(`
pushdefFUNC_NAME(`zend_trait_precedence')
FUNC_NAME (dst, src[0] TSRMLS_CC);
FUNC_NAME (dasm, dst, src[0] TSRMLS_CC);
popdef(`FUNC_NAME')
', `
ALLOC(dst[0], zend_trait_precedence)
@ -522,7 +522,7 @@ define(`UNION_znode_op', `dnl {{{
IFDASM(`{
zval *zv;
ALLOC_INIT_ZVAL(zv);
*zv = src->$1.literal->constant;
*zv = dasm->active_op_array_src->literals[src->$1.constant].constant;
zval_copy_ctor(zv);
add_assoc_zval_ex(dst, ZEND_STRS("$1.constant"), zv);
}
@ -694,6 +694,9 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
processor->active_op_array_dst = dst;
processor->active_op_array_src = src;
')
IFDASM(`
dasm->active_op_array_src = src;
')
{
IFRESTORE(`
const xc_op_array_info_t *op_array_info = &processor->active_op_array_infos_src[processor->active_op_array_index++];
@ -736,8 +739,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
#ifdef ZEND_ENGINE_2_4
pushdef(`UNION_znode_op_literal', `
if (opline->$1_type == IS_CONST) {
opline->$1.constant = opline->$1.literal - src->literals;
opline->$1.literal = &dst->literals[opline->$1.constant];
opline->$1.literal = &dst->literals[opline->$1.literal - src->literals];
}
')
UNION_znode_op_literal(op1)
@ -750,7 +752,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
case ZEND_GOTO:
#endif
case ZEND_JMP:
Z_OP(opline->op1).jmp_addr = dst->opcodes + (Z_OP(opline->op1).jmp_addr - src->opcodes);
Z_OP(opline->op1).jmp_addr = &dst->opcodes[Z_OP(opline->op1).jmp_addr - src->opcodes];
break;
case ZEND_JMPZ:
@ -763,7 +765,7 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
#ifdef ZEND_JMP_SET_VAR
case ZEND_JMP_SET_VAR:
#endif
Z_OP(opline->op2).jmp_addr = dst->opcodes + (Z_OP(opline->op2).jmp_addr - src->opcodes);
Z_OP(opline->op2).jmp_addr = &dst->opcodes[Z_OP(opline->op2).jmp_addr - src->opcodes];
break;
default:
@ -970,6 +972,9 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
processor->active_op_array_dst = NULL;
processor->active_op_array_src = NULL;
')
IFDASM(`
dasm->active_op_array_src = NULL;
')
')
dnl }}}

6
processor/struct.m4

@ -11,7 +11,7 @@ define(`DECL_STRUCT_P_FUNC', `translit(
IFCALC( `xc_processor_t *processor, const $1 * const src')
IFSTORE( `xc_processor_t *processor, $1 *dst, const $1 * const src')
IFRESTORE(`xc_processor_t *processor, $1 *dst, const $1 * const src')
IFDASM( `zval *dst, const $1 * const src')
IFDASM( `xc_dasm_t *dasm, zval *dst, const $1 * const src')
IFASM( `$1 *dst, const $1 * const src')
TSRMLS_DC
)ifelse(`$3', `', `;')
@ -136,7 +136,7 @@ define(`STRUCT_P_EX', `
IFCALC( `processor, $6 $3')
IFSTORE( `processor, $6 $2, $6 $3')
IFRESTORE(`processor, $6 $2, $6 $3')
IFDASM( `zv, $6 $3')
IFDASM( `dasm, zv, $6 $3')
IFASM( `$6 $2, $6 $3')
TSRMLS_CC
);
@ -191,7 +191,7 @@ define(`STRUCT_ARRAY', `
ALLOC_INIT_ZVAL(zv);
array_init(zv);
FUNC_NAME (zv, &(SRC(`$4[LOOPCOUNTER]')) TSRMLS_CC);
FUNC_NAME (dasm, zv, &(SRC(`$4[LOOPCOUNTER]')) TSRMLS_CC);
add_next_index_zval(arr, zv);
}
add_assoc_zval_ex(dst, ZEND_STRS("$4"), arr);

9
utils.c

@ -239,7 +239,14 @@ int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */
opline = op_array->opcodes;
end = opline + op_array->last;
while (opline < end) {
#ifndef 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
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 */

Loading…
Cancel
Save