Skip to content

Commit de97598

Browse files
committed
sim: 16-byte align CSimContext on x86_64-pc-windows-gnu
The C `jmp_buf` embedded in this FFI struct needs 16-byte alignment under mingw's setjmp (saves XMM registers with movaps). The C compiler aligns the struct to 16 to satisfy that, but Rust's repr(C) only picked the 8-byte alignment of [u64; 48], so the field could land 8-byte aligned and setjmp faulted with STATUS_ACCESS_VIOLATION. Signed-off-by: José Simões <jose.simoes@eclo.solutions>
1 parent 37048b1 commit de97598

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

sim/mcuboot-sys/src/api.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ impl Default for FlashContext {
8989
}
9090
}
9191

92-
#[repr(C)]
92+
// The C side embeds a `jmp_buf` here. On x86_64-pc-windows-gnu mingw's `_setjmpex` saves XMM
93+
// registers with `movaps`, which requires 16-byte alignment; the C compiler therefore aligns
94+
// this struct to 16 to satisfy that. Match that on the Rust side or the FFI struct ends up
95+
// only 8-byte aligned and setjmp faults with STATUS_ACCESS_VIOLATION.
96+
#[cfg_attr(all(target_os = "windows", target_env = "gnu"), repr(C, align(16)))]
97+
#[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), repr(C))]
9398
#[derive(Debug)]
9499
pub struct CSimContext {
95100
pub flash_counter: libc::c_int,

0 commit comments

Comments
 (0)