@@ -24,7 +24,7 @@ use crate::{
2424 } ,
2525 elf:: ElfFile ,
2626 sdf:: {
27- CapMapType , CpuCore , SysMap , SysMapPerms , SystemDescription , BUDGET_DEFAULT , CAP_MAP_TYPES ,
27+ CapMapType , CpuCore , SysMap , SysMapPerms , SystemDescription , BUDGET_DEFAULT ,
2828 MONITOR_PD_NAME , MONITOR_PRIORITY ,
2929 } ,
3030 sel4:: { Arch , Config , PageSize } ,
@@ -548,15 +548,15 @@ pub fn build_capdl_spec(
548548 } ;
549549
550550 // Mapping between pd name and id for faster lookups
551- let mut pd_name_to_id: HashMap < String , usize > = HashMap :: new ( ) ;
551+ let mut pd_name_to_id: HashMap < & String , usize > = HashMap :: new ( ) ;
552552
553553 // Keep tabs on each PD's CSpace, Notification and Endpoint objects so we can create channels between them at a later step.
554554 let mut pd_id_to_cspace_id: HashMap < usize , ObjectId > = HashMap :: new ( ) ;
555555 let mut pd_id_to_ntfn_id: HashMap < usize , ObjectId > = HashMap :: new ( ) ;
556556 let mut pd_id_to_ep_id: HashMap < usize , ObjectId > = HashMap :: new ( ) ;
557557
558558 // Keep tabs on caps such as TCB and SC so that we can create additional mappings for the cap into other PD's cspaces.
559- let mut pd_shadow_cspace: HashMap < usize , Vec < Option < Cap > > > = HashMap :: new ( ) ;
559+ let mut pd_shadow_cspace: HashMap < usize , HashMap < CapMapType , Cap > > = HashMap :: new ( ) ;
560560
561561 // Keep track of the global count of vCPU objects so we can bind them to the monitor for setting TCB name in debug config.
562562 // Only used on ARM and RISC-V as on x86-64 VMs share the same TCB as PD's which will have their TCB name set separately.
@@ -568,8 +568,9 @@ pub fn build_capdl_spec(
568568 for ( pd_global_idx, pd) in system. protection_domains . iter ( ) . enumerate ( ) {
569569 let elf_obj = & elfs[ pd_global_idx] ;
570570
571- pd_name_to_id. insert ( pd. name . clone ( ) , pd_global_idx) ;
571+ pd_name_to_id. insert ( & pd. name , pd_global_idx) ;
572572
573+ let mut pd_shadow_cspace_inner: HashMap < CapMapType , Cap > = HashMap :: new ( ) ;
573574 let mut caps_to_bind_to_tcb: Vec < CapTableEntry > = Vec :: new ( ) ;
574575 let mut caps_to_insert_to_pd_cspace: Vec < CapTableEntry > = Vec :: new ( ) ;
575576
@@ -582,12 +583,8 @@ pub fn build_capdl_spec(
582583 let pd_tcb_obj = capdl_util_make_tcb_cap ( pd_tcb_obj_id) ;
583584 let pd_vspace_obj = capdl_util_make_page_table_cap ( pd_vspace_obj_id) ;
584585
585- pd_shadow_cspace
586- . entry ( pd_global_idx)
587- . or_insert_with ( || vec ! [ None ; CAP_MAP_TYPES ] ) [ CapMapType :: Tcb as usize ] =
588- Some ( pd_tcb_obj. clone ( ) ) ;
589- pd_shadow_cspace. get_mut ( & pd_global_idx) . unwrap ( ) [ CapMapType :: Vspace as usize ] =
590- Some ( pd_vspace_obj. clone ( ) ) ;
586+ pd_shadow_cspace_inner. insert ( CapMapType :: Tcb , pd_tcb_obj. clone ( ) ) ;
587+ pd_shadow_cspace_inner. insert ( CapMapType :: Vspace , pd_vspace_obj. clone ( ) ) ;
591588
592589 // In the benchmark configuration, we allow PDs to access their own TCB.
593590 // This is necessary for accessing kernel's benchmark API.
@@ -677,8 +674,7 @@ pub fn build_capdl_spec(
677674 ) ;
678675 let pd_sc_cap = capdl_util_make_sc_cap ( pd_sc_obj_id) ;
679676
680- pd_shadow_cspace. get_mut ( & pd_global_idx) . unwrap ( ) [ CapMapType :: Sc as usize ] =
681- Some ( pd_sc_cap. clone ( ) ) ;
677+ pd_shadow_cspace_inner. insert ( CapMapType :: Sc , pd_sc_cap. clone ( ) ) ;
682678
683679 caps_to_bind_to_tcb. push ( capdl_util_make_cte (
684680 TcbBoundSlot :: SchedContext as u32 ,
@@ -996,8 +992,7 @@ pub fn build_capdl_spec(
996992 ) ;
997993 let pd_guard_size = kernel_config. cap_address_bits - PD_CAP_BITS as u64 ;
998994 let pd_cnode_cap = capdl_util_make_cnode_cap ( pd_cnode_obj_id, 0 , pd_guard_size as u8 ) ;
999- pd_shadow_cspace. get_mut ( & pd_global_idx) . unwrap ( ) [ CapMapType :: Cnode as usize ] =
1000- Some ( pd_cnode_cap. clone ( ) ) ;
995+ pd_shadow_cspace_inner. insert ( CapMapType :: Cnode , pd_cnode_cap. clone ( ) ) ;
1001996 caps_to_bind_to_tcb. push ( capdl_util_make_cte (
1002997 TcbBoundSlot :: CSpace as u32 ,
1003998 pd_cnode_cap,
@@ -1048,6 +1043,7 @@ pub fn build_capdl_spec(
10481043 capdl_util_make_ntfn_cap ( pd_ntfn_obj_id, true , true , 0 ) ,
10491044 ) ;
10501045 }
1046+ pd_shadow_cspace. insert ( pd_global_idx, pd_shadow_cspace_inner) ;
10511047 }
10521048
10531049 // *********************************
@@ -1119,22 +1115,24 @@ pub fn build_capdl_spec(
11191115
11201116 for ( pd_dest_idx, pd) in system. protection_domains . iter ( ) . enumerate ( ) {
11211117 let pd_dest_cspace_id = pd_id_to_cspace_id[ & pd_dest_idx] ;
1122-
11231118 for cap_map in pd. cap_maps . iter ( ) {
11241119 let pd_src_idx = pd_name_to_id. get ( & cap_map. pd_name ) . ok_or ( format ! (
11251120 "PD: '{}', does not exist when trying to map extra TCB cap into PD: '{}'" ,
11261121 cap_map. pd_name, pd. name
11271122 ) ) ?;
11281123
1129- let pd_obj = pd_shadow_cspace[ pd_src_idx] [ cap_map. cap_type as usize ]
1130- . as_ref ( )
1131- . unwrap ( ) ;
1124+ let pd_shadow_cspace_inner = pd_shadow_cspace. get ( pd_src_idx) . unwrap ( ) ;
1125+
1126+ let pd_obj = pd_shadow_cspace_inner
1127+ . get ( & cap_map. cap_type )
1128+ . unwrap ( )
1129+ . clone ( ) ;
11321130 // Map this into the destination pd's cspace and the specified slot.
11331131 capdl_util_insert_cap_into_cspace (
11341132 & mut spec_container,
11351133 pd_dest_cspace_id,
11361134 ( PD_BASE_USER_CAPS + cap_map. dest_cspace_slot ) as u32 ,
1137- pd_obj. clone ( ) ,
1135+ pd_obj,
11381136 ) ;
11391137 }
11401138 }
0 commit comments