Skip to content
Draft
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
53 changes: 53 additions & 0 deletions litebox_common_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,33 @@ bitflags::bitflags! {
}
}

/// Flags for the `splice(2)` and `tee(2)` syscalls.
#[derive(Clone, Copy, Debug, PartialEq, Eq, FromBytes, IntoBytes)]
#[repr(C)]
pub struct SpliceFlags(u32);

bitflags::bitflags! {
impl SpliceFlags: u32 {
/// `SPLICE_F_MOVE`: Attempt to move pages instead of copying.
/// This is only a hint; the kernel may still copy.
const MOVE = 0x01;
/// `SPLICE_F_NONBLOCK`: Do not block on I/O.
const NONBLOCK = 0x02;
/// `SPLICE_F_MORE`: More data will be coming in a subsequent splice.
/// This is a hint for sockets.
const MORE = 0x04;
/// `SPLICE_F_GIFT`: Pages passed in are a gift (vmsplice only).
const GIFT = 0x08;
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
const _ = !0;
}
}

impl SpliceFlags {
/// All valid splice flags combined.
pub const VALID_MASK: u32 = 0x0F;
}

/// Packaged sigset with its size, used by `pselect` syscall
#[derive(Clone, Copy, FromBytes, IntoBytes)]
#[repr(C)]
Expand Down Expand Up @@ -2261,6 +2288,24 @@ pub enum SyscallRequest<Platform: litebox::platform::RawPointerProvider> {
new_value: Platform::RawConstPointer<ItimerVal>,
old_value: Option<Platform::RawMutPointer<ItimerVal>>,
},
/// Move data between file descriptors without copying.
/// At least one of fd_in or fd_out must be a pipe.
Splice {
fd_in: i32,
off_in: Option<Platform::RawMutPointer<i64>>,
fd_out: i32,
off_out: Option<Platform::RawMutPointer<i64>>,
len: usize,
flags: SpliceFlags,
},
/// Duplicate pipe content without consuming it.
/// Both fd_in and fd_out must be pipes.
Tee {
fd_in: i32,
fd_out: i32,
len: usize,
flags: SpliceFlags,
},
}

impl<Platform: litebox::platform::RawPointerProvider> SyscallRequest<Platform> {
Expand Down Expand Up @@ -2800,6 +2845,13 @@ impl<Platform: litebox::platform::RawPointerProvider> SyscallRequest<Platform> {
Sysno::umask => sys_req!(Umask { mask }),
Sysno::alarm => sys_req!(Alarm { seconds }),
Sysno::setitimer => sys_req!(SetITimer { which:?, new_value:*, old_value:* }),
Sysno::splice => sys_req!(Splice { fd_in, off_in:*, fd_out, off_out:*, len, flags }),
Sysno::tee => sys_req!(Tee {
fd_in,
fd_out,
len,
flags
}),
// Noisy unsupported syscalls.
Sysno::statx | Sysno::io_uring_setup | Sysno::rseq | Sysno::statfs => {
return Err(errno::Errno::ENOSYS);
Expand Down Expand Up @@ -3184,6 +3236,7 @@ reinterpret_truncated_from_usize_for! {
EfdFlags,
RngFlags,
TimerFlags,
SpliceFlags,
],
}

Expand Down
14 changes: 14 additions & 0 deletions litebox_shim_linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,20 @@ impl Task {
SyscallRequest::Tkill { tid, sig } => self.sys_tkill(tid, sig),
SyscallRequest::Tgkill { tgid, tid, sig } => self.sys_tgkill(tgid, tid, sig),
SyscallRequest::Sigaltstack { ss, old_ss } => self.sys_sigaltstack(ss, old_ss, ctx),
SyscallRequest::Splice {
fd_in,
off_in,
fd_out,
off_out,
len,
flags,
} => self.sys_splice(fd_in, off_in, fd_out, off_out, len, flags),
SyscallRequest::Tee {
fd_in,
fd_out,
len,
flags,
} => self.sys_tee(fd_in, fd_out, len, flags),
_ => {
log_unsupported!("{request:?}");
Err(Errno::ENOSYS)
Expand Down
Loading