]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
rust: timer: add bindings to timer_mod_ns and timer_expire_time_ns
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 20 Nov 2025 16:20:52 +0000 (17:20 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 27 Dec 2025 09:11:10 +0000 (10:11 +0100)
These are needed to implement ToMigrationStateShared for timers,
and thus allow including them in Migratable<> structs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rust/util/src/timer.rs

index 829f52d111e13dda39a7d34b60631e996602a55c..f8e65c9a0ac089ce87ab15f368b7f57faf71b7ea 100644 (file)
@@ -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<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