zend_vm_execute.skl 3.6 KB

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