qemu/rust/hw
Paolo Bonzini a32b239699 rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements
Timers must be pinned in memory, because modify() stores a pointer to them
in the TimerList.  To express this requirement, change init_full() to take
a pinned reference.  Because the only way to obtain a Timer is through
Timer::new(), which is unsafe, modify() can assume that the timer it got
was later initialized; and because the initialization takes a Pin<&mut
Timer> modify() can assume that the timer is pinned.  In the future the
pinning requirement will be expressed through the pin_init crate instead.

Note that Timer is a bit different from other users of Opaque, in that
it is created in Rust code rather than C code.  This is why it has to
use the unsafe constructors provided by Opaque; and in fact Timer::new()
is also unsafe, because it leaves it to the caller to invoke init_full()
before modify().  Without a call to init_full(), modify() will cause a
NULL pointer dereference.

An alternative could be to combine new() + init_full() by returning a
pinned box; however, using a reference makes it easier to express
the requirement that the opaque outlives the timer.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-06 12:44:46 +01:00
..
char rust: qom: get rid of ClassInitImpl 2025-02-25 16:18:12 +01:00
timer rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements 2025-03-06 12:44:46 +01:00
Kconfig i386: enable rust hpet for pc when rust is enabled 2025-02-13 12:51:34 +01:00
meson.build rust/timer/hpet: define hpet_fw_cfg 2025-02-13 12:51:34 +01:00