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: 63 83 75.9 %
Date: 2014-04-16 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 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             : typedef union _temp_variable {
      31             :         zval tmp_var;
      32             :         struct {
      33             :                 zval **ptr_ptr;
      34             :                 zval *ptr;
      35             :                 zend_bool fcall_returned_reference;
      36             :         } var;
      37             :         struct {
      38             :                 zval **ptr_ptr; /* shared with var.ptr_ptr */
      39             :                 zval *str;
      40             :                 zend_uint offset;
      41             :         } str_offset;
      42             :         struct {
      43             :                 zval **ptr_ptr; /* shared with var.ptr_ptr */
      44             :                 zval *ptr;      /* shared with var.ptr */
      45             :                 HashPointer fe_pos;
      46             :         } fe;
      47             :         zend_class_entry *class_entry;
      48             : } temp_variable;
      49             : 
      50             : 
      51             : BEGIN_EXTERN_C()
      52             : struct _zend_fcall_info;
      53             : ZEND_API extern void (*zend_execute_ex)(zend_execute_data *execute_data TSRMLS_DC);
      54             : ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
      55             : 
      56             : void init_executor(TSRMLS_D);
      57             : void shutdown_executor(TSRMLS_D);
      58             : void shutdown_destructors(TSRMLS_D);
      59             : ZEND_API zend_execute_data *zend_create_execute_data_from_op_array(zend_op_array *op_array, zend_bool nested TSRMLS_DC);
      60             : ZEND_API void zend_execute(zend_op_array *op_array TSRMLS_DC);
      61             : ZEND_API void execute_ex(zend_execute_data *execute_data TSRMLS_DC);
      62             : ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
      63             : ZEND_API int zend_is_true(zval *op TSRMLS_DC);
      64             : ZEND_API int zend_lookup_class(const char *name, int name_length, zend_class_entry ***ce TSRMLS_DC);
      65             : ZEND_API int zend_lookup_class_ex(const char *name, int name_length, const zend_literal *key, int use_autoload, zend_class_entry ***ce TSRMLS_DC);
      66             : ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC);
      67             : ZEND_API int zend_eval_stringl(char *str, int str_len, zval *retval_ptr, char *string_name TSRMLS_DC);
      68             : ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
      69             : ZEND_API int zend_eval_stringl_ex(char *str, int str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
      70             : 
      71             : ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, ulong fetch_type, const char **class_name, zend_class_entry **pce TSRMLS_DC);
      72             : ZEND_API int zend_verify_arg_error(int error_type, const zend_function *zf, zend_uint arg_num, const char *need_msg, const char *need_kind, const char *given_msg, const char *given_kind TSRMLS_DC);
      73             : 
      74             : static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC TSRMLS_DC)
      75             : {
      76    49779316 :         if (!Z_DELREF_P(zval_ptr)) {
      77             :                 ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
      78    17383032 :                 GC_REMOVE_ZVAL_FROM_BUFFER(zval_ptr);
      79             :                 zval_dtor(zval_ptr);
      80    17383032 :                 efree_rel(zval_ptr);
      81             :         } else {
      82    32396284 :                 if (Z_REFCOUNT_P(zval_ptr) == 1) {
      83             :                         Z_UNSET_ISREF_P(zval_ptr);
      84             :                 }
      85             : 
      86             :                 GC_ZVAL_CHECK_POSSIBLE_ROOT(zval_ptr);
      87             :         }
      88             : }
      89             : 
      90             : static zend_always_inline void i_zval_ptr_dtor_nogc(zval *zval_ptr ZEND_FILE_LINE_DC TSRMLS_DC)
      91             : {
      92    23511121 :         if (!Z_DELREF_P(zval_ptr)) {
      93             :                 ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
      94    10094993 :                 GC_REMOVE_ZVAL_FROM_BUFFER(zval_ptr);
      95             :                 zval_dtor(zval_ptr);
      96    10094993 :                 efree_rel(zval_ptr);
      97             :         } else {
      98    13416128 :                 if (Z_REFCOUNT_P(zval_ptr) == 1) {
      99             :                         Z_UNSET_ISREF_P(zval_ptr);
     100             :                 }
     101             :         }
     102             : }
     103             : 
     104             : static zend_always_inline int i_zend_is_true(zval *op TSRMLS_DC)
     105             : {
     106             :         int result;
     107             : 
     108     8705602 :         switch (Z_TYPE_P(op)) {
     109             :                 case IS_NULL:
     110       42710 :                         result = 0;
     111             :                         break;
     112             :                 case IS_LONG:
     113             :                 case IS_BOOL:
     114             :                 case IS_RESOURCE:
     115     8369076 :                         result = (Z_LVAL_P(op)?1:0);
     116             :                         break;
     117             :                 case IS_DOUBLE:
     118          12 :                         result = (Z_DVAL_P(op) ? 1 : 0);
     119             :                         break;
     120             :                 case IS_STRING:
     121       98435 :                         if (Z_STRLEN_P(op) == 0
     122       98435 :                                 || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
     123        6742 :                                 result = 0;
     124             :                         } else {
     125       45616 :                                 result = 1;
     126             :                         }
     127             :                         break;
     128             :                 case IS_ARRAY:
     129      153740 :                         result = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
     130             :                         break;
     131             :                 case IS_OBJECT:
     132       87706 :                         if(IS_ZEND_STD_OBJECT(*op)) {
     133       87706 :                                 if (Z_OBJ_HT_P(op)->cast_object) {
     134             :                                         zval tmp;
     135       87706 :                                         if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_BOOL TSRMLS_CC) == SUCCESS) {
     136       87706 :                                                 result = Z_LVAL(tmp);
     137             :                                                 break;
     138             :                                         }
     139           0 :                                 } else if (Z_OBJ_HT_P(op)->get) {
     140           0 :                                         zval *tmp = Z_OBJ_HT_P(op)->get(op TSRMLS_CC);
     141           0 :                                         if(Z_TYPE_P(tmp) != IS_OBJECT) {
     142             :                                                 /* for safety - avoid loop */
     143           0 :                                                 convert_to_boolean(tmp);
     144           0 :                                                 result = Z_LVAL_P(tmp);
     145           0 :                                                 zval_ptr_dtor(&tmp);
     146             :                                                 break;
     147             :                                         }
     148             :                                 }
     149             :                         }
     150           0 :                         result = 1;
     151             :                         break;
     152             :                 default:
     153           0 :                         result = 0;
     154             :                         break;
     155             :         }
     156     8705602 :         return result;
     157             : }
     158             : 
     159             : ZEND_API int zval_update_constant(zval **pp, zend_bool inline_change TSRMLS_DC);
     160             : ZEND_API int zval_update_constant_inline_change(zval **pp, zend_class_entry *scope TSRMLS_DC);
     161             : ZEND_API int zval_update_constant_no_inline_change(zval **pp, zend_class_entry *scope TSRMLS_DC);
     162             : ZEND_API int zval_update_constant_ex(zval **pp, zend_bool inline_change, zend_class_entry *scope TSRMLS_DC);
     163             : 
     164             : /* dedicated Zend executor functions - do not use! */
     165             : #define ZEND_VM_STACK_PAGE_SIZE ((16 * 1024) - 16)
     166             : 
     167             : struct _zend_vm_stack {
     168             :         void **top;
     169             :         void **end;
     170             :         zend_vm_stack prev;
     171             : };
     172             : 
     173             : #define ZEND_VM_STACK_ELEMETS(stack) \
     174             :         ((void**)(((char*)(stack)) + ZEND_MM_ALIGNED_SIZE(sizeof(struct _zend_vm_stack))))
     175             : 
     176             : #define ZEND_VM_STACK_GROW_IF_NEEDED(count)                                                     \
     177             :         do {                                                                                                                    \
     178             :                 if (UNEXPECTED((count) >                                                                     \
     179             :                     EG(argument_stack)->end - EG(argument_stack)->top)) { \
     180             :                         zend_vm_stack_extend((count) TSRMLS_CC);                                \
     181             :                 }                                                                                                                       \
     182             :         } while (0)
     183             : 
     184             : static zend_always_inline zend_vm_stack zend_vm_stack_new_page(int count) {
     185         108 :         zend_vm_stack page = (zend_vm_stack)emalloc(ZEND_MM_ALIGNED_SIZE(sizeof(*page)) + sizeof(void*) * count);
     186             : 
     187         108 :         page->top = ZEND_VM_STACK_ELEMETS(page);
     188         108 :         page->end = page->top + count;
     189         108 :         page->prev = NULL;
     190         108 :         return page;
     191             : }
     192             : 
     193             : static zend_always_inline void zend_vm_stack_init(TSRMLS_D)
     194             : {
     195           0 :         EG(argument_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE);
     196             : }
     197             : 
     198             : static zend_always_inline void zend_vm_stack_destroy(TSRMLS_D)
     199             : {
     200           0 :         zend_vm_stack stack = EG(argument_stack);
     201             : 
     202           0 :         while (stack != NULL) {
     203           0 :                 zend_vm_stack p = stack->prev;
     204           0 :                 efree(stack);
     205           0 :                 stack = p;
     206             :         }
     207             : }
     208             : 
     209             : static zend_always_inline void zend_vm_stack_extend(int count TSRMLS_DC)
     210             : {
     211          54 :         zend_vm_stack p = zend_vm_stack_new_page(count >= ZEND_VM_STACK_PAGE_SIZE ? count : ZEND_VM_STACK_PAGE_SIZE);
     212          27 :         p->prev = EG(argument_stack);
     213          27 :         EG(argument_stack) = p;
     214             : }
     215             : 
     216             : static zend_always_inline void **zend_vm_stack_top(TSRMLS_D)
     217             : {
     218    73194423 :         return EG(argument_stack)->top;
     219             : }
     220             : 
     221             : static zend_always_inline void zend_vm_stack_push(void *ptr TSRMLS_DC)
     222             : {
     223    59675266 :         *(EG(argument_stack)->top++) = ptr;
     224             : }
     225             : 
     226             : static zend_always_inline void *zend_vm_stack_pop(TSRMLS_D)
     227             : {
     228          70 :         void *el = *(--EG(argument_stack)->top);
     229             : 
     230          70 :         return el;
     231             : }
     232             : 
     233             : static zend_always_inline void *zend_vm_stack_alloc(size_t size TSRMLS_DC)
     234             : {
     235             :         void *ret;
     236             : 
     237     2112421 :         size = (size + (sizeof(void*) - 1)) / sizeof(void*);
     238             : 
     239             :         /* the following comparison must be optimized out at compile time */
     240             :         if (ZEND_MM_ALIGNMENT > sizeof(void*)) {
     241             :                 int extra = (ZEND_MM_ALIGNMENT - ((zend_uintptr_t)EG(argument_stack)->top & (ZEND_MM_ALIGNMENT - 1))) / sizeof(void*);
     242             : 
     243             :                 if (UNEXPECTED(size + extra + ZEND_MM_ALIGNED_SIZE(sizeof(void*)) / sizeof(void*) >
     244             :                     (zend_uintptr_t)(EG(argument_stack)->end - EG(argument_stack)->top))) {
     245             :                         zend_vm_stack_extend(size TSRMLS_CC);
     246             :                 } else {
     247             :                         void **old_top = EG(argument_stack)->top;
     248             : 
     249             :                         EG(argument_stack)->top += extra;
     250             :                         /* store old top on the stack */
     251             :                         *EG(argument_stack)->top = (void*)old_top;
     252             :                         EG(argument_stack)->top += ZEND_MM_ALIGNED_SIZE(sizeof(void*)) / sizeof(void*);
     253             :                 }
     254             :         } else {
     255     2112421 :                 ZEND_VM_STACK_GROW_IF_NEEDED((int)size);
     256             :         }
     257     2112421 :         ret = (void*)EG(argument_stack)->top;
     258     2112421 :         EG(argument_stack)->top += size;
     259     2112421 :         return ret;
     260             : }
     261             : 
     262             : static zend_always_inline void** zend_vm_stack_frame_base(zend_execute_data *ex)
     263             : {
     264     6342390 :         return (void**)((char*)ex->call_slots +
     265     4228260 :                 ZEND_MM_ALIGNED_SIZE(sizeof(call_slot)) * ex->op_array->nested_calls);
     266             : }
     267             : 
     268             : static zend_always_inline void zend_vm_stack_free_int(void *ptr TSRMLS_DC)
     269             : {
     270           0 :         if (UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (void**)ptr)) {
     271           0 :                 zend_vm_stack p = EG(argument_stack);
     272             : 
     273           0 :                 EG(argument_stack) = p->prev;
     274           0 :                 efree(p);
     275             :         } else {
     276           0 :                 EG(argument_stack)->top = (void**)ptr;
     277             :         }
     278             : }
     279             : 
     280             : static zend_always_inline void zend_vm_stack_free(void *ptr TSRMLS_DC)
     281             : {
     282     2110685 :         if (UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (void**)ptr)) {
     283          23 :                 zend_vm_stack p = EG(argument_stack);
     284             : 
     285          23 :                 EG(argument_stack) = p->prev;
     286          23 :                 efree(p);
     287             :         } else {
     288             :                 /* the following comparison must be optimized out at compile time */
     289             :                 if (ZEND_MM_ALIGNMENT > sizeof(void*)) {
     290             :                         ptr = (void*)(((char*)ptr) - ZEND_MM_ALIGNED_SIZE(sizeof(void*)));
     291             :                         EG(argument_stack)->top = *(void***)ptr;
     292             :                 } else {
     293     2110662 :                         EG(argument_stack)->top = (void**)ptr;
     294             :                 }
     295             :         }
     296             : }
     297             : 
     298             : static zend_always_inline void zend_vm_stack_clear_multiple(int nested TSRMLS_DC)
     299             : {
     300    21201678 :         void **p = EG(argument_stack)->top - 1;
     301    21201678 :         void **end = p - (int)(zend_uintptr_t)*p;
     302             : 
     303    59674449 :         while (p != end) {
     304    38472771 :                 zval *q = (zval *) *(--p);
     305    38472771 :                 *p = NULL;
     306             :                 i_zval_ptr_dtor(q ZEND_FILE_LINE_CC TSRMLS_CC);
     307             :         }
     308    21201678 :         if (nested) {
     309    21201678 :                 EG(argument_stack)->top = p;
     310             :         } else {
     311             :                 zend_vm_stack_free_int(p TSRMLS_CC);
     312             :         }
     313             : }
     314             : 
     315             : static zend_always_inline int zend_vm_stack_get_args_count_ex(zend_execute_data *ex)
     316             : {
     317         124 :         if (ex) {
     318         124 :                 void **p = ex->function_state.arguments;
     319         124 :                 return (int)(zend_uintptr_t) *p;
     320             :         } else {
     321           0 :                 return 0;                       
     322             :         }
     323             : }
     324             : 
     325             : static zend_always_inline zval** zend_vm_stack_get_arg_ex(zend_execute_data *ex, int requested_arg)
     326             : {
     327     5318789 :         void **p = ex->function_state.arguments;
     328     5318789 :         int arg_count = (int)(zend_uintptr_t) *p;
     329             : 
     330     5318789 :         if (UNEXPECTED(requested_arg > arg_count)) {
     331      101410 :                 return NULL;
     332             :         }
     333     5217379 :         return (zval**)p - arg_count + requested_arg - 1;
     334             : }
     335             : 
     336             : static zend_always_inline int zend_vm_stack_get_args_count(TSRMLS_D)
     337             : {
     338          86 :         return zend_vm_stack_get_args_count_ex(EG(current_execute_data)->prev_execute_data);
     339             : }
     340             : 
     341             : static zend_always_inline zval** zend_vm_stack_get_arg(int requested_arg TSRMLS_DC)
     342             : {
     343    10637478 :         return zend_vm_stack_get_arg_ex(EG(current_execute_data)->prev_execute_data, requested_arg);
     344             : }
     345             : 
     346             : void execute_new_code(TSRMLS_D);
     347             : 
     348             : 
     349             : /* services */
     350             : ZEND_API const char *get_active_class_name(const char **space TSRMLS_DC);
     351             : ZEND_API const char *get_active_function_name(TSRMLS_D);
     352             : ZEND_API const char *zend_get_executed_filename(TSRMLS_D);
     353             : ZEND_API uint zend_get_executed_lineno(TSRMLS_D);
     354             : ZEND_API zend_bool zend_is_executing(TSRMLS_D);
     355             : 
     356             : ZEND_API void zend_set_timeout(long seconds, int reset_signals);
     357             : ZEND_API void zend_unset_timeout(TSRMLS_D);
     358             : ZEND_API void zend_timeout(int dummy);
     359             : ZEND_API zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len, int fetch_type TSRMLS_DC);
     360             : ZEND_API zend_class_entry *zend_fetch_class_by_name(const char *class_name, uint class_name_len, const zend_literal *key, int fetch_type TSRMLS_DC);
     361             : void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC);
     362             : 
     363             : ZEND_API void zend_fetch_dimension_by_zval(zval **result, zval *container, zval *dim TSRMLS_DC);
     364             : 
     365             : #ifdef ZEND_WIN32
     366             : void zend_init_timeout_thread(void);
     367             : void zend_shutdown_timeout_thread(void);
     368             : #define WM_REGISTER_ZEND_TIMEOUT                (WM_USER+1)
     369             : #define WM_UNREGISTER_ZEND_TIMEOUT              (WM_USER+2)
     370             : #endif
     371             : 
     372             : #define zendi_zval_copy_ctor(p) zval_copy_ctor(&(p))
     373             : #define zendi_zval_dtor(p) zval_dtor(&(p))
     374             : 
     375             : #define active_opline (*EG(opline_ptr))
     376             : 
     377             : /* The following tries to resolve the classname of a zval of type object.
     378             :  * Since it is slow it should be only used in error messages.
     379             :  */
     380             : #define Z_OBJ_CLASS_NAME_P(zval) ((zval) && Z_TYPE_P(zval) == IS_OBJECT && Z_OBJ_HT_P(zval)->get_class_entry != NULL && Z_OBJ_HT_P(zval)->get_class_entry(zval TSRMLS_CC) ? Z_OBJ_HT_P(zval)->get_class_entry(zval TSRMLS_CC)->name : "")
     381             : 
     382             : ZEND_API zval** zend_get_compiled_variable_value(const zend_execute_data *execute_data_ptr, zend_uint var);
     383             : 
     384             : #define ZEND_USER_OPCODE_CONTINUE   0 /* execute next opcode */
     385             : #define ZEND_USER_OPCODE_RETURN     1 /* exit from executor (return from function) */
     386             : #define ZEND_USER_OPCODE_DISPATCH   2 /* call original opcode handler */
     387             : #define ZEND_USER_OPCODE_ENTER      3 /* enter into new op_array without recursion */
     388             : #define ZEND_USER_OPCODE_LEAVE      4 /* return to calling op_array within the same executor */
     389             : 
     390             : #define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
     391             : 
     392             : ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
     393             : ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
     394             : 
     395             : /* former zend_execute_locks.h */
     396             : typedef struct _zend_free_op {
     397             :         zval* var;
     398             : /*      int   is_var; */
     399             : } zend_free_op;
     400             : 
     401             : 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 TSRMLS_DC);
     402             : ZEND_API zval **zend_get_zval_ptr_ptr(int op_type, const znode_op *node, const zend_execute_data *execute_data, zend_free_op *should_free, int type TSRMLS_DC);
     403             : 
     404             : ZEND_API int zend_do_fcall(ZEND_OPCODE_HANDLER_ARGS);
     405             : 
     406             : void zend_clean_and_cache_symbol_table(HashTable *symbol_table TSRMLS_DC);
     407             : void zend_free_compiled_variables(zend_execute_data *execute_data TSRMLS_DC);
     408             : 
     409             : #define CACHED_PTR(num) \
     410             :         EG(active_op_array)->run_time_cache[(num)]
     411             : 
     412             : #define CACHE_PTR(num, ptr) do { \
     413             :                 EG(active_op_array)->run_time_cache[(num)] = (ptr); \
     414             :         } while (0)
     415             : 
     416             : #define CACHED_POLYMORPHIC_PTR(num, ce) \
     417             :         ((EG(active_op_array)->run_time_cache[(num)] == (ce)) ? \
     418             :                 EG(active_op_array)->run_time_cache[(num) + 1] : \
     419             :                 NULL)
     420             : 
     421             : #define CACHE_POLYMORPHIC_PTR(num, ce, ptr) do { \
     422             :                 EG(active_op_array)->run_time_cache[(num)] = (ce); \
     423             :                 EG(active_op_array)->run_time_cache[(num) + 1] = (ptr); \
     424             :         } while (0)
     425             : 
     426             : END_EXTERN_C()
     427             : 
     428             : #endif /* ZEND_EXECUTE_H */
     429             : 
     430             : /*
     431             :  * Local variables:
     432             :  * tab-width: 4
     433             :  * c-basic-offset: 4
     434             :  * indent-tabs-mode: t
     435             :  * End:
     436             :  */

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:44 +0000 (2 days ago)

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