@@ -213,8 +213,43 @@ impl Mapping {
213
213
} else if reason. contains ( PageFaultErrorCode :: CAUSED_BY_WRITE )
214
214
&& !reason. contains ( PageFaultErrorCode :: PROTECTION_VIOLATION )
215
215
{
216
+ // We are writing to private file mapping so copy the content of the page.
216
217
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 ( ) ;
218
253
} else if reason. contains ( PageFaultErrorCode :: PROTECTION_VIOLATION )
219
254
&& reason. contains ( PageFaultErrorCode :: CAUSED_BY_WRITE )
220
255
{
0 commit comments