Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 65536 pages #2258

Closed
wants to merge 10 commits into from
Closed
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
- [#2149](https://github.com/wasmerio/wasmer/pull/2144) `wasmer-engine-native` looks for clang-11 instead of clang-10.

### Fixed
- [#2258](https://github.com/wasmerio/wasmer/pull/2258) Fixed a bug that only worked with memory size 65535 or less.
- [#2208](https://github.com/wasmerio/wasmer/pull/2208) Fix ownership in Wasm C API of `wasm_extern_as_func`, `wasm_extern_as_memory`, `wasm_extern_as_table`, `wasm_extern_as_global`, `wasm_func_as_extern`, `wasm_memory_as_extern`, `wasm_table_as_extern`, and `wasm_global_as_extern`. These functions no longer allocate memory and thus their results should not be freed. This is a breaking change to align more closely with the Wasm C API's stated ownership.
- [#2210](https://github.com/wasmerio/wasmer/pull/2210) Fix a memory leak in the Wasm C API in the strings used to identify imports and exports coming from user code.
- [#2108](https://github.com/wasmerio/wasmer/pull/2108) The Object Native Engine generates code that now compiles correctly with C++.
Expand Down
6 changes: 6 additions & 0 deletions lib/types/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ impl From<u32> for Bytes {
}
}

impl From<u64> for Bytes {
fn from(other: u64) -> Self {
Self(other.try_into().unwrap())
}
}

impl<T> Sub<T> for Pages
where
T: Into<Self>,
Expand Down
2 changes: 1 addition & 1 deletion lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ impl Instance {
.map_or(true, |n| n as usize > data.len())
|| dst
.checked_add(len)
.map_or(true, |m| m > memory.current_length)
.map_or(true, |m| u64::from(m) > memory.current_length)
{
return Err(Trap::new_from_runtime(TrapCode::HeapAccessOutOfBounds));
}
Expand Down
8 changes: 4 additions & 4 deletions lib/vm/src/vmcontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ pub struct VMMemoryDefinition {
pub base: *mut u8,

/// The current logical size of this linear memory in bytes.
pub current_length: u32,
pub current_length: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should not create a type alias to represent the memory size, something like pub type MemorySize = u64. Thoughts @nlewycky, @MarkMcCaskey, @syrusakbary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so in this case, we aren't going to be changing this type or confusing it with other values much.

}

/// # Safety
Expand Down Expand Up @@ -379,10 +379,10 @@ impl VMMemoryDefinition {
// https://webassembly.github.io/reference-types/core/exec/instructions.html#exec-memory-copy
if src
.checked_add(len)
.map_or(true, |n| n > self.current_length)
.map_or(true, |n| u64::from(n) > self.current_length)
|| dst
.checked_add(len)
.map_or(true, |m| m > self.current_length)
.map_or(true, |m| u64::from(m) > self.current_length)
{
return Err(Trap::new_from_runtime(TrapCode::HeapAccessOutOfBounds));
}
Expand Down Expand Up @@ -412,7 +412,7 @@ impl VMMemoryDefinition {
pub(crate) unsafe fn memory_fill(&self, dst: u32, val: u32, len: u32) -> Result<(), Trap> {
if dst
.checked_add(len)
.map_or(true, |m| m > self.current_length)
.map_or(true, |m| u64::from(m) > self.current_length)
{
return Err(Trap::new_from_runtime(TrapCode::HeapAccessOutOfBounds));
}
Expand Down
1 change: 1 addition & 0 deletions tests/wast/wasmer/max_size_of_memory.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(module (memory 65536))