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