Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/cross_domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use mesa3d_util::TubeType;
use mesa3d_util::WaitContext;
use mesa3d_util::WaitTimeout;
use mesa3d_util::WritePipe;
use mesa3d_util::MESA_HANDLE_TYPE_MEM_DMABUF;
use mesa3d_util::MESA_HANDLE_TYPE_MEM_SHM;
use zerocopy::FromBytes;
use zerocopy::Immutable;
use zerocopy::IntoBytes;
Expand All @@ -54,7 +52,6 @@ use crate::rutabaga_utils::RutabagaPath;
use crate::rutabaga_utils::RutabagaResult;
use crate::rutabaga_utils::RUTABAGA_BLOB_FLAG_USE_MAPPABLE;
use crate::rutabaga_utils::RUTABAGA_BLOB_MEM_GUEST;
use crate::rutabaga_utils::RUTABAGA_MAP_ACCESS_READ;
use crate::rutabaga_utils::RUTABAGA_MAP_ACCESS_RW;
use crate::rutabaga_utils::RUTABAGA_MAP_CACHE_CACHED;
use crate::DrmFormat;
Expand Down Expand Up @@ -876,14 +873,10 @@ impl RutabagaContext for CrossDomainContext {
// Items that are removed from the table after one usage.
match item {
CrossDomainItem::Blob(hnd) => {
let map_access = if hnd.handle_type == MESA_HANDLE_TYPE_MEM_SHM {
RUTABAGA_MAP_ACCESS_READ
} else if hnd.handle_type == MESA_HANDLE_TYPE_MEM_DMABUF {
RUTABAGA_MAP_ACCESS_RW
} else {
// Default to READ for unknown types
RUTABAGA_MAP_ACCESS_READ
};
let map_access = hnd
.os_handle
.determine_map_access_mode()
.map_err(|e| RutabagaError::MesaError(e.into()))?;
let map_info = Some(RUTABAGA_MAP_CACHE_CACHED | map_access);

Ok(RutabagaResource {
Expand Down
26 changes: 26 additions & 0 deletions third_party/mesa3d/src/util/rust/sys/linux/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ use std::os::unix::io::FromRawFd;
use std::os::unix::io::IntoRawFd;
use std::os::unix::io::RawFd;

use rustix::fs::fcntl_get_seals;
use rustix::fs::fcntl_getfl;
use rustix::fs::seek;
use rustix::fs::OFlags;
use rustix::fs::SealFlags;
use rustix::fs::SeekFrom;
use rustix::io::Errno;

use crate::descriptor::AsRawDescriptor;
use crate::descriptor::FromRawDescriptor;
use crate::descriptor::IntoRawDescriptor;
use crate::DescriptorType;
use crate::MESA_HANDLE_TYPE_MEM_DMABUF;
use crate::MESA_HANDLE_TYPE_MEM_SHM;
use crate::MESA_MAP_ACCESS_READ;
use crate::MESA_MAP_ACCESS_RW;
use crate::MESA_MAP_ACCESS_WRITE;

pub type RawDescriptor = RawFd;
pub const DEFAULT_RAW_DESCRIPTOR: RawDescriptor = -1;
Expand Down Expand Up @@ -61,6 +67,26 @@ impl OwnedDescriptor {
}
}

pub fn determine_map_access_mode(&self) -> Result<u32> {
let flags = fcntl_getfl(&self.owned)?;
let mut access = match flags & OFlags::ACCMODE {
OFlags::RDONLY => MESA_MAP_ACCESS_READ,
OFlags::WRONLY => MESA_MAP_ACCESS_WRITE,
OFlags::RDWR => MESA_MAP_ACCESS_RW,
_ => return Err(Error::from(ErrorKind::Unsupported)),
};
// Access mode can be RDWR, but a write seal would still prevent RW mappings!
let seals = match fcntl_get_seals(&self.owned) {
Ok(seals) => seals,
Err(Errno::INVAL) => SealFlags::empty(), // It's fine if the file does not support sealing
Err(err) => return Err(err.into()),
};
if seals.contains(SealFlags::WRITE) || seals.contains(SealFlags::FUTURE_WRITE) {
access &= !MESA_MAP_ACCESS_WRITE;
}
Ok(access)
}

fn get_memory_handle_type(&self) -> Result<u32> {
let fd_path = read_link(format!("/proc/self/fd/{}", self.as_raw_descriptor()))
.map_err(|_| Error::from(ErrorKind::Unsupported))?;
Expand Down
4 changes: 4 additions & 0 deletions third_party/mesa3d/src/util/rust/sys/stub/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl OwnedDescriptor {
pub fn determine_type(&self) -> Result<DescriptorType> {
Err(Error::from(ErrorKind::Unsupported))
}

pub fn determine_map_access_mode(&self) -> Result<u32> {
Err(Error::from(ErrorKind::Unsupported))
}
}

impl AsRawDescriptor for OwnedDescriptor {
Expand Down
4 changes: 4 additions & 0 deletions third_party/mesa3d/src/util/rust/sys/windows/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl OwnedDescriptor {
pub fn determine_type(&self) -> Result<DescriptorType> {
Err(Error::from(ErrorKind::Unsupported))
}

pub fn determine_map_access_mode(&self) -> Result<u32> {
Err(Error::from(ErrorKind::Unsupported))
}
}

impl AsRawDescriptor for OwnedDescriptor {
Expand Down
Loading