[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 07/10] rust: qemu_api: add vmstate_struct
From: |
Zhao Liu |
Subject: |
Re: [PATCH 07/10] rust: qemu_api: add vmstate_struct |
Date: |
Wed, 22 Jan 2025 21:17:26 +0800 |
On Fri, Jan 17, 2025 at 10:00:43AM +0100, Paolo Bonzini wrote:
> Date: Fri, 17 Jan 2025 10:00:43 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 07/10] rust: qemu_api: add vmstate_struct
> X-Mailer: git-send-email 2.47.1
>
> It is not type safe, but it's the best that can be done without
> const_refs_static. It can also be used with BqlCell and BqlRefCell.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> rust/qemu-api/src/vmstate.rs | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
...
> +#[doc(alias = "VMSTATE_STRUCT")]
> +#[macro_export]
> +macro_rules! vmstate_struct {
> + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(*
> $factor:expr)?])?, $vmsd:expr, $type:ty $(,)?) => {
> + $crate::bindings::VMStateField {
> + name: ::core::concat!(::core::stringify!($field_name), "\0")
> + .as_bytes()
> + .as_ptr() as *const ::std::os::raw::c_char,
> + $(.num_offset: $crate::offset_of!($struct_name, $num),)?
> + offset: {
> + $crate::assert_field_type!($struct_name, $field_name, $type);
> + $crate::offset_of!($struct_name, $field_name)
> + },
> + size: ::core::mem::size_of::<$type>(),
> + flags: $crate::bindings::VMStateFlags::VMS_STRUCT,
> + vmsd: unsafe { $vmsd },
Yes, this `unsafe` is fitting.
> + ..$crate::zeroable::Zeroable::ZERO $(
> + .with_varray_flag($crate::call_func_with_field!(
> + $crate::vmstate::vmstate_varray_flag,
> + $struct_name,
> + $num))
> + $(.with_varray_multiply($factor))?)?
> + }
> + };
> +}
> +
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
- [PATCH 00/10] rust: (mostly) type safe VMState, Paolo Bonzini, 2025/01/17
- [PATCH 01/10] rust: vmstate: add new type safe implementation, Paolo Bonzini, 2025/01/17
- [PATCH 04/10] rust: vmstate: implement Zeroable for VMStateField, Paolo Bonzini, 2025/01/17
- [PATCH 05/10] rust: vmstate: implement VMState for scalar types, Paolo Bonzini, 2025/01/17
- [PATCH 03/10] rust: vmstate: add varray support to vmstate_of!, Paolo Bonzini, 2025/01/17
- [PATCH 07/10] rust: qemu_api: add vmstate_struct, Paolo Bonzini, 2025/01/17
- Re: [PATCH 07/10] rust: qemu_api: add vmstate_struct,
Zhao Liu <=
- [PATCH 06/10] rust: vmstate: add public utility macros to implement VMState, Paolo Bonzini, 2025/01/17
- [PATCH 08/10] rust: pl011: switch vmstate to new-style macros, Paolo Bonzini, 2025/01/17
- [PATCH 10/10] rust: vmstate: make order of parameters consistent in vmstate_clock, Paolo Bonzini, 2025/01/17
- [PATCH 09/10] rust: vmstate: remove translation of C vmstate macros, Paolo Bonzini, 2025/01/17
- [PATCH 02/10] rust: vmstate: implement VMState for non-leaf types, Paolo Bonzini, 2025/01/17