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> {