Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2777.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made `fcntl::vmsplice` an unsafe function.
11 changes: 10 additions & 1 deletion src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,17 @@ pub fn tee<Fd1: std::os::fd::AsFd, Fd2: std::os::fd::AsFd>(
///
/// # See Also
/// *[`vmsplice`](https://man7.org/linux/man-pages/man2/vmsplice.2.html)
///
/// # Safety
///
/// * The content of `iov` must not be changed until kernel has finished reading it "even after the caller process finished".
/// * If `SpliceFFlags::SPLICE_F_GIFT` is set:
/// - The contents of `iov` must never be modified after the call.
/// - All pointers in `iov` must be page-aligned.
/// - All lengths must be a multiple of the system page size in bytes.
/// **Note** Linux kernel does not have an API to know when the kernel finished using the content of RAM
#[cfg(linux_android)]
pub fn vmsplice<F: std::os::fd::AsFd>(
pub unsafe fn vmsplice<F: std::os::fd::AsFd>(
fd: F,
iov: &[std::io::IoSlice<'_>],
flags: SpliceFFlags,
Expand Down
3 changes: 2 additions & 1 deletion test/test_fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ mod linux_android {
let buf2 = b"defghi";
let iovecs = [IoSlice::new(&buf1[0..3]), IoSlice::new(&buf2[0..3])];

let res = vmsplice(wr, &iovecs[..], SpliceFFlags::empty()).unwrap();
let res = unsafe { vmsplice(wr, &iovecs[..], SpliceFFlags::empty()) }
.unwrap();

assert_eq!(6, res);

Expand Down
Loading