zend_vm_execute.skl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {%DEFINES%}
  2. ZEND_API void {%EXECUTOR_NAME%}_ex(zend_execute_data *ex)
  3. {
  4. DCL_OPLINE
  5. {%HELPER_VARS%}
  6. {%INTERNAL_LABELS%}
  7. LOAD_OPLINE();
  8. ZEND_VM_LOOP_INTERRUPT_CHECK();
  9. while (1) {
  10. {%ZEND_VM_CONTINUE_LABEL%}
  11. {%ZEND_VM_DISPATCH%} {
  12. {%INTERNAL_EXECUTOR%}
  13. }
  14. }
  15. zend_error_noreturn(E_CORE_ERROR, "Arrived at end of main loop which shouldn't happen");
  16. }
  17. ZEND_API void zend_{%EXECUTOR_NAME%}(zend_op_array *op_array, zval *return_value)
  18. {
  19. zend_execute_data *execute_data;
  20. if (EG(exception) != NULL) {
  21. return;
  22. }
  23. execute_data = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_CODE | ZEND_CALL_HAS_SYMBOL_TABLE,
  24. (zend_function*)op_array, 0, zend_get_called_scope(EG(current_execute_data)), zend_get_this_object(EG(current_execute_data)));
  25. if (EG(current_execute_data)) {
  26. execute_data->symbol_table = zend_rebuild_symbol_table();
  27. } else {
  28. execute_data->symbol_table = &EG(symbol_table);
  29. }
  30. EX(prev_execute_data) = EG(current_execute_data);
  31. i_init_code_execute_data(execute_data, op_array, return_value);
  32. zend_{%EXECUTOR_NAME%}_ex(execute_data);
  33. zend_vm_stack_free_call_frame(execute_data);
  34. }
  35. {%EXTERNAL_EXECUTOR%}
  36. void {%INITIALIZER_NAME%}(void)
  37. {
  38. {%EXTERNAL_LABELS%}
  39. VM_TRACE_START();
  40. }
  41. void zend_vm_dtor(void)
  42. {
  43. VM_TRACE_END();
  44. }
  45. static HashTable *zend_handlers_table = NULL;
  46. static void init_opcode_serialiser(void)
  47. {
  48. int i;
  49. zval tmp;
  50. zend_handlers_table = malloc(sizeof(HashTable));
  51. zend_hash_init_ex(zend_handlers_table, zend_handlers_count, NULL, NULL, 1, 0);
  52. zend_hash_real_init(zend_handlers_table, 0);
  53. Z_TYPE_INFO(tmp) = IS_LONG;
  54. for (i = 0; i < zend_handlers_count; i++) {
  55. Z_LVAL(tmp) = i;
  56. zend_hash_index_add(zend_handlers_table, (zend_long)(zend_uintptr_t)zend_opcode_handlers[i], &tmp);
  57. }
  58. }
  59. ZEND_API void ZEND_FASTCALL zend_serialize_opcode_handler(zend_op *op)
  60. {
  61. zval *zv;
  62. if (!zend_handlers_table) {
  63. init_opcode_serialiser();
  64. }
  65. zv = zend_hash_index_find(zend_handlers_table, (zend_long)(zend_uintptr_t)op->handler);
  66. ZEND_ASSERT(zv != NULL);
  67. op->handler = (const void *)(zend_uintptr_t)Z_LVAL_P(zv);
  68. }
  69. ZEND_API void ZEND_FASTCALL zend_deserialize_opcode_handler(zend_op *op)
  70. {
  71. op->handler = zend_opcode_handlers[(zend_uintptr_t)op->handler];
  72. }
  73. ZEND_API const void* ZEND_FASTCALL zend_get_opcode_handler_func(const zend_op *op)
  74. {
  75. #if ZEND_VM_KIND == ZEND_VM_KIND_CALL
  76. return op->handler;
  77. #elif ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
  78. zval *zv;
  79. if (!zend_handlers_table) {
  80. init_opcode_serialiser();
  81. }
  82. zv = zend_hash_index_find(zend_handlers_table, (zend_long)(zend_uintptr_t)op->handler);
  83. ZEND_ASSERT(zv != NULL);
  84. return zend_opcode_handler_funcs[Z_LVAL_P(zv)];
  85. #else
  86. return NULL;
  87. #endif
  88. }
  89. ZEND_API const zend_op *zend_get_halt_op(void)
  90. {
  91. #if ZEND_VM_KIND == ZEND_VM_KIND_HYBRID
  92. return &hybrid_halt_op;
  93. #else
  94. return NULL;
  95. #endif
  96. }
  97. ZEND_API int zend_vm_kind(void)
  98. {
  99. return ZEND_VM_KIND;
  100. }