mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
build: upgrade whole* workspace to Rust edition 2024
This upgrades the Cargo workspace to Rust edition 2024 to keep the code base clean and up to date. The commit only contains the adjustments to the Cargo.toml files and basic compiler error fixes. Also, this commit includes new SAFETY comments as discussed in [1]. The changes were not automatically fixed by `cargo fix --edition` but needed manual adjustments. Apart from that, all formatting and clippy adjustments follow in subsequent commits. * As only exception, workspace member net_gen sticks to edition 2021 for now as discussed in [0]. [0] https://github.com/cloud-hypervisor/cloud-hypervisor/pull/7295#discussion_r2310851041 [1] https://github.com/cloud-hypervisor/cloud-hypervisor/pull/7256#issuecomment-3271888674 Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Bo Chen
parent
5790bcefee
commit
061351d82d
@@ -33,5 +33,6 @@ pub struct clone_args {
|
||||
/// - On error: `-1` and `errno` is set
|
||||
#[must_use]
|
||||
pub unsafe fn clone3(args: &mut clone_args, size: size_t) -> c_long {
|
||||
syscall(SYS_clone3, args, size)
|
||||
// SAFETY: parameters are assumed to be valid
|
||||
unsafe { syscall(SYS_clone3, args, size) }
|
||||
}
|
||||
|
||||
@@ -3373,7 +3373,7 @@ impl DeviceManager {
|
||||
let mut devices = Vec::new();
|
||||
|
||||
let mut vsock = self.config.lock().unwrap().vsock.clone();
|
||||
if let Some(ref mut vsock_cfg) = &mut vsock {
|
||||
if let Some(vsock_cfg) = &mut vsock {
|
||||
devices.push(self.make_virtio_vsock_device(vsock_cfg)?);
|
||||
}
|
||||
self.config.lock().unwrap().vsock = vsock;
|
||||
|
||||
@@ -83,7 +83,8 @@ unsafe fn close_fds_fallback(keep_fds: &BTreeSet<RawFd>) {
|
||||
.collect();
|
||||
|
||||
for fd in open_fds.difference(keep_fds) {
|
||||
close(*fd);
|
||||
// SAFETY: The FD is valid
|
||||
unsafe { close(*fd) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,12 +109,14 @@ unsafe fn close_unused_fds(keep_fds: &mut [RawFd]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if syscall(SYS_close_range, first, last, 0) == -1 {
|
||||
// SAFETY: FDs are valid
|
||||
if unsafe { syscall(SYS_close_range, first, last, 0) } == -1 {
|
||||
// The kernel might be too old to have close_range, in
|
||||
// which case we need to fall back to an uglier method.
|
||||
let e = io::Error::last_os_error();
|
||||
if e.raw_os_error() == Some(ENOSYS) {
|
||||
return close_fds_fallback(&keep_fds.iter().copied().collect());
|
||||
// SAFETY: FDs are valid
|
||||
return unsafe { close_fds_fallback(&keep_fds.iter().copied().collect()) };
|
||||
}
|
||||
|
||||
panic!("close_range: {e}");
|
||||
@@ -212,7 +215,8 @@ unsafe fn clone_clear_sighand() -> io::Result<u64> {
|
||||
..Default::default()
|
||||
};
|
||||
args.flags |= CLONE_CLEAR_SIGHAND;
|
||||
let r = clone3(&mut args, size_of::<clone_args>());
|
||||
// SAFETY: parameters are assumed to be valid
|
||||
let r = unsafe { clone3(&mut args, size_of::<clone_args>()) };
|
||||
if r != -1 {
|
||||
return Ok(r.try_into().unwrap());
|
||||
}
|
||||
@@ -223,13 +227,15 @@ unsafe fn clone_clear_sighand() -> io::Result<u64> {
|
||||
|
||||
// If CLONE_CLEAR_SIGHAND isn't available, fall back to resetting
|
||||
// all the signal handlers one by one.
|
||||
let r = fork();
|
||||
// SAFETY: trivially safe, and we check the return value.
|
||||
let r = unsafe { fork() };
|
||||
if r == -1 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
if r == 0 {
|
||||
for signum in 1.._NSIG {
|
||||
let _ = signal(signum, SIG_DFL);
|
||||
// SAFETY: trivially safe, we unset the user-space signal handler
|
||||
let _ = unsafe { signal(signum, SIG_DFL) };
|
||||
}
|
||||
}
|
||||
Ok(r.try_into().unwrap())
|
||||
|
||||
Reference in New Issue
Block a user