From: Paolo Bonzini Date: Thu, 20 Nov 2025 16:20:52 +0000 (+0100) Subject: rust: timer: add bindings to timer_mod_ns and timer_expire_time_ns X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=709beed426b36e9b1ec524a9d50832023e81e9c4;p=thirdparty%2Fqemu.git rust: timer: add bindings to timer_mod_ns and timer_expire_time_ns These are needed to implement ToMigrationStateShared for timers, and thus allow including them in Migratable<> structs. Signed-off-by: Paolo Bonzini --- diff --git a/rust/util/src/timer.rs b/rust/util/src/timer.rs index 829f52d111..f8e65c9a0a 100644 --- a/rust/util/src/timer.rs +++ b/rust/util/src/timer.rs @@ -10,7 +10,8 @@ use std::{ 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 @@ impl Timer { } } + pub fn expire_time_ns(&self) -> Option { + // 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