qemu-cr16/rust/qemu-api/src
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
..
assertions.rs rust: add module to convert between success/-errno and io::Result 2025-02-25 16:18:08 +01:00
bindings.rs rust: qemu_api: add a documentation header for all modules 2025-02-13 12:51:34 +01:00
bitops.rs rust: add a bit operation module 2024-12-10 18:49:26 +01:00
c_str.rs rust: qemu_api: add a documentation header for all modules 2025-02-13 12:51:34 +01:00
callbacks.rs rust: callbacks: allow passing optional callbacks as () 2025-02-13 12:19:33 +01:00
cell.rs rust: qemu_api_macros: add Wrapper derive macro 2025-03-06 12:44:46 +01:00
chardev.rs rust: chardev, qdev: add bindings to qdev_prop_set_chr 2025-02-13 12:19:34 +01:00
errno.rs rust: add module to convert between success/-errno and io::Result 2025-02-25 16:18:08 +01:00
irq.rs rust: prefer importing std::ptr over core::ptr 2025-02-25 16:18:11 +01:00
lib.rs rust: add module to convert between success/-errno and io::Result 2025-02-25 16:18:08 +01:00
memory.rs rust: add bindings for memattrs 2025-02-13 12:51:34 +01:00
module.rs rust: rename qemu-api modules to follow C code a bit more 2024-12-19 19:36:37 +01:00
offset_of.rs rust: qemu_api: add a documentation header for all modules 2025-02-13 12:51:34 +01:00
prelude.rs rust: add module to convert between success/-errno and io::Result 2025-02-25 16:18:08 +01:00
qdev.rs rust: qom: get rid of ClassInitImpl 2025-02-25 16:18:12 +01:00
qom.rs rust: qom: get rid of ClassInitImpl 2025-02-25 16:18:12 +01:00
sysbus.rs rust: qom: get rid of ClassInitImpl 2025-02-25 16:18:12 +01:00
timer.rs rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements 2025-03-06 12:44:46 +01:00
vmstate.rs rust: vmstate: add std::pin::Pin as transparent wrapper 2025-03-06 12:44:46 +01:00
zeroable.rs rust: fix doctests 2025-02-13 13:50:43 +01:00