| 1 | |
|---|
| 2 | #include "xcache.h" |
|---|
| 3 | #include "stack.h" |
|---|
| 4 | #include "xcache_globals.h" |
|---|
| 5 | #include "utils.h" |
|---|
| 6 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 7 | #include "zend_vm.h" |
|---|
| 8 | #endif |
|---|
| 9 | #include "opcode_spec.h" |
|---|
| 10 | #undef NDEBUG |
|---|
| 11 | #include "assert.h" |
|---|
| 12 | |
|---|
| 13 | #ifndef max |
|---|
| 14 | #define max(a, b) ((a) < (b) ? (b) : (a)) |
|---|
| 15 | #endif |
|---|
| 16 | |
|---|
| 17 | #ifndef ZEND_VM_SET_OPCODE_HANDLER |
|---|
| 18 | # define ZEND_VM_SET_OPCODE_HANDLER(opline) do { } while (0) |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | #define OP_ZVAL_DTOR(op) do { \ |
|---|
| 22 | Z_UNSET_ISREF((op).u.constant); \ |
|---|
| 23 | zval_dtor(&(op).u.constant); \ |
|---|
| 24 | } while(0) |
|---|
| 25 | xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, /* {{{ */ |
|---|
| 26 | zend_op_array *op_array, |
|---|
| 27 | HashTable *function_table, |
|---|
| 28 | HashTable *class_table) |
|---|
| 29 | { |
|---|
| 30 | if (cr) { |
|---|
| 31 | cr->alloc = 0; |
|---|
| 32 | } |
|---|
| 33 | else { |
|---|
| 34 | cr = emalloc(sizeof(xc_compile_result_t)); |
|---|
| 35 | cr->alloc = 1; |
|---|
| 36 | } |
|---|
| 37 | cr->op_array = op_array; |
|---|
| 38 | cr->function_table = function_table; |
|---|
| 39 | cr->class_table = class_table; |
|---|
| 40 | return cr; |
|---|
| 41 | } |
|---|
| 42 | /* }}} */ |
|---|
| 43 | xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 44 | { |
|---|
| 45 | return xc_compile_result_init(cr, op_array, CG(function_table), CG(class_table)); |
|---|
| 46 | } |
|---|
| 47 | /* }}} */ |
|---|
| 48 | void xc_compile_result_free(xc_compile_result_t *cr) /* {{{ */ |
|---|
| 49 | { |
|---|
| 50 | if (cr->alloc) { |
|---|
| 51 | efree(cr); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | /* }}} */ |
|---|
| 55 | |
|---|
| 56 | int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC) /* {{{ */ |
|---|
| 57 | { |
|---|
| 58 | switch (zf->type) { |
|---|
| 59 | case ZEND_USER_FUNCTION: |
|---|
| 60 | case ZEND_EVAL_CODE: |
|---|
| 61 | return applyer(&zf->op_array TSRMLS_CC); |
|---|
| 62 | break; |
|---|
| 63 | |
|---|
| 64 | case ZEND_INTERNAL_FUNCTION: |
|---|
| 65 | case ZEND_OVERLOADED_FUNCTION: |
|---|
| 66 | break; |
|---|
| 67 | |
|---|
| 68 | EMPTY_SWITCH_DEFAULT_CASE(); |
|---|
| 69 | } |
|---|
| 70 | return 0; |
|---|
| 71 | } |
|---|
| 72 | /* }}} */ |
|---|
| 73 | typedef struct { |
|---|
| 74 | apply_func_t applyer; |
|---|
| 75 | zend_class_entry *ce; |
|---|
| 76 | } xc_apply_method_info; |
|---|
| 77 | int xc_apply_method(zend_function *zf, xc_apply_method_info *mi TSRMLS_DC) /* {{{ */ |
|---|
| 78 | { |
|---|
| 79 | /* avoid duplicate apply for shadowed method */ |
|---|
| 80 | #ifdef ZEND_ENGINE_2 |
|---|
| 81 | if (mi->ce != zf->common.scope) { |
|---|
| 82 | /* fprintf(stderr, "avoided duplicate %s\n", zf->common.function_name); */ |
|---|
| 83 | return 0; |
|---|
| 84 | } |
|---|
| 85 | #else |
|---|
| 86 | char *name = zf->common.function_name; |
|---|
| 87 | int name_s = strlen(name) + 1; |
|---|
| 88 | zend_class_entry *ce; |
|---|
| 89 | zend_function *ptr; |
|---|
| 90 | |
|---|
| 91 | for (ce = mi->ce->parent; ce; ce = ce->parent) { |
|---|
| 92 | if (zend_hash_find(&ce->function_table, name, name_s, (void **) &ptr) == SUCCESS) { |
|---|
| 93 | if (ptr->op_array.refcount == zf->op_array.refcount) { |
|---|
| 94 | return 0; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | #endif |
|---|
| 99 | return xc_apply_function(zf, mi->applyer TSRMLS_CC); |
|---|
| 100 | } |
|---|
| 101 | /* }}} */ |
|---|
| 102 | #if 0 |
|---|
| 103 | int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC) /* {{{ */ |
|---|
| 104 | { |
|---|
| 105 | xc_apply_method_info mi; |
|---|
| 106 | |
|---|
| 107 | mi.applyer = applyer; |
|---|
| 108 | mi.ce = ce; |
|---|
| 109 | zend_hash_apply_with_argument(&(ce->function_table), (apply_func_arg_t) xc_apply_method, &mi TSRMLS_CC); |
|---|
| 110 | return 0; |
|---|
| 111 | } |
|---|
| 112 | /* }}} */ |
|---|
| 113 | #endif |
|---|
| 114 | static int xc_apply_cest(xc_cest_t *cest, apply_func_t applyer TSRMLS_DC) /* {{{ */ |
|---|
| 115 | { |
|---|
| 116 | xc_apply_method_info mi; |
|---|
| 117 | |
|---|
| 118 | mi.applyer = applyer; |
|---|
| 119 | mi.ce = CestToCePtr(*cest); |
|---|
| 120 | zend_hash_apply_with_argument(&(CestToCePtr(*cest)->function_table), (apply_func_arg_t) xc_apply_method, &mi TSRMLS_CC); |
|---|
| 121 | return 0; |
|---|
| 122 | } |
|---|
| 123 | /* }}} */ |
|---|
| 124 | int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC) /* {{{ */ |
|---|
| 125 | { |
|---|
| 126 | zend_hash_apply_with_argument(cr->function_table, (apply_func_arg_t) xc_apply_function, (void *) applyer TSRMLS_CC); |
|---|
| 127 | zend_hash_apply_with_argument(cr->class_table, (apply_func_arg_t) xc_apply_cest, (void *) applyer TSRMLS_CC); |
|---|
| 128 | |
|---|
| 129 | return applyer(cr->op_array TSRMLS_CC); |
|---|
| 130 | } |
|---|
| 131 | /* }}} */ |
|---|
| 132 | |
|---|
| 133 | int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 134 | { |
|---|
| 135 | zend_op *opline, *end; |
|---|
| 136 | |
|---|
| 137 | if (!op_array->done_pass_two) { |
|---|
| 138 | return 0; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | opline = op_array->opcodes; |
|---|
| 142 | end = opline + op_array->last; |
|---|
| 143 | while (opline < end) { |
|---|
| 144 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 145 | switch (opline->opcode) { |
|---|
| 146 | #ifdef ZEND_GOTO |
|---|
| 147 | case ZEND_GOTO: |
|---|
| 148 | #endif |
|---|
| 149 | case ZEND_JMP: |
|---|
| 150 | opline->op1.u.opline_num = opline->op1.u.jmp_addr - op_array->opcodes; |
|---|
| 151 | assert(opline->op1.u.opline_num < op_array->last); |
|---|
| 152 | break; |
|---|
| 153 | case ZEND_JMPZ: |
|---|
| 154 | case ZEND_JMPNZ: |
|---|
| 155 | case ZEND_JMPZ_EX: |
|---|
| 156 | case ZEND_JMPNZ_EX: |
|---|
| 157 | #ifdef ZEND_JMP_SET |
|---|
| 158 | case ZEND_JMP_SET: |
|---|
| 159 | #endif |
|---|
| 160 | opline->op2.u.opline_num = opline->op2.u.jmp_addr - op_array->opcodes; |
|---|
| 161 | assert(opline->op2.u.opline_num < op_array->last); |
|---|
| 162 | break; |
|---|
| 163 | } |
|---|
| 164 | #endif |
|---|
| 165 | opline++; |
|---|
| 166 | } |
|---|
| 167 | op_array->done_pass_two = 0; |
|---|
| 168 | |
|---|
| 169 | return 0; |
|---|
| 170 | } |
|---|
| 171 | /* }}} */ |
|---|
| 172 | int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 173 | { |
|---|
| 174 | zend_op *opline, *end; |
|---|
| 175 | |
|---|
| 176 | if (op_array->done_pass_two) { |
|---|
| 177 | return 0; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | /* |
|---|
| 181 | op_array->opcodes = (zend_op *) erealloc(op_array->opcodes, sizeof(zend_op)*op_array->last); |
|---|
| 182 | op_array->size = op_array->last; |
|---|
| 183 | */ |
|---|
| 184 | |
|---|
| 185 | opline = op_array->opcodes; |
|---|
| 186 | end = opline + op_array->last; |
|---|
| 187 | while (opline < end) { |
|---|
| 188 | if (opline->op1.op_type == IS_CONST) { |
|---|
| 189 | Z_SET_ISREF(opline->op1.u.constant); |
|---|
| 190 | Z_SET_REFCOUNT(opline->op1.u.constant, 2); /* Make sure is_ref won't be reset */ |
|---|
| 191 | |
|---|
| 192 | } |
|---|
| 193 | if (opline->op2.op_type == IS_CONST) { |
|---|
| 194 | Z_SET_ISREF(opline->op2.u.constant); |
|---|
| 195 | Z_SET_REFCOUNT(opline->op2.u.constant, 2); |
|---|
| 196 | } |
|---|
| 197 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 198 | switch (opline->opcode) { |
|---|
| 199 | #ifdef ZEND_GOTO |
|---|
| 200 | case ZEND_GOTO: |
|---|
| 201 | #endif |
|---|
| 202 | case ZEND_JMP: |
|---|
| 203 | assert(opline->op1.u.opline_num < op_array->last); |
|---|
| 204 | opline->op1.u.jmp_addr = op_array->opcodes + opline->op1.u.opline_num; |
|---|
| 205 | break; |
|---|
| 206 | case ZEND_JMPZ: |
|---|
| 207 | case ZEND_JMPNZ: |
|---|
| 208 | case ZEND_JMPZ_EX: |
|---|
| 209 | case ZEND_JMPNZ_EX: |
|---|
| 210 | #ifdef ZEND_JMP_SET |
|---|
| 211 | case ZEND_JMP_SET: |
|---|
| 212 | #endif |
|---|
| 213 | assert(opline->op2.u.opline_num < op_array->last); |
|---|
| 214 | opline->op2.u.jmp_addr = op_array->opcodes + opline->op2.u.opline_num; |
|---|
| 215 | break; |
|---|
| 216 | } |
|---|
| 217 | ZEND_VM_SET_OPCODE_HANDLER(opline); |
|---|
| 218 | #endif |
|---|
| 219 | opline++; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | op_array->done_pass_two = 1; |
|---|
| 223 | return 0; |
|---|
| 224 | } |
|---|
| 225 | /* }}} */ |
|---|
| 226 | |
|---|
| 227 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
|---|
| 228 | static void xc_fix_opcode_ex_znode(int tofix, xc_op_spec_t spec, znode *znode, int type TSRMLS_DC) /* {{{ */ |
|---|
| 229 | { |
|---|
| 230 | #ifdef ZEND_ENGINE_2 |
|---|
| 231 | if ((znode->op_type != IS_UNUSED && (spec == OPSPEC_UCLASS || spec == OPSPEC_CLASS)) || |
|---|
| 232 | spec == OPSPEC_FETCH) { |
|---|
| 233 | if (tofix) { |
|---|
| 234 | switch (znode->op_type) { |
|---|
| 235 | case IS_VAR: |
|---|
| 236 | case IS_TMP_VAR: |
|---|
| 237 | break; |
|---|
| 238 | |
|---|
| 239 | default: |
|---|
| 240 | /* TODO: data lost, find a way to keep it */ |
|---|
| 241 | /* assert(znode->op_type == IS_CONST); */ |
|---|
| 242 | znode->op_type = IS_TMP_VAR; |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | switch (znode->op_type) { |
|---|
| 247 | case IS_TMP_VAR: |
|---|
| 248 | case IS_VAR: |
|---|
| 249 | if (tofix) { |
|---|
| 250 | znode->u.var /= sizeof(temp_variable); |
|---|
| 251 | } |
|---|
| 252 | else { |
|---|
| 253 | znode->u.var *= sizeof(temp_variable); |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| 256 | #endif |
|---|
| 257 | } |
|---|
| 258 | /* }}} */ |
|---|
| 259 | |
|---|
| 260 | static void xc_fix_opcode_ex(zend_op_array *op_array, int tofix TSRMLS_DC) /* {{{ */ |
|---|
| 261 | { |
|---|
| 262 | zend_op *opline; |
|---|
| 263 | zend_uint i; |
|---|
| 264 | |
|---|
| 265 | opline = op_array->opcodes; |
|---|
| 266 | for (i = 0; i < op_array->last; i ++, opline ++) { |
|---|
| 267 | /* 3rd optimizer may have ... */ |
|---|
| 268 | if (opline->opcode < xc_get_opcode_spec_count()) { |
|---|
| 269 | const xc_opcode_spec_t *spec; |
|---|
| 270 | spec = xc_get_opcode_spec(opline->opcode); |
|---|
| 271 | |
|---|
| 272 | xc_fix_opcode_ex_znode(tofix, spec->op1, &opline->op1, 0 TSRMLS_CC); |
|---|
| 273 | xc_fix_opcode_ex_znode(tofix, spec->op2, &opline->op2, 1 TSRMLS_CC); |
|---|
| 274 | xc_fix_opcode_ex_znode(tofix, spec->res, &opline->result, 2 TSRMLS_CC); |
|---|
| 275 | } |
|---|
| 276 | } |
|---|
| 277 | } |
|---|
| 278 | /* }}} */ |
|---|
| 279 | int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 280 | { |
|---|
| 281 | xc_fix_opcode_ex(op_array, 1 TSRMLS_CC); |
|---|
| 282 | return 0; |
|---|
| 283 | } |
|---|
| 284 | /* }}} */ |
|---|
| 285 | int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 286 | { |
|---|
| 287 | xc_fix_opcode_ex(op_array, 0 TSRMLS_CC); |
|---|
| 288 | |
|---|
| 289 | return 0; |
|---|
| 290 | } |
|---|
| 291 | /* }}} */ |
|---|
| 292 | #endif |
|---|
| 293 | |
|---|
| 294 | int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zend_op *opline, int oplineno, void *data TSRMLS_DC), void *data TSRMLS_DC) /* {{{ */ |
|---|
| 295 | { |
|---|
| 296 | zend_op *opline, *begin, *end, *next = NULL; |
|---|
| 297 | |
|---|
| 298 | opline = begin = op_array->opcodes; |
|---|
| 299 | end = opline + op_array->last; |
|---|
| 300 | while (opline < end) { |
|---|
| 301 | switch (opline->opcode) { |
|---|
| 302 | #ifdef ZEND_GOTO |
|---|
| 303 | case ZEND_GOTO: |
|---|
| 304 | #endif |
|---|
| 305 | case ZEND_JMP: |
|---|
| 306 | next = begin + opline->op1.u.opline_num; |
|---|
| 307 | break; |
|---|
| 308 | |
|---|
| 309 | case ZEND_JMPZNZ: |
|---|
| 310 | next = begin + max(opline->op2.u.opline_num, opline->extended_value); |
|---|
| 311 | break; |
|---|
| 312 | |
|---|
| 313 | case ZEND_JMPZ: |
|---|
| 314 | case ZEND_JMPNZ: |
|---|
| 315 | case ZEND_JMPZ_EX: |
|---|
| 316 | case ZEND_JMPNZ_EX: |
|---|
| 317 | #ifdef ZEND_JMP_SET |
|---|
| 318 | case ZEND_JMP_SET: |
|---|
| 319 | #endif |
|---|
| 320 | next = begin + opline->op2.u.opline_num; |
|---|
| 321 | break; |
|---|
| 322 | |
|---|
| 323 | case ZEND_RETURN: |
|---|
| 324 | opline = end; |
|---|
| 325 | break; |
|---|
| 326 | |
|---|
| 327 | #ifdef ZEND_ENGINE_2 |
|---|
| 328 | case ZEND_DECLARE_INHERITED_CLASS: |
|---|
| 329 | callback(opline, opline - begin, data TSRMLS_CC); |
|---|
| 330 | break; |
|---|
| 331 | #else |
|---|
| 332 | case ZEND_DECLARE_FUNCTION_OR_CLASS: |
|---|
| 333 | if (opline->extended_value == ZEND_DECLARE_INHERITED_CLASS) { |
|---|
| 334 | callback(opline, opline - begin, data TSRMLS_CC); |
|---|
| 335 | } |
|---|
| 336 | break; |
|---|
| 337 | #endif |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | if (opline < next) { |
|---|
| 341 | opline = next; |
|---|
| 342 | } |
|---|
| 343 | else { |
|---|
| 344 | opline ++; |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | return SUCCESS; |
|---|
| 348 | } |
|---|
| 349 | /* }}} */ |
|---|
| 350 | static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, int oplineno TSRMLS_DC) /* {{{ */ |
|---|
| 351 | { |
|---|
| 352 | zend_op *opline; |
|---|
| 353 | |
|---|
| 354 | TRACE("binding %d", oplineno); |
|---|
| 355 | assert(oplineno >= 0); |
|---|
| 356 | |
|---|
| 357 | /* do early binding */ |
|---|
| 358 | opline = &(op_array->opcodes[oplineno]); |
|---|
| 359 | |
|---|
| 360 | switch (opline->opcode) { |
|---|
| 361 | #ifdef ZEND_ENGINE_2 |
|---|
| 362 | case ZEND_DECLARE_INHERITED_CLASS: |
|---|
| 363 | { |
|---|
| 364 | zval *parent_name; |
|---|
| 365 | zend_class_entry **pce; |
|---|
| 366 | |
|---|
| 367 | /* don't early-bind classes that implement interfaces */ |
|---|
| 368 | if ((opline + 1)->opcode == ZEND_FETCH_CLASS && (opline + 2)->opcode == ZEND_ADD_INTERFACE) { |
|---|
| 369 | return FAILURE; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | parent_name = &(opline - 1)->op2.u.constant; |
|---|
| 373 | TRACE("binding with parent %s", Z_STRVAL_P(parent_name)); |
|---|
| 374 | if (zend_lookup_class(Z_STRVAL_P(parent_name), Z_STRLEN_P(parent_name), &pce TSRMLS_CC) == FAILURE) { |
|---|
| 375 | return FAILURE; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | if (do_bind_inherited_class(opline, class_table, *pce, 1 TSRMLS_CC) == NULL) { |
|---|
| 379 | return FAILURE; |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | /* clear unnecessary ZEND_FETCH_CLASS opcode */ |
|---|
| 384 | if (opline > op_array->opcodes |
|---|
| 385 | && (opline - 1)->opcode == ZEND_FETCH_CLASS) { |
|---|
| 386 | zend_op *fetch_class_opline = opline - 1; |
|---|
| 387 | |
|---|
| 388 | TRACE("%s %p", Z_STRVAL(fetch_class_opline->op2.u.constant), Z_STRVAL(fetch_class_opline->op2.u.constant)); |
|---|
| 389 | OP_ZVAL_DTOR(fetch_class_opline->op2); |
|---|
| 390 | fetch_class_opline->opcode = ZEND_NOP; |
|---|
| 391 | ZEND_VM_SET_OPCODE_HANDLER(fetch_class_opline); |
|---|
| 392 | memset(&fetch_class_opline->op1, 0, sizeof(znode)); |
|---|
| 393 | memset(&fetch_class_opline->op2, 0, sizeof(znode)); |
|---|
| 394 | SET_UNUSED(fetch_class_opline->op1); |
|---|
| 395 | SET_UNUSED(fetch_class_opline->op2); |
|---|
| 396 | SET_UNUSED(fetch_class_opline->result); |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | /* clear unnecessary ZEND_VERIFY_ABSTRACT_CLASS opcode */ |
|---|
| 400 | if ((opline + 1)->opcode == ZEND_VERIFY_ABSTRACT_CLASS) { |
|---|
| 401 | zend_op *abstract_op = opline + 1; |
|---|
| 402 | memset(abstract_op, 0, sizeof(abstract_op[0])); |
|---|
| 403 | abstract_op->lineno = 0; |
|---|
| 404 | SET_UNUSED(abstract_op->op1); |
|---|
| 405 | SET_UNUSED(abstract_op->op2); |
|---|
| 406 | SET_UNUSED(abstract_op->result); |
|---|
| 407 | abstract_op->opcode = ZEND_NOP; |
|---|
| 408 | ZEND_VM_SET_OPCODE_HANDLER(abstract_op); |
|---|
| 409 | } |
|---|
| 410 | #else |
|---|
| 411 | case ZEND_DECLARE_FUNCTION_OR_CLASS: |
|---|
| 412 | if (do_bind_function_or_class(opline, NULL, class_table, 1) == FAILURE) { |
|---|
| 413 | return FAILURE; |
|---|
| 414 | } |
|---|
| 415 | #endif |
|---|
| 416 | break; |
|---|
| 417 | |
|---|
| 418 | default: |
|---|
| 419 | return FAILURE; |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | zend_hash_del(class_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len); |
|---|
| 423 | OP_ZVAL_DTOR(opline->op1); |
|---|
| 424 | OP_ZVAL_DTOR(opline->op2); |
|---|
| 425 | opline->opcode = ZEND_NOP; |
|---|
| 426 | ZEND_VM_SET_OPCODE_HANDLER(opline); |
|---|
| 427 | memset(&opline->op1, 0, sizeof(znode)); |
|---|
| 428 | memset(&opline->op2, 0, sizeof(znode)); |
|---|
| 429 | SET_UNUSED(opline->op1); |
|---|
| 430 | SET_UNUSED(opline->op2); |
|---|
| 431 | return SUCCESS; |
|---|
| 432 | } |
|---|
| 433 | /* }}} */ |
|---|
| 434 | |
|---|
| 435 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 436 | void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| 437 | { |
|---|
| 438 | if (zend_u_hash_add(EG(zend_constants), type, key, len, |
|---|
| 439 | constant, sizeof(zend_constant), |
|---|
| 440 | NULL |
|---|
| 441 | ) == FAILURE) { |
|---|
| 442 | CG(zend_lineno) = 0; |
|---|
| 443 | #ifdef IS_UNICODE |
|---|
| 444 | zend_error(E_NOTICE, "Constant %R already defined", type, key); |
|---|
| 445 | #else |
|---|
| 446 | zend_error(E_NOTICE, "Constant %s already defined", key); |
|---|
| 447 | #endif |
|---|
| 448 | free(ZSTR_V(constant->name)); |
|---|
| 449 | if (!(constant->flags & CONST_PERSISTENT)) { |
|---|
| 450 | zval_dtor(&constant->value); |
|---|
| 451 | } |
|---|
| 452 | } |
|---|
| 453 | } |
|---|
| 454 | /* }}} */ |
|---|
| 455 | #endif |
|---|
| 456 | void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| 457 | { |
|---|
| 458 | zend_bool istmpkey; |
|---|
| 459 | |
|---|
| 460 | if (func->type == ZEND_USER_FUNCTION) { |
|---|
| 461 | #ifdef IS_UNICODE |
|---|
| 462 | istmpkey = (type == IS_STRING && ZSTR_S(key)[0] == 0) || ZSTR_U(key)[0] == 0; |
|---|
| 463 | #else |
|---|
| 464 | istmpkey = ZSTR_S(key)[0] == 0; |
|---|
| 465 | #endif |
|---|
| 466 | if (istmpkey) { |
|---|
| 467 | zend_u_hash_update(CG(function_table), type, key, len, |
|---|
| 468 | func, sizeof(zend_op_array), |
|---|
| 469 | NULL |
|---|
| 470 | ); |
|---|
| 471 | } |
|---|
| 472 | else if (zend_u_hash_add(CG(function_table), type, key, len, |
|---|
| 473 | func, sizeof(zend_op_array), |
|---|
| 474 | NULL |
|---|
| 475 | ) == FAILURE) { |
|---|
| 476 | CG(zend_lineno) = ZESW(func->op_array.opcodes[0].lineno, func->op_array.line_start); |
|---|
| 477 | #ifdef IS_UNICODE |
|---|
| 478 | zend_error(E_ERROR, "Cannot redeclare %R()", type, key); |
|---|
| 479 | #else |
|---|
| 480 | zend_error(E_ERROR, "Cannot redeclare %s()", key); |
|---|
| 481 | #endif |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | } |
|---|
| 485 | /* }}} */ |
|---|
| 486 | ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| 487 | { |
|---|
| 488 | zend_bool istmpkey; |
|---|
| 489 | zend_class_entry *cep = CestToCePtr(*cest); |
|---|
| 490 | ZESW(void *stored_ce_ptr, NOTHING); |
|---|
| 491 | |
|---|
| 492 | #ifdef IS_UNICODE |
|---|
| 493 | istmpkey = (type == IS_STRING && ZSTR_S(key)[0] == 0) || ZSTR_U(key)[0] == 0; |
|---|
| 494 | #else |
|---|
| 495 | istmpkey = ZSTR_S(key)[0] == 0; |
|---|
| 496 | #endif |
|---|
| 497 | if (istmpkey) { |
|---|
| 498 | zend_u_hash_quick_update(CG(class_table), type, key, len, h, |
|---|
| 499 | cest, sizeof(xc_cest_t), |
|---|
| 500 | ZESW(&stored_ce_ptr, NULL) |
|---|
| 501 | ); |
|---|
| 502 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 503 | if (oplineno != -1) { |
|---|
| 504 | xc_do_early_binding(CG(active_op_array), CG(class_table), oplineno TSRMLS_CC); |
|---|
| 505 | } |
|---|
| 506 | #endif |
|---|
| 507 | } |
|---|
| 508 | else if (zend_u_hash_quick_add(CG(class_table), type, key, len, h, |
|---|
| 509 | cest, sizeof(xc_cest_t), |
|---|
| 510 | ZESW(&stored_ce_ptr, NULL) |
|---|
| 511 | ) == FAILURE) { |
|---|
| 512 | CG(zend_lineno) = ZESW(0, cep->line_start); |
|---|
| 513 | #ifdef IS_UNICODE |
|---|
| 514 | zend_error(E_ERROR, "Cannot redeclare class %R", type, cep->name); |
|---|
| 515 | #else |
|---|
| 516 | zend_error(E_ERROR, "Cannot redeclare class %s", cep->name); |
|---|
| 517 | #endif |
|---|
| 518 | assert(oplineno == -1); |
|---|
| 519 | } |
|---|
| 520 | ZESW(return (xc_cest_t *) stored_ce_ptr, NOTHING); |
|---|
| 521 | } |
|---|
| 522 | /* }}} */ |
|---|
| 523 | |
|---|
| 524 | /* sandbox {{{ */ |
|---|
| 525 | #undef TG |
|---|
| 526 | #undef OG |
|---|
| 527 | #define TG(x) (sandbox->tmp_##x) |
|---|
| 528 | #define OG(x) (sandbox->orig_##x) |
|---|
| 529 | /* }}} */ |
|---|
| 530 | #ifdef E_STRICT |
|---|
| 531 | static void xc_sandbox_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) /* {{{ */ |
|---|
| 532 | { |
|---|
| 533 | xc_compilererror_t *compilererror; |
|---|
| 534 | xc_sandbox_t *sandbox; |
|---|
| 535 | TSRMLS_FETCH(); |
|---|
| 536 | |
|---|
| 537 | sandbox = (xc_sandbox_t *) XG(sandbox); |
|---|
| 538 | assert(sandbox != NULL); |
|---|
| 539 | if (type != E_STRICT) { |
|---|
| 540 | /* give up, and user handler is not supported in this case */ |
|---|
| 541 | zend_uint i; |
|---|
| 542 | zend_uint orig_lineno = CG(zend_lineno); |
|---|
| 543 | zend_error_cb = sandbox->orig_zend_error_cb; |
|---|
| 544 | |
|---|
| 545 | for (i = 0; i < sandbox->compilererror_cnt; i ++) { |
|---|
| 546 | compilererror = &sandbox->compilererrors[i]; |
|---|
| 547 | CG(zend_lineno) = compilererror->lineno; |
|---|
| 548 | zend_error(E_STRICT, "%s", compilererror->error); |
|---|
| 549 | } |
|---|
| 550 | CG(zend_lineno) = orig_lineno; |
|---|
| 551 | sandbox->compilererror_cnt = 0; |
|---|
| 552 | |
|---|
| 553 | sandbox->orig_zend_error_cb(type, error_filename, error_lineno, format, args); |
|---|
| 554 | return; |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | if (sandbox->compilererror_cnt <= sandbox->compilererror_size) { |
|---|
| 558 | if (sandbox->compilererror_size) { |
|---|
| 559 | sandbox->compilererror_size += 16; |
|---|
| 560 | sandbox->compilererrors = erealloc(sandbox->compilererrors, sandbox->compilererror_size * sizeof(sandbox->compilererrors)); |
|---|
| 561 | } |
|---|
| 562 | else { |
|---|
| 563 | sandbox->compilererror_size = 16; |
|---|
| 564 | sandbox->compilererrors = emalloc(sandbox->compilererror_size * sizeof(sandbox->compilererrors)); |
|---|
| 565 | } |
|---|
| 566 | } |
|---|
| 567 | compilererror = &sandbox->compilererrors[sandbox->compilererror_cnt++]; |
|---|
| 568 | compilererror->lineno = error_lineno; |
|---|
| 569 | compilererror->error_len = vspprintf(&compilererror->error, 0, format, args); |
|---|
| 570 | } |
|---|
| 571 | /* }}} */ |
|---|
| 572 | #endif |
|---|
| 573 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 574 | static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */ |
|---|
| 575 | { |
|---|
| 576 | zend_auto_global *auto_global; |
|---|
| 577 | if (zend_u_hash_find(CG(auto_globals), UG(unicode) ? IS_UNICODE : IS_STRING, ZSTR(name), name_len + 1, (void **) &auto_global) == FAILURE) { |
|---|
| 578 | return 1; |
|---|
| 579 | } |
|---|
| 580 | return 0; |
|---|
| 581 | } |
|---|
| 582 | /* }}} */ |
|---|
| 583 | static int xc_auto_global_arm(zend_auto_global *auto_global TSRMLS_DC) /* {{{ */ |
|---|
| 584 | { |
|---|
| 585 | if (auto_global->auto_global_callback) { |
|---|
| 586 | auto_global->armed = 1; |
|---|
| 587 | auto_global->auto_global_callback = xc_auto_global_callback; |
|---|
| 588 | } |
|---|
| 589 | else { |
|---|
| 590 | auto_global->armed = 0; |
|---|
| 591 | } |
|---|
| 592 | return ZEND_HASH_APPLY_KEEP; |
|---|
| 593 | } |
|---|
| 594 | /* }}} */ |
|---|
| 595 | #endif |
|---|
| 596 | |
|---|
| 597 | static void xc_copy_zend_constant(zend_constant *c) /* {{{ */ |
|---|
| 598 | { |
|---|
| 599 | c->name = zend_strndup(c->name, c->name_len - 1); |
|---|
| 600 | if (!(c->flags & CONST_PERSISTENT)) { |
|---|
| 601 | zval_copy_ctor(&c->value); |
|---|
| 602 | } |
|---|
| 603 | } |
|---|
| 604 | /* }}} */ |
|---|
| 605 | xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */ |
|---|
| 606 | { |
|---|
| 607 | HashTable *h; |
|---|
| 608 | |
|---|
| 609 | if (sandbox) { |
|---|
| 610 | memset(sandbox, 0, sizeof(sandbox[0])); |
|---|
| 611 | } |
|---|
| 612 | else { |
|---|
| 613 | ECALLOC_ONE(sandbox); |
|---|
| 614 | sandbox->alloc = 1; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | memcpy(&OG(included_files), &EG(included_files), sizeof(EG(included_files))); |
|---|
| 618 | |
|---|
| 619 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 620 | OG(zend_constants) = EG(zend_constants); |
|---|
| 621 | EG(zend_constants) = &TG(zend_constants); |
|---|
| 622 | #endif |
|---|
| 623 | |
|---|
| 624 | OG(function_table) = CG(function_table); |
|---|
| 625 | CG(function_table) = &TG(function_table); |
|---|
| 626 | |
|---|
| 627 | OG(class_table) = CG(class_table); |
|---|
| 628 | CG(class_table) = &TG(class_table); |
|---|
| 629 | EG(class_table) = CG(class_table); |
|---|
| 630 | |
|---|
| 631 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 632 | OG(auto_globals) = CG(auto_globals); |
|---|
| 633 | CG(auto_globals) = &TG(auto_globals); |
|---|
| 634 | #endif |
|---|
| 635 | |
|---|
| 636 | TG(included_files) = &EG(included_files); |
|---|
| 637 | |
|---|
| 638 | zend_hash_init_ex(TG(included_files), 5, NULL, NULL, 0, 1); |
|---|
| 639 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 640 | h = OG(zend_constants); |
|---|
| 641 | zend_hash_init_ex(&TG(zend_constants), 20, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| 642 | { |
|---|
| 643 | zend_constant tmp_const; |
|---|
| 644 | zend_hash_copy(&TG(zend_constants), &XG(internal_constant_table), (copy_ctor_func_t) xc_copy_zend_constant, (void *) &tmp_const, sizeof(tmp_const)); |
|---|
| 645 | } |
|---|
| 646 | #endif |
|---|
| 647 | h = OG(function_table); |
|---|
| 648 | zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| 649 | { |
|---|
| 650 | zend_function tmp_func; |
|---|
| 651 | zend_hash_copy(&TG(function_table), &XG(internal_function_table), NULL, (void *) &tmp_func, sizeof(tmp_func)); |
|---|
| 652 | } |
|---|
| 653 | TG(internal_function_tail) = TG(function_table).pListTail; |
|---|
| 654 | |
|---|
| 655 | h = OG(class_table); |
|---|
| 656 | zend_hash_init_ex(&TG(class_table), 16, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| 657 | #if 0 && TODO |
|---|
| 658 | { |
|---|
| 659 | xc_cest_t tmp_cest; |
|---|
| 660 | zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &tmp_cest, sizeof(tmp_cest)); |
|---|
| 661 | } |
|---|
| 662 | #endif |
|---|
| 663 | TG(internal_class_tail) = TG(class_table).pListTail; |
|---|
| 664 | |
|---|
| 665 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 666 | /* shallow copy, don't destruct */ |
|---|
| 667 | h = OG(auto_globals); |
|---|
| 668 | zend_hash_init_ex(&TG(auto_globals), 8, NULL, NULL, h->persistent, h->bApplyProtection); |
|---|
| 669 | { |
|---|
| 670 | zend_auto_global tmp_autoglobal; |
|---|
| 671 | |
|---|
| 672 | zend_hash_copy(&TG(auto_globals), OG(auto_globals), NULL, (void *) &tmp_autoglobal, sizeof(tmp_autoglobal)); |
|---|
| 673 | zend_hash_apply(&TG(auto_globals), (apply_func_t) xc_auto_global_arm TSRMLS_CC); |
|---|
| 674 | } |
|---|
| 675 | #endif |
|---|
| 676 | |
|---|
| 677 | sandbox->filename = filename; |
|---|
| 678 | |
|---|
| 679 | #ifdef E_STRICT |
|---|
| 680 | sandbox->orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting); |
|---|
| 681 | EG(user_error_handler_error_reporting) = 0; |
|---|
| 682 | |
|---|
| 683 | sandbox->compilererror_cnt = 0; |
|---|
| 684 | sandbox->compilererror_size = 0; |
|---|
| 685 | sandbox->orig_zend_error_cb = zend_error_cb; |
|---|
| 686 | zend_error_cb = xc_sandbox_error_cb; |
|---|
| 687 | #endif |
|---|
| 688 | |
|---|
| 689 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 690 | sandbox->orig_compiler_options = CG(compiler_options); |
|---|
| 691 | /* Using ZEND_COMPILE_IGNORE_INTERNAL_CLASSES for ZEND_FETCH_CLASS_RT_NS_CHECK |
|---|
| 692 | */ |
|---|
| 693 | CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES | ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_DELAYED_BINDING; |
|---|
| 694 | #endif |
|---|
| 695 | |
|---|
| 696 | XG(sandbox) = (void *) sandbox; |
|---|
| 697 | return sandbox; |
|---|
| 698 | } |
|---|
| 699 | /* }}} */ |
|---|
| 700 | static void xc_early_binding_cb(zend_op *opline, int oplineno, void *data TSRMLS_DC) /* {{{ */ |
|---|
| 701 | { |
|---|
| 702 | xc_sandbox_t *sandbox = (xc_sandbox_t *) data; |
|---|
| 703 | xc_do_early_binding(CG(active_op_array), OG(class_table), oplineno TSRMLS_CC); |
|---|
| 704 | } |
|---|
| 705 | /* }}} */ |
|---|
| 706 | static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */ |
|---|
| 707 | { |
|---|
| 708 | zend_uint i; |
|---|
| 709 | Bucket *b; |
|---|
| 710 | |
|---|
| 711 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 712 | b = /*TG(internal_constant_tail) ? TG(internal_constant_tail)->pListNext :*/ TG(zend_constants).pListHead; |
|---|
| 713 | /* install constants */ |
|---|
| 714 | while (b != NULL) { |
|---|
| 715 | zend_constant *c = (zend_constant*) b->pData; |
|---|
| 716 | xc_install_constant(sandbox->filename, c, |
|---|
| 717 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| 718 | b = b->pListNext; |
|---|
| 719 | } |
|---|
| 720 | #endif |
|---|
| 721 | |
|---|
| 722 | b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead; |
|---|
| 723 | /* install function */ |
|---|
| 724 | while (b != NULL) { |
|---|
| 725 | zend_function *func = (zend_function*) b->pData; |
|---|
| 726 | xc_install_function(sandbox->filename, func, |
|---|
| 727 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| 728 | b = b->pListNext; |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead; |
|---|
| 732 | /* install class */ |
|---|
| 733 | while (b != NULL) { |
|---|
| 734 | xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1, |
|---|
| 735 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| 736 | b = b->pListNext; |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 740 | /* trigger auto_globals jit */ |
|---|
| 741 | for (b = TG(auto_globals).pListHead; b != NULL; b = b->pListNext) { |
|---|
| 742 | zend_auto_global *auto_global = (zend_auto_global *) b->pData; |
|---|
| 743 | /* check if actived */ |
|---|
| 744 | if (auto_global->auto_global_callback && !auto_global->armed) { |
|---|
| 745 | zend_u_is_auto_global(BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), auto_global->name_len TSRMLS_CC); |
|---|
| 746 | } |
|---|
| 747 | } |
|---|
| 748 | #endif |
|---|
| 749 | |
|---|
| 750 | if (install != XC_InstallNoBinding) { |
|---|
| 751 | #ifdef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 752 | zend_do_delayed_early_binding(CG(active_op_array) TSRMLS_CC); |
|---|
| 753 | #else |
|---|
| 754 | xc_undo_pass_two(CG(active_op_array) TSRMLS_CC); |
|---|
| 755 | xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC); |
|---|
| 756 | xc_redo_pass_two(CG(active_op_array) TSRMLS_CC); |
|---|
| 757 | #endif |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | #ifdef E_STRICT |
|---|
| 761 | /* restore trigger errors */ |
|---|
| 762 | for (i = 0; i < sandbox->compilererror_cnt; i ++) { |
|---|
| 763 | xc_compilererror_t *error = &sandbox->compilererrors[i]; |
|---|
| 764 | CG(zend_lineno) = error->lineno; |
|---|
| 765 | zend_error(E_STRICT, "%s", error->error); |
|---|
| 766 | } |
|---|
| 767 | CG(zend_lineno) = 0; |
|---|
| 768 | #endif |
|---|
| 769 | |
|---|
| 770 | i = 1; |
|---|
| 771 | zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL); |
|---|
| 772 | } |
|---|
| 773 | /* }}} */ |
|---|
| 774 | void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */ |
|---|
| 775 | { |
|---|
| 776 | XG(sandbox) = NULL; |
|---|
| 777 | #ifdef E_STRICT |
|---|
| 778 | EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting; |
|---|
| 779 | zend_error_cb = sandbox->orig_zend_error_cb; |
|---|
| 780 | #endif |
|---|
| 781 | |
|---|
| 782 | /* restore first first install function/class */ |
|---|
| 783 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 784 | EG(zend_constants) = OG(zend_constants); |
|---|
| 785 | #endif |
|---|
| 786 | CG(function_table) = OG(function_table); |
|---|
| 787 | CG(class_table) = OG(class_table); |
|---|
| 788 | EG(class_table) = CG(class_table); |
|---|
| 789 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 790 | CG(auto_globals) = OG(auto_globals); |
|---|
| 791 | #endif |
|---|
| 792 | |
|---|
| 793 | if (install != XC_NoInstall) { |
|---|
| 794 | CG(in_compilation) = 1; |
|---|
| 795 | CG(compiled_filename) = sandbox->filename; |
|---|
| 796 | CG(zend_lineno) = 0; |
|---|
| 797 | xc_sandbox_install(sandbox, install TSRMLS_CC); |
|---|
| 798 | CG(in_compilation) = 0; |
|---|
| 799 | CG(compiled_filename) = NULL; |
|---|
| 800 | |
|---|
| 801 | /* no free as it's installed */ |
|---|
| 802 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 803 | TG(zend_constants).pDestructor = NULL; |
|---|
| 804 | #endif |
|---|
| 805 | TG(function_table).pDestructor = NULL; |
|---|
| 806 | TG(class_table).pDestructor = NULL; |
|---|
| 807 | } |
|---|
| 808 | |
|---|
| 809 | /* destroy all the tmp */ |
|---|
| 810 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 811 | zend_hash_destroy(&TG(zend_constants)); |
|---|
| 812 | #endif |
|---|
| 813 | zend_hash_destroy(&TG(function_table)); |
|---|
| 814 | zend_hash_destroy(&TG(class_table)); |
|---|
| 815 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 816 | zend_hash_destroy(&TG(auto_globals)); |
|---|
| 817 | #endif |
|---|
| 818 | zend_hash_destroy(TG(included_files)); |
|---|
| 819 | |
|---|
| 820 | /* restore orig here, as EG/CG holded tmp before */ |
|---|
| 821 | memcpy(&EG(included_files), &OG(included_files), sizeof(EG(included_files))); |
|---|
| 822 | |
|---|
| 823 | #ifdef E_STRICT |
|---|
| 824 | if (sandbox->compilererrors) { |
|---|
| 825 | zend_uint i; |
|---|
| 826 | for (i = 0; i < sandbox->compilererror_cnt; i ++) { |
|---|
| 827 | efree(sandbox->compilererrors[i].error); |
|---|
| 828 | } |
|---|
| 829 | efree(sandbox->compilererrors); |
|---|
| 830 | } |
|---|
| 831 | #endif |
|---|
| 832 | |
|---|
| 833 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 834 | CG(compiler_options) = sandbox->orig_compiler_options; |
|---|
| 835 | #endif |
|---|
| 836 | |
|---|
| 837 | if (sandbox->alloc) { |
|---|
| 838 | efree(sandbox); |
|---|
| 839 | } |
|---|
| 840 | } |
|---|
| 841 | /* }}} */ |
|---|
| 842 | int xc_vtrace(const char *fmt, va_list args) /* {{{ */ |
|---|
| 843 | { |
|---|
| 844 | return vfprintf(stderr, fmt, args); |
|---|
| 845 | } |
|---|
| 846 | /* }}} */ |
|---|
| 847 | int xc_trace(const char *fmt, ...) /* {{{ */ |
|---|
| 848 | { |
|---|
| 849 | va_list args; |
|---|
| 850 | int ret; |
|---|
| 851 | |
|---|
| 852 | va_start(args, fmt); |
|---|
| 853 | ret = xc_vtrace(fmt, args); |
|---|
| 854 | va_end(args); |
|---|
| 855 | return ret; |
|---|
| 856 | } |
|---|
| 857 | /* }}} */ |
|---|