diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-05-30 01:59:03 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-05-30 01:59:03 +0200 |
commit | 85d55ca8f2539a5f766aa375b011163832d5a592 (patch) | |
tree | b7bc5a12470f73d3f9f4737c51ad0c817b2cb16e /src | |
parent | 795a5d7ecdbc1999b7cf7eabf5251a4e3cd192ce (diff) | |
download | mini-kvm-rs-85d55ca8f2539a5f766aa375b011163832d5a592.tar.gz mini-kvm-rs-85d55ca8f2539a5f766aa375b011163832d5a592.zip |
usermem: add load fn
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -63,7 +63,7 @@ impl UserMem { } /// Allocate a zero-initialized memory region of `len` bytes and initialize the first bytes - /// with `init_len`. + /// with `init_from`. /// /// # Panics /// @@ -72,9 +72,21 @@ impl UserMem { assert!(len >= init_from.len()); let mut m = UserMem::new(len)?; - m.as_mut()[..init_from.len()].copy_from_slice(init_from); + m.load(PhysAddr(0), init_from); Ok(m) } + + /// Load the bytes stored in `data` into memory at physical address `addr`. + /// + /// # Panics + /// + /// Panics if `addr + data.len` is larger than the memory size `len`. + pub fn load(&mut self, addr: PhysAddr, data: &[u8]) { + assert!(self.len >= addr.0 as usize + data.len()); + + let addr = addr.0 as usize; + self.as_mut()[addr..addr + data.len()].copy_from_slice(data); + } } impl ops::Drop for UserMem { |