mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 09:43:56 -06:00
rust: qdev: move bridge for realize and reset functions out of pl011
Allow the DeviceImpl trait to expose safe Rust functions. rust_device_class_init<> adds thunks around the functions in DeviceImpl. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
8c80c472da
commit
f75fb90ff2
4 changed files with 33 additions and 36 deletions
|
@ -125,9 +125,8 @@ impl DeviceImpl for PL011State {
|
|||
fn vmsd() -> Option<&'static VMStateDescription> {
|
||||
Some(&device_class::VMSTATE_PL011)
|
||||
}
|
||||
const REALIZE: Option<unsafe extern "C" fn(*mut DeviceState, *mut *mut Error)> =
|
||||
Some(device_class::pl011_realize);
|
||||
const RESET: Option<unsafe extern "C" fn(*mut DeviceState)> = Some(device_class::pl011_reset);
|
||||
const REALIZE: Option<fn(&mut Self)> = Some(Self::realize);
|
||||
const RESET: Option<fn(&mut Self)> = Some(Self::reset);
|
||||
}
|
||||
|
||||
impl_device_class!(PL011State);
|
||||
|
|
|
@ -92,29 +92,3 @@ qemu_api::declare_properties! {
|
|||
default = true
|
||||
),
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// We expect the FFI user of this function to pass a valid pointer, that has
|
||||
/// the same size as [`PL011State`]. We also expect the device is
|
||||
/// readable/writeable from one thread at any time.
|
||||
pub unsafe extern "C" fn pl011_realize(dev: *mut DeviceState, _errp: *mut *mut Error) {
|
||||
unsafe {
|
||||
assert!(!dev.is_null());
|
||||
let mut state = NonNull::new_unchecked(dev.cast::<PL011State>());
|
||||
state.as_mut().realize();
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// We expect the FFI user of this function to pass a valid pointer, that has
|
||||
/// the same size as [`PL011State`]. We also expect the device is
|
||||
/// readable/writeable from one thread at any time.
|
||||
pub unsafe extern "C" fn pl011_reset(dev: *mut DeviceState) {
|
||||
unsafe {
|
||||
assert!(!dev.is_null());
|
||||
let mut state = NonNull::new_unchecked(dev.cast::<PL011State>());
|
||||
state.as_mut().reset();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue