MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / new

Method new

crates/wasmtime/src/runtime/vm/memory.rs:549–593  ·  view source on GitHub ↗
(
        ty: &wasmtime_environ::Memory,
        memory_tunables: &MemoryTunables<'_>,
        alloc: Box<dyn RuntimeLinearMemory>,
        memory_image: Option<&Arc<MemoryImage>>,
    )

Source from the content-addressed store, hash-verified

547
548impl 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

Callers

nothing calls this directly

Calls 12

OkFunction · 0.85
guard_sizeMethod · 0.80
reservationMethod · 0.80
newFunction · 0.50
createFunction · 0.50
byte_sizeMethod · 0.45
baseMethod · 0.45
byte_capacityMethod · 0.45
instantiateMethod · 0.45
memory_may_moveMethod · 0.45
unwrapMethod · 0.45
try_intoMethod · 0.45

Tested by

no test coverage detected