Skip to content

Commit d65777d

Browse files
committed
tool: add child_pt tag checks
Signed-off-by: Krishnan Winter <krishnan-git@wintermail.me>
1 parent dac489a commit d65777d

File tree

1 file changed

+76
-72
lines changed

1 file changed

+76
-72
lines changed

tool/microkit/src/main.rs

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,93 +2046,97 @@ fn build_system(
20462046

20472047
let mut frame_cap = BASE_FRAME_CAP;
20482048

2049-
for (pd_idx, _) in system.protection_domains.iter().enumerate() {
2050-
for maybe_child_pd in system.protection_domains.iter() {
2051-
if maybe_child_pd.parent.is_some_and(|x| x == pd_idx) {
2052-
for map_set in [&maybe_child_pd.maps, &pd_extra_maps[maybe_child_pd]] {
2053-
for mp in map_set {
2054-
let mr = all_mr_by_name[mp.mr.as_str()];
2055-
let mut invocation = Invocation::new(
2056-
config,
2057-
InvocationArgs::CnodeMint {
2058-
cnode: cnode_objs[pd_idx].cap_addr,
2059-
dest_index: frame_cap,
2060-
dest_depth: PD_CAP_BITS,
2061-
src_root: root_cnode_cap,
2062-
src_obj: mr_pages[mr][0].cap_addr,
2063-
src_depth: config.cap_address_bits,
2064-
rights: (Rights::Read as u64 | Rights::Write as u64),
2065-
badge: 0,
2066-
},
2067-
);
2068-
2069-
invocation.repeat(
2070-
mr_pages[mr].len() as u32,
2071-
InvocationArgs::CnodeMint {
2072-
cnode: 0,
2073-
dest_index: 1,
2074-
dest_depth: 0,
2075-
src_root: 0,
2076-
src_obj: 1,
2077-
src_depth: 0,
2078-
rights: 0,
2079-
badge: 0,
2080-
},
2081-
);
2082-
2083-
for mr_idx in 0..mr_pages[mr].len() {
2084-
let vaddr = mp.vaddr + mr.page_size_bytes() * mr_idx as u64;
2085-
let minted_cap = frame_cap + mr_idx as u64;
2086-
2087-
all_child_page_tables[pd_idx].as_mut().unwrap()
2088-
[maybe_child_pd.id.unwrap() as usize]
2089-
.add_page_at_vaddr(vaddr, minted_cap, mr.page_size);
2090-
}
2049+
for (pd_idx, pd) in system.protection_domains.iter().enumerate() {
2050+
if pd.child_pts {
2051+
for maybe_child_pd in system.protection_domains.iter() {
2052+
if maybe_child_pd.parent.is_some_and(|x| x == pd_idx) {
2053+
for map_set in [&maybe_child_pd.maps, &pd_extra_maps[maybe_child_pd]] {
2054+
for mp in map_set {
2055+
let mr = all_mr_by_name[mp.mr.as_str()];
2056+
let mut invocation = Invocation::new(
2057+
config,
2058+
InvocationArgs::CnodeMint {
2059+
cnode: cnode_objs[pd_idx].cap_addr,
2060+
dest_index: frame_cap,
2061+
dest_depth: PD_CAP_BITS,
2062+
src_root: root_cnode_cap,
2063+
src_obj: mr_pages[mr][0].cap_addr,
2064+
src_depth: config.cap_address_bits,
2065+
rights: (Rights::Read as u64 | Rights::Write as u64),
2066+
badge: 0,
2067+
},
2068+
);
2069+
2070+
invocation.repeat(
2071+
mr_pages[mr].len() as u32,
2072+
InvocationArgs::CnodeMint {
2073+
cnode: 0,
2074+
dest_index: 1,
2075+
dest_depth: 0,
2076+
src_root: 0,
2077+
src_obj: 1,
2078+
src_depth: 0,
2079+
rights: 0,
2080+
badge: 0,
2081+
},
2082+
);
20912083

2092-
frame_cap += mr_pages[mr].len() as u64;
2093-
system_invocations.push(invocation);
2084+
for mr_idx in 0..mr_pages[mr].len() {
2085+
let vaddr = mp.vaddr + mr.page_size_bytes() * mr_idx as u64;
2086+
let minted_cap = frame_cap + mr_idx as u64;
2087+
2088+
all_child_page_tables[pd_idx].as_mut().unwrap()
2089+
[maybe_child_pd.id.unwrap() as usize]
2090+
.add_page_at_vaddr(vaddr, minted_cap, mr.page_size);
2091+
}
2092+
2093+
frame_cap += mr_pages[mr].len() as u64;
2094+
system_invocations.push(invocation);
2095+
}
20942096
}
20952097
}
20962098
}
20972099
}
20982100
}
20992101

2100-
for (pd_idx, _) in system.protection_domains.iter().enumerate() {
2101-
let mut child_pds: Vec<usize> = vec![];
2102+
for (pd_idx, pd) in system.protection_domains.iter().enumerate() {
2103+
if pd.child_pts {
2104+
let mut child_pds: Vec<usize> = vec![];
21022105

2103-
for maybe_child_pd in system.protection_domains.iter() {
2104-
if let Some(parent_idx) = maybe_child_pd.parent {
2105-
if parent_idx == pd_idx {
2106-
let id = maybe_child_pd.id.unwrap() as usize;
2107-
child_pds.push(id);
2106+
for maybe_child_pd in system.protection_domains.iter() {
2107+
if let Some(parent_idx) = maybe_child_pd.parent {
2108+
if parent_idx == pd_idx {
2109+
let id = maybe_child_pd.id.unwrap() as usize;
2110+
child_pds.push(id);
2111+
}
21082112
}
21092113
}
2110-
}
21112114

2112-
if child_pds.is_empty() {
2113-
continue;
2114-
}
2115+
if child_pds.is_empty() {
2116+
continue;
2117+
}
21152118

2116-
let mut table_metadata = TableMetadata {
2117-
base_addr: 0,
2118-
pgd: [0; 64],
2119-
};
2120-
let mut table_data = Vec::<u8>::new();
2121-
let mut offset = 0;
2119+
let mut table_metadata = TableMetadata {
2120+
base_addr: 0,
2121+
pgd: [0; 64],
2122+
};
2123+
let mut table_data = Vec::<u8>::new();
2124+
let mut offset = 0;
21222125

2123-
for i in child_pds {
2124-
offset =
2125-
all_child_page_tables[pd_idx].as_mut().unwrap()[i].recurse(offset, &mut table_data);
2126-
table_metadata.pgd[i] = offset - (512 * 8);
2127-
}
2126+
for i in child_pds {
2127+
offset =
2128+
all_child_page_tables[pd_idx].as_mut().unwrap()[i].recurse(offset, &mut table_data);
2129+
table_metadata.pgd[i] = offset - (512 * 8);
2130+
}
21282131

2129-
// patch the data in
2130-
let elf = &mut pd_elf_files[pd_idx];
2131-
elf.populate_segment(".table_data", &table_data);
2132-
let new_elf_seg = elf.get_segment(".table_data").unwrap();
2132+
// patch the data in
2133+
let elf = &mut pd_elf_files[pd_idx];
2134+
elf.populate_segment(".table_data", &table_data);
2135+
let new_elf_seg = elf.get_segment(".table_data").unwrap();
21332136

2134-
table_metadata.base_addr = new_elf_seg.virt_addr;
2135-
elf.write_symbol("table_metadata", table_metadata.as_bytes())?;
2137+
table_metadata.base_addr = new_elf_seg.virt_addr;
2138+
elf.write_symbol("table_metadata", table_metadata.as_bytes())?;
2139+
}
21362140
}
21372141

21382142
let mut badged_irq_caps: HashMap<&ProtectionDomain, Vec<u64>> = HashMap::new();

0 commit comments

Comments
 (0)