Skip to content

Commit

Permalink
rust: add definitions for vmstate
Browse files Browse the repository at this point in the history
Add a new qemu_api module, `vmstate`. Declare a bunch of Rust
macros declared that are equivalent in spirit to the C macros in
include/migration/vmstate.h.

For example the Rust of equivalent of the C macro:

  VMSTATE_UINT32(field_name, struct_name)

is:

  vmstate_uint32!(field_name, StructName)

This breathtaking development will allow us to reach feature parity between
the Rust and C pl011 implementations.

Extracted from a patch by Manos Pitsidianakis
(https://lore.kernel.org/qemu-devel/[email protected]/).

Signed-off-by: Manos Pitsidianakis <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
epilys authored and bonzini committed Nov 5, 2024
1 parent f60f367 commit 0a65e41
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 26 deletions.
1 change: 1 addition & 0 deletions rust/qemu-api/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _qemu_api_rs = static_library(
'src/lib.rs',
'src/definitions.rs',
'src/device_class.rs',
'src/vmstate.rs',
'src/zeroable.rs',
],
{'.' : bindings_rs},
Expand Down
21 changes: 0 additions & 21 deletions rust/qemu-api/src/device_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,3 @@ macro_rules! declare_properties {
];
};
}

#[macro_export]
macro_rules! vm_state_description {
($(#[$outer:meta])*
$name:ident,
$(name: $vname:expr,)*
$(unmigratable: $um_val:expr,)*
) => {
#[used]
$(#[$outer])*
pub static $name: $crate::bindings::VMStateDescription = $crate::bindings::VMStateDescription {
$(name: {
#[used]
static VMSTATE_NAME: &::core::ffi::CStr = $vname;
$vname.as_ptr()
},)*
unmigratable: true,
..$crate::zeroable::Zeroable::ZERO
};
}
}
3 changes: 3 additions & 0 deletions rust/qemu-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ unsafe impl Send for bindings::Property {}
unsafe impl Sync for bindings::Property {}
unsafe impl Sync for bindings::TypeInfo {}
unsafe impl Sync for bindings::VMStateDescription {}
unsafe impl Sync for bindings::VMStateField {}
unsafe impl Sync for bindings::VMStateInfo {}

pub mod definitions;
pub mod device_class;
pub mod vmstate;
pub mod zeroable;

use std::alloc::{GlobalAlloc, Layout};
Expand Down
Loading

0 comments on commit 0a65e41

Please sign in to comment.