@@ -37,6 +37,10 @@ use std::path::{Path, PathBuf};
3737const PD_MAX_ID : u64 = 61 ;
3838const VCPU_MAX_ID : u64 = PD_MAX_ID ;
3939
40+ /// This is the maximum slot allowed for cap maps. This can change if you wish,
41+ /// but also update the MICROKIT_MAX_USER_CAPS define in `microkit.h`.
42+ const CAP_MAP_MAX_SLOT : u64 = 128 ;
43+
4044pub const MONITOR_PRIORITY : u8 = 255 ;
4145const PD_MAX_PRIORITY : u8 = 254 ;
4246/// In microseconds
@@ -276,13 +280,15 @@ pub struct ProtectionDomain {
276280 text_pos : Option < roxmltree:: TextPos > ,
277281}
278282
283+ /// Update CAP_MAP_TYPES whenever making changes to the CapMapType enum
284+ pub const CAP_MAP_TYPES : usize = 4 ;
285+
279286#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
280287pub enum CapMapType {
281288 Tcb = 0 ,
282289 Sc ,
283290 Vspace ,
284291 Cnode ,
285- __Len,
286292}
287293
288294#[ derive( Debug , PartialEq , Eq ) ]
@@ -1240,29 +1246,24 @@ impl CapMap {
12401246 fn from_xml ( xml_sdf : & XmlSystemDescription , node : & roxmltree:: Node ) -> Result < CapMap , String > {
12411247 check_attributes ( xml_sdf, node, & [ "type" , "pd" , "dest_cspace_slot" ] ) ?;
12421248
1243- let cap_type = match checked_lookup ( xml_sdf, node, "type" ) ? {
1249+ let xml_cap_type = checked_lookup ( xml_sdf, node, "type" ) ?;
1250+ let cap_type = match xml_cap_type {
12441251 "tcb" => CapMapType :: Tcb ,
12451252 "sc" => CapMapType :: Sc ,
12461253 "vspace" => CapMapType :: Vspace ,
12471254 "cnode" => CapMapType :: Cnode ,
1248- _ => {
1249- return Err ( value_error (
1250- xml_sdf,
1251- node,
1252- "type must be 'tcb' or 'sc' " . to_string ( ) ,
1253- ) )
1254- }
1255+ _ => return Err ( format ! ( "Cap type: '{}' is not supported." , xml_cap_type, ) ) ,
12551256 } ;
12561257
12571258 let pd_name = checked_lookup ( xml_sdf, node, "pd" ) ?. to_string ( ) ;
12581259 let dest_cspace_slot =
12591260 sdf_parse_number ( checked_lookup ( xml_sdf, node, "dest_cspace_slot" ) ?, node) ?;
12601261
1261- if dest_cspace_slot >= 128 {
1262+ if dest_cspace_slot >= CAP_MAP_MAX_SLOT {
12621263 return Err ( value_error (
12631264 xml_sdf,
12641265 node,
1265- "There are only 128 destination cspace slots available. Max slot allowed is 63"
1266+ format ! ( "There are only {CAP_MAP_MAX_SLOT} destination cspace slots available." )
12661267 . to_string ( ) ,
12671268 ) ) ;
12681269 }
@@ -1956,7 +1957,7 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
19561957 let mut user_cap_slots = Vec :: new ( ) ;
19571958 let mut seen_pd_cap_maps: Vec < ( CapMapType , String ) > = Vec :: new ( ) ;
19581959
1959- for cap_map in pd. cap_maps . iter ( ) {
1960+ for cap_map in & pd. cap_maps {
19601961 if user_cap_slots. contains ( & cap_map. dest_cspace_slot ) {
19611962 return Err ( format ! (
19621963 "Error: Overlapping cap slot: {} in protection domain: '{}'" ,
@@ -1968,9 +1969,9 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
19681969
19691970 if seen_pd_cap_maps. contains ( & ( cap_map. cap_type , cap_map. pd_name . clone ( ) ) ) {
19701971 return Err ( format ! (
1971- "Error: Duplicate cap mapping of type '{:?}'. Src PD: '{}', dest PD: '{}'." ,
1972- cap_map. cap_type, cap_map. pd_name, pd. name
1973- ) ) ;
1972+ "Error: Duplicate cap mapping of type '{:?}'. Src PD: '{}', dest PD: '{}'." ,
1973+ cap_map. cap_type, cap_map. pd_name, pd. name
1974+ ) ) ;
19741975 } else {
19751976 seen_pd_cap_maps. push ( ( cap_map. cap_type . clone ( ) , cap_map. pd_name . clone ( ) ) )
19761977 }
0 commit comments