Use C string literals not cstr!
Since Rust 1.77.0 the language has supported C string literals, so the
`cstr!` macro is no longer needed. Replace existing usages with the
equivalent literal.
See https://doc.rust-lang.org/reference/tokens.html#c-string-literals.
I believe that the two are equivalent:
- Escapes are handled the same way;
- Both allow arbitrary Unicode, which is mapped to UTF-8 (I don't
think we made any use of this);
- Both treat any embedded NUL character as a compile time error.
This is of no significance whatsoever, but it does make the code a
tiny bit simpler. It should not change the compiled code at all, so
no flagging should be needed.
I'm not deleting the macro in this CL; I'll do a follow-up for that,
since there may be usages I can't see, and it has greater chance of
accidental conflict.
Test: TH
Change-Id: I4354b3b0a0c53fbec0c2d78b4182786e4e2d0ce8
diff --git a/android/virtmgr/Android.bp b/android/virtmgr/Android.bp
index ad63995..c2d67cf 100644
--- a/android/virtmgr/Android.bp
+++ b/android/virtmgr/Android.bp
@@ -38,7 +38,6 @@
"libcfg_if",
"libclap",
"libcrosvm_control_static",
- "libcstr",
"libcommand_fds",
"libdisk",
"libglob",
diff --git a/android/virtmgr/src/aidl.rs b/android/virtmgr/src/aidl.rs
index c71b5c5..5ad7ee1 100644
--- a/android/virtmgr/src/aidl.rs
+++ b/android/virtmgr/src/aidl.rs
@@ -68,7 +68,6 @@
self, wait_for_interface, Accessor, BinderFeatures, ConnectionInfo, ExceptionCode, Interface, ParcelFileDescriptor,
SpIBinder, Status, StatusCode, Strong, IntoBinderResult,
};
-use cstr::cstr;
use glob::glob;
use libc::{AF_VSOCK, sa_family_t, sockaddr_vm};
use log::{debug, error, info, warn};
@@ -976,7 +975,7 @@
"Passing vendor hashtree digest to pvmfw. This will be rejected if it doesn't \
match the trusted digest in the pvmfw config, causing the VM to fail to start."
);
- vec![(cstr!("vendor_hashtree_descriptor_root_digest"), vendor_hashtree_digest.as_slice())]
+ vec![(c"vendor_hashtree_descriptor_root_digest", vendor_hashtree_digest.as_slice())]
} else {
vec![]
};
@@ -984,18 +983,18 @@
let key_material;
let mut untrusted_props = Vec::with_capacity(2);
if cfg!(llpvm_changes) {
- untrusted_props.push((cstr!("instance-id"), &instance_id[..]));
+ untrusted_props.push((c"instance-id", &instance_id[..]));
let want_updatable = extract_want_updatable(config);
if want_updatable && is_secretkeeper_supported() {
// Let guest know that it can defer rollback protection to Secretkeeper by setting
// an empty property in untrusted node in DT. This enables Updatable VMs.
- untrusted_props.push((cstr!("defer-rollback-protection"), &[]));
+ untrusted_props.push((c"defer-rollback-protection", &[]));
let sk: Strong<dyn ISecretkeeper> =
binder::wait_for_interface(SECRETKEEPER_IDENTIFIER)?;
if sk.getInterfaceVersion()? >= 2 {
let PublicKey { keyMaterial } = sk.getSecretkeeperIdentity()?;
key_material = keyMaterial;
- trusted_props.push((cstr!("secretkeeper_public_key"), key_material.as_slice()));
+ trusted_props.push((c"secretkeeper_public_key", key_material.as_slice()));
}
}
}
diff --git a/android/virtmgr/src/dt_overlay.rs b/android/virtmgr/src/dt_overlay.rs
index 108ed61..fe2a419 100644
--- a/android/virtmgr/src/dt_overlay.rs
+++ b/android/virtmgr/src/dt_overlay.rs
@@ -15,14 +15,13 @@
//! This module support creating AFV related overlays, that can then be appended to DT by VM.
use anyhow::{anyhow, Result};
-use cstr::cstr;
use fsfdt::FsFdt;
use libfdt::Fdt;
use std::ffi::CStr;
use std::path::Path;
-pub(crate) const AVF_NODE_NAME: &CStr = cstr!("avf");
-pub(crate) const UNTRUSTED_NODE_NAME: &CStr = cstr!("untrusted");
+pub(crate) const AVF_NODE_NAME: &CStr = c"avf";
+pub(crate) const UNTRUSTED_NODE_NAME: &CStr = c"untrusted";
pub(crate) const VM_DT_OVERLAY_PATH: &str = "vm_dt_overlay.dtbo";
pub(crate) const VM_DT_OVERLAY_MAX_SIZE: usize = 2000;
@@ -63,13 +62,13 @@
Fdt::create_empty_tree(buffer).map_err(|e| anyhow!("Failed to create empty Fdt: {e:?}"))?;
let mut fragment = fdt
.root_mut()
- .add_subnode(cstr!("fragment@0"))
+ .add_subnode(c"fragment@0")
.map_err(|e| anyhow!("Failed to add fragment node: {e:?}"))?;
fragment
- .setprop(cstr!("target-path"), b"/\0")
+ .setprop(c"target-path", b"/\0")
.map_err(|e| anyhow!("Failed to set target-path property: {e:?}"))?;
let overlay = fragment
- .add_subnode(cstr!("__overlay__"))
+ .add_subnode(c"__overlay__")
.map_err(|e| anyhow!("Failed to add __overlay__ node: {e:?}"))?;
let avf =
overlay.add_subnode(AVF_NODE_NAME).map_err(|e| anyhow!("Failed to add avf node: {e:?}"))?;
@@ -87,12 +86,12 @@
// Read dt_path from host DT and overlay onto fdt.
if let Some(path) = dt_path {
- fdt.overlay_onto(cstr!("/fragment@0/__overlay__"), path)?;
+ fdt.overlay_onto(c"/fragment@0/__overlay__", path)?;
}
if !trusted_props.is_empty() {
let mut avf = fdt
- .node_mut(cstr!("/fragment@0/__overlay__/avf"))
+ .node_mut(c"/fragment@0/__overlay__/avf")
.map_err(|e| anyhow!("Failed to search avf node: {e:?}"))?
.ok_or(anyhow!("Failed to get avf node"))?;
for (name, value) in trusted_props {
@@ -120,14 +119,14 @@
#[test]
fn untrusted_prop_test() {
let mut buffer = vec![0_u8; VM_DT_OVERLAY_MAX_SIZE];
- let prop_name = cstr!("XOXO");
+ let prop_name = c"XOXO";
let prop_val_input = b"OXOX";
let fdt =
create_device_tree_overlay(&mut buffer, None, &[(prop_name, prop_val_input)], &[])
.unwrap();
let prop_value_dt = fdt
- .node(cstr!("/fragment@0/__overlay__/avf/untrusted"))
+ .node(c"/fragment@0/__overlay__/avf/untrusted")
.unwrap()
.expect("/avf/untrusted node doesn't exist")
.getprop(prop_name)
@@ -139,14 +138,14 @@
#[test]
fn trusted_prop_test() {
let mut buffer = vec![0_u8; VM_DT_OVERLAY_MAX_SIZE];
- let prop_name = cstr!("XOXOXO");
+ let prop_name = c"XOXOXO";
let prop_val_input = b"OXOXOX";
let fdt =
create_device_tree_overlay(&mut buffer, None, &[], &[(prop_name, prop_val_input)])
.unwrap();
let prop_value_dt = fdt
- .node(cstr!("/fragment@0/__overlay__/avf"))
+ .node(c"/fragment@0/__overlay__/avf")
.unwrap()
.expect("/avf node doesn't exist")
.getprop(prop_name)
diff --git a/guest/derive_microdroid_vendor_dice_node/Android.bp b/guest/derive_microdroid_vendor_dice_node/Android.bp
index 8b79aad..7a3ccbe 100644
--- a/guest/derive_microdroid_vendor_dice_node/Android.bp
+++ b/guest/derive_microdroid_vendor_dice_node/Android.bp
@@ -10,7 +10,6 @@
rustlibs: [
"libanyhow",
"libclap",
- "libcstr",
"libdice_driver",
"libdiced_open_dice",
"libdm_rust",
diff --git a/guest/derive_microdroid_vendor_dice_node/src/main.rs b/guest/derive_microdroid_vendor_dice_node/src/main.rs
index 0f0631e..4ec91ad 100644
--- a/guest/derive_microdroid_vendor_dice_node/src/main.rs
+++ b/guest/derive_microdroid_vendor_dice_node/src/main.rs
@@ -16,7 +16,6 @@
use anyhow::{bail, Context, Result};
use clap::Parser;
-use cstr::cstr;
use dice_driver::DiceDriver;
use diced_open_dice::{
hash, retry_bcc_format_config_descriptor, DiceConfigValues, OwnedDiceArtifacts, HIDDEN_SIZE,
@@ -50,7 +49,7 @@
// See dice_for_avf_guest.cddl for CDDL of Configuration Descriptor of VM components.
fn build_descriptor(vbmeta: &VbMetaImage) -> Result<Vec<u8>> {
let values = DiceConfigValues {
- component_name: Some(cstr!("Microdroid vendor")),
+ component_name: Some(c"Microdroid vendor"),
security_version: Some(vbmeta.rollback_index()),
..Default::default()
};
diff --git a/guest/pvmfw/Android.bp b/guest/pvmfw/Android.bp
index 793204d..da056d6 100644
--- a/guest/pvmfw/Android.bp
+++ b/guest/pvmfw/Android.bp
@@ -17,7 +17,6 @@
"libciborium_nostd",
"libciborium_io_nostd",
"libcoset_nostd",
- "libcstr",
"libdiced_open_dice_nostd",
"libhypervisor_backends",
"liblibfdt_nostd",
@@ -52,9 +51,6 @@
unit_test: true,
},
prefer_rlib: true,
- rustlibs: [
- "libcstr",
- ],
}
rust_test {
diff --git a/guest/pvmfw/src/bootargs.rs b/guest/pvmfw/src/bootargs.rs
index aacd8e0..0a5697f 100644
--- a/guest/pvmfw/src/bootargs.rs
+++ b/guest/pvmfw/src/bootargs.rs
@@ -108,7 +108,6 @@
#[cfg(test)]
mod tests {
use super::*;
- use cstr::cstr;
fn check(raw: &CStr, expected: Result<&[(&str, Option<&str>)], ()>) {
let actual = BootArgsIterator::new(raw);
@@ -136,35 +135,35 @@
#[test]
fn empty() {
- check(cstr!(""), Ok(&[]));
- check(cstr!(" "), Ok(&[]));
- check(cstr!(" \n "), Ok(&[]));
+ check(c"", Ok(&[]));
+ check(c" ", Ok(&[]));
+ check(c" \n ", Ok(&[]));
}
#[test]
fn single() {
- check(cstr!("foo"), Ok(&[("foo", None)]));
- check(cstr!(" foo"), Ok(&[("foo", None)]));
- check(cstr!("foo "), Ok(&[("foo", None)]));
- check(cstr!(" foo "), Ok(&[("foo", None)]));
+ check(c"foo", Ok(&[("foo", None)]));
+ check(c" foo", Ok(&[("foo", None)]));
+ check(c"foo ", Ok(&[("foo", None)]));
+ check(c" foo ", Ok(&[("foo", None)]));
}
#[test]
fn single_with_value() {
- check(cstr!("foo=bar"), Ok(&[("foo", Some("=bar"))]));
- check(cstr!(" foo=bar"), Ok(&[("foo", Some("=bar"))]));
- check(cstr!("foo=bar "), Ok(&[("foo", Some("=bar"))]));
- check(cstr!(" foo=bar "), Ok(&[("foo", Some("=bar"))]));
+ check(c"foo=bar", Ok(&[("foo", Some("=bar"))]));
+ check(c" foo=bar", Ok(&[("foo", Some("=bar"))]));
+ check(c"foo=bar ", Ok(&[("foo", Some("=bar"))]));
+ check(c" foo=bar ", Ok(&[("foo", Some("=bar"))]));
- check(cstr!("foo="), Ok(&[("foo", Some("="))]));
- check(cstr!(" foo="), Ok(&[("foo", Some("="))]));
- check(cstr!("foo= "), Ok(&[("foo", Some("="))]));
- check(cstr!(" foo= "), Ok(&[("foo", Some("="))]));
+ check(c"foo=", Ok(&[("foo", Some("="))]));
+ check(c" foo=", Ok(&[("foo", Some("="))]));
+ check(c"foo= ", Ok(&[("foo", Some("="))]));
+ check(c" foo= ", Ok(&[("foo", Some("="))]));
}
#[test]
fn single_with_quote() {
- check(cstr!("foo=hello\" \"world"), Ok(&[("foo", Some("=hello\" \"world"))]));
+ check(c"foo=hello\" \"world", Ok(&[("foo", Some("=hello\" \"world"))]));
}
#[test]
@@ -175,32 +174,32 @@
#[test]
fn multiple() {
check(
- cstr!(" a=b c=d e= f g "),
+ c" a=b c=d e= f g ",
Ok(&[("a", Some("=b")), ("c", Some("=d")), ("e", Some("=")), ("f", None), ("g", None)]),
);
check(
- cstr!(" a=b \n c=d e= f g"),
+ c" a=b \n c=d e= f g",
Ok(&[("a", Some("=b")), ("c", Some("=d")), ("e", Some("=")), ("f", None), ("g", None)]),
);
}
#[test]
fn incomplete_quote() {
- check(
- cstr!("foo=incomplete\" quote bar=y"),
- Ok(&[("foo", Some("=incomplete\" quote bar=y"))]),
- );
+ check(c"foo=incomplete\" quote bar=y", Ok(&[("foo", Some("=incomplete\" quote bar=y"))]));
}
#[test]
fn complex() {
- check(cstr!(" a a1= b=c d=e,f,g x=\"value with quote\" y=val\"ue with \"multiple\" quo\"te "), Ok(&[
- ("a", None),
- ("a1", Some("=")),
- ("b", Some("=c")),
- ("d", Some("=e,f,g")),
- ("x", Some("=\"value with quote\"")),
- ("y", Some("=val\"ue with \"multiple\" quo\"te")),
- ]));
+ check(
+ c" a a1= b=c d=e,f,g x=\"value with quote\" y=val\"ue with \"multiple\" quo\"te ",
+ Ok(&[
+ ("a", None),
+ ("a1", Some("=")),
+ ("b", Some("=c")),
+ ("d", Some("=e,f,g")),
+ ("x", Some("=\"value with quote\"")),
+ ("y", Some("=val\"ue with \"multiple\" quo\"te")),
+ ]),
+ );
}
}
diff --git a/guest/pvmfw/src/device_assignment.rs b/guest/pvmfw/src/device_assignment.rs
index f37f443..bb2e6ce 100644
--- a/guest/pvmfw/src/device_assignment.rs
+++ b/guest/pvmfw/src/device_assignment.rs
@@ -37,18 +37,6 @@
use zerocopy::byteorder::big_endian::U32;
use zerocopy::FromBytes as _;
-// TODO(b/308694211): Use cstr! from vmbase instead.
-macro_rules! cstr {
- ($str:literal) => {{
- const S: &str = concat!($str, "\0");
- const C: &::core::ffi::CStr = match ::core::ffi::CStr::from_bytes_with_nul(S.as_bytes()) {
- Ok(v) => v,
- Err(_) => panic!("string contains interior NUL"),
- };
- C
- }};
-}
-
// TODO(b/277993056): Keep constants derived from platform.dts in one place.
const CELLS_PER_INTERRUPT: usize = 3; // from /intc node in platform.dts
@@ -332,7 +320,7 @@
// };
// };
//
- // Then locate_overlay_target_path(cstr!("/fragment@rng/__overlay__/rng")) is Ok("/rng")
+ // Then locate_overlay_target_path(c"/fragment@rng/__overlay__/rng") is Ok("/rng")
//
// Contrary to fdt_overlay_target_offset(), this API enforces overlay target property
// 'target-path = "/"', so the overlay doesn't modify and/or append platform DT's existing
@@ -343,10 +331,9 @@
dtbo_node: &FdtNode,
) -> Result<CString> {
let fragment_node = dtbo_node.supernode_at_depth(1)?;
- let target_path = fragment_node
- .getprop_str(cstr!("target-path"))?
- .ok_or(DeviceAssignmentError::InvalidDtbo)?;
- if target_path != cstr!("/") {
+ let target_path =
+ fragment_node.getprop_str(c"target-path")?.ok_or(DeviceAssignmentError::InvalidDtbo)?;
+ if target_path != c"/" {
return Err(DeviceAssignmentError::UnsupportedOverlayTarget);
}
@@ -415,7 +402,7 @@
/// Parses Physical devices in VM DTBO
fn parse_physical_devices(&self) -> Result<BTreeMap<Phandle, PhysicalDeviceInfo>> {
- let Some(physical_node) = self.as_ref().node(cstr!("/host"))? else {
+ let Some(physical_node) = self.as_ref().node(c"/host")? else {
return Ok(BTreeMap::new());
};
@@ -459,7 +446,7 @@
let vm_dtbo = self.as_ref();
let mut phandle_map = BTreeMap::new();
- let Some(local_fixups) = vm_dtbo.node(cstr!("/__local_fixups__"))? else {
+ let Some(local_fixups) = vm_dtbo.node(c"/__local_fixups__")? else {
return Ok(phandle_map);
};
@@ -615,15 +602,14 @@
impl PvIommu {
fn parse(node: &FdtNode) -> Result<Self> {
- let iommu_cells = node
- .getprop_u32(cstr!("#iommu-cells"))?
- .ok_or(DeviceAssignmentError::InvalidPvIommu)?;
+ let iommu_cells =
+ node.getprop_u32(c"#iommu-cells")?.ok_or(DeviceAssignmentError::InvalidPvIommu)?;
// Ensures #iommu-cells = <1>. It means that `<iommus>` entry contains pair of
// (pvIOMMU ID, vSID)
if iommu_cells != 1 {
return Err(DeviceAssignmentError::InvalidPvIommu);
}
- let id = node.getprop_u32(cstr!("id"))?.ok_or(DeviceAssignmentError::InvalidPvIommu)?;
+ let id = node.getprop_u32(c"id")?.ok_or(DeviceAssignmentError::InvalidPvIommu)?;
Ok(Self { id })
}
}
@@ -687,10 +673,10 @@
impl PhysIommu {
fn parse(node: &FdtNode) -> Result<Option<Self>> {
- let Some(token) = node.getprop_u64(cstr!("android,pvmfw,token"))? else {
+ let Some(token) = node.getprop_u64(c"android,pvmfw,token")? else {
return Ok(None);
};
- let Some(iommu_cells) = node.getprop_u32(cstr!("#iommu-cells"))? else {
+ let Some(iommu_cells) = node.getprop_u32(c"#iommu-cells")? else {
return Err(DeviceAssignmentError::InvalidPhysIommu);
};
// Currently only supports #iommu-cells = <1>.
@@ -715,7 +701,7 @@
phys_iommus: &BTreeMap<Phandle, PhysIommu>,
) -> Result<Vec<(PhysIommu, Sid)>> {
let mut iommus = vec![];
- let Some(mut cells) = node.getprop_cells(cstr!("iommus"))? else {
+ let Some(mut cells) = node.getprop_cells(c"iommus")? else {
return Ok(iommus);
};
while let Some(cell) = cells.next() {
@@ -735,7 +721,7 @@
}
fn parse(node: &FdtNode, phys_iommus: &BTreeMap<Phandle, PhysIommu>) -> Result<Option<Self>> {
- let Some(phandle) = node.getprop_u32(cstr!("android,pvmfw,target"))? else {
+ let Some(phandle) = node.getprop_u32(c"android,pvmfw,target")? else {
return Ok(None);
};
let target = Phandle::try_from(phandle)?;
@@ -812,7 +798,7 @@
// Validation: Validate if interrupts cell numbers are multiple of #interrupt-cells.
// We can't know how many interrupts would exist.
let interrupts_cells = node
- .getprop_cells(cstr!("interrupts"))?
+ .getprop_cells(c"interrupts")?
.ok_or(DeviceAssignmentError::InvalidInterrupts)?
.count();
if interrupts_cells % CELLS_PER_INTERRUPT != 0 {
@@ -820,7 +806,7 @@
}
// Once validated, keep the raw bytes so patch can be done with setprop()
- Ok(node.getprop(cstr!("interrupts")).unwrap().unwrap().into())
+ Ok(node.getprop(c"interrupts").unwrap().unwrap().into())
}
// TODO(b/277993056): Also validate /__local_fixups__ to ensure that <iommus> has phandle.
@@ -829,7 +815,7 @@
pviommus: &BTreeMap<Phandle, PvIommu>,
) -> Result<Vec<(PvIommu, Vsid)>> {
let mut iommus = vec![];
- let Some(mut cells) = node.getprop_cells(cstr!("iommus"))? else {
+ let Some(mut cells) = node.getprop_cells(c"iommus")? else {
return Ok(iommus);
};
while let Some(cell) = cells.next() {
@@ -917,15 +903,15 @@
fn patch(&self, fdt: &mut Fdt, pviommu_phandles: &BTreeMap<PvIommu, Phandle>) -> Result<()> {
let mut dst = fdt.node_mut(&self.node_path)?.unwrap();
- dst.setprop(cstr!("reg"), &to_be_bytes(&self.reg))?;
- dst.setprop(cstr!("interrupts"), &self.interrupts)?;
+ dst.setprop(c"reg", &to_be_bytes(&self.reg))?;
+ dst.setprop(c"interrupts", &self.interrupts)?;
let mut iommus = Vec::with_capacity(8 * self.iommus.len());
for (pviommu, vsid) in &self.iommus {
let phandle = pviommu_phandles.get(pviommu).unwrap();
iommus.extend_from_slice(&u32::from(*phandle).to_be_bytes());
iommus.extend_from_slice(&vsid.0.to_be_bytes());
}
- dst.setprop(cstr!("iommus"), &iommus)?;
+ dst.setprop(c"iommus", &iommus)?;
Ok(())
}
@@ -939,7 +925,7 @@
}
impl DeviceAssignmentInfo {
- const PVIOMMU_COMPATIBLE: &'static CStr = cstr!("pkvm,pviommu");
+ const PVIOMMU_COMPATIBLE: &'static CStr = c"pkvm,pviommu";
/// Parses pvIOMMUs in fdt
// Note: This will validate pvIOMMU ids' uniqueness, even when unassigned.
@@ -1046,8 +1032,8 @@
Self::validate_pviommu_topology(&assigned_devices)?;
let mut vm_dtbo_mask = vm_dtbo.build_mask(assigned_device_paths)?;
- vm_dtbo_mask.mask_all(&DtPathTokens::new(cstr!("/__local_fixups__"))?);
- vm_dtbo_mask.mask_all(&DtPathTokens::new(cstr!("/__symbols__"))?);
+ vm_dtbo_mask.mask_all(&DtPathTokens::new(c"/__local_fixups__")?);
+ vm_dtbo_mask.mask_all(&DtPathTokens::new(c"/__symbols__")?);
// Note: Any node without __overlay__ will be ignored by fdt_apply_overlay,
// so doesn't need to be filtered.
@@ -1060,7 +1046,7 @@
let vm_dtbo = vm_dtbo.as_mut();
// Filter unused references in /__local_fixups__
- if let Some(local_fixups) = vm_dtbo.node_mut(cstr!("/__local_fixups__"))? {
+ if let Some(local_fixups) = vm_dtbo.node_mut(c"/__local_fixups__")? {
filter_with_mask(local_fixups, &self.vm_dtbo_mask)?;
}
@@ -1078,7 +1064,7 @@
for pviommu in &self.pviommus {
let mut node = compatible.ok_or(DeviceAssignmentError::TooManyPvIommu)?;
let phandle = node.as_node().get_phandle()?.ok_or(DeviceAssignmentError::Internal)?;
- node.setprop_inplace(cstr!("id"), &pviommu.id.to_be_bytes())?;
+ node.setprop_inplace(c"id", &pviommu.id.to_be_bytes())?;
if pviommu_phandles.insert(*pviommu, phandle).is_some() {
return Err(DeviceAssignmentError::Internal);
}
@@ -1108,10 +1094,10 @@
/// Cleans device trees not to contain any pre-populated nodes/props for device assignment.
pub fn clean(fdt: &mut Fdt) -> Result<()> {
- let mut compatible = fdt.root_mut().next_compatible(cstr!("pkvm,pviommu"))?;
+ let mut compatible = fdt.root_mut().next_compatible(c"pkvm,pviommu")?;
// Filters pre-populated
while let Some(filtered_pviommu) = compatible {
- compatible = filtered_pviommu.delete_and_next_compatible(cstr!("pkvm,pviommu"))?;
+ compatible = filtered_pviommu.delete_and_next_compatible(c"pkvm,pviommu")?;
}
// Removes any dangling references in __symbols__ (e.g. removed pvIOMMUs)
@@ -1239,24 +1225,23 @@
return Err(FdtError::NotFound.into());
};
- let reg = node.getprop(cstr!("reg"))?.ok_or(DeviceAssignmentError::MalformedReg)?;
- let interrupts = node
- .getprop(cstr!("interrupts"))?
- .ok_or(DeviceAssignmentError::InvalidInterrupts)?;
+ let reg = node.getprop(c"reg")?.ok_or(DeviceAssignmentError::MalformedReg)?;
+ let interrupts =
+ node.getprop(c"interrupts")?.ok_or(DeviceAssignmentError::InvalidInterrupts)?;
let mut iommus = vec![];
- if let Some(mut cells) = node.getprop_cells(cstr!("iommus"))? {
+ if let Some(mut cells) = node.getprop_cells(c"iommus")? {
while let Some(pviommu_id) = cells.next() {
// pvIOMMU id
let phandle = Phandle::try_from(pviommu_id)?;
let pviommu = fdt
.node_with_phandle(phandle)?
.ok_or(DeviceAssignmentError::MalformedIommus)?;
- let compatible = pviommu.getprop_str(cstr!("compatible"));
- if compatible != Ok(Some(cstr!("pkvm,pviommu"))) {
+ let compatible = pviommu.getprop_str(c"compatible");
+ if compatible != Ok(Some(c"pkvm,pviommu")) {
return Err(DeviceAssignmentError::MalformedIommus);
}
let id = pviommu
- .getprop_u32(cstr!("id"))?
+ .getprop_u32(c"id")?
.ok_or(DeviceAssignmentError::MalformedIommus)?;
iommus.push(id);
@@ -1273,8 +1258,8 @@
fn collect_pviommus(fdt: &Fdt) -> Result<Vec<u32>> {
let mut pviommus = BTreeSet::new();
- for pviommu in fdt.compatible_nodes(cstr!("pkvm,pviommu"))? {
- if let Ok(Some(id)) = pviommu.getprop_u32(cstr!("id")) {
+ for pviommu in fdt.compatible_nodes(c"pkvm,pviommu")? {
+ if let Ok(Some(id)) = pviommu.getprop_u32(c"id") {
pviommus.insert(id);
}
}
@@ -1395,24 +1380,24 @@
let symbols = vm_dtbo.symbols().unwrap().unwrap();
- let rng = vm_dtbo.node(cstr!("/fragment@0/__overlay__/rng")).unwrap();
+ let rng = vm_dtbo.node(c"/fragment@0/__overlay__/rng").unwrap();
assert_ne!(rng, None);
- let rng_symbol = symbols.getprop_str(cstr!("rng")).unwrap();
- assert_eq!(Some(cstr!("/fragment@0/__overlay__/rng")), rng_symbol);
+ let rng_symbol = symbols.getprop_str(c"rng").unwrap();
+ assert_eq!(Some(c"/fragment@0/__overlay__/rng"), rng_symbol);
- let light = vm_dtbo.node(cstr!("/fragment@0/__overlay__/light")).unwrap();
+ let light = vm_dtbo.node(c"/fragment@0/__overlay__/light").unwrap();
assert_eq!(light, None);
- let light_symbol = symbols.getprop_str(cstr!("light")).unwrap();
+ let light_symbol = symbols.getprop_str(c"light").unwrap();
assert_eq!(None, light_symbol);
- let led = vm_dtbo.node(cstr!("/fragment@0/__overlay__/led")).unwrap();
+ let led = vm_dtbo.node(c"/fragment@0/__overlay__/led").unwrap();
assert_eq!(led, None);
- let led_symbol = symbols.getprop_str(cstr!("led")).unwrap();
+ let led_symbol = symbols.getprop_str(c"led").unwrap();
assert_eq!(None, led_symbol);
- let backlight = vm_dtbo.node(cstr!("/fragment@0/__overlay__/bus0/backlight")).unwrap();
+ let backlight = vm_dtbo.node(c"/fragment@0/__overlay__/bus0/backlight").unwrap();
assert_eq!(backlight, None);
- let backlight_symbol = symbols.getprop_str(cstr!("backlight")).unwrap();
+ let backlight_symbol = symbols.getprop_str(c"backlight").unwrap();
assert_eq!(None, backlight_symbol);
}
@@ -1440,19 +1425,19 @@
}
device_info.patch(platform_dt).unwrap();
- let rng_node = platform_dt.node(cstr!("/bus0/backlight")).unwrap().unwrap();
- let phandle = rng_node.getprop_u32(cstr!("phandle")).unwrap();
+ let rng_node = platform_dt.node(c"/bus0/backlight").unwrap().unwrap();
+ let phandle = rng_node.getprop_u32(c"phandle").unwrap();
assert_ne!(None, phandle);
// Note: Intentionally not using AssignedDeviceNode for matching all props.
type FdtResult<T> = libfdt::Result<T>;
let expected: Vec<(FdtResult<&CStr>, FdtResult<Vec<u8>>)> = vec![
- (Ok(cstr!("android,backlight,ignore-gctrl-reset")), Ok(Vec::new())),
- (Ok(cstr!("compatible")), Ok(Vec::from(*b"android,backlight\0"))),
- (Ok(cstr!("interrupts")), Ok(into_fdt_prop(vec![0x0, 0xF, 0x4]))),
- (Ok(cstr!("iommus")), Ok(Vec::new())),
- (Ok(cstr!("phandle")), Ok(into_fdt_prop(vec![phandle.unwrap()]))),
- (Ok(cstr!("reg")), Ok(into_fdt_prop(vec![0x0, 0x9, 0x0, 0xFF]))),
+ (Ok(c"android,backlight,ignore-gctrl-reset"), Ok(Vec::new())),
+ (Ok(c"compatible"), Ok(Vec::from(*b"android,backlight\0"))),
+ (Ok(c"interrupts"), Ok(into_fdt_prop(vec![0x0, 0xF, 0x4]))),
+ (Ok(c"iommus"), Ok(Vec::new())),
+ (Ok(c"phandle"), Ok(into_fdt_prop(vec![phandle.unwrap()]))),
+ (Ok(c"reg"), Ok(into_fdt_prop(vec![0x0, 0x9, 0x0, 0xFF]))),
];
let mut properties: Vec<_> = rng_node
@@ -1493,7 +1478,7 @@
}
device_info.patch(platform_dt).unwrap();
- let compatible = platform_dt.root().next_compatible(cstr!("pkvm,pviommu")).unwrap();
+ let compatible = platform_dt.root().next_compatible(c"pkvm,pviommu").unwrap();
assert_eq!(None, compatible);
if let Some(symbols) = platform_dt.symbols().unwrap() {
@@ -1794,12 +1779,12 @@
let mut platform_dt_data = pvmfw_fdt_template::RAW.to_vec();
let platform_dt = Fdt::from_mut_slice(&mut platform_dt_data).unwrap();
- let compatible = platform_dt.root().next_compatible(cstr!("pkvm,pviommu"));
+ let compatible = platform_dt.root().next_compatible(c"pkvm,pviommu");
assert_ne!(None, compatible.unwrap());
clean(platform_dt).unwrap();
- let compatible = platform_dt.root().next_compatible(cstr!("pkvm,pviommu"));
+ let compatible = platform_dt.root().next_compatible(c"pkvm,pviommu");
assert_eq!(Ok(None), compatible);
}
diff --git a/guest/pvmfw/src/fdt.rs b/guest/pvmfw/src/fdt.rs
index 4370675..29212f9 100644
--- a/guest/pvmfw/src/fdt.rs
+++ b/guest/pvmfw/src/fdt.rs
@@ -28,7 +28,6 @@
use core::fmt;
use core::mem::size_of;
use core::ops::Range;
-use cstr::cstr;
use hypervisor_backends::get_device_assigner;
use hypervisor_backends::get_mem_sharer;
use libfdt::AddressRange;
@@ -83,10 +82,10 @@
/// Extract from /config the address range containing the pre-loaded kernel. Absence of /config is
/// not an error.
pub fn read_kernel_range_from(fdt: &Fdt) -> libfdt::Result<Option<Range<usize>>> {
- let addr = cstr!("kernel-address");
- let size = cstr!("kernel-size");
+ let addr = c"kernel-address";
+ let size = c"kernel-size";
- if let Some(config) = fdt.node(cstr!("/config"))? {
+ if let Some(config) = fdt.node(c"/config")? {
if let (Some(addr), Some(size)) = (config.getprop_u32(addr)?, config.getprop_u32(size)?) {
let addr = addr as usize;
let size = size as usize;
@@ -101,8 +100,8 @@
/// Extract from /chosen the address range containing the pre-loaded ramdisk. Absence is not an
/// error as there can be initrd-less VM.
pub fn read_initrd_range_from(fdt: &Fdt) -> libfdt::Result<Option<Range<usize>>> {
- let start = cstr!("linux,initrd-start");
- let end = cstr!("linux,initrd-end");
+ let start = c"linux,initrd-start";
+ let end = c"linux,initrd-end";
if let Some(chosen) = fdt.chosen()? {
if let (Some(start), Some(end)) = (chosen.getprop_u32(start)?, chosen.getprop_u32(end)?) {
@@ -118,14 +117,14 @@
let end = u32::try_from(initrd_range.end).unwrap();
let mut node = fdt.chosen_mut()?.ok_or(FdtError::NotFound)?;
- node.setprop(cstr!("linux,initrd-start"), &start.to_be_bytes())?;
- node.setprop(cstr!("linux,initrd-end"), &end.to_be_bytes())?;
+ node.setprop(c"linux,initrd-start", &start.to_be_bytes())?;
+ node.setprop(c"linux,initrd-end", &end.to_be_bytes())?;
Ok(())
}
fn read_bootargs_from(fdt: &Fdt) -> libfdt::Result<Option<CString>> {
if let Some(chosen) = fdt.chosen()? {
- if let Some(bootargs) = chosen.getprop_str(cstr!("bootargs"))? {
+ if let Some(bootargs) = chosen.getprop_str(c"bootargs")? {
// We need to copy the string to heap because the original fdt will be invalidated
// by the templated DT
let copy = CString::new(bootargs.to_bytes()).map_err(|_| FdtError::BadValue)?;
@@ -140,7 +139,7 @@
// This function is called before the verification is done. So, we just copy the bootargs to
// the new FDT unmodified. This will be filtered again in the modify_for_next_stage function
// if the VM is not debuggable.
- node.setprop(cstr!("bootargs"), bootargs.to_bytes_with_nul())
+ node.setprop(c"bootargs", bootargs.to_bytes_with_nul())
}
/// Reads and validates the memory range in the DT.
@@ -186,9 +185,9 @@
fn patch_memory_range(fdt: &mut Fdt, memory_range: &Range<usize>) -> libfdt::Result<()> {
let addr = u64::try_from(MEM_START).unwrap();
let size = u64::try_from(memory_range.len()).unwrap();
- fdt.node_mut(cstr!("/memory"))?
+ fdt.node_mut(c"/memory")?
.ok_or(FdtError::NotFound)?
- .setprop_inplace(cstr!("reg"), [addr.to_be(), size.to_be()].as_bytes())
+ .setprop_inplace(c"reg", [addr.to_be(), size.to_be()].as_bytes())
}
#[derive(Debug, Default)]
@@ -207,7 +206,7 @@
let mut table = ArrayVec::new();
let mut opp_nodes = opp_node.subnodes()?;
for subnode in opp_nodes.by_ref().take(table.capacity()) {
- let prop = subnode.getprop_u64(cstr!("opp-hz"))?.ok_or(FdtError::NotFound)?;
+ let prop = subnode.getprop_u64(c"opp-hz")?.ok_or(FdtError::NotFound)?;
table.push(prop);
}
@@ -239,7 +238,7 @@
}
fn read_cpu_map_from(fdt: &Fdt) -> libfdt::Result<Option<BTreeMap<Phandle, (usize, usize)>>> {
- let Some(cpu_map) = fdt.node(cstr!("/cpus/cpu-map"))? else {
+ let Some(cpu_map) = fdt.node(c"/cpus/cpu-map")? else {
return Ok(None);
};
@@ -254,7 +253,7 @@
let Some(core) = cluster.subnode(&name)? else {
break;
};
- let cpu = core.getprop_u32(cstr!("cpu"))?.ok_or(FdtError::NotFound)?;
+ let cpu = core.getprop_u32(c"cpu")?.ok_or(FdtError::NotFound)?;
let prev = topology.insert(cpu.try_into()?, (n, m));
if prev.is_some() {
return Err(FdtError::BadValue);
@@ -273,10 +272,10 @@
let cpu_map = read_cpu_map_from(fdt)?;
let mut topology: CpuTopology = Default::default();
- let mut cpu_nodes = fdt.compatible_nodes(cstr!("arm,armv8"))?;
+ let mut cpu_nodes = fdt.compatible_nodes(c"arm,armv8")?;
for (idx, cpu) in cpu_nodes.by_ref().take(cpus.capacity()).enumerate() {
- let cpu_capacity = cpu.getprop_u32(cstr!("capacity-dmips-mhz"))?;
- let opp_phandle = cpu.getprop_u32(cstr!("operating-points-v2"))?;
+ let cpu_capacity = cpu.getprop_u32(c"capacity-dmips-mhz")?;
+ let opp_phandle = cpu.getprop_u32(c"operating-points-v2")?;
let opptable_info = if let Some(phandle) = opp_phandle {
let phandle = phandle.try_into()?;
let node = fdt.node_with_phandle(phandle)?.ok_or(FdtError::NotFound)?;
@@ -313,7 +312,7 @@
}
fn read_vcpufreq_info(fdt: &Fdt) -> libfdt::Result<Option<VcpufreqInfo>> {
- let mut nodes = fdt.compatible_nodes(cstr!("virtual,android-v-only-cpufreq"))?;
+ let mut nodes = fdt.compatible_nodes(c"virtual,android-v-only-cpufreq")?;
let Some(node) = nodes.next() else {
return Ok(None);
};
@@ -351,7 +350,7 @@
node: FdtNodeMut,
opptable: Option<ArrayVec<[u64; CpuInfo::MAX_OPPTABLES]>>,
) -> libfdt::Result<()> {
- let oppcompat = cstr!("operating-points-v2");
+ let oppcompat = c"operating-points-v2";
let next = node.next_compatible(oppcompat)?.ok_or(FdtError::NoSpace)?;
let Some(opptable) = opptable else {
@@ -362,7 +361,7 @@
for entry in opptable {
let mut subnode = next_subnode.ok_or(FdtError::NoSpace)?;
- subnode.setprop_inplace(cstr!("opp-hz"), &entry.to_be_bytes())?;
+ subnode.setprop_inplace(c"opp-hz", &entry.to_be_bytes())?;
next_subnode = subnode.next_subnode()?;
}
@@ -391,14 +390,14 @@
cpus: &[CpuInfo],
topology: &Option<CpuTopology>,
) -> libfdt::Result<()> {
- const COMPAT: &CStr = cstr!("arm,armv8");
+ const COMPAT: &CStr = c"arm,armv8";
let mut cpu_phandles = Vec::new();
for (idx, cpu) in cpus.iter().enumerate() {
let mut cur = get_nth_compatible(fdt, idx, COMPAT)?.ok_or(FdtError::NoSpace)?;
let phandle = cur.as_node().get_phandle()?.unwrap();
cpu_phandles.push(phandle);
if let Some(cpu_capacity) = cpu.cpu_capacity {
- cur.setprop_inplace(cstr!("capacity-dmips-mhz"), &cpu_capacity.to_be_bytes())?;
+ cur.setprop_inplace(c"capacity-dmips-mhz", &cpu_capacity.to_be_bytes())?;
}
patch_opptable(cur, cpu.opptable_info)?;
}
@@ -418,7 +417,7 @@
iter = if let Some(core_idx) = core {
let phandle = *cpu_phandles.get(core_idx).unwrap();
let value = u32::from(phandle).to_be_bytes();
- core_node.setprop_inplace(cstr!("cpu"), &value)?;
+ core_node.setprop_inplace(c"cpu", &value)?;
core_node.next_subnode()?
} else {
core_node.delete_and_next_subnode()?
@@ -430,7 +429,7 @@
}
}
} else {
- fdt.node_mut(cstr!("/cpus/cpu-map"))?.unwrap().nop()?;
+ fdt.node_mut(c"/cpus/cpu-map")?.unwrap().nop()?;
}
Ok(())
@@ -440,7 +439,7 @@
/// the guest that don't require being validated by pvmfw.
fn parse_untrusted_props(fdt: &Fdt) -> libfdt::Result<BTreeMap<CString, Vec<u8>>> {
let mut props = BTreeMap::new();
- if let Some(node) = fdt.node(cstr!("/avf/untrusted"))? {
+ if let Some(node) = fdt.node(c"/avf/untrusted")? {
for property in node.properties()? {
let name = property.name()?;
let value = property.value()?;
@@ -457,7 +456,7 @@
/// Read candidate properties' names from DT which could be overlaid
fn parse_vm_ref_dt(fdt: &Fdt) -> libfdt::Result<BTreeMap<CString, Vec<u8>>> {
let mut property_map = BTreeMap::new();
- if let Some(avf_node) = fdt.node(cstr!("/avf"))? {
+ if let Some(avf_node) = fdt.node(c"/avf")? {
for property in avf_node.properties()? {
let name = property.name()?;
let value = property.value()?;
@@ -471,8 +470,7 @@
}
fn validate_untrusted_props(props: &BTreeMap<CString, Vec<u8>>) -> Result<(), FdtValidationError> {
- const FORBIDDEN_PROPS: &[&CStr] =
- &[cstr!("compatible"), cstr!("linux,phandle"), cstr!("phandle")];
+ const FORBIDDEN_PROPS: &[&CStr] = &[c"compatible", c"linux,phandle", c"phandle"];
for name in FORBIDDEN_PROPS {
if props.contains_key(*name) {
@@ -491,9 +489,9 @@
props_info: &BTreeMap<CString, Vec<u8>>,
) -> libfdt::Result<()> {
let root_vm_dt = vm_dt.root_mut();
- let mut avf_vm_dt = root_vm_dt.add_subnode(cstr!("avf"))?;
+ let mut avf_vm_dt = root_vm_dt.add_subnode(c"avf")?;
// TODO(b/318431677): Validate nodes beyond /avf.
- let avf_node = vm_ref_dt.node(cstr!("/avf"))?.ok_or(FdtError::NotFound)?;
+ let avf_node = vm_ref_dt.node(c"/avf")?.ok_or(FdtError::NotFound)?;
for (name, value) in props_info.iter() {
if let Some(ref_value) = avf_node.getprop(name)? {
if value != ref_value {
@@ -551,14 +549,13 @@
/// Read pci host controller ranges, irq maps, and irq map masks from DT
fn read_pci_info_from(fdt: &Fdt) -> libfdt::Result<PciInfo> {
- let node =
- fdt.compatible_nodes(cstr!("pci-host-cam-generic"))?.next().ok_or(FdtError::NotFound)?;
+ let node = fdt.compatible_nodes(c"pci-host-cam-generic")?.next().ok_or(FdtError::NotFound)?;
let mut ranges = node.ranges::<(u32, u64), u64, u64>()?.ok_or(FdtError::NotFound)?;
let range0 = ranges.next().ok_or(FdtError::NotFound)?;
let range1 = ranges.next().ok_or(FdtError::NotFound)?;
- let irq_masks = node.getprop_cells(cstr!("interrupt-map-mask"))?.ok_or(FdtError::NotFound)?;
+ let irq_masks = node.getprop_cells(c"interrupt-map-mask")?.ok_or(FdtError::NotFound)?;
let mut chunks = CellChunkIterator::<{ PciInfo::IRQ_MASK_CELLS }>::new(irq_masks);
let irq_masks = (&mut chunks).take(PciInfo::MAX_IRQS).collect();
@@ -567,7 +564,7 @@
return Err(FdtError::NoSpace);
}
- let irq_maps = node.getprop_cells(cstr!("interrupt-map"))?.ok_or(FdtError::NotFound)?;
+ let irq_maps = node.getprop_cells(c"interrupt-map")?.ok_or(FdtError::NotFound)?;
let mut chunks = CellChunkIterator::<{ PciInfo::IRQ_MAP_CELLS }>::new(irq_maps);
let irq_maps = (&mut chunks).take(PciInfo::MAX_IRQS).collect();
@@ -721,16 +718,16 @@
fn patch_pci_info(fdt: &mut Fdt, pci_info: &PciInfo) -> libfdt::Result<()> {
let mut node =
- fdt.root_mut().next_compatible(cstr!("pci-host-cam-generic"))?.ok_or(FdtError::NotFound)?;
+ fdt.root_mut().next_compatible(c"pci-host-cam-generic")?.ok_or(FdtError::NotFound)?;
let irq_masks_size = pci_info.irq_masks.len() * size_of::<PciIrqMask>();
- node.trimprop(cstr!("interrupt-map-mask"), irq_masks_size)?;
+ node.trimprop(c"interrupt-map-mask", irq_masks_size)?;
let irq_maps_size = pci_info.irq_maps.len() * size_of::<PciIrqMap>();
- node.trimprop(cstr!("interrupt-map"), irq_maps_size)?;
+ node.trimprop(c"interrupt-map", irq_maps_size)?;
node.setprop_inplace(
- cstr!("ranges"),
+ c"ranges",
[pci_info.ranges[0].to_cells(), pci_info.ranges[1].to_cells()].as_flattened(),
)
}
@@ -747,7 +744,7 @@
fn read_serial_info_from(fdt: &Fdt) -> libfdt::Result<SerialInfo> {
let mut addrs = ArrayVec::new();
- let mut serial_nodes = fdt.compatible_nodes(cstr!("ns16550a"))?;
+ let mut serial_nodes = fdt.compatible_nodes(c"ns16550a")?;
for node in serial_nodes.by_ref().take(addrs.capacity()) {
let reg = node.first_reg()?;
addrs.push(reg.addr);
@@ -793,7 +790,7 @@
}
fn read_wdt_info_from(fdt: &Fdt) -> libfdt::Result<WdtInfo> {
- let mut node_iter = fdt.compatible_nodes(cstr!("qemu,vcpu-stall-detector"))?;
+ let mut node_iter = fdt.compatible_nodes(c"qemu,vcpu-stall-detector")?;
let node = node_iter.next().ok_or(FdtError::NotFound)?;
let mut ranges = node.reg()?.ok_or(FdtError::NotFound)?;
@@ -803,7 +800,7 @@
warn!("Discarding extra vmwdt <reg> entries.");
}
- let interrupts = node.getprop_cells(cstr!("interrupts"))?.ok_or(FdtError::NotFound)?;
+ let interrupts = node.getprop_cells(c"interrupts")?.ok_or(FdtError::NotFound)?;
let mut chunks = CellChunkIterator::<{ WdtInfo::IRQ_CELLS }>::new(interrupts);
let irq = chunks.next().ok_or(FdtError::NotFound)?;
@@ -831,15 +828,15 @@
let mut node = fdt
.root_mut()
- .next_compatible(cstr!("qemu,vcpu-stall-detector"))?
+ .next_compatible(c"qemu,vcpu-stall-detector")?
.ok_or(libfdt::FdtError::NotFound)?;
- node.setprop_inplace(cstr!("interrupts"), interrupts.as_bytes())?;
+ node.setprop_inplace(c"interrupts", interrupts.as_bytes())?;
Ok(())
}
/// Patch the DT by deleting the ns16550a compatible nodes whose address are unknown
fn patch_serial_info(fdt: &mut Fdt, serial_info: &SerialInfo) -> libfdt::Result<()> {
- let name = cstr!("ns16550a");
+ let name = c"ns16550a";
let mut next = fdt.root_mut().next_compatible(name);
while let Some(current) = next? {
let reg =
@@ -889,27 +886,27 @@
fn patch_swiotlb_info(fdt: &mut Fdt, swiotlb_info: &SwiotlbInfo) -> libfdt::Result<()> {
let mut node =
- fdt.root_mut().next_compatible(cstr!("restricted-dma-pool"))?.ok_or(FdtError::NotFound)?;
+ fdt.root_mut().next_compatible(c"restricted-dma-pool")?.ok_or(FdtError::NotFound)?;
if let Some(range) = swiotlb_info.fixed_range() {
node.setprop_addrrange_inplace(
- cstr!("reg"),
+ c"reg",
range.start.try_into().unwrap(),
range.len().try_into().unwrap(),
)?;
- node.nop_property(cstr!("size"))?;
- node.nop_property(cstr!("alignment"))?;
+ node.nop_property(c"size")?;
+ node.nop_property(c"alignment")?;
} else {
- node.nop_property(cstr!("reg"))?;
- node.setprop_inplace(cstr!("size"), &swiotlb_info.size.to_be_bytes())?;
- node.setprop_inplace(cstr!("alignment"), &swiotlb_info.align.unwrap().to_be_bytes())?;
+ node.nop_property(c"reg")?;
+ node.setprop_inplace(c"size", &swiotlb_info.size.to_be_bytes())?;
+ node.setprop_inplace(c"alignment", &swiotlb_info.align.unwrap().to_be_bytes())?;
}
Ok(())
}
fn patch_gic(fdt: &mut Fdt, num_cpus: usize) -> libfdt::Result<()> {
- let node = fdt.compatible_nodes(cstr!("arm,gic-v3"))?.next().ok_or(FdtError::NotFound)?;
+ let node = fdt.compatible_nodes(c"arm,gic-v3")?.next().ok_or(FdtError::NotFound)?;
let mut ranges = node.reg()?.ok_or(FdtError::NotFound)?;
let range0 = ranges.next().ok_or(FdtError::NotFound)?;
let mut range1 = ranges.next().ok_or(FdtError::NotFound)?;
@@ -927,16 +924,15 @@
let (addr1, size1) = range1.to_cells();
let value = [addr0, size0.unwrap(), addr1, size1.unwrap()];
- let mut node =
- fdt.root_mut().next_compatible(cstr!("arm,gic-v3"))?.ok_or(FdtError::NotFound)?;
- node.setprop_inplace(cstr!("reg"), value.as_flattened())
+ let mut node = fdt.root_mut().next_compatible(c"arm,gic-v3")?.ok_or(FdtError::NotFound)?;
+ node.setprop_inplace(c"reg", value.as_flattened())
}
fn patch_timer(fdt: &mut Fdt, num_cpus: usize) -> libfdt::Result<()> {
const NUM_INTERRUPTS: usize = 4;
const CELLS_PER_INTERRUPT: usize = 3;
- let node = fdt.compatible_nodes(cstr!("arm,armv8-timer"))?.next().ok_or(FdtError::NotFound)?;
- let interrupts = node.getprop_cells(cstr!("interrupts"))?.ok_or(FdtError::NotFound)?;
+ let node = fdt.compatible_nodes(c"arm,armv8-timer")?.next().ok_or(FdtError::NotFound)?;
+ let interrupts = node.getprop_cells(c"interrupts")?.ok_or(FdtError::NotFound)?;
let mut value: ArrayVec<[u32; NUM_INTERRUPTS * CELLS_PER_INTERRUPT]> =
interrupts.take(NUM_INTERRUPTS * CELLS_PER_INTERRUPT).collect();
@@ -953,20 +949,19 @@
let value = value.into_inner();
- let mut node =
- fdt.root_mut().next_compatible(cstr!("arm,armv8-timer"))?.ok_or(FdtError::NotFound)?;
- node.setprop_inplace(cstr!("interrupts"), value.as_bytes())
+ let mut node = fdt.root_mut().next_compatible(c"arm,armv8-timer")?.ok_or(FdtError::NotFound)?;
+ node.setprop_inplace(c"interrupts", value.as_bytes())
}
fn patch_untrusted_props(fdt: &mut Fdt, props: &BTreeMap<CString, Vec<u8>>) -> libfdt::Result<()> {
- let avf_node = if let Some(node) = fdt.node_mut(cstr!("/avf"))? {
+ let avf_node = if let Some(node) = fdt.node_mut(c"/avf")? {
node
} else {
- fdt.root_mut().add_subnode(cstr!("avf"))?
+ fdt.root_mut().add_subnode(c"avf")?
};
// The node shouldn't already be present; if it is, return the error.
- let mut node = avf_node.add_subnode(cstr!("untrusted"))?;
+ let mut node = avf_node.add_subnode(c"untrusted")?;
for (name, value) in props {
node.setprop(name, value)?;
@@ -982,9 +977,9 @@
}
fn patch_vcpufreq(fdt: &mut Fdt, vcpufreq_info: &Option<VcpufreqInfo>) -> libfdt::Result<()> {
- let mut node = fdt.node_mut(cstr!("/cpufreq"))?.unwrap();
+ let mut node = fdt.node_mut(c"/cpufreq")?.unwrap();
if let Some(info) = vcpufreq_info {
- node.setprop_addrrange_inplace(cstr!("reg"), info.addr, info.size)
+ node.setprop_addrrange_inplace(c"reg", info.addr, info.size)
} else {
node.nop()
}
@@ -1304,9 +1299,9 @@
patch_dice_node(fdt, bcc.as_ptr() as usize, bcc.len())?;
if let Some(mut chosen) = fdt.chosen_mut()? {
- empty_or_delete_prop(&mut chosen, cstr!("avf,strict-boot"), strict_boot)?;
- empty_or_delete_prop(&mut chosen, cstr!("avf,new-instance"), new_instance)?;
- chosen.setprop_inplace(cstr!("kaslr-seed"), &kaslr_seed.to_be_bytes())?;
+ empty_or_delete_prop(&mut chosen, c"avf,strict-boot", strict_boot)?;
+ empty_or_delete_prop(&mut chosen, c"avf,new-instance", new_instance)?;
+ chosen.setprop_inplace(c"kaslr-seed", &kaslr_seed.to_be_bytes())?;
};
if !debuggable {
if let Some(bootargs) = read_bootargs_from(fdt)? {
@@ -1323,13 +1318,13 @@
fn patch_dice_node(fdt: &mut Fdt, addr: usize, size: usize) -> libfdt::Result<()> {
// We reject DTs with missing reserved-memory node as validation should have checked that the
// "swiotlb" subnode (compatible = "restricted-dma-pool") was present.
- let node = fdt.node_mut(cstr!("/reserved-memory"))?.ok_or(libfdt::FdtError::NotFound)?;
+ let node = fdt.node_mut(c"/reserved-memory")?.ok_or(libfdt::FdtError::NotFound)?;
- let mut node = node.next_compatible(cstr!("google,open-dice"))?.ok_or(FdtError::NotFound)?;
+ let mut node = node.next_compatible(c"google,open-dice")?.ok_or(FdtError::NotFound)?;
let addr: u64 = addr.try_into().unwrap();
let size: u64 = size.try_into().unwrap();
- node.setprop_inplace(cstr!("reg"), [addr.to_be_bytes(), size.to_be_bytes()].as_flattened())
+ node.setprop_inplace(c"reg", [addr.to_be_bytes(), size.to_be_bytes()].as_flattened())
}
fn empty_or_delete_prop(
@@ -1376,7 +1371,7 @@
}
fn has_common_debug_policy(fdt: &Fdt, debug_feature_name: &CStr) -> libfdt::Result<bool> {
- if let Some(node) = fdt.node(cstr!("/avf/guest/common"))? {
+ if let Some(node) = fdt.node(c"/avf/guest/common")? {
if let Some(value) = node.getprop_u32(debug_feature_name)? {
return Ok(value == 1);
}
@@ -1385,8 +1380,8 @@
}
fn filter_out_dangerous_bootargs(fdt: &mut Fdt, bootargs: &CStr) -> libfdt::Result<()> {
- let has_crashkernel = has_common_debug_policy(fdt, cstr!("ramdump"))?;
- let has_console = has_common_debug_policy(fdt, cstr!("log"))?;
+ let has_crashkernel = has_common_debug_policy(fdt, c"ramdump")?;
+ let has_console = has_common_debug_policy(fdt, c"log")?;
let accepted: &[(&str, Box<dyn Fn(Option<&str>) -> bool>)] = &[
("panic", Box::new(|v| if let Some(v) = v { v == "=-1" } else { false })),
@@ -1417,5 +1412,5 @@
new_bootargs.push(b'\0');
let mut node = fdt.chosen_mut()?.ok_or(FdtError::NotFound)?;
- node.setprop(cstr!("bootargs"), new_bootargs.as_slice())
+ node.setprop(c"bootargs", new_bootargs.as_slice())
}
diff --git a/guest/pvmfw/src/main.rs b/guest/pvmfw/src/main.rs
index a28a039..5ff9c4c 100644
--- a/guest/pvmfw/src/main.rs
+++ b/guest/pvmfw/src/main.rs
@@ -40,7 +40,6 @@
use alloc::borrow::Cow;
use alloc::boxed::Box;
use bssl_avf::Digester;
-use cstr::cstr;
use diced_open_dice::{bcc_handover_parse, DiceArtifacts, DiceContext, Hidden, VM_KEY_ALGORITHM};
use libfdt::{Fdt, FdtNode};
use log::{debug, error, info, trace, warn};
@@ -220,7 +219,7 @@
fn instance_id(fdt: &Fdt) -> Result<&[u8], RebootReason> {
let node = avf_untrusted_node(fdt)?;
- let id = node.getprop(cstr!("instance-id")).map_err(|e| {
+ let id = node.getprop(c"instance-id").map_err(|e| {
error!("Failed to get instance-id in DT: {e}");
RebootReason::InvalidFdt
})?;
@@ -231,7 +230,7 @@
}
fn avf_untrusted_node(fdt: &Fdt) -> Result<FdtNode, RebootReason> {
- let node = fdt.node(cstr!("/avf/untrusted")).map_err(|e| {
+ let node = fdt.node(c"/avf/untrusted").map_err(|e| {
error!("Failed to get /avf/untrusted node: {e}");
RebootReason::InvalidFdt
})?;
diff --git a/guest/pvmfw/src/rollback.rs b/guest/pvmfw/src/rollback.rs
index bc16332..15d22b3 100644
--- a/guest/pvmfw/src/rollback.rs
+++ b/guest/pvmfw/src/rollback.rs
@@ -19,7 +19,6 @@
use crate::instance::EntryBody;
use crate::instance::Error as InstanceError;
use crate::instance::{get_recorded_entry, record_instance_entry};
-use cstr::cstr;
use diced_open_dice::Hidden;
use libfdt::{Fdt, FdtNode};
use log::{error, info};
@@ -138,7 +137,7 @@
fn should_defer_rollback_protection(fdt: &Fdt) -> Result<bool, RebootReason> {
let node = avf_untrusted_node(fdt)?;
let defer_rbp = node
- .getprop(cstr!("defer-rollback-protection"))
+ .getprop(c"defer-rollback-protection")
.map_err(|e| {
error!("Failed to get defer-rollback-protection property in DT: {e}");
RebootReason::InvalidFdt
@@ -148,7 +147,7 @@
}
fn avf_untrusted_node(fdt: &Fdt) -> Result<FdtNode, RebootReason> {
- let node = fdt.node(cstr!("/avf/untrusted")).map_err(|e| {
+ let node = fdt.node(c"/avf/untrusted").map_err(|e| {
error!("Failed to get /avf/untrusted node: {e}");
RebootReason::InvalidFdt
})?;
diff --git a/guest/rialto/Android.bp b/guest/rialto/Android.bp
index a525168..35ede7a 100644
--- a/guest/rialto/Android.bp
+++ b/guest/rialto/Android.bp
@@ -12,7 +12,6 @@
"libbssl_avf_nostd",
"libciborium_io_nostd",
"libciborium_nostd",
- "libcstr",
"libdiced_open_dice_nostd",
"libhypervisor_backends",
"liblibfdt_nostd",
diff --git a/guest/rialto/src/fdt.rs b/guest/rialto/src/fdt.rs
index e97a262..06879d0 100644
--- a/guest/rialto/src/fdt.rs
+++ b/guest/rialto/src/fdt.rs
@@ -15,24 +15,23 @@
//! High-level FDT functions.
use core::ops::Range;
-use cstr::cstr;
use libfdt::{Fdt, FdtError};
/// Reads the DICE data range from the given `fdt`.
pub fn read_dice_range_from(fdt: &Fdt) -> libfdt::Result<Range<usize>> {
- let node = fdt.node(cstr!("/reserved-memory"))?.ok_or(FdtError::NotFound)?;
- let node = node.next_compatible(cstr!("google,open-dice"))?.ok_or(FdtError::NotFound)?;
+ let node = fdt.node(c"/reserved-memory")?.ok_or(FdtError::NotFound)?;
+ let node = node.next_compatible(c"google,open-dice")?.ok_or(FdtError::NotFound)?;
node.first_reg()?.try_into()
}
pub(crate) fn read_vendor_hashtree_root_digest(fdt: &Fdt) -> libfdt::Result<Option<&[u8]>> {
- let node = fdt.node(cstr!("/avf"))?.ok_or(FdtError::NotFound)?;
- node.getprop(cstr!("vendor_hashtree_descriptor_root_digest"))
+ let node = fdt.node(c"/avf")?.ok_or(FdtError::NotFound)?;
+ node.getprop(c"vendor_hashtree_descriptor_root_digest")
}
pub(crate) fn read_is_strict_boot(fdt: &Fdt) -> libfdt::Result<bool> {
match fdt.chosen()? {
- Some(node) => Ok(node.getprop(cstr!("avf,strict-boot"))?.is_some()),
+ Some(node) => Ok(node.getprop(c"avf,strict-boot")?.is_some()),
None => Ok(false),
}
}
diff --git a/guest/vmbase_example/Android.bp b/guest/vmbase_example/Android.bp
index 09bd77c..ab21191 100644
--- a/guest/vmbase_example/Android.bp
+++ b/guest/vmbase_example/Android.bp
@@ -9,7 +9,6 @@
srcs: ["src/main.rs"],
rustlibs: [
"libaarch64_paging",
- "libcstr",
"libdiced_open_dice_nostd",
"liblibfdt_nostd",
"liblog_rust_nostd",
diff --git a/guest/vmbase_example/src/main.rs b/guest/vmbase_example/src/main.rs
index 4c5e880..f5b41bd 100644
--- a/guest/vmbase_example/src/main.rs
+++ b/guest/vmbase_example/src/main.rs
@@ -27,7 +27,6 @@
use crate::pci::check_pci;
use alloc::{vec, vec::Vec};
use core::ptr::addr_of_mut;
-use cstr::cstr;
use libfdt::Fdt;
use log::{debug, error, info, trace, warn, LevelFilter};
use vmbase::{
@@ -147,7 +146,7 @@
info!("memory @ {reg:#x?}");
}
- let compatible = cstr!("ns16550a");
+ let compatible = c"ns16550a";
for c in reader.compatible_nodes(compatible).unwrap() {
let reg = c.reg().unwrap().unwrap().next().unwrap();
@@ -159,17 +158,17 @@
writer.unpack().unwrap();
info!("FDT successfully unpacked.");
- let path = cstr!("/memory");
+ let path = c"/memory";
let node = writer.node_mut(path).unwrap().unwrap();
- let name = cstr!("child");
+ let name = c"child";
let mut child = node.add_subnode(name).unwrap();
info!("Created subnode '{}/{}'.", path.to_str().unwrap(), name.to_str().unwrap());
- let name = cstr!("str-property");
+ let name = c"str-property";
child.appendprop(name, b"property-value\0").unwrap();
info!("Appended property '{}'.", name.to_str().unwrap());
- let name = cstr!("pair-property");
+ let name = c"pair-property";
let addr = 0x0123_4567u64;
let size = 0x89ab_cdefu64;
child.appendprop_addrrange(name, addr, size).unwrap();
diff --git a/libs/libfdt/Android.bp b/libs/libfdt/Android.bp
index 09f288d..829b30f 100644
--- a/libs/libfdt/Android.bp
+++ b/libs/libfdt/Android.bp
@@ -35,7 +35,6 @@
],
edition: "2021",
rustlibs: [
- "libcstr",
"liblibfdt_bindgen",
"libstatic_assertions",
"libzerocopy_nostd",
@@ -79,7 +78,6 @@
],
prefer_rlib: true,
rustlibs: [
- "libcstr",
"liblibfdt",
],
}
diff --git a/libs/libfdt/src/lib.rs b/libs/libfdt/src/lib.rs
index c969749..0dcd31a 100644
--- a/libs/libfdt/src/lib.rs
+++ b/libs/libfdt/src/lib.rs
@@ -31,7 +31,6 @@
use core::ffi::{c_void, CStr};
use core::ops::Range;
-use cstr::cstr;
use libfdt::get_slice_at_ptr;
use zerocopy::IntoBytes as _;
@@ -167,12 +166,12 @@
/// Returns the standard (deprecated) device_type <string> property.
pub fn device_type(&self) -> Result<Option<&CStr>> {
- self.getprop_str(cstr!("device_type"))
+ self.getprop_str(c"device_type")
}
/// Returns the standard reg <prop-encoded-array> property.
pub fn reg(&self) -> Result<Option<RegIterator<'a>>> {
- if let Some(cells) = self.getprop_cells(cstr!("reg"))? {
+ if let Some(cells) = self.getprop_cells(c"reg")? {
let parent = self.parent()?;
let addr_cells = parent.address_cells()?;
@@ -186,7 +185,7 @@
/// Returns the standard ranges property.
pub fn ranges<A, P, S>(&self) -> Result<Option<RangesIterator<'a, A, P, S>>> {
- if let Some(cells) = self.getprop_cells(cstr!("ranges"))? {
+ if let Some(cells) = self.getprop_cells(c"ranges")? {
let parent = self.parent()?;
let addr_cells = self.address_cells()?;
let parent_addr_cells = parent.address_cells()?;
@@ -320,9 +319,9 @@
/// Returns the phandle
pub fn get_phandle(&self) -> Result<Option<Phandle>> {
// This rewrites the fdt_get_phandle() because it doesn't return error code.
- if let Some(prop) = self.getprop_u32(cstr!("phandle"))? {
+ if let Some(prop) = self.getprop_u32(c"phandle")? {
Ok(Some(prop.try_into()?))
- } else if let Some(prop) = self.getprop_u32(cstr!("linux,phandle"))? {
+ } else if let Some(prop) = self.getprop_u32(c"linux,phandle")? {
Ok(Some(prop.try_into()?))
} else {
Ok(None)
@@ -693,8 +692,8 @@
///
/// NOTE: This does not support individual "/memory@XXXX" banks.
pub fn memory(&self) -> Result<MemRegIterator> {
- let node = self.root().subnode(cstr!("memory"))?.ok_or(FdtError::NotFound)?;
- if node.device_type()? != Some(cstr!("memory")) {
+ let node = self.root().subnode(c"memory")?.ok_or(FdtError::NotFound)?;
+ if node.device_type()? != Some(c"memory") {
return Err(FdtError::BadValue);
}
node.reg()?.ok_or(FdtError::BadValue).map(MemRegIterator::new)
@@ -707,12 +706,12 @@
/// Returns the standard /chosen node.
pub fn chosen(&self) -> Result<Option<FdtNode>> {
- self.root().subnode(cstr!("chosen"))
+ self.root().subnode(c"chosen")
}
/// Returns the standard /chosen node as mutable.
pub fn chosen_mut(&mut self) -> Result<Option<FdtNodeMut>> {
- self.node_mut(cstr!("/chosen"))
+ self.node_mut(c"/chosen")
}
/// Returns the root node of the tree.
@@ -722,12 +721,12 @@
/// Returns the standard /__symbols__ node.
pub fn symbols(&self) -> Result<Option<FdtNode>> {
- self.root().subnode(cstr!("__symbols__"))
+ self.root().subnode(c"__symbols__")
}
/// Returns the standard /__symbols__ node as mutable
pub fn symbols_mut(&mut self) -> Result<Option<FdtNodeMut>> {
- self.node_mut(cstr!("/__symbols__"))
+ self.node_mut(c"/__symbols__")
}
/// Returns a tree node by its full path.
diff --git a/libs/libfdt/tests/api_test.rs b/libs/libfdt/tests/api_test.rs
index f521a00..e027164 100644
--- a/libs/libfdt/tests/api_test.rs
+++ b/libs/libfdt/tests/api_test.rs
@@ -17,7 +17,6 @@
//! Integration tests of the library libfdt.
use core::ffi::CStr;
-use cstr::cstr;
use libfdt::{Fdt, FdtError, FdtNodeMut, Phandle};
use std::collections::HashSet;
use std::ffi::CString;
@@ -82,14 +81,14 @@
let fdt = Fdt::from_slice(&data).unwrap();
let root = fdt.root();
- assert_eq!(root.name(), Ok(cstr!("")));
+ assert_eq!(root.name(), Ok(c""));
let chosen = fdt.chosen().unwrap().unwrap();
- assert_eq!(chosen.name(), Ok(cstr!("chosen")));
+ assert_eq!(chosen.name(), Ok(c"chosen"));
- let nested_node_path = cstr!("/cpus/PowerPC,970@0");
+ let nested_node_path = c"/cpus/PowerPC,970@0";
let nested_node = fdt.node(nested_node_path).unwrap().unwrap();
- assert_eq!(nested_node.name(), Ok(cstr!("PowerPC,970@0")));
+ assert_eq!(nested_node.name(), Ok(c"PowerPC,970@0"));
}
#[test]
@@ -97,7 +96,7 @@
let data = fs::read(TEST_TREE_WITH_NO_MEMORY_NODE_PATH).unwrap();
let fdt = Fdt::from_slice(&data).unwrap();
let root = fdt.root();
- let expected = [Ok(cstr!("cpus")), Ok(cstr!("randomnode")), Ok(cstr!("chosen"))];
+ let expected = [Ok(c"cpus"), Ok(c"randomnode"), Ok(c"chosen")];
let root_subnodes = root.subnodes().unwrap();
let subnode_names: Vec<_> = root_subnodes.map(|node| node.name()).collect();
@@ -112,11 +111,11 @@
let one_be = 0x1_u32.to_be_bytes();
type Result<T> = core::result::Result<T, FdtError>;
let expected: Vec<(Result<&CStr>, Result<&[u8]>)> = vec![
- (Ok(cstr!("model")), Ok(b"MyBoardName\0".as_ref())),
- (Ok(cstr!("compatible")), Ok(b"MyBoardName\0MyBoardFamilyName\0".as_ref())),
- (Ok(cstr!("#address-cells")), Ok(&one_be)),
- (Ok(cstr!("#size-cells")), Ok(&one_be)),
- (Ok(cstr!("empty_prop")), Ok(&[])),
+ (Ok(c"model"), Ok(b"MyBoardName\0".as_ref())),
+ (Ok(c"compatible"), Ok(b"MyBoardName\0MyBoardFamilyName\0".as_ref())),
+ (Ok(c"#address-cells"), Ok(&one_be)),
+ (Ok(c"#size-cells"), Ok(&one_be)),
+ (Ok(c"empty_prop"), Ok(&[])),
];
let properties = root.properties().unwrap();
@@ -129,8 +128,8 @@
fn node_supernode_at_depth() {
let data = fs::read(TEST_TREE_WITH_NO_MEMORY_NODE_PATH).unwrap();
let fdt = Fdt::from_slice(&data).unwrap();
- let node = fdt.node(cstr!("/cpus/PowerPC,970@1")).unwrap().unwrap();
- let expected = vec![Ok(cstr!("")), Ok(cstr!("cpus")), Ok(cstr!("PowerPC,970@1"))];
+ let node = fdt.node(c"/cpus/PowerPC,970@1").unwrap().unwrap();
+ let expected = vec![Ok(c""), Ok(c"cpus"), Ok(c"PowerPC,970@1")];
let mut supernode_names = vec![];
let mut depth = 0;
@@ -187,12 +186,12 @@
// Test linux,phandle
let phandle = Phandle::new(0xFF).unwrap();
let node = fdt.node_with_phandle(phandle).unwrap().unwrap();
- assert_eq!(node.name(), Ok(cstr!("node_zz")));
+ assert_eq!(node.name(), Ok(c"node_zz"));
// Test phandle
let phandle = Phandle::new(0x22).unwrap();
let node = fdt.node_with_phandle(phandle).unwrap().unwrap();
- assert_eq!(node.name(), Ok(cstr!("node_abc")));
+ assert_eq!(node.name(), Ok(c"node_abc"));
}
#[test]
@@ -203,12 +202,12 @@
// Test linux,phandle
let phandle = Phandle::new(0xFF).unwrap();
let node: FdtNodeMut = fdt.node_mut_with_phandle(phandle).unwrap().unwrap();
- assert_eq!(node.as_node().name(), Ok(cstr!("node_zz")));
+ assert_eq!(node.as_node().name(), Ok(c"node_zz"));
// Test phandle
let phandle = Phandle::new(0x22).unwrap();
let node: FdtNodeMut = fdt.node_mut_with_phandle(phandle).unwrap().unwrap();
- assert_eq!(node.as_node().name(), Ok(cstr!("node_abc")));
+ assert_eq!(node.as_node().name(), Ok(c"node_abc"));
}
#[test]
@@ -217,15 +216,15 @@
let fdt = Fdt::from_slice(&data).unwrap();
// Test linux,phandle
- let node = fdt.node(cstr!("/node_z/node_zz")).unwrap().unwrap();
+ let node = fdt.node(c"/node_z/node_zz").unwrap().unwrap();
assert_eq!(node.get_phandle(), Ok(Phandle::new(0xFF)));
// Test phandle
- let node = fdt.node(cstr!("/node_a/node_ab/node_abc")).unwrap().unwrap();
+ let node = fdt.node(c"/node_a/node_ab/node_abc").unwrap().unwrap();
assert_eq!(node.get_phandle(), Ok(Phandle::new(0x22)));
// Test no phandle
- let node = fdt.node(cstr!("/node_b")).unwrap().unwrap();
+ let node = fdt.node(c"/node_b").unwrap().unwrap();
assert_eq!(node.get_phandle(), Ok(None));
}
@@ -234,7 +233,7 @@
let mut data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();
let fdt = Fdt::from_mut_slice(&mut data).unwrap();
let phandle = Phandle::new(0xFF).unwrap();
- let path = cstr!("/node_z/node_zz");
+ let path = c"/node_z/node_zz";
fdt.node_with_phandle(phandle).unwrap().unwrap();
let node = fdt.node_mut(path).unwrap().unwrap();
@@ -259,8 +258,8 @@
let fdt = Fdt::from_mut_slice(&mut data).unwrap();
fdt.unpack().unwrap();
- let node_path = cstr!("/node_z/node_zz");
- let subnode_name = cstr!("123456789");
+ let node_path = c"/node_z/node_zz";
+ let subnode_name = c"123456789";
for len in 0..subnode_name.to_bytes().len() {
let name = &subnode_name.to_bytes()[0..len];
@@ -289,7 +288,7 @@
let data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();
let fdt = Fdt::from_slice(&data).unwrap();
- let name = cstr!("node_a");
+ let name = c"node_a";
let root = fdt.root();
let node = root.subnode(name).unwrap();
assert_ne!(None, node);
@@ -309,7 +308,7 @@
assert_ne!(None, node);
let node = node.unwrap();
- assert_eq!(Ok(cstr!("node_a")), node.name());
+ assert_eq!(Ok(c"node_a"), node.name());
}
#[test]
@@ -317,7 +316,7 @@
let data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();
let fdt = Fdt::from_slice(&data).unwrap();
- let name = cstr!("node_a");
+ let name = c"node_a";
let node = {
let root = fdt.root();
root.subnode(name).unwrap().unwrap()
@@ -332,7 +331,7 @@
let fdt = Fdt::from_mut_slice(&mut data).unwrap();
let symbols = fdt.symbols().unwrap().unwrap();
- assert_eq!(symbols.name(), Ok(cstr!("__symbols__")));
+ assert_eq!(symbols.name(), Ok(c"__symbols__"));
// Validates type.
let _symbols: FdtNodeMut = fdt.symbols_mut().unwrap().unwrap();
@@ -343,14 +342,14 @@
let mut data = fs::read(TEST_TREE_WITH_ONE_MEMORY_RANGE_PATH).unwrap();
let fdt = Fdt::from_mut_slice(&mut data).unwrap();
- let mut memory = fdt.node_mut(cstr!("/memory")).unwrap().unwrap();
+ let mut memory = fdt.node_mut(c"/memory").unwrap().unwrap();
{
let memory = memory.as_node();
- assert_eq!(memory.name(), Ok(cstr!("memory")));
+ assert_eq!(memory.name(), Ok(c"memory"));
}
// Just check whether borrow checker doesn't complain this.
- memory.setprop_inplace(cstr!("device_type"), b"MEMORY\0").unwrap();
+ memory.setprop_inplace(c"device_type", b"MEMORY\0").unwrap();
}
#[test]
@@ -358,18 +357,13 @@
let mut data = fs::read(TEST_TREE_PHANDLE_PATH).unwrap();
let fdt = Fdt::from_mut_slice(&mut data).unwrap();
- let node_z = fdt.node(cstr!("/node_z")).unwrap().unwrap();
+ let node_z = fdt.node(c"/node_z").unwrap().unwrap();
let descendants: Vec<_> =
node_z.descendants().map(|(node, depth)| (node.name().unwrap(), depth)).collect();
assert_eq!(
descendants,
- vec![
- (cstr!("node_za"), 1),
- (cstr!("node_zb"), 1),
- (cstr!("node_zz"), 1),
- (cstr!("node_zzz"), 2)
- ]
+ vec![(c"node_za", 1), (c"node_zb", 1), (c"node_zz", 1), (c"node_zzz", 2)]
);
}
@@ -382,7 +376,7 @@
let mut subnode_iter = root.first_subnode().unwrap();
while let Some(subnode) = subnode_iter {
- if subnode.as_node().name() == Ok(cstr!("node_z")) {
+ if subnode.as_node().name() == Ok(c"node_z") {
subnode_iter = subnode.delete_and_next_subnode().unwrap();
} else {
subnode_iter = subnode.next_subnode().unwrap();
@@ -390,12 +384,7 @@
}
let root = fdt.root();
- let expected_names = vec![
- Ok(cstr!("node_a")),
- Ok(cstr!("node_b")),
- Ok(cstr!("node_c")),
- Ok(cstr!("__symbols__")),
- ];
+ let expected_names = vec![Ok(c"node_a"), Ok(c"node_b"), Ok(c"node_c"), Ok(c"__symbols__")];
let subnode_names: Vec<_> = root.subnodes().unwrap().map(|node| node.name()).collect();
assert_eq!(expected_names, subnode_names);
@@ -407,19 +396,19 @@
let fdt = Fdt::from_mut_slice(&mut data).unwrap();
let expected_nodes = vec![
- (Ok(cstr!("node_b")), 1),
- (Ok(cstr!("node_c")), 1),
- (Ok(cstr!("node_z")), 1),
- (Ok(cstr!("node_za")), 2),
- (Ok(cstr!("node_zb")), 2),
- (Ok(cstr!("__symbols__")), 1),
+ (Ok(c"node_b"), 1),
+ (Ok(c"node_c"), 1),
+ (Ok(c"node_z"), 1),
+ (Ok(c"node_za"), 2),
+ (Ok(c"node_zb"), 2),
+ (Ok(c"__symbols__"), 1),
];
let mut expected_nodes_iter = expected_nodes.iter();
let mut iter = fdt.root_mut().next_node(0).unwrap();
while let Some((node, depth)) = iter {
let node_name = node.as_node().name();
- if node_name == Ok(cstr!("node_a")) || node_name == Ok(cstr!("node_zz")) {
+ if node_name == Ok(c"node_a") || node_name == Ok(c"node_zz") {
iter = node.delete_and_next_node(depth).unwrap();
} else {
// Note: Checking name here is easier than collecting names and assert_eq!(),
@@ -464,7 +453,7 @@
root.name()
// Make root to be dropped
};
- assert_eq!(Ok(cstr!("")), name);
+ assert_eq!(Ok(c""), name);
}
#[test]
@@ -473,7 +462,7 @@
let fdt = Fdt::create_empty_tree(&mut data).unwrap();
let root = fdt.root_mut();
- let names = [cstr!("a"), cstr!("b")];
+ let names = [c"a", c"b"];
root.add_subnodes(&names).unwrap();
let expected: HashSet<_> = names.into_iter().collect();
@@ -492,14 +481,14 @@
let name = {
let node_a = {
let root = fdt.root();
- root.subnode(cstr!("node_a")).unwrap()
+ root.subnode(c"node_a").unwrap()
// Make root to be dropped
};
assert_ne!(None, node_a);
node_a.unwrap().name()
// Make node_a to be dropped
};
- assert_eq!(Ok(cstr!("node_a")), name);
+ assert_eq!(Ok(c"node_a"), name);
}
#[test]
@@ -521,7 +510,7 @@
first_subnode.name()
// Make first_subnode to be dropped
};
- assert_eq!(Ok(cstr!("node_a")), first_subnode_name);
+ assert_eq!(Ok(c"node_a"), first_subnode_name);
}
#[test]
@@ -543,5 +532,5 @@
first_descendant.name()
// Make first_descendant to be dropped
};
- assert_eq!(Ok(cstr!("node_a")), first_descendant_name);
+ assert_eq!(Ok(c"node_a"), first_descendant_name);
}
diff --git a/libs/libservice_vm_fake_chain/Android.bp b/libs/libservice_vm_fake_chain/Android.bp
index 56fb22a..65eddf8 100644
--- a/libs/libservice_vm_fake_chain/Android.bp
+++ b/libs/libservice_vm_fake_chain/Android.bp
@@ -26,9 +26,6 @@
"//packages/modules/Virtualization/guest/rialto:__subpackages__",
],
prefer_rlib: true,
- rustlibs: [
- "libcstr",
- ],
}
rust_library {
diff --git a/libs/libservice_vm_fake_chain/src/client_vm.rs b/libs/libservice_vm_fake_chain/src/client_vm.rs
index dc499e0..fa72739 100644
--- a/libs/libservice_vm_fake_chain/src/client_vm.rs
+++ b/libs/libservice_vm_fake_chain/src/client_vm.rs
@@ -22,7 +22,6 @@
use ciborium::{cbor, value::Value};
use core::result;
use coset::CborSerializable;
-use cstr::cstr;
use diced_open_dice::{
hash, retry_bcc_format_config_descriptor, retry_bcc_main_flow, Config, DiceArtifacts,
DiceConfigValues, DiceError, DiceMode, InputValues, OwnedDiceArtifacts, Result, HASH_SIZE,
@@ -96,7 +95,7 @@
// Adds an entry describing the Microdroid kernel.
let config_values = DiceConfigValues {
- component_name: Some(cstr!("vm_entry")),
+ component_name: Some(c"vm_entry"),
component_version: Some(12),
resettable: true,
security_version: Some(13),
diff --git a/libs/libservice_vm_fake_chain/src/service_vm.rs b/libs/libservice_vm_fake_chain/src/service_vm.rs
index 04297e4..5064ff8 100644
--- a/libs/libservice_vm_fake_chain/src/service_vm.rs
+++ b/libs/libservice_vm_fake_chain/src/service_vm.rs
@@ -24,7 +24,6 @@
iana::{self, EnumI64},
Algorithm, AsCborValue, CborSerializable, CoseKey, KeyOperation, KeyType, Label,
};
-use cstr::cstr;
use diced_open_dice::{
derive_cdi_private_key_seed, keypair_from_seed, retry_bcc_format_config_descriptor,
retry_bcc_main_flow, retry_dice_main_flow, CdiValues, Config, DiceConfigValues, DiceError,
@@ -113,7 +112,7 @@
// Gets the pvmfw certificate to as the root certificate of DICE chain.
let config_values = DiceConfigValues {
- component_name: Some(cstr!("Protected VM firmware")),
+ component_name: Some(c"Protected VM firmware"),
component_version: Some(1),
resettable: true,
rkp_vm_marker: true,
@@ -156,7 +155,7 @@
pub fn fake_service_vm_dice_artifacts() -> Result<OwnedDiceArtifacts> {
let (cdi_values, dice_chain) = fake_dice_artifacts_up_to_pvmfw()?;
let config_values = DiceConfigValues {
- component_name: Some(cstr!("vm_entry")),
+ component_name: Some(c"vm_entry"),
component_version: Some(12),
resettable: true,
rkp_vm_marker: true,
diff --git a/libs/libvmbase/Android.bp b/libs/libvmbase/Android.bp
index 3088633..de347c7 100644
--- a/libs/libvmbase/Android.bp
+++ b/libs/libvmbase/Android.bp
@@ -80,7 +80,6 @@
"libaarch64_paging",
"libbuddy_system_allocator",
"libcfg_if",
- "libcstr",
"libhypervisor_backends",
"liblibfdt_nostd",
"liblog_rust_nostd",
diff --git a/libs/libvmbase/src/bionic.rs b/libs/libvmbase/src/bionic.rs
index 3c0cd6f..37b6e45 100644
--- a/libs/libvmbase/src/bionic.rs
+++ b/libs/libvmbase/src/bionic.rs
@@ -24,7 +24,6 @@
use core::slice;
use core::str;
-use cstr::cstr;
use log::error;
use log::info;
@@ -230,138 +229,138 @@
fn cstr_error(n: c_int) -> &'static CStr {
// Messages taken from errno(1).
match n {
- 0 => cstr!("Success"),
- 1 => cstr!("Operation not permitted"),
- 2 => cstr!("No such file or directory"),
- 3 => cstr!("No such process"),
- 4 => cstr!("Interrupted system call"),
- 5 => cstr!("Input/output error"),
- 6 => cstr!("No such device or address"),
- 7 => cstr!("Argument list too long"),
- 8 => cstr!("Exec format error"),
- 9 => cstr!("Bad file descriptor"),
- 10 => cstr!("No child processes"),
- 11 => cstr!("Resource temporarily unavailable"),
- 12 => cstr!("Cannot allocate memory"),
- 13 => cstr!("Permission denied"),
- 14 => cstr!("Bad address"),
- 15 => cstr!("Block device required"),
- 16 => cstr!("Device or resource busy"),
- 17 => cstr!("File exists"),
- 18 => cstr!("Invalid cross-device link"),
- 19 => cstr!("No such device"),
- 20 => cstr!("Not a directory"),
- 21 => cstr!("Is a directory"),
- 22 => cstr!("Invalid argument"),
- 23 => cstr!("Too many open files in system"),
- 24 => cstr!("Too many open files"),
- 25 => cstr!("Inappropriate ioctl for device"),
- 26 => cstr!("Text file busy"),
- 27 => cstr!("File too large"),
- 28 => cstr!("No space left on device"),
- 29 => cstr!("Illegal seek"),
- 30 => cstr!("Read-only file system"),
- 31 => cstr!("Too many links"),
- 32 => cstr!("Broken pipe"),
- 33 => cstr!("Numerical argument out of domain"),
- 34 => cstr!("Numerical result out of range"),
- 35 => cstr!("Resource deadlock avoided"),
- 36 => cstr!("File name too long"),
- 37 => cstr!("No locks available"),
- 38 => cstr!("Function not implemented"),
- 39 => cstr!("Directory not empty"),
- 40 => cstr!("Too many levels of symbolic links"),
- 42 => cstr!("No message of desired type"),
- 43 => cstr!("Identifier removed"),
- 44 => cstr!("Channel number out of range"),
- 45 => cstr!("Level 2 not synchronized"),
- 46 => cstr!("Level 3 halted"),
- 47 => cstr!("Level 3 reset"),
- 48 => cstr!("Link number out of range"),
- 49 => cstr!("Protocol driver not attached"),
- 50 => cstr!("No CSI structure available"),
- 51 => cstr!("Level 2 halted"),
- 52 => cstr!("Invalid exchange"),
- 53 => cstr!("Invalid request descriptor"),
- 54 => cstr!("Exchange full"),
- 55 => cstr!("No anode"),
- 56 => cstr!("Invalid request code"),
- 57 => cstr!("Invalid slot"),
- 59 => cstr!("Bad font file format"),
- 60 => cstr!("Device not a stream"),
- 61 => cstr!("No data available"),
- 62 => cstr!("Timer expired"),
- 63 => cstr!("Out of streams resources"),
- 64 => cstr!("Machine is not on the network"),
- 65 => cstr!("Package not installed"),
- 66 => cstr!("Object is remote"),
- 67 => cstr!("Link has been severed"),
- 68 => cstr!("Advertise error"),
- 69 => cstr!("Srmount error"),
- 70 => cstr!("Communication error on send"),
- 71 => cstr!("Protocol error"),
- 72 => cstr!("Multihop attempted"),
- 73 => cstr!("RFS specific error"),
- 74 => cstr!("Bad message"),
- 75 => cstr!("Value too large for defined data type"),
- 76 => cstr!("Name not unique on network"),
- 77 => cstr!("File descriptor in bad state"),
- 78 => cstr!("Remote address changed"),
- 79 => cstr!("Can not access a needed shared library"),
- 80 => cstr!("Accessing a corrupted shared library"),
- 81 => cstr!(".lib section in a.out corrupted"),
- 82 => cstr!("Attempting to link in too many shared libraries"),
- 83 => cstr!("Cannot exec a shared library directly"),
- 84 => cstr!("Invalid or incomplete multibyte or wide character"),
- 85 => cstr!("Interrupted system call should be restarted"),
- 86 => cstr!("Streams pipe error"),
- 87 => cstr!("Too many users"),
- 88 => cstr!("Socket operation on non-socket"),
- 89 => cstr!("Destination address required"),
- 90 => cstr!("Message too long"),
- 91 => cstr!("Protocol wrong type for socket"),
- 92 => cstr!("Protocol not available"),
- 93 => cstr!("Protocol not supported"),
- 94 => cstr!("Socket type not supported"),
- 95 => cstr!("Operation not supported"),
- 96 => cstr!("Protocol family not supported"),
- 97 => cstr!("Address family not supported by protocol"),
- 98 => cstr!("Address already in use"),
- 99 => cstr!("Cannot assign requested address"),
- 100 => cstr!("Network is down"),
- 101 => cstr!("Network is unreachable"),
- 102 => cstr!("Network dropped connection on reset"),
- 103 => cstr!("Software caused connection abort"),
- 104 => cstr!("Connection reset by peer"),
- 105 => cstr!("No buffer space available"),
- 106 => cstr!("Transport endpoint is already connected"),
- 107 => cstr!("Transport endpoint is not connected"),
- 108 => cstr!("Cannot send after transport endpoint shutdown"),
- 109 => cstr!("Too many references: cannot splice"),
- 110 => cstr!("Connection timed out"),
- 111 => cstr!("Connection refused"),
- 112 => cstr!("Host is down"),
- 113 => cstr!("No route to host"),
- 114 => cstr!("Operation already in progress"),
- 115 => cstr!("Operation now in progress"),
- 116 => cstr!("Stale file handle"),
- 117 => cstr!("Structure needs cleaning"),
- 118 => cstr!("Not a XENIX named type file"),
- 119 => cstr!("No XENIX semaphores available"),
- 120 => cstr!("Is a named type file"),
- 121 => cstr!("Remote I/O error"),
- 122 => cstr!("Disk quota exceeded"),
- 123 => cstr!("No medium found"),
- 124 => cstr!("Wrong medium type"),
- 125 => cstr!("Operation canceled"),
- 126 => cstr!("Required key not available"),
- 127 => cstr!("Key has expired"),
- 128 => cstr!("Key has been revoked"),
- 129 => cstr!("Key was rejected by service"),
- 130 => cstr!("Owner died"),
- 131 => cstr!("State not recoverable"),
- 132 => cstr!("Operation not possible due to RF-kill"),
- 133 => cstr!("Memory page has hardware error"),
- _ => cstr!("Unknown errno value"),
+ 0 => c"Success",
+ 1 => c"Operation not permitted",
+ 2 => c"No such file or directory",
+ 3 => c"No such process",
+ 4 => c"Interrupted system call",
+ 5 => c"Input/output error",
+ 6 => c"No such device or address",
+ 7 => c"Argument list too long",
+ 8 => c"Exec format error",
+ 9 => c"Bad file descriptor",
+ 10 => c"No child processes",
+ 11 => c"Resource temporarily unavailable",
+ 12 => c"Cannot allocate memory",
+ 13 => c"Permission denied",
+ 14 => c"Bad address",
+ 15 => c"Block device required",
+ 16 => c"Device or resource busy",
+ 17 => c"File exists",
+ 18 => c"Invalid cross-device link",
+ 19 => c"No such device",
+ 20 => c"Not a directory",
+ 21 => c"Is a directory",
+ 22 => c"Invalid argument",
+ 23 => c"Too many open files in system",
+ 24 => c"Too many open files",
+ 25 => c"Inappropriate ioctl for device",
+ 26 => c"Text file busy",
+ 27 => c"File too large",
+ 28 => c"No space left on device",
+ 29 => c"Illegal seek",
+ 30 => c"Read-only file system",
+ 31 => c"Too many links",
+ 32 => c"Broken pipe",
+ 33 => c"Numerical argument out of domain",
+ 34 => c"Numerical result out of range",
+ 35 => c"Resource deadlock avoided",
+ 36 => c"File name too long",
+ 37 => c"No locks available",
+ 38 => c"Function not implemented",
+ 39 => c"Directory not empty",
+ 40 => c"Too many levels of symbolic links",
+ 42 => c"No message of desired type",
+ 43 => c"Identifier removed",
+ 44 => c"Channel number out of range",
+ 45 => c"Level 2 not synchronized",
+ 46 => c"Level 3 halted",
+ 47 => c"Level 3 reset",
+ 48 => c"Link number out of range",
+ 49 => c"Protocol driver not attached",
+ 50 => c"No CSI structure available",
+ 51 => c"Level 2 halted",
+ 52 => c"Invalid exchange",
+ 53 => c"Invalid request descriptor",
+ 54 => c"Exchange full",
+ 55 => c"No anode",
+ 56 => c"Invalid request code",
+ 57 => c"Invalid slot",
+ 59 => c"Bad font file format",
+ 60 => c"Device not a stream",
+ 61 => c"No data available",
+ 62 => c"Timer expired",
+ 63 => c"Out of streams resources",
+ 64 => c"Machine is not on the network",
+ 65 => c"Package not installed",
+ 66 => c"Object is remote",
+ 67 => c"Link has been severed",
+ 68 => c"Advertise error",
+ 69 => c"Srmount error",
+ 70 => c"Communication error on send",
+ 71 => c"Protocol error",
+ 72 => c"Multihop attempted",
+ 73 => c"RFS specific error",
+ 74 => c"Bad message",
+ 75 => c"Value too large for defined data type",
+ 76 => c"Name not unique on network",
+ 77 => c"File descriptor in bad state",
+ 78 => c"Remote address changed",
+ 79 => c"Can not access a needed shared library",
+ 80 => c"Accessing a corrupted shared library",
+ 81 => c".lib section in a.out corrupted",
+ 82 => c"Attempting to link in too many shared libraries",
+ 83 => c"Cannot exec a shared library directly",
+ 84 => c"Invalid or incomplete multibyte or wide character",
+ 85 => c"Interrupted system call should be restarted",
+ 86 => c"Streams pipe error",
+ 87 => c"Too many users",
+ 88 => c"Socket operation on non-socket",
+ 89 => c"Destination address required",
+ 90 => c"Message too long",
+ 91 => c"Protocol wrong type for socket",
+ 92 => c"Protocol not available",
+ 93 => c"Protocol not supported",
+ 94 => c"Socket type not supported",
+ 95 => c"Operation not supported",
+ 96 => c"Protocol family not supported",
+ 97 => c"Address family not supported by protocol",
+ 98 => c"Address already in use",
+ 99 => c"Cannot assign requested address",
+ 100 => c"Network is down",
+ 101 => c"Network is unreachable",
+ 102 => c"Network dropped connection on reset",
+ 103 => c"Software caused connection abort",
+ 104 => c"Connection reset by peer",
+ 105 => c"No buffer space available",
+ 106 => c"Transport endpoint is already connected",
+ 107 => c"Transport endpoint is not connected",
+ 108 => c"Cannot send after transport endpoint shutdown",
+ 109 => c"Too many references: cannot splice",
+ 110 => c"Connection timed out",
+ 111 => c"Connection refused",
+ 112 => c"Host is down",
+ 113 => c"No route to host",
+ 114 => c"Operation already in progress",
+ 115 => c"Operation now in progress",
+ 116 => c"Stale file handle",
+ 117 => c"Structure needs cleaning",
+ 118 => c"Not a XENIX named type file",
+ 119 => c"No XENIX semaphores available",
+ 120 => c"Is a named type file",
+ 121 => c"Remote I/O error",
+ 122 => c"Disk quota exceeded",
+ 123 => c"No medium found",
+ 124 => c"Wrong medium type",
+ 125 => c"Operation canceled",
+ 126 => c"Required key not available",
+ 127 => c"Key has expired",
+ 128 => c"Key has been revoked",
+ 129 => c"Key was rejected by service",
+ 130 => c"Owner died",
+ 131 => c"State not recoverable",
+ 132 => c"Operation not possible due to RF-kill",
+ 133 => c"Memory page has hardware error",
+ _ => c"Unknown errno value",
}
}
diff --git a/libs/libvmbase/src/fdt.rs b/libs/libvmbase/src/fdt.rs
index aaf354e..2113787 100644
--- a/libs/libvmbase/src/fdt.rs
+++ b/libs/libvmbase/src/fdt.rs
@@ -17,7 +17,6 @@
pub mod pci;
use core::ops::Range;
-use cstr::cstr;
use libfdt::{self, Fdt, FdtError};
/// Represents information about a SWIOTLB buffer.
@@ -34,7 +33,7 @@
impl SwiotlbInfo {
/// Creates a `SwiotlbInfo` struct from the given device tree.
pub fn new_from_fdt(fdt: &Fdt) -> libfdt::Result<Option<SwiotlbInfo>> {
- let Some(node) = fdt.compatible_nodes(cstr!("restricted-dma-pool"))?.next() else {
+ let Some(node) = fdt.compatible_nodes(c"restricted-dma-pool")?.next() else {
return Ok(None);
};
let (addr, size, align) = if let Some(mut reg) = node.reg()? {
@@ -42,8 +41,8 @@
let size = reg.size.ok_or(FdtError::BadValue)?;
(Some(reg.addr.try_into().unwrap()), size.try_into().unwrap(), None)
} else {
- let size = node.getprop_u64(cstr!("size"))?.ok_or(FdtError::NotFound)?;
- let align = node.getprop_u64(cstr!("alignment"))?.ok_or(FdtError::NotFound)?;
+ let size = node.getprop_u64(c"size")?.ok_or(FdtError::NotFound)?;
+ let align = node.getprop_u64(c"alignment")?.ok_or(FdtError::NotFound)?;
(None, size.try_into().unwrap(), Some(align.try_into().unwrap()))
};
Ok(Some(Self { addr, size, align }))
diff --git a/tests/testapk/Android.bp b/tests/testapk/Android.bp
index cb374a5..8a95fe9 100644
--- a/tests/testapk/Android.bp
+++ b/tests/testapk/Android.bp
@@ -224,7 +224,6 @@
"libandroid_logger",
"libanyhow",
"libavflog",
- "libcstr",
"liblog_rust",
"libvm_payload_rs",
],
diff --git a/tests/testapk/src/native/testbinary.rs b/tests/testapk/src/native/testbinary.rs
index 2502113..a84b955 100644
--- a/tests/testapk/src/native/testbinary.rs
+++ b/tests/testapk/src/native/testbinary.rs
@@ -24,7 +24,6 @@
},
binder::{BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Status, Strong},
};
-use cstr::cstr;
use log::{error, info};
use std::process::exit;
use std::string::String;
@@ -130,7 +129,7 @@
}
fn unimplemented<T>() -> BinderResult<T> {
- let message = cstr!("Got a call to an unimplemented ITestService method in testbinary.rs");
+ let message = c"Got a call to an unimplemented ITestService method in testbinary.rs";
error!("{message:?}");
Err(Status::new_exception(ExceptionCode::UNSUPPORTED_OPERATION, Some(message)))
}