Skip to content

Syscall sendfile#73

Open
henriquebritoM wants to merge 7 commits intoNetBSD:trunkfrom
henriquebritoM:syscall-sendfile
Open

Syscall sendfile#73
henriquebritoM wants to merge 7 commits intoNetBSD:trunkfrom
henriquebritoM:syscall-sendfile

Conversation

@henriquebritoM
Copy link

What was done

This patch adds the implementation of the sendfile(2) syscall for compat linux on amd64.

The sendfile(2) syscall allows efficient data transfers between two file descriptors, directly within the kernel space, eliminating the need to copy data to user space.

The emulation was validated against the Linux Test Project, passing all sendfile related tests, providing Linux Binaries with the expected ABI.

Performance wise, my tests showed it being as efficient as the default read + write, ensuring that Binaries that can use read + write when sendfile is not present won't suffer any negative performance impact.

Instructions to reproduce the LTP tests

On Linux:

  • Clone the LTP repository and run the default commands:
git clone --recurse-submodules https://github.com/linux-test-project/ltp.git
cd ltp
make autotools
./configure
cd testcases/kernel/syscalls/sendfile/
  • Modify the Makefile to compile with static flag:
    Open Makefile
    Find the line: %_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
    Add this in the following line: LDFLAGS = -static

  • Modify the test 7 (The emulation of write syscall returns a different error code than expected by this test)
    Open sendfile07.c
    Find this line: if (TST_ERR == EAGAIN)
    Replace it with: if (TST_ERR == EAGAIN || TST_ERR == ENOBUFS)

  • run the make

make
  • Copy the binaries to NetBSD

On NetBSD:

  • Clone the repository, recompile the compat linux module and load it
  • Mount the tmpfs: mount -t tmpfs -o -s=6g tmpfs /tmp (Be sure you have 6GB of free RAM)
  • Execute the LTP tests

henriquebritoM and others added 7 commits February 20, 2026 09:45
Implements Linux-compatible sendfile semantics and
passes LTP coverage.

XXX: ENOBUFS from fo_write() may be reported with
non-zero progress for SOCK_DGRAM. Needs more work.
Fixed error handling for the fo_write(). The ENOBUFS with non-zero progress is now correctly treated.
Removed debug printfs and improved comments.
Fixed double writting, increased buffer size and improved offset logic. Performance now is about the same as read() + write().
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.

1 participant