mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-03-22 03:00:35 +01:00
This is intended to a Rust analog to "src/util", which has
many utilities used by Mesa developers. This is mostly
a copy of ${crosvm} rutabaga_gfx/src/rutabaga_os (which will
be deleted in favor of this crate).
Key constructs include:
- SharedMemory
- MemoryMapping
- Tube (sockets, essentially)
- OwnedDescriptor (HANDLE or fd-based)
- WaitContext (epoll, ..)
As one would expect, Linux implementations are the most complete.
Acked-by: Aaron Ruby <aruby@qnx.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35210>
44 lines
1.7 KiB
Rust
44 lines
1.7 KiB
Rust
// Copyright 2025 Google
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use crate::OwnedDescriptor;
|
|
use crate::RawDescriptor;
|
|
|
|
/// Trait for forfeiting ownership of the current raw descriptor, and returning the raw descriptor
|
|
pub trait IntoRawDescriptor {
|
|
fn into_raw_descriptor(self) -> RawDescriptor;
|
|
}
|
|
|
|
/// Trait for returning the underlying raw descriptor, without giving up ownership of the
|
|
/// descriptor.
|
|
pub trait AsRawDescriptor {
|
|
/// Returns the underlying raw descriptor.
|
|
///
|
|
/// Since the descriptor is still owned by the provider, callers should not assume that it will
|
|
/// remain open for longer than the immediate call of this method. In particular, it is a
|
|
/// dangerous practice to store the result of this method for future use: instead, it should be
|
|
/// used to e.g. obtain a raw descriptor that is immediately passed to a system call.
|
|
///
|
|
/// If you need to use the descriptor for a longer time (and particularly if you cannot reliably
|
|
/// track the lifetime of the providing object), you should probably consider using
|
|
/// `OwnedDescriptor` (possibly along with `IntoRawDescriptor`) to get full ownership
|
|
/// over a descriptor pointing to the same resource.
|
|
fn as_raw_descriptor(&self) -> RawDescriptor;
|
|
}
|
|
|
|
pub trait FromRawDescriptor {
|
|
/// # Safety
|
|
/// Safe only if the caller ensures nothing has access to the descriptor after passing it to
|
|
/// `from_raw_descriptor`
|
|
unsafe fn from_raw_descriptor(descriptor: RawDescriptor) -> Self;
|
|
}
|
|
|
|
impl IntoRawDescriptor for i64 {
|
|
fn into_raw_descriptor(self) -> RawDescriptor {
|
|
self as RawDescriptor
|
|
}
|
|
}
|
|
|
|
pub trait AsBorrowedDescriptor {
|
|
fn as_borrowed_descriptor(&self) -> &OwnedDescriptor;
|
|
}
|