Skip to content

Commit a3b6e88

Browse files
committed
run rust-fmt and clippy fix
Signed-off-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
1 parent 66f28dd commit a3b6e88

5 files changed

Lines changed: 70 additions & 64 deletions

File tree

tool/microkit/src/capdl/builder.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::{
1111
};
1212

1313
use sel4_capdl_initializer_types::{
14-
object, CapTableEntry, Fill, FillEntry, FillEntryContent, NamedObject, Object, ObjectId, Spec,
15-
Word, DomainSchedEntry,
14+
object, CapTableEntry, DomainSchedEntry, Fill, FillEntry, FillEntryContent, NamedObject,
15+
Object, ObjectId, Spec, Word,
1616
};
1717

1818
use crate::{
@@ -410,8 +410,7 @@ pub fn build_capdl_spec(
410410
for pd in system.protection_domains.iter() {
411411
if pd.name == monitor_name {
412412
return Err(format!(
413-
"Error: User defined PD name clashes with monitor name '{}'",
414-
monitor_name,
413+
"Error: User defined PD name clashes with monitor name '{monitor_name}'",
415414
));
416415
}
417416
}
@@ -432,7 +431,8 @@ pub fn build_capdl_spec(
432431
// Create monitor fault endpoint object + cap
433432
let mon_fault_ep_obj_id =
434433
capdl_util_make_endpoint_obj(&mut spec_container, monitor_name_str, true);
435-
let mon_fault_ep_cap = capdl_util_make_endpoint_cap(mon_fault_ep_obj_id, true, true, true, 0);
434+
let mon_fault_ep_cap =
435+
capdl_util_make_endpoint_cap(mon_fault_ep_obj_id, true, true, true, 0);
436436

437437
mon_fault_ep_id_by_dom.push(mon_fault_ep_obj_id);
438438

@@ -593,7 +593,13 @@ pub fn build_capdl_spec(
593593

594594
// Step 3-1: Create TCB and VSpace with all ELF loadable frames mapped in.
595595
let pd_tcb_obj_id = spec_container
596-
.add_elf_to_spec(kernel_config, &pd.name, pd.cpu, ElfIndex::SystemElf(pd_global_idx), elf_obj)
596+
.add_elf_to_spec(
597+
kernel_config,
598+
&pd.name,
599+
pd.cpu,
600+
ElfIndex::SystemElf(pd_global_idx),
601+
elf_obj,
602+
)
597603
.unwrap();
598604
let pd_vspace_obj_id = capdl_util_get_vspace_id_from_tcb_id(&spec_container, pd_tcb_obj_id);
599605

@@ -1132,21 +1138,25 @@ pub fn build_capdl_spec(
11321138
};
11331139

11341140
for sched_entry in system.domain_schedule.as_ref().unwrap().schedule.iter() {
1135-
domain_schedule.push(DomainSchedEntry{
1141+
domain_schedule.push(DomainSchedEntry {
11361142
id: sched_entry.id,
11371143
time: sched_entry.length * ticks_in_ms,
11381144
});
11391145
}
11401146

11411147
spec_container.spec.domain_schedule = Some(domain_schedule);
1142-
spec_container.spec.domain_set_start = system.domain_schedule
1143-
.as_ref()
1144-
.unwrap()
1145-
.domain_start_idx.map(|idx| Word(idx));
1146-
spec_container.spec.domain_idx_shift = system.domain_schedule
1147-
.as_ref()
1148-
.unwrap()
1149-
.domain_idx_shift.map(|shift| Word(shift));
1148+
spec_container.spec.domain_set_start = system
1149+
.domain_schedule
1150+
.as_ref()
1151+
.unwrap()
1152+
.domain_start_idx
1153+
.map(Word);
1154+
spec_container.spec.domain_idx_shift = system
1155+
.domain_schedule
1156+
.as_ref()
1157+
.unwrap()
1158+
.domain_idx_shift
1159+
.map(Word);
11501160
}
11511161

11521162
// *********************************

tool/microkit/src/capdl/packaging.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
//
66

77
use crate::{
8+
capdl::spec::ElfIndex,
89
capdl::{initialiser::CapDLInitialiser, CapDLSpecContainer},
910
elf::ElfFile,
1011
sel4::{Config, PageSize},
11-
capdl::spec::{ElfIndex},
1212
};
1313

1414
pub fn pack_spec_into_initial_task(
@@ -29,16 +29,18 @@ pub fn pack_spec_into_initial_task(
2929
match d.elf_id {
3030
ElfIndex::SystemElf(elf_id) => {
3131
buf.copy_from_slice(
32-
&system_elfs[elf_id].segments[d.elf_seg_idx].data()[d.elf_seg_data_range.clone()],
32+
&system_elfs[elf_id].segments[d.elf_seg_idx].data()
33+
[d.elf_seg_data_range.clone()],
3334
);
3435
}
3536
ElfIndex::MonitorElf(elf_id) => {
3637
buf.copy_from_slice(
37-
&monitor_elfs[elf_id].segments[d.elf_seg_idx].data()[d.elf_seg_data_range.clone()],
38+
&monitor_elfs[elf_id].segments[d.elf_seg_idx].data()
39+
[d.elf_seg_data_range.clone()],
3840
);
3941
}
4042
}
41-
43+
4244
compress_frames
4345
},
4446
);
@@ -52,7 +54,9 @@ pub fn pack_spec_into_initial_task(
5254
match build_config {
5355
"smp-debug" | "debug" | "debug_domains" => {}
5456
// We don't copy over the object names as there is no debug printing in these configuration to save memory.
55-
"release" | "release_domains" | "benchmark" | "smp-release" | "smp-benchmark" => named_obj.name = None,
57+
"release" | "release_domains" | "benchmark" | "smp-release" | "smp-benchmark" => {
58+
named_obj.name = None
59+
}
5660
_ => panic!("unknown configuration {build_config}"),
5761
};
5862
}

tool/microkit/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,15 @@ fn main() -> Result<(), String> {
687687
spec_need_refinement = false;
688688

689689
// Patch all the required symbols in the Monitor and PDs according to the Microkit's requirements
690-
if let Err(err) = patch_symbols(&kernel_config, &mut system_elfs, &mut monitor_elfs, &system) {
690+
if let Err(err) =
691+
patch_symbols(&kernel_config, &mut system_elfs, &mut monitor_elfs, &system)
692+
{
691693
eprintln!("ERROR: {err}");
692694
std::process::exit(1);
693695
}
694696

695-
let mut spec_container = build_capdl_spec(&kernel_config, &mut system_elfs, &mut monitor_elfs, &system)?;
697+
let mut spec_container =
698+
build_capdl_spec(&kernel_config, &mut system_elfs, &mut monitor_elfs, &system)?;
696699
pack_spec_into_initial_task(
697700
&kernel_config,
698701
args.config,

tool/microkit/src/sdf.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::sel4::{
2121
};
2222
use crate::util::{ranges_overlap, str_to_bool};
2323
use crate::MAX_PDS;
24-
use std::collections::HashSet;
2524
use std::collections::HashMap;
25+
use std::collections::HashSet;
2626
use std::fmt::Display;
2727
use std::path::{Path, PathBuf};
2828

@@ -608,16 +608,16 @@ impl ProtectionDomain {
608608
(Some(domain_schedule), Ok(domain_name)) => {
609609
let domain_id_get = domain_schedule.domain_ids.get(domain_name);
610610
if domain_id_get.is_none() {
611-
return Err(format!("Protection domain {} specifies a domain {} that is not in the domain schedule", name, domain_name));
611+
return Err(format!("Protection domain {name} specifies a domain {domain_name} that is not in the domain schedule"));
612612
}
613613
domain_id = Some(*domain_id_get.unwrap());
614614
}
615615
(Some(_), _) => {
616-
return Err(format!("System specifies a domain schedule but protection domain {} does not specify a domain", name))
616+
return Err(format!("System specifies a domain schedule but protection domain {name} does not specify a domain"))
617617
}
618618
(_, Ok(domain)) => {
619619
if config.num_domain_schedules > 1 {
620-
return Err(format!("Protection domain {} specifies a domain {} but system does not specify a domain schedule", name, domain));
620+
return Err(format!("Protection domain {name} specifies a domain {domain} but system does not specify a domain schedule"));
621621
} else {
622622
return Err("Assigning PDs to domains is only supported built with a config that supports domains".to_string());
623623
}
@@ -1029,7 +1029,8 @@ impl ProtectionDomain {
10291029
checked_add_setvar(&mut setvars, setvar, xml_sdf, &child)?;
10301030
}
10311031
"protection_domain" => {
1032-
let child_pd = ProtectionDomain::from_xml(config, xml_sdf, &child, true, domain_schedule)?;
1032+
let child_pd =
1033+
ProtectionDomain::from_xml(config, xml_sdf, &child, true, domain_schedule)?;
10331034

10341035
if let Some(setvar_id) = &child_pd.setvar_id {
10351036
let setvar = SysSetVar {
@@ -1127,9 +1128,7 @@ impl DomainSchedule {
11271128
node: &roxmltree::Node,
11281129
) -> Result<DomainSchedule, String> {
11291130
if config.num_domains <= 1 {
1130-
return Err(format!(
1131-
"Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain",
1132-
));
1131+
return Err("Error: Attempting to set a domain schedule when kernel config does not support more than 1 domain".to_string());
11331132
}
11341133

11351134
let pos = xml_sdf.doc.text_pos_at(node.range().start);
@@ -1188,34 +1187,28 @@ impl DomainSchedule {
11881187
return Err(format!(
11891188
"Error: Duplicate setting of domain start index, already set to '{}'",
11901189
domain_start_idx.unwrap()
1191-
))
1190+
));
11921191
}
11931192
check_attributes(xml_sdf, &child, &["index"])?;
11941193
let start_index = checked_lookup(xml_sdf, &child, "index")?.parse::<u64>();
11951194
if start_index.is_err() {
1196-
return Err(format!(
1197-
"Error: invalid domain start index",
1198-
))
1195+
return Err("Error: invalid domain start index".to_string());
11991196
}
12001197
domain_start_idx = Some(start_index.unwrap());
1201-
12021198
}
12031199
"domain_idx_shift" => {
12041200
if domain_idx_shift.is_some() {
12051201
return Err(format!(
12061202
"Error: Duplicate setting of domain index shift, already set to '{}'",
12071203
domain_idx_shift.unwrap()
1208-
))
1204+
));
12091205
}
12101206
check_attributes(xml_sdf, &child, &["shift"])?;
12111207
let index_shift = checked_lookup(xml_sdf, &child, "shift")?.parse::<u64>();
12121208
if index_shift.is_err() {
1213-
return Err(format!(
1214-
"Error: invalid domain index shift",
1215-
))
1209+
return Err("Error: invalid domain index shift".to_string());
12161210
}
12171211
domain_idx_shift = Some(index_shift.unwrap());
1218-
12191212
}
12201213
_ => {
12211214
return Err(format!(
@@ -1224,7 +1217,6 @@ impl DomainSchedule {
12241217
loc_string(xml_sdf, pos)
12251218
));
12261219
}
1227-
12281220
}
12291221
}
12301222

@@ -1808,9 +1800,13 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
18081800

18091801
let child_name = child.tag_name().name();
18101802
match child_name {
1811-
"protection_domain" => {
1812-
root_pds.push(ProtectionDomain::from_xml(config, &xml_sdf, &child, false, &domain_schedule)?)
1813-
}
1803+
"protection_domain" => root_pds.push(ProtectionDomain::from_xml(
1804+
config,
1805+
&xml_sdf,
1806+
&child,
1807+
false,
1808+
&domain_schedule,
1809+
)?),
18141810
"channel" => channel_nodes.push(child),
18151811
"memory_region" => mrs.push(SysMemoryRegion::from_xml(config, &xml_sdf, &child)?),
18161812
"virtual_machine" => {
@@ -1819,15 +1815,19 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
18191815
"Error: virtual machine must be a child of a protection domain: {}",
18201816
loc_string(&xml_sdf, pos)
18211817
));
1822-
},
1818+
}
18231819
"domain_schedule" => {
18241820
if config.num_domain_schedules > 1 {
18251821
if let Some(domain_schedule_node) = system
18261822
.children()
18271823
.filter(|&child| child.is_element())
18281824
.find(|&child| child.tag_name().name() == "domain_schedule")
18291825
{
1830-
domain_schedule = Some(DomainSchedule::from_xml(&xml_sdf, &config, &domain_schedule_node)?);
1826+
domain_schedule = Some(DomainSchedule::from_xml(
1827+
&xml_sdf,
1828+
config,
1829+
&domain_schedule_node,
1830+
)?);
18311831
}
18321832
}
18331833
}
@@ -2200,18 +2200,16 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
22002200
"Error: Domain index of '{}' is out of bounds for domain schedule length '{}'. Note that the schedule is 0 indexed.",
22012201
dom_sched.domain_start_idx.unwrap(),
22022202
schedule_len
2203-
))
2203+
));
22042204
}
22052205

22062206
// Make sure our schedule length, including the shift, is in bounds of
22072207
// the kernel configured max number of schedules.
22082208
if schedule_len + dom_shift >= config.num_domain_schedules {
22092209
return Err(format!(
22102210
"Error: Schedule length '{}' with shift of '{}' exceeds max schedule length '{}'.",
2211-
schedule_len,
2212-
dom_shift,
2213-
config.num_domain_schedules,
2214-
))
2211+
schedule_len, dom_shift, config.num_domain_schedules,
2212+
));
22152213
}
22162214
}
22172215

