diff --git a/lib/types/src/serialize.rs b/lib/types/src/serialize.rs index 23dd7524d19..5d4c74cb5e2 100644 --- a/lib/types/src/serialize.rs +++ b/lib/types/src/serialize.rs @@ -211,7 +211,7 @@ pub struct MetadataHeader { impl MetadataHeader { /// Current ABI version. Increment this any time breaking changes are made /// to the format of the serialized data. - pub const CURRENT_VERSION: u32 = 4; + pub const CURRENT_VERSION: u32 = 5; /// Magic number to identify wasmer metadata. const MAGIC: [u8; 8] = *b"WASMER\0\0"; diff --git a/lib/types/src/vmoffsets.rs b/lib/types/src/vmoffsets.rs index 4c387f737e3..47e457fa209 100644 --- a/lib/types/src/vmoffsets.rs +++ b/lib/types/src/vmoffsets.rs @@ -12,6 +12,7 @@ use crate::{ }; use more_asserts::assert_lt; use std::convert::TryFrom; +use std::mem::size_of; /// An index type for builtin functions. #[derive(Copy, Clone, Debug)] @@ -284,34 +285,44 @@ impl VMOffsets { base.checked_add(num_items.checked_mul(item_size).unwrap()) .unwrap() } + /// Offset base by num_items items of size item_size, panicking on overflow + /// Also, will align the value on pointer size boundary, + /// to avoid misalignement issue + fn offset_by_aligned(base: u32, num_items: u32, item_size: u32) -> u32 { + align( + base.checked_add(num_items.checked_mul(item_size).unwrap()) + .unwrap(), + size_of::<&u32>() as u32, + ) + } self.vmctx_signature_ids_begin = 0; - self.vmctx_imported_functions_begin = offset_by( + self.vmctx_imported_functions_begin = offset_by_aligned( self.vmctx_signature_ids_begin, self.num_signature_ids, u32::from(self.size_of_vmshared_signature_index()), ); - self.vmctx_imported_tables_begin = offset_by( + self.vmctx_imported_tables_begin = offset_by_aligned( self.vmctx_imported_functions_begin, self.num_imported_functions, u32::from(self.size_of_vmfunction_import()), ); - self.vmctx_imported_memories_begin = offset_by( + self.vmctx_imported_memories_begin = offset_by_aligned( self.vmctx_imported_tables_begin, self.num_imported_tables, u32::from(self.size_of_vmtable_import()), ); - self.vmctx_imported_globals_begin = offset_by( + self.vmctx_imported_globals_begin = offset_by_aligned( self.vmctx_imported_memories_begin, self.num_imported_memories, u32::from(self.size_of_vmmemory_import()), ); - self.vmctx_tables_begin = offset_by( + self.vmctx_tables_begin = offset_by_aligned( self.vmctx_imported_globals_begin, self.num_imported_globals, u32::from(self.size_of_vmglobal_import()), ); - self.vmctx_memories_begin = offset_by( + self.vmctx_memories_begin = offset_by_aligned( self.vmctx_tables_begin, self.num_local_tables, u32::from(self.size_of_vmtable_definition()), diff --git a/tests/compilers/wasmu/linux/bash.wasmu b/tests/compilers/wasmu/linux/bash.wasmu index decd275c533..5b53efc16d7 100644 Binary files a/tests/compilers/wasmu/linux/bash.wasmu and b/tests/compilers/wasmu/linux/bash.wasmu differ diff --git a/tests/compilers/wasmu/linux/cowsay.wasmu b/tests/compilers/wasmu/linux/cowsay.wasmu index f38e99a2d0e..21806f10b56 100644 Binary files a/tests/compilers/wasmu/linux/cowsay.wasmu and b/tests/compilers/wasmu/linux/cowsay.wasmu differ diff --git a/tests/compilers/wasmu/linux/python-3.11.3.wasmu b/tests/compilers/wasmu/linux/python-3.11.3.wasmu index ae4cb686282..cb306294f38 100644 Binary files a/tests/compilers/wasmu/linux/python-3.11.3.wasmu and b/tests/compilers/wasmu/linux/python-3.11.3.wasmu differ diff --git a/tests/compilers/wasmu/windows/bash.wasmu b/tests/compilers/wasmu/windows/bash.wasmu index 2e450dc6b99..d2ae618b866 100644 Binary files a/tests/compilers/wasmu/windows/bash.wasmu and b/tests/compilers/wasmu/windows/bash.wasmu differ diff --git a/tests/compilers/wasmu/windows/cowsay.wasmu b/tests/compilers/wasmu/windows/cowsay.wasmu index e0730e48413..58977ce4c34 100644 Binary files a/tests/compilers/wasmu/windows/cowsay.wasmu and b/tests/compilers/wasmu/windows/cowsay.wasmu differ diff --git a/tests/compilers/wasmu/windows/python-3.11.3.wasmu b/tests/compilers/wasmu/windows/python-3.11.3.wasmu index 2fb4ac8ff43..ce686f16d20 100644 Binary files a/tests/compilers/wasmu/windows/python-3.11.3.wasmu and b/tests/compilers/wasmu/windows/python-3.11.3.wasmu differ