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