Skip to content

Commit 665f890

Browse files
vm: implement private file copy
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 052892e commit 665f890

File tree

1 file changed

+36
-1
lines changed
  • src/aero_kernel/src/userland

1 file changed

+36
-1
lines changed

src/aero_kernel/src/userland/vm.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,43 @@ impl Mapping {
213213
} else if reason.contains(PageFaultErrorCode::CAUSED_BY_WRITE)
214214
&& !reason.contains(PageFaultErrorCode::PROTECTION_VIOLATION)
215215
{
216+
// We are writing to private file mapping so copy the content of the page.
216217
log::trace!(" - private file C: {:?}", address);
217-
unimplemented!()
218+
219+
// // addr_aligned, p.page().to_virt(), bytes, self.prot
220+
let frame: PhysFrame = unsafe { FRAME_ALLOCATOR.allocate_frame() }
221+
.expect("failed to allocate frame for a private file write");
222+
223+
let buffer = unsafe {
224+
let phys = frame.start_address().as_u64();
225+
let virt = crate::PHYSICAL_MEMORY_OFFSET + phys;
226+
let ptr = virt.as_mut_ptr::<u8>();
227+
228+
core::slice::from_raw_parts_mut(ptr, size as usize)
229+
};
230+
231+
mmap_file
232+
.file
233+
.inode()
234+
.read_at(offset as usize, buffer)
235+
.unwrap();
236+
237+
let flags = PageTableFlags::PRESENT
238+
| PageTableFlags::USER_ACCESSIBLE
239+
| self.protocol.into();
240+
241+
unsafe {
242+
offset_table.map_to(
243+
Page::containing_address(address),
244+
frame,
245+
PageTableFlags::PRESENT
246+
| PageTableFlags::USER_ACCESSIBLE
247+
| self.protocol.into(),
248+
&mut FRAME_ALLOCATOR,
249+
)
250+
}
251+
.expect("failed to map allocated frame for private file read")
252+
.flush();
218253
} else if reason.contains(PageFaultErrorCode::PROTECTION_VIOLATION)
219254
&& reason.contains(PageFaultErrorCode::CAUSED_BY_WRITE)
220255
{

0 commit comments

Comments
 (0)