1 : /*
2 : +----------------------------------------------------------------------+
3 : | Zend Engine |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1998-2009 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.c 289987 2009-10-27 13:02:36Z dsp $ */
21 :
22 : #include "zend.h"
23 : #include "zend_extensions.h"
24 : #include "zend_modules.h"
25 : #include "zend_constants.h"
26 : #include "zend_list.h"
27 : #include "zend_API.h"
28 : #include "zend_exceptions.h"
29 : #include "zend_builtin_functions.h"
30 : #include "zend_ini.h"
31 : #include "zend_vm.h"
32 :
33 : #ifdef ZTS
34 : # define GLOBAL_FUNCTION_TABLE global_function_table
35 : # define GLOBAL_CLASS_TABLE global_class_table
36 : # define GLOBAL_CONSTANTS_TABLE global_constants_table
37 : # define GLOBAL_AUTO_GLOBALS_TABLE global_auto_globals_table
38 : #else
39 : # define GLOBAL_FUNCTION_TABLE CG(function_table)
40 : # define GLOBAL_CLASS_TABLE CG(class_table)
41 : # define GLOBAL_AUTO_GLOBALS_TABLE CG(auto_globals)
42 : # define GLOBAL_CONSTANTS_TABLE EG(zend_constants)
43 : #endif
44 :
45 : #if defined(ZEND_WIN32) && ZEND_DEBUG
46 : BOOL WINAPI IsDebuggerPresent(VOID);
47 : #endif
48 :
49 : /* true multithread-shared globals */
50 : ZEND_API zend_class_entry *zend_standard_class_def = NULL;
51 : ZEND_API int (*zend_printf)(const char *format, ...);
52 : ZEND_API zend_write_func_t zend_write;
53 : ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
54 : ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
55 : ZEND_API void (*zend_block_interruptions)(void);
56 : ZEND_API void (*zend_unblock_interruptions)(void);
57 : ZEND_API void (*zend_ticks_function)(int ticks);
58 : ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
59 : int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
60 : ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
61 : ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
62 :
63 : void (*zend_on_timeout)(int seconds TSRMLS_DC);
64 :
65 : static void (*zend_message_dispatcher_p)(long message, void *data TSRMLS_DC);
66 : static int (*zend_get_configuration_directive_p)(const char *name, uint name_length, zval *contents);
67 :
68 : static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
69 2027140 : {
70 2027140 : if (!new_value) {
71 124 : EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
72 : } else {
73 2027016 : EG(error_reporting) = atoi(new_value);
74 : }
75 2027140 : return SUCCESS;
76 : }
77 : /* }}} */
78 :
79 : static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
80 17644 : {
81 17644 : OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
82 :
83 17644 : if (GC_G(gc_enabled)) {
84 17638 : gc_init(TSRMLS_C);
85 : }
86 :
87 17644 : return SUCCESS;
88 : }
89 : /* }}} */
90 :
91 : ZEND_INI_BEGIN()
92 : ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting)
93 : STD_ZEND_INI_BOOLEAN("zend.enable_gc", "1", ZEND_INI_ALL, OnUpdateGCEnabled, gc_enabled, zend_gc_globals, gc_globals)
94 : #ifdef ZEND_MULTIBYTE
95 : STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
96 : #endif
97 : ZEND_INI_END()
98 :
99 :
100 : #ifdef ZTS
101 : ZEND_API int compiler_globals_id;
102 : ZEND_API int executor_globals_id;
103 : static HashTable *global_function_table = NULL;
104 : static HashTable *global_class_table = NULL;
105 : static HashTable *global_constants_table = NULL;
106 : static HashTable *global_auto_globals_table = NULL;
107 : static HashTable *global_persistent_list = NULL;
108 : #endif
109 :
110 : ZEND_API zend_utility_values zend_uv;
111 :
112 : ZEND_API zval zval_used_for_init; /* True global variable */
113 :
114 : /* version information */
115 : static char *zend_version_info;
116 : static uint zend_version_info_length;
117 : #define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2009 Zend Technologies\n"
118 : #define PRINT_ZVAL_INDENT 4
119 :
120 : static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
121 938 : {
122 : zval **tmp;
123 : char *string_key;
124 : HashPosition iterator;
125 : ulong num_key;
126 : uint str_len;
127 : int i;
128 :
129 3674 : for (i = 0; i < indent; i++) {
130 2736 : ZEND_PUTS_EX(" ");
131 : }
132 938 : ZEND_PUTS_EX("(\n");
133 938 : indent += PRINT_ZVAL_INDENT;
134 938 : zend_hash_internal_pointer_reset_ex(ht, &iterator);
135 5158 : while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
136 26714 : for (i = 0; i < indent; i++) {
137 23432 : ZEND_PUTS_EX(" ");
138 : }
139 3282 : ZEND_PUTS_EX("[");
140 3282 : switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
141 : case HASH_KEY_IS_STRING:
142 1632 : if (is_object) {
143 : char *prop_name, *class_name;
144 507 : int mangled = zend_unmangle_property_name(string_key, str_len - 1, &class_name, &prop_name);
145 :
146 507 : ZEND_PUTS_EX(prop_name);
147 507 : if (class_name && mangled == SUCCESS) {
148 194 : if (class_name[0]=='*') {
149 87 : ZEND_PUTS_EX(":protected");
150 : } else {
151 107 : ZEND_PUTS_EX(":");
152 107 : ZEND_PUTS_EX(class_name);
153 107 : ZEND_PUTS_EX(":private");
154 : }
155 : }
156 : } else {
157 1125 : ZEND_WRITE_EX(string_key, str_len-1);
158 : }
159 1632 : break;
160 : case HASH_KEY_IS_LONG:
161 : {
162 : char key[25];
163 1650 : snprintf(key, sizeof(key), "%ld", num_key);
164 1650 : ZEND_PUTS_EX(key);
165 : }
166 : break;
167 : }
168 3282 : ZEND_PUTS_EX("] => ");
169 3282 : zend_print_zval_r_ex(write_func, *tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
170 3282 : ZEND_PUTS_EX("\n");
171 3282 : zend_hash_move_forward_ex(ht, &iterator);
172 : }
173 938 : indent -= PRINT_ZVAL_INDENT;
174 3674 : for (i = 0; i < indent; i++) {
175 2736 : ZEND_PUTS_EX(" ");
176 : }
177 938 : ZEND_PUTS_EX(")\n");
178 938 : }
179 : /* }}} */
180 :
181 : static void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
182 36 : {
183 : zval **tmp;
184 : char *string_key;
185 : HashPosition iterator;
186 : ulong num_key;
187 : uint str_len;
188 36 : int i = 0;
189 :
190 36 : zend_hash_internal_pointer_reset_ex(ht, &iterator);
191 511 : while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
192 439 : if (i++ > 0) {
193 422 : ZEND_PUTS(",");
194 : }
195 439 : ZEND_PUTS("[");
196 439 : switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
197 : case HASH_KEY_IS_STRING:
198 433 : ZEND_PUTS(string_key);
199 433 : break;
200 : case HASH_KEY_IS_LONG:
201 6 : zend_printf("%ld", num_key);
202 : break;
203 : }
204 439 : ZEND_PUTS("] => ");
205 439 : zend_print_flat_zval_r(*tmp TSRMLS_CC);
206 439 : zend_hash_move_forward_ex(ht, &iterator);
207 : }
208 36 : }
209 : /* }}} */
210 :
211 : ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
212 4741466 : {
213 4741466 : if (Z_TYPE_P(expr)==IS_STRING) {
214 3185409 : *use_copy = 0;
215 3185409 : return;
216 : }
217 1556057 : switch (Z_TYPE_P(expr)) {
218 : case IS_NULL:
219 1648 : Z_STRLEN_P(expr_copy) = 0;
220 1648 : Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
221 1648 : break;
222 : case IS_BOOL:
223 20628 : if (Z_LVAL_P(expr)) {
224 1353 : Z_STRLEN_P(expr_copy) = 1;
225 1353 : Z_STRVAL_P(expr_copy) = estrndup("1", 1);
226 : } else {
227 19275 : Z_STRLEN_P(expr_copy) = 0;
228 19275 : Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
229 : }
230 20628 : break;
231 : case IS_RESOURCE:
232 5077 : Z_STRVAL_P(expr_copy) = (char *) emalloc(sizeof("Resource id #") - 1 + MAX_LENGTH_OF_LONG);
233 5077 : Z_STRLEN_P(expr_copy) = sprintf(Z_STRVAL_P(expr_copy), "Resource id #%ld", Z_LVAL_P(expr));
234 5077 : break;
235 : case IS_ARRAY:
236 946 : Z_STRLEN_P(expr_copy) = sizeof("Array") - 1;
237 946 : Z_STRVAL_P(expr_copy) = estrndup("Array", Z_STRLEN_P(expr_copy));
238 946 : break;
239 : case IS_OBJECT:
240 : {
241 : TSRMLS_FETCH();
242 :
243 104895 : if (Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
244 104841 : break;
245 : }
246 : /* Standard PHP objects */
247 53 : if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HANDLER_P(expr, cast_object)) {
248 51 : if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
249 0 : break;
250 : }
251 : }
252 53 : if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
253 0 : zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC);
254 :
255 0 : Z_ADDREF_P(z);
256 0 : if (Z_TYPE_P(z) != IS_OBJECT) {
257 0 : zend_make_printable_zval(z, expr_copy, use_copy);
258 0 : if (*use_copy) {
259 0 : zval_ptr_dtor(&z);
260 : } else {
261 0 : ZVAL_ZVAL(expr_copy, z, 0, 1);
262 0 : *use_copy = 1;
263 : }
264 0 : return;
265 : }
266 0 : zval_ptr_dtor(&z);
267 : }
268 53 : zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name);
269 43 : Z_STRLEN_P(expr_copy) = 0;
270 43 : Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
271 : }
272 43 : break;
273 : case IS_DOUBLE:
274 19026 : *expr_copy = *expr;
275 19026 : zval_copy_ctor(expr_copy);
276 19026 : zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
277 19026 : break;
278 : default:
279 1403837 : *expr_copy = *expr;
280 1403837 : zval_copy_ctor(expr_copy);
281 1403837 : convert_to_string(expr_copy);
282 : break;
283 : }
284 1556046 : Z_TYPE_P(expr_copy) = IS_STRING;
285 1556046 : *use_copy = 1;
286 : }
287 : /* }}} */
288 :
289 : ZEND_API int zend_print_zval(zval *expr, int indent) /* {{{ */
290 207868 : {
291 207868 : return zend_print_zval_ex(zend_write, expr, indent);
292 : }
293 : /* }}} */
294 :
295 : ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
296 211138 : {
297 : zval expr_copy;
298 : int use_copy;
299 :
300 211138 : zend_make_printable_zval(expr, &expr_copy, &use_copy);
301 211138 : if (use_copy) {
302 3510 : expr = &expr_copy;
303 : }
304 211138 : if (Z_STRLEN_P(expr) == 0) { /* optimize away empty strings */
305 736 : if (use_copy) {
306 550 : zval_dtor(expr);
307 : }
308 736 : return 0;
309 : }
310 210402 : write_func(Z_STRVAL_P(expr), Z_STRLEN_P(expr));
311 210400 : if (use_copy) {
312 2960 : zval_dtor(expr);
313 : }
314 210400 : return Z_STRLEN_P(expr);
315 : }
316 : /* }}} */
317 :
318 : ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
319 459 : {
320 459 : switch (Z_TYPE_P(expr)) {
321 : case IS_ARRAY:
322 37 : ZEND_PUTS("Array (");
323 37 : if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
324 2 : ZEND_PUTS(" *RECURSION*");
325 2 : Z_ARRVAL_P(expr)->nApplyCount--;
326 2 : return;
327 : }
328 35 : print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
329 35 : ZEND_PUTS(")");
330 35 : Z_ARRVAL_P(expr)->nApplyCount--;
331 35 : break;
332 : case IS_OBJECT:
333 : {
334 1 : HashTable *properties = NULL;
335 1 : char *class_name = NULL;
336 : zend_uint clen;
337 :
338 1 : if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
339 1 : Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
340 : }
341 1 : if (class_name) {
342 1 : zend_printf("%s Object (", class_name);
343 : } else {
344 0 : zend_printf("%s Object (", "Unknown Class");
345 : }
346 1 : if (class_name) {
347 1 : efree(class_name);
348 : }
349 1 : if (Z_OBJ_HANDLER_P(expr, get_properties)) {
350 1 : properties = Z_OBJPROP_P(expr);
351 : }
352 1 : if (properties) {
353 1 : if (++properties->nApplyCount>1) {
354 0 : ZEND_PUTS(" *RECURSION*");
355 0 : properties->nApplyCount--;
356 0 : return;
357 : }
358 1 : print_flat_hash(properties TSRMLS_CC);
359 1 : properties->nApplyCount--;
360 : }
361 1 : ZEND_PUTS(")");
362 1 : break;
363 : }
364 : default:
365 421 : zend_print_variable(expr);
366 : break;
367 : }
368 : }
369 : /* }}} */
370 :
371 : ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
372 932 : {
373 932 : zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
374 932 : }
375 : /* }}} */
376 :
377 : ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
378 4215 : {
379 4215 : switch (Z_TYPE_P(expr)) {
380 : case IS_ARRAY:
381 740 : ZEND_PUTS_EX("Array\n");
382 740 : if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
383 0 : ZEND_PUTS_EX(" *RECURSION*");
384 0 : Z_ARRVAL_P(expr)->nApplyCount--;
385 0 : return;
386 : }
387 740 : print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
388 740 : Z_ARRVAL_P(expr)->nApplyCount--;
389 740 : break;
390 : case IS_OBJECT:
391 : {
392 : HashTable *properties;
393 205 : char *class_name = NULL;
394 : zend_uint clen;
395 : int is_temp;
396 :
397 205 : if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
398 205 : Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
399 : }
400 205 : if (class_name) {
401 205 : ZEND_PUTS_EX(class_name);
402 : } else {
403 0 : ZEND_PUTS_EX("Unknown Class");
404 : }
405 205 : ZEND_PUTS_EX(" Object\n");
406 205 : if (class_name) {
407 205 : efree(class_name);
408 : }
409 205 : if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
410 0 : break;
411 : }
412 205 : if (++properties->nApplyCount>1) {
413 7 : ZEND_PUTS_EX(" *RECURSION*");
414 7 : properties->nApplyCount--;
415 7 : return;
416 : }
417 198 : print_hash(write_func, properties, indent, 1 TSRMLS_CC);
418 198 : properties->nApplyCount--;
419 198 : if (is_temp) {
420 10 : zend_hash_destroy(properties);
421 10 : efree(properties);
422 : }
423 198 : break;
424 : }
425 : default:
426 3270 : zend_print_zval_ex(write_func, expr, indent);
427 : break;
428 : }
429 : }
430 : /* }}} */
431 :
432 : static FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
433 0 : {
434 0 : if (opened_path) {
435 0 : *opened_path = estrdup(filename);
436 : }
437 0 : return fopen(filename, "rb");
438 : }
439 : /* }}} */
440 :
441 : #ifdef ZTS
442 : static zend_bool asp_tags_default = 0;
443 : static zend_bool short_tags_default = 1;
444 : static zend_bool ct_pass_ref_default = 1;
445 : static zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT;
446 : #else
447 : # define asp_tags_default 0
448 : # define short_tags_default 1
449 : # define ct_pass_ref_default 1
450 : # define compiler_options_default ZEND_COMPILE_DEFAULT
451 : #endif
452 :
453 : static void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
454 17633 : {
455 : /* default compile-time values */
456 17633 : CG(asp_tags) = asp_tags_default;
457 17633 : CG(short_tags) = short_tags_default;
458 17633 : CG(allow_call_time_pass_reference) = ct_pass_ref_default;
459 17633 : CG(compiler_options) = compiler_options_default;
460 17633 : }
461 : /* }}} */
462 :
463 : static void zend_init_exception_op(TSRMLS_D) /* {{{ */
464 17633 : {
465 17633 : memset(EG(exception_op), 0, sizeof(EG(exception_op)));
466 17633 : EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
467 17633 : EG(exception_op)[0].op1.op_type = IS_UNUSED;
468 17633 : EG(exception_op)[0].op2.op_type = IS_UNUSED;
469 17633 : EG(exception_op)[0].result.op_type = IS_UNUSED;
470 17633 : ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
471 17633 : EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
472 17633 : EG(exception_op)[1].op1.op_type = IS_UNUSED;
473 17633 : EG(exception_op)[1].op2.op_type = IS_UNUSED;
474 17633 : EG(exception_op)[1].result.op_type = IS_UNUSED;
475 17633 : ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
476 17633 : EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
477 17633 : EG(exception_op)[2].op1.op_type = IS_UNUSED;
478 17633 : EG(exception_op)[2].op2.op_type = IS_UNUSED;
479 17633 : EG(exception_op)[2].result.op_type = IS_UNUSED;
480 17633 : ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
481 17633 : }
482 : /* }}} */
483 :
484 : #ifdef ZTS
485 : static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
486 : {
487 : zend_function tmp_func;
488 : zend_class_entry *tmp_class;
489 :
490 : compiler_globals->compiled_filename = NULL;
491 :
492 : compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
493 : zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
494 : zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function));
495 :
496 : compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
497 : zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
498 : zend_hash_copy(compiler_globals->class_table, global_class_table, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry *));
499 :
500 : zend_set_default_compile_time_values(TSRMLS_C);
501 :
502 : CG(interactive) = 0;
503 :
504 : compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
505 : zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
506 : zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(zend_auto_global) /* empty element */);
507 :
508 : compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
509 : if (compiler_globals->last_static_member) {
510 : compiler_globals->static_members = (HashTable**)calloc(compiler_globals->last_static_member, sizeof(HashTable*));
511 : } else {
512 : compiler_globals->static_members = NULL;
513 : }
514 : }
515 : /* }}} */
516 :
517 : static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
518 : {
519 : if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
520 : zend_hash_destroy(compiler_globals->function_table);
521 : free(compiler_globals->function_table);
522 : }
523 : if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
524 : zend_hash_destroy(compiler_globals->class_table);
525 : free(compiler_globals->class_table);
526 : }
527 : if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
528 : zend_hash_destroy(compiler_globals->auto_globals);
529 : free(compiler_globals->auto_globals);
530 : }
531 : if (compiler_globals->static_members) {
532 : free(compiler_globals->static_members);
533 : }
534 : compiler_globals->last_static_member = 0;
535 : }
536 : /* }}} */
537 :
538 : static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
539 : {
540 : zend_startup_constants(TSRMLS_C);
541 : zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
542 : zend_init_rsrc_plist(TSRMLS_C);
543 : zend_init_exception_op(TSRMLS_C);
544 : EG(lambda_count) = 0;
545 : EG(user_error_handler) = NULL;
546 : EG(user_exception_handler) = NULL;
547 : EG(in_execution) = 0;
548 : EG(in_autoload) = NULL;
549 : EG(current_execute_data) = NULL;
550 : EG(current_module) = NULL;
551 : EG(exit_status) = 0;
552 : EG(saved_fpu_cw) = NULL;
553 : EG(active) = 0;
554 : }
555 : /* }}} */
556 :
557 : static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
558 : {
559 : zend_ini_shutdown(TSRMLS_C);
560 : if (&executor_globals->persistent_list != global_persistent_list) {
561 : zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
562 : }
563 : if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
564 : zend_hash_destroy(executor_globals->zend_constants);
565 : free(executor_globals->zend_constants);
566 : }
567 : }
568 : /* }}} */
569 :
570 : static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
571 : {
572 : if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
573 : zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
574 : }
575 : }
576 : /* }}} */
577 : #endif
578 :
579 : #if defined(__FreeBSD__) || defined(__DragonFly__)
580 : /* FreeBSD and DragonFly floating point precision fix */
581 : #include <floatingpoint.h>
582 : #endif
583 :
584 : static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
585 17633 : {
586 17633 : memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
587 17633 : }
588 : /* }}} */
589 :
590 : static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
591 17633 : {
592 17633 : memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
593 17633 : }
594 : /* }}} */
595 :
596 : void zend_init_opcodes_handlers(void);
597 :
598 : int zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
599 17633 : {
600 : #ifdef ZTS
601 : zend_compiler_globals *compiler_globals;
602 : zend_executor_globals *executor_globals;
603 : extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
604 : extern ZEND_API ts_rsrc_id language_scanner_globals_id;
605 : #else
606 : extern zend_ini_scanner_globals ini_scanner_globals;
607 : extern zend_php_scanner_globals language_scanner_globals;
608 : #endif
609 :
610 17633 : start_memory_manager(TSRMLS_C);
611 :
612 : #if defined(__FreeBSD__) || defined(__DragonFly__)
613 : /* FreeBSD and DragonFly floating point precision fix */
614 : fpsetmask(0);
615 : #endif
616 :
617 17633 : zend_startup_strtod();
618 17633 : zend_startup_extensions_mechanism();
619 :
620 : /* Set up utility functions and values */
621 17633 : zend_error_cb = utility_functions->error_function;
622 17633 : zend_printf = utility_functions->printf_function;
623 17633 : zend_write = (zend_write_func_t) utility_functions->write_function;
624 17633 : zend_fopen = utility_functions->fopen_function;
625 17633 : if (!zend_fopen) {
626 0 : zend_fopen = zend_fopen_wrapper;
627 : }
628 17633 : zend_stream_open_function = utility_functions->stream_open_function;
629 17633 : zend_message_dispatcher_p = utility_functions->message_handler;
630 17633 : zend_block_interruptions = utility_functions->block_interruptions;
631 17633 : zend_unblock_interruptions = utility_functions->unblock_interruptions;
632 17633 : zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
633 17633 : zend_ticks_function = utility_functions->ticks_function;
634 17633 : zend_on_timeout = utility_functions->on_timeout;
635 17633 : zend_vspprintf = utility_functions->vspprintf_function;
636 17633 : zend_getenv = utility_functions->getenv_function;
637 17633 : zend_resolve_path = utility_functions->resolve_path_function;
638 :
639 17633 : zend_compile_file = compile_file;
640 17633 : zend_compile_string = compile_string;
641 17633 : zend_execute = execute;
642 17633 : zend_execute_internal = NULL;
643 17633 : zend_throw_exception_hook = NULL;
644 :
645 17633 : zend_init_opcodes_handlers();
646 :
647 : /* set up version */
648 17633 : zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
649 17633 : zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
650 :
651 17633 : GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
652 17633 : GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
653 17633 : GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
654 17633 : GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
655 :
656 17633 : zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
657 17633 : zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
658 17633 : zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, (dtor_func_t) zend_auto_global_dtor, 1, 0);
659 17633 : zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
660 :
661 17633 : zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
662 17633 : zend_init_rsrc_list_dtors();
663 :
664 : /* This zval can be used to initialize allocate zval's to an uninit'ed value */
665 17633 : Z_UNSET_ISREF(zval_used_for_init);
666 17633 : Z_SET_REFCOUNT(zval_used_for_init, 1);
667 17633 : Z_TYPE(zval_used_for_init) = IS_NULL;
668 :
669 : #ifdef ZTS
670 : ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
671 : ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
672 : ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
673 : ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
674 : compiler_globals = ts_resource(compiler_globals_id);
675 : executor_globals = ts_resource(executor_globals_id);
676 :
677 : compiler_globals_dtor(compiler_globals TSRMLS_CC);
678 : compiler_globals->in_compilation = 0;
679 : compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
680 : compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
681 :
682 : *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
683 : *compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
684 : compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
685 :
686 : zend_hash_destroy(executor_globals->zend_constants);
687 : *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
688 : #else
689 17633 : ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
690 17633 : php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
691 17633 : zend_set_default_compile_time_values(TSRMLS_C);
692 17633 : EG(user_error_handler) = NULL;
693 17633 : EG(user_exception_handler) = NULL;
694 : #endif
695 :
696 17633 : zend_startup_builtin_functions(TSRMLS_C);
697 17633 : zend_register_standard_constants(TSRMLS_C);
698 17633 : zend_register_auto_global("GLOBALS", sizeof("GLOBALS") - 1, NULL TSRMLS_CC);
699 :
700 : #ifndef ZTS
701 17633 : zend_init_rsrc_plist(TSRMLS_C);
702 17633 : zend_init_exception_op(TSRMLS_C);
703 : #endif
704 :
705 17633 : zend_ini_startup(TSRMLS_C);
706 :
707 : #ifdef ZTS
708 : tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
709 : #endif
710 :
711 17633 : return SUCCESS;
712 : }
713 : /* }}} */
714 :
715 : void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
716 17633 : {
717 17633 : int module_number = 0;
718 :
719 17633 : REGISTER_INI_ENTRIES();
720 17633 : }
721 : /* }}} */
722 :
723 : /* Unlink the global (r/o) copies of the class, function and constant tables,
724 : * and use a fresh r/w copy for the startup thread
725 : */
726 : void zend_post_startup(TSRMLS_D) /* {{{ */
727 0 : {
728 : #ifdef ZTS
729 : zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
730 : zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
731 :
732 : *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
733 : *GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
734 : *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
735 :
736 : asp_tags_default = CG(asp_tags);
737 : short_tags_default = CG(short_tags);
738 : ct_pass_ref_default = CG(allow_call_time_pass_reference);
739 : compiler_options_default = CG(compiler_options);
740 :
741 : zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
742 : free(compiler_globals->function_table);
743 : free(compiler_globals->class_table);
744 : compiler_globals_ctor(compiler_globals, tsrm_ls);
745 : free(EG(zend_constants));
746 : executor_globals_ctor(executor_globals, tsrm_ls);
747 : global_persistent_list = &EG(persistent_list);
748 : zend_copy_ini_directives(TSRMLS_C);
749 : #endif
750 0 : }
751 : /* }}} */
752 :
753 : void zend_shutdown(TSRMLS_D) /* {{{ */
754 17665 : {
755 : #ifdef ZEND_WIN32
756 : zend_shutdown_timeout_thread();
757 : #endif
758 17665 : zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
759 17665 : zend_hash_graceful_reverse_destroy(&module_registry);
760 :
761 17665 : zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
762 17665 : zend_hash_destroy(GLOBAL_CLASS_TABLE);
763 :
764 17665 : zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
765 17665 : free(GLOBAL_AUTO_GLOBALS_TABLE);
766 :
767 17665 : zend_shutdown_extensions(TSRMLS_C);
768 17665 : free(zend_version_info);
769 :
770 17665 : free(GLOBAL_FUNCTION_TABLE);
771 17665 : free(GLOBAL_CLASS_TABLE);
772 :
773 17665 : zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
774 17665 : free(GLOBAL_CONSTANTS_TABLE);
775 17665 : zend_shutdown_strtod();
776 :
777 : #ifdef ZTS
778 : GLOBAL_FUNCTION_TABLE = NULL;
779 : GLOBAL_CLASS_TABLE = NULL;
780 : GLOBAL_AUTO_GLOBALS_TABLE = NULL;
781 : GLOBAL_CONSTANTS_TABLE = NULL;
782 : #endif
783 17665 : zend_destroy_rsrc_list_dtors();
784 17665 : }
785 : /* }}} */
786 :
787 : void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
788 17633 : {
789 17633 : zend_uv = *utility_values;
790 17633 : zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
791 17633 : }
792 : /* }}} */
793 :
794 : /* this should be compatible with the standard zenderror */
795 : void zenderror(const char *error) /* {{{ */
796 31 : {
797 31 : zend_error(E_PARSE, "%s", error);
798 31 : }
799 : /* }}} */
800 :
801 : BEGIN_EXTERN_C()
802 : ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
803 1545 : {
804 : TSRMLS_FETCH();
805 :
806 1545 : if (!EG(bailout)) {
807 0 : zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
808 0 : exit(-1);
809 : }
810 1545 : CG(unclean_shutdown) = 1;
811 1545 : CG(in_compilation) = EG(in_execution) = 0;
812 1545 : EG(current_execute_data) = NULL;
813 1545 : LONGJMP(*EG(bailout), FAILURE);
814 : }
815 : /* }}} */
816 : END_EXTERN_C()
817 :
818 : void zend_append_version_info(const zend_extension *extension) /* {{{ */
819 0 : {
820 : char *new_info;
821 : uint new_info_length;
822 :
823 0 : new_info_length = sizeof(" with v, by \n")
824 : + strlen(extension->name)
825 : + strlen(extension->version)
826 : + strlen(extension->copyright)
827 : + strlen(extension->author);
828 :
829 0 : new_info = (char *) malloc(new_info_length + 1);
830 :
831 0 : sprintf(new_info, " with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
832 :
833 0 : zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
834 0 : strcat(zend_version_info, new_info);
835 0 : zend_version_info_length += new_info_length;
836 0 : free(new_info);
837 0 : }
838 : /* }}} */
839 :
840 : ZEND_API char *get_zend_version(void) /* {{{ */
841 52 : {
842 52 : return zend_version_info;
843 : }
844 : /* }}} */
845 :
846 : void zend_activate(TSRMLS_D) /* {{{ */
847 17619 : {
848 17619 : gc_reset(TSRMLS_C);
849 17619 : init_compiler(TSRMLS_C);
850 17619 : init_executor(TSRMLS_C);
851 17619 : startup_scanner(TSRMLS_C);
852 17619 : }
853 : /* }}} */
854 :
855 : void zend_activate_modules(TSRMLS_D) /* {{{ */
856 17619 : {
857 17619 : zend_hash_apply(&module_registry, (apply_func_t) module_registry_request_startup TSRMLS_CC);
858 17619 : }
859 : /* }}} */
860 :
861 : void zend_deactivate_modules(TSRMLS_D) /* {{{ */
862 17651 : {
863 17651 : EG(opline_ptr) = NULL; /* we're no longer executing anything */
864 :
865 17651 : zend_try {
866 17651 : zend_hash_reverse_apply(&module_registry, (apply_func_t) module_registry_cleanup TSRMLS_CC);
867 17651 : } zend_end_try();
868 17651 : }
869 : /* }}} */
870 :
871 : void zend_call_destructors(TSRMLS_D) /* {{{ */
872 17651 : {
873 17651 : zend_try {
874 17651 : shutdown_destructors(TSRMLS_C);
875 17651 : } zend_end_try();
876 17651 : }
877 : /* }}} */
878 :
879 : void zend_deactivate(TSRMLS_D) /* {{{ */
880 17651 : {
881 : /* we're no longer executing anything */
882 17651 : EG(opline_ptr) = NULL;
883 17651 : EG(active_symbol_table) = NULL;
884 :
885 17651 : zend_try {
886 17651 : shutdown_scanner(TSRMLS_C);
887 17651 : } zend_end_try();
888 :
889 : /* shutdown_executor() takes care of its own bailout handling */
890 17651 : shutdown_executor(TSRMLS_C);
891 :
892 17651 : zend_try {
893 17651 : shutdown_compiler(TSRMLS_C);
894 17651 : } zend_end_try();
895 :
896 17651 : zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
897 :
898 : #ifdef ZEND_DEBUG
899 17651 : if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
900 16297 : gc_collect_cycles(TSRMLS_C);
901 : }
902 : #endif
903 :
904 : #if GC_BENCH
905 : fprintf(stderr, "GC Statistics\n");
906 : fprintf(stderr, "-------------\n");
907 : fprintf(stderr, "Runs: %d\n", GC_G(gc_runs));
908 : fprintf(stderr, "Collected: %d\n", GC_G(collected));
909 : fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
910 : fprintf(stderr, "Root buffer peak: %d\n\n", GC_G(root_buf_peak));
911 : fprintf(stderr, " Possible Remove from Marked\n");
912 : fprintf(stderr, " Root Buffered buffer grey\n");
913 : fprintf(stderr, " -------- -------- ----------- ------\n");
914 : fprintf(stderr, "ZVAL %8d %8d %9d %8d\n", GC_G(zval_possible_root), GC_G(zval_buffered), GC_G(zval_remove_from_buffer), GC_G(zval_marked_grey));
915 : fprintf(stderr, "ZOBJ %8d %8d %9d %8d\n", GC_G(zobj_possible_root), GC_G(zobj_buffered), GC_G(zobj_remove_from_buffer), GC_G(zobj_marked_grey));
916 : #endif
917 :
918 17651 : zend_try {
919 17651 : zend_ini_deactivate(TSRMLS_C);
920 17651 : } zend_end_try();
921 17651 : }
922 : /* }}} */
923 :
924 : static int exec_done_cb(zend_module_entry *module TSRMLS_DC) /* {{{ */
925 1218234 : {
926 1218234 : if (module->post_deactivate_func) {
927 0 : module->post_deactivate_func();
928 : }
929 1218234 : return 0;
930 : }
931 : /* }}} */
932 :
933 : void zend_post_deactivate_modules(TSRMLS_D) /* {{{ */
934 17651 : {
935 17651 : zend_hash_apply(&module_registry, (apply_func_t) exec_done_cb TSRMLS_CC);
936 17651 : zend_hash_reverse_apply(&module_registry, (apply_func_t) module_registry_unload_temp TSRMLS_CC);
937 17651 : }
938 : /* }}} */
939 :
940 : BEGIN_EXTERN_C()
941 : ZEND_API void zend_message_dispatcher(long message, void *data TSRMLS_DC) /* {{{ */
942 31 : {
943 31 : if (zend_message_dispatcher_p) {
944 31 : zend_message_dispatcher_p(message, data TSRMLS_CC);
945 : }
946 28 : }
947 : /* }}} */
948 : END_EXTERN_C()
949 :
950 : ZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */
951 3969995 : {
952 3969995 : if (zend_get_configuration_directive_p) {
953 3969995 : return zend_get_configuration_directive_p(name, name_length, contents);
954 : } else {
955 0 : return FAILURE;
956 : }
957 : }
958 : /* }}} */
959 :
960 : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
961 2407887 : {
962 : va_list args;
963 : va_list usr_copy;
964 : zval ***params;
965 : zval *retval;
966 : zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context;
967 : char *error_filename;
968 : uint error_lineno;
969 : zval *orig_user_error_handler;
970 : zend_bool in_compilation;
971 : zend_class_entry *saved_class_entry;
972 : TSRMLS_FETCH();
973 :
974 : /* Obtain relevant filename and lineno */
975 2407887 : switch (type) {
976 : case E_CORE_ERROR:
977 : case E_CORE_WARNING:
978 1 : error_filename = NULL;
979 1 : error_lineno = 0;
980 1 : break;
981 : case E_PARSE:
982 : case E_COMPILE_ERROR:
983 : case E_COMPILE_WARNING:
984 : case E_ERROR:
985 : case E_NOTICE:
986 : case E_STRICT:
987 : case E_DEPRECATED:
988 : case E_WARNING:
989 : case E_USER_ERROR:
990 : case E_USER_WARNING:
991 : case E_USER_NOTICE:
992 : case E_USER_DEPRECATED:
993 : case E_RECOVERABLE_ERROR:
994 2407886 : if (zend_is_compiling(TSRMLS_C)) {
995 227 : error_filename = zend_get_compiled_filename(TSRMLS_C);
996 227 : error_lineno = zend_get_compiled_lineno(TSRMLS_C);
997 2407659 : } else if (zend_is_executing(TSRMLS_C)) {
998 2407569 : error_filename = zend_get_executed_filename(TSRMLS_C);
999 2407569 : error_lineno = zend_get_executed_lineno(TSRMLS_C);
1000 : } else {
1001 90 : error_filename = NULL;
1002 90 : error_lineno = 0;
1003 : }
1004 2407886 : break;
1005 : default:
1006 0 : error_filename = NULL;
1007 0 : error_lineno = 0;
1008 : break;
1009 : }
1010 2407887 : if (!error_filename) {
1011 91 : error_filename = "Unknown";
1012 : }
1013 :
1014 2407887 : va_start(args, format);
1015 :
1016 : /* if we don't have a user defined error handler */
1017 4812572 : if (!EG(user_error_handler)
1018 : || !(EG(user_error_handler_error_reporting) & type)
1019 : || EG(error_handling) != EH_NORMAL) {
1020 2405147 : zend_error_cb(type, error_filename, error_lineno, format, args);
1021 2740 : } else switch (type) {
1022 : case E_ERROR:
1023 : case E_PARSE:
1024 : case E_CORE_ERROR:
1025 : case E_CORE_WARNING:
1026 : case E_COMPILE_ERROR:
1027 : case E_COMPILE_WARNING:
1028 : /* The error may not be safe to handle in user-space */
1029 1 : zend_error_cb(type, error_filename, error_lineno, format, args);
1030 0 : break;
1031 : default:
1032 : /* Handle the error in user space */
1033 2739 : ALLOC_INIT_ZVAL(z_error_message);
1034 2739 : ALLOC_INIT_ZVAL(z_error_type);
1035 2739 : ALLOC_INIT_ZVAL(z_error_filename);
1036 2739 : ALLOC_INIT_ZVAL(z_error_lineno);
1037 2739 : ALLOC_INIT_ZVAL(z_context);
1038 :
1039 : /* va_copy() is __va_copy() in old gcc versions.
1040 : * According to the autoconf manual, using
1041 : * memcpy(&dst, &src, sizeof(va_list))
1042 : * gives maximum portability. */
1043 : #ifndef va_copy
1044 : # ifdef __va_copy
1045 : # define va_copy(dest, src) __va_copy((dest), (src))
1046 : # else
1047 : # define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
1048 : # endif
1049 : #endif
1050 2739 : va_copy(usr_copy, args);
1051 2739 : Z_STRLEN_P(z_error_message) = zend_vspprintf(&Z_STRVAL_P(z_error_message), 0, format, usr_copy);
1052 : #ifdef va_copy
1053 2739 : va_end(usr_copy);
1054 : #endif
1055 2739 : Z_TYPE_P(z_error_message) = IS_STRING;
1056 :
1057 2739 : Z_LVAL_P(z_error_type) = type;
1058 2739 : Z_TYPE_P(z_error_type) = IS_LONG;
1059 :
1060 2739 : if (error_filename) {
1061 2739 : ZVAL_STRING(z_error_filename, error_filename, 1);
1062 : }
1063 :
1064 2739 : Z_LVAL_P(z_error_lineno) = error_lineno;
1065 2739 : Z_TYPE_P(z_error_lineno) = IS_LONG;
1066 :
1067 2739 : if (!EG(active_symbol_table)) {
1068 21 : zend_rebuild_symbol_table(TSRMLS_C);
1069 : }
1070 :
1071 : /* during shutdown the symbol table table can be still null */
1072 2739 : if (!EG(active_symbol_table)) {
1073 0 : Z_TYPE_P(z_context) = IS_NULL;
1074 : } else {
1075 2739 : Z_ARRVAL_P(z_context) = EG(active_symbol_table);
1076 2739 : Z_TYPE_P(z_context) = IS_ARRAY;
1077 2739 : zval_copy_ctor(z_context);
1078 : }
1079 :
1080 2739 : params = (zval ***) emalloc(sizeof(zval **)*5);
1081 2739 : params[0] = &z_error_type;
1082 2739 : params[1] = &z_error_message;
1083 2739 : params[2] = &z_error_filename;
1084 2739 : params[3] = &z_error_lineno;
1085 2739 : params[4] = &z_context;
1086 :
1087 2739 : orig_user_error_handler = EG(user_error_handler);
1088 2739 : EG(user_error_handler) = NULL;
1089 :
1090 : /* User error handler may include() additinal PHP files.
1091 : * If an error was generated during comilation PHP will compile
1092 : * such scripts recursivly, but some CG() variables may be
1093 : * inconsistent. */
1094 :
1095 2739 : in_compilation = zend_is_compiling(TSRMLS_C);
1096 2739 : if (in_compilation) {
1097 1 : saved_class_entry = CG(active_class_entry);
1098 1 : CG(active_class_entry) = NULL;
1099 : }
1100 :
1101 2739 : if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC) == SUCCESS) {
1102 2738 : if (retval) {
1103 2723 : if (Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval) == 0) {
1104 1 : zend_error_cb(type, error_filename, error_lineno, format, args);
1105 : }
1106 2723 : zval_ptr_dtor(&retval);
1107 : }
1108 0 : } else if (!EG(exception)) {
1109 : /* The user error handler failed, use built-in error handler */
1110 0 : zend_error_cb(type, error_filename, error_lineno, format, args);
1111 : }
1112 :
1113 2738 : if (in_compilation) {
1114 0 : CG(active_class_entry) = saved_class_entry;
1115 : }
1116 :
1117 2738 : if (!EG(user_error_handler)) {
1118 2738 : EG(user_error_handler) = orig_user_error_handler;
1119 : }
1120 : else {
1121 0 : zval_ptr_dtor(&orig_user_error_handler);
1122 : }
1123 :
1124 2738 : efree(params);
1125 2738 : zval_ptr_dtor(&z_error_message);
1126 2738 : zval_ptr_dtor(&z_error_type);
1127 2738 : zval_ptr_dtor(&z_error_filename);
1128 2738 : zval_ptr_dtor(&z_error_lineno);
1129 2738 : zval_ptr_dtor(&z_context);
1130 : break;
1131 : }
1132 :
1133 2407423 : va_end(args);
1134 :
1135 2407423 : if (type == E_PARSE) {
1136 31 : EG(exit_status) = 255;
1137 31 : zend_init_compiler_data_structures(TSRMLS_C);
1138 : }
1139 2407423 : }
1140 : /* }}} */
1141 :
1142 : #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)
1143 : void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
1144 : #endif
1145 :
1146 : ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */
1147 0 : {
1148 : #if ZEND_DEBUG
1149 : va_list args;
1150 :
1151 : va_start(args, format);
1152 : # ifdef ZEND_WIN32
1153 : {
1154 : char output_buf[1024];
1155 :
1156 : vsnprintf(output_buf, 1024, format, args);
1157 : OutputDebugString(output_buf);
1158 : OutputDebugString("\n");
1159 : if (trigger_break && IsDebuggerPresent()) {
1160 : DebugBreak();
1161 : }
1162 : }
1163 : # else
1164 : vfprintf(stderr, format, args);
1165 : fprintf(stderr, "\n");
1166 : # endif
1167 : va_end(args);
1168 : #endif
1169 0 : }
1170 : /* }}} */
1171 :
1172 : ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...) /* {{{ */
1173 17539 : {
1174 : va_list files;
1175 : int i;
1176 : zend_file_handle *file_handle;
1177 17539 : zend_op_array *orig_op_array = EG(active_op_array);
1178 17539 : zval **orig_retval_ptr_ptr = EG(return_value_ptr_ptr);
1179 :
1180 17539 : va_start(files, file_count);
1181 67532 : for (i = 0; i < file_count; i++) {
1182 51305 : file_handle = va_arg(files, zend_file_handle *);
1183 51305 : if (!file_handle) {
1184 33765 : continue;
1185 : }
1186 17540 : EG(active_op_array) = zend_compile_file(file_handle, type TSRMLS_CC);
1187 17385 : if (file_handle->opened_path) {
1188 17385 : int dummy = 1;
1189 17385 : zend_hash_add(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path) + 1, (void *)&dummy, sizeof(int), NULL);
1190 : }
1191 17385 : zend_destroy_file_handle(file_handle TSRMLS_CC);
1192 17385 : if (EG(active_op_array)) {
1193 17385 : EG(return_value_ptr_ptr) = retval ? retval : NULL;
1194 17385 : zend_execute(EG(active_op_array) TSRMLS_CC);
1195 16295 : zend_exception_restore(TSRMLS_C);
1196 16295 : if (EG(exception)) {
1197 75 : if (EG(user_exception_handler)) {
1198 : zval *orig_user_exception_handler;
1199 : zval **params[1], *retval2, *old_exception;
1200 9 : old_exception = EG(exception);
1201 9 : EG(exception) = NULL;
1202 9 : params[0] = &old_exception;
1203 9 : orig_user_exception_handler = EG(user_exception_handler);
1204 9 : if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
1205 8 : if (retval2 != NULL) {
1206 8 : zval_ptr_dtor(&retval2);
1207 : }
1208 8 : if (EG(exception)) {
1209 0 : zval_ptr_dtor(&EG(exception));
1210 0 : EG(exception) = NULL;
1211 : }
1212 8 : zval_ptr_dtor(&old_exception);
1213 : } else {
1214 0 : EG(exception) = old_exception;
1215 0 : zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
1216 : }
1217 : } else {
1218 66 : zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
1219 : }
1220 : }
1221 16228 : destroy_op_array(EG(active_op_array) TSRMLS_CC);
1222 16228 : efree(EG(active_op_array));
1223 0 : } else if (type==ZEND_REQUIRE) {
1224 0 : va_end(files);
1225 0 : EG(active_op_array) = orig_op_array;
1226 0 : EG(return_value_ptr_ptr) = orig_retval_ptr_ptr;
1227 0 : return FAILURE;
1228 : }
1229 : }
1230 16227 : va_end(files);
1231 16227 : EG(active_op_array) = orig_op_array;
1232 16227 : EG(return_value_ptr_ptr) = orig_retval_ptr_ptr;
1233 :
1234 16227 : return SUCCESS;
1235 : }
1236 : /* }}} */
1237 :
1238 : #define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
1239 :
1240 : ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC) /* {{{ */
1241 964 : {
1242 : char *cur_filename;
1243 : int cur_lineno;
1244 : char *compiled_string_description;
1245 :
1246 964 : if (zend_is_compiling(TSRMLS_C)) {
1247 0 : cur_filename = zend_get_compiled_filename(TSRMLS_C);
1248 0 : cur_lineno = zend_get_compiled_lineno(TSRMLS_C);
1249 964 : } else if (zend_is_executing(TSRMLS_C)) {
1250 964 : cur_filename = zend_get_executed_filename(TSRMLS_C);
1251 964 : cur_lineno = zend_get_executed_lineno(TSRMLS_C);
1252 : } else {
1253 0 : cur_filename = "Unknown";
1254 0 : cur_lineno = 0;
1255 : }
1256 :
1257 964 : zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
1258 964 : return compiled_string_description;
1259 : }
1260 : /* }}} */
1261 :
1262 : void free_estring(char **str_p) /* {{{ */
1263 25562 : {
1264 25562 : efree(*str_p);
1265 25562 : }
1266 : /* }}} */
1267 :
1268 : /*
1269 : * Local variables:
1270 : * tab-width: 4
1271 : * c-basic-offset: 4
1272 : * indent-tabs-mode: t
1273 : * End:
1274 : */
|