F: rust/migration/
F: rust/qemu-api
F: rust/qemu-api-macros
+F: rust/qom/
F: rust/rustfmt.toml
F: rust/util/
F: scripts/get-wraps-from-cargo-registry.py
"migration",
"qemu_api",
"qemu_api_macros",
+ "qom",
"util",
]
"migration",
"qemu_api",
"qemu_api_macros",
+ "qom",
"util",
]
"common",
"migration",
"qemu_api_macros",
+ "qom",
"util",
]
"syn",
]
+[[package]]
+name = "qom"
+version = "0.1.0"
+dependencies = [
+ "bql",
+ "common",
+ "migration",
+ "qemu_api_macros",
+ "util",
+]
+
[[package]]
name = "quote"
version = "1.0.36"
"migration",
"qemu-api-macros",
"qemu-api",
+ "qom",
"hw/char/pl011",
"hw/timer/hpet",
"util",
util = { path = "../../../util" }
bql = { path = "../../../bql" }
migration = { path = "../../../migration" }
+qom = { path = "../../../qom" }
qemu_api = { path = "../../../qemu-api" }
qemu_api_macros = { path = "../../../qemu-api-macros" }
migration_rs,
bql_rs,
qemu_api_macros,
+ qom_rs,
],
)
memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
prelude::*,
qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, ResetType, ResettablePhasesImpl},
- qom::{ObjectImpl, Owned, ParentField, ParentInit},
sysbus::{SysBusDevice, SysBusDeviceImpl},
};
+use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
use util::{log::Log, log_mask_ln};
use crate::registers::{self, Interrupt, RegisterOffset};
util = { path = "../../../util" }
migration = { path = "../../../migration" }
bql = { path = "../../../bql" }
+qom = { path = "../../../qom" }
qemu_api = { path = "../../../qemu-api" }
qemu_api_macros = { path = "../../../qemu-api-macros" }
migration_rs,
bql_rs,
qemu_api_macros,
+ qom_rs,
],
)
},
prelude::*,
qdev::{DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
- qom::{ObjectImpl, ObjectType, ParentField, ParentInit},
- qom_isa,
sysbus::{SysBusDevice, SysBusDeviceImpl},
};
+use qom::{prelude::*, ObjectImpl, ParentField, ParentInit};
use util::timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND};
use crate::fw_cfg::HPETFwConfig;
subdir('util')
subdir('migration')
subdir('bql')
+subdir('qom')
subdir('qemu-api')
subdir('hw')
///
/// [`BqlCell`]: ../../bql/cell/struct.BqlCell.html
/// [`BqlRefCell`]: ../../bql/cell/struct.BqlRefCell.html
-/// [`Owned`]: ../../qemu_api/qom/struct.Owned.html
+/// [`Owned`]: ../../qom/qom/struct.Owned.html
#[macro_export]
macro_rules! vmstate_of {
($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(, $test_fn:expr)? $(,)?) => {
Ok(quote! {
::common::assert_field_type!(#name, #parent,
- ::qemu_api::qom::ParentField<<#name as ::qemu_api::qom::ObjectImpl>::ParentType>);
+ ::qom::ParentField<<#name as ::qom::ObjectImpl>::ParentType>);
::util::module_init! {
MODULE_INIT_QOM => unsafe {
- ::qemu_api::bindings::type_register_static(&<#name as ::qemu_api::qom::ObjectImpl>::TYPE_INFO);
+ ::qom::type_register_static(&<#name as ::qom::ObjectImpl>::TYPE_INFO);
}
}
})
::common::assert_field_type!(
Foo,
_unused,
- ::qemu_api::qom::ParentField<<Foo as ::qemu_api::qom::ObjectImpl>::ParentType>
+ ::qom::ParentField<<Foo as ::qom::ObjectImpl>::ParentType>
);
::util::module_init! {
MODULE_INIT_QOM => unsafe {
- ::qemu_api::bindings::type_register_static(&<Foo as ::qemu_api::qom::ObjectImpl>::TYPE_INFO);
+ ::qom::type_register_static(&<Foo as ::qom::ObjectImpl>::TYPE_INFO);
}
}
}
migration = { path = "../migration" }
util = { path = "../util" }
bql = { path = "../bql" }
+qom = { path = "../qom" }
qemu_api_macros = { path = "../qemu-api-macros" }
[lints]
_qemu_api_bindgen_args += ['--bitfield-enum', enum]
endforeach
-_qemu_api_bindgen_args += ['--blocklist-type', 'VMStateDescription']
+blocked_type = [
+ 'ObjectClass',
+ 'VMStateDescription',
+ 'Error',
+]
+foreach type: blocked_type
+ _qemu_api_bindgen_args += ['--blocklist-type', type]
+endforeach
-_qemu_api_bindgen_args += ['--blocklist-type', 'Error']
# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
#
# Rust bindings generation with `bindgen` might fail in some cases where the
'src/memory.rs',
'src/prelude.rs',
'src/qdev.rs',
- 'src/qom.rs',
'src/sysbus.rs',
],
{'.' : _qemu_api_bindings_inc_rs},
rust_abi: 'rust',
rust_args: _qemu_api_cfg,
dependencies: [anyhow_rs, bql_rs, common_rs, foreign_rs, libc_rs, migration_rs, qemu_api_macros,
- util_rs, qom, hwcore, chardev],
+ qom_rs, util_rs, hwcore, chardev],
)
qemu_api_rs = declare_dependency(link_with: [_qemu_api_rs],
override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_args: ['--test'],
install: false,
- dependencies: [bql_rs, common_rs, util_rs, migration_rs, qemu_api_rs]),
+ dependencies: [bql_rs, common_rs, util_rs, migration_rs, qom_rs, qemu_api_rs]),
args: [
'--test', '--test-threads', '1',
'--format', 'pretty',
use common::Zeroable;
use migration::bindings::VMStateDescription;
+use qom::bindings::ObjectClass;
use util::bindings::Error;
#[cfg(MESON)]
use bql::{BqlRefCell, BqlRefMut};
use common::{callbacks::FnCall, errno, Opaque};
+use qom::prelude::*;
-use crate::{bindings, prelude::*};
+use crate::bindings;
/// A safe wrapper around [`bindings::Chardev`].
#[repr(transparent)]
use bql::BqlCell;
use common::Opaque;
+use qom::{prelude::*, ObjectClass};
-use crate::{
- bindings::{self, qemu_set_irq},
- prelude::*,
- qom::ObjectClass,
-};
+use crate::bindings::{self, qemu_set_irq};
/// An opaque wrapper around [`bindings::IRQState`].
#[repr(transparent)]
///
/// Interrupts are implemented as a pointer to the interrupt "sink", which has
/// type [`IRQState`]. A device exposes its source as a QOM link property using
-/// a function such as [`SysBusDeviceMethods::init_irq`], and
+/// a function such as [`crate::sysbus::SysBusDeviceMethods::init_irq`], and
/// initially leaves the pointer to a NULL value, representing an unconnected
/// interrupt. To connect it, whoever creates the device fills the pointer with
/// the sink's `IRQState *`, for example using `sysbus_connect_irq`. Because
const TYPE_NAME: &'static CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_IRQ) };
}
+
qom_isa!(IRQState: Object);
pub mod irq;
pub mod memory;
pub mod qdev;
-pub mod qom;
pub mod sysbus;
// Allow proc-macros to refer to `::qemu_api` inside the `qemu_api` crate (this
pub use bindings::{hwaddr, MemTxAttrs};
use common::{callbacks::FnCall, uninit::MaybeUninitField, zeroable::Zeroable, Opaque};
+use qom::prelude::*;
-use crate::{
- bindings::{self, device_endian, memory_region_init_io},
- prelude::*,
-};
+use crate::bindings::{self, device_endian, memory_region_init_io};
pub struct MemoryRegionOps<T>(
bindings::MemoryRegionOps,
const TYPE_NAME: &'static CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_MEMORY_REGION) };
}
+
qom_isa!(MemoryRegion: Object);
/// A special `MemTxAttrs` constant, used to indicate that no memory
pub use crate::qdev::DeviceMethods;
-pub use crate::qom::InterfaceType;
-pub use crate::qom::IsA;
-pub use crate::qom::Object;
-pub use crate::qom::ObjectCast;
-pub use crate::qom::ObjectClassMethods;
-pub use crate::qom::ObjectDeref;
-pub use crate::qom::ObjectMethods;
-pub use crate::qom::ObjectType;
-
-pub use crate::qom_isa;
-
pub use crate::sysbus::SysBusDeviceMethods;
pub use bindings::{ClockEvent, DeviceClass, Property, ResetType};
use common::{callbacks::FnCall, Opaque};
use migration::{impl_vmstate_c_struct, VMStateDescription};
+use qom::{prelude::*, ObjectClass, ObjectImpl, Owned, ParentInit};
use util::{Error, Result};
use crate::{
bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClass},
chardev::Chardev,
irq::InterruptSource,
- prelude::*,
- qom::{ObjectClass, ObjectImpl, Owned, ParentInit},
};
/// A safe wrapper around [`bindings::Clock`].
const TYPE_NAME: &'static CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_DEVICE) };
}
+
qom_isa!(DeviceState: Object);
/// Initialization methods take a [`ParentInit`] and can be called as
const TYPE_NAME: &'static CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_CLOCK) };
}
+
qom_isa!(Clock: Object);
impl_vmstate_c_struct!(Clock, bindings::vmstate_clock);
pub use bindings::SysBusDeviceClass;
use common::Opaque;
+use qom::{prelude::*, Owned};
use crate::{
bindings,
irq::{IRQState, InterruptSource},
memory::MemoryRegion,
- prelude::*,
qdev::{DeviceImpl, DeviceState},
- qom::Owned,
};
/// A safe wrapper around [`bindings::SysBusDevice`].
const TYPE_NAME: &'static CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) };
}
+
qom_isa!(SysBusDevice: DeviceState, Object);
// TODO: add virtual methods
use bql::BqlCell;
use migration::{VMStateDescription, VMStateDescriptionBuilder};
use qemu_api::{
- prelude::*,
qdev::{DeviceImpl, DeviceState, ResettablePhasesImpl},
- qom::{ObjectImpl, ParentField},
sysbus::SysBusDevice,
};
+use qom::{prelude::*, ObjectImpl, ParentField};
use util::bindings::{module_call_init, module_init_type};
mod vmstate_tests;
--- /dev/null
+[package]
+name = "qom"
+version = "0.1.0"
+description = "Rust bindings for QEMU/QOM"
+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" }
+bql = { path = "../bql" }
+migration = { path = "../migration" }
+qemu_api_macros = { path = "../qemu-api-macros" }
+util = { path = "../util" }
+
+[lints]
+workspace = true
--- /dev/null
+../util/build.rs
\ No newline at end of file
--- /dev/null
+# 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
+_qom_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,
+)
+
+_qom_rs = static_library(
+ 'qom',
+ structured_sources(
+ [
+ 'src/lib.rs',
+ 'src/bindings.rs',
+ 'src/prelude.rs',
+ 'src/qom.rs',
+ ],
+ {'.': _qom_bindings_inc_rs}
+ ),
+ override_options: ['rust_std=2021', 'build.rust_std=2021'],
+ rust_abi: 'rust',
+ link_with: [_bql_rs, _migration_rs],
+ dependencies: [common_rs, qemu_api_macros],
+)
+
+qom_rs = declare_dependency(link_with: [_qom_rs], dependencies: [qemu_api_macros, qom])
+
+# 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-qom-rs-doctests',
+ _qom_rs,
+ protocol: 'rust',
+ dependencies: qom_rs,
+ suite: ['doc', 'rust'])
--- /dev/null
+// 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
+)]
+
+#[cfg(MESON)]
+include!("bindings.inc.rs");
+
+#[cfg(not(MESON))]
+include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+pub mod bindings;
+
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
+
+mod qom;
+pub use qom::*;
--- /dev/null
+//! Traits and essential types intended for blanket imports.
+
+pub use crate::qom::InterfaceType;
+pub use crate::qom::IsA;
+pub use crate::qom::Object;
+pub use crate::qom::ObjectCast;
+pub use crate::qom::ObjectClassMethods;
+pub use crate::qom::ObjectDeref;
+pub use crate::qom::ObjectMethods;
+pub use crate::qom::ObjectType;
+
+pub use crate::qom_isa;
ptr::NonNull,
};
-pub use bindings::ObjectClass;
use common::Opaque;
use migration::impl_vmstate_pointer;
self, object_class_dynamic_cast, object_dynamic_cast, object_get_class, object_get_typename,
object_new, object_ref, object_unref, TypeInfo,
};
+pub use crate::bindings::{type_register_static, ObjectClass};
/// A safe wrapper around [`bindings::Object`].
#[repr(transparent)]
$(
// SAFETY: it is the caller responsibility to have $parent as the
// first field
- unsafe impl $crate::qom::IsA<$parent> for $struct {}
+ unsafe impl $crate::IsA<$parent> for $struct {}
impl AsRef<$parent> for $struct {
fn as_ref(&self) -> &$parent {
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * 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 "qom/object.h"