Changeset 937 for trunk/disassembler.c
- Timestamp:
- 2012-06-28T11:38:30+02:00 (11 months ago)
- File:
-
- 1 edited
-
trunk/disassembler.c (modified) (7 diffs)
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 /* }}} */
Note: See TracChangeset
for help on using the changeset viewer.

