sim: Don't take address of movable struct
This struct was having addresses taken of fields within it, and then being
returned. It is platform-specific whether this causes a move. It seems to be
working on x86_64, but causes a segfault on aarch64. Box the struct so that it
isn't moved after being initialized.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/mcuboot-sys/src/area.rs b/sim/mcuboot-sys/src/area.rs
index 95eea41..1ebb405 100644
--- a/sim/mcuboot-sys/src/area.rs
+++ b/sim/mcuboot-sys/src/area.rs
@@ -9,6 +9,7 @@
use simflash::{Flash, SimFlash, Sector};
use std::ptr;
use std::collections::HashMap;
+use std::borrow::BorrowMut;
/// Structure to build up the boot area table.
#[derive(Debug, Default, Clone)]
@@ -124,8 +125,9 @@
None
}
- pub fn get_c(&self) -> CAreaDesc {
- let mut areas: CAreaDesc = Default::default();
+ pub fn get_c(&self) -> Box<CAreaDesc> {
+ let mut areas_box: Box<CAreaDesc> = Box::new(Default::default());
+ let areas: &mut CAreaDesc = areas_box.borrow_mut();
assert_eq!(self.areas.len(), self.whole.len());
@@ -140,7 +142,7 @@
areas.num_slots = self.areas.len() as u32;
- areas
+ areas_box
}
/// Return an iterator over all `FlashArea`s present.