| [212] | 1 | |
|---|
| [1] | 2 | #include "xcache.h" |
|---|
| [344] | 3 | #include "stack.h" |
|---|
| 4 | #include "xcache_globals.h" |
|---|
| [1] | 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 | |
|---|
| [213] | 13 | #ifndef max |
|---|
| 14 | #define max(a, b) ((a) < (b) ? (b) : (a)) |
|---|
| 15 | #endif |
|---|
| 16 | |
|---|
| [212] | 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 { \ |
|---|
| [485] | 22 | Z_UNSET_ISREF((op).u.constant); \ |
|---|
| [212] | 23 | zval_dtor(&(op).u.constant); \ |
|---|
| 24 | } while(0) |
|---|
| [1] | 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 | { |
|---|
| [294] | 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); |
|---|
| [1] | 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) { |
|---|
| [515] | 146 | #ifdef ZEND_GOTO |
|---|
| 147 | case ZEND_GOTO: |
|---|
| 148 | #endif |
|---|
| [1] | 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: |
|---|
| [485] | 157 | #ifdef ZEND_JMP_SET |
|---|
| 158 | case ZEND_JMP_SET: |
|---|
| 159 | #endif |
|---|
| [1] | 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) { |
|---|
| [485] | 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 | |
|---|
| [1] | 192 | } |
|---|
| 193 | if (opline->op2.op_type == IS_CONST) { |
|---|
| [485] | 194 | Z_SET_ISREF(opline->op2.u.constant); |
|---|
| 195 | Z_SET_REFCOUNT(opline->op2.u.constant, 2); |
|---|
| [1] | 196 | } |
|---|
| 197 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 198 | switch (opline->opcode) { |
|---|
| [515] | 199 | #ifdef ZEND_GOTO |
|---|
| 200 | case ZEND_GOTO: |
|---|
| 201 | #endif |
|---|
| [1] | 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: |
|---|
| [485] | 210 | #ifdef ZEND_JMP_SET |
|---|
| 211 | case ZEND_JMP_SET: |
|---|
| 212 | #endif |
|---|
| [1] | 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 | |
|---|
| [8] | 227 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
|---|
| [1] | 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; |
|---|
| [11] | 263 | zend_uint i; |
|---|
| [1] | 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 | /* }}} */ |
|---|
| [8] | 292 | #endif |
|---|
| [1] | 293 | |
|---|
| [212] | 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) { |
|---|
| [515] | 302 | #ifdef ZEND_GOTO |
|---|
| 303 | case ZEND_GOTO: |
|---|
| 304 | #endif |
|---|
| [212] | 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: |
|---|
| [485] | 317 | #ifdef ZEND_JMP_SET |
|---|
| 318 | case ZEND_JMP_SET: |
|---|
| 319 | #endif |
|---|
| [212] | 320 | next = begin + opline->op2.u.opline_num; |
|---|
| 321 | break; |
|---|
| 322 | |
|---|
| 323 | case ZEND_RETURN: |
|---|
| 324 | opline = end; |
|---|
| 325 | break; |
|---|
| 326 | |
|---|
| [226] | 327 | #ifdef ZEND_ENGINE_2 |
|---|
| [212] | 328 | case ZEND_DECLARE_INHERITED_CLASS: |
|---|
| 329 | callback(opline, opline - begin, data TSRMLS_CC); |
|---|
| 330 | break; |
|---|
| [226] | 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 |
|---|
| [212] | 338 | } |
|---|
| 339 | |
|---|
| 340 | if (opline < next) { |
|---|
| 341 | opline = next; |
|---|
| 342 | } |
|---|
| 343 | else { |
|---|
| 344 | opline ++; |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| [295] | 347 | return SUCCESS; |
|---|
| [212] | 348 | } |
|---|
| 349 | /* }}} */ |
|---|
| [214] | 350 | static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, int oplineno TSRMLS_DC) /* {{{ */ |
|---|
| [212] | 351 | { |
|---|
| [295] | 352 | zend_op *opline; |
|---|
| [212] | 353 | |
|---|
| [305] | 354 | TRACE("binding %d", oplineno); |
|---|
| [212] | 355 | assert(oplineno >= 0); |
|---|
| 356 | |
|---|
| 357 | /* do early binding */ |
|---|
| 358 | opline = &(op_array->opcodes[oplineno]); |
|---|
| 359 | |
|---|
| 360 | switch (opline->opcode) { |
|---|
| [226] | 361 | #ifdef ZEND_ENGINE_2 |
|---|
| [212] | 362 | case ZEND_DECLARE_INHERITED_CLASS: |
|---|
| 363 | { |
|---|
| 364 | zval *parent_name; |
|---|
| 365 | zend_class_entry **pce; |
|---|
| [214] | 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 | |
|---|
| [212] | 372 | parent_name = &(opline - 1)->op2.u.constant; |
|---|
| [305] | 373 | TRACE("binding with parent %s", Z_STRVAL_P(parent_name)); |
|---|
| [212] | 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 | |
|---|
| [305] | 388 | TRACE("%s %p", Z_STRVAL(fetch_class_opline->op2.u.constant), Z_STRVAL(fetch_class_opline->op2.u.constant)); |
|---|
| [212] | 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 | } |
|---|
| [214] | 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 |
|---|
| [226] | 411 | case ZEND_DECLARE_FUNCTION_OR_CLASS: |
|---|
| [214] | 412 | if (do_bind_function_or_class(opline, NULL, class_table, 1) == FAILURE) { |
|---|
| 413 | return FAILURE; |
|---|
| 414 | } |
|---|
| [212] | 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 | |
|---|
| [95] | 435 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| [506] | 436 | void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| [95] | 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; |
|---|
| [103] | 443 | #ifdef IS_UNICODE |
|---|
| 444 | zend_error(E_NOTICE, "Constant %R already defined", type, key); |
|---|
| 445 | #else |
|---|
| [95] | 446 | zend_error(E_NOTICE, "Constant %s already defined", key); |
|---|
| [103] | 447 | #endif |
|---|
| 448 | free(ZSTR_V(constant->name)); |
|---|
| [95] | 449 | if (!(constant->flags & CONST_PERSISTENT)) { |
|---|
| 450 | zval_dtor(&constant->value); |
|---|
| 451 | } |
|---|
| 452 | } |
|---|
| 453 | } |
|---|
| 454 | /* }}} */ |
|---|
| 455 | #endif |
|---|
| [506] | 456 | void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| [1] | 457 | { |
|---|
| [103] | 458 | zend_bool istmpkey; |
|---|
| 459 | |
|---|
| [1] | 460 | if (func->type == ZEND_USER_FUNCTION) { |
|---|
| [103] | 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) { |
|---|
| [88] | 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, |
|---|
| [1] | 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); |
|---|
| [103] | 477 | #ifdef IS_UNICODE |
|---|
| 478 | zend_error(E_ERROR, "Cannot redeclare %R()", type, key); |
|---|
| 479 | #else |
|---|
| [1] | 480 | zend_error(E_ERROR, "Cannot redeclare %s()", key); |
|---|
| [103] | 481 | #endif |
|---|
| [1] | 482 | } |
|---|
| 483 | } |
|---|
| 484 | } |
|---|
| 485 | /* }}} */ |
|---|
| [506] | 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) /* {{{ */ |
|---|
| [1] | 487 | { |
|---|
| [103] | 488 | zend_bool istmpkey; |
|---|
| [11] | 489 | zend_class_entry *cep = CestToCePtr(*cest); |
|---|
| [19] | 490 | ZESW(void *stored_ce_ptr, NOTHING); |
|---|
| [1] | 491 | |
|---|
| [103] | 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) { |
|---|
| [506] | 498 | zend_u_hash_quick_update(CG(class_table), type, key, len, h, |
|---|
| [88] | 499 | cest, sizeof(xc_cest_t), |
|---|
| 500 | ZESW(&stored_ce_ptr, NULL) |
|---|
| 501 | ); |
|---|
| [548] | 502 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| [212] | 503 | if (oplineno != -1) { |
|---|
| 504 | xc_do_early_binding(CG(active_op_array), CG(class_table), oplineno TSRMLS_CC); |
|---|
| 505 | } |
|---|
| [548] | 506 | #endif |
|---|
| [88] | 507 | } |
|---|
| [506] | 508 | else if (zend_u_hash_quick_add(CG(class_table), type, key, len, h, |
|---|
| [1] | 509 | cest, sizeof(xc_cest_t), |
|---|
| 510 | ZESW(&stored_ce_ptr, NULL) |
|---|
| 511 | ) == FAILURE) { |
|---|
| 512 | CG(zend_lineno) = ZESW(0, cep->line_start); |
|---|
| [103] | 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 |
|---|
| [212] | 518 | assert(oplineno == -1); |
|---|
| [1] | 519 | } |
|---|
| [19] | 520 | ZESW(return (xc_cest_t *) stored_ce_ptr, NOTHING); |
|---|
| [1] | 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 | /* }}} */ |
|---|
| [496] | 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); |
|---|
| [500] | 539 | if (type != E_STRICT) { |
|---|
| 540 | /* give up, and user handler is not supported in this case */ |
|---|
| 541 | int 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 | |
|---|
| [496] | 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; |
|---|
| [545] | 569 | compilererror->error_len = vspprintf(&compilererror->error, 0, format, args); |
|---|
| [496] | 570 | } |
|---|
| 571 | /* }}} */ |
|---|
| 572 | #endif |
|---|
| [268] | 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 |
|---|
| [345] | 596 | |
|---|
| [1] | 597 | xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */ |
|---|
| 598 | { |
|---|
| [269] | 599 | HashTable *h; |
|---|
| [344] | 600 | |
|---|
| [1] | 601 | if (sandbox) { |
|---|
| 602 | memset(sandbox, 0, sizeof(sandbox[0])); |
|---|
| 603 | } |
|---|
| 604 | else { |
|---|
| 605 | ECALLOC_ONE(sandbox); |
|---|
| 606 | sandbox->alloc = 1; |
|---|
| 607 | } |
|---|
| [95] | 608 | |
|---|
| [1] | 609 | memcpy(&OG(included_files), &EG(included_files), sizeof(EG(included_files))); |
|---|
| 610 | |
|---|
| [95] | 611 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 612 | OG(zend_constants) = EG(zend_constants); |
|---|
| 613 | EG(zend_constants) = &TG(zend_constants); |
|---|
| 614 | #endif |
|---|
| 615 | |
|---|
| [1] | 616 | OG(function_table) = CG(function_table); |
|---|
| 617 | CG(function_table) = &TG(function_table); |
|---|
| 618 | |
|---|
| 619 | OG(class_table) = CG(class_table); |
|---|
| 620 | CG(class_table) = &TG(class_table); |
|---|
| 621 | EG(class_table) = CG(class_table); |
|---|
| 622 | |
|---|
| [268] | 623 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 624 | OG(auto_globals) = CG(auto_globals); |
|---|
| 625 | CG(auto_globals) = &TG(auto_globals); |
|---|
| 626 | #endif |
|---|
| 627 | |
|---|
| [1] | 628 | TG(included_files) = &EG(included_files); |
|---|
| 629 | |
|---|
| 630 | zend_hash_init_ex(TG(included_files), 5, NULL, NULL, 0, 1); |
|---|
| [95] | 631 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| [269] | 632 | h = OG(zend_constants); |
|---|
| 633 | zend_hash_init_ex(&TG(zend_constants), 20, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| [95] | 634 | #endif |
|---|
| [270] | 635 | h = OG(function_table); |
|---|
| [269] | 636 | zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| [346] | 637 | { |
|---|
| 638 | zend_function tmp_func; |
|---|
| [504] | 639 | zend_hash_copy(&TG(function_table), &XG(internal_function_table), NULL, (void *) &tmp_func, sizeof(tmp_func)); |
|---|
| [346] | 640 | } |
|---|
| [434] | 641 | TG(internal_function_tail) = TG(function_table).pListTail; |
|---|
| [344] | 642 | |
|---|
| [270] | 643 | h = OG(class_table); |
|---|
| [269] | 644 | zend_hash_init_ex(&TG(class_table), 16, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| [346] | 645 | #if 0 && TODO |
|---|
| 646 | { |
|---|
| 647 | xc_cest_t tmp_cest; |
|---|
| [504] | 648 | zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &tmp_cest, sizeof(tmp_cest)); |
|---|
| [346] | 649 | } |
|---|
| 650 | #endif |
|---|
| [344] | 651 | TG(internal_class_tail) = TG(class_table).pListTail; |
|---|
| 652 | |
|---|
| [268] | 653 | #ifdef ZEND_ENGINE_2_1 |
|---|
| [269] | 654 | /* shallow copy, don't destruct */ |
|---|
| [270] | 655 | h = OG(auto_globals); |
|---|
| [269] | 656 | zend_hash_init_ex(&TG(auto_globals), 8, NULL, NULL, h->persistent, h->bApplyProtection); |
|---|
| [268] | 657 | { |
|---|
| 658 | zend_auto_global tmp_autoglobal; |
|---|
| [1] | 659 | |
|---|
| [268] | 660 | zend_hash_copy(&TG(auto_globals), OG(auto_globals), NULL, (void *) &tmp_autoglobal, sizeof(tmp_autoglobal)); |
|---|
| 661 | zend_hash_apply(&TG(auto_globals), (apply_func_t) xc_auto_global_arm TSRMLS_CC); |
|---|
| 662 | } |
|---|
| 663 | #endif |
|---|
| 664 | |
|---|
| [1] | 665 | sandbox->filename = filename; |
|---|
| 666 | |
|---|
| [209] | 667 | #ifdef E_STRICT |
|---|
| 668 | sandbox->orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting); |
|---|
| [496] | 669 | EG(user_error_handler_error_reporting) = 0; |
|---|
| 670 | |
|---|
| 671 | sandbox->compilererror_cnt = 0; |
|---|
| 672 | sandbox->compilererror_size = 0; |
|---|
| 673 | sandbox->orig_zend_error_cb = zend_error_cb; |
|---|
| 674 | zend_error_cb = xc_sandbox_error_cb; |
|---|
| [209] | 675 | #endif |
|---|
| 676 | |
|---|
| [548] | 677 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 678 | sandbox->orig_compiler_options = CG(compiler_options); |
|---|
| 679 | /* Using ZEND_COMPILE_IGNORE_INTERNAL_CLASSES for ZEND_FETCH_CLASS_RT_NS_CHECK |
|---|
| 680 | */ |
|---|
| 681 | CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES | ZEND_COMPILE_DELAYED_BINDING; |
|---|
| 682 | #endif |
|---|
| 683 | |
|---|
| [496] | 684 | XG(sandbox) = (void *) sandbox; |
|---|
| [1] | 685 | return sandbox; |
|---|
| 686 | } |
|---|
| 687 | /* }}} */ |
|---|
| [212] | 688 | static void xc_early_binding_cb(zend_op *opline, int oplineno, void *data TSRMLS_DC) /* {{{ */ |
|---|
| 689 | { |
|---|
| 690 | xc_sandbox_t *sandbox = (xc_sandbox_t *) data; |
|---|
| 691 | xc_do_early_binding(CG(active_op_array), OG(class_table), oplineno TSRMLS_CC); |
|---|
| 692 | } |
|---|
| 693 | /* }}} */ |
|---|
| [405] | 694 | static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */ |
|---|
| [1] | 695 | { |
|---|
| 696 | int i; |
|---|
| 697 | Bucket *b; |
|---|
| 698 | |
|---|
| [95] | 699 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 700 | b = TG(zend_constants).pListHead; |
|---|
| 701 | /* install constants */ |
|---|
| 702 | while (b != NULL) { |
|---|
| 703 | zend_constant *c = (zend_constant*) b->pData; |
|---|
| 704 | xc_install_constant(sandbox->filename, c, |
|---|
| [506] | 705 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| [95] | 706 | b = b->pListNext; |
|---|
| 707 | } |
|---|
| 708 | #endif |
|---|
| 709 | |
|---|
| [344] | 710 | b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead; |
|---|
| [1] | 711 | /* install function */ |
|---|
| 712 | while (b != NULL) { |
|---|
| 713 | zend_function *func = (zend_function*) b->pData; |
|---|
| 714 | xc_install_function(sandbox->filename, func, |
|---|
| [506] | 715 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| [1] | 716 | b = b->pListNext; |
|---|
| 717 | } |
|---|
| 718 | |
|---|
| [344] | 719 | b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead; |
|---|
| [1] | 720 | /* install class */ |
|---|
| 721 | while (b != NULL) { |
|---|
| [212] | 722 | xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1, |
|---|
| [506] | 723 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| [1] | 724 | b = b->pListNext; |
|---|
| 725 | } |
|---|
| [268] | 726 | |
|---|
| 727 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 728 | /* trigger auto_globals jit */ |
|---|
| 729 | for (b = TG(auto_globals).pListHead; b != NULL; b = b->pListNext) { |
|---|
| 730 | zend_auto_global *auto_global = (zend_auto_global *) b->pData; |
|---|
| 731 | /* check if actived */ |
|---|
| 732 | if (auto_global->auto_global_callback && !auto_global->armed) { |
|---|
| 733 | zend_u_is_auto_global(BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), auto_global->name_len TSRMLS_CC); |
|---|
| 734 | } |
|---|
| 735 | } |
|---|
| 736 | #endif |
|---|
| 737 | |
|---|
| [405] | 738 | if (install != XC_InstallNoBinding) { |
|---|
| [548] | 739 | #ifdef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 740 | zend_do_delayed_early_binding(CG(active_op_array) TSRMLS_CC); |
|---|
| 741 | #else |
|---|
| [405] | 742 | xc_undo_pass_two(CG(active_op_array) TSRMLS_CC); |
|---|
| 743 | xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC); |
|---|
| 744 | xc_redo_pass_two(CG(active_op_array) TSRMLS_CC); |
|---|
| [548] | 745 | #endif |
|---|
| [405] | 746 | } |
|---|
| [1] | 747 | |
|---|
| [496] | 748 | #ifdef E_STRICT |
|---|
| 749 | /* restore trigger errors */ |
|---|
| 750 | for (i = 0; i < sandbox->compilererror_cnt; i ++) { |
|---|
| 751 | xc_compilererror_t *error = &sandbox->compilererrors[i]; |
|---|
| 752 | CG(zend_lineno) = error->lineno; |
|---|
| [500] | 753 | zend_error(E_STRICT, "%s", error->error); |
|---|
| [496] | 754 | } |
|---|
| 755 | CG(zend_lineno) = 0; |
|---|
| 756 | #endif |
|---|
| 757 | |
|---|
| [1] | 758 | i = 1; |
|---|
| 759 | zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL); |
|---|
| 760 | } |
|---|
| 761 | /* }}} */ |
|---|
| [405] | 762 | void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */ |
|---|
| [1] | 763 | { |
|---|
| [496] | 764 | XG(sandbox) = NULL; |
|---|
| 765 | #ifdef E_STRICT |
|---|
| 766 | EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting; |
|---|
| 767 | zend_error_cb = sandbox->orig_zend_error_cb; |
|---|
| 768 | #endif |
|---|
| 769 | |
|---|
| [1] | 770 | /* restore first first install function/class */ |
|---|
| [95] | 771 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 772 | EG(zend_constants) = OG(zend_constants); |
|---|
| 773 | #endif |
|---|
| [1] | 774 | CG(function_table) = OG(function_table); |
|---|
| 775 | CG(class_table) = OG(class_table); |
|---|
| 776 | EG(class_table) = CG(class_table); |
|---|
| [268] | 777 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 778 | CG(auto_globals) = OG(auto_globals); |
|---|
| 779 | #endif |
|---|
| [1] | 780 | |
|---|
| [405] | 781 | if (install != XC_NoInstall) { |
|---|
| [235] | 782 | CG(in_compilation) = 1; |
|---|
| 783 | CG(compiled_filename) = sandbox->filename; |
|---|
| 784 | CG(zend_lineno) = 0; |
|---|
| [405] | 785 | xc_sandbox_install(sandbox, install TSRMLS_CC); |
|---|
| [235] | 786 | CG(in_compilation) = 0; |
|---|
| 787 | CG(compiled_filename) = NULL; |
|---|
| [1] | 788 | |
|---|
| 789 | /* no free as it's installed */ |
|---|
| [95] | 790 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 791 | TG(zend_constants).pDestructor = NULL; |
|---|
| 792 | #endif |
|---|
| [1] | 793 | TG(function_table).pDestructor = NULL; |
|---|
| 794 | TG(class_table).pDestructor = NULL; |
|---|
| 795 | } |
|---|
| 796 | |
|---|
| 797 | /* destroy all the tmp */ |
|---|
| [95] | 798 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 799 | zend_hash_destroy(&TG(zend_constants)); |
|---|
| 800 | #endif |
|---|
| [1] | 801 | zend_hash_destroy(&TG(function_table)); |
|---|
| 802 | zend_hash_destroy(&TG(class_table)); |
|---|
| [268] | 803 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 804 | zend_hash_destroy(&TG(auto_globals)); |
|---|
| 805 | #endif |
|---|
| [1] | 806 | zend_hash_destroy(TG(included_files)); |
|---|
| 807 | |
|---|
| 808 | /* restore orig here, as EG/CG holded tmp before */ |
|---|
| 809 | memcpy(&EG(included_files), &OG(included_files), sizeof(EG(included_files))); |
|---|
| 810 | |
|---|
| [508] | 811 | #ifdef E_STRICT |
|---|
| [496] | 812 | if (sandbox->compilererrors) { |
|---|
| 813 | int i; |
|---|
| 814 | for (i = 0; i < sandbox->compilererror_cnt; i ++) { |
|---|
| 815 | efree(sandbox->compilererrors[i].error); |
|---|
| 816 | } |
|---|
| 817 | efree(sandbox->compilererrors); |
|---|
| 818 | } |
|---|
| [508] | 819 | #endif |
|---|
| [548] | 820 | |
|---|
| 821 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 822 | CG(compiler_options) = sandbox->orig_compiler_options; |
|---|
| 823 | #endif |
|---|
| 824 | |
|---|
| [1] | 825 | if (sandbox->alloc) { |
|---|
| 826 | efree(sandbox); |
|---|
| 827 | } |
|---|
| 828 | } |
|---|
| 829 | /* }}} */ |
|---|
| [305] | 830 | int xc_vtrace(const char *fmt, va_list args) /* {{{ */ |
|---|
| 831 | { |
|---|
| [349] | 832 | return vfprintf(stderr, fmt, args); |
|---|
| [305] | 833 | } |
|---|
| 834 | /* }}} */ |
|---|
| 835 | int xc_trace(const char *fmt, ...) /* {{{ */ |
|---|
| 836 | { |
|---|
| 837 | va_list args; |
|---|
| [349] | 838 | int ret; |
|---|
| [305] | 839 | |
|---|
| 840 | va_start(args, fmt); |
|---|
| [349] | 841 | ret = xc_vtrace(fmt, args); |
|---|
| [305] | 842 | va_end(args); |
|---|
| [349] | 843 | return ret; |
|---|
| [305] | 844 | } |
|---|
| 845 | /* }}} */ |
|---|