PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_execute.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 87 90 96.7 %
Date: 2015-07-26 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifndef ZEND_EXECUTE_H
      23             : #define ZEND_EXECUTE_H
      24             : 
      25             : #include "zend_compile.h"
      26             : #include "zend_hash.h"
      27             : #include "zend_operators.h"
      28             : #include "zend_variables.h"
      29             : 
      30             : BEGIN_EXTERN_C()
      31             : struct _zend_fcall_info;
      32             : ZEND_API extern void (*zend_execute_ex)(zend_execute_data *execute_data);
      33             : ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
      34             : 
      35             : void init_executor(void);
      36             : void shutdown_executor(void);
      37             : void shutdown_destructors(void);
      38             : ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
      39             : ZEND_API zend_execute_data *zend_create_generator_execute_data(zend_execute_data *call, zend_op_array *op_array, zval *return_value);
      40             : ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
      41             : ZEND_API void execute_ex(zend_execute_data *execute_data);
      42             : ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value);
      43             : ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
      44             : ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload);
      45             : ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex);
      46             : ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex);
      47             : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name);
      48             : ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name);
      49             : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions);
      50             : ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions);
      51             : 
      52             : ZEND_API char * zend_verify_internal_arg_class_kind(const zend_internal_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce);
      53             : ZEND_API void zend_verify_arg_error(const zend_function *zf, uint32_t arg_num, const char *need_msg, const char *need_kind, const char *given_msg, const char *given_kind, zval *arg);
      54             : ZEND_API void zend_verify_return_error(const zend_function *zf, const char *need_msg, const char *need_kind, const char *returned_msg, const char *returned_kind);
      55             : ZEND_API void zend_verify_internal_return_error(const zend_function *zf, const char *need_msg, const char *need_kind, const char *returned_msg, const char *returned_kind);
      56             : 
      57             : static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type)
      58             : {
      59    25903112 :         zend_refcounted *ref = NULL;
      60             : 
      61    43188601 :         if ((value_type & (IS_VAR|IS_CV)) && Z_ISREF_P(value)) {
      62      842427 :                 ref = Z_COUNTED_P(value);
      63      842427 :                 value = Z_REFVAL_P(value);
      64             :         }
      65             : 
      66             :         do {
      67    25903112 :                 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
      68             :                         zend_refcounted *garbage;
      69             : 
      70    16750880 :                         if (Z_ISREF_P(variable_ptr)) {
      71     2773681 :                                 variable_ptr = Z_REFVAL_P(variable_ptr);
      72     2773681 :                                 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
      73             :                                         break;
      74             :                                 }
      75             :                         }
      76    15821300 :                         if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
      77      840955 :                         UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
      78           0 :                                 Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value);
      79           0 :                                 return variable_ptr;
      80             :                         }
      81    14980345 :                         if ((value_type & (IS_VAR|IS_CV)) && variable_ptr == value) {
      82         120 :                                 return variable_ptr;
      83             :                         }
      84    14980225 :                         garbage = Z_COUNTED_P(variable_ptr);
      85    14980225 :                         if (--GC_REFCOUNT(garbage) == 0) {
      86     8334262 :                                 ZVAL_COPY_VALUE(variable_ptr, value);
      87     8334262 :                                 if (value_type == IS_CONST) {
      88             :                                         /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
      89     1012241 :                                         if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
      90       14913 :                                                 zval_copy_ctor_func(variable_ptr);
      91             :                                         }
      92     7322021 :                                 } else if (value_type == IS_CV) {
      93     1489033 :                                         if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
      94             :                                                 Z_ADDREF_P(variable_ptr);
      95             :                                         }
      96     5832988 :                                 } else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) {
      97           4 :                                         if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
      98           0 :                                                 efree_size(ref, sizeof(zend_reference));
      99           4 :                                         } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
     100             :                                                 Z_ADDREF_P(variable_ptr);
     101             :                                         }
     102             :                                 }
     103     8334262 :                                 zval_dtor_func_for_ptr(garbage);
     104     8334261 :                                 return variable_ptr;
     105             :                         } else { /* we need to split */
     106             :                                 /* optimized version of GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) */
     107     6961803 :                                 if ((Z_COLLECTABLE_P(variable_ptr)) &&
     108      315840 :                                 UNEXPECTED(!GC_INFO(garbage))) {
     109       28027 :                                         gc_possible_root(garbage);
     110             :                                 }
     111             :                         }
     112             :                 }
     113             :         } while (0);
     114             : 
     115    17568730 :         ZVAL_COPY_VALUE(variable_ptr, value);
     116    17568730 :         if (value_type == IS_CONST) {
     117             :                 /* IS_CONST can't be IS_OBJECT, IS_RESOURCE or IS_REFERENCE */
     118     4639638 :                 if (UNEXPECTED(Z_OPT_COPYABLE_P(variable_ptr))) {
     119      205242 :                         zval_copy_ctor_func(variable_ptr);
     120             :                 }
     121    12929092 :         } else if (value_type == IS_CV) {
     122     4110375 :                 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
     123             :                         Z_ADDREF_P(variable_ptr);
     124             :                 }
     125     8818717 :         } else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) {
     126          15 :                 if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
     127           1 :                         efree_size(ref, sizeof(zend_reference));
     128          14 :                 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
     129             :                         Z_ADDREF_P(variable_ptr);
     130             :                 }
     131             :         }
     132    17568730 :         return variable_ptr;
     133             : }
     134             : 
     135             : ZEND_API int zval_update_constant(zval *pp, zend_bool inline_change);
     136             : ZEND_API int zval_update_constant_ex(zval *pp, zend_bool inline_change, zend_class_entry *scope);
     137             : 
     138             : /* dedicated Zend executor functions - do not use! */
     139             : struct _zend_vm_stack {
     140             :         zval *top;
     141             :         zval *end;
     142             :         zend_vm_stack prev;
     143             : };
     144             : 
     145             : #define ZEND_VM_STACK_HEADER_SLOTS \
     146             :         ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
     147             : 
     148             : #define ZEND_VM_STACK_ELEMETS(stack) \
     149             :         (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
     150             : 
     151             : /*
     152             :  * In general in RELEASE build ZEND_ASSERT() must be zero-cost, but for some
     153             :  * reason, GCC generated worse code, performing CSE on assertion code and the
     154             :  * following "slow path" and moving memory read operatins from slow path into
     155             :  * common header. This made a degradation for the fast path.
     156             :  * The following "#if ZEND_DEBUG" eliminates it.
     157             :  */
     158             : #if ZEND_DEBUG
     159             : # define ZEND_ASSERT_VM_STACK(stack) ZEND_ASSERT(stack->top > (zval *) stack && stack->end > (zval *) stack && stack->top <= stack->end)
     160             : # define ZEND_ASSERT_VM_STACK_GLOBAL ZEND_ASSERT(EG(vm_stack_top) > (zval *) EG(vm_stack) && EG(vm_stack_end) > (zval *) EG(vm_stack) && EG(vm_stack_top) <= EG(vm_stack_end))
     161             : #else
     162             : # define ZEND_ASSERT_VM_STACK(stack)
     163             : # define ZEND_ASSERT_VM_STACK_GLOBAL
     164             : #endif
     165             : 
     166             : ZEND_API void zend_vm_stack_init(void);
     167             : ZEND_API void zend_vm_stack_destroy(void);
     168             : ZEND_API void* zend_vm_stack_extend(size_t size);
     169             : 
     170             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     171             : {
     172    28329162 :         zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
     173             : 
     174             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     175             : 
     176    28329162 :         if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
     177           4 :                 call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
     178           4 :                 ZEND_SET_CALL_INFO(call, call_info | ZEND_CALL_ALLOCATED);
     179             :         } else {
     180    28329158 :                 EG(vm_stack_top) = (zval*)((char*)call + used_stack);
     181    28329158 :                 ZEND_SET_CALL_INFO(call, call_info);
     182             :         }
     183             : 
     184             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     185             : 
     186    28329162 :         call->func = func;
     187    28329162 :         Z_OBJ(call->This) = object;
     188    28329162 :         ZEND_CALL_NUM_ARGS(call) = num_args;
     189    28329162 :         call->called_scope = called_scope;
     190    28329162 :         return call;
     191             : }
     192             : 
     193             : static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, zend_function *func)
     194             : {
     195     4543979 :         uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
     196             : 
     197     4543979 :         if (EXPECTED(ZEND_USER_CODE(func->type))) {
     198     1099547 :                 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
     199             :         }
     200     4543979 :         return used_stack * sizeof(zval);
     201             : }
     202             : 
     203             : static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     204             : {
     205     4310400 :         uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
     206             : 
     207     4310400 :         return zend_vm_stack_push_call_frame_ex(used_stack, call_info,
     208             :                 func, num_args, called_scope, object);
     209             : }
     210             : 
     211             : static zend_always_inline void zend_vm_stack_free_extra_args_ex(uint32_t call_info, zend_execute_data *call)
     212             : {
     213     2030715 :         if (UNEXPECTED(call_info & ZEND_CALL_FREE_EXTRA_ARGS)) {
     214         393 :                 zval *end = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
     215         393 :                 zval *p = end + (ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args);
     216             :                 do {
     217        1095 :                         p--;
     218        1095 :                         if (Z_REFCOUNTED_P(p)) {
     219         735 :                                 if (!Z_DELREF_P(p)) {
     220           5 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     221           5 :                                         ZVAL_NULL(p);
     222           5 :                                         zval_dtor_func_for_ptr(r);
     223             :                                 } else {
     224             :                                         GC_ZVAL_CHECK_POSSIBLE_ROOT(p);
     225             :                                 }
     226             :                         }
     227        1095 :                 } while (p != end);
     228             :         }
     229             : }
     230             : 
     231             : static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call)
     232             : {
     233       50383 :         zend_vm_stack_free_extra_args_ex(ZEND_CALL_INFO(call), call);
     234             : }
     235             : 
     236             : static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call)
     237             : {
     238    26217532 :         uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
     239             : 
     240    26217532 :         if (EXPECTED(num_args > 0)) {
     241    19567738 :                 zval *end = ZEND_CALL_ARG(call, 1);
     242    19567738 :                 zval *p = end + num_args;
     243             : 
     244             :                 do {
     245    34836824 :                         p--;
     246    34836824 :                         if (Z_REFCOUNTED_P(p)) {
     247    20906247 :                                 if (!Z_DELREF_P(p)) {
     248     1772060 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     249     1772060 :                                         ZVAL_NULL(p);
     250     1772060 :                                         zval_dtor_func_for_ptr(r);
     251             :                                 }
     252             :                         }
     253    34836824 :                 } while (p != end);
     254             :         }
     255             : }
     256             : 
     257             : static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_info, zend_execute_data *call)
     258             : {
     259             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     260             : 
     261    28277182 :         if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
     262           8 :                 zend_vm_stack p = EG(vm_stack);
     263             : 
     264           8 :                 zend_vm_stack prev = p->prev;
     265             : 
     266           8 :                 EG(vm_stack_top) = prev->top;
     267           8 :                 EG(vm_stack_end) = prev->end;
     268           8 :                 EG(vm_stack) = prev;
     269           8 :                 efree(p);
     270             : 
     271             :         } else {
     272    28277174 :                 EG(vm_stack_top) = (zval*)call;
     273             :         }
     274             : 
     275             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     276             : }
     277             : 
     278             : static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call)
     279             : {
     280    26732497 :         zend_vm_stack_free_call_frame_ex(ZEND_CALL_INFO(call), call);
     281             : }
     282             : 
     283             : /* services */
     284             : ZEND_API const char *get_active_class_name(const char **space);
     285             : ZEND_API const char *get_active_function_name(void);
     286             : ZEND_API const char *zend_get_executed_filename(void);
     287             : ZEND_API zend_string *zend_get_executed_filename_ex(void);
     288             : ZEND_API uint zend_get_executed_lineno(void);
     289             : ZEND_API zend_bool zend_is_executing(void);
     290             : 
     291             : ZEND_API void zend_set_timeout(zend_long seconds, int reset_signals);
     292             : ZEND_API void zend_unset_timeout(void);
     293             : ZEND_API void zend_timeout(int dummy);
     294             : ZEND_API zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type);
     295             : ZEND_API zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type);
     296             : void zend_verify_abstract_class(zend_class_entry *ce);
     297             : 
     298             : ZEND_API void zend_fetch_dimension_by_zval(zval *result, zval *container, zval *dim);
     299             : 
     300             : ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
     301             : 
     302             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     303             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     304             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     305             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     306             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     307             : 
     308             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     309             : 
     310             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     311             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     312             : 
     313             : /* former zend_execute_locks.h */
     314             : typedef zval* zend_free_op;
     315             : 
     316             : ZEND_API zval *zend_get_zval_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type);
     317             : 
     318             : ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table);
     319             : void zend_free_compiled_variables(zend_execute_data *execute_data);
     320             : void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num);
     321             : 
     322             : #define CACHE_ADDR(num) \
     323             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))
     324             : 
     325             : #define CACHED_PTR(num) \
     326             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0]
     327             : 
     328             : #define CACHE_PTR(num, ptr) do { \
     329             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] = (ptr); \
     330             :         } while (0)
     331             : 
     332             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     333             :         (EXPECTED(((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] == (void*)(ce)) ? \
     334             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[1] : \
     335             :                 NULL)
     336             : 
     337             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     338             :                 void **slot = (void**)((char*)EX_RUN_TIME_CACHE() + (num)); \
     339             :                 slot[0] = (ce); \
     340             :                 slot[1] = (ptr); \
     341             :         } while (0)
     342             : 
     343             : #define CACHED_PTR_EX(slot) \
     344             :         (slot)[0]
     345             : 
     346             : #define CACHE_PTR_EX(slot, ptr) do { \
     347             :                 (slot)[0] = (ptr); \
     348             :         } while (0)
     349             : 
     350             : #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
     351             :         (EXPECTED((slot)[0] == (ce)) ? (slot)[1] : NULL)
     352             : 
     353             : #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
     354             :                 (slot)[0] = (ce); \
     355             :                 (slot)[1] = (ptr); \
     356             :         } while (0)
     357             : 
     358             : END_EXTERN_C()
     359             : 
     360             : #endif /* ZEND_EXECUTE_H */
     361             : 
     362             : /*
     363             :  * Local variables:
     364             :  * tab-width: 4
     365             :  * c-basic-offset: 4
     366             :  * indent-tabs-mode: t
     367             :  * End:
     368             :  */

Generated by: LCOV version 1.10

Generated at Mon, 27 Jul 2015 02:32:15 +0000 (2 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.