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/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)