From 101b2f61b467c827d9d62ce54108fdd73989b347 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 6 Nov 2023 17:21:54 -0800 Subject: [PATCH 1/4] Use `rustix` instead of `nix` Not *too* hard to update by defining macros like Nix had. It would be possible to replace use of the macro with just type aliases for opcodes, but it's still necessary to deal with `Getter`/`Setter`/`Updater`, and repeat the type. --- Cargo.toml | 12 +---- drm-ffi/Cargo.toml | 6 +-- drm-ffi/src/gem.rs | 8 ++-- drm-ffi/src/ioctl.rs | 48 +++++++++++++++++-- drm-ffi/src/lib.rs | 52 +++++++-------------- drm-ffi/src/mode.rs | 98 ++++++++++++++++++--------------------- drm-ffi/src/syncobj.rs | 22 ++++----- examples/syncobj.rs | 6 +-- src/control/dumbbuffer.rs | 5 +- src/control/mod.rs | 29 ++++++------ src/lib.rs | 4 +- 11 files changed, 143 insertions(+), 147 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7e69b383..c6b3d3fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,19 +14,11 @@ bitflags = "2" bytemuck = { version = "1.12", features = ["extern_crate_alloc", "derive"] } drm-ffi = { path = "drm-ffi", version = "0.6.0" } drm-fourcc = "^2.2.0" - -[dependencies.nix] -version = "0.27" -default-features = false -features = ["mman", "fs"] - -[dev-dependencies.nix] -version = "0.27" -default-features = false -features = ["mman", "poll"] +rustix = { version = "0.38.22", features = ["mm", "fs"] } [dev-dependencies] image = { version = "0.24", default-features = false, features = ["png"] } +rustix = { version = "0.38.22", features = ["event", "mm"] } rustyline = "12" [features] diff --git a/drm-ffi/Cargo.toml b/drm-ffi/Cargo.toml index d57c2378..da2ad1b9 100644 --- a/drm-ffi/Cargo.toml +++ b/drm-ffi/Cargo.toml @@ -10,11 +10,7 @@ edition = "2021" [dependencies] drm-sys = { path = "drm-sys", version = "0.5.0" } - -[dependencies.nix] -version = "0.27" -default-features = false -features = ["ioctl"] +rustix = { version = "0.38.22" } [features] use_bindgen = ["drm-sys/use_bindgen"] diff --git a/drm-ffi/src/gem.rs b/drm-ffi/src/gem.rs index 4d330d6d..01b7f0b7 100644 --- a/drm-ffi/src/gem.rs +++ b/drm-ffi/src/gem.rs @@ -18,7 +18,7 @@ pub fn open(fd: BorrowedFd<'_>, name: u32) -> io::Result { }; unsafe { - ioctl::gem::open(fd.as_raw_fd(), &mut gem)?; + ioctl::gem::open(fd, &mut gem)?; } Ok(gem) @@ -32,7 +32,7 @@ pub fn close(fd: BorrowedFd<'_>, handle: u32) -> io::Result { }; unsafe { - ioctl::gem::close(fd.as_raw_fd(), &gem)?; + ioctl::gem::close(fd, &gem)?; } Ok(gem) @@ -47,7 +47,7 @@ pub fn handle_to_fd(fd: BorrowedFd<'_>, handle: u32, flags: u32) -> io::Result, primefd: BorrowedFd<'_>) -> io::Result { + pub unsafe fn $name(fd: BorrowedFd, data: &mut $ty) -> io::Result<()> { + type Opcode = ReadWriteOpcode<$ioty, $nr, $ty>; + Ok(ioctl(fd, Updater::::new(data))?) + } + }; +} + +macro_rules! ioctl_read { + ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => { + pub unsafe fn $name(fd: BorrowedFd) -> io::Result<$ty> { + type Opcode = ReadOpcode<$ioty, $nr, $ty>; + Ok(ioctl(fd, Getter::::new())?) + } + }; +} + +macro_rules! ioctl_write_ptr { + ($name:ident, $ioty:expr, $nr:expr, $ty:ty) => { + pub unsafe fn $name(fd: BorrowedFd, data: &$ty) -> io::Result<()> { + type Opcode = WriteOpcode<$ioty, $nr, $ty>; + Ok(ioctl(fd, Setter::::new(*data))?) + } + }; +} + +macro_rules! ioctl_none { + ($name:ident, $ioty:expr, $nr:expr) => { + pub unsafe fn $name(fd: BorrowedFd) -> io::Result<()> { + type Opcode = NoneOpcode<$ioty, $nr, ()>; + Ok(ioctl(fd, NoArg::::new())?) + } + }; +} /// Gets the bus ID of the device /// @@ -94,8 +133,7 @@ ioctl_readwrite!(get_irq_from_bus_id, DRM_IOCTL_BASE, 0x03, drm_irq_busid); ioctl_readwrite!(wait_vblank, DRM_IOCTL_BASE, 0x3a, drm_wait_vblank); pub(crate) mod mode { - use drm_sys::*; - use nix::libc::c_uint; + use super::*; /// Modesetting resources ioctl_readwrite!(get_resources, DRM_IOCTL_BASE, 0xA0, drm_mode_card_res); @@ -198,7 +236,7 @@ pub(crate) mod mode { } pub(crate) mod gem { - use drm_sys::*; + use super::*; /// GEM related functions ioctl_readwrite!(open, DRM_IOCTL_BASE, 0x0b, drm_gem_open); @@ -212,7 +250,7 @@ pub(crate) mod gem { } pub(crate) mod syncobj { - use drm_sys::*; + use super::*; /// Creates a syncobj. ioctl_readwrite!(create, DRM_IOCTL_BASE, 0xBF, drm_syncobj_create); diff --git a/drm-ffi/src/lib.rs b/drm-ffi/src/lib.rs index c63c9558..cb375151 100644 --- a/drm-ffi/src/lib.rs +++ b/drm-ffi/src/lib.rs @@ -7,9 +7,6 @@ pub use drm_sys::{self, *}; -#[macro_use] -extern crate nix; - #[macro_use] pub(crate) mod utils; @@ -18,10 +15,10 @@ mod ioctl; pub mod mode; pub mod syncobj; -use nix::libc::{c_int, c_ulong}; use std::{ + ffi::{c_int, c_ulong}, io, - os::unix::io::{AsRawFd, BorrowedFd}, + os::unix::io::BorrowedFd, }; /// @@ -31,20 +28,11 @@ pub mod auth { use crate::ioctl; use drm_sys::*; - use std::{ - io, - os::unix::io::{AsRawFd, BorrowedFd}, - }; + use std::{io, os::unix::io::BorrowedFd}; /// Get the 'Magic Authentication Token' for this file descriptor. pub fn get_magic_token(fd: BorrowedFd<'_>) -> io::Result { - let mut auth = drm_auth::default(); - - unsafe { - ioctl::get_token(fd.as_raw_fd(), &mut auth)?; - } - - Ok(auth) + unsafe { ioctl::get_token(fd) } } /// Authorize another process' 'Magic Authentication Token'. @@ -52,7 +40,7 @@ pub mod auth { let token = drm_auth { magic: auth }; unsafe { - ioctl::auth_token(fd.as_raw_fd(), &token)?; + ioctl::auth_token(fd, &token)?; } Ok(token) @@ -60,20 +48,12 @@ pub mod auth { /// Acquire the 'Master DRM Lock' for this file descriptor. pub fn acquire_master(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ioctl::acquire_master(fd.as_raw_fd())?; - } - - Ok(()) + unsafe { ioctl::acquire_master(fd) } } /// Release the 'Master DRM Lock' for this file descriptor. pub fn release_master(fd: BorrowedFd<'_>) -> io::Result<()> { - unsafe { - ioctl::release_master(fd.as_raw_fd())?; - } - - Ok(()) + unsafe { ioctl::release_master(fd) } } } @@ -81,7 +61,7 @@ pub mod auth { pub fn get_bus_id(fd: BorrowedFd<'_>, mut buf: Option<&mut Vec>) -> io::Result { let mut sizes = drm_unique::default(); unsafe { - ioctl::get_bus_id(fd.as_raw_fd(), &mut sizes)?; + ioctl::get_bus_id(fd, &mut sizes)?; } if buf.is_none() { @@ -96,7 +76,7 @@ pub fn get_bus_id(fd: BorrowedFd<'_>, mut buf: Option<&mut Vec>) -> io::Resu }; unsafe { - ioctl::get_bus_id(fd.as_raw_fd(), &mut busid)?; + ioctl::get_bus_id(fd, &mut busid)?; } map_set!(buf, busid.unique_len as usize); @@ -119,7 +99,7 @@ pub fn get_interrupt_from_bus_id( }; unsafe { - ioctl::get_irq_from_bus_id(fd.as_raw_fd(), &mut irq)?; + ioctl::get_irq_from_bus_id(fd, &mut irq)?; } Ok(irq) @@ -133,7 +113,7 @@ pub fn get_client(fd: BorrowedFd<'_>, idx: c_int) -> io::Result { }; unsafe { - ioctl::get_client(fd.as_raw_fd(), &mut client)?; + ioctl::get_client(fd, &mut client)?; } Ok(client) @@ -147,7 +127,7 @@ pub fn get_capability(fd: BorrowedFd<'_>, cty: u64) -> io::Result { }; unsafe { - ioctl::get_cap(fd.as_raw_fd(), &mut cap)?; + ioctl::get_cap(fd, &mut cap)?; } Ok(cap) @@ -161,7 +141,7 @@ pub fn set_capability(fd: BorrowedFd<'_>, cty: u64, val: bool) -> io::Result io::Result { let mut sizes = drm_version::default(); unsafe { - ioctl::get_version(fd.as_raw_fd(), &mut sizes)?; + ioctl::get_version(fd, &mut sizes)?; } map_reserve!(name_buf, sizes.name_len as usize); @@ -194,7 +174,7 @@ pub fn get_version( }; unsafe { - ioctl::get_version(fd.as_raw_fd(), &mut version)?; + ioctl::get_version(fd, &mut version)?; } map_set!(name_buf, version.name_len as usize); @@ -223,7 +203,7 @@ pub fn wait_vblank( }; unsafe { - ioctl::wait_vblank(fd.as_raw_fd(), &mut wait_vblank)?; + ioctl::wait_vblank(fd, &mut wait_vblank)?; }; Ok(unsafe { wait_vblank.reply }) diff --git a/drm-ffi/src/mode.rs b/drm-ffi/src/mode.rs index 49c2d5a2..1b30b8f8 100644 --- a/drm-ffi/src/mode.rs +++ b/drm-ffi/src/mode.rs @@ -7,10 +7,7 @@ use crate::ioctl; use drm_sys::*; -use std::{ - io, - os::unix::io::{AsRawFd, BorrowedFd}, -}; +use std::{io, os::unix::io::BorrowedFd}; /// Enumerate most card resources. pub fn get_resources( @@ -22,7 +19,7 @@ pub fn get_resources( ) -> io::Result { let mut sizes = drm_mode_card_res::default(); unsafe { - ioctl::mode::get_resources(fd.as_raw_fd(), &mut sizes)?; + ioctl::mode::get_resources(fd, &mut sizes)?; } map_reserve!(fbs, sizes.count_fbs as usize); @@ -43,7 +40,7 @@ pub fn get_resources( }; unsafe { - ioctl::mode::get_resources(fd.as_raw_fd(), &mut res)?; + ioctl::mode::get_resources(fd, &mut res)?; } map_set!(fbs, res.count_fbs as usize); @@ -61,7 +58,7 @@ pub fn get_plane_resources( ) -> io::Result { let mut sizes = drm_mode_get_plane_res::default(); unsafe { - ioctl::mode::get_plane_resources(fd.as_raw_fd(), &mut sizes)?; + ioctl::mode::get_plane_resources(fd, &mut sizes)?; } if planes.is_none() { @@ -76,7 +73,7 @@ pub fn get_plane_resources( }; unsafe { - ioctl::mode::get_plane_resources(fd.as_raw_fd(), &mut res)?; + ioctl::mode::get_plane_resources(fd, &mut res)?; } map_set!(planes, res.count_planes as usize); @@ -92,7 +89,7 @@ pub fn get_framebuffer(fd: BorrowedFd<'_>, fb_id: u32) -> io::Result, fb_id: u32) -> io::Result, mut id: u32) -> io::Result<()> { unsafe { - ioctl::mode::rm_fb(fd.as_raw_fd(), &mut id)?; + ioctl::mode::rm_fb(fd, &mut id)?; } Ok(()) @@ -193,7 +190,7 @@ pub fn dirty_fb( }; unsafe { - ioctl::mode::dirty_fb(fd.as_raw_fd(), &mut dirty)?; + ioctl::mode::dirty_fb(fd, &mut dirty)?; } Ok(dirty) @@ -207,7 +204,7 @@ pub fn get_crtc(fd: BorrowedFd<'_>, crtc_id: u32) -> io::Result { }; unsafe { - ioctl::mode::get_crtc(fd.as_raw_fd(), &mut info)?; + ioctl::mode::get_crtc(fd, &mut info)?; } Ok(info) @@ -239,7 +236,7 @@ pub fn set_crtc( }; unsafe { - ioctl::mode::set_crtc(fd.as_raw_fd(), &mut crtc)?; + ioctl::mode::set_crtc(fd, &mut crtc)?; } Ok(crtc) @@ -263,7 +260,7 @@ pub fn get_gamma( }; unsafe { - ioctl::mode::get_gamma(fd.as_raw_fd(), &mut lut)?; + ioctl::mode::get_gamma(fd, &mut lut)?; } Ok(lut) @@ -287,7 +284,7 @@ pub fn set_gamma( }; unsafe { - ioctl::mode::set_gamma(fd.as_raw_fd(), &mut lut)?; + ioctl::mode::set_gamma(fd, &mut lut)?; } Ok(lut) @@ -315,7 +312,7 @@ pub fn set_cursor( }; unsafe { - ioctl::mode::cursor(fd.as_raw_fd(), &mut cursor)?; + ioctl::mode::cursor(fd, &mut cursor)?; } Ok(cursor) @@ -350,7 +347,7 @@ pub fn set_cursor2( }; unsafe { - ioctl::mode::cursor2(fd.as_raw_fd(), &mut cursor)?; + ioctl::mode::cursor2(fd, &mut cursor)?; } Ok(cursor) @@ -373,7 +370,7 @@ pub fn move_cursor( }; unsafe { - ioctl::mode::cursor(fd.as_raw_fd(), &mut cursor)?; + ioctl::mode::cursor(fd, &mut cursor)?; } Ok(cursor) @@ -404,7 +401,7 @@ pub fn get_connector( }; unsafe { - ioctl::mode::get_connector(fd.as_raw_fd(), &mut sizes)?; + ioctl::mode::get_connector(fd, &mut sizes)?; } let info = loop { @@ -444,7 +441,7 @@ pub fn get_connector( }; unsafe { - ioctl::mode::get_connector(fd.as_raw_fd(), &mut info)?; + ioctl::mode::get_connector(fd, &mut info)?; } if info.count_modes == sizes.count_modes @@ -473,7 +470,7 @@ pub fn get_encoder(fd: BorrowedFd<'_>, encoder_id: u32) -> io::Result, id: u32) -> io::Result, lessee_id: u32) -> io::Result<()> { let mut data = drm_mode_revoke_lease { lessee_id }; unsafe { - ioctl::mode::revoke_lease(fd.as_raw_fd(), &mut data)?; + ioctl::mode::revoke_lease(fd, &mut data)?; } Ok(()) @@ -883,10 +880,7 @@ pub mod dumbbuffer { use crate::ioctl; use drm_sys::*; - use std::{ - io, - os::unix::io::{AsRawFd, BorrowedFd}, - }; + use std::{io, os::unix::io::BorrowedFd}; /// Create a dumb buffer pub fn create( @@ -905,7 +899,7 @@ pub mod dumbbuffer { }; unsafe { - ioctl::mode::create_dumb(fd.as_raw_fd(), &mut db)?; + ioctl::mode::create_dumb(fd, &mut db)?; } Ok(db) @@ -916,7 +910,7 @@ pub mod dumbbuffer { let mut db = drm_mode_destroy_dumb { handle }; unsafe { - ioctl::mode::destroy_dumb(fd.as_raw_fd(), &mut db)?; + ioctl::mode::destroy_dumb(fd, &mut db)?; } Ok(db) @@ -936,7 +930,7 @@ pub mod dumbbuffer { }; unsafe { - ioctl::mode::map_dumb(fd.as_raw_fd(), &mut map)?; + ioctl::mode::map_dumb(fd, &mut map)?; } Ok(map) diff --git a/drm-ffi/src/syncobj.rs b/drm-ffi/src/syncobj.rs index 8dd9b5d3..6cb45a95 100644 --- a/drm-ffi/src/syncobj.rs +++ b/drm-ffi/src/syncobj.rs @@ -22,7 +22,7 @@ pub fn create(fd: BorrowedFd<'_>, signaled: bool) -> io::Result, handle: u32) -> io::Result, handles: &[u32]) -> io::Result, handles: &[u32]) -> io::Result { impl<'a> Drop for DumbMapping<'a> { fn drop(&mut self) { - use nix::sys::mman; - unsafe { - mman::munmap(self.map.as_mut_ptr() as *mut _, self.map.len()).expect("Unmap failed"); + rustix::mm::munmap(self.map.as_mut_ptr() as *mut _, self.map.len()) + .expect("Unmap failed"); } } } diff --git a/src/control/mod.rs b/src/control/mod.rs index 8b67b2d8..aafcc6da 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -32,7 +32,7 @@ use drm_ffi as ffi; use drm_fourcc::{DrmFourcc, DrmModifier, UnrecognizedFourcc}; use bytemuck::allocation::TransparentWrapperAlloc; -use nix::libc::EINVAL; +use rustix::io::Errno; pub mod atomic; pub mod connector; @@ -57,14 +57,13 @@ use std::fmt; use std::io; use std::iter::Zip; use std::mem; -use std::num::NonZeroUsize; use std::ops::RangeBounds; -use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd}; +use std::os::unix::io::{AsFd, BorrowedFd, FromRawFd, OwnedFd, RawFd}; use std::time::Duration; use core::num::NonZeroU32; -pub use nix::fcntl::OFlag; +pub use rustix::fs::OFlags; /// Raw handle for a drm resource pub type RawResourceHandle = NonZeroU32; @@ -609,7 +608,7 @@ pub trait Device: super::Device { || crtc_info.gamma_length as usize > green.len() || crtc_info.gamma_length as usize > blue.len() { - return Err(io::Error::from_raw_os_error(EINVAL)); + return Err(Errno::INVAL.into()); } ffi::mode::get_gamma( @@ -637,7 +636,7 @@ pub trait Device: super::Device { || crtc_info.gamma_length as usize > green.len() || crtc_info.gamma_length as usize > blue.len() { - return Err(io::Error::from_raw_os_error(EINVAL)); + return Err(Errno::INVAL.into()); } ffi::mode::set_gamma( @@ -688,19 +687,17 @@ pub trait Device: super::Device { let info = drm_ffi::mode::dumbbuffer::map(self.as_fd(), buffer.handle.into(), 0, 0)?; let map = { - use nix::sys::mman; - let prot = mman::ProtFlags::PROT_READ | mman::ProtFlags::PROT_WRITE; - let flags = mman::MapFlags::MAP_SHARED; - let length = NonZeroUsize::new(buffer.length) - .ok_or_else(|| io::Error::from_raw_os_error(EINVAL))?; + use rustix::mm; + let prot = mm::ProtFlags::READ | mm::ProtFlags::WRITE; + let flags = mm::MapFlags::SHARED; let fd = self.as_fd(); let offset = info.offset as _; - unsafe { mman::mmap(None, length, prot, flags, Some(fd), offset)? } + unsafe { mm::mmap(std::ptr::null_mut(), buffer.length, prot, flags, fd, offset)? } }; let mapping = DumbMapping { - _phantom: ::std::marker::PhantomData, - map: unsafe { ::std::slice::from_raw_parts_mut(map as *mut _, buffer.length) }, + _phantom: std::marker::PhantomData, + map: unsafe { std::slice::from_raw_parts_mut(map as *mut _, buffer.length) }, }; Ok(mapping) @@ -961,7 +958,7 @@ pub trait Device: super::Device { fn create_lease( &self, objects: &[RawResourceHandle], - flags: OFlag, + flags: OFlags, ) -> io::Result<(LeaseId, OwnedFd)> { let lease = ffi::mode::create_lease( self.as_fd(), @@ -992,7 +989,7 @@ pub trait Device: super::Device { Self: Sized, { let mut event_buf: [u8; 1024] = [0; 1024]; - let amount = ::nix::unistd::read(self.as_fd().as_raw_fd(), &mut event_buf)?; + let amount = rustix::io::read(self.as_fd(), &mut event_buf)?; Ok(Events::with_event_buf(event_buf, amount)) } diff --git a/src/lib.rs b/src/lib.rs index de08b66c..c60092fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ use std::{ os::unix::{ffi::OsStringExt, io::AsFd}, }; -use nix::libc::EINVAL; +use rustix::io::Errno; use crate::util::*; @@ -192,7 +192,7 @@ pub trait Device: AsFd { let high_crtc_mask = _DRM_VBLANK_HIGH_CRTC_MASK >> _DRM_VBLANK_HIGH_CRTC_SHIFT; if (high_crtc & !high_crtc_mask) != 0 { - return Err(io::Error::from_raw_os_error(EINVAL)); + return Err(Errno::INVAL.into()); } let (sequence, wait_type) = match target_sequence { From 43f24bda4e98ae72fcf79cde3ce043929343ae8a Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 13 Nov 2023 15:03:07 -0800 Subject: [PATCH 2/4] ffi: Remove unused legacy `get_stats` ioctl Since https://github.com/torvalds/linux/commit/d79cdc831 in 2013, the `GET_STATS` ioctl has been a no-op. A wrapper for this was not exported in the API here anyway. --- drm-ffi/src/ioctl.rs | 7 ------- examples/ffi.rs | 7 ------- 2 files changed, 14 deletions(-) diff --git a/drm-ffi/src/ioctl.rs b/drm-ffi/src/ioctl.rs index 6e877739..0f46801f 100644 --- a/drm-ffi/src/ioctl.rs +++ b/drm-ffi/src/ioctl.rs @@ -55,13 +55,6 @@ ioctl_readwrite!(get_bus_id, DRM_IOCTL_BASE, 0x01, drm_unique); /// # Nodes: Primary ioctl_readwrite!(get_client, DRM_IOCTL_BASE, 0x05, drm_client); -/// Gets statistical information from the device -/// -/// # Locks DRM mutex: No -/// # Permissions: None -/// # Nodes: Primary -ioctl_read!(get_stats, DRM_IOCTL_BASE, 0x06, drm_stats); - /// Get capabilities of the device. /// /// # Locks DRM mutex: No diff --git a/examples/ffi.rs b/examples/ffi.rs index ccabcf7b..bcff231f 100644 --- a/examples/ffi.rs +++ b/examples/ffi.rs @@ -63,13 +63,6 @@ fn print_token(fd: BorrowedFd<'_>) { println!("{:#?}", token); } -/* -fn print_stats(fd: BorrowedFd<'_>) { - let stats = ffi::basic::get_stats(fd); - println!("{:#?}", stats); -} -*/ - fn main() { let card = Card::open_global(); let fd = card.as_fd(); From 678c4d6e7fc3dba2591b15de56e9e9745dc30400 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 13 Nov 2023 15:13:47 -0800 Subject: [PATCH 3/4] ffi: Add public `set_version` function Somehow Cargo didn't complain about the previous generated ioctl function being unused, but does now with the macro based on Rustix. Taking an `&mut` matches the API of `drmSetInterfaceVersion` in libdrm, so it makes sense to just stick with that. --- drm-ffi/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drm-ffi/src/lib.rs b/drm-ffi/src/lib.rs index cb375151..4be96143 100644 --- a/drm-ffi/src/lib.rs +++ b/drm-ffi/src/lib.rs @@ -147,6 +147,11 @@ pub fn set_capability(fd: BorrowedFd<'_>, cty: u64, val: bool) -> io::Result, version: &mut drm_set_version) -> io::Result<()> { + unsafe { ioctl::set_version(fd, version) } +} + /// Gets the driver version for this device. pub fn get_version( fd: BorrowedFd<'_>, From 40a022df66daae79a7d3f0eaa4973438809f9bf1 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 13 Nov 2023 15:20:08 -0800 Subject: [PATCH 4/4] Take `u32` instead of `OFlags` in `create_lease` This shouldn't be too much worse to use, and avoids any kind of public dependency of Rustix. So a new version of it won't be a breaking change. --- src/control/mod.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/control/mod.rs b/src/control/mod.rs index aafcc6da..2b6f9463 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -63,8 +63,6 @@ use std::time::Duration; use core::num::NonZeroU32; -pub use rustix::fs::OFlags; - /// Raw handle for a drm resource pub type RawResourceHandle = NonZeroU32; @@ -958,13 +956,9 @@ pub trait Device: super::Device { fn create_lease( &self, objects: &[RawResourceHandle], - flags: OFlags, + flags: u32, ) -> io::Result<(LeaseId, OwnedFd)> { - let lease = ffi::mode::create_lease( - self.as_fd(), - bytemuck::cast_slice(objects), - flags.bits() as u32, - )?; + let lease = ffi::mode::create_lease(self.as_fd(), bytemuck::cast_slice(objects), flags)?; Ok(( unsafe { NonZeroU32::new_unchecked(lease.lessee_id) }, unsafe { OwnedFd::from_raw_fd(lease.fd as RawFd) },