Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fink committed Nov 22, 2023
1 parent 432c7c5 commit 9d408c3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 49 deletions.
4 changes: 2 additions & 2 deletions cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::cell::Cell;
pub use super::MachLabel;
use super::RetPair;
pub use crate::ir::{
condcodes::CondCode, dynamic_to_fixed, Constant, DynamicStackSlot, ExternalName,
FuncRef, GlobalValue, Immediate, SigRef, StackSlot,
condcodes::CondCode, dynamic_to_fixed, Constant, DynamicStackSlot, ExternalName, FuncRef,
GlobalValue, Immediate, SigRef, StackSlot,
};
pub use crate::isa::{unwind::UnwindInst, TargetIsa};
pub use crate::machinst::{
Expand Down
33 changes: 15 additions & 18 deletions cranelift/wasm/src/func_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,11 @@ mod tests {

let mut trans = FuncTranslator::new();
let flags = settings::Flags::new(settings::builder());
let runtime = DummyEnvironment::new(
isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
has_mte: false,
});
let runtime = DummyEnvironment::new(isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
has_mte: false,
});

let mut ctx = Context::new();

Expand Down Expand Up @@ -360,12 +359,11 @@ mod tests {

let mut trans = FuncTranslator::new();
let flags = settings::Flags::new(settings::builder());
let runtime = DummyEnvironment::new(
isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
has_mte: false,
});
let runtime = DummyEnvironment::new(isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
has_mte: false,
});

let mut ctx = Context::new();

Expand Down Expand Up @@ -402,12 +400,11 @@ mod tests {

let mut trans = FuncTranslator::new();
let flags = settings::Flags::new(settings::builder());
let runtime = DummyEnvironment::new(
isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
has_mte: false,
});
let runtime = DummyEnvironment::new(isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
has_mte: false,
});

let mut ctx = Context::new();

Expand Down
31 changes: 16 additions & 15 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,19 +1846,20 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m

