Skip to content

Commit a73e457

Browse files
authored
Merge branch 'master' into feat-c-api-update-wasm-h
2 parents 9955da1 + 1bb3b99 commit a73e457

File tree

12 files changed

+110
-46
lines changed

12 files changed

+110
-46
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- [#1699](https://github.com/wasmerio/wasmer/pull/1699) Update `wasm.h` to its latest version.
1313
- [#1685](https://github.com/wasmerio/wasmer/pull/1685) Implement `wasm_exporttype_delete` in the Wasm C API.
14+
- [#1725](https://github.com/wasmerio/wasmer/pull/1725) Implement `wasm_func_type` in the Wasm C API.
1415
- [#1715](https://github.com/wasmerio/wasmer/pull/1715) Register errors from `wasm_module_serialize` in the Wasm C API.
1516
- [#1709](https://github.com/wasmerio/wasmer/pull/1709) Implement `wasm_module_name` and `wasm_module_set_name` in the Wasm(er) C API.
1617
- [#1700](https://github.com/wasmerio/wasmer/pull/1700) Implement `wasm_externtype_copy` in the Wasm C API.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
* **Pluggable**. Wasmer supports different compilation frameworks to best suit your needs (LLVM, Cranelift...).
3737

38-
* **Universal**. You can run Wasmer in almost any *platform* (macOS, Linux and Windows) and *chipset*.
38+
* **Universal**. You can run Wasmer in any *platform* (macOS, Linux and Windows) and *chipset*.
3939

4040
* **Standards compliant**. The runtime passes [official WebAssembly test
4141
suite](https://github.com/WebAssembly/testsuite) supporting [WASI](https://github.com/WebAssembly/WASI) and [Emscripten](https://emscripten.org/).

lib/c-api/src/wasm_c_api/externals/function.rs

+5
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ pub unsafe extern "C" fn wasm_func_param_arity(func: &wasm_func_t) -> usize {
176176
pub unsafe extern "C" fn wasm_func_result_arity(func: &wasm_func_t) -> usize {
177177
func.inner.ty().results().len()
178178
}
179+
180+
#[no_mangle]
181+
pub extern "C" fn wasm_func_type(func: &wasm_func_t) -> Box<wasm_functype_t> {
182+
Box::new(wasm_functype_t::new(func.inner.ty().clone()))
183+
}

lib/c-api/src/wasm_c_api/types/function.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ impl wasm_functype_t {
1717
unreachable!("data corruption: `wasm_functype_t` does not contain a function")
1818
}
1919
}
20+
21+
pub(crate) fn new(function_type: FunctionType) -> Self {
22+
Self {
23+
extern_: wasm_externtype_t {
24+
inner: ExternType::Function(function_type),
25+
},
26+
}
27+
}
2028
}
2129

2230
wasm_declare_vec!(functype);
@@ -52,10 +60,9 @@ unsafe fn wasm_functype_new_inner(
5260
.map(Into::into)
5361
.collect::<Vec<_>>();
5462

55-
let extern_ = wasm_externtype_t {
56-
inner: ExternType::Function(FunctionType::new(params, results)),
57-
};
58-
Some(Box::new(wasm_functype_t { extern_ }))
63+
Some(Box::new(wasm_functype_t::new(FunctionType::new(
64+
params, results,
65+
))))
5966
}
6067

6168
#[no_mangle]

lib/compiler-llvm/src/translator/code.rs

+56
Original file line numberDiff line numberDiff line change
@@ -6286,6 +6286,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
62866286
offset,
62876287
4,
62886288
)?;
6289+
let dead_load = self.builder.build_load(effective_address, "");
6290+
self.annotate_user_memaccess(
6291+
memory_index,
6292+
memarg,
6293+
1,
6294+
dead_load.as_instruction_value().unwrap(),
6295+
)?;
62896296
let store = self.builder.build_store(effective_address, value);
62906297
self.annotate_user_memaccess(memory_index, memarg, 1, store)?;
62916298
}
@@ -6300,6 +6307,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
63006307
offset,
63016308
8,
63026309
)?;
6310+
let dead_load = self.builder.build_load(effective_address, "");
6311+
self.annotate_user_memaccess(
6312+
memory_index,
6313+
memarg,
6314+
1,
6315+
dead_load.as_instruction_value().unwrap(),
6316+
)?;
63036317
let store = self.builder.build_store(effective_address, value);
63046318
self.annotate_user_memaccess(memory_index, memarg, 1, store)?;
63056319
}
@@ -6315,6 +6329,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
63156329
offset,
63166330
4,
63176331
)?;
6332+
let dead_load = self.builder.build_load(effective_address, "");
6333+
self.annotate_user_memaccess(
6334+
memory_index,
6335+
memarg,
6336+
1,
6337+
dead_load.as_instruction_value().unwrap(),
6338+
)?;
63186339
let store = self.builder.build_store(effective_address, v);
63196340
self.annotate_user_memaccess(memory_index, memarg, 1, store)?;
63206341
}
@@ -6330,6 +6351,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
63306351
offset,
63316352
8,
63326353
)?;
6354+
let dead_load = self.builder.build_load(effective_address, "");
6355+
self.annotate_user_memaccess(
6356+
memory_index,
6357+
memarg,
6358+
1,
6359+
dead_load.as_instruction_value().unwrap(),
6360+
)?;
63336361
let store = self.builder.build_store(effective_address, v);
63346362
self.annotate_user_memaccess(memory_index, memarg, 1, store)?;
63356363
}
@@ -6345,6 +6373,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
63456373
offset,
63466374
16,
63476375
)?;
6376+
let dead_load = self.builder.build_load(effective_address, "");
6377+
self.annotate_user_memaccess(
6378+
memory_index,
6379+
memarg,
6380+
1,
6381+
dead_load.as_instruction_value().unwrap(),
6382+
)?;
63486383
let store = self.builder.build_store(effective_address, v);
63496384
self.annotate_user_memaccess(memory_index, memarg, 1, store)?;
63506385
}
@@ -6603,6 +6638,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
66036638
offset,
66046639
1,
66056640
)?;
6641+
let dead_load = self.builder.build_load(effective_address, "");
6642+
self.annotate_user_memaccess(
6643+
memory_index,
6644+
memarg,
6645+
1,
6646+
dead_load.as_instruction_value().unwrap(),
6647+
)?;
66066648
let narrow_value =
66076649
self.builder
66086650
.build_int_truncate(value, self.intrinsics.i8_ty, "");
@@ -6620,6 +6662,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
66206662
offset,
66216663
2,
66226664
)?;
6665+
let dead_load = self.builder.build_load(effective_address, "");
6666+
self.annotate_user_memaccess(
6667+
memory_index,
6668+
memarg,
6669+
1,
6670+
dead_load.as_instruction_value().unwrap(),
6671+
)?;
66236672
let narrow_value =
66246673
self.builder
66256674
.build_int_truncate(value, self.intrinsics.i16_ty, "");
@@ -6637,6 +6686,13 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
66376686
offset,
66386687
4,
66396688
)?;
6689+
let dead_load = self.builder.build_load(effective_address, "");
6690+
self.annotate_user_memaccess(
6691+
memory_index,
6692+
memarg,
6693+
1,
6694+
dead_load.as_instruction_value().unwrap(),
6695+
)?;
66406696
let narrow_value =
66416697
self.builder
66426698
.build_int_truncate(value, self.intrinsics.i32_ty, "");

