Skip to content

Commit

Permalink
fixup! feat: implement memory.atomic.notify,wait32,wait64
Browse files Browse the repository at this point in the history
Signed-off-by: Harald Hoyer <[email protected]>
  • Loading branch information
haraldh committed Nov 18, 2022
1 parent 5589129 commit ad8c894
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions crates/runtime/src/vmcontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod vm_host_func_context;

use crate::externref::VMExternRef;
use crate::instance::Instance;
use anyhow::ensure;
use std::any::Any;
use std::cell::UnsafeCell;
use std::marker;
Expand Down Expand Up @@ -227,14 +228,6 @@ pub struct VMMemoryDefinition {
pub current_length: AtomicUsize,
}

macro_rules! ensure {
($cond:expr, $trap:expr) => {
if !($cond) {
return Err($trap);
}
};
}

impl VMMemoryDefinition {
/// Return the current length of the [`VMMemoryDefinition`] by performing a
/// relaxed load; do not use this function for situations in which a precise
Expand Down Expand Up @@ -268,13 +261,15 @@ impl VMMemoryDefinition {
access_alignment: u64,
) -> Result<*const u8, TrapCode> {
debug_assert!(access_alignment.is_power_of_two());
ensure!(addr % access_alignment == 0, TrapCode::HeapMisaligned);
if !(addr % access_alignment == 0) {
return Err(TrapCode::HeapMisaligned);
}

let length = u64::try_from(self.current_length()).unwrap();
ensure!(
addr.saturating_add(access_size) < length,
TrapCode::HeapOutOfBounds
);
if !(addr.saturating_add(access_size) < length) {
return Err(TrapCode::HeapOutOfBounds);
}

// SAFETY: checked above that the address is in bounds
Ok(unsafe { self.base.add(addr as usize) })
}
Expand Down

0 comments on commit ad8c894

Please sign in to comment.