@@ -11,8 +11,8 @@ use std::{
1111} ;
1212
1313use sel4_capdl_initializer_types:: {
14- object, CapTableEntry , Fill , FillEntry , FillEntryContent , NamedObject , Object , ObjectId , Spec ,
15- Word ,
14+ object, Cap , CapTableEntry , Fill , FillEntry , FillEntryContent , NamedObject , Object , ObjectId ,
15+ Spec , Word ,
1616} ;
1717
1818use crate :: {
@@ -556,8 +556,7 @@ pub fn build_capdl_spec(
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_id_to_tcb_id: HashMap < usize , ObjectId > = HashMap :: new ( ) ;
560- let mut pd_id_to_sc_id: HashMap < usize , ObjectId > = HashMap :: new ( ) ;
559+ let mut pd_shadow_cspace: HashMap < usize , Vec < Option < Cap > > > = HashMap :: new ( ) ;
561560
562561 // Keep track of the global count of vCPU objects so we can bind them to the monitor for setting TCB name in debug config.
563562 // 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.
@@ -580,15 +579,17 @@ pub fn build_capdl_spec(
580579 . unwrap ( ) ;
581580 let pd_vspace_obj_id = capdl_util_get_vspace_id_from_tcb_id ( & spec_container, pd_tcb_obj_id) ;
582581
583- pd_id_to_tcb_id. insert ( pd_global_idx, pd_tcb_obj_id) ;
582+ let pd_tcb_obj = capdl_util_make_tcb_cap ( pd_tcb_obj_id) ;
583+
584+ pd_shadow_cspace
585+ . entry ( pd_global_idx)
586+ . or_insert_with ( || vec ! [ None ; CapMapType :: __Len as usize ] ) [ CapMapType :: Tcb as usize ] = Some ( pd_tcb_obj. clone ( ) ) ;
584587
585588 // In the benchmark configuration, we allow PDs to access their own TCB.
586589 // This is necessary for accessing kernel's benchmark API.
587590 if kernel_config. benchmark {
588- caps_to_insert_to_pd_cspace. push ( capdl_util_make_cte (
589- PD_TCB_CAP_IDX as u32 ,
590- capdl_util_make_tcb_cap ( pd_tcb_obj_id) ,
591- ) ) ;
591+ caps_to_insert_to_pd_cspace
592+ . push ( capdl_util_make_cte ( PD_TCB_CAP_IDX as u32 , pd_tcb_obj) ) ;
592593 }
593594
594595 // Allow PD to access their own VSpace for ops such as cache cleaning on ARM.
@@ -673,9 +674,11 @@ pub fn build_capdl_spec(
673674 0x100 + pd_global_idx as u64 ,
674675 ) ;
675676
676- pd_id_to_sc_id. insert ( pd_global_idx, pd_sc_obj_id) ;
677-
678677 let pd_sc_cap = capdl_util_make_sc_cap ( pd_sc_obj_id) ;
678+
679+ pd_shadow_cspace. get_mut ( & pd_global_idx) . unwrap ( ) [ CapMapType :: Sc as usize ] =
680+ Some ( pd_sc_cap. clone ( ) ) ;
681+
679682 caps_to_bind_to_tcb. push ( capdl_util_make_cte (
680683 TcbBoundSlot :: SchedContext as u32 ,
681684 pd_sc_cap,
@@ -1120,36 +1123,16 @@ pub fn build_capdl_spec(
11201123 cap_map. pd_name, pd. name
11211124 ) ) ?;
11221125
1123- if cap_map. cap_type == CapMapType :: Tcb {
1124- // Get the TCB of the pd referenced in cap_map name
1125- let pd_tcb_id = * pd_id_to_tcb_id. get ( pd_src_idx) . unwrap ( ) ;
1126-
1127- // Map this into the destination pd's cspace and the specified slot.
1128- let pd_tcb_cap = capdl_util_make_tcb_cap ( pd_tcb_id) ;
1129- capdl_util_insert_cap_into_cspace (
1130- & mut spec_container,
1131- pd_dest_cspace_id,
1132- ( PD_BASE_USER_CAPS + cap_map. dest_cspace_slot ) as u32 ,
1133- pd_tcb_cap,
1134- ) ;
1135- } else if cap_map. cap_type == CapMapType :: Sc {
1136- if system. protection_domains [ * pd_src_idx] . passive {
1137- return Err ( format ! (
1138- "Trying to map scheduling context of a passive PD: '{}' into PD: '{}'" ,
1139- cap_map. pd_name, pd. name
1140- ) ) ;
1141- }
1142-
1143- let pd_sc_id = * pd_id_to_sc_id. get ( pd_src_idx) . unwrap ( ) ;
1144-
1145- let pd_sc_cap = capdl_util_make_tcb_cap ( pd_sc_id) ;
1146- capdl_util_insert_cap_into_cspace (
1147- & mut spec_container,
1148- pd_dest_cspace_id,
1149- ( PD_BASE_USER_CAPS + cap_map. dest_cspace_slot ) as u32 ,
1150- pd_sc_cap,
1151- ) ;
1152- }
1126+ let pd_obj = pd_shadow_cspace. get ( pd_src_idx) . unwrap ( ) [ cap_map. cap_type as usize ]
1127+ . as_ref ( )
1128+ . unwrap ( ) ;
1129+ // Map this into the destination pd's cspace and the specified slot.
1130+ capdl_util_insert_cap_into_cspace (
1131+ & mut spec_container,
1132+ pd_dest_cspace_id,
1133+ ( PD_BASE_USER_CAPS + cap_map. dest_cspace_slot ) as u32 ,
1134+ pd_obj. clone ( ) ,
1135+ ) ;
11531136 }
11541137 }
11551138
0 commit comments