Skip to content

Conversation

@wdcui
Copy link
Member

@wdcui wdcui commented Feb 2, 2026

Summary

Add support for the Linux splice(2) and tee(2) syscalls, enabling zero-copy data transfer between file descriptors using pipes as intermediary buffers.

New Syscalls

  • splice: Move data between a pipe and a file descriptor (or two pipes) without copying between kernel and user space
  • tee: Duplicate pipe content without consuming it from the source pipe

Implementation Details

SpliceFlags

  • SPLICE_F_MOVE (0x01): Hint to move pages instead of copying (advisory)
  • SPLICE_F_NONBLOCK (0x02): Don't block on pipe I/O
  • SPLICE_F_MORE (0x04): More data will be coming (hint for sockets)
  • SPLICE_F_GIFT (0x08): Pages are a gift (vmsplice only)

splice Behavior

  • Validates that at least one fd is a pipe
  • Rejects offset pointers for pipe fds (returns ESPIPE)
  • Supports: pipe→file, file→pipe, pipe→pipe transfers
  • Uses temporary buffer (max 64KB) for efficient data transfer
  • Respects SPLICE_F_NONBLOCK for non-blocking operation

tee Behavior

  • Validates that both fds are pipes
  • Rejects same fd for input and output (returns EINVAL)
  • Duplicates data without consuming from source pipe

Files Modified

  • litebox_common_linux/src/lib.rs: SpliceFlags type, Splice/Tee syscall variants, parsing
  • litebox_shim_linux/src/lib.rs: Syscall dispatch
  • litebox_shim_linux/src/syscalls/file.rs: sys_splice, sys_tee implementations
  • litebox_shim_linux/src/syscalls/tests.rs: 8 unit tests

Testing

  • 8 unit tests added covering error cases
  • All 178 tests pass
  • No clippy warnings

References

  • Linux man pages: man 2 splice, man 2 tee
  • Linux source: /fs/splice.c

wdcui and others added 2 commits February 2, 2026 00:26
Add support for the Linux splice(2) and tee(2) syscalls, enabling
zero-copy data transfer between file descriptors using pipes as
intermediary buffers.

New syscalls implemented:
- splice: Move data between a pipe and a file descriptor (or two pipes)
- tee: Duplicate pipe content without consuming it

Implementation details:
- SpliceFlags bitflags type for SPLICE_F_MOVE, SPLICE_F_NONBLOCK, etc.
- Validates that at least one fd is a pipe for splice
- Validates that both fds are pipes for tee
- Rejects offset pointers for pipe fds (returns ESPIPE)
- Uses temporary buffer (max 64KB) for efficient data transfer
- Respects SPLICE_F_NONBLOCK for non-blocking operation

Files modified:
- litebox_common_linux/src/lib.rs: SpliceFlags type, syscall variants
- litebox_shim_linux/src/lib.rs: Syscall dispatch
- litebox_shim_linux/src/syscalls/file.rs: sys_splice, sys_tee
- litebox_shim_linux/src/syscalls/tests.rs: 8 unit tests

Co-Authored-By: Claude <[email protected]>
Address code review feedback:

Security fixes:
- TOCTOU vulnerability: Read offset only once, store in local variable
- Integer overflow: Use checked_add() with EOVERFLOW error
- Same-pipe check: Add fd_in != fd_out validation for splice
- Negative offset validation: Explicit check before conversion

Correctness fixes:
- tee partial write: Only write back bytes_written to input pipe
  to avoid data inconsistency on partial writes

Documentation:
- Add Implementation Notes section to sys_tee explaining limitations
- Update clippy expect reasons to be more accurate (bytes_written ≤ 65536)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants