@@ -31,7 +31,7 @@ use crate::memory::vspace::{AddressSpace, MapAction};
3131use crate :: memory:: { paddr_to_kernel_vaddr, Frame , KernelAllocator , MemType , PAddr , VAddr } ;
3232use crate :: nrproc:: NrProcess ;
3333use crate :: process:: {
34- Eid , Executor , Pid , Process , ResumeHandle , MAX_FRAMES_PER_PROCESS , MAX_PROCESSES ,
34+ Eid , Executor , FrameManagement , Pid , Process , ProcessFrames , ResumeHandle , MAX_PROCESSES ,
3535 MAX_WRITEABLE_SECTIONS_PER_PROCESS ,
3636} ;
3737use crate :: round_up;
@@ -859,7 +859,7 @@ pub(crate) struct Ring3Process {
859859 /// File descriptors for the opened file.
860860 pub fds : ArrayVec < Option < FileDescriptorEntry > , MAX_FILES_PER_PROCESS > ,
861861 /// Physical frame objects registered to the process.
862- pub frames : ArrayVec < ( Option < Frame > , Option < VAddr > ) , MAX_FRAMES_PER_PROCESS > ,
862+ pub pfm : ProcessFrames ,
863863 /// Frames of the writeable ELF data section (shared across all replicated Process structs)
864864 pub writeable_sections : ArrayVec < Frame , MAX_WRITEABLE_SECTIONS_PER_PROCESS > ,
865865 /// Section in ELF where last read-only header is
@@ -879,8 +879,7 @@ impl Ring3Process {
879879 let fds: ArrayVec < Option < FileDescriptorEntry > , MAX_FILES_PER_PROCESS > =
880880 ArrayVec :: from ( [ NONE_FD ; MAX_FILES_PER_PROCESS ] ) ;
881881
882- let frames: ArrayVec < ( Option < Frame > , Option < VAddr > ) , MAX_FRAMES_PER_PROCESS > =
883- ArrayVec :: from ( [ ( None , None ) ; MAX_FRAMES_PER_PROCESS ] ) ;
882+ let pfm = ProcessFrames :: default ( ) ;
884883
885884 Ok ( Ring3Process {
886885 pid : pid,
@@ -892,7 +891,7 @@ impl Ring3Process {
892891 executor_offset : VAddr :: from ( EXECUTOR_OFFSET ) ,
893892 fds,
894893 pinfo : Default :: default ( ) ,
895- frames ,
894+ pfm ,
896895 writeable_sections : ArrayVec :: new ( ) ,
897896 read_only_offset : VAddr :: zero ( ) ,
898897 } )
@@ -1333,51 +1332,27 @@ impl Process for Ring3Process {
13331332 fn pinfo ( & self ) -> & kpi:: process:: ProcessInfo {
13341333 & self . pinfo
13351334 }
1335+ }
13361336
1337+ impl FrameManagement for Ring3Process {
13371338 fn add_frame ( & mut self , frame : Frame ) -> Result < FrameId , KError > {
1338- if let Some ( fid) = self . frames . iter ( ) . position ( |entry| entry. 0 . is_none ( ) ) {
1339- self . frames [ fid] = ( Some ( frame) , None ) ;
1340- Ok ( fid)
1341- } else {
1342- Err ( KError :: TooManyRegisteredFrames )
1343- }
1339+ self . pfm . add_frame ( frame)
13441340 }
13451341
1346- fn get_frame ( & mut self , frame_id : FrameId ) -> Result < ( Frame , Option < VAddr > ) , KError > {
1347- let ( frame, mapped_at) = self
1348- . frames
1349- . get ( frame_id)
1350- . cloned ( )
1351- . ok_or ( KError :: InvalidFrameId ) ?;
1352-
1353- if let Some ( frame) = frame {
1354- Ok ( ( frame, mapped_at) )
1355- } else {
1356- Err ( KError :: InvalidFrameId )
1357- }
1342+ fn get_frame ( & mut self , frame_id : FrameId ) -> Result < ( Frame , usize ) , KError > {
1343+ self . pfm . get_frame ( frame_id)
13581344 }
13591345
1360- fn add_frame_mapping ( & mut self , frame_id : FrameId , base : VAddr ) -> Result < ( ) , KError > {
1361- self . frames
1362- . get_mut ( frame_id)
1363- . and_then ( |( _, mapping) | {
1364- * mapping = Some ( base) ;
1365- Some ( ( ) )
1366- } )
1367- . ok_or ( KError :: InvalidFrameId )
1346+ fn add_frame_mapping ( & mut self , frame_id : FrameId , vaddr : VAddr ) -> Result < ( ) , KError > {
1347+ self . pfm . add_frame_mapping ( frame_id, vaddr)
13681348 }
13691349
1370- fn deallocate_frame ( & mut self , fid : FrameId ) -> Result < ( Frame , Option < VAddr > ) , KError > {
1371- match self . frames . get_mut ( fid) {
1372- Some ( cur) => {
1373- let mut temp = ( None , None ) ;
1374- core:: mem:: swap ( & mut temp, cur) ;
1350+ fn remove_frame_mapping ( & mut self , frame_id : FrameId , _vaddr : VAddr ) -> Result < ( ) , KError > {
1351+ self . pfm . remove_frame_mapping ( frame_id, _vaddr)
1352+ }
13751353
1376- let va = temp. 1 ;
1377- Ok ( ( temp. 0 . ok_or ( KError :: InvalidFrame ) ?, va) )
1378- }
1379- _ => Err ( KError :: InvalidFrameId ) ,
1380- }
1354+ fn deallocate_frame ( & mut self , fid : FrameId ) -> Result < Frame , KError > {
1355+ self . pfm . deallocate_frame ( fid)
13811356 }
13821357}
13831358
0 commit comments