@@ -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,19 @@ 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+ // @kwinter: Making this size 10, this covers a PD's basic caps. Not sure if we should change to a hashmap or something in
585+ // the future
586+ pd_shadow_cspace
587+ . entry ( pd_global_idx)
588+ . or_insert_with ( || vec ! [ None ; 10 ] ) [ CapMapType :: Tcb as usize ] = Some ( pd_tcb_obj. clone ( ) ) ;
584589
585590 // In the benchmark configuration, we allow PDs to access their own TCB.
586591 // This is necessary for accessing kernel's benchmark API.
587592 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- ) ) ;
593+ caps_to_insert_to_pd_cspace
594+ . push ( capdl_util_make_cte ( PD_TCB_CAP_IDX as u32 , pd_tcb_obj) ) ;
592595 }
593596
594597 // Allow PD to access their own VSpace for ops such as cache cleaning on ARM.
@@ -673,9 +676,11 @@ pub fn build_capdl_spec(
673676 0x100 + pd_global_idx as u64 ,
674677 ) ;
675678
676- pd_id_to_sc_id. insert ( pd_global_idx, pd_sc_obj_id) ;
677-
678679 let pd_sc_cap = capdl_util_make_sc_cap ( pd_sc_obj_id) ;
680+
681+ pd_shadow_cspace. get_mut ( & pd_global_idx) . unwrap ( ) [ CapMapType :: Sc as usize ] =
682+ Some ( pd_sc_cap. clone ( ) ) ;
683+
679684 caps_to_bind_to_tcb. push ( capdl_util_make_cte (
680685 TcbBoundSlot :: SchedContext as u32 ,
681686 pd_sc_cap,
@@ -1120,36 +1125,16 @@ pub fn build_capdl_spec(
11201125 cap_map. pd_name, pd. name
11211126 ) ) ?;
11221127
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- }
1128+ let pd_obj = pd_shadow_cspace. get ( pd_src_idx) . unwrap ( ) [ cap_map. cap_type as usize ]
1129+ . as_ref ( )
1130+ . unwrap ( ) ;
1131+ // Map this into the destination pd's cspace and the specified slot.
1132+ capdl_util_insert_cap_into_cspace (
1133+ & mut spec_container,
1134+ pd_dest_cspace_id,
1135+ ( PD_BASE_USER_CAPS + cap_map. dest_cspace_slot ) as u32 ,
1136+ pd_obj. clone ( ) ,
1137+ ) ;
11531138 }
11541139 }
11551140
0 commit comments