mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
@@ -7,7 +7,6 @@
|
||||
|
||||
use crate::mmap::Mmap;
|
||||
use crate::vmcontext::VMMemoryDefinition;
|
||||
use loupe::MemoryUsage;
|
||||
use more_asserts::assert_ge;
|
||||
use std::borrow::BorrowMut;
|
||||
use std::cell::UnsafeCell;
|
||||
@@ -61,7 +60,7 @@ pub enum MemoryError {
|
||||
}
|
||||
|
||||
/// Trait for implementing Wasm Memory used by Wasmer.
|
||||
pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
|
||||
pub trait Memory: fmt::Debug + Send + Sync {
|
||||
/// Returns the memory type for this memory.
|
||||
fn ty(&self) -> MemoryType;
|
||||
|
||||
@@ -81,7 +80,7 @@ pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
|
||||
}
|
||||
|
||||
/// A linear memory instance.
|
||||
#[derive(Debug, MemoryUsage)]
|
||||
#[derive(Debug)]
|
||||
pub struct LinearMemory {
|
||||
// The underlying allocation.
|
||||
mmap: Mutex<WasmMmap>,
|
||||
@@ -101,15 +100,11 @@ pub struct LinearMemory {
|
||||
|
||||
/// The owned memory definition used by the generated code
|
||||
vm_memory_definition: VMMemoryDefinitionOwnership,
|
||||
|
||||
// Records whether we're using a bounds-checking strategy which requires
|
||||
// handlers to catch trapping accesses.
|
||||
pub(crate) needs_signal_handlers: bool,
|
||||
}
|
||||
|
||||
/// A type to help manage who is responsible for the backing memory of them
|
||||
/// `VMMemoryDefinition`.
|
||||
#[derive(Debug, MemoryUsage)]
|
||||
#[derive(Debug)]
|
||||
enum VMMemoryDefinitionOwnership {
|
||||
/// The `VMMemoryDefinition` is owned by the `Instance` and we should use
|
||||
/// its memory. This is how a local memory that's exported should be stored.
|
||||
@@ -132,7 +127,7 @@ unsafe impl Send for LinearMemory {}
|
||||
/// This is correct because all internal mutability is protected by a mutex.
|
||||
unsafe impl Sync for LinearMemory {}
|
||||
|
||||
#[derive(Debug, MemoryUsage)]
|
||||
#[derive(Debug)]
|
||||
struct WasmMmap {
|
||||
// Our OS allocation of mmap'd memory.
|
||||
alloc: Mmap,
|
||||
@@ -196,15 +191,6 @@ impl LinearMemory {
|
||||
|
||||
let offset_guard_bytes = style.offset_guard_size() as usize;
|
||||
|
||||
// If we have an offset guard, or if we're doing the static memory
|
||||
// allocation strategy, we need signal handlers to catch out of bounds
|
||||
// acceses.
|
||||
let needs_signal_handlers = offset_guard_bytes > 0
|
||||
|| match style {
|
||||
MemoryStyle::Dynamic { .. } => false,
|
||||
MemoryStyle::Static { .. } => true,
|
||||
};
|
||||
|
||||
let minimum_pages = match style {
|
||||
MemoryStyle::Dynamic { .. } => memory.minimum,
|
||||
MemoryStyle::Static { bound, .. } => {
|
||||
@@ -229,7 +215,6 @@ impl LinearMemory {
|
||||
mmap: Mutex::new(mmap),
|
||||
maximum: memory.maximum,
|
||||
offset_guard_size: offset_guard_bytes,
|
||||
needs_signal_handlers,
|
||||
vm_memory_definition: if let Some(mem_loc) = vm_memory_location {
|
||||
{
|
||||
let mut ptr = mem_loc;
|
||||
|
||||
Reference in New Issue
Block a user