Skip to content

sim: Fix STATUS_ACCESS_VIOLATION on Windows x86_64 #2771

Open
josesimoes wants to merge 3 commits into
mcu-tools:mainfrom
josesimoes:sim-context-windows
Open

sim: Fix STATUS_ACCESS_VIOLATION on Windows x86_64 #2771
josesimoes wants to merge 3 commits into
mcu-tools:mainfrom
josesimoes:sim-context-windows

Conversation

@josesimoes

Copy link
Copy Markdown
Contributor

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.

@josesimoes
josesimoes requested a review from d3zd3z as a code owner June 19, 2026 11:57
@josesimoes
josesimoes force-pushed the sim-context-windows branch from de97598 to 7057338 Compare June 19, 2026 11:57
@josesimoes

Copy link
Copy Markdown
Contributor Author

Pinging @d3zd3z in case this slipped through the cracks...

Comment thread sim/mcuboot-sys/src/api.rs Outdated
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>
@josesimoes
josesimoes force-pushed the sim-context-windows branch from 7057338 to e0e086c Compare July 9, 2026 07:56
- Removed the cfg_attr conditionals so it windows-msvc too.
- Added a compile-time assertion to document the invariant and will fail the build if a future field reorder/addition ever regresses alignment below 16 bytes. Works on all platforms.

Signed-off-by: José Simões <jose.simoes@eclo.solutions>
@josesimoes
josesimoes force-pushed the sim-context-windows branch from e0e086c to cdd833a Compare July 9, 2026 14:33
Comment thread sim/mcuboot-sys/src/api.rs Outdated
Signed-off-by: José Simões <jose.simoes@eclo.solutions>
@josesimoes

Copy link
Copy Markdown
Contributor Author

@d3zd3z anything missing here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants