(
_ty: &wasmtime_environ::Memory,
memory_tunables: &MemoryTunables<'_>,
minimum: usize,
)
| 24 | |
| 25 | impl MallocMemory { |
| 26 | pub fn new( |
| 27 | _ty: &wasmtime_environ::Memory, |
| 28 | memory_tunables: &MemoryTunables<'_>, |
| 29 | minimum: usize, |
| 30 | ) -> Result<Self> { |
| 31 | if memory_tunables.guard_size() > 0 { |
| 32 | bail!("malloc memory is only compatible if guard pages aren't used"); |
| 33 | } |
| 34 | if memory_tunables.reservation() > 0 { |
| 35 | bail!("malloc memory is only compatible with no ahead-of-time memory reservation"); |
| 36 | } |
| 37 | if memory_tunables.tunables().memory_init_cow { |
| 38 | bail!("malloc memory cannot be used with CoW images"); |
| 39 | } |
| 40 | |
| 41 | let initial_allocation_byte_size = minimum |
| 42 | .checked_add(memory_tunables.reservation_for_growth().try_into()?) |
| 43 | .context("memory allocation size too large")?; |
| 44 | |
| 45 | let initial_allocation_len = byte_size_to_element_len(initial_allocation_byte_size); |
| 46 | let mut storage = Vec::new(); |
| 47 | storage |
| 48 | .try_reserve(initial_allocation_len) |
| 49 | .with_context(|| { |
| 50 | format!( |
| 51 | "failed to allocate {initial_allocation_byte_size:#x} \ |
| 52 | bytes ({minimum:#x} minimum + {:#x} memory_reservation_for_growth)", |
| 53 | memory_tunables.reservation_for_growth(), |
| 54 | ) |
| 55 | })?; |
| 56 | |
| 57 | let initial_len = byte_size_to_element_len(minimum); |
| 58 | if initial_len > 0 { |
| 59 | grow_storage_to(&mut storage, initial_len); |
| 60 | } |
| 61 | Ok(MallocMemory { |
| 62 | base_ptr: SendSyncPtr::new(NonNull::new(storage.as_mut_ptr()).unwrap()).cast(), |
| 63 | storage, |
| 64 | byte_len: minimum, |
| 65 | }) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | impl RuntimeLinearMemory for MallocMemory { |
nothing calls this directly
no test coverage detected