rust: migration: allow passing ParentField<> to vmstate_of!
The common superclass for devices could have its own migration state; for it to be included in the subclass's VMState, ParentField<> must implement the VMState trait. Reported-by: Chen Miao <chenmiao@openatom.club> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
d5e1d2dea1
commit
d4fbf6ff8d
2 changed files with 4 additions and 2 deletions
|
|
@ -268,7 +268,7 @@ macro_rules! impl_vmstate_transparent {
|
||||||
($type:ty where $base:tt: VMState $($where:tt)*) => {
|
($type:ty where $base:tt: VMState $($where:tt)*) => {
|
||||||
unsafe impl<$base> $crate::vmstate::VMState for $type where $base: $crate::vmstate::VMState $($where)* {
|
unsafe impl<$base> $crate::vmstate::VMState for $type where $base: $crate::vmstate::VMState $($where)* {
|
||||||
const BASE: $crate::vmstate::VMStateField = $crate::vmstate::VMStateField {
|
const BASE: $crate::vmstate::VMStateField = $crate::vmstate::VMStateField {
|
||||||
size: mem::size_of::<$type>(),
|
size: ::core::mem::size_of::<$type>(),
|
||||||
..<$base as $crate::vmstate::VMState>::BASE
|
..<$base as $crate::vmstate::VMState>::BASE
|
||||||
};
|
};
|
||||||
const VARRAY_FLAG: $crate::bindings::VMStateFlags = <$base as $crate::vmstate::VMState>::VARRAY_FLAG;
|
const VARRAY_FLAG: $crate::bindings::VMStateFlags = <$base as $crate::vmstate::VMState>::VARRAY_FLAG;
|
||||||
|
|
@ -282,6 +282,7 @@ impl_vmstate_transparent!(std::cell::Cell<T> where T: VMState);
|
||||||
impl_vmstate_transparent!(std::cell::UnsafeCell<T> where T: VMState);
|
impl_vmstate_transparent!(std::cell::UnsafeCell<T> where T: VMState);
|
||||||
impl_vmstate_transparent!(std::pin::Pin<T> where T: VMState);
|
impl_vmstate_transparent!(std::pin::Pin<T> where T: VMState);
|
||||||
impl_vmstate_transparent!(common::Opaque<T> where T: VMState);
|
impl_vmstate_transparent!(common::Opaque<T> where T: VMState);
|
||||||
|
impl_vmstate_transparent!(std::mem::ManuallyDrop<T> where T: VMState);
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! impl_vmstate_bitsized {
|
macro_rules! impl_vmstate_bitsized {
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use common::Opaque;
|
use common::Opaque;
|
||||||
use migration::impl_vmstate_pointer;
|
use migration::{impl_vmstate_pointer, impl_vmstate_transparent};
|
||||||
|
|
||||||
use crate::bindings::{
|
use crate::bindings::{
|
||||||
self, object_class_dynamic_cast, object_dynamic_cast, object_get_class, object_get_typename,
|
self, object_class_dynamic_cast, object_dynamic_cast, object_get_class, object_get_typename,
|
||||||
|
|
@ -182,6 +182,7 @@ macro_rules! qom_isa {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct ParentField<T: ObjectType>(std::mem::ManuallyDrop<T>);
|
pub struct ParentField<T: ObjectType>(std::mem::ManuallyDrop<T>);
|
||||||
|
impl_vmstate_transparent!(ParentField<T> where T: VMState + ObjectType);
|
||||||
|
|
||||||
impl<T: ObjectType> Deref for ParentField<T> {
|
impl<T: ObjectType> Deref for ParentField<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue