Skip to content

Commit d8afee9

Browse files
authored
Fix copy_file_range to use ABI specified len types (#499)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com> Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent dff1d9f commit d8afee9

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ pub(crate) fn copy_file_range(
779779
off_in: Option<&mut u64>,
780780
fd_out: BorrowedFd<'_>,
781781
off_out: Option<&mut u64>,
782-
len: u64,
783-
) -> io::Result<u64> {
782+
len: usize,
783+
) -> io::Result<usize> {
784784
assert_eq!(size_of::<c::loff_t>(), size_of::<u64>());
785785

786786
let mut off_in_val: c::loff_t = 0;
@@ -798,7 +798,6 @@ pub(crate) fn copy_file_range(
798798
} else {
799799
null_mut()
800800
};
801-
let len: usize = len.try_into().unwrap_or(usize::MAX);
802801
let copied = unsafe {
803802
syscall_ret_ssize_t(c::syscall(
804803
c::SYS_copy_file_range,
@@ -816,7 +815,7 @@ pub(crate) fn copy_file_range(
816815
if let Some(off_out) = off_out {
817816
*off_out = off_out_val as u64;
818817
}
819-
Ok(copied as u64)
818+
Ok(copied as usize)
820819
}
821820

822821
#[cfg(not(any(

src/backend/linux_raw/fs/syscalls.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::fs::{
3030
};
3131
use crate::io::{self, SeekFrom};
3232
use crate::process::{Gid, Uid};
33+
#[cfg(any(target_pointer_width = "32", target_arch = "mips64"))]
3334
use core::convert::TryInto;
3435
use core::mem::MaybeUninit;
3536
#[cfg(target_arch = "mips64")]
@@ -1342,24 +1343,11 @@ pub(crate) fn accessat(
13421343

13431344
#[inline]
13441345
pub(crate) fn copy_file_range(
1345-
fd_in: BorrowedFd<'_>,
1346-
off_in: Option<&mut u64>,
1347-
fd_out: BorrowedFd<'_>,
1348-
off_out: Option<&mut u64>,
1349-
len: u64,
1350-
) -> io::Result<u64> {
1351-
let len: usize = len.try_into().unwrap_or(usize::MAX);
1352-
_copy_file_range(fd_in, off_in, fd_out, off_out, len, 0).map(|result| result as u64)
1353-
}
1354-
1355-
#[inline]
1356-
fn _copy_file_range(
13571346
fd_in: BorrowedFd<'_>,
13581347
off_in: Option<&mut u64>,
13591348
fd_out: BorrowedFd<'_>,
13601349
off_out: Option<&mut u64>,
13611350
len: usize,
1362-
flags: c::c_uint,
13631351
) -> io::Result<usize> {
13641352
unsafe {
13651353
ret_usize(syscall!(
@@ -1369,7 +1357,7 @@ fn _copy_file_range(
13691357
fd_out,
13701358
opt_mut(off_out),
13711359
pass_usize(len),
1372-
c_uint(flags)
1360+
c_uint(0)
13731361
))
13741362
}
13751363
}

src/fs/copy_file_range.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn copy_file_range<InFd: AsFd, OutFd: AsFd>(
1414
off_in: Option<&mut u64>,
1515
fd_out: OutFd,
1616
off_out: Option<&mut u64>,
17-
len: u64,
18-
) -> io::Result<u64> {
17+
len: usize,
18+
) -> io::Result<usize> {
1919
backend::fs::syscalls::copy_file_range(fd_in.as_fd(), off_in, fd_out.as_fd(), off_out, len)
2020
}

0 commit comments

Comments
 (0)