(
ty: &wasmtime_environ::Memory,
memory_tunables: &MemoryTunables<'_>,
alloc: Box<dyn RuntimeLinearMemory>,
memory_image: Option<&Arc<MemoryImage>>,
)
| 547 | |
| 548 | impl LocalMemory { |
| 549 | pub fn new( |
| 550 | ty: &wasmtime_environ::Memory, |
| 551 | memory_tunables: &MemoryTunables<'_>, |
| 552 | alloc: Box<dyn RuntimeLinearMemory>, |
| 553 | memory_image: Option<&Arc<MemoryImage>>, |
| 554 | ) -> Result<LocalMemory> { |
| 555 | // If a memory image was specified, try to create the MemoryImageSlot on |
| 556 | // top of our mmap. |
| 557 | let memory_image = match memory_image { |
| 558 | #[cfg(has_virtual_memory)] |
| 559 | Some(image) => { |
| 560 | // We currently don't support memory_image if |
| 561 | // `RuntimeLinearMemory::byte_size` is not a multiple of the host page |
| 562 | // size. See https://github.com/bytecodealliance/wasmtime/issues/9660. |
| 563 | if let Ok(byte_size) = HostAlignedByteCount::new(alloc.byte_size()) { |
| 564 | // memory_image is CoW-based so it is expected to be backed |
| 565 | // by an mmap. |
| 566 | let mmap_base = match alloc.base() { |
| 567 | MemoryBase::Mmap(offset) => offset, |
| 568 | MemoryBase::Raw { .. } => { |
| 569 | unreachable!("memory_image is Some only for mmap-based memories") |
| 570 | } |
| 571 | }; |
| 572 | |
| 573 | let mut slot = |
| 574 | MemoryImageSlot::create(mmap_base, byte_size, alloc.byte_capacity()); |
| 575 | slot.instantiate(alloc.byte_size(), Some(image), ty, memory_tunables)?; |
| 576 | Some(slot) |
| 577 | } else { |
| 578 | None |
| 579 | } |
| 580 | } |
| 581 | #[cfg(not(has_virtual_memory))] |
| 582 | Some(_) => unreachable!(), |
| 583 | None => None, |
| 584 | }; |
| 585 | Ok(LocalMemory { |
| 586 | ty: *ty, |
| 587 | alloc, |
| 588 | memory_may_move: ty.memory_may_move(memory_tunables), |
| 589 | memory_image, |
| 590 | memory_guard_size: memory_tunables.guard_size().try_into().unwrap(), |
| 591 | memory_reservation: memory_tunables.reservation().try_into().unwrap(), |
| 592 | }) |
| 593 | } |
| 594 | |
| 595 | pub fn ty(&self) -> &wasmtime_environ::Memory { |
| 596 | &self.ty |
nothing calls this directly
no test coverage detected