范德萨发而为
全部博文(392)
分类: Python/Ruby
2011-05-25 11:08:29
typedef int (*opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS); //在zend_vm_execute.h引用zend_opcode_handlers, //zend_opcode_handlers = (opcode_handler_t*)labels; extern ZEND_API opcode_handler_t *zend_opcode_handlers; |
static const opcode_handler_t labels[] = { ZEND_NOP_SPEC_HANDLER, ZEND_NOP_SPEC_HANDLER, //中间省略。。。。。 ZEND_NOP_SPEC_HANDLER, ZEND_ADD_SPEC_CONST_CONST_HANDLER, ZEND_ADD_SPEC_CONST_TMP_HANDLER, ZEND_ADD_SPEC_CONST_VAR_HANDLER, 。。。。。。。 } |
static opcode_handler_t zend_vm_get_opcode_handler(zend_uchar opcode, zend_op* op) { static const int zend_vm_decode[] = { _UNUSED_CODE, /* 0 */ _CONST_CODE, /* 1 = IS_CONST */ _TMP_CODE, /* 2 = IS_TMP_VAR */ _UNUSED_CODE, /* 3 */ _VAR_CODE, /* 4 = IS_VAR */ _UNUSED_CODE, /* 5 */ _UNUSED_CODE, /* 6 */ _UNUSED_CODE, /* 7 */ _UNUSED_CODE, /* 8 = IS_UNUSED */ _UNUSED_CODE, /* 9 */ _UNUSED_CODE, /* 10 */ _UNUSED_CODE, /* 11 */ _UNUSED_CODE, /* 12 */ _UNUSED_CODE, /* 13 */ _UNUSED_CODE, /* 14 */ _UNUSED_CODE, /* 15 */ _CV_CODE /* 16 = IS_CV */ }; //这句很关键,就是返回处理当前opcode的handler, //zend_opcode_handlers等于上面定义的lables return zend_opcode_handlers[opcode * 25 + zend_vm_decode[op->op1.op_type] * 5 + zend_vm_decode[op->op2.op_type]]; } //设置zend_op里面的handler,指定处理的函数 ZEND_API void zend_vm_set_opcode_handler(zend_op* op) { op->handler = zend_vm_get_opcode_handler(zend_user_opcodes[op->opcode], op); } |
int index; index = opcode * 25 + zend_vm_decode[op->op1.op_type] * 5 + zend_vm_decode[op->op2.op_type]; printf("zend_opcode_handlers_index:%d\n", index); |
static int ZEND_ASSIGN_SPEC_CV_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { zend_op *opline = EX(opline); zval *value = &opline->op2.u.constant; zend_assign_to_variable(&opline->result, &opline->op1, &opline->op2, value, (0?IS_TMP_VAR:IS_CONST), EX(Ts) TSRMLS_CC); /* zend_assign_to_variable() always takes care of op2, never free it! */ ZEND_VM_NEXT_OPCODE(); } |
#include<stdio.h> #include<stdlib.h> int main(int c, char *v[]){ //在labels的偏移量 int offset = atoi(v[1]); FILE *fp; fp = fopen("/home/dexin/op_code_handler.txt","r"); char handler[200]; int i = 0; while(!feof(fp)){ fgets(handler,1024,fp); if(i != offset){ i++; }else{ printf("opcode handler:%s\n", handler); break; } } return 1; } |