mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-20 04:06:30 +00:00
renaming
This commit is contained in:
@ -219,7 +219,7 @@ impl<'env, 'module, 'isa> FuncEnvironment for FuncEnv<'env, 'module, 'isa> {
|
|||||||
|
|
||||||
func.create_heap(ir::HeapData {
|
func.create_heap(ir::HeapData {
|
||||||
base: local_memory_base,
|
base: local_memory_base,
|
||||||
min_size: ((description.min as u64) * (WASM_PAGE_SIZE as u64)).into(),
|
min_size: ((description.minimum as u64) * (WASM_PAGE_SIZE as u64)).into(),
|
||||||
offset_guard_size: mem_type.guard_size().into(),
|
offset_guard_size: mem_type.guard_size().into(),
|
||||||
style: ir::HeapStyle::Dynamic {
|
style: ir::HeapStyle::Dynamic {
|
||||||
bound_gv: local_memory_bound,
|
bound_gv: local_memory_bound,
|
||||||
@ -230,7 +230,7 @@ impl<'env, 'module, 'isa> FuncEnvironment for FuncEnv<'env, 'module, 'isa> {
|
|||||||
mem_type @ MemoryType::Static | mem_type @ MemoryType::SharedStatic => func
|
mem_type @ MemoryType::Static | mem_type @ MemoryType::SharedStatic => func
|
||||||
.create_heap(ir::HeapData {
|
.create_heap(ir::HeapData {
|
||||||
base: local_memory_base,
|
base: local_memory_base,
|
||||||
min_size: ((description.min as u64) * (WASM_PAGE_SIZE as u64)).into(),
|
min_size: ((description.minimum as u64) * (WASM_PAGE_SIZE as u64)).into(),
|
||||||
offset_guard_size: mem_type.guard_size().into(),
|
offset_guard_size: mem_type.guard_size().into(),
|
||||||
style: ir::HeapStyle::Static {
|
style: ir::HeapStyle::Static {
|
||||||
bound: mem_type.bounds().unwrap().into(),
|
bound: mem_type.bounds().unwrap().into(),
|
||||||
@ -327,7 +327,7 @@ impl<'env, 'module, 'isa> FuncEnvironment for FuncEnv<'env, 'module, 'isa> {
|
|||||||
|
|
||||||
func.create_table(ir::TableData {
|
func.create_table(ir::TableData {
|
||||||
base_gv: table_base,
|
base_gv: table_base,
|
||||||
min_size: (description.min as u64).into(),
|
min_size: (description.minimum as u64).into(),
|
||||||
bound_gv: table_count,
|
bound_gv: table_count,
|
||||||
element_size: (vm::Anyfunc::size() as u64).into(),
|
element_size: (vm::Anyfunc::size() as u64).into(),
|
||||||
index_type: ir::types::I32,
|
index_type: ir::types::I32,
|
||||||
|
@ -180,8 +180,8 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
TableElementType::Func => ElementType::Anyfunc,
|
TableElementType::Func => ElementType::Anyfunc,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
},
|
},
|
||||||
min: table.minimum,
|
minimum: table.minimum,
|
||||||
max: table.maximum,
|
maximum: table.maximum,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,8 +204,8 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
TableElementType::Func => ElementType::Anyfunc,
|
TableElementType::Func => ElementType::Anyfunc,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
},
|
},
|
||||||
min: table.minimum,
|
minimum: table.minimum,
|
||||||
max: table.maximum,
|
maximum: table.maximum,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add import names to list of imported tables
|
// Add import names to list of imported tables
|
||||||
@ -251,8 +251,8 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
/// Declares a memory to the environment
|
/// Declares a memory to the environment
|
||||||
fn declare_memory(&mut self, memory: cranelift_wasm::Memory) {
|
fn declare_memory(&mut self, memory: cranelift_wasm::Memory) {
|
||||||
self.module.memories.push(MemoryDescriptor {
|
self.module.memories.push(MemoryDescriptor {
|
||||||
min: memory.minimum,
|
minimum: memory.minimum,
|
||||||
max: memory.maximum,
|
maximum: memory.maximum,
|
||||||
shared: memory.shared,
|
shared: memory.shared,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -270,8 +270,8 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
};
|
};
|
||||||
|
|
||||||
let memory = MemoryDescriptor {
|
let memory = MemoryDescriptor {
|
||||||
min: memory.minimum,
|
minimum: memory.minimum,
|
||||||
max: memory.maximum,
|
maximum: memory.maximum,
|
||||||
shared: memory.shared,
|
shared: memory.shared,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ impl LocalBacking {
|
|||||||
LocalOrImport::Local(local_memory_index) => {
|
LocalOrImport::Local(local_memory_index) => {
|
||||||
let memory_desc = module.memories[local_memory_index];
|
let memory_desc = module.memories[local_memory_index];
|
||||||
let data_top = init_base + init.data.len();
|
let data_top = init_base + init.data.len();
|
||||||
assert!(memory_desc.min as usize * WASM_PAGE_SIZE >= data_top);
|
assert!(memory_desc.minimum as usize * WASM_PAGE_SIZE >= data_top);
|
||||||
|
|
||||||
let mem = &memories[local_memory_index];
|
let mem = &memories[local_memory_index];
|
||||||
mem.write_many(init_base as u32, &init.data).unwrap();
|
mem.write_many(init_base as u32, &init.data).unwrap();
|
||||||
|
@ -30,13 +30,13 @@ impl DynamicMemory {
|
|||||||
pub(super) fn new(desc: MemoryDescriptor, local: &mut vm::LocalMemory) -> Option<Box<Self>> {
|
pub(super) fn new(desc: MemoryDescriptor, local: &mut vm::LocalMemory) -> Option<Box<Self>> {
|
||||||
let memory = {
|
let memory = {
|
||||||
let mut memory =
|
let mut memory =
|
||||||
sys::Memory::with_size((desc.min as usize * WASM_PAGE_SIZE) + DYNAMIC_GUARD_SIZE)
|
sys::Memory::with_size((desc.minimum as usize * WASM_PAGE_SIZE) + DYNAMIC_GUARD_SIZE)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
if desc.min != 0 {
|
if desc.minimum != 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
memory
|
memory
|
||||||
.protect(
|
.protect(
|
||||||
0..(desc.min as usize * WASM_PAGE_SIZE),
|
0..(desc.minimum as usize * WASM_PAGE_SIZE),
|
||||||
sys::Protect::ReadWrite,
|
sys::Protect::ReadWrite,
|
||||||
)
|
)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
@ -48,13 +48,13 @@ impl DynamicMemory {
|
|||||||
|
|
||||||
let mut storage = Box::new(DynamicMemory {
|
let mut storage = Box::new(DynamicMemory {
|
||||||
memory,
|
memory,
|
||||||
current: desc.min,
|
current: desc.minimum,
|
||||||
max: desc.max,
|
max: desc.maximum,
|
||||||
});
|
});
|
||||||
let storage_ptr: *mut DynamicMemory = &mut *storage;
|
let storage_ptr: *mut DynamicMemory = &mut *storage;
|
||||||
|
|
||||||
local.base = storage.memory.as_ptr();
|
local.base = storage.memory.as_ptr();
|
||||||
local.bound = desc.min as usize * WASM_PAGE_SIZE;
|
local.bound = desc.minimum as usize * WASM_PAGE_SIZE;
|
||||||
local.memory = storage_ptr as *mut ();
|
local.memory = storage_ptr as *mut ();
|
||||||
|
|
||||||
Some(storage)
|
Some(storage)
|
||||||
|
@ -23,6 +23,29 @@ pub struct Memory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
|
/// Create a new `Memory` from a [`MemoryDescriptor`]
|
||||||
|
///
|
||||||
|
/// [`MemoryDescriptor`]: struct.MemoryDescriptor.html
|
||||||
|
///
|
||||||
|
/// Usage:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use wasmer_runtime_core::types::MemoryDescriptor;
|
||||||
|
/// # use wasmer_runtime_core::memory::Memory;
|
||||||
|
/// # use wasmer_runtime_core::error::Result;
|
||||||
|
///
|
||||||
|
/// # fn create_memory() -> Result<()> {
|
||||||
|
/// let descriptor = MemoryDescriptor {
|
||||||
|
/// minimum: 10,
|
||||||
|
/// maximum: None,
|
||||||
|
/// shared: false,
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// let memory = Memory::new(descriptor)?;
|
||||||
|
///
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
pub fn new(desc: MemoryDescriptor) -> Option<Self> {
|
pub fn new(desc: MemoryDescriptor) -> Option<Self> {
|
||||||
let mut vm_local_memory = Box::new(vm::LocalMemory {
|
let mut vm_local_memory = Box::new(vm::LocalMemory {
|
||||||
base: ptr::null_mut(),
|
base: ptr::null_mut(),
|
||||||
@ -46,10 +69,15 @@ impl Memory {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the [`MemoryDescriptor`] that this memory
|
||||||
|
/// was created with.
|
||||||
|
///
|
||||||
|
/// [`MemoryDescriptor`]: struct.MemoryDescriptor.html
|
||||||
pub fn descriptor(&self) -> MemoryDescriptor {
|
pub fn descriptor(&self) -> MemoryDescriptor {
|
||||||
self.desc
|
self.desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Grow this memory by the specfied number of pages.
|
||||||
pub fn grow(&mut self, delta: u32) -> Option<u32> {
|
pub fn grow(&mut self, delta: u32) -> Option<u32> {
|
||||||
match &mut *self.storage.borrow_mut() {
|
match &mut *self.storage.borrow_mut() {
|
||||||
(MemoryStorage::Dynamic(ref mut dynamic_memory), ref mut local) => {
|
(MemoryStorage::Dynamic(ref mut dynamic_memory), ref mut local) => {
|
||||||
@ -62,8 +90,13 @@ impl Memory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This returns the number of pages in the memory.
|
/// The size, in bytes, of this memory.
|
||||||
pub fn current_pages(&self) -> u32 {
|
pub fn bytes(&self) -> usize {
|
||||||
|
(self.size() as usize) * WASM_PAGE_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The size, in wasm pages, of this memory.
|
||||||
|
pub fn size(&self) -> u32 {
|
||||||
match &*self.storage.borrow() {
|
match &*self.storage.borrow() {
|
||||||
(MemoryStorage::Dynamic(ref dynamic_memory), _) => dynamic_memory.current(),
|
(MemoryStorage::Dynamic(ref dynamic_memory), _) => dynamic_memory.current(),
|
||||||
(MemoryStorage::Static(ref static_memory), _) => static_memory.current(),
|
(MemoryStorage::Static(ref static_memory), _) => static_memory.current(),
|
||||||
@ -271,7 +304,7 @@ impl fmt::Debug for Memory {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.debug_struct("Memory")
|
f.debug_struct("Memory")
|
||||||
.field("desc", &self.desc)
|
.field("desc", &self.desc)
|
||||||
.field("size", &(self.current_pages() as usize * WASM_PAGE_SIZE))
|
.field("size", &self.bytes())
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,11 @@ impl StaticMemory {
|
|||||||
let memory = {
|
let memory = {
|
||||||
let mut memory =
|
let mut memory =
|
||||||
sys::Memory::with_size(SAFE_STATIC_HEAP_SIZE + SAFE_STATIC_GUARD_SIZE).ok()?;
|
sys::Memory::with_size(SAFE_STATIC_HEAP_SIZE + SAFE_STATIC_GUARD_SIZE).ok()?;
|
||||||
if desc.min != 0 {
|
if desc.minimum != 0 {
|
||||||
unsafe {
|
unsafe {
|
||||||
memory
|
memory
|
||||||
.protect(
|
.protect(
|
||||||
0..(desc.min as usize * WASM_PAGE_SIZE),
|
0..(desc.minimum as usize * WASM_PAGE_SIZE),
|
||||||
sys::Protect::ReadWrite,
|
sys::Protect::ReadWrite,
|
||||||
)
|
)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
@ -49,13 +49,13 @@ impl StaticMemory {
|
|||||||
|
|
||||||
let mut storage = Box::new(StaticMemory {
|
let mut storage = Box::new(StaticMemory {
|
||||||
memory,
|
memory,
|
||||||
current: desc.min,
|
current: desc.minimum,
|
||||||
max: desc.max,
|
max: desc.maximum,
|
||||||
});
|
});
|
||||||
let storage_ptr: *mut StaticMemory = &mut *storage;
|
let storage_ptr: *mut StaticMemory = &mut *storage;
|
||||||
|
|
||||||
local.base = storage.memory.as_ptr();
|
local.base = storage.memory.as_ptr();
|
||||||
local.bound = desc.min as usize * WASM_PAGE_SIZE;
|
local.bound = desc.minimum as usize * WASM_PAGE_SIZE;
|
||||||
local.memory = storage_ptr as *mut ();
|
local.memory = storage_ptr as *mut ();
|
||||||
|
|
||||||
Some(storage)
|
Some(storage)
|
||||||
|
@ -49,14 +49,14 @@ pub struct AnyfuncTable {
|
|||||||
|
|
||||||
impl AnyfuncTable {
|
impl AnyfuncTable {
|
||||||
pub fn new(desc: TableDescriptor, local: &mut vm::LocalTable) -> Result<Box<Self>, ()> {
|
pub fn new(desc: TableDescriptor, local: &mut vm::LocalTable) -> Result<Box<Self>, ()> {
|
||||||
let initial_table_backing_len = match desc.max {
|
let initial_table_backing_len = match desc.maximum {
|
||||||
Some(max) => max,
|
Some(max) => max,
|
||||||
None => desc.min,
|
None => desc.minimum,
|
||||||
} as usize;
|
} as usize;
|
||||||
|
|
||||||
let mut storage = Box::new(AnyfuncTable {
|
let mut storage = Box::new(AnyfuncTable {
|
||||||
backing: vec![vm::Anyfunc::null(); initial_table_backing_len],
|
backing: vec![vm::Anyfunc::null(); initial_table_backing_len],
|
||||||
max: desc.max,
|
max: desc.maximum,
|
||||||
});
|
});
|
||||||
|
|
||||||
let storage_ptr: *mut AnyfuncTable = &mut *storage;
|
let storage_ptr: *mut AnyfuncTable = &mut *storage;
|
||||||
|
@ -27,6 +27,29 @@ pub struct Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Table {
|
impl Table {
|
||||||
|
/// Create a new `Table` from a [`TableDescriptor`]
|
||||||
|
///
|
||||||
|
/// [`TableDescriptor`]: struct.TableDescriptor.html
|
||||||
|
///
|
||||||
|
/// Usage:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use wasmer_runtime_core::types::{TableDescriptor, ElementType};
|
||||||
|
/// # use wasmer_runtime_core::table::Table;
|
||||||
|
/// # use wasmer_runtime_core::error::Result;
|
||||||
|
///
|
||||||
|
/// # fn create_table() -> Result<()> {
|
||||||
|
/// let descriptor = TableDescriptor {
|
||||||
|
/// element: ElementType::Anyfunc,
|
||||||
|
/// minimum: 10,
|
||||||
|
/// maximum: None,
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// let table = Table::new(descriptor)?;
|
||||||
|
///
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
pub fn new(desc: TableDescriptor) -> Result<Self, ()> {
|
pub fn new(desc: TableDescriptor) -> Result<Self, ()> {
|
||||||
let mut local = vm::LocalTable {
|
let mut local = vm::LocalTable {
|
||||||
base: ptr::null_mut(),
|
base: ptr::null_mut(),
|
||||||
|
@ -132,17 +132,17 @@ pub struct TableDescriptor {
|
|||||||
/// Type of data stored in this table.
|
/// Type of data stored in this table.
|
||||||
pub element: ElementType,
|
pub element: ElementType,
|
||||||
/// The minimum number of elements that must be stored in this table.
|
/// The minimum number of elements that must be stored in this table.
|
||||||
pub min: u32,
|
pub minimum: u32,
|
||||||
/// The maximum number of elements in this table.
|
/// The maximum number of elements in this table.
|
||||||
pub max: Option<u32>,
|
pub maximum: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableDescriptor {
|
impl TableDescriptor {
|
||||||
pub(crate) fn fits_in_imported(&self, imported: TableDescriptor) -> bool {
|
pub(crate) fn fits_in_imported(&self, imported: TableDescriptor) -> bool {
|
||||||
// TODO: We should define implementation limits.
|
// TODO: We should define implementation limits.
|
||||||
let imported_max = imported.max.unwrap_or(u32::max_value());
|
let imported_max = imported.maximum.unwrap_or(u32::max_value());
|
||||||
let self_max = self.max.unwrap_or(u32::max_value());
|
let self_max = self.maximum.unwrap_or(u32::max_value());
|
||||||
self.element == imported.element && imported_max <= self_max && self.min <= imported.min
|
self.element == imported.element && imported_max <= self_max && self.minimum <= imported.minimum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,16 +174,16 @@ pub struct GlobalInit {
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MemoryDescriptor {
|
pub struct MemoryDescriptor {
|
||||||
/// The minimum number of allowed pages.
|
/// The minimum number of allowed pages.
|
||||||
pub min: u32,
|
pub minimum: u32,
|
||||||
/// The maximum number of allowed pages.
|
/// The maximum number of allowed pages.
|
||||||
pub max: Option<u32>,
|
pub maximum: Option<u32>,
|
||||||
/// This memory can be shared between wasm threads.
|
/// This memory can be shared between wasm threads.
|
||||||
pub shared: bool,
|
pub shared: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryDescriptor {
|
impl MemoryDescriptor {
|
||||||
pub fn memory_type(self) -> MemoryType {
|
pub fn memory_type(self) -> MemoryType {
|
||||||
match (self.max.is_some(), self.shared) {
|
match (self.maximum.is_some(), self.shared) {
|
||||||
(true, true) => MemoryType::SharedStatic,
|
(true, true) => MemoryType::SharedStatic,
|
||||||
(true, false) => MemoryType::Static,
|
(true, false) => MemoryType::Static,
|
||||||
(false, false) => MemoryType::Dynamic,
|
(false, false) => MemoryType::Dynamic,
|
||||||
@ -192,10 +192,10 @@ impl MemoryDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fits_in_imported(&self, imported: MemoryDescriptor) -> bool {
|
pub(crate) fn fits_in_imported(&self, imported: MemoryDescriptor) -> bool {
|
||||||
let imported_max = imported.max.unwrap_or(65_536);
|
let imported_max = imported.maximum.unwrap_or(65_536);
|
||||||
let self_max = self.max.unwrap_or(65_536);
|
let self_max = self.maximum.unwrap_or(65_536);
|
||||||
|
|
||||||
self.shared == imported.shared && imported_max <= self_max && self.min <= imported.min
|
self.shared == imported.shared && imported_max <= self_max && self.minimum <= imported.minimum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user