Use the more-asserts crate in more places.
This provides assert_le, assert_lt, and so on, which can print the values of the operands.
This commit is contained in:
@@ -33,6 +33,7 @@ use cranelift_wasm::{
|
||||
GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex,
|
||||
};
|
||||
use indexmap;
|
||||
use more_asserts::assert_lt;
|
||||
use thiserror::Error;
|
||||
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
|
||||
|
||||
@@ -458,7 +459,7 @@ impl Instance {
|
||||
(body, self.vmctx_mut() as *mut VMContext)
|
||||
}
|
||||
None => {
|
||||
assert!(index.index() < self.module.imported_funcs.len());
|
||||
assert_lt!(index.index(), self.module.imported_funcs.len());
|
||||
let import = self.imported_function(index);
|
||||
(import.body, import.vmctx)
|
||||
}
|
||||
@@ -526,7 +527,7 @@ impl Instance {
|
||||
let index = DefinedTableIndex::new(
|
||||
(end as usize - begin as usize) / mem::size_of::<VMTableDefinition>(),
|
||||
);
|
||||
assert!(index.index() < self.tables.len());
|
||||
assert_lt!(index.index(), self.tables.len());
|
||||
index
|
||||
}
|
||||
|
||||
@@ -542,7 +543,7 @@ impl Instance {
|
||||
let index = DefinedMemoryIndex::new(
|
||||
(end as usize - begin as usize) / mem::size_of::<VMMemoryDefinition>(),
|
||||
);
|
||||
assert!(index.index() < self.memories.len());
|
||||
assert_lt!(index.index(), self.memories.len());
|
||||
index
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::mmap::Mmap;
|
||||
use crate::vmcontext::VMMemoryDefinition;
|
||||
use alloc::string::String;
|
||||
use core::convert::TryFrom;
|
||||
use more_asserts::{assert_ge, assert_le};
|
||||
use wasmtime_environ::{MemoryPlan, MemoryStyle, WASM_MAX_PAGES, WASM_PAGE_SIZE};
|
||||
|
||||
/// A linear memory instance.
|
||||
@@ -33,7 +34,7 @@ impl LinearMemory {
|
||||
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
|
||||
pub fn new(plan: &MemoryPlan) -> Result<Self, String> {
|
||||
// `maximum` cannot be set to more than `65536` pages.
|
||||
assert!(plan.memory.minimum <= WASM_MAX_PAGES);
|
||||
assert_le!(plan.memory.minimum, WASM_MAX_PAGES);
|
||||
assert!(plan.memory.maximum.is_none() || plan.memory.maximum.unwrap() <= WASM_MAX_PAGES);
|
||||
|
||||
let offset_guard_bytes = plan.offset_guard_size as usize;
|
||||
@@ -50,7 +51,7 @@ impl LinearMemory {
|
||||
let minimum_pages = match plan.style {
|
||||
MemoryStyle::Dynamic => plan.memory.minimum,
|
||||
MemoryStyle::Static { bound } => {
|
||||
assert!(bound >= plan.memory.minimum);
|
||||
assert_ge!(bound, plan.memory.minimum);
|
||||
bound
|
||||
}
|
||||
} as usize;
|
||||
|
||||
@@ -7,6 +7,8 @@ use core::ptr;
|
||||
use core::slice;
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use libc;
|
||||
use more_asserts::assert_le;
|
||||
use more_asserts::assert_lt;
|
||||
use region;
|
||||
use std::io;
|
||||
|
||||
@@ -51,7 +53,7 @@ impl Mmap {
|
||||
mapping_size: usize,
|
||||
) -> Result<Self, String> {
|
||||
let page_size = region::page::size();
|
||||
assert!(accessible_size <= mapping_size);
|
||||
assert_le!(accessible_size, mapping_size);
|
||||
assert_eq!(mapping_size & (page_size - 1), 0);
|
||||
assert_eq!(accessible_size & (page_size - 1), 0);
|
||||
|
||||
@@ -123,7 +125,7 @@ impl Mmap {
|
||||
use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_NOACCESS, PAGE_READWRITE};
|
||||
|
||||
let page_size = region::page::size();
|
||||
assert!(accessible_size <= mapping_size);
|
||||
assert_le!(accessible_size, mapping_size);
|
||||
assert_eq!(mapping_size & (page_size - 1), 0);
|
||||
assert_eq!(accessible_size & (page_size - 1), 0);
|
||||
|
||||
@@ -175,8 +177,8 @@ impl Mmap {
|
||||
let page_size = region::page::size();
|
||||
assert_eq!(start & (page_size - 1), 0);
|
||||
assert_eq!(len & (page_size - 1), 0);
|
||||
assert!(len < self.len);
|
||||
assert!(start < self.len - len);
|
||||
assert_lt!(len, self.len);
|
||||
assert_lt!(start, self.len - len);
|
||||
|
||||
// Commit the accessible size.
|
||||
unsafe { region::protect(self.ptr.add(start), len, region::Protection::ReadWrite) }
|
||||
@@ -194,8 +196,8 @@ impl Mmap {
|
||||
let page_size = region::page::size();
|
||||
assert_eq!(start & (page_size - 1), 0);
|
||||
assert_eq!(len & (page_size - 1), 0);
|
||||
assert!(len < self.len);
|
||||
assert!(start < self.len - len);
|
||||
assert_lt!(len, self.len);
|
||||
assert_lt!(start, self.len - len);
|
||||
|
||||
// Commit the accessible size.
|
||||
if unsafe {
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::vmcontext::VMSharedSignatureIndex;
|
||||
use crate::{hash_map, HashMap};
|
||||
use core::convert::TryFrom;
|
||||
use cranelift_codegen::ir;
|
||||
use more_asserts::{assert_lt, debug_assert_lt};
|
||||
|
||||
/// WebAssembly requires that the caller and callee signatures in an indirect
|
||||
/// call must match. To implement this efficiently, keep a registry of all
|
||||
@@ -31,8 +32,9 @@ impl SignatureRegistry {
|
||||
hash_map::Entry::Vacant(entry) => {
|
||||
// Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(core::u32::MAX)
|
||||
// is reserved for VMSharedSignatureIndex::default().
|
||||
debug_assert!(
|
||||
len < core::u32::MAX as usize,
|
||||
debug_assert_lt!(
|
||||
len,
|
||||
core::u32::MAX as usize,
|
||||
"Invariant check: signature_hash.len() < core::u32::MAX"
|
||||
);
|
||||
let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap());
|
||||
|
||||
@@ -260,15 +260,16 @@ pub struct VMGlobalDefinition {
|
||||
mod test_vmglobal_definition {
|
||||
use super::VMGlobalDefinition;
|
||||
use core::mem::{align_of, size_of};
|
||||
use more_asserts::assert_ge;
|
||||
use wasmtime_environ::{Module, VMOffsets};
|
||||
|
||||
#[test]
|
||||
fn check_vmglobal_definition_alignment() {
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<i32>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<i64>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<f32>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<f64>());
|
||||
assert!(align_of::<VMGlobalDefinition>() >= align_of::<[u8; 16]>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<i32>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<i64>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<f32>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<f64>());
|
||||
assert_ge!(align_of::<VMGlobalDefinition>(), align_of::<[u8; 16]>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user