Refactoring: Make a config Entries type
We pass all the config entries we've found around a bit, so let's have
a struct for doing that instead of a tuple. This is mostly about
minimizing churn when new entries are added (since we're about to do
that). But it also slightly reduces the scope for mistakes in tuple
ordering.
Bug: 291232226
Bug: 285855436
Test: flash pvmfw, atest MicrodroidTests
Test: atest libpvmfw_avb.integration_test libpvmfw.bootargs.test
libpvmfw.device_assignment.test libpvmfw.dice.test
Change-Id: Iddeb28318c3d1845fb5df6e88886123bd66b6a82
diff --git a/pvmfw/src/config.rs b/pvmfw/src/config.rs
index 4957df2..2fe4ec9 100644
--- a/pvmfw/src/config.rs
+++ b/pvmfw/src/config.rs
@@ -131,6 +131,13 @@
const COUNT: usize = Self::_VARIANT_COUNT as usize;
}
+#[derive(Default)]
+pub struct Entries<'a> {
+ pub bcc: &'a mut [u8],
+ pub debug_policy: Option<&'a mut [u8]>,
+ pub vm_dtbo: Option<&'a mut [u8]>,
+}
+
#[repr(packed)]
#[derive(Clone, Copy, Debug, FromZeroes, FromBytes)]
struct HeaderEntry {
@@ -260,7 +267,7 @@
}
/// Get slice containing the platform BCC.
- pub fn get_entries(&mut self) -> (&mut [u8], Option<&mut [u8]>, Option<&mut [u8]>) {
+ pub fn get_entries(&mut self) -> Entries<'_> {
// This assumes that the blobs are in-order w.r.t. the entries.
let bcc_range = self.get_entry_range(Entry::Bcc);
let dp_range = self.get_entry_range(Entry::DebugPolicy);
@@ -270,16 +277,17 @@
info!("Found VM DTBO at {:?}", vm_dtbo_range);
}
- // SAFETY: When instantiate, ranges are validated to be in the body range without
+ // SAFETY: When instantiated, ranges are validated to be in the body range without
// overlapping.
- unsafe {
+ let (bcc, debug_policy, vm_dtbo) = unsafe {
let ptr = self.body.as_mut_ptr() as usize;
(
Self::from_raw_range_mut(ptr, bcc_range.unwrap()),
dp_range.map(|dp_range| Self::from_raw_range_mut(ptr, dp_range)),
vm_dtbo_range.map(|vm_dtbo_range| Self::from_raw_range_mut(ptr, vm_dtbo_range)),
)
- }
+ };
+ Entries { bcc, debug_policy, vm_dtbo }
}
fn get_entry_range(&self, entry: Entry) -> Option<NonEmptyRange> {
diff --git a/pvmfw/src/entry.rs b/pvmfw/src/entry.rs
index ed73bc9..f4078a3 100644
--- a/pvmfw/src/entry.rs
+++ b/pvmfw/src/entry.rs
@@ -212,7 +212,7 @@
RebootReason::InvalidConfig
})?;
- let (bcc_slice, debug_policy, vm_dtbo) = appended.get_entries();
+ let config_entries = appended.get_entries();
// Up to this point, we were using the built-in static (from .rodata) page tables.
MEMORY.lock().replace(MemoryTracker::new(
@@ -222,13 +222,19 @@
Some(memory::appended_payload_range()),
));
- let slices = MemorySlices::new(fdt, payload, payload_size, vm_dtbo)?;
+ let slices = MemorySlices::new(fdt, payload, payload_size, config_entries.vm_dtbo)?;
// This wrapper allows main() to be blissfully ignorant of platform details.
- let next_bcc = crate::main(slices.fdt, slices.kernel, slices.ramdisk, bcc_slice, debug_policy)?;
+ let next_bcc = crate::main(
+ slices.fdt,
+ slices.kernel,
+ slices.ramdisk,
+ config_entries.bcc,
+ config_entries.debug_policy,
+ )?;
// Writable-dirty regions will be flushed when MemoryTracker is dropped.
- bcc_slice.zeroize();
+ config_entries.bcc.zeroize();
info!("Expecting a bug making MMIO_GUARD_UNMAP return NOT_SUPPORTED on success");
MEMORY.lock().as_mut().unwrap().mmio_unmap_all().map_err(|e| {
@@ -432,10 +438,10 @@
}
}
- fn get_entries(&mut self) -> (&mut [u8], Option<&mut [u8]>, Option<&mut [u8]>) {
+ fn get_entries(&mut self) -> config::Entries<'_> {
match self {
- Self::Config(ref mut cfg) => cfg.get_entries(),
- Self::LegacyBcc(ref mut bcc) => (bcc, None, None),
+ Self::Config(cfg) => cfg.get_entries(),
+ Self::LegacyBcc(bcc) => config::Entries { bcc, ..Default::default() },
}
}
}