fix memory memory creator reserved_size (#1844)
* fix memory memory creator reserved_size * update doc comment
This commit is contained in:
@@ -879,7 +879,7 @@ pub unsafe trait MemoryCreator: Send + Sync {
|
|||||||
/// The type of memory being created is specified by `ty` which indicates
|
/// The type of memory being created is specified by `ty` which indicates
|
||||||
/// both the minimum and maximum size, in wasm pages.
|
/// both the minimum and maximum size, in wasm pages.
|
||||||
///
|
///
|
||||||
/// The `reserved_size` value indicates the expected size of the
|
/// The `reserved_size_in_bytes` value indicates the expected size of the
|
||||||
/// reservation that is to be made for this memory. If this value is `None`
|
/// reservation that is to be made for this memory. If this value is `None`
|
||||||
/// than the implementation is free to allocate memory as it sees fit. If
|
/// than the implementation is free to allocate memory as it sees fit. If
|
||||||
/// the value is `Some`, however, then the implementation is expected to
|
/// the value is `Some`, however, then the implementation is expected to
|
||||||
@@ -887,23 +887,23 @@ pub unsafe trait MemoryCreator: Send + Sync {
|
|||||||
/// size at the end. Note that this reservation need only be a virtual
|
/// size at the end. Note that this reservation need only be a virtual
|
||||||
/// memory reservation, physical memory does not need to be allocated
|
/// memory reservation, physical memory does not need to be allocated
|
||||||
/// immediately. In this case `grow` should never move the base pointer and
|
/// immediately. In this case `grow` should never move the base pointer and
|
||||||
/// the maximum size of `ty` is guaranteed to fit within `reserved_size`.
|
/// the maximum size of `ty` is guaranteed to fit within `reserved_size_in_bytes`.
|
||||||
///
|
///
|
||||||
/// The `guard_size` parameter indicates how many bytes of space, after the
|
/// The `guard_size_in_bytes` parameter indicates how many bytes of space, after the
|
||||||
/// memory allocation, is expected to be unmapped. JIT code will elide
|
/// memory allocation, is expected to be unmapped. JIT code will elide
|
||||||
/// bounds checks based on the `guard_size` provided, so for JIT code to
|
/// bounds checks based on the `guard_size_in_bytes` provided, so for JIT code to
|
||||||
/// work correctly the memory returned will need to be properly guarded with
|
/// work correctly the memory returned will need to be properly guarded with
|
||||||
/// `guard_size` bytes left unmapped after the base allocation.
|
/// `guard_size_in_bytes` bytes left unmapped after the base allocation.
|
||||||
///
|
///
|
||||||
/// Note that the `reserved_size` and `guard_size` options are tuned from
|
/// Note that the `reserved_size_in_bytes` and `guard_size_in_bytes` options are tuned from
|
||||||
/// the various [`Config`](crate::Config) methods about memory
|
/// the various [`Config`](crate::Config) methods about memory
|
||||||
/// sizes/guards. Additionally these two values are guaranteed to be
|
/// sizes/guards. Additionally these two values are guaranteed to be
|
||||||
/// multiples of the system page size.
|
/// multiples of the system page size.
|
||||||
fn new_memory(
|
fn new_memory(
|
||||||
&self,
|
&self,
|
||||||
ty: MemoryType,
|
ty: MemoryType,
|
||||||
reserved_size: Option<u64>,
|
reserved_size_in_bytes: Option<u64>,
|
||||||
guard_size: u64,
|
guard_size_in_bytes: u64,
|
||||||
) -> Result<Box<dyn LinearMemory>, String>;
|
) -> Result<Box<dyn LinearMemory>, String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,12 +67,12 @@ pub(crate) struct MemoryCreatorProxy {
|
|||||||
impl RuntimeMemoryCreator for MemoryCreatorProxy {
|
impl RuntimeMemoryCreator for MemoryCreatorProxy {
|
||||||
fn new_memory(&self, plan: &MemoryPlan) -> Result<Box<dyn RuntimeLinearMemory>, String> {
|
fn new_memory(&self, plan: &MemoryPlan) -> Result<Box<dyn RuntimeLinearMemory>, String> {
|
||||||
let ty = MemoryType::new(Limits::new(plan.memory.minimum, plan.memory.maximum));
|
let ty = MemoryType::new(Limits::new(plan.memory.minimum, plan.memory.maximum));
|
||||||
let reserved_size = match plan.style {
|
let reserved_size_in_bytes = match plan.style {
|
||||||
MemoryStyle::Static { bound } => Some(bound.into()),
|
MemoryStyle::Static { bound } => Some(bound as u64 * WASM_PAGE_SIZE as u64),
|
||||||
MemoryStyle::Dynamic => None,
|
MemoryStyle::Dynamic => None,
|
||||||
};
|
};
|
||||||
self.mem_creator
|
self.mem_creator
|
||||||
.new_memory(ty, reserved_size, plan.offset_guard_size)
|
.new_memory(ty, reserved_size_in_bytes, plan.offset_guard_size)
|
||||||
.map(|mem| Box::new(LinearMemoryProxy { mem }) as Box<dyn RuntimeLinearMemory>)
|
.map(|mem| Box::new(LinearMemoryProxy { mem }) as Box<dyn RuntimeLinearMemory>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user