| 1 | #include "php.h" |
|---|
| 2 | #include "xcache.h" |
|---|
| 3 | |
|---|
| 4 | #ifdef DEBUG |
|---|
| 5 | # define IFDEBUG(x) (x) |
|---|
| 6 | # define TRACE(fmt, ...) \ |
|---|
| 7 | xc_trace("%s:%d: " fmt "\r\n", __FILE__, __LINE__, __VA_ARGS__) |
|---|
| 8 | int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2); |
|---|
| 9 | # undef NDEBUG |
|---|
| 10 | # undef inline |
|---|
| 11 | # define inline |
|---|
| 12 | #else |
|---|
| 13 | # define TRACE(fmt, ...) do { } while (0) |
|---|
| 14 | # define IFDEBUG(x) do { } while (0) |
|---|
| 15 | # ifndef NDEBUG |
|---|
| 16 | # define NDEBUG |
|---|
| 17 | # endif |
|---|
| 18 | #endif |
|---|
| 19 | #include <assert.h> |
|---|
| 20 | |
|---|
| 21 | typedef struct { |
|---|
| 22 | int alloc; |
|---|
| 23 | zend_op_array *op_array; |
|---|
| 24 | HashTable *function_table; |
|---|
| 25 | HashTable *class_table; |
|---|
| 26 | } xc_compile_result_t; |
|---|
| 27 | |
|---|
| 28 | xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, |
|---|
| 29 | zend_op_array *op_array, |
|---|
| 30 | HashTable *function_table, |
|---|
| 31 | HashTable *class_table); |
|---|
| 32 | void xc_compile_result_free(xc_compile_result_t *cr); |
|---|
| 33 | xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC); |
|---|
| 34 | /* apply func */ |
|---|
| 35 | int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC); |
|---|
| 36 | int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC); |
|---|
| 37 | int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC); |
|---|
| 38 | |
|---|
| 39 | int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC); |
|---|
| 40 | int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC); |
|---|
| 41 | int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC); |
|---|
| 42 | int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC); |
|---|
| 43 | zend_uchar xc_get_fixed_opcode(zend_uchar opcode, int line); |
|---|
| 44 | |
|---|
| 45 | 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); |
|---|
| 46 | |
|---|
| 47 | /* installer */ |
|---|
| 48 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 49 | void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len TSRMLS_DC); |
|---|
| 50 | #endif |
|---|
| 51 | void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len TSRMLS_DC); |
|---|
| 52 | ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len TSRMLS_DC); |
|---|
| 53 | |
|---|
| 54 | /* sandbox */ |
|---|
| 55 | typedef struct { |
|---|
| 56 | int alloc; |
|---|
| 57 | int orig_user_error_handler_error_reporting; |
|---|
| 58 | char *filename; |
|---|
| 59 | |
|---|
| 60 | HashTable orig_included_files; |
|---|
| 61 | HashTable *tmp_included_files; |
|---|
| 62 | |
|---|
| 63 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 64 | HashTable *orig_zend_constants; |
|---|
| 65 | HashTable tmp_zend_constants; |
|---|
| 66 | #endif |
|---|
| 67 | HashTable *orig_function_table; |
|---|
| 68 | HashTable *orig_class_table; |
|---|
| 69 | HashTable *orig_auto_globals; |
|---|
| 70 | HashTable tmp_function_table; |
|---|
| 71 | HashTable tmp_class_table; |
|---|
| 72 | HashTable tmp_auto_globals; |
|---|
| 73 | Bucket *tmp_internal_function_tail; |
|---|
| 74 | Bucket *tmp_internal_class_tail; |
|---|
| 75 | } xc_sandbox_t; |
|---|
| 76 | |
|---|
| 77 | xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC); |
|---|
| 78 | void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC); |
|---|