[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 0/8] rust: qom: move bridge for TypeInfo and DeviceClass function
From: |
Paolo Bonzini |
Subject: |
[PATCH 0/8] rust: qom: move bridge for TypeInfo and DeviceClass functions to common code |
Date: |
Mon, 25 Nov 2024 09:04:59 +0100 |
This is a first step towards modeling QOM in the Rust type system.
This is by no means the final state of the bindings; rather, the
one thing it focuses on is moving unsafe code out of devices. This
in principle removes code duplication, though with only one device
the duplication is still theoretical.
In particular the pl011 device includes bridge functions for instance_init,
DeviceClass::realize and DeviceClass::unrealize that take raw pointers
and call to (usually safe, though not always) functions that take Rust
references.
These functions would be the same for all devices; parameterize them on
a generic type, so that the implementation of TypeInfo.class_init can
reuse them. Likewise implement TypeInfo.instance_finalize simply as
std::ptr::drop_in_place, which automatically bridges to the Drop trait
if the class implements it.
Some of the traits resemble those in Manos's implementation at
https://lore.kernel.org/qemu-devel/20241024-rust-round-2-v1-3-051e7a25b978@linaro.org/;
in particular DeviceImpl is an extension of his same-named trait, also
covering properties and vmstate, and ClassInitImpl for now is the same
as his ClassImplUnsafe. I have not added an explicit "Unsafe" suffix
because I don't plan to have separate safe and unsafe versions of the
traits, just like there is no DeviceImplUnsafe. The main difference
lies in the usage of generics and monomorphization over macros;
generics are always compiled and any compiler error messages point
at the implementation rather than the invocation of the macro.
While at it, the series starts adding documentation to the QOM machinery.
A lot of the extra lines of code in fact is documentation and/or safety
comments.
Paolo
Paolo Bonzini (8):
rust: qom: add default definitions for ObjectImpl
rust: qom: rename Class trait to ClassInitImpl
rust: qom: convert type_info! macro to an associated const
rust: qom: move ClassInitImpl to the instance side
rust: qdev: move device_class_init! body to generic function,
ClassInitImpl implementation to macro
rust: qdev: move bridge for realize and reset functions out of pl011
rust: qom: automatically use Drop trait to implement instance_finalize
rust: qom: move bridge for TypeInfo functions out of pl011
rust/hw/char/pl011/src/device.rs | 85 ++++++---------
rust/hw/char/pl011/src/device_class.rs | 34 ------
rust/qemu-api/src/definitions.rs | 140 ++++++++++++++++++-------
rust/qemu-api/src/device_class.rs | 114 +++++++++++++++++---
rust/qemu-api/tests/tests.rs | 33 +++---
5 files changed, 246 insertions(+), 160 deletions(-)
--
2.47.0
- [PATCH 0/8] rust: qom: move bridge for TypeInfo and DeviceClass functions to common code,
Paolo Bonzini <=
- [PATCH 1/8] rust: qom: add default definitions for ObjectImpl, Paolo Bonzini, 2024/11/25
- [PATCH 2/8] rust: qom: rename Class trait to ClassInitImpl, Paolo Bonzini, 2024/11/25
- [PATCH 3/8] rust: qom: convert type_info! macro to an associated const, Paolo Bonzini, 2024/11/25
- [PATCH 6/8] rust: qdev: move bridge for realize and reset functions out of pl011, Paolo Bonzini, 2024/11/25
- [PATCH 7/8] rust: qom: automatically use Drop trait to implement instance_finalize, Paolo Bonzini, 2024/11/25
- [PATCH 5/8] rust: qdev: move device_class_init! body to generic function, ClassInitImpl implementation to macro, Paolo Bonzini, 2024/11/25
- [PATCH 8/8] rust: qom: move bridge for TypeInfo functions out of pl011, Paolo Bonzini, 2024/11/25
- [PATCH 4/8] rust: qom: move ClassInitImpl to the instance side, Paolo Bonzini, 2024/11/25