added memory/table import limits validation

This commit is contained in:
Svyatoslav Nikolsky
2017-09-04 12:00:01 +03:00
parent 8da7d22e37
commit a85162dcd1
12 changed files with 224 additions and 29 deletions

View File

@ -1,7 +1,7 @@
use std::u32;
use std::sync::Arc;
use parking_lot::RwLock;
use elements::TableType;
use elements::{TableType, ResizableLimits};
use interpreter::{Error, UserError};
use interpreter::module::check_limits;
use interpreter::variable::{VariableInstance, VariableType};
@ -9,6 +9,8 @@ use interpreter::value::RuntimeValue;
/// Table instance.
pub struct TableInstance<E: UserError> {
/// Table limits.
limits: ResizableLimits,
/// Table variables type.
variable_type: VariableType,
/// Table memory buffer.
@ -27,6 +29,7 @@ impl<E> TableInstance<E> where E: UserError {
let variable_type = table_type.elem_type().into();
Ok(Arc::new(TableInstance {
limits: table_type.limits().clone(),
variable_type: variable_type,
buffer: RwLock::new(
vec![TableElement::new(VariableInstance::new(true, variable_type, RuntimeValue::Null)?); table_type.limits().initial() as usize]
@ -34,6 +37,11 @@ impl<E> TableInstance<E> where E: UserError {
}))
}
/// Return table limits.
pub fn limits(&self) -> &ResizableLimits {
&self.limits
}
/// Get variable type for this table.
pub fn variable_type(&self) -> VariableType {
self.variable_type