module level validation

This commit is contained in:
Svyatoslav Nikolsky
2017-06-08 10:49:32 +03:00
parent 6c31fd61c2
commit 0cb48d7730
6 changed files with 145 additions and 24 deletions

View File

@ -3,6 +3,7 @@ use std::sync::Arc;
use parking_lot::RwLock;
use elements::MemoryType;
use interpreter::Error;
use interpreter::module::check_limits;
/// Linear memory page size.
pub const LINEAR_MEMORY_PAGE_SIZE: u32 = 65536;
@ -18,6 +19,8 @@ pub struct MemoryInstance {
impl MemoryInstance {
/// Create new linear memory instance.
pub fn new(memory_type: &MemoryType) -> Result<Arc<Self>, Error> {
check_limits(memory_type.limits())?;
let memory = MemoryInstance {
buffer: RwLock::new(Vec::new()), // TODO: with_capacity
maximum_size: memory_type.limits().maximum()