| [1] | 1 | #include "php.h" |
|---|
| [305] | 2 | #include "xcache.h" |
|---|
| [1] | 3 | |
|---|
| [543] | 4 | #ifdef XCACHE_DEBUG |
|---|
| [305] | 5 | # define IFDEBUG(x) (x) |
|---|
| [349] | 6 | int xc_vtrace(const char *fmt, va_list args); |
|---|
| [305] | 7 | int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2); |
|---|
| [349] | 8 | |
|---|
| 9 | # ifdef ZEND_WIN32 |
|---|
| 10 | static inline int TRACE(const char *fmt, ...) |
|---|
| 11 | { |
|---|
| 12 | va_list args; |
|---|
| 13 | int ret; |
|---|
| 14 | |
|---|
| 15 | va_start(args, fmt); |
|---|
| 16 | ret = xc_vtrace(fmt, args); |
|---|
| 17 | va_end(args); |
|---|
| 18 | return ret; |
|---|
| 19 | } |
|---|
| 20 | # else |
|---|
| 21 | # define TRACE(fmt, ...) \ |
|---|
| 22 | xc_trace("%s:%d: " fmt "\r\n", __FILE__, __LINE__, __VA_ARGS__) |
|---|
| 23 | # endif /* ZEND_WIN32 */ |
|---|
| [305] | 24 | # undef NDEBUG |
|---|
| 25 | # undef inline |
|---|
| 26 | # define inline |
|---|
| [543] | 27 | #else /* XCACHE_DEBUG */ |
|---|
| [349] | 28 | |
|---|
| 29 | # ifdef ZEND_WIN32 |
|---|
| [350] | 30 | static inline int TRACE_DUMMY(const char *fmt, ...) |
|---|
| [349] | 31 | { |
|---|
| 32 | return 0; |
|---|
| 33 | } |
|---|
| [351] | 34 | # define TRACE 1 ? 0 : TRACE_DUMMY |
|---|
| [349] | 35 | # else |
|---|
| 36 | # define TRACE(fmt, ...) do { } while (0) |
|---|
| 37 | # endif /* ZEND_WIN32 */ |
|---|
| 38 | |
|---|
| [305] | 39 | # define IFDEBUG(x) do { } while (0) |
|---|
| [543] | 40 | #endif /* XCACHE_DEBUG */ |
|---|
| [305] | 41 | #include <assert.h> |
|---|
| 42 | |
|---|
| [903] | 43 | int xc_util_init(int module_number TSRMLS_DC); |
|---|
| 44 | void xc_util_destroy(); |
|---|
| 45 | |
|---|
| [1] | 46 | typedef struct { |
|---|
| 47 | zend_op_array *op_array; |
|---|
| 48 | HashTable *function_table; |
|---|
| 49 | HashTable *class_table; |
|---|
| 50 | } xc_compile_result_t; |
|---|
| 51 | |
|---|
| 52 | xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, |
|---|
| 53 | zend_op_array *op_array, |
|---|
| 54 | HashTable *function_table, |
|---|
| 55 | HashTable *class_table); |
|---|
| 56 | void xc_compile_result_free(xc_compile_result_t *cr); |
|---|
| 57 | xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC); |
|---|
| 58 | /* apply func */ |
|---|
| 59 | int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC); |
|---|
| 60 | int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC); |
|---|
| 61 | int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC); |
|---|
| 62 | |
|---|
| 63 | int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC); |
|---|
| 64 | int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC); |
|---|
| 65 | int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC); |
|---|
| 66 | int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC); |
|---|
| 67 | zend_uchar xc_get_fixed_opcode(zend_uchar opcode, int line); |
|---|
| 68 | |
|---|
| [212] | 69 | 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); |
|---|
| 70 | |
|---|
| [1] | 71 | /* installer */ |
|---|
| [95] | 72 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| [860] | 73 | void xc_install_constant(ZEND_24(NOTHING, const) char *filename, zend_constant *constant, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); |
|---|
| [95] | 74 | #endif |
|---|
| [860] | 75 | void xc_install_function(ZEND_24(NOTHING, const) char *filename, zend_function *func, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); |
|---|
| 76 | ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(NOTHING, const) char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); |
|---|
| [1] | 77 | |
|---|
| [669] | 78 | #if defined(E_STRICT) || defined(E_DEPRECATED) |
|---|
| 79 | #define XCACHE_ERROR_CACHING |
|---|
| 80 | #endif |
|---|
| 81 | |
|---|
| [937] | 82 | /* return op_array to install */ |
|---|
| 83 | typedef zend_op_array *(*xc_sandboxed_func_t)(void *data TSRMLS_DC); |
|---|
| 84 | zend_op_array *xc_sandbox(xc_sandboxed_func_t sandboxed_func, void *data, ZEND_24(NOTHING, const) char *filename TSRMLS_DC); |
|---|
| 85 | const Bucket *xc_sandbox_user_function_begin(); |
|---|
| 86 | const Bucket *xc_sandbox_user_class_begin(); |
|---|
| 87 | zend_uint xc_sandbox_compilererror_cnt(); |
|---|
| [669] | 88 | #ifdef XCACHE_ERROR_CACHING |
|---|
| [937] | 89 | xc_compilererror_t *xc_sandbox_compilererrors(); |
|---|
| 90 | zend_uint xc_sandbox_compilererror_cnt(); |
|---|
| [496] | 91 | #endif |
|---|
| [548] | 92 | |
|---|
| [345] | 93 | void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce)); |
|---|
| [640] | 94 | |
|---|
| 95 | typedef zend_bool (*xc_if_func_t)(void *data); |
|---|
| 96 | |
|---|
| 97 | void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker); |
|---|
| 98 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 99 | void xc_zend_constant_ctor(zend_constant *c); |
|---|
| 100 | void xc_zend_constant_dtor(zend_constant *c); |
|---|
| 101 | void xc_copy_internal_zend_constants(HashTable *target, HashTable *source); |
|---|
| 102 | #endif |
|---|
| [662] | 103 | |
|---|
| [671] | 104 | #ifndef ZEND_ENGINE_2_3 |
|---|
| [847] | 105 | size_t xc_dirname(char *path, size_t len); |
|---|
| 106 | #define zend_dirname xc_dirname |
|---|
| 107 | long xc_atol(const char *str, int len); |
|---|
| 108 | #define zend_atol xc_atol |
|---|
| [671] | 109 | #endif |
|---|
| 110 | |
|---|
| [662] | 111 | typedef struct { |
|---|
| 112 | zend_uint size; |
|---|
| 113 | zend_uint cnt; |
|---|
| 114 | void *data; |
|---|
| 115 | } xc_vector_t; |
|---|
| 116 | |
|---|
| 117 | #define xc_vector_init(type, vector) do { \ |
|---|
| 118 | (vector)->cnt = 0; \ |
|---|
| 119 | (vector)->size = 0; \ |
|---|
| 120 | (vector)->data = NULL; \ |
|---|
| 121 | } while (0) |
|---|
| 122 | |
|---|
| 123 | #define xc_vector_add(type, vector, value) do { \ |
|---|
| 124 | if ((vector)->cnt == (vector)->size) { \ |
|---|
| 125 | if ((vector)->size) { \ |
|---|
| 126 | (vector)->size <<= 1; \ |
|---|
| 127 | (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \ |
|---|
| 128 | } \ |
|---|
| 129 | else { \ |
|---|
| 130 | (vector)->size = 8; \ |
|---|
| 131 | (vector)->data = emalloc(sizeof(type) * (vector)->size); \ |
|---|
| 132 | } \ |
|---|
| 133 | } \ |
|---|
| 134 | ((type *) (vector)->data)[(vector)->cnt++] = value; \ |
|---|
| 135 | } while (0) |
|---|
| 136 | |
|---|
| 137 | static inline void *xc_vector_detach_impl(xc_vector_t *vector) |
|---|
| 138 | { |
|---|
| 139 | void *data = vector->data; |
|---|
| 140 | vector->data = NULL; |
|---|
| 141 | vector->size = 0; |
|---|
| 142 | vector->cnt = 0; |
|---|
| 143 | return data; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | #define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector)) |
|---|
| 147 | |
|---|
| 148 | static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC) |
|---|
| 149 | { |
|---|
| 150 | if (vector->data) { |
|---|
| 151 | efree(vector->data); |
|---|
| 152 | } |
|---|
| 153 | vector->size = 0; |
|---|
| 154 | vector->cnt = 0; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | #define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC) |
|---|
| 158 | |
|---|