()
| 148 | |
| 149 | #[test] |
| 150 | fn libcall_function() { |
| 151 | let Some(isa) = isa() else { |
| 152 | return; |
| 153 | }; |
| 154 | let mut module = JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())); |
| 155 | |
| 156 | let sig = Signature { |
| 157 | params: vec![], |
| 158 | returns: vec![], |
| 159 | call_conv: CallConv::SystemV, |
| 160 | }; |
| 161 | |
| 162 | let func_id = module |
| 163 | .declare_function("function", Linkage::Local, &sig) |
| 164 | .unwrap(); |
| 165 | |
| 166 | let mut ctx = Context::new(); |
| 167 | ctx.func = Function::with_name_signature(UserFuncName::user(0, func_id.as_u32()), sig); |
| 168 | |
| 169 | let mut func_ctx = FunctionBuilderContext::new(); |
| 170 | { |
| 171 | let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx); |
| 172 | let block = bcx.create_block(); |
| 173 | bcx.switch_to_block(block); |
| 174 | |
| 175 | let int = module.target_config().pointer_type(); |
| 176 | let zero = bcx.ins().iconst(I16, 0); |
| 177 | let size = bcx.ins().iconst(int, 10); |
| 178 | |
| 179 | let mut signature = module.make_signature(); |
| 180 | signature.params.push(AbiParam::new(int)); |
| 181 | signature.returns.push(AbiParam::new(int)); |
| 182 | let callee = module |
| 183 | .declare_function("malloc", Linkage::Import, &signature) |
| 184 | .expect("declare malloc function"); |
| 185 | let local_callee = module.declare_func_in_func(callee, &mut bcx.func); |
| 186 | let argument_exprs = vec![size]; |
| 187 | let call = bcx.ins().call(local_callee, &argument_exprs); |
| 188 | let buffer = bcx.inst_results(call)[0]; |
| 189 | |
| 190 | bcx.call_memset(module.target_config(), buffer, zero, size); |
| 191 | |
| 192 | bcx.ins().return_(&[]); |
| 193 | } |
| 194 | |
| 195 | module |
| 196 | .define_function_with_control_plane(func_id, &mut ctx, &mut Default::default()) |
| 197 | .unwrap(); |
| 198 | |
| 199 | module.finalize_definitions().unwrap(); |
| 200 | } |
| 201 | |
| 202 | // This used to cause UB. See https://github.com/bytecodealliance/wasmtime/issues/7918. |
| 203 | #[test] |
nothing calls this directly
no test coverage detected