| 263 | | |
|---|
| 264 | | #ifdef ZEND_ENGINE_2 |
|---|
| 265 | | static opcode_handler_t eaccelerator_opcode_handlers[LAST_OPCODE]; |
|---|
| 266 | | static int handlers_retrived = 0; |
|---|
| 267 | | |
|---|
| 268 | | ZEND_DLEXPORT void retrive_opcode_handlers_handler(zend_op_array *op_array) { |
|---|
| 269 | | unsigned char i; |
|---|
| 270 | | efree(op_array->opcodes); |
|---|
| 271 | | op_array->opcodes = (zend_op*)emalloc(sizeof(zend_op)*(LAST_OPCODE)); |
|---|
| 272 | | op_array->last = LAST_OPCODE; |
|---|
| 273 | | op_array->size = LAST_OPCODE; |
|---|
| 274 | | op_array->T = 0; |
|---|
| 275 | | for (i=0; i<LAST_OPCODE; i++) { |
|---|
| 276 | | op_array->opcodes[i].opcode = i; |
|---|
| 277 | | op_array->opcodes[i].op1.op_type = IS_UNUSED; |
|---|
| 278 | | op_array->opcodes[i].op1.u.opline_num = i; |
|---|
| 279 | | op_array->opcodes[i].op2.op_type = IS_UNUSED; |
|---|
| 280 | | op_array->opcodes[i].op2.u.opline_num = i; |
|---|
| 281 | | op_array->opcodes[i].result.op_type = IS_UNUSED; |
|---|
| 282 | | } |
|---|
| 283 | | } |
|---|
| 284 | | |
|---|
| 285 | | static int retrive_opcode_handlers(TSRMLS_D) { |
|---|
| 286 | | zend_extension* ext; |
|---|
| 287 | | |
|---|
| 288 | | if ((ext = zend_get_extension(EACCELERATOR_EXTENSION_NAME)) != NULL) { |
|---|
| 289 | | zend_op_array* p; |
|---|
| 290 | | zval str; |
|---|
| 291 | | void (*old)(zend_op_array *o_a); |
|---|
| 292 | | |
|---|
| 293 | | str.type = IS_STRING; |
|---|
| 294 | | str.is_ref = 1; |
|---|
| 295 | | str.refcount = 2; |
|---|
| 296 | | |
|---|
| 297 | | Z_STRVAL(str) = "return 1;"; |
|---|
| 298 | | Z_STRLEN(str) = 9; |
|---|
| 299 | | old = ext->op_array_handler; |
|---|
| 300 | | ext->op_array_handler = retrive_opcode_handlers_handler; |
|---|
| 301 | | p = compile_string(&str, empty_string TSRMLS_CC); |
|---|
| 302 | | ext->op_array_handler = old; |
|---|
| 303 | | if (p != NULL && p->last == (LAST_OPCODE - 1)) { |
|---|
| 304 | | int i = 0; |
|---|
| 305 | | while (i < LAST_OPCODE) { |
|---|
| 306 | | eaccelerator_opcode_handlers[p->opcodes[i].opcode] = p->opcodes[i].handler; |
|---|
| 307 | | ++i; |
|---|
| 308 | | } |
|---|
| 309 | | return 1; |
|---|
| 310 | | } |
|---|
| 311 | | } |
|---|
| 312 | | return 0; |
|---|
| 313 | | } |
|---|
| 314 | | |
|---|
| 315 | | opcode_handler_t get_opcode_handler(zend_uchar opcode TSRMLS_DC) { |
|---|
| 316 | | if (!handlers_retrived) { |
|---|
| 317 | | if (retrive_opcode_handlers(TSRMLS_C)) { |
|---|
| 318 | | handlers_retrived = 1; |
|---|
| 319 | | } else { |
|---|
| 320 | | return NULL; |
|---|
| 321 | | } |
|---|
| 322 | | } |
|---|
| 323 | | if (opcode < LAST_OPCODE) { |
|---|
| 324 | | return eaccelerator_opcode_handlers[opcode]; |
|---|
| 325 | | } else { |
|---|
| 326 | | return (opcode_handler_t) NULL; |
|---|
| 327 | | } |
|---|
| 328 | | } |
|---|
| 329 | | #endif |
|---|