From: Marc-André Lureau Date: Mon, 8 Sep 2025 10:49:47 +0000 (+0200) Subject: rust: move Cell vmstate impl X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6765c04beac0a3e20032b619df6afbc70b6ef74;p=thirdparty%2Fqemu.git rust: move Cell vmstate impl This will allow to split vmstate to a standalone crate next. Signed-off-by: Marc-André Lureau Link: https://lore.kernel.org/r/20250827104147.717203-10-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs index 148a13e3f56..9943d7286b6 100644 --- a/rust/qemu-api/src/cell.rs +++ b/rust/qemu-api/src/cell.rs @@ -221,7 +221,7 @@ use std::{ ptr::NonNull, }; -use crate::bindings; +use crate::{bindings, impl_vmstate_transparent}; /// An internal function that is used by doctests. pub fn bql_start_test() { @@ -456,6 +456,8 @@ impl BqlCell { } } +impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); + /// A mutable memory location with dynamically checked borrow rules, /// protected by the Big QEMU Lock. /// @@ -764,6 +766,8 @@ impl From for BqlRefCell { } } +impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); + struct BorrowRef<'b> { borrow: &'b Cell, } diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 4e1086779ac..ce42b031bc1 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -124,7 +124,8 @@ pub const fn vmstate_varray_flag(_: PhantomData) -> VMStateFlags /// * scalar types (integer and `bool`) /// * the C struct `QEMUTimer` /// * a transparent wrapper for any of the above (`Cell`, `UnsafeCell`, -/// [`BqlCell`], [`BqlRefCell`] +/// [`BqlCell`](crate::cell::BqlCell), +/// [`BqlRefCell`](crate::cell::BqlRefCell)), /// * a raw pointer to any of the above /// * a `NonNull` pointer, a `Box` or an [`Owned`](crate::qom::Owned) for any of /// the above @@ -254,14 +255,15 @@ macro_rules! impl_vmstate_forward { // Transparent wrappers: just use the internal type +#[macro_export] macro_rules! impl_vmstate_transparent { ($type:ty where $base:tt: VMState $($where:tt)*) => { - unsafe impl<$base> VMState for $type where $base: VMState $($where)* { - const BASE: VMStateField = VMStateField { + unsafe impl<$base> $crate::vmstate::VMState for $type where $base: $crate::vmstate::VMState $($where)* { + const BASE: $crate::vmstate::VMStateField = $crate::vmstate::VMStateField { size: mem::size_of::<$type>(), - ..<$base as VMState>::BASE + ..<$base as $crate::vmstate::VMState>::BASE }; - const VARRAY_FLAG: VMStateFlags = <$base as VMState>::VARRAY_FLAG; + const VARRAY_FLAG: $crate::bindings::VMStateFlags = <$base as $crate::vmstate::VMState>::VARRAY_FLAG; } }; } @@ -269,8 +271,6 @@ macro_rules! impl_vmstate_transparent { impl_vmstate_transparent!(std::cell::Cell where T: VMState); impl_vmstate_transparent!(std::cell::UnsafeCell where T: VMState); impl_vmstate_transparent!(std::pin::Pin where T: VMState); -impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); -impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); impl_vmstate_transparent!(crate::cell::Opaque where T: VMState); #[macro_export]