tests/compilers/imports.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn get_module(store: &Store) -> Result<Module> {
4343

4444
#[test]
4545
fn dynamic_function() -> Result<()> {
46-
let store = get_store();
46+
let store = get_store(false);
4747
let module = get_module(&store)?;
4848
static HITS: AtomicUsize = AtomicUsize::new(0);
4949
Instance::new(
@@ -83,7 +83,7 @@ fn dynamic_function() -> Result<()> {
8383

8484
#[test]
8585
fn dynamic_function_with_env() -> Result<()> {
86-
let store = get_store();
86+
let store = get_store(false);
8787
let module = get_module(&store)?;
8888

8989
let env: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
@@ -124,7 +124,7 @@ fn dynamic_function_with_env() -> Result<()> {
124124

125125
#[test]
126126
fn static_function() -> Result<()> {
127-
let store = get_store();
127+
let store = get_store(false);
128128
let module = get_module(&store)?;
129129

130130
static HITS: AtomicUsize = AtomicUsize::new(0);
@@ -162,7 +162,7 @@ fn static_function() -> Result<()> {
162162

163163
#[test]
164164
fn static_function_with_results() -> Result<()> {
165-
let store = get_store();
165+
let store = get_store(false);
166166
let module = get_module(&store)?;
167167

168168
static HITS: AtomicUsize = AtomicUsize::new(0);
@@ -200,7 +200,7 @@ fn static_function_with_results() -> Result<()> {
200200

201201
#[test]
202202
fn static_function_with_env() -> Result<()> {
203-
let store = get_store();
203+
let store = get_store(false);
204204
let module = get_module(&store)?;
205205

206206
let env: Arc<AtomicUsize> = Arc::new(AtomicUsize::new(0));
@@ -238,7 +238,7 @@ fn static_function_with_env() -> Result<()> {
238238

239239
#[test]
240240
fn static_function_that_fails() -> Result<()> {
241-
let store = get_store();
241+
let store = get_store(false);
242242
let wat = r#"
243243
(import "host" "0" (func))
244244

tests/compilers/multi_value_imports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! mvr_test {
3939
#[test]
4040
#[cfg_attr(any(feature = "test-cranelift", feature="test-singlepass"), ignore)]
4141
fn native() -> anyhow::Result<()> {
42-
let store = get_store();
42+
let store = get_store(false);
4343
let module = get_module(&store)?;
4444
let instance = wasmer::Instance::new(
4545
&module,
@@ -65,7 +65,7 @@ macro_rules! mvr_test {
6565
#[test]
6666
#[cfg_attr(feature="test-singlepass", ignore)]
6767
fn dynamic() -> anyhow::Result<()> {
68-
let store = get_store();
68+
let store = get_store(false);
6969
let module = get_module(&store)?;
7070
let callback_fn = wasmer::Function::new(&store, &wasmer::FunctionType::new(vec![wasmer::ValType::I32], vec![ $( <$result_type>::expected_valtype() ),* ]), dynamic_callback_fn);
7171
let instance = wasmer::Instance::new(

tests/compilers/native_functions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use wasmer::*;
88

99
#[test]
1010
fn native_function_works_for_wasm() -> Result<()> {
11-
let store = get_store();
11+
let store = get_store(false);
1212
let wat = r#"(module
1313
(func $multiply (import "env" "multiply") (param i32 i32) (result i32))
1414
(func (export "add") (param i32 i32) (result i32)
@@ -52,7 +52,7 @@ fn native_function_works_for_wasm() -> Result<()> {
5252

5353
#[test]
5454
fn static_host_function_without_env() -> anyhow::Result<()> {
55-
let store = get_store();
55+
let store = get_store(false);
5656

5757
fn f(a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) {
5858
(d * 4.0, c * 3.0, b * 2, a * 1)
@@ -83,7 +83,7 @@ fn static_host_function_without_env() -> anyhow::Result<()> {
8383

8484
#[test]
8585
fn static_host_function_with_env() -> anyhow::Result<()> {
86-
let store = get_store();
86+
let store = get_store(false);
8787

8888
fn f(env: &mut Env, a: i32, b: i64, c: f32, d: f64) -> (f64, f32, i64, i32) {
8989
assert_eq!(*env.0.borrow(), 100);
@@ -143,7 +143,7 @@ fn static_host_function_with_env() -> anyhow::Result<()> {
143143

144144
#[test]
145145
fn dynamic_host_function_without_env() -> anyhow::Result<()> {
146-
let store = get_store();
146+
let store = get_store(false);
147147

148148
let f = Function::new(
149149
&store,
@@ -170,7 +170,7 @@ fn dynamic_host_function_without_env() -> anyhow::Result<()> {
170170

171171
#[test]
172172
fn dynamic_host_function_with_env() -> anyhow::Result<()> {
173-
let store = get_store();
173+
let store = get_store(false);
174174

175175
#[derive(Clone)]
176176
struct Env(Rc<RefCell<i32>>);

tests/compilers/serialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use wasmer::*;
44

55
#[test]
66
fn test_serialize() -> Result<()> {
7-
let store = get_store();
7+
let store = get_store(false);
88
let wat = r#"
99
(module
1010
(func $hello (import "" "hello"))
@@ -20,7 +20,7 @@ fn test_serialize() -> Result<()> {
2020

2121
#[test]
2222
fn test_deserialize() -> Result<()> {
23-
let store = get_store();
23+
let store = get_store(false);
2424
let wat = r#"
2525
(module $name
2626
(import "host" "sum_part" (func (param i32 i64 i32 f32 f64) (result i64)))

0 commit comments

Comments
 (0)