From 1819dc78940f437cdac92c1272e04c087dfe152e Mon Sep 17 00:00:00 2001 From: Asaf Fisher Date: Mon, 16 May 2022 18:47:32 +0300 Subject: [PATCH 1/3] Fix #323: Remove `std` usage in `linux_raw::io::syscalls` --- src/imp/linux_raw/io/syscalls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imp/linux_raw/io/syscalls.rs b/src/imp/linux_raw/io/syscalls.rs index c0b26a3d2..8d668b7a9 100644 --- a/src/imp/linux_raw/io/syscalls.rs +++ b/src/imp/linux_raw/io/syscalls.rs @@ -557,7 +557,7 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &OwnedFd) -> io::Result<()> { { // `dup3` fails if the old and new file descriptors have the same // value, so emulate the `dup2` behvior. - use std::os::unix::io::AsRawFd; + use crate::fd::AsRawFd; if fd.as_raw_fd() == new.as_raw_fd() { return Ok(()); } From 847456a4fea8fc9d60d24d2f761f2987371d1d10 Mon Sep 17 00:00:00 2001 From: Asaf Fisher Date: Fri, 13 May 2022 21:52:29 +0300 Subject: [PATCH 2/3] Match casting type to the destination iov_len's type. fix #324 --- src/imp/linux_raw/io/io_slice.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/imp/linux_raw/io/io_slice.rs b/src/imp/linux_raw/io/io_slice.rs index 1a369df75..bbe886a58 100644 --- a/src/imp/linux_raw/io/io_slice.rs +++ b/src/imp/linux_raw/io/io_slice.rs @@ -7,6 +7,7 @@ use super::c; use core::marker::PhantomData; use core::slice; +use linux_raw_sys::general::__kernel_size_t; /// #[derive(Copy, Clone)] @@ -23,7 +24,7 @@ impl<'a> IoSlice<'a> { IoSlice { vec: c::iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void, - iov_len: buf.len() as u64, + iov_len: buf.len() as _, }, _p: PhantomData, } @@ -32,12 +33,12 @@ impl<'a> IoSlice<'a> { /// #[inline] pub fn advance(&mut self, n: usize) { - if self.vec.iov_len < n as u64 { + if self.vec.iov_len < n as _ { panic!("advancing IoSlice beyond its length"); } unsafe { - self.vec.iov_len -= n as u64; + self.vec.iov_len -= n as __kernel_size_t; self.vec.iov_base = self.vec.iov_base.add(n); } } @@ -63,7 +64,7 @@ impl<'a> IoSliceMut<'a> { IoSliceMut { vec: c::iovec { iov_base: buf.as_mut_ptr() as *mut c::c_void, - iov_len: buf.len() as u64, + iov_len: buf.len() as _, }, _p: PhantomData, } @@ -72,12 +73,12 @@ impl<'a> IoSliceMut<'a> { /// #[inline] pub fn advance(&mut self, n: usize) { - if self.vec.iov_len < n as u64 { + if self.vec.iov_len < n as _ { panic!("advancing IoSliceMut beyond its length"); } unsafe { - self.vec.iov_len -= n as u64; + self.vec.iov_len -= n as __kernel_size_t; self.vec.iov_base = self.vec.iov_base.add(n); } } From 2eaff1dd75196a518f23e11cfa970277871e172a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 10 May 2022 08:04:55 -0700 Subject: [PATCH 3/3] Don't use `syscall_readonly` in `set_thread_area`. `set_thread_area` updates the `entry_number` field of the struct passed to it, so don't use `syscall_readonly`. --- src/imp/linux_raw/syscalls.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/imp/linux_raw/syscalls.rs b/src/imp/linux_raw/syscalls.rs index ab10ebf70..c72e88aae 100644 --- a/src/imp/linux_raw/syscalls.rs +++ b/src/imp/linux_raw/syscalls.rs @@ -34,7 +34,10 @@ use linux_raw_sys::general::{ __kernel_pid_t, PR_SET_NAME, SIGCHLD, }; #[cfg(target_arch = "x86")] -use {super::conv::by_mut, linux_raw_sys::general::__NR_set_thread_area}; +use { + super::arch::choose::syscall1, super::conv::by_mut, + linux_raw_sys::general::__NR_set_thread_area, +}; #[cfg(target_arch = "x86_64")] use { super::conv::ret_infallible, @@ -92,7 +95,7 @@ pub(crate) mod tls { #[cfg(target_arch = "x86")] #[inline] pub(crate) unsafe fn set_thread_area(u_info: &mut UserDesc) -> io::Result<()> { - ret(syscall1_readonly(nr(__NR_set_thread_area), by_mut(u_info))) + ret(syscall1(nr(__NR_set_thread_area), by_mut(u_info))) } #[cfg(target_arch = "arm")]