rust: split "migration" crate
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-11-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
59869b4d58
commit
4dff343d23
29 changed files with 252 additions and 68 deletions
|
|
@ -3516,6 +3516,7 @@ Rust
|
|||
M: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
|
||||
S: Maintained
|
||||
F: rust/common/
|
||||
F: rust/migration/
|
||||
F: rust/qemu-api
|
||||
F: rust/qemu-api-macros
|
||||
F: rust/rustfmt.toml
|
||||
|
|
|
|||
12
rust/Cargo.lock
generated
12
rust/Cargo.lock
generated
|
|
@ -71,6 +71,7 @@ name = "hpet"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"common",
|
||||
"migration",
|
||||
"qemu_api",
|
||||
"qemu_api_macros",
|
||||
"util",
|
||||
|
|
@ -91,6 +92,15 @@ version = "0.2.162"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
|
||||
|
||||
[[package]]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"common",
|
||||
"qemu_api_macros",
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pl011"
|
||||
version = "0.1.0"
|
||||
|
|
@ -99,6 +109,7 @@ dependencies = [
|
|||
"bilge-impl",
|
||||
"bits",
|
||||
"common",
|
||||
"migration",
|
||||
"qemu_api",
|
||||
"qemu_api_macros",
|
||||
"util",
|
||||
|
|
@ -141,6 +152,7 @@ name = "qemu_api"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"common",
|
||||
"migration",
|
||||
"qemu_api_macros",
|
||||
"util",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ resolver = "2"
|
|||
members = [
|
||||
"bits",
|
||||
"common",
|
||||
"migration",
|
||||
"qemu-api-macros",
|
||||
"qemu-api",
|
||||
"hw/char/pl011",
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ bilge-impl = { version = "0.2.0" }
|
|||
bits = { path = "../../../bits" }
|
||||
common = { path = "../../../common" }
|
||||
util = { path = "../../../util" }
|
||||
migration = { path = "../../../migration" }
|
||||
qemu_api = { path = "../../../qemu-api" }
|
||||
qemu_api_macros = { path = "../../../qemu-api-macros" }
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ _libpl011_rs = static_library(
|
|||
common_rs,
|
||||
qemu_api_rs,
|
||||
util_rs,
|
||||
migration_rs,
|
||||
qemu_api_macros,
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,17 +5,18 @@
|
|||
use std::{ffi::CStr, mem::size_of};
|
||||
|
||||
use common::{static_assert, uninit_field_mut};
|
||||
use migration::{
|
||||
self, impl_vmstate_forward, impl_vmstate_struct, vmstate_fields, vmstate_of,
|
||||
vmstate_subsections, vmstate_unused, VMStateDescription, VMStateDescriptionBuilder,
|
||||
};
|
||||
use qemu_api::{
|
||||
chardev::{CharBackend, Chardev, Event},
|
||||
impl_vmstate_forward, impl_vmstate_struct,
|
||||
irq::{IRQState, InterruptSource},
|
||||
memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
|
||||
prelude::*,
|
||||
qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, ResetType, ResettablePhasesImpl},
|
||||
qom::{ObjectImpl, Owned, ParentField, ParentInit},
|
||||
sysbus::{SysBusDevice, SysBusDeviceImpl},
|
||||
vmstate::{self, VMStateDescription, VMStateDescriptionBuilder},
|
||||
vmstate_fields, vmstate_of, vmstate_subsections, vmstate_unused,
|
||||
};
|
||||
use util::{log::Log, log_mask_ln};
|
||||
|
||||
|
|
@ -458,10 +459,10 @@ impl PL011Registers {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn post_load(&mut self) -> Result<(), vmstate::InvalidError> {
|
||||
pub fn post_load(&mut self) -> Result<(), migration::InvalidError> {
|
||||
/* Sanity-check input state */
|
||||
if self.read_pos >= self.read_fifo.len() || self.read_count > self.read_fifo.len() {
|
||||
return Err(vmstate::InvalidError);
|
||||
return Err(migration::InvalidError);
|
||||
}
|
||||
|
||||
if !self.fifo_enabled() && self.read_count > 0 && self.read_pos > 0 {
|
||||
|
|
@ -640,7 +641,7 @@ impl PL011State {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn post_load(&self, _version_id: u8) -> Result<(), vmstate::InvalidError> {
|
||||
pub fn post_load(&self, _version_id: u8) -> Result<(), migration::InvalidError> {
|
||||
self.regs.borrow_mut().post_load()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use bilge::prelude::*;
|
||||
use bits::bits;
|
||||
use qemu_api::{impl_vmstate_bitsized, impl_vmstate_forward};
|
||||
use migration::{impl_vmstate_bitsized, impl_vmstate_forward};
|
||||
|
||||
/// Offset of each register from the base memory address of the device.
|
||||
#[doc(alias = "offset")]
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ rust-version.workspace = true
|
|||
[dependencies]
|
||||
common = { path = "../../../common" }
|
||||
util = { path = "../../../util" }
|
||||
migration = { path = "../../../migration" }
|
||||
qemu_api = { path = "../../../qemu-api" }
|
||||
qemu_api_macros = { path = "../../../qemu-api-macros" }
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ _libhpet_rs = static_library(
|
|||
common_rs,
|
||||
qemu_api_rs,
|
||||
util_rs,
|
||||
migration_rs,
|
||||
qemu_api_macros,
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,13 +11,16 @@ use std::{
|
|||
};
|
||||
|
||||
use common::{bitops::IntegerExt, uninit_field_mut};
|
||||
use migration::{
|
||||
self, impl_vmstate_struct, vmstate_fields, vmstate_of, vmstate_subsections, vmstate_validate,
|
||||
VMStateDescription, VMStateDescriptionBuilder,
|
||||
};
|
||||
use qemu_api::{
|
||||
bindings::{
|
||||
address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_prop_bool,
|
||||
qdev_prop_uint32, qdev_prop_usize,
|
||||
},
|
||||
cell::{BqlCell, BqlRefCell},
|
||||
impl_vmstate_struct,
|
||||
irq::InterruptSource,
|
||||
memory::{
|
||||
hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
|
||||
|
|
@ -27,8 +30,6 @@ use qemu_api::{
|
|||
qom::{ObjectImpl, ObjectType, ParentField, ParentInit},
|
||||
qom_isa,
|
||||
sysbus::{SysBusDevice, SysBusDeviceImpl},
|
||||
vmstate::{self, VMStateDescription, VMStateDescriptionBuilder},
|
||||
vmstate_fields, vmstate_of, vmstate_subsections, vmstate_validate,
|
||||
};
|
||||
use util::timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND};
|
||||
|
||||
|
|
@ -845,7 +846,7 @@ impl HPETState {
|
|||
}
|
||||
}
|
||||
|
||||
fn pre_save(&self) -> Result<(), vmstate::Infallible> {
|
||||
fn pre_save(&self) -> Result<(), migration::Infallible> {
|
||||
if self.is_hpet_enabled() {
|
||||
self.counter.set(self.get_ticks());
|
||||
}
|
||||
|
|
@ -859,7 +860,7 @@ impl HPETState {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn post_load(&self, _version_id: u8) -> Result<(), vmstate::Infallible> {
|
||||
fn post_load(&self, _version_id: u8) -> Result<(), migration::Infallible> {
|
||||
for timer in self.timers.iter().take(self.num_timers) {
|
||||
let mut t = timer.borrow_mut();
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ subdir('common')
|
|||
subdir('qemu-api-macros')
|
||||
subdir('bits')
|
||||
subdir('util')
|
||||
subdir('migration')
|
||||
subdir('qemu-api')
|
||||
|
||||
subdir('hw')
|
||||
|
|
|
|||
21
rust/migration/Cargo.toml
Normal file
21
rust/migration/Cargo.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[package]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
description = "Rust bindings for QEMU/migration"
|
||||
resolver = "2"
|
||||
publish = false
|
||||
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
util = { path = "../util" }
|
||||
qemu_api_macros = { path = "../qemu-api-macros" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
1
rust/migration/build.rs
Symbolic link
1
rust/migration/build.rs
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../util/build.rs
|
||||
53
rust/migration/meson.build
Normal file
53
rust/migration/meson.build
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
_migration_bindgen_args = []
|
||||
c_bitfields = [
|
||||
'MigrationPolicy',
|
||||
'MigrationPriority',
|
||||
'VMStateFlags',
|
||||
]
|
||||
foreach enum : c_bitfields
|
||||
_migration_bindgen_args += ['--bitfield-enum', enum]
|
||||
endforeach
|
||||
#
|
||||
# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
|
||||
#
|
||||
# Rust bindings generation with `bindgen` might fail in some cases where the
|
||||
# detected `libclang` does not match the expected `clang` version/target. In
|
||||
# this case you must pass the path to `clang` and `libclang` to your build
|
||||
# command invocation using the environment variables CLANG_PATH and
|
||||
# LIBCLANG_PATH
|
||||
_migration_bindings_inc_rs = rust.bindgen(
|
||||
input: 'wrapper.h',
|
||||
dependencies: common_ss.all_dependencies(),
|
||||
output: 'bindings.inc.rs',
|
||||
include_directories: bindings_incdir,
|
||||
bindgen_version: ['>=0.60.0'],
|
||||
args: bindgen_args_common + _migration_bindgen_args,
|
||||
)
|
||||
|
||||
_migration_rs = static_library(
|
||||
'migration',
|
||||
structured_sources(
|
||||
[
|
||||
'src/lib.rs',
|
||||
'src/bindings.rs',
|
||||
'src/vmstate.rs',
|
||||
],
|
||||
{'.' : _migration_bindings_inc_rs},
|
||||
),
|
||||
override_options: ['rust_std=2021', 'build.rust_std=2021'],
|
||||
rust_abi: 'rust',
|
||||
link_with: [_util_rs],
|
||||
dependencies: [common_rs],
|
||||
)
|
||||
|
||||
migration_rs = declare_dependency(link_with: [_migration_rs],
|
||||
dependencies: [migration, qemuutil])
|
||||
|
||||
# Doctests are essentially integration tests, so they need the same dependencies.
|
||||
# Note that running them requires the object files for C code, so place them
|
||||
# in a separate suite that is run by the "build" CI jobs rather than "check".
|
||||
rust.doctest('rust-migration-rs-doctests',
|
||||
_migration_rs,
|
||||
protocol: 'rust',
|
||||
dependencies: migration_rs,
|
||||
suite: ['doc', 'rust'])
|
||||
48
rust/migration/src/bindings.rs
Normal file
48
rust/migration/src/bindings.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#![allow(
|
||||
dead_code,
|
||||
improper_ctypes_definitions,
|
||||
improper_ctypes,
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
non_upper_case_globals,
|
||||
unnecessary_transmutes,
|
||||
unsafe_op_in_unsafe_fn,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::style,
|
||||
clippy::missing_const_for_fn,
|
||||
clippy::ptr_offset_with_cast,
|
||||
clippy::useless_transmute,
|
||||
clippy::missing_safety_doc,
|
||||
clippy::too_many_arguments
|
||||
)]
|
||||
|
||||
use common::Zeroable;
|
||||
|
||||
#[cfg(MESON)]
|
||||
include!("bindings.inc.rs");
|
||||
|
||||
#[cfg(not(MESON))]
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
|
||||
|
||||
unsafe impl Send for VMStateDescription {}
|
||||
unsafe impl Sync for VMStateDescription {}
|
||||
|
||||
unsafe impl Send for VMStateField {}
|
||||
unsafe impl Sync for VMStateField {}
|
||||
|
||||
unsafe impl Send for VMStateInfo {}
|
||||
unsafe impl Sync for VMStateInfo {}
|
||||
|
||||
// bindgen does not derive Default here
|
||||
#[allow(clippy::derivable_impls)]
|
||||
impl Default for VMStateFlags {
|
||||
fn default() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Zeroable for VMStateFlags {}
|
||||
unsafe impl Zeroable for VMStateField {}
|
||||
unsafe impl Zeroable for VMStateDescription {}
|
||||
6
rust/migration/src/lib.rs
Normal file
6
rust/migration/src/lib.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
pub mod bindings;
|
||||
|
||||
pub mod vmstate;
|
||||
pub use vmstate::*;
|
||||
|
|
@ -52,7 +52,7 @@ pub use crate::bindings::{MigrationPriority, VMStateField};
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use qemu_api::call_func_with_field;
|
||||
/// # use migration::call_func_with_field;
|
||||
/// # use core::marker::PhantomData;
|
||||
/// const fn size_of_field<T>(_: PhantomData<T>) -> usize {
|
||||
/// std::mem::size_of::<T>()
|
||||
|
|
@ -125,17 +125,19 @@ pub const fn vmstate_varray_flag<T: VMState>(_: PhantomData<T>) -> VMStateFlags
|
|||
/// * scalar types (integer and `bool`)
|
||||
/// * the C struct `QEMUTimer`
|
||||
/// * a transparent wrapper for any of the above (`Cell`, `UnsafeCell`,
|
||||
/// [`BqlCell`](crate::cell::BqlCell),
|
||||
/// [`BqlRefCell`](crate::cell::BqlRefCell)),
|
||||
/// [`BqlCell`], [`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
|
||||
/// * a `NonNull` pointer, a `Box` or an [`Owned`] for any of the above
|
||||
/// * an array of any of the above
|
||||
///
|
||||
/// In order to support other types, the trait `VMState` must be implemented
|
||||
/// for them. The macros [`impl_vmstate_forward`](crate::impl_vmstate_forward),
|
||||
/// [`impl_vmstate_bitsized`](crate::impl_vmstate_bitsized), and
|
||||
/// [`impl_vmstate_struct`](crate::impl_vmstate_struct) help with this.
|
||||
///
|
||||
/// [`BqlCell`]: ../../qemu_api/cell/struct.BqlCell.html
|
||||
/// [`BqlRefCell`]: ../../qemu_api/cell/struct.BqlRefCell.html
|
||||
/// [`Owned`]: ../../qemu_api/qom/struct.Owned.html
|
||||
#[macro_export]
|
||||
macro_rules! vmstate_of {
|
||||
($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(, $test_fn:expr)? $(,)?) => {
|
||||
|
|
@ -161,7 +163,11 @@ macro_rules! vmstate_of {
|
|||
};
|
||||
}
|
||||
|
||||
impl VMStateFlags {
|
||||
pub trait VMStateFlagsExt {
|
||||
const VMS_VARRAY_FLAGS: VMStateFlags;
|
||||
}
|
||||
|
||||
impl VMStateFlagsExt for VMStateFlags {
|
||||
const VMS_VARRAY_FLAGS: VMStateFlags = VMStateFlags(
|
||||
VMStateFlags::VMS_VARRAY_INT32.0
|
||||
| VMStateFlags::VMS_VARRAY_UINT8.0
|
||||
|
|
@ -207,7 +213,7 @@ impl VMStateField {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn with_varray_flag_unchecked(mut self, flag: VMStateFlags) -> VMStateField {
|
||||
pub const fn with_varray_flag_unchecked(mut self, flag: VMStateFlags) -> Self {
|
||||
self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_ARRAY.0);
|
||||
self.flags = VMStateFlags(self.flags.0 | flag.0);
|
||||
self.num = 0; // varray uses num_offset instead of num.
|
||||
|
|
@ -216,13 +222,13 @@ impl VMStateField {
|
|||
|
||||
#[must_use]
|
||||
#[allow(unused_mut)]
|
||||
pub const fn with_varray_flag(mut self, flag: VMStateFlags) -> VMStateField {
|
||||
pub const fn with_varray_flag(mut self, flag: VMStateFlags) -> Self {
|
||||
assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) != 0);
|
||||
self.with_varray_flag_unchecked(flag)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField {
|
||||
pub const fn with_varray_multiply(mut self, num: u32) -> Self {
|
||||
assert!(num <= 0x7FFF_FFFFu32);
|
||||
self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_MULTIPLY_ELEMENTS.0);
|
||||
self.num = num as i32;
|
||||
|
|
@ -237,7 +243,7 @@ impl VMStateField {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use qemu_api::impl_vmstate_forward;
|
||||
/// # use migration::impl_vmstate_forward;
|
||||
/// pub struct Fifo([u8; 16]);
|
||||
/// impl_vmstate_forward!(Fifo);
|
||||
/// ```
|
||||
|
|
@ -272,7 +278,7 @@ macro_rules! impl_vmstate_transparent {
|
|||
impl_vmstate_transparent!(std::cell::Cell<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!(::common::Opaque<T> where T: VMState);
|
||||
impl_vmstate_transparent!(common::Opaque<T> where T: VMState);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_vmstate_bitsized {
|
||||
|
|
@ -294,12 +300,12 @@ macro_rules! impl_vmstate_bitsized {
|
|||
|
||||
macro_rules! impl_vmstate_scalar {
|
||||
($info:ident, $type:ty$(, $varray_flag:ident)?) => {
|
||||
unsafe impl VMState for $type {
|
||||
const BASE: VMStateField = VMStateField {
|
||||
unsafe impl $crate::vmstate::VMState for $type {
|
||||
const BASE: $crate::vmstate::VMStateField = $crate::vmstate::VMStateField {
|
||||
info: addr_of!(bindings::$info),
|
||||
size: mem::size_of::<$type>(),
|
||||
flags: VMStateFlags::VMS_SINGLE,
|
||||
..Zeroable::ZERO
|
||||
flags: $crate::vmstate::VMStateFlags::VMS_SINGLE,
|
||||
..::common::zeroable::Zeroable::ZERO
|
||||
};
|
||||
$(const VARRAY_FLAG: VMStateFlags = VMStateFlags::$varray_flag;)?
|
||||
}
|
||||
|
|
@ -320,12 +326,12 @@ impl_vmstate_scalar!(vmstate_info_timer, util::timer::Timer);
|
|||
#[macro_export]
|
||||
macro_rules! impl_vmstate_c_struct {
|
||||
($type:ty, $vmsd:expr) => {
|
||||
unsafe impl VMState for $type {
|
||||
unsafe impl $crate::vmstate::VMState for $type {
|
||||
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,
|
||||
..common::zeroable::Zeroable::ZERO
|
||||
..::common::zeroable::Zeroable::ZERO
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
@ -391,7 +397,7 @@ pub type VMSFieldExistCb = unsafe extern "C" fn(
|
|||
#[macro_export]
|
||||
macro_rules! vmstate_exist_fn {
|
||||
($struct_name:ty, $test_fn:expr) => {{
|
||||
const fn test_cb_builder__<T, F: for<'a> ::common::callbacks::FnCall<(&'a T, u8), bool>>(
|
||||
const fn test_cb_builder__<T, F: for<'a> ::common::FnCall<(&'a T, u8), bool>>(
|
||||
_phantom: ::core::marker::PhantomData<F>,
|
||||
) -> $crate::vmstate::VMSFieldExistCb {
|
||||
const { assert!(F::IS_SOME) };
|
||||
51
rust/migration/wrapper.h
Normal file
51
rust/migration/wrapper.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* QEMU System Emulator
|
||||
*
|
||||
* Copyright (c) 2024 Linaro Ltd.
|
||||
*
|
||||
* Authors: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This header file is meant to be used as input to the `bindgen` application
|
||||
* in order to generate C FFI compatible Rust bindings.
|
||||
*/
|
||||
|
||||
#ifndef __CLANG_STDATOMIC_H
|
||||
#define __CLANG_STDATOMIC_H
|
||||
/*
|
||||
* Fix potential missing stdatomic.h error in case bindgen does not insert the
|
||||
* correct libclang header paths on its own. We do not use stdatomic.h symbols
|
||||
* in QEMU code, so it's fine to declare dummy types instead.
|
||||
*/
|
||||
typedef enum memory_order {
|
||||
memory_order_relaxed,
|
||||
memory_order_consume,
|
||||
memory_order_acquire,
|
||||
memory_order_release,
|
||||
memory_order_acq_rel,
|
||||
memory_order_seq_cst,
|
||||
} memory_order;
|
||||
#endif /* __CLANG_STDATOMIC_H */
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "migration/vmstate.h"
|
||||
|
|
@ -15,6 +15,7 @@ rust-version.workspace = true
|
|||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
migration = { path = "../migration" }
|
||||
util = { path = "../util" }
|
||||
qemu_api_macros = { path = "../qemu-api-macros" }
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ c_enums = [
|
|||
'GpioPolarity',
|
||||
'MachineInitPhase',
|
||||
'MemoryDeviceInfoKind',
|
||||
'MigrationPolicy',
|
||||
'MigrationPriority',
|
||||
'QEMUChrEvent',
|
||||
'ResetType',
|
||||
'device_endian',
|
||||
|
|
@ -23,12 +21,13 @@ foreach enum : c_enums
|
|||
endforeach
|
||||
c_bitfields = [
|
||||
'ClockEvent',
|
||||
'VMStateFlags',
|
||||
]
|
||||
foreach enum : c_bitfields
|
||||
_qemu_api_bindgen_args += ['--bitfield-enum', enum]
|
||||
endforeach
|
||||
|
||||
_qemu_api_bindgen_args += ['--blocklist-type', 'VMStateDescription']
|
||||
|
||||
_qemu_api_bindgen_args += ['--blocklist-type', 'Error']
|
||||
# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
|
||||
#
|
||||
|
|
@ -60,15 +59,14 @@ _qemu_api_rs = static_library(
|
|||
'src/qdev.rs',
|
||||
'src/qom.rs',
|
||||
'src/sysbus.rs',
|
||||
'src/vmstate.rs',
|
||||
],
|
||||
{'.' : _qemu_api_bindings_inc_rs},
|
||||
),
|
||||
override_options: ['rust_std=2021', 'build.rust_std=2021'],
|
||||
rust_abi: 'rust',
|
||||
rust_args: _qemu_api_cfg,
|
||||
dependencies: [anyhow_rs, common_rs, foreign_rs, libc_rs, qemu_api_macros, util_rs,
|
||||
qom, hwcore, chardev, migration],
|
||||
dependencies: [anyhow_rs, common_rs, foreign_rs, libc_rs, migration_rs, qemu_api_macros,
|
||||
util_rs, qom, hwcore, chardev],
|
||||
)
|
||||
|
||||
qemu_api_rs = declare_dependency(link_with: [_qemu_api_rs],
|
||||
|
|
@ -90,7 +88,7 @@ test('rust-qemu-api-integration',
|
|||
override_options: ['rust_std=2021', 'build.rust_std=2021'],
|
||||
rust_args: ['--test'],
|
||||
install: false,
|
||||
dependencies: [common_rs, util_rs, qemu_api_rs]),
|
||||
dependencies: [common_rs, util_rs, migration_rs, qemu_api_rs]),
|
||||
args: [
|
||||
'--test', '--test-threads', '1',
|
||||
'--format', 'pretty',
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
//! `bindgen`-generated declarations.
|
||||
|
||||
use common::Zeroable;
|
||||
use migration::bindings::VMStateDescription;
|
||||
use util::bindings::Error;
|
||||
|
||||
#[cfg(MESON)]
|
||||
|
|
@ -51,28 +52,8 @@ unsafe impl Sync for Property {}
|
|||
unsafe impl Send for TypeInfo {}
|
||||
unsafe impl Sync for TypeInfo {}
|
||||
|
||||
unsafe impl Send for VMStateDescription {}
|
||||
unsafe impl Sync for VMStateDescription {}
|
||||
|
||||
unsafe impl Send for VMStateField {}
|
||||
unsafe impl Sync for VMStateField {}
|
||||
|
||||
unsafe impl Send for VMStateInfo {}
|
||||
unsafe impl Sync for VMStateInfo {}
|
||||
|
||||
// bindgen does not derive Default here
|
||||
#[allow(clippy::derivable_impls)]
|
||||
impl Default for crate::bindings::VMStateFlags {
|
||||
fn default() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {}
|
||||
unsafe impl Zeroable for crate::bindings::Property {}
|
||||
unsafe impl Zeroable for crate::bindings::VMStateFlags {}
|
||||
unsafe impl Zeroable for crate::bindings::VMStateField {}
|
||||
unsafe impl Zeroable for crate::bindings::VMStateDescription {}
|
||||
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {}
|
||||
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {}
|
||||
unsafe impl Zeroable for crate::bindings::MemoryRegionOps {}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,9 @@ use std::{
|
|||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use crate::{bindings, impl_vmstate_transparent};
|
||||
use migration::impl_vmstate_transparent;
|
||||
|
||||
use crate::bindings;
|
||||
|
||||
/// An internal function that is used by doctests.
|
||||
pub fn bql_start_test() {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ pub mod memory;
|
|||
pub mod qdev;
|
||||
pub mod qom;
|
||||
pub mod sysbus;
|
||||
pub mod vmstate;
|
||||
|
||||
// Allow proc-macros to refer to `::qemu_api` inside the `qemu_api` crate (this
|
||||
// crate).
|
||||
|
|
|
|||
|
|
@ -21,5 +21,3 @@ pub use crate::qom::ObjectType;
|
|||
pub use crate::qom_isa;
|
||||
|
||||
pub use crate::sysbus::SysBusDeviceMethods;
|
||||
|
||||
pub use crate::vmstate::VMState;
|
||||
|
|
|
|||
|
|
@ -11,17 +11,16 @@ use std::{
|
|||
|
||||
pub use bindings::{ClockEvent, DeviceClass, Property, ResetType};
|
||||
use common::{callbacks::FnCall, Opaque};
|
||||
use migration::{impl_vmstate_c_struct, VMStateDescription};
|
||||
use util::{Error, Result};
|
||||
|
||||
use crate::{
|
||||
bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClass},
|
||||
cell::bql_locked,
|
||||
chardev::Chardev,
|
||||
impl_vmstate_c_struct,
|
||||
irq::InterruptSource,
|
||||
prelude::*,
|
||||
qom::{ObjectClass, ObjectImpl, Owned, ParentInit},
|
||||
vmstate::VMStateDescription,
|
||||
};
|
||||
|
||||
/// A safe wrapper around [`bindings::Clock`].
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ use std::{
|
|||
|
||||
pub use bindings::ObjectClass;
|
||||
use common::Opaque;
|
||||
use migration::impl_vmstate_pointer;
|
||||
|
||||
use crate::{
|
||||
bindings::{
|
||||
|
|
@ -110,7 +111,6 @@ use crate::{
|
|||
object_get_typename, object_new, object_ref, object_unref, TypeInfo,
|
||||
},
|
||||
cell::bql_locked,
|
||||
impl_vmstate_pointer,
|
||||
};
|
||||
|
||||
/// A safe wrapper around [`bindings::Object`].
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
use std::{ffi::CStr, ptr::addr_of};
|
||||
|
||||
use migration::{VMStateDescription, VMStateDescriptionBuilder};
|
||||
use qemu_api::{
|
||||
cell::{self, BqlCell},
|
||||
prelude::*,
|
||||
qdev::{DeviceImpl, DeviceState, ResettablePhasesImpl},
|
||||
qom::{ObjectImpl, ParentField},
|
||||
sysbus::SysBusDevice,
|
||||
vmstate::{VMStateDescription, VMStateDescriptionBuilder},
|
||||
};
|
||||
use util::bindings::{module_call_init, module_init_type};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,16 +10,16 @@ use std::{
|
|||
};
|
||||
|
||||
use common::Opaque;
|
||||
use qemu_api::{
|
||||
use migration::{
|
||||
bindings::{
|
||||
vmstate_info_bool, vmstate_info_int32, vmstate_info_int64, vmstate_info_int8,
|
||||
vmstate_info_uint64, vmstate_info_uint8, vmstate_info_unused_buffer, VMStateFlags,
|
||||
},
|
||||
cell::BqlCell,
|
||||
impl_vmstate_forward, impl_vmstate_struct,
|
||||
vmstate::{VMStateDescription, VMStateDescriptionBuilder, VMStateField},
|
||||
vmstate_fields, vmstate_of, vmstate_unused, vmstate_validate,
|
||||
};
|
||||
use qemu_api::cell::BqlCell;
|
||||
|
||||
const FOO_ARRAY_MAX: usize = 3;
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ typedef enum memory_order {
|
|||
#include "hw/qdev-properties.h"
|
||||
#include "hw/qdev-properties-system.h"
|
||||
#include "hw/irq.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "chardev/char-serial.h"
|
||||
#include "exec/memattrs.h"
|
||||
#include "system/address-spaces.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue