aboutsummaryrefslogtreecommitdiff
path: root/rust/hw
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-10-25 08:23:53 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2024-11-05 14:18:16 +0100
commit718e255f0a97cf43939ae2e90ba4673ae9a8bd2f (patch)
treeab5d09e3b4cb9cae3e44fed6a8f77458f354c6c5 /rust/hw
parent9f7d4520d679364f7ca95b7ddb899ff084e7d7c6 (diff)
downloadqemu-718e255f0a97cf43939ae2e90ba4673ae9a8bd2f.zip
qemu-718e255f0a97cf43939ae2e90ba4673ae9a8bd2f.tar.gz
qemu-718e255f0a97cf43939ae2e90ba4673ae9a8bd2f.tar.bz2
rust: introduce a c_str macro
This allows CStr constants to be defined easily on Rust 1.63.0, while checking that there are no embedded NULs. c"" literals were only stabilized in Rust 1.77.0. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/hw')
-rw-r--r--rust/hw/char/pl011/src/device.rs5
-rw-r--r--rust/hw/char/pl011/src/device_class.rs18
-rw-r--r--rust/hw/char/pl011/src/lib.rs6
3 files changed, 15 insertions, 14 deletions
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 036757f..2d225d5 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -10,6 +10,7 @@ use std::{
use qemu_api::{
bindings::{self, *},
+ c_str,
definitions::ObjectImpl,
};
@@ -135,7 +136,7 @@ impl PL011State {
/// location/instance. All its fields are expected to hold unitialized
/// values with the sole exception of `parent_obj`.
unsafe fn init(&mut self) {
- const CLK_NAME: &CStr = c"clk";
+ const CLK_NAME: &CStr = c_str!("clk");
let dev = addr_of_mut!(*self).cast::<DeviceState>();
// SAFETY:
@@ -598,7 +599,7 @@ pub unsafe extern "C" fn pl011_create(
let dev: *mut DeviceState = qdev_new(PL011State::TYPE_INFO.name);
let sysbus: *mut SysBusDevice = dev.cast::<SysBusDevice>();
- qdev_prop_set_chr(dev, c"chardev".as_ptr(), chr);
+ qdev_prop_set_chr(dev, c_str!("chardev").as_ptr(), chr);
sysbus_realize_and_unref(sysbus, addr_of!(error_fatal) as *mut *mut Error);
sysbus_mmio_map(sysbus, 0, addr);
sysbus_connect_irq(sysbus, 0, irq);
diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs
index 6a554ad..a707fde 100644
--- a/rust/hw/char/pl011/src/device_class.rs
+++ b/rust/hw/char/pl011/src/device_class.rs
@@ -2,14 +2,12 @@
// Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
// SPDX-License-Identifier: GPL-2.0-or-later
-use core::{
- ffi::{c_int, c_void},
- ptr::NonNull,
-};
+use core::ptr::NonNull;
+use std::os::raw::{c_int, c_void};
use qemu_api::{
- bindings::*, vmstate_clock, vmstate_fields, vmstate_int32, vmstate_subsections, vmstate_uint32,
- vmstate_uint32_array, vmstate_unused, zeroable::Zeroable,
+ bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_int32, vmstate_subsections,
+ vmstate_uint32, vmstate_uint32_array, vmstate_unused, zeroable::Zeroable,
};
use crate::device::{PL011State, PL011_FIFO_DEPTH};
@@ -24,7 +22,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool {
/// Migration subsection for [`PL011State`] clock.
pub static VMSTATE_PL011_CLOCK: VMStateDescription = VMStateDescription {
- name: c"pl011/clock".as_ptr(),
+ name: c_str!("pl011/clock").as_ptr(),
version_id: 1,
minimum_version_id: 1,
needed: Some(pl011_clock_needed),
@@ -48,7 +46,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int {
}
pub static VMSTATE_PL011: VMStateDescription = VMStateDescription {
- name: c"pl011".as_ptr(),
+ name: c_str!("pl011").as_ptr(),
version_id: 2,
minimum_version_id: 2,
post_load: Some(pl011_post_load),
@@ -79,14 +77,14 @@ pub static VMSTATE_PL011: VMStateDescription = VMStateDescription {
qemu_api::declare_properties! {
PL011_PROPERTIES,
qemu_api::define_property!(
- c"chardev",
+ c_str!("chardev"),
PL011State,
char_backend,
unsafe { &qdev_prop_chr },
CharBackend
),
qemu_api::define_property!(
- c"migrate-clk",
+ c_str!("migrate-clk"),
PL011State,
migrate_clock,
unsafe { &qdev_prop_bool },
diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs
index 69e96d7..cd0a49a 100644
--- a/rust/hw/char/pl011/src/lib.rs
+++ b/rust/hw/char/pl011/src/lib.rs
@@ -42,12 +42,14 @@ extern crate bilge;
extern crate bilge_impl;
extern crate qemu_api;
+use qemu_api::c_str;
+
pub mod device;
pub mod device_class;
pub mod memory_ops;
-pub const TYPE_PL011: &::std::ffi::CStr = c"pl011";
-pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr = c"pl011_luminary";
+pub const TYPE_PL011: &::std::ffi::CStr = c_str!("pl011");
+pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr = c_str!("pl011_luminary");
/// Offset of each register from the base memory address of the device.
///