qemu/rust
Peter Maydell cc3d262aa9 rust: pl011: Check size of state struct at compile time
The PL011 device's C implementation exposes its PL011State struct to
users of the device, and one common usage pattern is to embed that
struct into the user's own state struct.  (The internals of the
struct are technically visible to the C user of the device, but in
practice are treated as implementation details.)

This means that the Rust version of the state struct must not be
larger than the C version's struct; otherwise it will trip a runtime
assertion in object_initialize_type() when the C user attempts to
in-place initialize the type.

Add a compile-time assertion on the Rust side, so that if we
accidentally make the Rust device state larger we know immediately
that we need to expand the padding in the C version of the struct.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Link: https://lore.kernel.org/r/20250321112523.1774131-4-peter.maydell@linaro.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-21 12:51:16 +01:00
..
hw rust: pl011: Check size of state struct at compile time 2025-03-21 12:51:16 +01:00
qemu-api rust: assertions: add static_assert 2025-03-21 12:51:16 +01:00
qemu-api-macros rust: qemu_api_macros: add Wrapper derive macro 2025-03-06 12:44:46 +01:00
.gitignore rust: add bindgen step as a meson dependency 2024-10-11 12:32:17 +02:00
Cargo.lock rust: subprojects: add libc crate 2025-02-25 10:49:23 +01:00
Cargo.toml rust: hpet: decode HPET registers into enums 2025-03-06 12:44:47 +01:00
clippy.toml rust: add clippy configuration file 2025-02-07 15:51:01 +01:00
Kconfig rust: add PL011 device model 2024-11-05 14:18:15 +01:00
meson.build rust: build: add "make clippy", "make rustfmt", "make rustdoc" 2024-12-10 18:44:06 +01:00
rustfmt.toml rust: add crate to expose bindings and interfaces 2024-10-11 12:32:17 +02:00
wrapper.h rust: pl011: Check size of state struct at compile time 2025-03-21 12:51:16 +01:00