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

Method new_static

crates/wasmtime/src/runtime/vm/memory.rs:264–293  ·  view source on GitHub ↗
(
        ty: &wasmtime_environ::Memory,
        memory_tunables: &MemoryTunables<'_>,
        base: MemoryBase,
        base_capacity: usize,
        memory_image: MemoryImageSlot,
        limiter: O

Source from the content-addressed store, hash-verified

262 /// Create a new static (immovable) memory instance for the specified plan.
263 #[cfg(feature = "pooling-allocator")]
264 pub async fn new_static(
265 ty: &wasmtime_environ::Memory,
266 memory_tunables: &MemoryTunables<'_>,
267 base: MemoryBase,
268 base_capacity: usize,
269 memory_image: MemoryImageSlot,
270 limiter: Option<&mut StoreResourceLimiter<'_>>,
271 ) -> Result<Self> {
272 let (minimum, maximum) = Self::limit_new(ty, limiter).await?;
273 let pooled_memory = StaticMemory::new(base, base_capacity, minimum, maximum)?;
274 let allocation = try_new::<Box<_>>(pooled_memory)?;
275
276 // Configure some defaults a bit differently for this memory within the
277 // `LocalMemory` structure created, notably we already have
278 // `memory_image` and regardless of configuration settings this memory
279 // can't move its base pointer since it's a fixed allocation.
280 let mut memory = LocalMemory::new(ty, memory_tunables, allocation, None)?;
281 assert!(memory.memory_image.is_none());
282 memory.memory_image = Some(memory_image);
283 memory.memory_may_move = false;
284
285 Ok(if ty.shared {
286 // FIXME(#4244): not supported with the pooling allocator (which
287 // `new_static` is always used with), see `MemoryPool::validate` as
288 // well).
289 todo!("using shared memory with the pooling allocator is a work in progress");
290 } else {
291 Memory::Local(memory)
292 })
293 }
294
295 /// Calls the `store`'s limiter to optionally prevent a memory from being allocated.
296 ///

Callers

nothing calls this directly

Calls 3

OkFunction · 0.85
LocalClass · 0.85
newFunction · 0.50

Tested by

no test coverage detected