Skip to content

Commit e2661e0

Browse files
committed
sdf: Simplify error checking for extra cap maps
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent 514cf01 commit e2661e0

File tree

1 file changed

+8
-40
lines changed

1 file changed

+8
-40
lines changed

tool/microkit/src/sdf.rs

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,13 +1951,10 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
19511951
}
19521952

19531953
// Ensure that there are no overlapping extra cap maps in the user caps region
1954-
// and we are not mapping in the same tcb/sc
1954+
// and we are not mapping in the same cap from the same source more than once
19551955
for pd in &pds {
19561956
let mut user_cap_slots = Vec::new();
1957-
let mut user_tcb_names = Vec::new();
1958-
let mut user_sc_names = Vec::new();
1959-
let mut user_vspace_names = Vec::new();
1960-
let mut user_cnode_names = Vec::new();
1957+
let mut seen_pd_cap_maps: Vec<(CapMapType, String)> = Vec::new();
19611958

19621959
for cap_map in pd.cap_maps.iter() {
19631960
if user_cap_slots.contains(&cap_map.dest_cspace_slot) {
@@ -1969,42 +1966,13 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
19691966
user_cap_slots.push(cap_map.dest_cspace_slot);
19701967
}
19711968

1972-
if cap_map.cap_type == CapMapType::Tcb {
1973-
if user_tcb_names.contains(&cap_map.pd_name) {
1974-
return Err(format!(
1975-
"Error: Duplicate tcb cap mapping. Src PD: '{}', dest PD: '{}'",
1976-
cap_map.pd_name, pd.name
1977-
));
1978-
} else {
1979-
user_tcb_names.push(cap_map.pd_name.clone());
1980-
}
1981-
} else if cap_map.cap_type == CapMapType::Sc {
1982-
if user_sc_names.contains(&cap_map.pd_name) {
1983-
return Err(format!(
1984-
"Error: Duplicate sc cap mapping. Src PD: '{}', dest PD: '{}'",
1985-
cap_map.pd_name, pd.name
1986-
));
1987-
} else {
1988-
user_sc_names.push(cap_map.pd_name.clone());
1989-
}
1990-
} else if cap_map.cap_type == CapMapType::Vspace {
1991-
if user_vspace_names.contains(&cap_map.pd_name) {
1992-
return Err(format!(
1993-
"Error: Duplicate vspace cap mapping. Src PD: '{}', dest PD: '{}'",
1994-
cap_map.pd_name, pd.name
1995-
));
1996-
} else {
1997-
user_vspace_names.push(cap_map.pd_name.clone());
1998-
}
1999-
} else if cap_map.cap_type == CapMapType::Cnode {
2000-
if user_cnode_names.contains(&cap_map.pd_name) {
2001-
return Err(format!(
2002-
"Error: Duplicate cnode cap mapping. Src PD: '{}', dest PD: '{}'",
2003-
cap_map.pd_name, pd.name
1969+
if seen_pd_cap_maps.contains(&(cap_map.cap_type, cap_map.pd_name.clone())) {
1970+
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
20041973
));
2005-
} else {
2006-
user_cnode_names.push(cap_map.pd_name.clone());
2007-
}
1974+
} else {
1975+
seen_pd_cap_maps.push((cap_map.cap_type.clone(), cap_map.pd_name.clone()))
20081976
}
20091977
}
20101978
}

0 commit comments

Comments
 (0)