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