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: 84 87 96.6 %
Date: 2016-08-24 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2016 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             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #ifndef ZEND_EXECUTE_H
      24             : #define ZEND_EXECUTE_H
      25             : 
      26             : #include "zend_compile.h"
      27             : #include "zend_hash.h"
      28             : #include "zend_operators.h"
      29             : #include "zend_variables.h"
      30             : 
      31             : BEGIN_EXTERN_C()
      32             : struct _zend_fcall_info;
      33             : ZEND_API extern void (*zend_execute_ex)(zend_execute_data *execute_data);
      34             : ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value);
      35             : 
      36             : void init_executor(void);
      37             : void shutdown_executor(void);
      38             : void shutdown_destructors(void);
      39             : ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, 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             : /* export zend_pass_function to allow comparisons against it */
      53             : extern ZEND_API const zend_internal_function zend_pass_function;
      54             : 
      55             : ZEND_API void ZEND_FASTCALL zend_check_internal_arg_type(zend_function *zf, uint32_t arg_num, zval *arg);
      56             : ZEND_API int  ZEND_FASTCALL zend_check_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, zval *default_value, void **cache_slot);
      57             : ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *execute_data);
      58             : 
      59             : static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval *value, zend_uchar value_type)
      60             : {
      61    35126553 :         zend_refcounted *ref = NULL;
      62             : 
      63    35126553 :         if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) {
      64      811622 :                 ref = Z_COUNTED_P(value);
      65      811622 :                 value = Z_REFVAL_P(value);
      66             :         }
      67             : 
      68             :         do {
      69    35126553 :                 if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) {
      70             :                         zend_refcounted *garbage;
      71             : 
      72    23559767 :                         if (Z_ISREF_P(variable_ptr)) {
      73     8381248 :                                 variable_ptr = Z_REFVAL_P(variable_ptr);
      74     8381248 :                                 if (EXPECTED(!Z_REFCOUNTED_P(variable_ptr))) {
      75             :                                         break;
      76             :                                 }
      77             :                         }
      78    17164321 :                         if (Z_TYPE_P(variable_ptr) == IS_OBJECT &&
      79     1013388 :                         UNEXPECTED(Z_OBJ_HANDLER_P(variable_ptr, set) != NULL)) {
      80           0 :                                 Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value);
      81           0 :                                 return variable_ptr;
      82             :                         }
      83    16150933 :                         if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && variable_ptr == value) {
      84         121 :                                 return variable_ptr;
      85             :                         }
      86    16150812 :                         garbage = Z_COUNTED_P(variable_ptr);
      87    16150812 :                         if (--GC_REFCOUNT(garbage) == 0) {
      88     8830338 :                                 ZVAL_COPY_VALUE(variable_ptr, value);
      89     8830338 :                                 if (value_type & (IS_CONST|IS_CV)) {
      90     2591789 :                                         if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
      91             :                                                 Z_ADDREF_P(variable_ptr);
      92             :                                         }
      93     6238549 :                                 } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
      94           3 :                                         if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
      95           0 :                                                 efree_size(ref, sizeof(zend_reference));
      96           3 :                                         } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
      97             :                                                 Z_ADDREF_P(variable_ptr);
      98             :                                         }
      99             :                                 }
     100     8830338 :                                 zval_dtor_func(garbage);
     101     8830337 :                                 return variable_ptr;
     102             :                         } else { /* we need to split */
     103             :                                 /* optimized version of GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) */
     104     7707353 :                                 if ((Z_COLLECTABLE_P(variable_ptr)) &&
     105      386879 :                                 UNEXPECTED(!GC_INFO(garbage))) {
     106       45289 :                                         gc_possible_root(garbage);
     107             :                                 }
     108             :                         }
     109             :                 }
     110             :         } while (0);
     111             : 
     112    26296094 :         ZVAL_COPY_VALUE(variable_ptr, value);
     113    26296094 :         if (value_type & (IS_CONST|IS_CV)) {
     114     9082088 :                 if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) {
     115             :                         Z_ADDREF_P(variable_ptr);
     116             :                 }
     117    17214006 :         } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) {
     118          13 :                 if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) {
     119           1 :                         efree_size(ref, sizeof(zend_reference));
     120          12 :                 } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) {
     121             :                         Z_ADDREF_P(variable_ptr);
     122             :                 }
     123             :         }
     124    26296094 :         return variable_ptr;
     125             : }
     126             : 
     127             : ZEND_API int zval_update_constant(zval *pp);
     128             : ZEND_API int zval_update_constant_ex(zval *pp, zend_class_entry *scope);
     129             : 
     130             : /* dedicated Zend executor functions - do not use! */
     131             : struct _zend_vm_stack {
     132             :         zval *top;
     133             :         zval *end;
     134             :         zend_vm_stack prev;
     135             : };
     136             : 
     137             : #define ZEND_VM_STACK_HEADER_SLOTS \
     138             :         ((ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
     139             : 
     140             : #define ZEND_VM_STACK_ELEMENTS(stack) \
     141             :         (((zval*)(stack)) + ZEND_VM_STACK_HEADER_SLOTS)
     142             : 
     143             : /*
     144             :  * In general in RELEASE build ZEND_ASSERT() must be zero-cost, but for some
     145             :  * reason, GCC generated worse code, performing CSE on assertion code and the
     146             :  * following "slow path" and moving memory read operatins from slow path into
     147             :  * common header. This made a degradation for the fast path.
     148             :  * The following "#if ZEND_DEBUG" eliminates it.
     149             :  */
     150             : #if ZEND_DEBUG
     151             : # define ZEND_ASSERT_VM_STACK(stack) ZEND_ASSERT(stack->top > (zval *) stack && stack->end > (zval *) stack && stack->top <= stack->end)
     152             : # 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))
     153             : #else
     154             : # define ZEND_ASSERT_VM_STACK(stack)
     155             : # define ZEND_ASSERT_VM_STACK_GLOBAL
     156             : #endif
     157             : 
     158             : ZEND_API void zend_vm_stack_init(void);
     159             : ZEND_API void zend_vm_stack_destroy(void);
     160             : ZEND_API void* zend_vm_stack_extend(size_t size);
     161             : 
     162             : static zend_always_inline void zend_vm_init_call_frame(zend_execute_data *call, uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object)
     163             : {
     164    34343303 :         call->func = func;
     165    34343303 :         if (object) {
     166     4188628 :                 Z_OBJ(call->This) = object;
     167     4188628 :                 ZEND_SET_CALL_INFO(call, 1, call_info);
     168             :         } else {
     169    30154675 :                 Z_CE(call->This) = called_scope;
     170    30154675 :                 ZEND_SET_CALL_INFO(call, 0, call_info);
     171             :         }
     172    34343303 :         ZEND_CALL_NUM_ARGS(call) = num_args;
     173             : }
     174             : 
     175             : 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)
     176             : {
     177    34343303 :         zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
     178             : 
     179             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     180             : 
     181    34343303 :         if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
     182          10 :                 call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
     183             :                 ZEND_ASSERT_VM_STACK_GLOBAL;
     184          10 :                 zend_vm_init_call_frame(call, call_info | ZEND_CALL_ALLOCATED, func, num_args, called_scope, object);
     185          10 :                 return call;
     186             :         } else {
     187    34343293 :                 EG(vm_stack_top) = (zval*)((char*)call + used_stack);
     188             :                 zend_vm_init_call_frame(call, call_info, func, num_args, called_scope, object);
     189    34343293 :                 return call;
     190             :         }
     191             : }
     192             : 
     193             : static zend_always_inline uint32_t zend_vm_calc_used_stack(uint32_t num_args, zend_function *func)
     194             : {
     195     5128452 :         uint32_t used_stack = ZEND_CALL_FRAME_SLOT + num_args;
     196             : 
     197     5128452 :         if (EXPECTED(ZEND_USER_CODE(func->type))) {
     198     1183679 :                 used_stack += func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args);
     199             :         }
     200     5128452 :         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     4855038 :         uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
     206             : 
     207     4855038 :         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       51320 :         if (UNEXPECTED(call_info & ZEND_CALL_FREE_EXTRA_ARGS)) {
     214         433 :                 zval *end = ZEND_CALL_VAR_NUM(call, call->func->op_array.last_var + call->func->op_array.T);
     215         433 :                 zval *p = end + (ZEND_CALL_NUM_ARGS(call) - call->func->op_array.num_args);
     216             :                 do {
     217        1223 :                         p--;
     218        1223 :                         if (Z_REFCOUNTED_P(p)) {
     219         818 :                                 if (!Z_DELREF_P(p)) {
     220           2 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     221           2 :                                         ZVAL_NULL(p);
     222           2 :                                         zval_dtor_func(r);
     223             :                                 } else {
     224             :                                         GC_ZVAL_CHECK_POSSIBLE_ROOT(p);
     225             :                                 }
     226             :                         }
     227        1223 :                 } while (p != end);
     228             :         }
     229             : }
     230             : 
     231             : static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *call)
     232             : {
     233       50449 :         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    29359514 :         uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
     239             : 
     240    29359514 :         if (EXPECTED(num_args > 0)) {
     241    28480892 :                 zval *end = ZEND_CALL_ARG(call, 1);
     242    28480892 :                 zval *p = end + num_args;
     243             : 
     244             :                 do {
     245    51154025 :                         p--;
     246    51154025 :                         if (Z_REFCOUNTED_P(p)) {
     247    24214702 :                                 if (!Z_DELREF_P(p)) {
     248     1691945 :                                         zend_refcounted *r = Z_COUNTED_P(p);
     249     1691945 :                                         ZVAL_NULL(p);
     250     1691945 :                                         zval_dtor_func(r);
     251             :                                 }
     252             :                         }
     253    51154025 :                 } 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    29965930 :         if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
     262          17 :                 zend_vm_stack p = EG(vm_stack);
     263          17 :                 zend_vm_stack prev = p->prev;
     264             : 
     265             :                 ZEND_ASSERT(call == (zend_execute_data*)ZEND_VM_STACK_ELEMENTS(EG(vm_stack)));
     266          17 :                 EG(vm_stack_top) = prev->top;
     267          17 :                 EG(vm_stack_end) = prev->end;
     268          17 :                 EG(vm_stack) = prev;
     269          17 :                 efree(p);
     270             :         } else {
     271    29965913 :                 EG(vm_stack_top) = (zval*)call;
     272             :         }
     273             : 
     274             :         ZEND_ASSERT_VM_STACK_GLOBAL;
     275             : }
     276             : 
     277             : static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call)
     278             : {
     279    29954722 :         zend_vm_stack_free_call_frame_ex(ZEND_CALL_INFO(call), call);
     280             : }
     281             : 
     282             : /* services */
     283             : ZEND_API const char *get_active_class_name(const char **space);
     284             : ZEND_API const char *get_active_function_name(void);
     285             : ZEND_API const char *zend_get_executed_filename(void);
     286             : ZEND_API zend_string *zend_get_executed_filename_ex(void);
     287             : ZEND_API uint zend_get_executed_lineno(void);
     288             : ZEND_API zend_class_entry *zend_get_executed_scope(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 ZEND_NORETURN 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             : ZEND_API void zend_fetch_dimension_by_zval_is(zval *result, zval *container, zval *dim, int dim_type);
     300             : 
     301             : ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, uint32_t var);
     302             : 
     303             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     304             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     305             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     306             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     307             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     308             : 
     309             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     310             : 
     311             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     312             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     313             : 
     314             : /* former zend_execute_locks.h */
     315             : typedef zval* zend_free_op;
     316             : 
     317             : 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);
     318             : 
     319             : ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table);
     320             : void zend_free_compiled_variables(zend_execute_data *execute_data);
     321             : void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num);
     322             : 
     323             : #define CACHE_ADDR(num) \
     324             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))
     325             : 
     326             : #define CACHED_PTR(num) \
     327             :         ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0]
     328             : 
     329             : #define CACHE_PTR(num, ptr) do { \
     330             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] = (ptr); \
     331             :         } while (0)
     332             : 
     333             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     334             :         (EXPECTED(((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[0] == (void*)(ce)) ? \
     335             :                 ((void**)((char*)EX_RUN_TIME_CACHE() + (num)))[1] : \
     336             :                 NULL)
     337             : 
     338             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     339             :                 void **slot = (void**)((char*)EX_RUN_TIME_CACHE() + (num)); \
     340             :                 slot[0] = (ce); \
     341             :                 slot[1] = (ptr); \
     342             :         } while (0)
     343             : 
     344             : #define CACHED_PTR_EX(slot) \
     345             :         (slot)[0]
     346             : 
     347             : #define CACHE_PTR_EX(slot, ptr) do { \
     348             :                 (slot)[0] = (ptr); \
     349             :         } while (0)
     350             : 
     351             : #define CACHED_POLYMORPHIC_PTR_EX(slot, ce) \
     352             :         (EXPECTED((slot)[0] == (ce)) ? (slot)[1] : NULL)
     353             : 
     354             : #define CACHE_POLYMORPHIC_PTR_EX(slot, ce, ptr) do { \
     355             :                 (slot)[0] = (ce); \
     356             :                 (slot)[1] = (ptr); \
     357             :         } while (0)
     358             : 
     359             : #define SKIP_EXT_OPLINE(opline) do { \
     360             :                 while (UNEXPECTED((opline)->opcode >= ZEND_EXT_STMT \
     361             :                         && (opline)->opcode <= ZEND_TICKS)) {     \
     362             :                         (opline)--;                                  \
     363             :                 }                                                \
     364             :         } while (0)
     365             : 
     366             : END_EXTERN_C()
     367             : 
     368             : #endif /* ZEND_EXECUTE_H */
     369             : 
     370             : /*
     371             :  * Local variables:
     372             :  * tab-width: 4
     373             :  * c-basic-offset: 4
     374             :  * indent-tabs-mode: t
     375             :  * End:
     376             :  */

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:17 +0000 (2 days ago)

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