mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-19 04:26:39 +00:00
Implement copy for VmFrame
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
38ee2cafcd
commit
3a3cb7cd15
@ -359,6 +359,24 @@ impl VmFrame {
|
|||||||
PAGE_SIZE,
|
PAGE_SIZE,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_ptr(&self) -> *const u8 {
|
||||||
|
super::paddr_to_vaddr(self.start_paddr()) as *const u8
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_mut_ptr(&self) -> *mut u8 {
|
||||||
|
super::paddr_to_vaddr(self.start_paddr()) as *mut u8
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_from_frame(&self, src: &VmFrame) {
|
||||||
|
if Arc::ptr_eq(&self.frame_index, &src.frame_index) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Safety: src and dst is not overlapped.
|
||||||
|
unsafe {
|
||||||
|
core::ptr::copy_nonoverlapping(src.as_ptr(), self.as_mut_ptr(), PAGE_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VmIo for VmFrame {
|
impl VmIo for VmFrame {
|
||||||
|
@ -221,7 +221,7 @@ impl VmoInner {
|
|||||||
let options = VmAllocOptions::new(1);
|
let options = VmAllocOptions::new(1);
|
||||||
VmFrameVec::allocate(&options)?.pop().unwrap()
|
VmFrameVec::allocate(&options)?.pop().unwrap()
|
||||||
};
|
};
|
||||||
frame.write_bytes(0, &*tmp_buffer)?;
|
frame.copy_from_frame(&inherited_frame);
|
||||||
Ok(frame)
|
Ok(frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user