These are needed to implement ToMigrationStateShared for timers, and thus allow including them in Migratable<> structs.
Signed-off-by: Paolo Bonzini <[email protected]> --- rust/util/src/timer.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rust/util/src/timer.rs b/rust/util/src/timer.rs index 829f52d111e..f8e65c9a0ac 100644 --- a/rust/util/src/timer.rs +++ b/rust/util/src/timer.rs @@ -10,7 +10,8 @@ use common::{callbacks::FnCall, Opaque}; use crate::bindings::{ - self, qemu_clock_get_ns, timer_del, timer_init_full, timer_mod, QEMUClockType, + self, qemu_clock_get_ns, timer_del, timer_expire_time_ns, timer_init_full, timer_mod, + timer_mod_ns, QEMUClockType, }; /// A safe wrapper around [`bindings::QEMUTimer`]. @@ -88,6 +89,19 @@ pub fn init_full<T, F>( } } + pub fn expire_time_ns(&self) -> Option<i64> { + // SAFETY: the only way to obtain a Timer safely is via methods that + // take a Pin<&mut Self>, therefore the timer is pinned + let ret = unsafe { timer_expire_time_ns(self.as_ptr()) }; + i64::try_from(ret).ok() + } + + pub fn modify_ns(&self, expire_time: u64) { + // SAFETY: the only way to obtain a Timer safely is via methods that + // take a Pin<&mut Self>, therefore the timer is pinned + unsafe { timer_mod_ns(self.as_mut_ptr(), expire_time.try_into().unwrap()) } + } + pub fn modify(&self, expire_time: u64) { // SAFETY: the only way to obtain a Timer safely is via methods that // take a Pin<&mut Self>, therefore the timer is pinned -- 2.52.0
