Add DmaBuf for DMA-capable memory areas

This commit is contained in:
Jianfeng Jiang
2024-03-12 11:09:15 +00:00
committed by Tate, Hongliang Tian
parent a60a8ad3e1
commit d8a841f88a
6 changed files with 129 additions and 3 deletions

View File

@ -595,6 +595,21 @@ impl<'a> VmReader<'a> {
}
copy_len
}
/// Read a value of `Pod` type.
///
/// # Panic
///
/// If the length of the `Pod` type exceeds `self.remain()`, then this method will panic.
pub fn read_val<T: Pod>(&mut self) -> T {
assert!(self.remain() >= core::mem::size_of::<T>());
let mut val = T::new_uninit();
let mut writer = VmWriter::from(val.as_bytes_mut());
let read_len = self.read(&mut writer);
val
}
}
impl<'a> From<&'a [u8]> for VmReader<'a> {