From 6bce162b92ed7185e1f1cd8b6d9ee240858fea10 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 14 Dec 2025 20:45:26 +0100 Subject: [PATCH] Fix read-only and write-only ioctls Read-only ioctls write data to userspace, while write-only ioctls read data from userspace. This matches the read and write syscalls. --- src/header/sys_ioctl/redox/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/header/sys_ioctl/redox/mod.rs b/src/header/sys_ioctl/redox/mod.rs index bc2f08fa69..2914769366 100644 --- a/src/header/sys_ioctl/redox/mod.rs +++ b/src/header/sys_ioctl/redox/mod.rs @@ -67,15 +67,15 @@ fn dup_write(fd: c_int, name: &str, t: &T) -> Result { #[derive(Debug)] enum IoctlBuffer { None, - Read(*const c_void, usize), - Write(*mut c_void, usize), + Read(*mut c_void, usize), // read (write to userspace) + Write(*const c_void, usize), // write (read from userspace) ReadWrite(*mut c_void, usize), } impl IoctlBuffer { unsafe fn read(&self) -> Result { let (ptr, size) = match *self { - Self::Read(ptr, size) => (ptr, size), + Self::Write(ptr, size) => (ptr, size), Self::ReadWrite(ptr, size) => (ptr as *const c_void, size), _ => { return Err(Errno(EINVAL)); @@ -91,7 +91,7 @@ impl IoctlBuffer { unsafe fn write(&mut self, value: T) -> Result<()> { let (ptr, size) = match *self { - Self::Write(ptr, size) | Self::ReadWrite(ptr, size) => (ptr, size), + Self::Read(ptr, size) | Self::ReadWrite(ptr, size) => (ptr, size), _ => { return Err(Errno(EINVAL)); } @@ -105,7 +105,6 @@ impl IoctlBuffer { } } - unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result { match request { FIONBIO => { @@ -179,7 +178,7 @@ unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result IoctlBuffer::None, }; return drm::ioctl(fd, func, buf); - }, + } _ => { return Err(Errno(EINVAL)); }