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.
diff --git a/sim/mcuboot-sys/src/c.rs b/sim/mcuboot-sys/src/c.rs
index 483ca8f..284cac0 100644
--- a/sim/mcuboot-sys/src/c.rs
+++ b/sim/mcuboot-sys/src/c.rs
@@ -13,6 +13,8 @@
#[allow(unused)]
use std::sync::Once;
+use std::borrow::Borrow;
+
/// The result of an invocation of `boot_go`. This is intentionally opaque so that we can provide
/// accessors for everything we need from this.
#[derive(Debug)]
@@ -90,12 +92,13 @@
image_off: 0,
};
let result: i32 = unsafe {
+ let adesc = areadesc.get_c();
match image_index {
None => raw::invoke_boot_go(&mut sim_ctx as *mut _,
- &areadesc.get_c() as *const _,
+ adesc.borrow() as *const _,
&mut rsp as *mut _, -1) as i32,
Some(i) => raw::invoke_boot_go(&mut sim_ctx as *mut _,
- &areadesc.get_c() as *const _,
+ adesc.borrow() as *const _,
&mut rsp as *mut _,
i as i32) as i32
}