MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / operate_on_memory_range

Method operate_on_memory_range

devices/src/pvmemcontrol.rs:431–451  ·  view source on GitHub ↗

f is called with the host address of `range_base` and only when [`range_base`, `range_base` + `range_len`) is present in the guest

(&self, addr: u64, length: u64, f: F)

Source from the content-addressed store, hash-verified

429 /// f is called with the host address of `range_base` and only when
430 /// [`range_base`, `range_base` + `range_len`) is present in the guest
431 fn operate_on_memory_range<F>(&self, addr: u64, length: u64, f: F) -> result::Result<(), Error>
432 where
433 F: FnOnce(*mut libc::c_void, usize) -> libc::c_int,
434 {
435 let memory = self.mem.memory();
436 let range_base = GuestAddress(addr);
437 let range_len = usize::try_from(length).map_err(|_| Error::InvalidRequest)?;
438
439 // assume guest memory is not interleaved with vmm memory on the host.
440 let Ok(slice) = memory.get_slice(range_base, range_len) else {
441 return Err(Error::GuestMemory(GuestMemoryError::InvalidGuestAddress(
442 range_base,
443 )));
444 };
445 assert!(slice.len() >= range_len);
446 let res = f(slice.ptr_guard_mut().as_ptr().cast(), slice.len());
447 if res != 0 {
448 return Err(Error::LibcFail(io::Error::last_os_error()));
449 }
450 Ok(())
451 }
452
453 fn madvise(&self, addr: u64, length: u64, advice: libc::c_int) -> result::Result<(), Error> {
454 // SAFETY: [`base`, `base` + `len`) is guest memory

Callers 5

madviseMethod · 0.80
mlockMethod · 0.80
munlockMethod · 0.80
mprotectMethod · 0.80
set_vma_anon_nameMethod · 0.80

Calls 2

memoryMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected