From c3085661f84a995344d9599ab87e1029bd439493 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Mon, 17 Nov 2025 20:17:59 +0900 Subject: [PATCH] Fix SharedVectorHeader alignment mismatch on ARM32 platforms Add explicit 8-byte alignment to SharedVectorHeader on both Rust and C++ sides to fix layout corruption on ARM Cortex-M7 (32-bit). Without explicit alignment, the struct has 4-byte natural alignment on ARM32, but pointer arithmetic calculations differ between Rust and C++, causing a 4-byte offset when accessing SharedVector data. This corrupts all layout calculations (HorizontalLayout, VerticalLayout, GridLayout) and makes Slint unusable on ARM32 embedded platforms. The fix adds alignas(8) to C++ and #[repr(C, align(8))] to Rust, ensuring consistent struct layout across the FFI boundary on all platforms. Fixes: #10097 --- api/cpp/include/slint_sharedvector.h | 2 +- internal/core/sharedvector.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/cpp/include/slint_sharedvector.h b/api/cpp/include/slint_sharedvector.h index e0d755251e3..2de1047cda3 100644 --- a/api/cpp/include/slint_sharedvector.h +++ b/api/cpp/include/slint_sharedvector.h @@ -218,7 +218,7 @@ struct SharedVector #if !defined(DOXYGEN) // Unfortunately, this cannot be generated by cbindgen because std::atomic is not understood - struct SharedVectorHeader + struct alignas(8) SharedVectorHeader { std::atomic refcount; std::size_t size; diff --git a/internal/core/sharedvector.rs b/internal/core/sharedvector.rs index c413f919f17..135693ec356 100644 --- a/internal/core/sharedvector.rs +++ b/internal/core/sharedvector.rs @@ -11,7 +11,7 @@ use core::ptr::NonNull; use portable_atomic as atomic; -#[repr(C)] +#[repr(C, align(8))] struct SharedVectorHeader { refcount: atomic::AtomicIsize, size: usize,