Skip to content

Commit 5d15513

Browse files
committed
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 <[email protected]>
1 parent 9ae634f commit 5d15513

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

sim/mcuboot-sys/src/area.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use simflash::{Flash, SimFlash, Sector};
1010
use std::ptr;
1111
use std::collections::HashMap;
12+
use std::borrow::BorrowMut;
1213

1314
/// Structure to build up the boot area table.
1415
#[derive(Debug, Default, Clone)]
@@ -124,8 +125,9 @@ impl AreaDesc {
124125
None
125126
}
126127

127-
pub fn get_c(&self) -> CAreaDesc {
128-
let mut areas: CAreaDesc = Default::default();
128+
pub fn get_c(&self) -> Box<CAreaDesc> {
129+
let mut areas_box: Box<CAreaDesc> = Box::new(Default::default());
130+
let areas: &mut CAreaDesc = areas_box.borrow_mut();
129131

130132
assert_eq!(self.areas.len(), self.whole.len());
131133

@@ -140,7 +142,7 @@ impl AreaDesc {
140142

141143
areas.num_slots = self.areas.len() as u32;
142144

143-
areas
145+
areas_box
144146
}
145147

146148
/// Return an iterator over all `FlashArea`s present.

sim/mcuboot-sys/src/c.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::api;
1313
#[allow(unused)]
1414
use std::sync::Once;
1515

16+
use std::borrow::Borrow;
17+
1618
/// The result of an invocation of `boot_go`. This is intentionally opaque so that we can provide
1719
/// accessors for everything we need from this.
1820
#[derive(Debug)]
@@ -90,12 +92,13 @@ pub fn boot_go(multiflash: &mut SimMultiFlash, areadesc: &AreaDesc,
9092
image_off: 0,
9193
};
9294
let result: i32 = unsafe {
95+
let adesc = areadesc.get_c();
9396
match image_index {
9497
None => raw::invoke_boot_go(&mut sim_ctx as *mut _,
95-
&areadesc.get_c() as *const _,
98+
adesc.borrow() as *const _,
9699
&mut rsp as *mut _, -1) as i32,
97100
Some(i) => raw::invoke_boot_go(&mut sim_ctx as *mut _,
98-
&areadesc.get_c() as *const _,
101+
adesc.borrow() as *const _,
99102
&mut rsp as *mut _,
100103
i as i32) as i32
101104
}

0 commit comments

Comments
 (0)