| [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 | int alloc; |
|---|
| 48 | zend_op_array *op_array; |
|---|
| 49 | HashTable *function_table; |
|---|
| 50 | HashTable *class_table; |
|---|
| 51 | } xc_compile_result_t; |
|---|
| 52 | |
|---|
| 53 | xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, |
|---|
| 54 | zend_op_array *op_array, |
|---|
| 55 | HashTable *function_table, |
|---|
| 56 | HashTable *class_table); |
|---|
| 57 | void xc_compile_result_free(xc_compile_result_t *cr); |
|---|
| 58 | xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC); |
|---|
| 59 | /* apply func */ |
|---|
| 60 | int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC); |
|---|
| 61 | int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC); |
|---|
| 62 | int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC); |
|---|
| 63 | |
|---|
| 64 | int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC); |
|---|
| 65 | int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC); |
|---|
| 66 | int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC); |
|---|
| 67 | int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC); |
|---|
| 68 | zend_uchar xc_get_fixed_opcode(zend_uchar opcode, int line); |
|---|
| 69 | |
|---|
| [212] | 70 | 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); |
|---|
| 71 | |
|---|
| [1] | 72 | /* installer */ |
|---|
| [95] | 73 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| [860] | 74 | 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] | 75 | #endif |
|---|
| [860] | 76 | 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); |
|---|
| 77 | 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] | 78 | |
|---|
| [669] | 79 | #if defined(E_STRICT) || defined(E_DEPRECATED) |
|---|
| 80 | #define XCACHE_ERROR_CACHING |
|---|
| 81 | #endif |
|---|
| 82 | |
|---|
| [1] | 83 | /* sandbox */ |
|---|
| 84 | typedef struct { |
|---|
| 85 | int alloc; |
|---|
| [860] | 86 | ZEND_24(NOTHING, const) char *filename; |
|---|
| [1] | 87 | |
|---|
| 88 | HashTable orig_included_files; |
|---|
| 89 | HashTable *tmp_included_files; |
|---|
| 90 | |
|---|
| [95] | 91 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 92 | HashTable *orig_zend_constants; |
|---|
| 93 | HashTable tmp_zend_constants; |
|---|
| 94 | #endif |
|---|
| [1] | 95 | HashTable *orig_function_table; |
|---|
| 96 | HashTable *orig_class_table; |
|---|
| [268] | 97 | HashTable *orig_auto_globals; |
|---|
| [1] | 98 | HashTable tmp_function_table; |
|---|
| 99 | HashTable tmp_class_table; |
|---|
| [268] | 100 | HashTable tmp_auto_globals; |
|---|
| [588] | 101 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 102 | Bucket *tmp_internal_constant_tail; |
|---|
| 103 | #endif |
|---|
| [344] | 104 | Bucket *tmp_internal_function_tail; |
|---|
| 105 | Bucket *tmp_internal_class_tail; |
|---|
| [496] | 106 | |
|---|
| [669] | 107 | #ifdef XCACHE_ERROR_CACHING |
|---|
| [496] | 108 | int orig_user_error_handler_error_reporting; |
|---|
| 109 | zend_uint compilererror_cnt; |
|---|
| 110 | zend_uint compilererror_size; |
|---|
| 111 | xc_compilererror_t *compilererrors; |
|---|
| 112 | #endif |
|---|
| [548] | 113 | |
|---|
| 114 | #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
|---|
| 115 | zend_uint orig_compiler_options; |
|---|
| 116 | #endif |
|---|
| [1] | 117 | } xc_sandbox_t; |
|---|
| 118 | |
|---|
| [405] | 119 | typedef enum _xc_install_action_t { |
|---|
| 120 | XC_NoInstall, |
|---|
| 121 | XC_Install, |
|---|
| 122 | XC_InstallNoBinding |
|---|
| 123 | } xc_install_action_t; |
|---|
| 124 | |
|---|
| [345] | 125 | void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce)); |
|---|
| [860] | 126 | xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) char *filename TSRMLS_DC); |
|---|
| [405] | 127 | void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC); |
|---|
| [640] | 128 | |
|---|
| 129 | typedef zend_bool (*xc_if_func_t)(void *data); |
|---|
| 130 | |
|---|
| 131 | void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker); |
|---|
| 132 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 133 | void xc_zend_constant_ctor(zend_constant *c); |
|---|
| 134 | void xc_zend_constant_dtor(zend_constant *c); |
|---|
| 135 | void xc_copy_internal_zend_constants(HashTable *target, HashTable *source); |
|---|
| 136 | #endif |
|---|
| [662] | 137 | |
|---|
| [671] | 138 | #ifndef ZEND_ENGINE_2_3 |
|---|
| [847] | 139 | size_t xc_dirname(char *path, size_t len); |
|---|
| 140 | #define zend_dirname xc_dirname |
|---|
| 141 | long xc_atol(const char *str, int len); |
|---|
| 142 | #define zend_atol xc_atol |
|---|
| [671] | 143 | #endif |
|---|
| 144 | |
|---|
| [662] | 145 | typedef struct { |
|---|
| 146 | zend_uint size; |
|---|
| 147 | zend_uint cnt; |
|---|
| 148 | void *data; |
|---|
| 149 | } xc_vector_t; |
|---|
| 150 | |
|---|
| 151 | #define xc_vector_init(type, vector) do { \ |
|---|
| 152 | (vector)->cnt = 0; \ |
|---|
| 153 | (vector)->size = 0; \ |
|---|
| 154 | (vector)->data = NULL; \ |
|---|
| 155 | } while (0) |
|---|
| 156 | |
|---|
| 157 | #define xc_vector_add(type, vector, value) do { \ |
|---|
| 158 | if ((vector)->cnt == (vector)->size) { \ |
|---|
| 159 | if ((vector)->size) { \ |
|---|
| 160 | (vector)->size <<= 1; \ |
|---|
| 161 | (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \ |
|---|
| 162 | } \ |
|---|
| 163 | else { \ |
|---|
| 164 | (vector)->size = 8; \ |
|---|
| 165 | (vector)->data = emalloc(sizeof(type) * (vector)->size); \ |
|---|
| 166 | } \ |
|---|
| 167 | } \ |
|---|
| 168 | ((type *) (vector)->data)[(vector)->cnt++] = value; \ |
|---|
| 169 | } while (0) |
|---|
| 170 | |
|---|
| 171 | static inline void *xc_vector_detach_impl(xc_vector_t *vector) |
|---|
| 172 | { |
|---|
| 173 | void *data = vector->data; |
|---|
| 174 | vector->data = NULL; |
|---|
| 175 | vector->size = 0; |
|---|
| 176 | vector->cnt = 0; |
|---|
| 177 | return data; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | #define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector)) |
|---|
| 181 | |
|---|
| 182 | static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC) |
|---|
| 183 | { |
|---|
| 184 | if (vector->data) { |
|---|
| 185 | efree(vector->data); |
|---|
| 186 | } |
|---|
| 187 | vector->size = 0; |
|---|
| 188 | vector->cnt = 0; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | #define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC) |
|---|
| 192 | |
|---|