Skip to content

Commit

Permalink
Add LinearMemory::needs_init
Browse files Browse the repository at this point in the history
The function is used to report to `wasmtime` if the linear memory
requires initialization. The user is required to ensure the memory is
initialized when it reports `false`
  • Loading branch information
Eduardo Leegwater Simões committed Feb 7, 2024
1 parent ab5a448 commit 006a60c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/wasmtime/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ pub unsafe trait LinearMemory: Send + Sync + 'static {
/// Returns `Ok` if memory was grown successfully.
fn grow_to(&mut self, new_size: usize) -> Result<()>;

/// Does this memory need initialization? It may not if it already
/// has initial contents set.
///
/// The user should guarantee that the memory is initialized if this
/// reports `false`.
fn needs_init(&self) -> bool {
true
}

/// Return the allocated memory as a mutable pointer to u8.
fn as_ptr(&self) -> *mut u8;

Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/trampoline/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl RuntimeLinearMemory for LinearMemoryProxy {
}

fn needs_init(&self) -> bool {
true
self.mem.needs_init()
}

fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
Expand Down

0 comments on commit 006a60c

Please sign in to comment.