tool/microkit/src/symbols.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{cmp::min, collections::HashMap};
88

99
use crate::{
1010
elf::ElfFile,
11-
sdf::{self, SysMemoryRegion, SystemDescription, ProtectionDomain},
11+
sdf::{self, ProtectionDomain, SysMemoryRegion, SystemDescription},
1212
sel4::{Arch, Config},
1313
util::{monitor_serialise_names, monitor_serialise_u64_vec},
1414
MAX_PDS, MAX_VMS, PD_MAX_NAME_LENGTH, VM_MAX_NAME_LENGTH,
@@ -35,15 +35,9 @@ pub fn patch_symbols(
3535
.filter(|pd| pd.domain_id.unwrap_or(0) == mon_idx as u8)
3636
.collect();
3737

38-
let pd_names: Vec<String> = filtered_pds
39-
.iter()
40-
.map(|pd| pd.name.clone())
41-
.collect();
38+
let pd_names: Vec<String> = filtered_pds.iter().map(|pd| pd.name.clone()).collect();
4239
monitor_elf
43-
.write_symbol(
44-
"pd_names_len",
45-
&filtered_pds.len().to_le_bytes(),
46-
)
40+
.write_symbol("pd_names_len", &filtered_pds.len().to_le_bytes())
4741
.unwrap();
4842
monitor_elf
4943
.write_symbol(
@@ -90,10 +84,7 @@ pub fn patch_symbols(
9084
.unwrap();
9185

9286
monitor_elf
93-
.write_symbol(
94-
"monitor_name",
95-
format!("monitor_{}", mon_idx).as_bytes()
96-
)
87+
.write_symbol("monitor_name", format!("monitor_{mon_idx}").as_bytes())
9788
.unwrap();
9889
}
9990

0 commit comments

Comments
 (0)