aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-09 04:05:07 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-09 04:05:07 +0000
commitdad82f53f44d49e806a7361654461f7595a86e71 (patch)
tree04e67e78b9de60519db5ce06e60b34e94f58a7da
parent3b5ffbbe7f5604f6f9cfdcd0bdd414db317fee7a (diff)
parentd588efcababb00c7a3716c832f39d53682b6da32 (diff)
downloadcrosvm-android14-qpr2-release.tar.gz
Change-Id: I4033caf691587578976214be5a7f72b29d0f41a9
-rw-r--r--rutabaga_gfx/Cargo.toml2
-rw-r--r--rutabaga_gfx/src/cross_domain/sys/linux.rs7
-rw-r--r--rutabaga_gfx/src/rutabaga_os/sys/linux/descriptor.rs10
-rw-r--r--rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs3
-rw-r--r--rutabaga_gfx/src/rutabaga_os/sys/linux/shm.rs8
5 files changed, 17 insertions, 13 deletions
diff --git a/rutabaga_gfx/Cargo.toml b/rutabaga_gfx/Cargo.toml
index 33d3281fa..0d063b92a 100644
--- a/rutabaga_gfx/Cargo.toml
+++ b/rutabaga_gfx/Cargo.toml
@@ -27,7 +27,7 @@ zerocopy = { version = "0.7", features = ["derive"] }
log = "0.4"
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
-nix = "0.26.1"
+nix = { version = "0.27.1", features = ["event", "feature", "fs", "mman", "socket", "uio"] }
[target.'cfg(windows)'.dependencies]
winapi = "0.3"
diff --git a/rutabaga_gfx/src/cross_domain/sys/linux.rs b/rutabaga_gfx/src/cross_domain/sys/linux.rs
index 13f0b4211..58a4f6e53 100644
--- a/rutabaga_gfx/src/cross_domain/sys/linux.rs
+++ b/rutabaga_gfx/src/cross_domain/sys/linux.rs
@@ -8,7 +8,6 @@ use std::io::IoSliceMut;
use std::io::Seek;
use std::io::SeekFrom;
use std::os::unix::io::AsRawFd;
-use std::os::unix::io::FromRawFd;
use std::os::unix::prelude::AsFd;
use libc::O_ACCMODE;
@@ -160,8 +159,8 @@ impl CrossDomainContext {
)?;
let unix_addr = UnixAddr::new(base_channel)?;
- connect(socket_fd, &unix_addr)?;
- let stream = unsafe { File::from_raw_fd(socket_fd) };
+ connect(socket_fd.as_raw_fd(), &unix_addr)?;
+ let stream = socket_fd.into();
Ok(Some(stream))
}
@@ -277,7 +276,7 @@ pub fn write_volatile(file: &File, opaque_data: &[u8]) -> RutabagaResult<()> {
}
pub fn channel() -> RutabagaResult<(Sender, Receiver)> {
- let sender = unsafe { File::from_raw_fd(eventfd(0, EfdFlags::empty())?) };
+ let sender: File = eventfd(0, EfdFlags::empty())?.into();
let receiver = sender.try_clone()?;
Ok((sender, receiver))
}
diff --git a/rutabaga_gfx/src/rutabaga_os/sys/linux/descriptor.rs b/rutabaga_gfx/src/rutabaga_os/sys/linux/descriptor.rs
index 2ce18b1bf..963f8f198 100644
--- a/rutabaga_gfx/src/rutabaga_os/sys/linux/descriptor.rs
+++ b/rutabaga_gfx/src/rutabaga_os/sys/linux/descriptor.rs
@@ -4,6 +4,8 @@
use std::convert::TryFrom;
use std::fs::File;
+use std::os::fd::AsFd;
+use std::os::fd::BorrowedFd;
use std::os::unix::io::AsRawFd;
use std::os::unix::io::FromRawFd;
use std::os::unix::io::IntoRawFd;
@@ -85,6 +87,14 @@ impl AsRawFd for Descriptor {
}
}
+impl AsFd for SafeDescriptor {
+ fn as_fd(&self) -> BorrowedFd {
+ // SAFETY: the `BorrowedFd` we return lives no longer than this `SafeDescriptor`, so the
+ // descriptor will remain open.
+ unsafe { BorrowedFd::borrow_raw(self.descriptor) }
+ }
+}
+
macro_rules! AsRawDescriptor {
($name:ident) => {
impl AsRawDescriptor for $name {
diff --git a/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs b/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
index 026f91343..7b16ac6c6 100644
--- a/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
+++ b/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
@@ -10,7 +10,6 @@ use nix::sys::mman::munmap;
use nix::sys::mman::MapFlags;
use nix::sys::mman::ProtFlags;
-use crate::rutabaga_os::descriptor::AsRawDescriptor;
use crate::rutabaga_os::descriptor::SafeDescriptor;
use crate::rutabaga_utils::RutabagaError;
use crate::rutabaga_utils::RutabagaResult;
@@ -59,7 +58,7 @@ impl MemoryMapping {
non_zero_size,
prot,
MapFlags::MAP_SHARED,
- descriptor.as_raw_descriptor(),
+ Some(descriptor),
0,
)?
};
diff --git a/rutabaga_gfx/src/rutabaga_os/sys/linux/shm.rs b/rutabaga_gfx/src/rutabaga_os/sys/linux/shm.rs
index bcfdee842..68472e5fb 100644
--- a/rutabaga_gfx/src/rutabaga_os/sys/linux/shm.rs
+++ b/rutabaga_gfx/src/rutabaga_os/sys/linux/shm.rs
@@ -4,8 +4,6 @@
use std::convert::TryInto;
use std::ffi::CStr;
-use std::os::unix::io::AsRawFd;
-use std::os::unix::io::FromRawFd;
use std::os::unix::io::OwnedFd;
use libc::off_t;
@@ -34,15 +32,13 @@ impl SharedMemory {
///
/// The file descriptor is opened with the close on exec flag and allows memfd sealing.
pub fn new(debug_name: &CStr, size: u64) -> RutabagaResult<SharedMemory> {
- // Nix will transition to owned fd in future releases, do it locally here.
- let raw_fd = memfd_create(
+ let fd = memfd_create(
debug_name,
MemFdCreateFlag::MFD_CLOEXEC | MemFdCreateFlag::MFD_ALLOW_SEALING,
)?;
- let fd = unsafe { OwnedFd::from_raw_fd(raw_fd) };
let size_off_t: off_t = size.try_into()?;
- ftruncate(fd.as_raw_fd(), size_off_t)?;
+ ftruncate(&fd, size_off_t)?;
Ok(SharedMemory { fd, size })
}