Changeset 937
Legend:
- Unmodified
- Added
- Removed
-
trunk/disassembler.c
r930 r937 4 4 #include "processor.h" 5 5 6 #define return_value dst7 8 /* sandbox {{{ */9 #undef TG10 #undef OG11 #define TG(x) (sandbox->tmp_##x)12 #define OG(x) (sandbox->orig_##x)13 /* }}} */14 15 6 #ifndef HAVE_XCACHE_OPCODE_SPEC_DEF 16 7 #error disassembler cannot be built without xcache/opcode_spec_def.h 17 8 #endif 18 static void xc_dasm( xc_sandbox_t *sandbox, zval *dst, zend_op_array *op_array TSRMLS_DC) /* {{{ */9 static void xc_dasm(zval *output, zend_op_array *op_array TSRMLS_DC) /* {{{ */ 19 10 { 20 Bucket *b;11 const Bucket *b; 21 12 zval *zv, *list; 22 13 xc_compile_result_t cr; … … 31 22 32 23 /* go */ 33 array_init( dst);24 array_init(output); 34 25 35 26 ALLOC_INIT_ZVAL(zv); 36 27 array_init(zv); 37 28 xc_dasm_zend_op_array(&dasm, zv, op_array TSRMLS_CC); 38 add_assoc_zval_ex( dst, ZEND_STRS("op_array"), zv);29 add_assoc_zval_ex(output, ZEND_STRS("op_array"), zv); 39 30 40 31 buf = emalloc(bufsize); … … 42 33 ALLOC_INIT_ZVAL(list); 43 34 array_init(list); 44 b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead; 45 for (; b; b = b->pListNext) { 35 for (b = xc_sandbox_user_function_begin(); b; b = b->pListNext) { 46 36 int keysize, keyLength; 47 37 … … 75 65 add_u_assoc_zval_ex(list, BUCKET_KEY_TYPE(b), ZSTR(buf), keyLength, zv); 76 66 } 77 add_assoc_zval_ex( dst, ZEND_STRS("function_table"), list);67 add_assoc_zval_ex(output, ZEND_STRS("function_table"), list); 78 68 79 69 ALLOC_INIT_ZVAL(list); 80 70 array_init(list); 81 b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead; 82 for (; b; b = b->pListNext) { 71 for (b = xc_sandbox_user_class_begin(); b; b = b->pListNext) { 83 72 int keysize, keyLength; 84 73 … … 112 101 } 113 102 efree(buf); 114 add_assoc_zval_ex( dst, ZEND_STRS("class_table"), list);103 add_assoc_zval_ex(output, ZEND_STRS("class_table"), list); 115 104 116 105 /*xc_apply_op_array(&cr, (apply_func_t) xc_redo_pass_two TSRMLS_CC);*/ 117 106 xc_compile_result_free(&cr); 118 119 return;120 107 } 121 108 /* }}} */ 122 void xc_dasm_string(zval *dst, zval *source TSRMLS_DC) /* {{{ */ 109 typedef struct xc_dasm_sandboxed_t { /* {{{ */ 110 enum Type { 111 xc_dasm_file_t 112 , xc_dasm_string_t 113 } type; 114 union { 115 zval *zfilename; 116 struct { 117 zval *source; 118 char *eval_name; 119 } compile_string; 120 } input; 121 122 zval *output; 123 } xc_dasm_sandboxed_t; /* {{{ */ 124 125 zend_op_array *xc_dasm_sandboxed(void *data TSRMLS_DC) 123 126 { 124 int catched;127 zend_bool catched = 0; 125 128 zend_op_array *op_array = NULL; 126 xc_sandbox_t sandbox; 127 char *eval_name = zend_make_compiled_string_description("runtime-created function" TSRMLS_CC); 129 xc_dasm_sandboxed_t *sandboxed_dasm = (xc_dasm_sandboxed_t *) data; 128 130 129 xc_sandbox_init(&sandbox, eval_name TSRMLS_CC);130 131 catched = 0;132 131 zend_try { 133 op_array = compile_string(source, eval_name TSRMLS_CC); 132 if (sandboxed_dasm->type == xc_dasm_file_t) { 133 op_array = compile_filename(ZEND_REQUIRE, sandboxed_dasm->input.zfilename TSRMLS_CC); 134 } 135 else { 136 op_array = compile_string(sandboxed_dasm->input.compile_string.source, sandboxed_dasm->input.compile_string.eval_name TSRMLS_CC); 137 } 134 138 } zend_catch { 135 139 catched = 1; … … 137 141 138 142 if (catched || !op_array) { 139 goto err_compile; 143 #define return_value sandboxed_dasm->output 144 RETVAL_FALSE; 145 #undef return_value 146 return NULL; 140 147 } 141 148 142 xc_dasm(&sandbox, dst, op_array TSRMLS_CC); 143 144 /* free */ 145 efree(eval_name); 146 #ifdef ZEND_ENGINE_2 147 destroy_op_array(op_array TSRMLS_CC); 148 #else 149 destroy_op_array(op_array); 150 #endif 151 efree(op_array); 152 xc_sandbox_free(&sandbox, 0 TSRMLS_CC); 153 return; 154 155 err_compile: 156 efree(eval_name); 157 xc_sandbox_free(&sandbox, 0 TSRMLS_CC); 158 159 RETURN_FALSE; 160 } 161 /* }}} */ 162 void xc_dasm_file(zval *dst, const char *filename TSRMLS_DC) /* {{{ */ 163 { 164 int catched; 165 zend_op_array *op_array = NULL; 166 xc_sandbox_t sandbox; 167 zval *zfilename; 168 169 MAKE_STD_ZVAL(zfilename); 170 zfilename->value.str.val = estrdup(filename); 171 zfilename->value.str.len = strlen(filename); 172 zfilename->type = IS_STRING; 173 174 xc_sandbox_init(&sandbox, zfilename->value.str.val TSRMLS_CC); 175 176 catched = 0; 177 zend_try { 178 op_array = compile_filename(ZEND_REQUIRE, zfilename TSRMLS_CC); 179 } zend_catch { 180 catched = 1; 181 } zend_end_try(); 182 183 if (catched || !op_array) { 184 goto err_compile; 185 } 186 187 xc_dasm(&sandbox, dst, op_array TSRMLS_CC); 149 xc_dasm(sandboxed_dasm->output, op_array TSRMLS_CC); 188 150 189 151 /* free */ … … 194 156 #endif 195 157 efree(op_array); 196 xc_sandbox_free(&sandbox, 0 TSRMLS_CC);197 zval_dtor(zfilename);198 FREE_ZVAL(zfilename);199 return;200 158 201 err_compile: 202 xc_sandbox_free(&sandbox, 0 TSRMLS_CC); 159 return NULL; 160 } /* }}} */ 161 void xc_dasm_string(zval *output, zval *source TSRMLS_DC) /* {{{ */ 162 { 163 xc_dasm_sandboxed_t sandboxed_dasm; 164 char *eval_name = zend_make_compiled_string_description("runtime-created function" TSRMLS_CC); 165 166 sandboxed_dasm.output = output; 167 sandboxed_dasm.type = xc_dasm_string_t; 168 sandboxed_dasm.input.compile_string.source = source; 169 sandboxed_dasm.input.compile_string.eval_name = eval_name; 170 xc_sandbox(&xc_dasm_sandboxed, (void *) &sandboxed_dasm, eval_name TSRMLS_CC); 171 efree(eval_name); 172 } 173 /* }}} */ 174 void xc_dasm_file(zval *output, const char *filename TSRMLS_DC) /* {{{ */ 175 { 176 zval *zfilename; 177 xc_dasm_sandboxed_t sandboxed_dasm; 178 179 MAKE_STD_ZVAL(zfilename); 180 zfilename->value.str.val = estrdup(filename); 181 zfilename->value.str.len = strlen(filename); 182 zfilename->type = IS_STRING; 183 184 sandboxed_dasm.output = output; 185 sandboxed_dasm.type = xc_dasm_file_t; 186 sandboxed_dasm.input.zfilename = zfilename; 187 xc_sandbox(&xc_dasm_sandboxed, (void *) &sandboxed_dasm, zfilename->value.str.val TSRMLS_CC); 203 188 204 189 zval_dtor(zfilename); 205 190 FREE_ZVAL(zfilename); 206 RETURN_FALSE;207 191 } 208 192 /* }}} */ -
trunk/utils.c
r935 r937 582 582 /* }}} */ 583 583 584 /* sandbox {{{ */ 584 typedef struct { /* sandbox {{{ */ 585 ZEND_24(NOTHING, const) char *filename; 586 587 HashTable orig_included_files; 588 HashTable *tmp_included_files; 589 590 #ifdef HAVE_XCACHE_CONSTANT 591 HashTable *orig_zend_constants; 592 HashTable tmp_zend_constants; 593 #endif 594 HashTable *orig_function_table; 595 HashTable *orig_class_table; 596 HashTable *orig_auto_globals; 597 HashTable tmp_function_table; 598 HashTable tmp_class_table; 599 HashTable tmp_auto_globals; 600 #ifdef HAVE_XCACHE_CONSTANT 601 Bucket *tmp_internal_constant_tail; 602 #endif 603 Bucket *tmp_internal_function_tail; 604 Bucket *tmp_internal_class_tail; 605 606 #ifdef XCACHE_ERROR_CACHING 607 int orig_user_error_handler_error_reporting; 608 zend_uint compilererror_cnt; 609 zend_uint compilererror_size; 610 xc_compilererror_t *compilererrors; 611 #endif 612 613 #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES 614 zend_uint orig_compiler_options; 615 #endif 616 } xc_sandbox_t; 617 585 618 #undef TG 586 619 #undef OG … … 731 764 /* }}} */ 732 765 #endif 766 733 767 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) char *filename TSRMLS_DC) /* {{{ */ 734 768 { … … 825 859 /* }}} */ 826 860 #endif 827 static void xc_sandbox_install(xc_sandbox_t *sandbox , xc_install_action_t installTSRMLS_DC) /* {{{ */861 static void xc_sandbox_install(xc_sandbox_t *sandbox TSRMLS_DC) /* {{{ */ 828 862 { 829 863 zend_uint i; … … 874 908 #endif 875 909 876 if (install != XC_InstallNoBinding) {877 910 #ifdef ZEND_COMPILE_DELAYED_BINDING 878 zend_do_delayed_early_binding(CG(active_op_array) TSRMLS_CC); 879 #else 880 xc_undo_pass_two(CG(active_op_array) TSRMLS_CC); 881 xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC); 882 xc_redo_pass_two(CG(active_op_array) TSRMLS_CC); 883 #endif 884 } 911 zend_do_delayed_early_binding(CG(active_op_array) TSRMLS_CC); 912 #else 913 xc_undo_pass_two(CG(active_op_array) TSRMLS_CC); 914 xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC); 915 xc_redo_pass_two(CG(active_op_array) TSRMLS_CC); 916 #endif 885 917 886 918 #ifdef XCACHE_ERROR_CACHING … … 898 930 } 899 931 /* }}} */ 900 void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t installTSRMLS_DC) /* {{{ */932 void xc_sandbox_free(xc_sandbox_t *sandbox, zend_op_array *op_array TSRMLS_DC) /* {{{ */ 901 933 { 902 934 XG(sandbox) = NULL; … … 916 948 #endif 917 949 918 if (install != XC_NoInstall) { 950 if (op_array) { 951 zend_op_array *old_active_op_array = CG(active_op_array); 919 952 CG(in_compilation) = 1; 920 953 CG(compiled_filename) = ZEND_24(NOTHING, (char *)) sandbox->filename; 921 954 CG(zend_lineno) = 0; 922 xc_sandbox_install(sandbox, install TSRMLS_CC); 955 956 CG(active_op_array) = op_array; 957 xc_sandbox_install(sandbox TSRMLS_CC); 958 CG(active_op_array) = old_active_op_array; 959 923 960 CG(in_compilation) = 0; 924 961 CG(compiled_filename) = NULL; … … 961 998 } 962 999 /* }}} */ 1000 const Bucket *xc_sandbox_user_function_begin() /* {{{ */ 1001 { 1002 xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox); 1003 assert(sandbox); 1004 return TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead; 1005 } /* {{{ */ 1006 const Bucket *xc_sandbox_user_class_begin() /* {{{ */ 1007 { 1008 xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox); 1009 assert(sandbox); 1010 return TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead; 1011 } /* {{{ */ 1012 #ifdef XCACHE_ERROR_CACHING 1013 xc_compilererror_t *xc_sandbox_compilererrors() /* {{{ */ 1014 { 1015 xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox); 1016 assert(sandbox); 1017 return sandbox->compilererrors; 1018 } /* }}} */ 1019 zend_uint xc_sandbox_compilererror_cnt() /* {{{ */ 1020 { 1021 xc_sandbox_t *sandbox = (xc_sandbox_t *) XG(sandbox); 1022 assert(sandbox); 1023 return sandbox->compilererror_cnt; 1024 } /* }}} */ 1025 #endif 1026 1027 963 1028 int xc_vtrace(const char *fmt, va_list args) /* {{{ */ 964 1029 { -
trunk/utils.h
r935 r937 80 80 #endif 81 81 82 /* sandbox */ 83 typedef struct { 84 ZEND_24(NOTHING, const) char *filename; 85 86 HashTable orig_included_files; 87 HashTable *tmp_included_files; 88 89 #ifdef HAVE_XCACHE_CONSTANT 90 HashTable *orig_zend_constants; 91 HashTable tmp_zend_constants; 92 #endif 93 HashTable *orig_function_table; 94 HashTable *orig_class_table; 95 HashTable *orig_auto_globals; 96 HashTable tmp_function_table; 97 HashTable tmp_class_table; 98 HashTable tmp_auto_globals; 99 #ifdef HAVE_XCACHE_CONSTANT 100 Bucket *tmp_internal_constant_tail; 101 #endif 102 Bucket *tmp_internal_function_tail; 103 Bucket *tmp_internal_class_tail; 104 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(); 105 88 #ifdef XCACHE_ERROR_CACHING 106 int orig_user_error_handler_error_reporting; 107 zend_uint compilererror_cnt; 108 zend_uint compilererror_size; 109 xc_compilererror_t *compilererrors; 89 xc_compilererror_t *xc_sandbox_compilererrors(); 90 zend_uint xc_sandbox_compilererror_cnt(); 110 91 #endif 111 92 112 #ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES113 zend_uint orig_compiler_options;114 #endif115 } xc_sandbox_t;116 117 typedef enum _xc_install_action_t {118 XC_NoInstall,119 XC_Install,120 XC_InstallNoBinding121 } xc_install_action_t;122 123 93 void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce)); 124 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) char *filename TSRMLS_DC);125 void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC);126 94 127 95 typedef zend_bool (*xc_if_func_t)(void *data); -
trunk/xcache.c
r936 r937 1007 1007 /* }}} */ 1008 1008 #endif 1009 typedef struct xc_compiler_t { /* {{{ */ 1010 /* XCache cached compile state */ 1011 const char *filename; 1012 size_t filename_len; 1013 const char *opened_path; 1014 char opened_path_buffer[MAXPATHLEN]; 1015 1016 xc_entry_hash_t entry_hash; 1017 xc_entry_php_t new_entry; 1018 xc_entry_data_php_t new_php; 1019 } xc_compiler_t; 1020 /* }}} */ 1009 1021 typedef struct xc_entry_resolve_path_data_t { /* {{{ */ 1010 1022 xc_compiler_t *compiler; … … 1798 1810 /* }}} */ 1799 1811 #ifdef XCACHE_ERROR_CACHING 1800 compiler->new_php.compilererrors = ((xc_sandbox_t *) XG(sandbox))->compilererrors;1801 compiler->new_php.compilererror_cnt = ((xc_sandbox_t *) XG(sandbox))->compilererror_cnt;1812 compiler->new_php.compilererrors = xc_sandbox_compilererrors(); 1813 compiler->new_php.compilererror_cnt = xc_sandbox_compilererror_cnt(); 1802 1814 #endif 1803 1815 #ifndef ZEND_COMPILE_DELAYED_BINDING … … 1882 1894 } 1883 1895 /* }}} */ 1884 static zend_op_array *xc_compile_file_ex(xc_compiler_t *compiler, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ 1896 typedef struct xc_sandboxed_compiler_t { /* {{{ */ 1897 xc_compiler_t *compiler; 1898 /* input */ 1899 zend_file_handle *h; 1900 int type; 1901 1902 /* sandbox output */ 1903 xc_entry_php_t *stored_entry; 1904 xc_entry_data_php_t *stored_php; 1905 } xc_sandboxed_compiler_t; /* {{{ */ 1906 1907 static zend_op_array *xc_compile_file_sandboxed(void *data TSRMLS_DC) /* {{{ */ 1908 { 1909 xc_sandboxed_compiler_t *sandboxed_compiler = (xc_sandboxed_compiler_t *) data; 1910 xc_compiler_t *compiler = sandboxed_compiler->compiler; 1911 zend_bool catched = 0; 1912 xc_cache_t *cache = xc_php_caches[compiler->entry_hash.cacheid]; 1913 xc_entry_php_t *stored_entry; 1914 xc_entry_data_php_t *stored_php; 1915 1916 /* {{{ compile */ 1917 /* make compile inside sandbox */ 1918 #ifdef HAVE_XCACHE_CONSTANT 1919 compiler->new_php.constinfos = NULL; 1920 #endif 1921 compiler->new_php.funcinfos = NULL; 1922 compiler->new_php.classinfos = NULL; 1923 #ifdef ZEND_ENGINE_2_1 1924 compiler->new_php.autoglobals = NULL; 1925 #endif 1926 memset(&compiler->new_php.op_array_info, 0, sizeof(compiler->new_php.op_array_info)); 1927 1928 XG(initial_compile_file_called) = 0; 1929 zend_try { 1930 compiler->new_php.op_array = NULL; 1931 xc_compile_php(compiler, sandboxed_compiler->h, sandboxed_compiler->type TSRMLS_CC); 1932 } zend_catch { 1933 catched = 1; 1934 } zend_end_try(); 1935 1936 if (catched 1937 || !compiler->new_php.op_array /* possible ? */ 1938 || !XG(initial_compile_file_called)) { 1939 goto err_aftersandbox; 1940 } 1941 1942 /* }}} */ 1943 #ifdef SHOW_DPRINT 1944 compiler->new_entry.php = &compiler->new_php; 1945 xc_dprint(&compiler->new_entry, 0 TSRMLS_CC); 1946 #endif 1947 1948 stored_entry = NULL; 1949 stored_php = NULL; 1950 ENTER_LOCK_EX(cache) { /* {{{ php_store/entry_store */ 1951 /* php_store */ 1952 stored_php = xc_php_store_unlocked(cache, &compiler->new_php TSRMLS_CC); 1953 if (!stored_php) { 1954 /* error */ 1955 break; 1956 } 1957 /* entry_store */ 1958 compiler->new_entry.php = stored_php; 1959 stored_entry = xc_entry_php_store_unlocked(cache, compiler->entry_hash.entryslotid, &compiler->new_entry TSRMLS_CC); 1960 if (stored_entry) { 1961 xc_php_addref_unlocked(stored_php); 1962 TRACE(" cached %d:%s, holding", compiler->new_entry.file_inode, stored_entry->entry.name.str.val); 1963 xc_entry_hold_php_unlocked(cache, stored_entry TSRMLS_CC); 1964 } 1965 } LEAVE_LOCK_EX(cache); 1966 /* }}} */ 1967 TRACE("%s", stored_entry ? "stored" : "store failed"); 1968 1969 if (catched || !stored_php) { 1970 goto err_aftersandbox; 1971 } 1972 1973 cache->compiling = 0; 1974 xc_free_php(&compiler->new_php TSRMLS_CC); 1975 1976 if (stored_entry) { 1977 if (compiler->new_php.op_array) { 1978 #ifdef ZEND_ENGINE_2 1979 destroy_op_array(compiler->new_php.op_array TSRMLS_CC); 1980 #else 1981 destroy_op_array(compiler->new_php.op_array); 1982 #endif 1983 efree(compiler->new_php.op_array); 1984 compiler->new_php.op_array = NULL; 1985 sandboxed_compiler->h = NULL; 1986 } 1987 sandboxed_compiler->stored_entry = stored_entry; 1988 sandboxed_compiler->stored_php = stored_php; 1989 /* sandbox no install */ 1990 return NULL; 1991 } 1992 else { 1993 /* install it with sandbox */ 1994 return compiler->new_php.op_array; 1995 } 1996 1997 err_aftersandbox: 1998 xc_free_php(&compiler->new_php TSRMLS_CC); 1999 2000 cache->compiling = 0; 2001 if (catched) { 2002 cache->errors ++; 2003 zend_bailout(); 2004 } 2005 return compiler->new_php.op_array; 2006 } /* }}} */ 2007 static zend_op_array *xc_compile_file_cached(xc_compiler_t *compiler, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ 1885 2008 { 1886 2009 /* … … 1899 2022 return old; 1900 2023 } 1901 php = compile(); 1902 entry = create entries[entry]; 2024 2025 inside_sandbox { 2026 php = compile; 2027 entry = create entries[entry]; 2028 } 1903 2029 } 1904 2030 … … 1912 2038 zend_bool gaveup = 0; 1913 2039 zend_bool catched = 0; 1914 xc_sandbox_t sandbox;2040 zend_op_array *op_array; 1915 2041 xc_cache_t *cache = xc_php_caches[compiler->entry_hash.cacheid]; 2042 xc_sandboxed_compiler_t sandboxed_compiler; 1916 2043 1917 2044 /* stale clogs precheck */ … … 2002 2129 /* }}} */ 2003 2130 2004 /* {{{ compile */ 2005 /* make compile inside sandbox */ 2006 2007 #ifdef HAVE_XCACHE_CONSTANT 2008 compiler->new_php.constinfos = NULL; 2009 #endif 2010 compiler->new_php.funcinfos = NULL; 2011 compiler->new_php.classinfos = NULL; 2012 #ifdef ZEND_ENGINE_2_1 2013 compiler->new_php.autoglobals = NULL; 2014 #endif 2015 memset(&compiler->new_php.op_array_info, 0, sizeof(compiler->new_php.op_array_info)); 2016 2017 XG(initial_compile_file_called) = 0; 2018 zend_try { 2019 xc_sandbox_init(&sandbox, h->opened_path ? h->opened_path : h->filename TSRMLS_CC); 2020 compiler->new_php.op_array = NULL; 2021 xc_compile_php(compiler, h, type TSRMLS_CC); 2022 } zend_catch { 2023 catched = 1; 2024 } zend_end_try(); 2025 2026 if (catched 2027 || !compiler->new_php.op_array /* possible ? */ 2028 || !XG(initial_compile_file_called)) { 2029 goto err_aftersandbox; 2030 } 2031 2032 /* }}} */ 2033 #ifdef SHOW_DPRINT 2034 compiler->new_entry.php = &compiler->new_php; 2035 xc_dprint(&compiler->new_entry, 0 TSRMLS_CC); 2036 #endif 2037 ENTER_LOCK_EX(cache) { /* {{{ php_store/entry_store */ 2038 /* php_store */ 2039 stored_php = xc_php_store_unlocked(cache, &compiler->new_php TSRMLS_CC); 2040 if (!stored_php) { 2041 /* error */ 2042 break; 2043 } 2044 /* entry_store */ 2045 compiler->new_entry.php = stored_php; 2046 stored_entry = xc_entry_php_store_unlocked(cache, compiler->entry_hash.entryslotid, &compiler->new_entry TSRMLS_CC); 2047 if (stored_entry) { 2048 xc_php_addref_unlocked(stored_php); 2049 TRACE(" cached %d:%s, holding", compiler->new_entry.file_inode, stored_entry->entry.name.str.val); 2050 xc_entry_hold_php_unlocked(cache, stored_entry TSRMLS_CC); 2051 } 2052 } LEAVE_LOCK_EX(cache); 2053 /* }}} */ 2054 TRACE("%s", stored_entry ? "stored" : "store failed"); 2055 2056 if (catched || !stored_php) { 2057 goto err_aftersandbox; 2058 } 2059 2060 cache->compiling = 0; 2061 xc_free_php(&compiler->new_php TSRMLS_CC); 2062 2063 if (stored_entry) { 2064 if (compiler->new_php.op_array) { 2065 #ifdef ZEND_ENGINE_2 2066 destroy_op_array(compiler->new_php.op_array TSRMLS_CC); 2067 #else 2068 destroy_op_array(compiler->new_php.op_array); 2069 #endif 2070 efree(compiler->new_php.op_array); 2071 compiler->new_php.op_array = NULL; 2072 h = NULL; 2073 } 2074 xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC); 2131 sandboxed_compiler.compiler = compiler; 2132 sandboxed_compiler.h = h; 2133 sandboxed_compiler.type = type; 2134 sandboxed_compiler.stored_php = NULL; 2135 sandboxed_compiler.stored_entry = NULL; 2136 op_array = xc_sandbox(xc_compile_file_sandboxed, (void *) &sandboxed_compiler, h->opened_path ? h->opened_path : h->filename TSRMLS_CC); 2137 if (sandboxed_compiler.stored_entry) { 2075 2138 return xc_compile_restore(stored_entry, stored_php, h TSRMLS_CC); 2076 2139 } 2077 2140 else { 2078 zend_op_array *old_active_op_array = CG(active_op_array); 2079 /* install it */ 2080 CG(active_op_array) = compiler->new_php.op_array; 2081 xc_sandbox_free(&sandbox, XC_Install TSRMLS_CC); 2082 CG(active_op_array) = old_active_op_array; 2083 } 2084 return compiler->new_php.op_array; 2085 2086 err_aftersandbox: 2087 xc_free_php(&compiler->new_php TSRMLS_CC); 2088 xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC); 2089 2090 cache->compiling = 0; 2091 if (catched) { 2092 cache->errors ++; 2093 zend_bailout(); 2094 } 2095 return compiler->new_php.op_array; 2141 return op_array; 2142 } 2096 2143 } 2097 2144 /* }}} */ … … 2131 2178 /* }}} */ 2132 2179 2133 op_array = xc_compile_file_ ex(&compiler, h, type TSRMLS_CC);2180 op_array = xc_compile_file_cached(&compiler, h, type TSRMLS_CC); 2134 2181 2135 2182 xc_entry_free_key_php(&compiler.new_entry TSRMLS_CC); -
trunk/xcache.h
r936 r937 465 465 } xc_entry_hash_t; 466 466 /* }}} */ 467 typedef struct xc_compiler_t { /* {{{ */468 const char *filename;469 size_t filename_len;470 const char *opened_path;471 char opened_path_buffer[MAXPATHLEN];472 473 xc_entry_hash_t entry_hash;474 xc_entry_php_t new_entry;475 xc_entry_data_php_t new_php;476 } xc_compiler_t;477 /* }}} */478 467 479 468 extern zend_module_entry xcache_module_entry;

