File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / Zend / zend_execute.h
Revision 1.1.1.4 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Sun Jun 15 20:04:03 2014 UTC (10 years, 4 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_29, HEAD
php 5.4.29

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>