Commit 5d155132 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

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: default avatarDavid Brown <david.brown@linaro.org>
parent 9ae634f3
Loading
Loading
Loading
Loading
+5 −3
Changes for sim/mcuboot-sys/src/area.rs: 5 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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 @@ impl AreaDesc {
        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 @@ impl AreaDesc {

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

        areas
        areas_box
    }

    /// Return an iterator over all `FlashArea`s present.
+5 −2
Changes for sim/mcuboot-sys/src/c.rs: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ use crate::api;
#[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 @@ pub fn boot_go(multiflash: &mut SimMultiFlash, areadesc: &AreaDesc,
        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
        }