mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-18 12:06:43 +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,
|
||||
)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -216,12 +216,12 @@ impl VmoInner {
|
||||
if self.should_share_frame_with_parent(write_page) {
|
||||
return Ok(inherited_frame);
|
||||
}
|
||||
|
||||
|
||||
let frame = {
|
||||
let options = VmAllocOptions::new(1);
|
||||
VmFrameVec::allocate(&options)?.pop().unwrap()
|
||||
};
|
||||
frame.write_bytes(0, &*tmp_buffer)?;
|
||||
frame.copy_from_frame(&inherited_frame);
|
||||
Ok(frame)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user