From d3c75a38fa5c7923020175326cdad43950f6d463 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 11:46:43 +0200 Subject: [PATCH 1/9] fix(runtime-c-api) `wasmer_instance_call` types matches `wasmer_export_func_*_arity`. The `wasmer_export_func_params_arity` and `wasmer_export_func_returns_arity` functions store the arity in a `uint32_t`. The `wasmer_instance_call` expects `c_int`. There is a type mismatch here. It's not annoying in C or C++, but in some other languages that have bindings to C/C++, it can imply useless casting. This patch changes `wasmer_instance_call` to expect `uint32_t` for `params_len` and `results_len` to match the `wasmer_export_func_*_arity` functions. --- lib/runtime-c-api/src/instance.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 87972060d..dfd7f2a14 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -125,9 +125,9 @@ pub unsafe extern "C" fn wasmer_instance_call( instance: *mut wasmer_instance_t, name: *const c_char, params: *const wasmer_value_t, - params_len: c_int, + params_len: uint32_t, results: *mut wasmer_value_t, - results_len: c_int, + results_len: uint32_t, ) -> wasmer_result_t { if instance.is_null() { update_last_error(CApiError { From f68379a6df7c9d802666c564f9bc1cbba6883c64 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 11:49:40 +0200 Subject: [PATCH 2/9] test(runtime-c-api) Use `*_arity` variables when calling `wasmer_export_func_call`. --- lib/runtime-c-api/tests/test-exports.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/runtime-c-api/tests/test-exports.c b/lib/runtime-c-api/tests/test-exports.c index 951c4f3a4..77ff6683b 100644 --- a/lib/runtime-c-api/tests/test-exports.c +++ b/lib/runtime-c-api/tests/test-exports.c @@ -60,7 +60,6 @@ int main() assert(returns_sig[0] == WASM_I32); free(returns_sig); - wasmer_value_t param_one; param_one.tag = WASM_I32; param_one.value.I32 = 7; @@ -71,7 +70,7 @@ int main() wasmer_value_t result_one; wasmer_value_t results[] = {result_one}; - wasmer_result_t call_result = wasmer_export_func_call(func, params, 2, results, 1); + wasmer_result_t call_result = wasmer_export_func_call(func, params, params_arity, results, returns_arity); printf("Call result: %d\n", call_result); printf("Result: %d\n", results[0].value.I32); assert(results[0].value.I32 == 15); From 2b250c30f32eeeefc1b9025fbdbd1adb62c3e205 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 11:50:10 +0200 Subject: [PATCH 3/9] chore(runtime-c-api) Regenerate C/C++ header files. --- lib/runtime-c-api/wasmer.h | 4 ++-- lib/runtime-c-api/wasmer.hh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index d11deab11..bb65a3ace 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -390,9 +390,9 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance, const char *name, const wasmer_value_t *params, - int params_len, + uint32_t params_len, wasmer_value_t *results, - int results_len); + uint32_t results_len); /** * Gets the `data` field within the context. diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 7b22732d0..ae36a0d86 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -313,9 +313,9 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance, const char *name, const wasmer_value_t *params, - int params_len, + uint32_t params_len, wasmer_value_t *results, - int results_len); + uint32_t results_len); /// Gets the `data` field within the context. void *wasmer_instance_context_data_get(const wasmer_instance_context_t *ctx); From 07499329ddcd209fa9a5d0cf8a25ef2e392f9a2a Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 11:54:13 +0200 Subject: [PATCH 4/9] chore(changelog) Add #440. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d7e67e6..0a3ff1a2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#440](https://github.com/wasmerio/wasmer/pull/440) Fix type mismatch between `wasmer_instance_call` and `wasmer_export_func_*_arity` functions in the runtime C API. - [#269](https://github.com/wasmerio/wasmer/pull/269) Add better runtime docs - [#432](https://github.com/wasmerio/wasmer/pull/432) Fix returned value of `wasmer_last_error_message` in the runtime C API - [#429](https://github.com/wasmerio/wasmer/pull/429) Get wasi::path_filestat_get working for some programs; misc. minor WASI FS improvements From 91006bab5330f8364c5dbc834412a663e70d01bb Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 16:15:36 +0200 Subject: [PATCH 5/9] fix(runtime-c-api) Update `wasmer_export_func_params_arity` signature. The `params_len` argument type of `wasmer_export_func_params_arity` must be `uint32_t` to match the `wasmer_export_func_*_arity` results, so that casts are not required. --- lib/runtime-c-api/src/export.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-c-api/src/export.rs b/lib/runtime-c-api/src/export.rs index 7a7bbd47b..ed9d3534d 100644 --- a/lib/runtime-c-api/src/export.rs +++ b/lib/runtime-c-api/src/export.rs @@ -222,7 +222,7 @@ pub unsafe extern "C" fn wasmer_export_func_params_arity( pub unsafe extern "C" fn wasmer_export_func_params( func: *const wasmer_export_func_t, params: *mut wasmer_value_tag, - params_len: c_int, + params_len: uint32_t, ) -> wasmer_result_t { let named_export = &*(func as *const NamedExport); let export = &named_export.export; From 53661385eda678851ab77cfc4498c0649bb327b2 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 16:17:13 +0200 Subject: [PATCH 6/9] chore(runtime-c-api) Update C/C++ header files. --- lib/runtime-c-api/wasmer.h | 2 +- lib/runtime-c-api/wasmer.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index bb65a3ace..d5b628032 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -197,7 +197,7 @@ wasmer_result_t wasmer_export_func_call(const wasmer_export_func_t *func, */ wasmer_result_t wasmer_export_func_params(const wasmer_export_func_t *func, wasmer_value_tag *params, - int params_len); + uint32_t params_len); /** * Sets the result parameter to the arity of the params of the wasmer_export_func_t diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index ae36a0d86..8293ab2e7 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -178,7 +178,7 @@ wasmer_result_t wasmer_export_func_call(const wasmer_export_func_t *func, /// and `wasmer_last_error_message` to get an error message. wasmer_result_t wasmer_export_func_params(const wasmer_export_func_t *func, wasmer_value_tag *params, - int params_len); + uint32_t params_len); /// Sets the result parameter to the arity of the params of the wasmer_export_func_t /// Returns `wasmer_result_t::WASMER_OK` upon success. From f04e77323b1a4660688d19b5f288bd7d69e39cc0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 16:18:41 +0200 Subject: [PATCH 7/9] fix(runtime-c-api) Update `wasmer_export_func_params_arity` signature. The `returns_len` argument type of `wasmer_export_func_returns_params` must be `uint32_t` to match the `wasmer_export_func_returns_arity` results, so that casts are not required. --- lib/runtime-c-api/src/export.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-c-api/src/export.rs b/lib/runtime-c-api/src/export.rs index ed9d3534d..cd9f69b66 100644 --- a/lib/runtime-c-api/src/export.rs +++ b/lib/runtime-c-api/src/export.rs @@ -252,7 +252,7 @@ pub unsafe extern "C" fn wasmer_export_func_params( pub unsafe extern "C" fn wasmer_export_func_returns( func: *const wasmer_export_func_t, returns: *mut wasmer_value_tag, - returns_len: c_int, + returns_len: uint32_t, ) -> wasmer_result_t { let named_export = &*(func as *const NamedExport); let export = &named_export.export; From 8bd9bbb508450e66a8198afa58c6bb1df1a2d3c2 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 14 May 2019 16:19:32 +0200 Subject: [PATCH 8/9] chore(runtime-c-api) Update C/C++ header files. --- lib/runtime-c-api/wasmer.h | 2 +- lib/runtime-c-api/wasmer.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index d5b628032..1e4941d36 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -215,7 +215,7 @@ wasmer_result_t wasmer_export_func_params_arity(const wasmer_export_func_t *func */ wasmer_result_t wasmer_export_func_returns(const wasmer_export_func_t *func, wasmer_value_tag *returns, - int returns_len); + uint32_t returns_len); /** * Sets the result parameter to the arity of the returns of the wasmer_export_func_t diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 8293ab2e7..12b5b0c70 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -192,7 +192,7 @@ wasmer_result_t wasmer_export_func_params_arity(const wasmer_export_func_t *func /// and `wasmer_last_error_message` to get an error message. wasmer_result_t wasmer_export_func_returns(const wasmer_export_func_t *func, wasmer_value_tag *returns, - int returns_len); + uint32_t returns_len); /// Sets the result parameter to the arity of the returns of the wasmer_export_func_t /// Returns `wasmer_result_t::WASMER_OK` upon success. From 5114d4223772249db0c5d93ffb32d6e494d3f062 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 14 May 2019 14:05:41 -0700 Subject: [PATCH 9/9] fix borrowing warning on nightly --- lib/wasi/src/syscalls/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 0389273fc..f82b9f9e8 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -788,15 +788,13 @@ pub fn fd_renumber(ctx: &mut Ctx, from: __wasi_fd_t, to: __wasi_fd_t) -> __wasi_ debug!("wasi::fd_renumber: from={}, to={}", from, to); let state = get_wasi_state(ctx); let fd_entry = wasi_try!(state.fs.fd_map.get(&from).ok_or(__WASI_EBADF)); + let new_fd_entry = Fd { + // TODO: verify this is correct + rights: fd_entry.rights_inheriting, + ..*fd_entry + }; - state.fs.fd_map.insert( - to, - Fd { - // TODO: verify this is correct - rights: fd_entry.rights_inheriting, - ..*fd_entry - }, - ); + state.fs.fd_map.insert(to, new_fd_entry); __WASI_ESUCCESS }