Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tool/microkit/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn build_system(
// a list like this.
let mut system_elfs = Vec::with_capacity(system.protection_domains.len());
// Get the elf files for each pd:
for pd in &system.protection_domains {
for pd in system.protection_domains.values() {
match get_full_path(&pd.program_image, &args.search_paths) {
Some(path) => {
let path_for_symbols = pd
Expand Down
40 changes: 20 additions & 20 deletions tool/microkit/src/capdl/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use core::ops::Range;

use std::{
cmp::{min, Ordering},
collections::HashMap,
collections::{BTreeMap, HashMap},
rc::Rc,
};

use sel4_capdl_initializer_types::{
Expand Down Expand Up @@ -532,7 +533,7 @@ pub fn build_capdl_spec(
// *********************************
// Step 2. Create the memory regions' spec. Result is a hashmap keyed on MR name, value is (parsed XML obj, Vec of frame object IDs)
// *********************************
let mut mr_name_to_frames: HashMap<&String, Vec<ObjectId>> = HashMap::new();
let mut mr_name_to_frames: BTreeMap<&str, Vec<ObjectId>> = BTreeMap::new();
for mr in system.memory_regions.iter() {
let mut frame_ids = Vec::new();
let frame_size_bits = mr.page_size.fixed_size_bits(kernel_config);
Expand Down Expand Up @@ -606,7 +607,7 @@ pub fn build_capdl_spec(
// On ARM, check if we need to create the SMC object
let arm_smc_obj_id = if kernel_config.arch == Arch::Aarch64
&& kernel_config.arm_smc.unwrap_or(false)
&& system.protection_domains.iter().any(|pd| pd.smc)
&& system.protection_domains.values().any(|pd| pd.smc)
{
Some(spec_container.add_root_object(NamedObject {
name: "arm_smc".to_owned().into(),
Expand All @@ -618,7 +619,7 @@ pub fn build_capdl_spec(

// This object keeps track of object IDs for various 'important' / nameable kernel objects for
// each PD so that we can make various references to them at later steps.
let mut pd_shadow_cspaces: HashMap<usize, PDShadowCspace> = HashMap::new();
let mut pd_shadow_cspaces: BTreeMap<Rc<str>, PDShadowCspace> = BTreeMap::new();

// Keep track of the global count of vCPU objects so we can bind them to the monitor for setting TCB name in debug config.
// 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.
Expand All @@ -627,7 +628,7 @@ pub fn build_capdl_spec(
// Keep tabs on each PD's stack bottom so we can write it out to the monitor for stack overflow detection.
let mut pd_stack_bottoms: Vec<u64> = Vec::new();

for (pd_global_idx, pd) in system.protection_domains.iter().enumerate() {
for (pd_global_idx, pd) in system.protection_domains.values().enumerate() {
let elf_obj = &elfs[pd_global_idx];

let mut caps_to_bind_to_tcb: Vec<CapTableEntry> = Vec::new();
Expand Down Expand Up @@ -658,7 +659,7 @@ pub fn build_capdl_spec(

// Step 3-2: Map in all Memory Regions
for map in pd.maps.iter() {
let frames = &mr_name_to_frames[&map.mr];
let frames = &mr_name_to_frames[map.mr.as_str()];
// MRs have frames of equal size so just use the first frame's page size.
let page_size_bytes =
1 << capdl_util_get_frame_size_bits(&spec_container, *frames.first().unwrap());
Expand Down Expand Up @@ -761,10 +762,9 @@ pub fn build_capdl_spec(
));

// Step 3-5 Create fault Endpoint cap to parent/monitor
let pd_fault_ep_cap = if let Some(pd_parent_id) = pd.parent {
assert!(pd_global_idx > pd_parent_id);
let pd_fault_ep_cap = if let Some(pd_parent) = &pd.parent {
let badge: u64 = FAULT_BADGE | pd.id.unwrap();
let parent_shadow_cspace = &pd_shadow_cspaces[&pd_parent_id];
let parent_shadow_cspace = &pd_shadow_cspaces[pd_parent];
let parent_ep_obj_id = parent_shadow_cspace
.endpoint
.expect("parent should have EP due to needs_ep()");
Expand Down Expand Up @@ -812,7 +812,7 @@ pub fn build_capdl_spec(
let pd_ntfn_obj_id = capdl_util_make_ntfn_obj(&mut spec_container, &pd.name);
let pd_ntfn_cap = capdl_util_make_ntfn_cap(pd_ntfn_obj_id, true, true, 0);
let mut pd_ep_obj_id: Option<ObjectId> = None;
if pd.needs_ep(pd_global_idx, &system.channels) {
if pd.needs_ep(&system.channels) {
pd_ep_obj_id = Some(capdl_util_make_endpoint_obj(
&mut spec_container,
&pd.name,
Expand Down Expand Up @@ -883,7 +883,7 @@ pub fn build_capdl_spec(
let vm_vspace_obj_id = vm_address_space.root();
let vm_vspace_cap = capdl_util_make_page_table_cap(vm_vspace_obj_id);
for map in virtual_machine.maps.iter() {
let frames = &mr_name_to_frames[&map.mr];
let frames = &mr_name_to_frames[map.mr.as_str()];
let page_size_bytes =
1 << capdl_util_get_frame_size_bits(&spec_container, *frames.first().unwrap());
map_memory_region(
Expand Down Expand Up @@ -1071,7 +1071,7 @@ pub fn build_capdl_spec(

let pd_root_cnode_obj_id = capdl_util_make_cnode_obj(
&mut spec_container,
&(pd.name.clone() + "_root"),
&format!("{}_root", pd.name),
PD_ROOT_CAP_BITS,
Vec::new(),
);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ pub fn build_capdl_spec(
}

pd_shadow_cspaces.insert(
pd_global_idx,
pd.name.clone(),
PDShadowCspace {
cspace: pd_root_cnode_obj_id,
microkit_cnode: pd_cnode_obj_id,
Expand Down Expand Up @@ -1218,7 +1218,7 @@ pub fn build_capdl_spec(
// *********************************
// Step 5. Create IOMMU Address Spaces
// *********************************
let mut iospace_by_device: HashMap<&str, AddressSpace> = HashMap::new();
let mut iospace_by_device: BTreeMap<&str, AddressSpace> = BTreeMap::new();
for iomap in system.iomaps.iter() {
let address_space = iospace_by_device.entry(&iomap.name).or_insert_with(|| {
create_iospace(
Expand All @@ -1230,7 +1230,7 @@ pub fn build_capdl_spec(
)
});
let page_size_bytes = mr_name_to_frames
.get(&iomap.mr)
.get(iomap.mr.as_str())
.ok_or(format!(
"Error: Memory region {} referenced by iomap not found.",
iomap.mr
Expand All @@ -1248,18 +1248,18 @@ pub fn build_capdl_spec(
iomap,
page_size_bytes,
address_space,
&mr_name_to_frames[&iomap.mr],
&mr_name_to_frames[iomap.mr.as_str()],
)?;
}

// *********************************
// Step 6. Handle extra cap mappings
// *********************************
for (pd_dest_idx, pd) in system.protection_domains.iter().enumerate() {
for pd in system.protection_domains.values() {
for cap_map in pd.cap_maps.iter() {
// TODO: Once we add more CapMap options, they might not all have
// the pd_name. But for now, they do.
let pd_src_shadow_cspace = &pd_shadow_cspaces[&cap_map.pd.unwrap()];
let pd_src_shadow_cspace = &pd_shadow_cspaces[&cap_map.pd];

let cap_map_obj = match cap_map.cap_type {
CapMapType::Tcb => capdl_util_make_tcb_cap(pd_src_shadow_cspace.tcb),
Expand All @@ -1268,7 +1268,7 @@ pub fn build_capdl_spec(
};

// Map this into the destination pd's cspace and the specified slot.
pd_shadow_cspaces[&pd_dest_idx].insert_cap_into_root_cnode(
pd_shadow_cspaces[&pd.name].insert_cap_into_root_cnode(
&mut spec_container,
cap_map.slot as u32,
cap_map_obj,
Expand Down Expand Up @@ -1298,7 +1298,7 @@ pub fn build_capdl_spec(
// 4. Recurse through every cap, for any cap bearing the original object ID, write the new object ID.

// Step 8-1
let mut obj_name_to_old_id: HashMap<String, ObjectId> = HashMap::new();
let mut obj_name_to_old_id: BTreeMap<String, ObjectId> = BTreeMap::new();
for (id, obj) in spec_container.spec.objects.iter().enumerate() {
obj_name_to_old_id.insert(obj.name.as_ref().unwrap().clone(), id.into());
}
Expand Down
5 changes: 1 addition & 4 deletions tool/microkit/src/capdl/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,7 @@ pub fn capdl_util_insert_cap_into_cspace(
}
}

pub fn capdl_util_make_vcpu_obj(
spec_container: &mut CapDLSpecContainer,
name: &String,
) -> ObjectId {
pub fn capdl_util_make_vcpu_obj(spec_container: &mut CapDLSpecContainer, name: &str) -> ObjectId {
let vcpu_inner_obj = Object::VCpu;
let vcpu_obj = CapDLNamedObject {
name: format!("vcpu_{name}").into(),
Expand Down
12 changes: 6 additions & 6 deletions tool/microkit/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::sel4::PageSize;
use crate::util::{bytes_to_struct, round_down, struct_to_bytes};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::fs::{self, metadata, File};
use std::io::Write;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -212,7 +212,7 @@ pub struct ElfFile {
pub machine: u16,
pub segments: Vec<ElfSegment>,
pub program_headers: Vec<ProgramHeader>,
symbols: HashMap<String, (ElfSymbol64, bool)>,
symbols: BTreeMap<String, (ElfSymbol64, bool)>,
}

impl ElfFile {
Expand All @@ -224,7 +224,7 @@ impl ElfFile {
machine,
segments: vec![],
program_headers: vec![],
symbols: HashMap::new(),
symbols: BTreeMap::new(),
}
}

Expand Down Expand Up @@ -373,7 +373,7 @@ impl ElfFileReader {
Ok(segments)
}

fn symbols(&self) -> Result<HashMap<String, (ElfSymbol64, bool)>, String> {
fn symbols(&self) -> Result<BTreeMap<String, (ElfSymbol64, bool)>, String> {
let hdr = &self.hdr;

// Read all the section headers
Expand Down Expand Up @@ -406,7 +406,7 @@ impl ElfFileReader {
let symtab_str = &self.bytes[symtab_str_start..symtab_str_end];

// Read all the symbols
let mut symbols: HashMap<String, (ElfSymbol64, bool)> = HashMap::new();
let mut symbols: BTreeMap<String, (ElfSymbol64, bool)> = BTreeMap::new();
let mut offset = 0;
let symbol_size = std::mem::size_of::<ElfSymbol64>();
while offset < symtab.len() {
Expand Down Expand Up @@ -649,7 +649,7 @@ impl ElfFile {
+ (shnum as u64) * (shentsize as u64);

// First thing to do is work out where to place all the data segments
let mut seg_idx_to_data_off: HashMap<usize, u64> = Default::default();
let mut seg_idx_to_data_off: BTreeMap<usize, u64> = Default::default();
for (i, seg) in self.loadable_segments().iter().enumerate() {
seg_idx_to_data_off.insert(i, data_off_watermark);
data_off_watermark += seg.file_size();
Expand Down
Loading
Loading