From 4c5bf193431dd48ae8d0be9e0ee8b0194592a95f Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Tue, 8 Sep 2020 13:31:14 -0700 Subject: [PATCH] Fix bug relating to type conversion in function calls --- CHANGELOG.md | 1 + lib/api/src/externals/function.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d24118bfb4..68f1ad30a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## **[Unreleased]** +- [#1602](https://github.com/wasmerio/wasmer/pull/1602) Fix panic when calling host functions with negative numbers in certain situations - [#1590](https://github.com/wasmerio/wasmer/pull/1590) Fix soundness issue in API of vm::Global - [#1566](https://github.com/wasmerio/wasmer/pull/1566) Add support for opening special Unix files to the WASI FS diff --git a/lib/api/src/externals/function.rs b/lib/api/src/externals/function.rs index b0cc211aa81..b1cd280563a 100644 --- a/lib/api/src/externals/function.rs +++ b/lib/api/src/externals/function.rs @@ -621,11 +621,39 @@ mod inner { }; } + macro_rules! from_to_native_wasm_type_same_size { + ( $( $type:ty => $native_type:ty ),* ) => { + $( + #[allow(clippy::use_self)] + unsafe impl FromToNativeWasmType for $type { + type Native = $native_type; + + #[inline] + fn from_native(native: Self::Native) -> Self { + unsafe { + std::mem::transmute::<$native_type, $type>(native) + } + } + + #[inline] + fn to_native(self) -> Self::Native { + unsafe { + std::mem::transmute::<$type, $native_type>(self) + } + } + } + )* + }; + } + from_to_native_wasm_type!( i8 => i32, u8 => i32, i16 => i32, - u16 => i32, + u16 => i32 + ); + + from_to_native_wasm_type_same_size!( i32 => i32, u32 => i32, i64 => i64,