| 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(Z_OP_CONSTANT(op)); \ |
|---|
| 23 | zval_dtor(&Z_OP_CONSTANT(op)); \ |
|---|
| 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 | #ifndef ZEND_ENGINE_2_4 |
|---|
| 138 | if (!op_array->done_pass_two) { |
|---|
| 139 | return 0; |
|---|
| 140 | } |
|---|
| 141 | #endif |
|---|
| 142 | |
|---|
| 143 | opline = op_array->opcodes; |
|---|
| 144 | end = opline + op_array->last; |
|---|
| 145 | while (opline < end) { |
|---|
| 146 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 147 | switch (opline->opcode) { |
|---|
| 148 | #ifdef ZEND_GOTO |
|---|
| 149 | case ZEND_GOTO: |
|---|
| 150 | #endif |
|---|
| 151 | case ZEND_JMP: |
|---|
| 152 | assert(Z_OP(opline->op1).jmp_addr >= op_array->opcodes && Z_OP(opline->op1).jmp_addr - op_array->opcodes < op_array->last); |
|---|
| 153 | Z_OP(opline->op1).opline_num = Z_OP(opline->op1).jmp_addr - op_array->opcodes; |
|---|
| 154 | break; |
|---|
| 155 | case ZEND_JMPZ: |
|---|
| 156 | case ZEND_JMPNZ: |
|---|
| 157 | case ZEND_JMPZ_EX: |
|---|
| 158 | case ZEND_JMPNZ_EX: |
|---|
| 159 | #ifdef ZEND_JMP_SET |
|---|
| 160 | case ZEND_JMP_SET: |
|---|
| 161 | #endif |
|---|
| 162 | assert(Z_OP(opline->op2).jmp_addr >= op_array->opcodes && Z_OP(opline->op2).jmp_addr - op_array->opcodes < op_array->last); |
|---|
| 163 | Z_OP(opline->op2).opline_num = Z_OP(opline->op2).jmp_addr - op_array->opcodes; |
|---|
| 164 | break; |
|---|
| 165 | } |
|---|
| 166 | #endif |
|---|
| 167 | opline++; |
|---|
| 168 | } |
|---|
| 169 | #ifndef ZEND_ENGINE_2_4 |
|---|
| 170 | op_array->done_pass_two = 0; |
|---|
| 171 | #endif |
|---|
| 172 | |
|---|
| 173 | return 0; |
|---|
| 174 | } |
|---|
| 175 | /* }}} */ |
|---|
| 176 | int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 177 | { |
|---|
| 178 | zend_op *opline, *end; |
|---|
| 179 | |
|---|
| 180 | #ifndef ZEND_ENGINE_2_4 |
|---|
| 181 | if (op_array->done_pass_two) { |
|---|
| 182 | return 0; |
|---|
| 183 | } |
|---|
| 184 | #endif |
|---|
| 185 | |
|---|
| 186 | /* |
|---|
| 187 | op_array->opcodes = (zend_op *) erealloc(op_array->opcodes, sizeof(zend_op)*op_array->last); |
|---|
| 188 | op_array->size = op_array->last; |
|---|
| 189 | */ |
|---|
| 190 | |
|---|
| 191 | opline = op_array->opcodes; |
|---|
| 192 | end = opline + op_array->last; |
|---|
| 193 | while (opline < end) { |
|---|
| 194 | if (Z_OP_TYPE(opline->op1) == IS_CONST) { |
|---|
| 195 | Z_SET_ISREF(Z_OP_CONSTANT(opline->op1)); |
|---|
| 196 | Z_SET_REFCOUNT(Z_OP_CONSTANT(opline->op1), 2); /* Make sure is_ref won't be reset */ |
|---|
| 197 | |
|---|
| 198 | } |
|---|
| 199 | if (Z_OP_TYPE(opline->op2) == IS_CONST) { |
|---|
| 200 | Z_SET_ISREF(Z_OP_CONSTANT(opline->op2)); |
|---|
| 201 | Z_SET_REFCOUNT(Z_OP_CONSTANT(opline->op2), 2); |
|---|
| 202 | } |
|---|
| 203 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 204 | switch (opline->opcode) { |
|---|
| 205 | #ifdef ZEND_GOTO |
|---|
| 206 | case ZEND_GOTO: |
|---|
| 207 | #endif |
|---|
| 208 | case ZEND_JMP: |
|---|
| 209 | assert(Z_OP(opline->op1).opline_num < op_array->last); |
|---|
| 210 | Z_OP(opline->op1).jmp_addr = op_array->opcodes + Z_OP(opline->op1).opline_num; |
|---|
| 211 | break; |
|---|
| 212 | case ZEND_JMPZ: |
|---|
| 213 | case ZEND_JMPNZ: |
|---|
| 214 | case ZEND_JMPZ_EX: |
|---|
| 215 | case ZEND_JMPNZ_EX: |
|---|
| 216 | #ifdef ZEND_JMP_SET |
|---|
| 217 | case ZEND_JMP_SET: |
|---|
| 218 | #endif |
|---|
| 219 | assert(Z_OP(opline->op2).opline_num < op_array->last); |
|---|
| 220 | Z_OP(opline->op2).jmp_addr = op_array->opcodes + Z_OP(opline->op2).opline_num; |
|---|
| 221 | break; |
|---|
| 222 | } |
|---|
| 223 | ZEND_VM_SET_OPCODE_HANDLER(opline); |
|---|
| 224 | #endif |
|---|
| 225 | opline++; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | #ifndef ZEND_ENGINE_2_4 |
|---|
| 229 | op_array->done_pass_two = 1; |
|---|
| 230 | #endif |
|---|
| 231 | return 0; |
|---|
| 232 | } |
|---|
| 233 | /* }}} */ |
|---|
| 234 | |
|---|
| 235 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
|---|
| 236 | static void xc_fix_opcode_ex_znode(int tofix, xc_op_spec_t spec, Z_OP_TYPEOF_TYPE *op_type, znode_op *op, int type TSRMLS_DC) /* {{{ */ |
|---|
| 237 | { |
|---|
| 238 | #ifdef ZEND_ENGINE_2 |
|---|
| 239 | if ((*op_type != IS_UNUSED && (spec == OPSPEC_UCLASS || spec == OPSPEC_CLASS)) || |
|---|
| 240 | spec == OPSPEC_FETCH) { |
|---|
| 241 | if (tofix) { |
|---|
| 242 | switch (*op_type) { |
|---|
| 243 | case IS_VAR: |
|---|
| 244 | case IS_TMP_VAR: |
|---|
| 245 | break; |
|---|
| 246 | |
|---|
| 247 | default: |
|---|
| 248 | /* TODO: data lost, find a way to keep it */ |
|---|
| 249 | /* assert(*op_type == IS_CONST); */ |
|---|
| 250 | *op_type = IS_TMP_VAR; |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | switch (*op_type) { |
|---|
| 255 | case IS_TMP_VAR: |
|---|
| 256 | case IS_VAR: |
|---|
| 257 | if (tofix) { |
|---|
| 258 | Z_OP(*op).var /= sizeof(temp_variable); |
|---|
| 259 | } |
|---|
| 260 | else { |
|---|
| 261 | Z_OP(*op).var *= sizeof(temp_variable); |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | #endif |
|---|
| 265 | } |
|---|
| 266 | /* }}} */ |
|---|
| 267 | |
|---|
| 268 | static void xc_fix_opcode_ex(zend_op_array *op_array, int tofix TSRMLS_DC) /* {{{ */ |
|---|
| 269 | { |
|---|
| 270 | zend_op *opline; |
|---|
| 271 | zend_uint i; |
|---|
| 272 | |
|---|
| 273 | opline = op_array->opcodes; |
|---|
| 274 | for (i = 0; i < op_array->last; i ++, opline ++) { |
|---|
| 275 | /* 3rd optimizer may have ... */ |
|---|
| 276 | if (opline->opcode < xc_get_opcode_spec_count()) { |
|---|
| 277 | const xc_opcode_spec_t *spec; |
|---|
| 278 | spec = xc_get_opcode_spec(opline->opcode); |
|---|
| 279 | |
|---|
| 280 | xc_fix_opcode_ex_znode(tofix, spec->op1, &Z_OP_TYPE(opline->op1), &opline->op1, 0 TSRMLS_CC); |
|---|
| 281 | xc_fix_opcode_ex_znode(tofix, spec->op2, &Z_OP_TYPE(opline->op2), &opline->op2, 1 TSRMLS_CC); |
|---|
| 282 | xc_fix_opcode_ex_znode(tofix, spec->res, &Z_OP_TYPE(opline->result), &opline->result, 2 TSRMLS_CC); |
|---|
| 283 | } |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | /* }}} */ |
|---|
| 287 | int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 288 | { |
|---|
| 289 | xc_fix_opcode_ex(op_array, 1 TSRMLS_CC); |
|---|
| 290 | return 0; |
|---|
| 291 | } |
|---|
| 292 | /* }}} */ |
|---|
| 293 | int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 294 | { |
|---|
| 295 | xc_fix_opcode_ex(op_array, 0 TSRMLS_CC); |
|---|
| 296 | |
|---|
| 297 | return 0; |
|---|
| 298 | } |
|---|
| 299 | /* }}} */ |
|---|
| 300 | #endif |
|---|
| 301 | |
|---|
| 302 | 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) /* {{{ */ |
|---|
| 303 | { |
|---|
| 304 | zend_op *opline, *begin, *end, *next = NULL; |
|---|
| 305 | |
|---|
| 306 | opline = begin = op_array->opcodes; |
|---|
| 307 | end = opline + op_array->last; |
|---|
| 308 | while (opline < end) { |
|---|
| 309 | switch (opline->opcode) { |
|---|
| 310 | #ifdef ZEND_GOTO |
|---|
| 311 | case ZEND_GOTO: |
|---|
| 312 | #endif |
|---|
| 313 | case ZEND_JMP: |
|---|
| 314 | next = begin + Z_OP(opline->op1).opline_num; |
|---|
| 315 | break; |
|---|
| 316 | |
|---|
| 317 | case ZEND_JMPZNZ: |
|---|
| 318 | next = begin + max(Z_OP(opline->op2).opline_num, opline->extended_value); |
|---|
| 319 | break; |
|---|
| 320 | |
|---|
| 321 | case ZEND_JMPZ: |
|---|
| 322 | case ZEND_JMPNZ: |
|---|
| 323 | case ZEND_JMPZ_EX: |
|---|
| 324 | case ZEND_JMPNZ_EX: |
|---|
| 325 | #ifdef ZEND_JMP_SET |
|---|
| 326 | case ZEND_JMP_SET: |
|---|
| 327 | #endif |
|---|
| 328 | next = begin + Z_OP(opline->op2).opline_num; |
|---|
| 329 | break; |
|---|
| 330 | |
|---|
| 331 | case ZEND_RETURN: |
|---|
| 332 | opline = end; |
|---|
| 333 | break; |
|---|
| 334 | |
|---|
| 335 | #ifdef ZEND_ENGINE_2 |
|---|
| 336 | case ZEND_DECLARE_INHERITED_CLASS: |
|---|
| 337 | callback(opline, opline - begin, data TSRMLS_CC); |
|---|
| 338 | break; |
|---|
| 339 | #else |
|---|
| 340 | case ZEND_DECLARE_FUNCTION_OR_CLASS: |
|---|
| 341 | if (opline->extended_value == ZEND_DECLARE_INHERITED_CLASS) { |
|---|
| 342 | callback(opline, opline - begin, data TSRMLS_CC); |
|---|
| 343 | } |
|---|
| 344 | break; |
|---|
| 345 | #endif |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | if (opline < next) { |
|---|
| 349 | opline = next; |
|---|
| 350 | } |
|---|
| 351 | else { |
|---|
| 352 | opline ++; |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | return SUCCESS; |
|---|
| 356 | } |
|---|
| 357 | /* }}} */ |
|---|
| 358 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 359 | static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, int oplineno TSRMLS_DC) /* {{{ */ |
|---|
| 360 | { |
|---|
| 361 | zend_op *opline; |
|---|
| 362 | |
|---|
| 363 | TRACE("binding %d", oplineno); |
|---|
| 364 | assert(oplineno >= 0); |
|---|
| 365 | |
|---|
| 366 | /* do early binding */ |
|---|
| 367 | opline = &(op_array->opcodes[oplineno]); |
|---|
| 368 | |
|---|
| 369 | switch (opline->opcode) { |
|---|
| 370 | #ifdef ZEND_ENGINE_2 |
|---|
| 371 | case ZEND_DECLARE_INHERITED_CLASS: |
|---|
| 372 | { |
|---|
| 373 | zval *parent_name; |
|---|
| 374 | zend_class_entry **pce; |
|---|
| 375 | |
|---|
| 376 | /* don't early-bind classes that implement interfaces */ |
|---|
| 377 | if ((opline + 1)->opcode == ZEND_FETCH_CLASS && (opline + 2)->opcode == ZEND_ADD_INTERFACE) { |
|---|
| 378 | return FAILURE; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | parent_name = &(Z_OP_CONSTANT((opline - 1)->op2)); |
|---|
| 382 | TRACE("binding with parent %s", Z_STRVAL_P(parent_name)); |
|---|
| 383 | if (zend_lookup_class(Z_STRVAL_P(parent_name), Z_STRLEN_P(parent_name), &pce TSRMLS_CC) == FAILURE) { |
|---|
| 384 | return FAILURE; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | if (do_bind_inherited_class(opline, class_table, *pce, 1 TSRMLS_CC) == NULL) { |
|---|
| 388 | return FAILURE; |
|---|
| 389 | } |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | /* clear unnecessary ZEND_FETCH_CLASS opcode */ |
|---|
| 393 | if (opline > op_array->opcodes |
|---|
| 394 | && (opline - 1)->opcode == ZEND_FETCH_CLASS) { |
|---|
| 395 | zend_op *fetch_class_opline = opline - 1; |
|---|
| 396 | |
|---|
| 397 | TRACE("%s %p", Z_STRVAL(Z_OP_CONSTANT(fetch_class_opline->op2)), Z_STRVAL(Z_OP_CONSTANT(fetch_class_opline->op2))); |
|---|
| 398 | OP_ZVAL_DTOR(fetch_class_opline->op2); |
|---|
| 399 | fetch_class_opline->opcode = ZEND_NOP; |
|---|
| 400 | ZEND_VM_SET_OPCODE_HANDLER(fetch_class_opline); |
|---|
| 401 | memset(&fetch_class_opline->op1, 0, sizeof(znode)); |
|---|
| 402 | memset(&fetch_class_opline->op2, 0, sizeof(znode)); |
|---|
| 403 | SET_UNUSED(fetch_class_opline->op1); |
|---|
| 404 | SET_UNUSED(fetch_class_opline->op2); |
|---|
| 405 | SET_UNUSED(fetch_class_opline->result); |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | /* clear unnecessary ZEND_VERIFY_ABSTRACT_CLASS opcode */ |
|---|
| 409 | if ((opline + 1)->opcode == ZEND_VERIFY_ABSTRACT_CLASS) { |
|---|
| 410 | zend_op *abstract_op = opline + 1; |
|---|
| 411 | memset(abstract_op, 0, sizeof(abstract_op[0])); |
|---|
| 412 | abstract_op->lineno = 0; |
|---|
| 413 | SET_UNUSED(abstract_op->op1); |
|---|
| 414 | SET_UNUSED(abstract_op->op2); |
|---|
| 415 | SET_UNUSED(abstract_op->result); |
|---|
| 416 | abstract_op->opcode = ZEND_NOP; |
|---|
| 417 | ZEND_VM_SET_OPCODE_HANDLER(abstract_op); |
|---|
| 418 | } |
|---|
| 419 | #else |
|---|
| 420 | case ZEND_DECLARE_FUNCTION_OR_CLASS: |
|---|
| 421 | if (do_bind_function_or_class(opline, NULL, class_table, 1) == FAILURE) { |
|---|
| 422 | return FAILURE; |
|---|
| 423 | } |
|---|
| 424 | #endif |
|---|
| 425 | break; |
|---|
| 426 | |
|---|
| 427 | default: |
|---|
| 428 | return FAILURE; |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | zend_hash_del(class_table, Z_OP_CONSTANT(opline->op1).value.str.val, Z_OP_CONSTANT(opline->op1).value.str.len); |
|---|
| 432 | OP_ZVAL_DTOR(opline->op1); |
|---|
| 433 | OP_ZVAL_DTOR(opline->op2); |
|---|
| 434 | opline->opcode = ZEND_NOP; |
|---|
| 435 | ZEND_VM_SET_OPCODE_HANDLER(opline); |
|---|
| 436 | memset(&opline->op1, 0, sizeof(znode)); |
|---|
| 437 | memset(&opline->op2, 0, sizeof(znode)); |
|---|
| 438 | SET_UNUSED(opline->op1); |
|---|
| 439 | SET_UNUSED(opline->op2); |
|---|
| 440 | return SUCCESS; |
|---|
| 441 | } |
|---|
| 442 | /* }}} */ |
|---|
| 443 | #endif |
|---|
| 444 | |
|---|
| 445 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 446 | void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| 447 | { |
|---|
| 448 | if (zend_u_hash_add(EG(zend_constants), type, key, len, |
|---|
| 449 | constant, sizeof(zend_constant), |
|---|
| 450 | NULL |
|---|
| 451 | ) == FAILURE) { |
|---|
| 452 | CG(zend_lineno) = 0; |
|---|
| 453 | #ifdef IS_UNICODE |
|---|
| 454 | zend_error(E_NOTICE, "Constant %R already defined", type, key); |
|---|
| 455 | #else |
|---|
| 456 | zend_error(E_NOTICE, "Constant %s already defined", key); |
|---|
| 457 | #endif |
|---|
| 458 | free(ZSTR_V(constant->name)); |
|---|
| 459 | if (!(constant->flags & CONST_PERSISTENT)) { |
|---|
| 460 | zval_dtor(&constant->value); |
|---|
| 461 | } |
|---|
| 462 | } |
|---|
| 463 | } |
|---|
| 464 | /* }}} */ |
|---|
| 465 | #endif |
|---|
| 466 | void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ |
|---|
| 467 | { |
|---|
| 468 | zend_bool istmpkey; |
|---|
| 469 | |
|---|
| 470 | if (func->type == ZEND_USER_FUNCTION) { |
|---|
| 471 | #ifdef IS_UNICODE |
|---|
| 472 | istmpkey = (type == IS_STRING && ZSTR_S(key)[0] == 0) || ZSTR_U(key)[0] == 0; |
|---|
| 473 | #else |
|---|
| 474 | istmpkey = ZSTR_S(key)[0] == 0; |
|---|
| 475 | #endif |
|---|
| 476 | if (istmpkey) { |
|---|
| 477 | zend_u_hash_update(CG(function_table), type, key, len, |
|---|
| 478 | func, sizeof(zend_op_array), |
|---|
| 479 | NULL |
|---|
| 480 | ); |
|---|
| 481 | } |
|---|
| 482 | else if (zend_u_hash_add(CG(function_table), type, key, len, |
|---|
| 483 | func, sizeof(zend_op_array), |
|---|
| 484 | NULL |
|---|
| 485 | ) == FAILURE) { |
|---|
| 486 | CG(zend_lineno) = ZESW(func->op_array.opcodes[0].lineno, func->op_array.line_start); |
|---|
| 487 | #ifdef IS_UNICODE |
|---|
| 488 | zend_error(E_ERROR, "Cannot redeclare %R()", type, key); |
|---|
| 489 | #else |
|---|
| 490 | zend_error(E_ERROR, "Cannot redeclare %s()", key); |
|---|
| 491 | #endif |
|---|
| 492 | } |
|---|
| 493 | } |
|---|
| 494 | } |
|---|
| 495 | /* }}} */ |
|---|
| 496 | 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) /* {{{ */ |
|---|
| 497 | { |
|---|
| 498 | zend_bool istmpkey; |
|---|
| 499 | zend_class_entry *cep = CestToCePtr(*cest); |
|---|
| 500 | ZESW(void *stored_ce_ptr, NOTHING); |
|---|
| 501 | |
|---|
| 502 | #ifdef IS_UNICODE |
|---|
| 503 | istmpkey = (type == IS_STRING && ZSTR_S(key)[0] == 0) || ZSTR_U(key)[0] == 0; |
|---|
| 504 | #else |
|---|
| 505 | istmpkey = ZSTR_S(key)[0] == 0; |
|---|
| 506 | #endif |
|---|
| 507 | if (istmpkey) { |
|---|
| 508 | zend_u_hash_quick_update(CG(class_table), type, key, len, h, |
|---|
| 509 | cest, sizeof(xc_cest_t), |
|---|
| 510 | ZESW(&stored_ce_ptr, NULL) |
|---|
| 511 | ); |
|---|
| 512 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 513 | if (oplineno != -1) { |
|---|
| 514 | xc_do_early_binding(CG(active_op_array), CG(class_table), oplineno TSRMLS_CC); |
|---|
| 515 | } |
|---|
| 516 | #endif |
|---|
| 517 | } |
|---|
| 518 | else if (zend_u_hash_quick_add(CG(class_table), type, key, len, h, |
|---|
| 519 | cest, sizeof(xc_cest_t), |
|---|
| 520 | ZESW(&stored_ce_ptr, NULL) |
|---|
| 521 | ) == FAILURE) { |
|---|
| 522 | CG(zend_lineno) = ZESW(0, Z_CLASS_INFO(*cep).line_start); |
|---|
| 523 | #ifdef IS_UNICODE |
|---|
| 524 | zend_error(E_ERROR, "Cannot redeclare class %R", type, cep->name); |
|---|
| 525 | #else |
|---|
| 526 | zend_error(E_ERROR, "Cannot redeclare class %s", cep->name); |
|---|
| 527 | #endif |
|---|
| 528 | assert(oplineno == -1); |
|---|
| 529 | } |
|---|
| 530 | ZESW(return (xc_cest_t *) stored_ce_ptr, NOTHING); |
|---|
| 531 | } |
|---|
| 532 | /* }}} */ |
|---|
| 533 | |
|---|
| 534 | /* sandbox {{{ */ |
|---|
| 535 | #undef TG |
|---|
| 536 | #undef OG |
|---|
| 537 | #define TG(x) (sandbox->tmp_##x) |
|---|
| 538 | #define OG(x) (sandbox->orig_##x) |
|---|
| 539 | /* }}} */ |
|---|
| 540 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 541 | static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */ |
|---|
| 542 | { |
|---|
| 543 | return 0; |
|---|
| 544 | } |
|---|
| 545 | /* }}} */ |
|---|
| 546 | static int xc_auto_global_arm(zend_auto_global *auto_global TSRMLS_DC) /* {{{ */ |
|---|
| 547 | { |
|---|
| 548 | if (auto_global->auto_global_callback) { |
|---|
| 549 | auto_global->armed = 1; |
|---|
| 550 | auto_global->auto_global_callback = xc_auto_global_callback; |
|---|
| 551 | } |
|---|
| 552 | else { |
|---|
| 553 | auto_global->armed = 0; |
|---|
| 554 | } |
|---|
| 555 | return ZEND_HASH_APPLY_KEEP; |
|---|
| 556 | } |
|---|
| 557 | /* }}} */ |
|---|
| 558 | #endif |
|---|
| 559 | |
|---|
| 560 | void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker) /* {{{ */ |
|---|
| 561 | { |
|---|
| 562 | Bucket *p; |
|---|
| 563 | void *new_entry; |
|---|
| 564 | zend_bool setTargetPointer; |
|---|
| 565 | |
|---|
| 566 | setTargetPointer = !target->pInternalPointer; |
|---|
| 567 | p = source->pListHead; |
|---|
| 568 | while (p) { |
|---|
| 569 | if (checker(p->pData)) { |
|---|
| 570 | if (setTargetPointer && source->pInternalPointer == p) { |
|---|
| 571 | target->pInternalPointer = NULL; |
|---|
| 572 | } |
|---|
| 573 | if (p->nKeyLength) { |
|---|
| 574 | zend_hash_quick_update(target, p->arKey, p->nKeyLength, p->h, p->pData, size, &new_entry); |
|---|
| 575 | } else { |
|---|
| 576 | zend_hash_index_update(target, p->h, p->pData, size, &new_entry); |
|---|
| 577 | } |
|---|
| 578 | if (pCopyConstructor) { |
|---|
| 579 | pCopyConstructor(new_entry); |
|---|
| 580 | } |
|---|
| 581 | } |
|---|
| 582 | p = p->pListNext; |
|---|
| 583 | } |
|---|
| 584 | if (!target->pInternalPointer) { |
|---|
| 585 | target->pInternalPointer = target->pListHead; |
|---|
| 586 | } |
|---|
| 587 | } |
|---|
| 588 | /* }}} */ |
|---|
| 589 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 590 | static zend_bool xc_is_internal_zend_constant(zend_constant *c) /* {{{ */ |
|---|
| 591 | { |
|---|
| 592 | return (c->flags & CONST_PERSISTENT) ? 1 : 0; |
|---|
| 593 | } |
|---|
| 594 | /* }}} */ |
|---|
| 595 | void xc_zend_constant_ctor(zend_constant *c) /* {{{ */ |
|---|
| 596 | { |
|---|
| 597 | assert((c->flags & CONST_PERSISTENT)); |
|---|
| 598 | #ifdef IS_UNICODE |
|---|
| 599 | c->name.u = zend_ustrndup(c->name.u, c->name_len - 1); |
|---|
| 600 | #else |
|---|
| 601 | c->name = zend_strndup(c->name, c->name_len - 1); |
|---|
| 602 | #endif |
|---|
| 603 | } |
|---|
| 604 | /* }}} */ |
|---|
| 605 | void xc_zend_constant_dtor(zend_constant *c) /* {{{ */ |
|---|
| 606 | { |
|---|
| 607 | free(ZSTR_U(c->name)); |
|---|
| 608 | } |
|---|
| 609 | /* }}} */ |
|---|
| 610 | static void xc_free_zend_constant(zend_constant *c) /* {{{ */ |
|---|
| 611 | { |
|---|
| 612 | if (!(c->flags & CONST_PERSISTENT)) { |
|---|
| 613 | zval_dtor(&c->value); |
|---|
| 614 | } |
|---|
| 615 | free(ZSTR_V(c->name)); |
|---|
| 616 | } |
|---|
| 617 | /* }}} */ |
|---|
| 618 | void xc_copy_internal_zend_constants(HashTable *target, HashTable *source) /* {{{ */ |
|---|
| 619 | { |
|---|
| 620 | zend_constant tmp_const; |
|---|
| 621 | xc_hash_copy_if(target, source, (copy_ctor_func_t) xc_zend_constant_ctor, (void *) &tmp_const, sizeof(zend_constant), (xc_if_func_t) xc_is_internal_zend_constant); |
|---|
| 622 | } |
|---|
| 623 | /* }}} */ |
|---|
| 624 | #endif |
|---|
| 625 | xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */ |
|---|
| 626 | { |
|---|
| 627 | HashTable *h; |
|---|
| 628 | |
|---|
| 629 | if (sandbox) { |
|---|
| 630 | memset(sandbox, 0, sizeof(sandbox[0])); |
|---|
| 631 | } |
|---|
| 632 | else { |
|---|
| 633 | ECALLOC_ONE(sandbox); |
|---|
| 634 | sandbox->alloc = 1; |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | memcpy(&OG(included_files), &EG(included_files), sizeof(EG(included_files))); |
|---|
| 638 | |
|---|
| 639 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 640 | OG(zend_constants) = EG(zend_constants); |
|---|
| 641 | EG(zend_constants) = &TG(zend_constants); |
|---|
| 642 | #endif |
|---|
| 643 | |
|---|
| 644 | OG(function_table) = CG(function_table); |
|---|
| 645 | CG(function_table) = &TG(function_table); |
|---|
| 646 | |
|---|
| 647 | OG(class_table) = CG(class_table); |
|---|
| 648 | CG(class_table) = &TG(class_table); |
|---|
| 649 | EG(class_table) = CG(class_table); |
|---|
| 650 | |
|---|
| 651 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 652 | OG(auto_globals) = CG(auto_globals); |
|---|
| 653 | CG(auto_globals) = &TG(auto_globals); |
|---|
| 654 | #endif |
|---|
| 655 | |
|---|
| 656 | TG(included_files) = &EG(included_files); |
|---|
| 657 | |
|---|
| 658 | zend_hash_init_ex(TG(included_files), 5, NULL, NULL, 0, 1); |
|---|
| 659 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 660 | h = OG(zend_constants); |
|---|
| 661 | zend_hash_init_ex(&TG(zend_constants), 20, NULL, (dtor_func_t) xc_free_zend_constant, h->persistent, h->bApplyProtection); |
|---|
| 662 | xc_copy_internal_zend_constants(&TG(zend_constants), &XG(internal_constant_table)); |
|---|
| 663 | TG(internal_constant_tail) = TG(zend_constants).pListTail; |
|---|
| 664 | #endif |
|---|
| 665 | h = OG(function_table); |
|---|
| 666 | zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| 667 | { |
|---|
| 668 | zend_function tmp_func; |
|---|
| 669 | zend_hash_copy(&TG(function_table), &XG(internal_function_table), NULL, (void *) &tmp_func, sizeof(tmp_func)); |
|---|
| 670 | } |
|---|
| 671 | TG(internal_function_tail) = TG(function_table).pListTail; |
|---|
| 672 | |
|---|
| 673 | h = OG(class_table); |
|---|
| 674 | zend_hash_init_ex(&TG(class_table), 16, NULL, h->pDestructor, h->persistent, h->bApplyProtection); |
|---|
| 675 | #if 0 && TODO |
|---|
| 676 | { |
|---|
| 677 | xc_cest_t tmp_cest; |
|---|
| 678 | zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &tmp_cest, sizeof(tmp_cest)); |
|---|
| 679 | } |
|---|
| 680 | #endif |
|---|
| 681 | TG(internal_class_tail) = TG(class_table).pListTail; |
|---|
| 682 | |
|---|
| 683 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 684 | /* shallow copy, don't destruct */ |
|---|
| 685 | h = OG(auto_globals); |
|---|
| 686 | zend_hash_init_ex(&TG(auto_globals), 8, NULL, NULL, h->persistent, h->bApplyProtection); |
|---|
| 687 | { |
|---|
| 688 | zend_auto_global tmp_autoglobal; |
|---|
| 689 | |
|---|
| 690 | zend_hash_copy(&TG(auto_globals), OG(auto_globals), NULL, (void *) &tmp_autoglobal, sizeof(tmp_autoglobal)); |
|---|
| 691 | zend_hash_apply(&TG(auto_globals), (apply_func_t) xc_auto_global_arm TSRMLS_CC); |
|---|
| 692 | } |
|---|
| 693 | #endif |
|---|
| 694 | |
|---|
| 695 | sandbox->filename = filename; |
|---|
| 696 | |
|---|
| 697 | #ifdef E_STRICT |
|---|
| 698 | sandbox->orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting); |
|---|
| 699 | EG(user_error_handler_error_reporting) &= ~E_STRICT; |
|---|
| 700 | #endif |
|---|
| 701 | |
|---|
| 702 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 703 | sandbox->orig_compiler_options = CG(compiler_options); |
|---|
| 704 | /* Using ZEND_COMPILE_IGNORE_INTERNAL_CLASSES for ZEND_FETCH_CLASS_RT_NS_CHECK |
|---|
| 705 | */ |
|---|
| 706 | CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES | ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_DELAYED_BINDING; |
|---|
| 707 | #endif |
|---|
| 708 | |
|---|
| 709 | return sandbox; |
|---|
| 710 | } |
|---|
| 711 | /* }}} */ |
|---|
| 712 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 713 | static void xc_early_binding_cb(zend_op *opline, int oplineno, void *data TSRMLS_DC) /* {{{ */ |
|---|
| 714 | { |
|---|
| 715 | xc_sandbox_t *sandbox = (xc_sandbox_t *) data; |
|---|
| 716 | xc_do_early_binding(CG(active_op_array), OG(class_table), oplineno TSRMLS_CC); |
|---|
| 717 | } |
|---|
| 718 | /* }}} */ |
|---|
| 719 | #endif |
|---|
| 720 | static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */ |
|---|
| 721 | { |
|---|
| 722 | zend_uint i; |
|---|
| 723 | Bucket *b; |
|---|
| 724 | |
|---|
| 725 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 726 | for (b = TG(zend_constants).pListHead; b != NULL && b != TG(internal_constant_tail); b = b->pListNext) { |
|---|
| 727 | zend_constant *c = (zend_constant*) b->pData; |
|---|
| 728 | xc_free_zend_constant(c); |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | b = TG(internal_constant_tail) ? TG(internal_constant_tail)->pListNext : TG(zend_constants).pListHead; |
|---|
| 732 | /* install constants */ |
|---|
| 733 | while (b != NULL) { |
|---|
| 734 | zend_constant *c = (zend_constant*) b->pData; |
|---|
| 735 | xc_install_constant(sandbox->filename, c, |
|---|
| 736 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| 737 | b = b->pListNext; |
|---|
| 738 | } |
|---|
| 739 | #endif |
|---|
| 740 | |
|---|
| 741 | b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead; |
|---|
| 742 | /* install function */ |
|---|
| 743 | while (b != NULL) { |
|---|
| 744 | zend_function *func = (zend_function*) b->pData; |
|---|
| 745 | xc_install_function(sandbox->filename, func, |
|---|
| 746 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| 747 | b = b->pListNext; |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead; |
|---|
| 751 | /* install class */ |
|---|
| 752 | while (b != NULL) { |
|---|
| 753 | xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1, |
|---|
| 754 | BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h TSRMLS_CC); |
|---|
| 755 | b = b->pListNext; |
|---|
| 756 | } |
|---|
| 757 | |
|---|
| 758 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 759 | /* trigger auto_globals jit */ |
|---|
| 760 | for (b = TG(auto_globals).pListHead; b != NULL; b = b->pListNext) { |
|---|
| 761 | zend_auto_global *auto_global = (zend_auto_global *) b->pData; |
|---|
| 762 | /* check if actived */ |
|---|
| 763 | if (auto_global->auto_global_callback && !auto_global->armed) { |
|---|
| 764 | zend_u_is_auto_global(BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), auto_global->name_len TSRMLS_CC); |
|---|
| 765 | } |
|---|
| 766 | } |
|---|
| 767 | #endif |
|---|
| 768 | |
|---|
| 769 | if (install != XC_InstallNoBinding) { |
|---|
| 770 | #ifdef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 771 | zend_do_delayed_early_binding(CG(active_op_array) TSRMLS_CC); |
|---|
| 772 | #else |
|---|
| 773 | xc_undo_pass_two(CG(active_op_array) TSRMLS_CC); |
|---|
| 774 | xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC); |
|---|
| 775 | xc_redo_pass_two(CG(active_op_array) TSRMLS_CC); |
|---|
| 776 | #endif |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | i = 1; |
|---|
| 780 | zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL); |
|---|
| 781 | } |
|---|
| 782 | /* }}} */ |
|---|
| 783 | void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */ |
|---|
| 784 | { |
|---|
| 785 | /* restore first first install function/class */ |
|---|
| 786 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 787 | EG(zend_constants) = OG(zend_constants); |
|---|
| 788 | #endif |
|---|
| 789 | CG(function_table) = OG(function_table); |
|---|
| 790 | CG(class_table) = OG(class_table); |
|---|
| 791 | EG(class_table) = CG(class_table); |
|---|
| 792 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 793 | CG(auto_globals) = OG(auto_globals); |
|---|
| 794 | #endif |
|---|
| 795 | |
|---|
| 796 | if (install != XC_NoInstall) { |
|---|
| 797 | CG(in_compilation) = 1; |
|---|
| 798 | CG(compiled_filename) = sandbox->filename; |
|---|
| 799 | CG(zend_lineno) = 0; |
|---|
| 800 | xc_sandbox_install(sandbox, install TSRMLS_CC); |
|---|
| 801 | CG(in_compilation) = 0; |
|---|
| 802 | CG(compiled_filename) = NULL; |
|---|
| 803 | |
|---|
| 804 | /* no free as it's installed */ |
|---|
| 805 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 806 | TG(zend_constants).pDestructor = NULL; |
|---|
| 807 | #endif |
|---|
| 808 | TG(function_table).pDestructor = NULL; |
|---|
| 809 | TG(class_table).pDestructor = NULL; |
|---|
| 810 | } |
|---|
| 811 | |
|---|
| 812 | /* destroy all the tmp */ |
|---|
| 813 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 814 | zend_hash_destroy(&TG(zend_constants)); |
|---|
| 815 | #endif |
|---|
| 816 | zend_hash_destroy(&TG(function_table)); |
|---|
| 817 | zend_hash_destroy(&TG(class_table)); |
|---|
| 818 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 819 | zend_hash_destroy(&TG(auto_globals)); |
|---|
| 820 | #endif |
|---|
| 821 | zend_hash_destroy(TG(included_files)); |
|---|
| 822 | |
|---|
| 823 | /* restore orig here, as EG/CG holded tmp before */ |
|---|
| 824 | memcpy(&EG(included_files), &OG(included_files), sizeof(EG(included_files))); |
|---|
| 825 | |
|---|
| 826 | #ifdef E_STRICT |
|---|
| 827 | EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting; |
|---|
| 828 | #endif |
|---|
| 829 | |
|---|
| 830 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 831 | CG(compiler_options) = sandbox->orig_compiler_options; |
|---|
| 832 | #endif |
|---|
| 833 | |
|---|
| 834 | if (sandbox->alloc) { |
|---|
| 835 | efree(sandbox); |
|---|
| 836 | } |
|---|
| 837 | } |
|---|
| 838 | /* }}} */ |
|---|
| 839 | int xc_vtrace(const char *fmt, va_list args) /* {{{ */ |
|---|
| 840 | { |
|---|
| 841 | return vfprintf(stderr, fmt, args); |
|---|
| 842 | } |
|---|
| 843 | /* }}} */ |
|---|
| 844 | int xc_trace(const char *fmt, ...) /* {{{ */ |
|---|
| 845 | { |
|---|
| 846 | va_list args; |
|---|
| 847 | int ret; |
|---|
| 848 | |
|---|
| 849 | va_start(args, fmt); |
|---|
| 850 | ret = xc_vtrace(fmt, args); |
|---|
| 851 | va_end(args); |
|---|
| 852 | return ret; |
|---|
| 853 | } |
|---|
| 854 | /* }}} */ |
|---|
| 855 | |
|---|
| 856 | #ifndef ZEND_ENGINE_2_3 |
|---|
| 857 | size_t zend_dirname(char *path, size_t len) /* {{{ */ |
|---|
| 858 | { |
|---|
| 859 | php_dirname(path, len); |
|---|
| 860 | return strlen(path); |
|---|
| 861 | } |
|---|
| 862 | /* }}} */ |
|---|
| 863 | |
|---|
| 864 | long zend_atol(const char *str, int str_len) /* {{{ */ |
|---|
| 865 | { |
|---|
| 866 | long retval; |
|---|
| 867 | |
|---|
| 868 | if (!str_len) { |
|---|
| 869 | str_len = strlen(str); |
|---|
| 870 | } |
|---|
| 871 | |
|---|
| 872 | retval = strtol(str, NULL, 0); |
|---|
| 873 | if (str_len > 0) { |
|---|
| 874 | switch (str[str_len - 1]) { |
|---|
| 875 | case 'g': |
|---|
| 876 | case 'G': |
|---|
| 877 | retval *= 1024; |
|---|
| 878 | /* break intentionally missing */ |
|---|
| 879 | case 'm': |
|---|
| 880 | case 'M': |
|---|
| 881 | retval *= 1024; |
|---|
| 882 | /* break intentionally missing */ |
|---|
| 883 | case 'k': |
|---|
| 884 | case 'K': |
|---|
| 885 | retval *= 1024; |
|---|
| 886 | break; |
|---|
| 887 | } |
|---|
| 888 | } |
|---|
| 889 | |
|---|
| 890 | return retval; |
|---|
| 891 | } |
|---|
| 892 | /* }}} */ |
|---|
| 893 | |
|---|
| 894 | #endif |
|---|