From: Marc-André Lureau <marcandre.lureau@redhat.com>
This will allow to split vmstate to a standalone crate next.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Link: https://lore.kernel.org/r/20250827104147.717203-8-marcandre.lureau@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/qdev.rs | 3 +++
rust/qemu-api/src/vmstate.rs | 14 ++++++--------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs
index 436142d8aef..e2b4121cac5 100644
--- a/rust/qemu-api/src/qdev.rs
+++ b/rust/qemu-api/src/qdev.rs
@@ -17,6 +17,7 @@
cell::{bql_locked, Opaque},
chardev::Chardev,
error::{Error, Result},
+ impl_vmstate_c_struct,
irq::InterruptSource,
prelude::*,
qom::{ObjectClass, ObjectImpl, Owned, ParentInit},
@@ -455,3 +456,5 @@ unsafe impl ObjectType for Clock {
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_CLOCK) };
}
qom_isa!(Clock: Object);
+
+impl_vmstate_c_struct!(Clock, bindings::vmstate_clock);
diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs
index b5c6b764fbb..59c7950a5aa 100644
--- a/rust/qemu-api/src/vmstate.rs
+++ b/rust/qemu-api/src/vmstate.rs
@@ -41,7 +41,6 @@
callbacks::FnCall,
errno::{into_neg_errno, Errno},
prelude::*,
- qdev,
qom::Owned,
zeroable::Zeroable,
};
@@ -318,21 +317,20 @@ unsafe impl VMState for $type {
impl_vmstate_scalar!(vmstate_info_uint64, u64);
impl_vmstate_scalar!(vmstate_info_timer, crate::timer::Timer);
+#[macro_export]
macro_rules! impl_vmstate_c_struct {
($type:ty, $vmsd:expr) => {
unsafe impl VMState for $type {
- const BASE: VMStateField = $crate::bindings::VMStateField {
- vmsd: addr_of!($vmsd),
- size: mem::size_of::<$type>(),
- flags: VMStateFlags::VMS_STRUCT,
- ..Zeroable::ZERO
+ const BASE: $crate::bindings::VMStateField = $crate::bindings::VMStateField {
+ vmsd: ::std::ptr::addr_of!($vmsd),
+ size: ::std::mem::size_of::<$type>(),
+ flags: $crate::bindings::VMStateFlags::VMS_STRUCT,
+ ..$crate::zeroable::Zeroable::ZERO
};
}
};
}
-impl_vmstate_c_struct!(qdev::Clock, bindings::vmstate_clock);
-
// Pointer types using the underlying type's VMState plus VMS_POINTER
// Note that references are not supported, though references to cells
// could be allowed.
--
2.51.0