| 1 |
From d49490ce6ade74c52c8a716ecf35906c033127e6 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Kevin Mehall <[email protected]> |
| 3 |
Date: Sat, 1 Feb 2025 20:38:53 -0700 |
| 4 |
Subject: [PATCH] Update Rustix to 1.0 |
| 5 |
|
| 6 |
--- |
| 7 |
Cargo.toml | 2 +- |
| 8 |
src/platform/linux_usbfs/events.rs | 5 +- |
| 9 |
src/platform/linux_usbfs/usbfs.rs | 108 +++++++++++++++-------------- |
| 10 |
3 files changed, 60 insertions(+), 55 deletions(-) |
| 11 |
|
| 12 |
--- a/Cargo.toml |
| 13 |
+++ b/Cargo.toml |
| 14 |
@@ -96,7 +96,7 @@ |
| 15 |
version = "0.2.155" |
| 16 |
|
| 17 |
[target.'cfg(any(target_os="linux", target_os="android"))'.dependencies.rustix] |
| 18 |
-version = "0.38.17" |
| 19 |
+version = "1" |
| 20 |
features = [ |
| 21 |
"fs", |
| 22 |
"event", |
| 23 |
--- a/src/platform/linux_usbfs/events.rs |
| 24 |
+++ b/src/platform/linux_usbfs/events.rs |
| 25 |
@@ -13,6 +13,7 @@ |
| 26 |
/// dispatch in the event loop avoids additonal synchronization. |
| 27 |
use once_cell::sync::OnceCell; |
| 28 |
use rustix::{ |
| 29 |
+ buffer::spare_capacity, |
| 30 |
event::epoll::{self, EventData, EventFlags}, |
| 31 |
fd::{AsFd, BorrowedFd, OwnedFd}, |
| 32 |
io::retry_on_intr, |
| 33 |
@@ -71,9 +72,9 @@ |
| 34 |
|
| 35 |
fn event_loop() { |
| 36 |
let epoll_fd = EPOLL_FD.get().unwrap(); |
| 37 |
- let mut event_list = epoll::EventVec::with_capacity(4); |
| 38 |
+ let mut event_list = Vec::with_capacity(4); |
| 39 |
loop { |
| 40 |
- retry_on_intr(|| epoll::wait(epoll_fd, &mut event_list, -1)).unwrap(); |
| 41 |
+ retry_on_intr(|| epoll::wait(epoll_fd, spare_capacity(&mut event_list), None)).unwrap(); |
| 42 |
for event in &event_list { |
| 43 |
let key = event.data.u64() as usize; |
| 44 |
let lock = WATCHES.lock().unwrap(); |
| 45 |
--- a/src/platform/linux_usbfs/usbfs.rs |
| 46 |
+++ b/src/platform/linux_usbfs/usbfs.rs |
| 47 |
@@ -4,37 +4,37 @@ |
| 48 |
//! [usbfs]: https://www.kernel.org/doc/html/latest/driver-api/usb/usb.html#the-usb-character-device-nodes |
| 49 |
//! [uapi]: https://github.com/torvalds/linux/blob/master/tools/include/uapi/linux/usbdevice_fs.h |
| 50 |
#![allow(dead_code)] |
| 51 |
-use std::{ |
| 52 |
- ffi::{c_int, c_uchar, c_uint, c_void}, |
| 53 |
- marker::PhantomData, |
| 54 |
-}; |
| 55 |
+use std::ffi::{c_int, c_uchar, c_uint, c_void}; |
| 56 |
|
| 57 |
use rustix::{ |
| 58 |
fd::AsFd, |
| 59 |
io, |
| 60 |
- ioctl::{self, CompileTimeOpcode, Ioctl, IoctlOutput}, |
| 61 |
+ ioctl::{self, Ioctl, IoctlOutput, Opcode}, |
| 62 |
}; |
| 63 |
|
| 64 |
pub fn set_configuration<Fd: AsFd>(fd: Fd, configuration: u8) -> io::Result<()> { |
| 65 |
unsafe { |
| 66 |
- let ctl = |
| 67 |
- ioctl::Setter::<ioctl::ReadOpcode<b'U', 5, c_uint>, c_uint>::new(configuration.into()); |
| 68 |
+ let ctl = ioctl::Setter::<{ ioctl::opcode::read::<c_uint>(b'U', 5) }, c_uint>::new( |
| 69 |
+ configuration.into(), |
| 70 |
+ ); |
| 71 |
ioctl::ioctl(fd, ctl) |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
pub fn claim_interface<Fd: AsFd>(fd: Fd, interface: u8) -> io::Result<()> { |
| 76 |
unsafe { |
| 77 |
- let ctl = |
| 78 |
- ioctl::Setter::<ioctl::ReadOpcode<b'U', 15, c_uint>, c_uint>::new(interface.into()); |
| 79 |
+ let ctl = ioctl::Setter::<{ ioctl::opcode::read::<c_uint>(b'U', 15) }, c_uint>::new( |
| 80 |
+ interface.into(), |
| 81 |
+ ); |
| 82 |
ioctl::ioctl(fd, ctl) |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
pub fn release_interface<Fd: AsFd>(fd: Fd, interface: u8) -> io::Result<()> { |
| 87 |
unsafe { |
| 88 |
- let ctl = |
| 89 |
- ioctl::Setter::<ioctl::ReadOpcode<b'U', 16, c_uint>, c_uint>::new(interface.into()); |
| 90 |
+ let ctl = ioctl::Setter::<{ ioctl::opcode::read::<c_uint>(b'U', 16) }, c_uint>::new( |
| 91 |
+ interface.into(), |
| 92 |
+ ); |
| 93 |
ioctl::ioctl(fd, ctl) |
| 94 |
} |
| 95 |
} |
| 96 |
@@ -57,7 +57,7 @@ |
| 97 |
|
| 98 |
dc.driver[0..6].copy_from_slice(b"usbfs\0"); |
| 99 |
|
| 100 |
- let ctl = ioctl::Setter::<opcodes::USBDEVFS_DISCONNECT_CLAIM, DetachAndClaim>::new(dc); |
| 101 |
+ let ctl = ioctl::Setter::<{ opcodes::USBDEVFS_DISCONNECT_CLAIM }, DetachAndClaim>::new(dc); |
| 102 |
|
| 103 |
ioctl::ioctl(&fd, ctl) |
| 104 |
} |
| 105 |
@@ -78,17 +78,19 @@ |
| 106 |
// TODO: Move the rest of the opcodes into here. |
| 107 |
#[allow(non_camel_case_types)] |
| 108 |
mod opcodes { |
| 109 |
+ use rustix::ioctl::Opcode; |
| 110 |
+ |
| 111 |
use super::*; |
| 112 |
|
| 113 |
- pub type USBDEVFS_IOCTL = ioctl::ReadWriteOpcode<b'U', 18, UsbFsIoctl>; |
| 114 |
- pub type USBDEVFS_DISCONNECT_CLAIM = ioctl::ReadOpcode<b'U', 27, DetachAndClaim>; |
| 115 |
+ pub const USBDEVFS_IOCTL: Opcode = ioctl::opcode::read_write::<UsbFsIoctl>(b'U', 18); |
| 116 |
+ pub const USBDEVFS_DISCONNECT_CLAIM: Opcode = ioctl::opcode::read::<DetachAndClaim>(b'U', 27); |
| 117 |
|
| 118 |
/// These opcodes are nested inside a [`USBDEVFS_IOCTL`] operation. |
| 119 |
pub mod nested { |
| 120 |
use super::*; |
| 121 |
|
| 122 |
- pub type USBDEVFS_DISCONNECT = ioctl::NoneOpcode<b'U', 22, ()>; |
| 123 |
- pub type USBDEVFS_CONNECT = ioctl::NoneOpcode<b'U', 23, ()>; |
| 124 |
+ pub const USBDEVFS_DISCONNECT: Opcode = ioctl::opcode::none(b'U', 22); |
| 125 |
+ pub const USBDEVFS_CONNECT: Opcode = ioctl::opcode::none(b'U', 23); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
@@ -96,11 +98,11 @@ |
| 130 |
let command = UsbFsIoctl { |
| 131 |
interface: interface.into(), |
| 132 |
// NOTE: Cast needed since on android this type is i32 vs u32 on linux |
| 133 |
- ioctl_code: opcodes::nested::USBDEVFS_DISCONNECT::OPCODE.raw() as _, |
| 134 |
+ ioctl_code: opcodes::nested::USBDEVFS_DISCONNECT as _, |
| 135 |
data: std::ptr::null_mut(), |
| 136 |
}; |
| 137 |
unsafe { |
| 138 |
- let ctl = ioctl::Setter::<opcodes::USBDEVFS_IOCTL, UsbFsIoctl>::new(command); |
| 139 |
+ let ctl = ioctl::Setter::<{ opcodes::USBDEVFS_IOCTL }, UsbFsIoctl>::new(command); |
| 140 |
ioctl::ioctl(fd, ctl) |
| 141 |
} |
| 142 |
} |
| 143 |
@@ -108,11 +110,11 @@ |
| 144 |
pub fn attach_kernel_driver<Fd: AsFd>(fd: Fd, interface: u8) -> io::Result<()> { |
| 145 |
let command = UsbFsIoctl { |
| 146 |
interface: interface.into(), |
| 147 |
- ioctl_code: opcodes::nested::USBDEVFS_CONNECT::OPCODE.raw() as _, |
| 148 |
+ ioctl_code: opcodes::nested::USBDEVFS_CONNECT as _, |
| 149 |
data: std::ptr::null_mut(), |
| 150 |
}; |
| 151 |
unsafe { |
| 152 |
- let ctl = ioctl::Setter::<opcodes::USBDEVFS_IOCTL, UsbFsIoctl>::new(command); |
| 153 |
+ let ctl = ioctl::Setter::<{ opcodes::USBDEVFS_IOCTL }, UsbFsIoctl>::new(command); |
| 154 |
ioctl::ioctl(fd, ctl) |
| 155 |
} |
| 156 |
} |
| 157 |
@@ -125,22 +127,22 @@ |
| 158 |
|
| 159 |
pub fn set_interface<Fd: AsFd>(fd: Fd, interface: u8, alt_setting: u8) -> io::Result<()> { |
| 160 |
unsafe { |
| 161 |
- let ctl = ioctl::Setter::<ioctl::ReadOpcode<b'U', 4, SetAltSetting>, SetAltSetting>::new( |
| 162 |
- SetAltSetting { |
| 163 |
- interface: interface.into(), |
| 164 |
- alt_setting: alt_setting.into(), |
| 165 |
- }, |
| 166 |
- ); |
| 167 |
+ let ctl = |
| 168 |
+ ioctl::Setter::<{ ioctl::opcode::read::<SetAltSetting>(b'U', 4) }, SetAltSetting>::new( |
| 169 |
+ SetAltSetting { |
| 170 |
+ interface: interface.into(), |
| 171 |
+ alt_setting: alt_setting.into(), |
| 172 |
+ }, |
| 173 |
+ ); |
| 174 |
ioctl::ioctl(fd, ctl) |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
-pub struct PassPtr<Opcode, Input> { |
| 179 |
+pub struct PassPtr<const OPCODE: Opcode, Input> { |
| 180 |
input: *mut Input, |
| 181 |
- _opcode: PhantomData<Opcode>, |
| 182 |
} |
| 183 |
|
| 184 |
-impl<Opcode: CompileTimeOpcode, Input> PassPtr<Opcode, Input> { |
| 185 |
+impl<const OPCODE: Opcode, Input> PassPtr<OPCODE, Input> { |
| 186 |
/// Create a new pointer setter-style `ioctl` object. |
| 187 |
/// |
| 188 |
/// # Safety |
| 189 |
@@ -150,18 +152,18 @@ |
| 190 |
/// get. |
| 191 |
#[inline] |
| 192 |
pub unsafe fn new(input: *mut Input) -> Self { |
| 193 |
- Self { |
| 194 |
- input, |
| 195 |
- _opcode: PhantomData, |
| 196 |
- } |
| 197 |
+ Self { input } |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
-unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for PassPtr<Opcode, Input> { |
| 202 |
+unsafe impl<const OPCODE: Opcode, Input> Ioctl for PassPtr<OPCODE, Input> { |
| 203 |
type Output = (); |
| 204 |
|
| 205 |
const IS_MUTATING: bool = false; |
| 206 |
- const OPCODE: rustix::ioctl::Opcode = Opcode::OPCODE; |
| 207 |
+ |
| 208 |
+ fn opcode(&self) -> ioctl::Opcode { |
| 209 |
+ OPCODE |
| 210 |
+ } |
| 211 |
|
| 212 |
fn as_ptr(&mut self) -> *mut c_void { |
| 213 |
self.input as *mut c_void |
| 214 |
@@ -174,28 +176,28 @@ |
| 215 |
|
| 216 |
pub unsafe fn submit_urb<Fd: AsFd>(fd: Fd, urb: *mut Urb) -> io::Result<()> { |
| 217 |
unsafe { |
| 218 |
- let ctl = PassPtr::<ioctl::ReadOpcode<b'U', 10, Urb>, Urb>::new(urb); |
| 219 |
+ let ctl = PassPtr::<{ ioctl::opcode::read::<Urb>(b'U', 10) }, Urb>::new(urb); |
| 220 |
ioctl::ioctl(fd, ctl) |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
pub fn reap_urb_ndelay<Fd: AsFd>(fd: Fd) -> io::Result<*mut Urb> { |
| 225 |
unsafe { |
| 226 |
- let ctl = ioctl::Getter::<ioctl::WriteOpcode<b'U', 13, *mut Urb>, *mut Urb>::new(); |
| 227 |
+ let ctl = ioctl::Getter::<{ ioctl::opcode::write::<*mut Urb>(b'U', 13) }, *mut Urb>::new(); |
| 228 |
ioctl::ioctl(fd, ctl) |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
pub unsafe fn discard_urb<Fd: AsFd>(fd: Fd, urb: *mut Urb) -> io::Result<()> { |
| 233 |
unsafe { |
| 234 |
- let ctl = PassPtr::<ioctl::NoneOpcode<b'U', 11, ()>, Urb>::new(urb); |
| 235 |
+ let ctl = PassPtr::<{ ioctl::opcode::none(b'U', 11) }, Urb>::new(urb); |
| 236 |
ioctl::ioctl(fd, ctl) |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
pub fn reset<Fd: AsFd>(fd: Fd) -> io::Result<()> { |
| 241 |
unsafe { |
| 242 |
- let ctl = ioctl::NoArg::<ioctl::NoneOpcode<b'U', 20, ()>>::new(); |
| 243 |
+ let ctl = ioctl::NoArg::<{ ioctl::opcode::none(b'U', 20) }>::new(); |
| 244 |
ioctl::ioctl(fd, ctl) |
| 245 |
} |
| 246 |
} |
| 247 |
@@ -229,26 +231,25 @@ |
| 248 |
// + variable size array of iso_packet_desc |
| 249 |
} |
| 250 |
|
| 251 |
-pub struct Transfer<Opcode, Input> { |
| 252 |
+pub struct Transfer<const OPCODE: Opcode, Input> { |
| 253 |
input: Input, |
| 254 |
- _opcode: PhantomData<Opcode>, |
| 255 |
} |
| 256 |
|
| 257 |
-impl<Opcode: CompileTimeOpcode, Input> Transfer<Opcode, Input> { |
| 258 |
+impl<const OPCODE: Opcode, Input> Transfer<OPCODE, Input> { |
| 259 |
#[inline] |
| 260 |
pub unsafe fn new(input: Input) -> Self { |
| 261 |
- Self { |
| 262 |
- input, |
| 263 |
- _opcode: PhantomData, |
| 264 |
- } |
| 265 |
+ Self { input } |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
-unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for Transfer<Opcode, Input> { |
| 270 |
+unsafe impl<const OPCODE: Opcode, Input> Ioctl for Transfer<OPCODE, Input> { |
| 271 |
type Output = usize; |
| 272 |
|
| 273 |
const IS_MUTATING: bool = true; |
| 274 |
- const OPCODE: rustix::ioctl::Opcode = Opcode::OPCODE; |
| 275 |
+ |
| 276 |
+ fn opcode(&self) -> ioctl::Opcode { |
| 277 |
+ OPCODE |
| 278 |
+ } |
| 279 |
|
| 280 |
fn as_ptr(&mut self) -> *mut c_void { |
| 281 |
&mut self.input as *mut Input as *mut c_void |
| 282 |
@@ -274,7 +275,7 @@ |
| 283 |
pub fn control<Fd: AsFd>(fd: Fd, transfer: CtrlTransfer) -> io::Result<usize> { |
| 284 |
unsafe { |
| 285 |
let ctl = |
| 286 |
- Transfer::<ioctl::ReadWriteOpcode<b'U', 0, CtrlTransfer>, CtrlTransfer>::new(transfer); |
| 287 |
+ Transfer::<{ ioctl::opcode::read_write::<CtrlTransfer>(b'U', 0) }, CtrlTransfer>::new(transfer); |
| 288 |
ioctl::ioctl(fd, ctl) |
| 289 |
} |
| 290 |
} |
| 291 |
@@ -282,7 +283,7 @@ |
| 292 |
pub fn clear_halt<Fd: AsFd>(fd: Fd, endpoint: u8) -> io::Result<()> { |
| 293 |
unsafe { |
| 294 |
let ctl = |
| 295 |
- ioctl::Setter::<ioctl::ReadOpcode<b'U', 21, c_uint>, c_uint>::new(endpoint.into()); |
| 296 |
+ ioctl::Setter::<{ ioctl::opcode::read::<c_uint>(b'U', 21) }, c_uint>::new(endpoint.into()); |
| 297 |
ioctl::ioctl(fd, ctl) |
| 298 |
} |
| 299 |
} |