// If we have a declared maximum, we can make this a "static" heap, which is
// allocated up front and never moved.
let (offset_guard_size, heap_style, readonly_base, base_fact, memory_type) = match self.module.memory_plans[index] {
MemoryPlan {
style: MemoryStyle::Dynamic { .. },
offset_guard_size,
pre_guard_size: _,
memory: _,
mte_protected: _,
} => {
let heap_bound = func.create_global_value(ir::GlobalValueData::Load {
base: ptr,
offset: Offset32::new(current_length_offset),
global_type: pointer_type,
flags: MemFlags::trusted(),
let (offset_guard_size, heap_style, readonly_base, base_fact, memory_type) =
match self.module.memory_plans[index] {
MemoryPlan {
style: MemoryStyle::Dynamic { .. },
offset_guard_size,
pre_guard_size: _,
memory: _,
mte_protected: _,
} => {
let heap_bound = func.create_global_value(ir::GlobalValueData::Load {
base: ptr,
offset: Offset32::new(current_length_offset),
global_type: pointer_type,
flags: MemFlags::trusted(),
});

let (base_fact, data_mt) = if let Some(ptr_memtype) = ptr_memtype {
Expand Down Expand Up @@ -1929,8 +1930,8 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
offset_guard_size,
pre_guard_size: _,
memory: _,
mte_protected: _,
} => {
mte_protected: _,
} => {
let bound_bytes = u64::from(bound_pages) * u64::from(WASM_PAGE_SIZE);
let (base_fact, data_mt) = if let Some(ptr_memtype) = ptr_memtype {
// Create a memtype representing the untyped memory region.
Expand Down
12 changes: 10 additions & 2 deletions crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,20 @@ impl Instance {
}

fn validate_inbounds(&self, max: usize, ptr: u64, len: u64) -> Result<usize, Trap> {
#[cfg(all(target_arch = "aarch64", any(target_os = "linux", target_os = "android"), target_feature = "mte"))]
#[cfg(all(
target_arch = "aarch64",
any(target_os = "linux", target_os = "android"),
target_feature = "mte"
))]
fn strip_mte_tag(ptr: u64) -> u64 {
ptr & 0xF0FF_FFFF_FFFF_FFFF
}

#[cfg(not(all(target_arch = "aarch64", any(target_os = "linux", target_os = "android"), target_feature = "mte")))]
#[cfg(not(all(
target_arch = "aarch64",
any(target_os = "linux", target_os = "android"),
target_feature = "mte"
)))]
fn strip_mte_tag(ptr: u64) -> u64 {
ptr
}
Expand Down
3 changes: 2 additions & 1 deletion crates/runtime/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ impl RuntimeLinearMemory for MmapMemory {
.and_then(|s| s.checked_add(self.offset_guard_size))
.ok_or_else(|| format_err!("overflow calculating size of memory allocation"))?;

let mut new_mmap = Mmap::accessible_reserved(0, request_bytes, self.mmap.mte_protected())?;
let mut new_mmap =
Mmap::accessible_reserved(0, request_bytes, self.mmap.mte_protected())?;
new_mmap.make_accessible(self.pre_guard_size, new_size)?;

// This method has an exclusive reference to `self.mmap` and just
Expand Down
6 changes: 5 additions & 1 deletion crates/runtime/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ impl Mmap {
///
/// This function will panic if `accessible_size` is greater than
/// `mapping_size` or if either of them are not page-aligned.
pub fn accessible_reserved(accessible_size: usize, mapping_size: usize, mte_protected: bool) -> Result<Self> {
pub fn accessible_reserved(
accessible_size: usize,
mapping_size: usize,
mte_protected: bool,
) -> Result<Self> {
let page_size = crate::page_size();
assert!(accessible_size <= mapping_size);
assert_eq!(mapping_size & (page_size - 1), 0);
Expand Down
21 changes: 16 additions & 5 deletions crates/runtime/src/mmap/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ impl Mmap {
}

/// Make memory accessible while enabling mte
#[cfg(all(target_arch = "aarch64", any(target_os = "linux", target_os = "android"), target_feature = "mte"))]
#[cfg(all(
target_arch = "aarch64",
any(target_os = "linux", target_os = "android"),
target_feature = "mte"
))]
fn make_accessible_with_mte(&mut self, start: usize, len: usize) -> Result<()> {
use std::io;

Expand Down Expand Up @@ -120,8 +124,7 @@ impl Mmap {
let ptr = unsafe { self.memory.as_ptr().cast::<u8>().add(start) };
eprintln!(
"enabling mte for memory (enable_mte): ptr = 0x{:x}, len = 0x{:x}",
ptr as usize,
len
ptr as usize, len
);

unsafe {
Expand All @@ -134,9 +137,17 @@ impl Mmap {
}

/// We don't support MTE on non arm64 linux
#[cfg(not(all(target_arch = "aarch64", any(target_os = "linux", target_os = "android"), target_feature = "mte")))]
#[cfg(not(all(
target_arch = "aarch64",
any(target_os = "linux", target_os = "android"),
target_feature = "mte"
)))]
fn make_accessible_with_mte(&mut self, _start: usize, _len: usize) -> Result<()> {
anyhow::bail!("cannot enable mte on os {}, arch {}", std::env::consts::OS, std::env::consts::ARCH)
anyhow::bail!(
"cannot enable mte on os {}, arch {}",
std::env::consts::OS,
std::env::consts::ARCH
)
}

#[inline]
Expand Down
6 changes: 1 addition & 5 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,7 @@ impl Metadata<'_> {
"relaxed simd deterministic semantics",
)?;
Self::check_bool(tail_callable, other.tail_callable, "WebAssembly tail calls")?;
Self::check_bool(
enable_mte,
other.enable_mte,
"mte protection"
)?;
Self::check_bool(enable_mte, other.enable_mte, "mte protection")?;

Ok(())
}
Expand Down

0 comments on commit 9d408c3

Please sign in to comment.