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

Method checked_load

cranelift/interpreter/src/interpreter.rs:321–355  ·  view source on GitHub ↗
(
        &self,
        addr: Address,
        ty: Type,
        mem_flags: MemFlagsData,
    )

Source from the content-addressed store, hash-verified

319 }
320
321 fn checked_load(
322 &self,
323 addr: Address,
324 ty: Type,
325 mem_flags: MemFlagsData,
326 ) -> Result<DataValue, MemoryError> {
327 let load_size = ty.bytes() as usize;
328 let addr_start = addr.offset as usize;
329 let addr_end = addr_start + load_size;
330
331 let src = match addr.region {
332 AddressRegion::Stack => {
333 if addr_end > self.stack.len() {
334 return Err(MemoryError::OutOfBoundsLoad {
335 addr,
336 load_size,
337 mem_flags,
338 });
339 }
340
341 &self.stack[addr_start..addr_end]
342 }
343 _ => unimplemented!(),
344 };
345
346 // Aligned flag is set and address is not aligned for the given type
347 if mem_flags.aligned() && addr_start % load_size != 0 {
348 return Err(MemoryError::MisalignedLoad { addr, load_size });
349 }
350
351 Ok(match mem_flags.endianness(self.native_endianness) {
352 Endianness::Big => DataValue::read_from_slice_be(src, ty),
353 Endianness::Little => DataValue::read_from_slice_le(src, ty),
354 })
355 }
356
357 fn checked_store(
358 &mut self,

Callers 2

stepFunction · 0.80
resolve_global_valueMethod · 0.80

Calls 5

OkFunction · 0.85
bytesMethod · 0.45
lenMethod · 0.45
alignedMethod · 0.45
endiannessMethod · 0.45

Tested by

no test coverage detected